xref: /aosp_15_r20/external/pdfium/xfa/fxfa/parser/cxfa_button.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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_button.h"
8 
9 #include "fxjs/xfa/cjx_node.h"
10 #include "xfa/fxfa/parser/cxfa_document.h"
11 
12 namespace {
13 
14 const CXFA_Node::PropertyData kButtonPropertyData[] = {
15     {XFA_Element::Extras, 1, {}},
16 };
17 
18 const CXFA_Node::AttributeData kButtonAttributeData[] = {
19     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
20     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
21     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
22     {XFA_Attribute::Highlight, XFA_AttributeType::Enum,
23      (void*)XFA_AttributeValue::Inverted},
24 };
25 
26 }  // namespace
27 
28 // static
FromNode(CXFA_Node * pNode)29 CXFA_Button* CXFA_Button::FromNode(CXFA_Node* pNode) {
30   return pNode && pNode->GetElementType() == XFA_Element::Button
31              ? static_cast<CXFA_Button*>(pNode)
32              : nullptr;
33 }
34 
CXFA_Button(CXFA_Document * doc,XFA_PacketType packet)35 CXFA_Button::CXFA_Button(CXFA_Document* doc, XFA_PacketType packet)
36     : CXFA_Node(doc,
37                 packet,
38                 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
39                 XFA_ObjectType::Node,
40                 XFA_Element::Button,
41                 kButtonPropertyData,
42                 kButtonAttributeData,
43                 cppgc::MakeGarbageCollected<CJX_Node>(
44                     doc->GetHeap()->GetAllocationHandle(),
45                     this)) {}
46 
47 CXFA_Button::~CXFA_Button() = default;
48 
GetDefaultFFWidgetType() const49 XFA_FFWidgetType CXFA_Button::GetDefaultFFWidgetType() const {
50   return XFA_FFWidgetType::kButton;
51 }
52 
GetHighlight()53 XFA_AttributeValue CXFA_Button::GetHighlight() {
54   return JSObject()->GetEnum(XFA_Attribute::Highlight);
55 }
56