• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_value.h"
8 
9 #include "fxjs/xfa/cjx_node.h"
10 #include "fxjs/xfa/cjx_object.h"
11 #include "xfa/fxfa/parser/cxfa_arc.h"
12 #include "xfa/fxfa/parser/cxfa_document.h"
13 #include "xfa/fxfa/parser/cxfa_exdata.h"
14 #include "xfa/fxfa/parser/cxfa_image.h"
15 #include "xfa/fxfa/parser/cxfa_line.h"
16 #include "xfa/fxfa/parser/cxfa_rectangle.h"
17 
18 namespace {
19 
20 constexpr CXFA_Node::PropertyData kValuePropertyData[] = {
21     {XFA_Element::Arc, 1, XFA_PropertyFlag::kOneOf},
22     {XFA_Element::Text, 1, XFA_PropertyFlag::kOneOf},
23     {XFA_Element::Time, 1, XFA_PropertyFlag::kOneOf},
24     {XFA_Element::DateTime, 1, XFA_PropertyFlag::kOneOf},
25     {XFA_Element::Image, 1, XFA_PropertyFlag::kOneOf},
26     {XFA_Element::Decimal, 1, XFA_PropertyFlag::kOneOf},
27     {XFA_Element::Boolean, 1, XFA_PropertyFlag::kOneOf},
28     {XFA_Element::Integer, 1, XFA_PropertyFlag::kOneOf},
29     {XFA_Element::ExData, 1, XFA_PropertyFlag::kOneOf},
30     {XFA_Element::Rectangle, 1, XFA_PropertyFlag::kOneOf},
31     {XFA_Element::Date, 1, XFA_PropertyFlag::kOneOf},
32     {XFA_Element::Float, 1, XFA_PropertyFlag::kOneOf},
33     {XFA_Element::Line, 1, XFA_PropertyFlag::kOneOf},
34 };
35 
36 constexpr CXFA_Node::AttributeData kValueAttributeData[] = {
37     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
38     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
39     {XFA_Attribute::Relevant, XFA_AttributeType::CData, nullptr},
40     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
41     {XFA_Attribute::Override, XFA_AttributeType::Boolean, (void*)0},
42 };
43 
44 }  // namespace
45 
CXFA_Value(CXFA_Document * doc,XFA_PacketType packet)46 CXFA_Value::CXFA_Value(CXFA_Document* doc, XFA_PacketType packet)
47     : CXFA_Node(doc,
48                 packet,
49                 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
50                 XFA_ObjectType::Node,
51                 XFA_Element::Value,
52                 kValuePropertyData,
53                 kValueAttributeData,
54                 cppgc::MakeGarbageCollected<CJX_Node>(
55                     doc->GetHeap()->GetAllocationHandle(),
56                     this)) {}
57 
58 CXFA_Value::~CXFA_Value() = default;
59 
GetChildValueClassID() const60 XFA_Element CXFA_Value::GetChildValueClassID() const {
61   CXFA_Node* pNode = GetFirstChild();
62   return pNode ? pNode->GetElementType() : XFA_Element::Unknown;
63 }
64 
GetChildValueContent() const65 WideString CXFA_Value::GetChildValueContent() const {
66   CXFA_Node* pNode = GetFirstChild();
67   return pNode
68              ? pNode->JSObject()->TryContent(false, true).value_or(WideString())
69              : WideString();
70 }
71 
GetArcIfExists() const72 CXFA_Arc* CXFA_Value::GetArcIfExists() const {
73   return CXFA_Arc::FromNode(GetFirstChild());
74 }
75 
GetLineIfExists() const76 CXFA_Line* CXFA_Value::GetLineIfExists() const {
77   return CXFA_Line::FromNode(GetFirstChild());
78 }
79 
GetRectangleIfExists() const80 CXFA_Rectangle* CXFA_Value::GetRectangleIfExists() const {
81   return CXFA_Rectangle::FromNode(GetFirstChild());
82 }
83 
GetTextIfExists() const84 CXFA_Text* CXFA_Value::GetTextIfExists() const {
85   return CXFA_Text::FromNode(GetFirstChild());
86 }
87 
GetExDataIfExists() const88 CXFA_ExData* CXFA_Value::GetExDataIfExists() const {
89   return CXFA_ExData::FromNode(GetFirstChild());
90 }
91 
GetImageIfExists() const92 CXFA_Image* CXFA_Value::GetImageIfExists() const {
93   return CXFA_Image::FromNode(GetFirstChild());
94 }
95