• 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_node.h"
10 #include "fxjs/xfa/cjx_object.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 kValuePropertyData[] = {
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 };
35 
36 const 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_Template | XFA_XDPPACKET_Form),
50                 XFA_ObjectType::Node,
51                 XFA_Element::Value,
52                 kValuePropertyData,
53                 kValueAttributeData,
54                 pdfium::MakeUnique<CJX_Node>(this)) {}
55 
56 CXFA_Value::~CXFA_Value() = default;
57 
GetChildValueClassID() const58 XFA_Element CXFA_Value::GetChildValueClassID() const {
59   CXFA_Node* pNode = GetFirstChild();
60   return pNode ? pNode->GetElementType() : XFA_Element::Unknown;
61 }
62 
GetChildValueContent() const63 WideString CXFA_Value::GetChildValueContent() const {
64   CXFA_Node* pNode = GetFirstChild();
65   return pNode
66              ? pNode->JSObject()->TryContent(false, true).value_or(WideString())
67              : WideString();
68 }
69 
GetArcIfExists() const70 CXFA_Arc* CXFA_Value::GetArcIfExists() const {
71   CXFA_Node* node = GetFirstChild();
72   if (!node || node->GetElementType() != XFA_Element::Arc)
73     return nullptr;
74   return static_cast<CXFA_Arc*>(node);
75 }
76 
GetLineIfExists() const77 CXFA_Line* CXFA_Value::GetLineIfExists() const {
78   CXFA_Node* node = GetFirstChild();
79   if (!node || node->GetElementType() != XFA_Element::Line)
80     return nullptr;
81   return static_cast<CXFA_Line*>(node);
82 }
83 
GetRectangleIfExists() const84 CXFA_Rectangle* CXFA_Value::GetRectangleIfExists() const {
85   CXFA_Node* node = GetFirstChild();
86   if (!node || node->GetElementType() != XFA_Element::Rectangle)
87     return nullptr;
88   return static_cast<CXFA_Rectangle*>(node);
89 }
90 
GetTextIfExists() const91 CXFA_Text* CXFA_Value::GetTextIfExists() const {
92   CXFA_Node* node = GetFirstChild();
93   if (!node || node->GetElementType() != XFA_Element::Text)
94     return nullptr;
95   return static_cast<CXFA_Text*>(node);
96 }
97 
GetExDataIfExists() const98 CXFA_ExData* CXFA_Value::GetExDataIfExists() const {
99   CXFA_Node* node = GetFirstChild();
100   if (!node || node->GetElementType() != XFA_Element::ExData)
101     return nullptr;
102   return static_cast<CXFA_ExData*>(node);
103 }
104 
GetImageIfExists() const105 CXFA_Image* CXFA_Value::GetImageIfExists() const {
106   CXFA_Node* node = GetFirstChild();
107   if (!node || node->GetElementType() != XFA_Element::Image)
108     return nullptr;
109   return static_cast<CXFA_Image*>(node);
110 }
111