Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjx_packet.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fxjs/xfa/cjx_packet.h"
8
9#include <utility>
10#include <vector>
11
12#include "core/fxcrt/xml/cfx_xmldocument.h"
13#include "core/fxcrt/xml/cfx_xmlelement.h"
14#include "core/fxcrt/xml/cfx_xmltext.h"
15#include "fxjs/cfx_v8.h"
16#include "fxjs/fxv8.h"
17#include "fxjs/js_resources.h"
18#include "third_party/base/containers/span.h"
19#include "v8/include/v8-primitive.h"
20#include "xfa/fxfa/cxfa_ffdoc.h"
21#include "xfa/fxfa/cxfa_ffnotify.h"
22#include "xfa/fxfa/parser/cxfa_packet.h"
23
24const CJX_MethodSpec CJX_Packet::MethodSpecs[] = {
25 {"getAttribute", getAttribute_static},
26 {"removeAttribute", removeAttribute_static},
27 {"setAttribute", setAttribute_static}};
28
29CJX_Packet::CJX_Packet(CXFA_Packet* packet) : CJX_Node(packet) {
30 DefineMethods(MethodSpecs);
31}
32
33CJX_Packet::~CJX_Packet() = default;
34
35bool CJX_Packet::DynamicTypeIs(TypeTag eType) const {
36 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
37}
38
39CJS_Result CJX_Packet::getAttribute(CFXJSE_Engine* runtime,
40 pdfium::span<v8::Local<v8::Value>> params) {
41 if (params.size() != 1)
43
44 WideString attributeValue;
45 CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
46 if (element)
47 attributeValue = element->GetAttribute(runtime->ToWideString(params[0]));
48
50 runtime->NewString(attributeValue.ToUTF8().AsStringView()));
51}
52
53CJS_Result CJX_Packet::setAttribute(CFXJSE_Engine* runtime,
54 pdfium::span<v8::Local<v8::Value>> params) {
55 if (params.size() != 2)
57
58 CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
59 if (element) {
60 element->SetAttribute(runtime->ToWideString(params[1]),
61 runtime->ToWideString(params[0]));
62 }
63 return CJS_Result::Success(runtime->NewNull());
64}
65
66CJS_Result CJX_Packet::removeAttribute(
67 CFXJSE_Engine* runtime,
68 pdfium::span<v8::Local<v8::Value>> params) {
69 if (params.size() != 1)
71
72 CFX_XMLElement* pElement = ToXMLElement(GetXFANode()->GetXMLMappingNode());
73 if (pElement)
74 pElement->RemoveAttribute(runtime->ToWideString(params[0]));
75
76 return CJS_Result::Success(runtime->NewNull());
77}
78
79void CJX_Packet::content(v8::Isolate* pIsolate,
80 v8::Local<v8::Value>* pValue,
81 bool bSetting,
82 XFA_Attribute eAttribute) {
83 CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
84 if (bSetting) {
85 if (element) {
86 element->AppendLastChild(
88 ->GetDocument()
89 ->GetNotify()
90 ->GetFFDoc()
91 ->GetXMLDocument()
92 ->CreateNode<CFX_XMLText>(
93 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue)));
94 }
95 return;
96 }
97
98 WideString wsTextData;
99 if (element)
100 wsTextData = element->GetTextData();
101
102 *pValue = fxv8::NewStringHelper(pIsolate, wsTextData.ToUTF8().AsStringView());
103}
friend class EventParamScope
WideString GetTextData() const
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
bool DynamicTypeIs(TypeTag eType) const override
Definition cjx_node.cpp:112
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
CXFA_Node * GetXFANode() const
~CJX_Packet() override
bool DynamicTypeIs(TypeTag eType) const override
ByteString ToUTF8() const
WideString & operator=(WideString &&that) noexcept
XFA_Attribute
Definition fxfa_basic.h:67
JSMessage