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_event.h"
8
9 #include "fxjs/xfa/cjx_node.h"
10 #include "xfa/fxfa/parser/cxfa_document.h"
11 #include "xfa/fxfa/parser/cxfa_script.h"
12 #include "xfa/fxfa/parser/cxfa_submit.h"
13
14 namespace {
15
16 const CXFA_Node::PropertyData kEventPropertyData[] = {
17 {XFA_Element::Execute, 1, XFA_PropertyFlag::kOneOf},
18 {XFA_Element::Script, 1, XFA_PropertyFlag::kOneOf},
19 {XFA_Element::SignData, 1, XFA_PropertyFlag::kOneOf},
20 {XFA_Element::Extras, 1, {}},
21 {XFA_Element::Submit, 1, XFA_PropertyFlag::kOneOf},
22 };
23
24 const CXFA_Node::AttributeData kEventAttributeData[] = {
25 {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
26 {XFA_Attribute::Name, XFA_AttributeType::CData, nullptr},
27 {XFA_Attribute::Ref, XFA_AttributeType::CData, nullptr},
28 {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
29 {XFA_Attribute::Listen, XFA_AttributeType::Enum,
30 (void*)XFA_AttributeValue::RefOnly},
31 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
32 {XFA_Attribute::Activity, XFA_AttributeType::Enum,
33 (void*)XFA_AttributeValue::Click},
34 };
35
36 } // namespace
37
CXFA_Event(CXFA_Document * doc,XFA_PacketType packet)38 CXFA_Event::CXFA_Event(CXFA_Document* doc, XFA_PacketType packet)
39 : CXFA_Node(doc,
40 packet,
41 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
42 XFA_ObjectType::Node,
43 XFA_Element::Event,
44 kEventPropertyData,
45 kEventAttributeData,
46 cppgc::MakeGarbageCollected<CJX_Node>(
47 doc->GetHeap()->GetAllocationHandle(),
48 this)) {}
49
50 CXFA_Event::~CXFA_Event() = default;
51
GetActivity()52 XFA_AttributeValue CXFA_Event::GetActivity() {
53 return JSObject()->GetEnum(XFA_Attribute::Activity);
54 }
55
GetEventType() const56 XFA_Element CXFA_Event::GetEventType() const {
57 CXFA_Node* pChild = GetFirstChild();
58 while (pChild) {
59 XFA_Element eType = pChild->GetElementType();
60 if (eType != XFA_Element::Extras)
61 return eType;
62
63 pChild = pChild->GetNextSibling();
64 }
65 return XFA_Element::Unknown;
66 }
67
GetRef()68 WideString CXFA_Event::GetRef() {
69 return JSObject()->GetCData(XFA_Attribute::Ref);
70 }
71
GetScriptIfExists()72 CXFA_Script* CXFA_Event::GetScriptIfExists() {
73 return GetChild<CXFA_Script>(0, XFA_Element::Script, false);
74 }
75
76 #ifdef PDF_XFA_ELEMENT_SUBMIT_ENABLED
GetSubmitIfExists()77 CXFA_Submit* CXFA_Event::GetSubmitIfExists() {
78 return GetChild<CXFA_Submit>(0, XFA_Element::Submit, false);
79 }
80 #endif // PDF_XFA_ELEMENT_SUBMIT_ENABLED
81