• 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_value.h"
8 
9 #include "fxjs/xfa/cjx_object.h"
10 #include "fxjs/xfa/cjx_value.h"
11 #include "third_party/base/ptr_util.h"
12 #include "xfa/fxfa/parser/cxfa_arc.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 const CXFA_Node::PropertyData kPropertyData[] = {
21     {XFA_Element::Arc, 1, XFA_PROPERTYFLAG_OneOf},
22     {XFA_Element::Text, 1, XFA_PROPERTYFLAG_OneOf},
23     {XFA_Element::Time, 1, XFA_PROPERTYFLAG_OneOf},
24     {XFA_Element::DateTime, 1, XFA_PROPERTYFLAG_OneOf},
25     {XFA_Element::Image, 1, XFA_PROPERTYFLAG_OneOf},
26     {XFA_Element::Decimal, 1, XFA_PROPERTYFLAG_OneOf},
27     {XFA_Element::Boolean, 1, XFA_PROPERTYFLAG_OneOf},
28     {XFA_Element::Integer, 1, XFA_PROPERTYFLAG_OneOf},
29     {XFA_Element::ExData, 1, XFA_PROPERTYFLAG_OneOf},
30     {XFA_Element::Rectangle, 1, XFA_PROPERTYFLAG_OneOf},
31     {XFA_Element::Date, 1, XFA_PROPERTYFLAG_OneOf},
32     {XFA_Element::Float, 1, XFA_PROPERTYFLAG_OneOf},
33     {XFA_Element::Line, 1, XFA_PROPERTYFLAG_OneOf},
34     {XFA_Element::Unknown, 0, 0}};
35 const CXFA_Node::AttributeData kAttributeData[] = {
36     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
37     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
38     {XFA_Attribute::Relevant, XFA_AttributeType::CData, nullptr},
39     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
40     {XFA_Attribute::Override, XFA_AttributeType::Boolean, (void*)0},
41     {XFA_Attribute::Unknown, XFA_AttributeType::Integer, nullptr}};
42 
43 constexpr wchar_t kName[] = L"value";
44 
45 }  // namespace
46 
CXFA_Value(CXFA_Document * doc,XFA_PacketType packet)47 CXFA_Value::CXFA_Value(CXFA_Document* doc, XFA_PacketType packet)
48     : CXFA_Node(doc,
49                 packet,
50                 (XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
51                 XFA_ObjectType::Node,
52                 XFA_Element::Value,
53                 kPropertyData,
54                 kAttributeData,
55                 kName,
56                 pdfium::MakeUnique<CJX_Value>(this)) {}
57 
~CXFA_Value()58 CXFA_Value::~CXFA_Value() {}
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 ? pNode->JSObject()->TryContent(false, true).value_or(L"") : L"";
68 }
69 
GetArcIfExists() const70 CXFA_Arc* CXFA_Value::GetArcIfExists() const {
71   CXFA_Node* node = GetFirstChild();
72   ASSERT(!node || node->GetElementType() == XFA_Element::Arc);
73   return static_cast<CXFA_Arc*>(node);
74 }
75 
GetLineIfExists() const76 CXFA_Line* CXFA_Value::GetLineIfExists() const {
77   CXFA_Node* node = GetFirstChild();
78   ASSERT(!node || node->GetElementType() == XFA_Element::Line);
79   return static_cast<CXFA_Line*>(node);
80 }
81 
GetRectangleIfExists() const82 CXFA_Rectangle* CXFA_Value::GetRectangleIfExists() const {
83   CXFA_Node* node = GetFirstChild();
84   ASSERT(!node || node->GetElementType() == XFA_Element::Rectangle);
85   return static_cast<CXFA_Rectangle*>(node);
86 }
87 
GetTextIfExists() const88 CXFA_Text* CXFA_Value::GetTextIfExists() const {
89   CXFA_Node* node = GetFirstChild();
90   ASSERT(!node || node->GetElementType() == XFA_Element::Text);
91   return static_cast<CXFA_Text*>(node);
92 }
93 
GetExDataIfExists() const94 CXFA_ExData* CXFA_Value::GetExDataIfExists() const {
95   CXFA_Node* node = GetFirstChild();
96   ASSERT(!node || node->GetElementType() == XFA_Element::ExData);
97   return static_cast<CXFA_ExData*>(node);
98 }
99 
GetImageIfExists() const100 CXFA_Image* CXFA_Value::GetImageIfExists() const {
101   CXFA_Node* node = GetFirstChild();
102   ASSERT(!node || node->GetElementType() == XFA_Element::Image);
103   return static_cast<CXFA_Image*>(node);
104 }
105