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
cxfa_script.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 "xfa/fxfa/parser/cxfa_script.h"
8
9#include "fxjs/xfa/cjx_script.h"
10#include "xfa/fxfa/parser/cxfa_document.h"
11
12namespace {
13
14const CXFA_Node::PropertyData kScriptPropertyData[] = {
15 {XFA_Element::Exclude, 1, {}},
16 {XFA_Element::CurrentPage, 1, {}},
17 {XFA_Element::RunScripts, 1, {}},
18};
19
20const CXFA_Node::AttributeData kScriptAttributeData[] = {
24 {XFA_Attribute::ContentType, XFA_AttributeType::CData, nullptr},
26 (void*)XFA_AttributeValue::Client},
27 {XFA_Attribute::Binding, XFA_AttributeType::CData, nullptr},
28 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
31};
32
33} // namespace
34
35// static
36CXFA_Script* CXFA_Script::FromNode(CXFA_Node* pNode) {
37 return pNode && pNode->GetElementType() == XFA_Element::Script
38 ? static_cast<CXFA_Script*>(pNode)
39 : nullptr;
40}
41
42CXFA_Script::CXFA_Script(CXFA_Document* doc, XFA_PacketType packet)
43 : CXFA_Node(doc,
44 packet,
45 {XFA_XDPPACKET::kConfig, XFA_XDPPACKET::kTemplate,
46 XFA_XDPPACKET::kForm},
47 XFA_ObjectType::ContentNode,
48 XFA_Element::Script,
49 kScriptPropertyData,
50 kScriptAttributeData,
51 cppgc::MakeGarbageCollected<CJX_Script>(
52 doc->GetHeap()->GetAllocationHandle(),
53 this)) {}
54
55CXFA_Script::~CXFA_Script() = default;
56
57CXFA_Script::Type CXFA_Script::GetContentType() {
58 absl::optional<WideString> cData =
59 JSObject()->TryCData(XFA_Attribute::ContentType, false);
60 if (!cData.has_value())
61 return Type::Formcalc;
62 if (cData.value().EqualsASCII("application/x-formcalc"))
63 return Type::Formcalc;
64 if (cData.value().EqualsASCII("application/x-javascript"))
65 return Type::Javascript;
66 return Type::Unknown;
67}
68
70 return JSObject()->GetEnum(XFA_Attribute::RunAt);
71}
72
73WideString CXFA_Script::GetExpression() {
74 return JSObject()->GetContent(false);
75}
XFA_Element GetElementType() const
Definition cxfa_object.h:91
static CXFA_Script * FromNode(CXFA_Node *pNode)
XFA_AttributeValue GetRunAt()
Type GetContentType()
~CXFA_Script() override
WideString GetExpression()
XFA_AttributeType
Definition fxfa_basic.h:83
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
XFA_PacketType
Definition fxfa_basic.h:44