• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_event.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 kPropertyData[] = {
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     {XFA_Element::Unknown, 0, 0}};
23 const CXFA_Node::AttributeData kAttributeData[] = {
24     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
25     {XFA_Attribute::Name, XFA_AttributeType::CData, nullptr},
26     {XFA_Attribute::Ref, XFA_AttributeType::CData, nullptr},
27     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
28     {XFA_Attribute::Listen, XFA_AttributeType::Enum,
29      (void*)XFA_AttributeEnum::RefOnly},
30     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
31     {XFA_Attribute::Activity, XFA_AttributeType::Enum,
32      (void*)XFA_AttributeEnum::Click},
33     {XFA_Attribute::Unknown, XFA_AttributeType::Integer, nullptr}};
34 
35 constexpr wchar_t kName[] = L"event";
36 
37 }  // namespace
38 
CXFA_Event(CXFA_Document * doc,XFA_PacketType packet)39 CXFA_Event::CXFA_Event(CXFA_Document* doc, XFA_PacketType packet)
40     : CXFA_Node(doc,
41                 packet,
42                 (XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
43                 XFA_ObjectType::Node,
44                 XFA_Element::Event,
45                 kPropertyData,
46                 kAttributeData,
47                 kName,
48                 pdfium::MakeUnique<CJX_Event>(this)) {}
49 
~CXFA_Event()50 CXFA_Event::~CXFA_Event() {}
51 
GetActivity()52 XFA_AttributeEnum 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 
GetSubmitIfExists()76 CXFA_Submit* CXFA_Event::GetSubmitIfExists() {
77   return GetChild<CXFA_Submit>(0, XFA_Element::Submit, false);
78 }
79