1 // Copyright 2017 PDFium Authors. All rights reserved.
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 "third_party/base/ptr_util.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_OneOf},
18 {XFA_Element::Script, 1, XFA_PROPERTYFLAG_OneOf},
19 {XFA_Element::SignData, 1, XFA_PROPERTYFLAG_OneOf},
20 {XFA_Element::Extras, 1, 0},
21 {XFA_Element::Submit, 1, XFA_PROPERTYFLAG_OneOf},
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_Template | XFA_XDPPACKET_Form),
42 XFA_ObjectType::Node,
43 XFA_Element::Event,
44 kEventPropertyData,
45 kEventAttributeData,
46 pdfium::MakeUnique<CJX_Node>(this)) {}
47
48 CXFA_Event::~CXFA_Event() = default;
49
GetActivity()50 XFA_AttributeValue CXFA_Event::GetActivity() {
51 return JSObject()->GetEnum(XFA_Attribute::Activity);
52 }
53
GetEventType() const54 XFA_Element CXFA_Event::GetEventType() const {
55 CXFA_Node* pChild = GetFirstChild();
56 while (pChild) {
57 XFA_Element eType = pChild->GetElementType();
58 if (eType != XFA_Element::Extras)
59 return eType;
60
61 pChild = pChild->GetNextSibling();
62 }
63 return XFA_Element::Unknown;
64 }
65
GetRef()66 WideString CXFA_Event::GetRef() {
67 return JSObject()->GetCData(XFA_Attribute::Ref);
68 }
69
GetScriptIfExists()70 CXFA_Script* CXFA_Event::GetScriptIfExists() {
71 return GetChild<CXFA_Script>(0, XFA_Element::Script, false);
72 }
73
74 #ifdef PDF_XFA_ELEMENT_SUBMIT_ENABLED
GetSubmitIfExists()75 CXFA_Submit* CXFA_Event::GetSubmitIfExists() {
76 return GetChild<CXFA_Submit>(0, XFA_Element::Submit, false);
77 }
78 #endif // PDF_XFA_ELEMENT_SUBMIT_ENABLED
79