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
11#include "core/fxcrt/span.h"
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 "v8/include/v8-primitive.h"
19#include "xfa/fxfa/cxfa_ffdoc.h"
20#include "xfa/fxfa/cxfa_ffnotify.h"
21#include "xfa/fxfa/parser/cxfa_packet.h"
22
23const CJX_MethodSpec CJX_Packet::MethodSpecs[] = {
24 {"getAttribute", getAttribute_static},
25 {"removeAttribute", removeAttribute_static},
26 {"setAttribute", setAttribute_static}};
27
28CJX_Packet::CJX_Packet(CXFA_Packet* packet) : CJX_Node(packet) {
29 DefineMethods(MethodSpecs);
30}
31
32CJX_Packet::~CJX_Packet() = default;
33
34bool CJX_Packet::DynamicTypeIs(TypeTag eType) const {
35 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
36}
37
38CJS_Result CJX_Packet::getAttribute(CFXJSE_Engine* runtime,
39 pdfium::span<v8::Local<v8::Value>> params) {
40 if (params.size() != 1)
42
43 WideString attributeValue;
44 CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
45 if (element)
46 attributeValue = element->GetAttribute(runtime->ToWideString(params[0]));
47
49 runtime->NewString(attributeValue.ToUTF8().AsStringView()));
50}
51
52CJS_Result CJX_Packet::setAttribute(CFXJSE_Engine* runtime,
53 pdfium::span<v8::Local<v8::Value>> params) {
54 if (params.size() != 2)
56
57 CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
58 if (element) {
59 element->SetAttribute(runtime->ToWideString(params[1]),
60 runtime->ToWideString(params[0]));
61 }
62 return CJS_Result::Success(runtime->NewNull());
63}
64
65CJS_Result CJX_Packet::removeAttribute(
66 CFXJSE_Engine* runtime,
67 pdfium::span<v8::Local<v8::Value>> params) {
68 if (params.size() != 1)
70
71 CFX_XMLElement* pElement = ToXMLElement(GetXFANode()->GetXMLMappingNode());
72 if (pElement)
73 pElement->RemoveAttribute(runtime->ToWideString(params[0]));
74
75 return CJS_Result::Success(runtime->NewNull());
76}
77
78void CJX_Packet::content(v8::Isolate* pIsolate,
79 v8::Local<v8::Value>* pValue,
80 bool bSetting,
81 XFA_Attribute eAttribute) {
82 CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
83 if (bSetting) {
84 if (element) {
85 element->AppendLastChild(
87 ->GetDocument()
88 ->GetNotify()
89 ->GetFFDoc()
90 ->GetXMLDocument()
91 ->CreateNode<CFX_XMLText>(
92 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue)));
93 }
94 return;
95 }
96
97 WideString wsTextData;
98 if (element)
99 wsTextData = element->GetTextData();
100
101 *pValue = fxv8::NewStringHelper(pIsolate, wsTextData.ToUTF8().AsStringView());
102}
friend class EventParamScope
WideString GetTextData() const
static CJS_Result Success()
Definition cjs_result.h:28
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:35
bool DynamicTypeIs(TypeTag eType) const override
Definition cjx_node.cpp:112
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
fxcrt::WideString WideString
Definition widestring.h:207