1 // Copyright 2016 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_object.h"
8
9 #include "core/fxcrt/fx_extension.h"
10 #include "fxjs/xfa/cfxjse_engine.h"
11 #include "fxjs/xfa/cfxjse_value.h"
12 #include "fxjs/xfa/cjx_object.h"
13 #include "xfa/fxfa/cxfa_ffnotify.h"
14 #include "xfa/fxfa/parser/cxfa_document.h"
15 #include "xfa/fxfa/parser/cxfa_node.h"
16 #include "xfa/fxfa/parser/cxfa_thisproxy.h"
17 #include "xfa/fxfa/parser/cxfa_treelist.h"
18 #include "xfa/fxfa/parser/xfa_basic_data.h"
19
CXFA_Object(CXFA_Document * pDocument,XFA_ObjectType objectType,XFA_Element elementType,CJX_Object * jsObject)20 CXFA_Object::CXFA_Object(CXFA_Document* pDocument,
21 XFA_ObjectType objectType,
22 XFA_Element elementType,
23 CJX_Object* jsObject)
24 : m_objectType(objectType),
25 m_elementType(elementType),
26 m_elementName(XFA_ElementToName(elementType)),
27 m_elementNameHash(FX_HashCode_GetAsIfW(m_elementName)),
28 m_pDocument(pDocument),
29 m_pJSObject(jsObject) {}
30
31 CXFA_Object::~CXFA_Object() = default;
32
Trace(cppgc::Visitor * visitor) const33 void CXFA_Object::Trace(cppgc::Visitor* visitor) const {
34 visitor->Trace(m_pDocument);
35 visitor->Trace(m_pJSObject);
36 }
37
GetSOMExpression()38 WideString CXFA_Object::GetSOMExpression() {
39 CXFA_Node* pNode = AsNode();
40 return pNode ? pNode->GetNameExpression() : WideString();
41 }
42
AsList()43 CXFA_List* CXFA_Object::AsList() {
44 return IsList() ? static_cast<CXFA_List*>(this) : nullptr;
45 }
46
AsNode()47 CXFA_Node* CXFA_Object::AsNode() {
48 return IsNode() ? static_cast<CXFA_Node*>(this) : nullptr;
49 }
50
AsTreeList()51 CXFA_TreeList* CXFA_Object::AsTreeList() {
52 return IsTreeList() ? static_cast<CXFA_TreeList*>(this) : nullptr;
53 }
54
AsThisProxy()55 CXFA_ThisProxy* CXFA_Object::AsThisProxy() {
56 return IsThisProxy() ? static_cast<CXFA_ThisProxy*>(this) : nullptr;
57 }
58
ToList(CXFA_Object * pObj)59 CXFA_List* ToList(CXFA_Object* pObj) {
60 return pObj ? pObj->AsList() : nullptr;
61 }
62
ToNode(CXFA_Object * pObj)63 CXFA_Node* ToNode(CXFA_Object* pObj) {
64 return pObj ? pObj->AsNode() : nullptr;
65 }
66
ToTreeList(CXFA_Object * pObj)67 CXFA_TreeList* ToTreeList(CXFA_Object* pObj) {
68 return pObj ? pObj->AsTreeList() : nullptr;
69 }
70
ToThisProxy(CXFA_Object * pObj)71 CXFA_ThisProxy* ToThisProxy(CXFA_Object* pObj) {
72 return pObj ? pObj->AsThisProxy() : nullptr;
73 }
74