1 // Copyright 2016 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_object.h"
8
9 #include <utility>
10
11 #include "core/fxcrt/fx_extension.h"
12 #include "fxjs/cfxjse_engine.h"
13 #include "fxjs/cfxjse_value.h"
14 #include "third_party/base/ptr_util.h"
15 #include "xfa/fxfa/cxfa_ffnotify.h"
16 #include "xfa/fxfa/parser/cxfa_document.h"
17 #include "xfa/fxfa/parser/cxfa_node.h"
18 #include "xfa/fxfa/parser/cxfa_treelist.h"
19
CXFA_Object(CXFA_Document * pDocument,XFA_ObjectType objectType,XFA_Element elementType,const WideStringView & elementName,std::unique_ptr<CJX_Object> jsObject)20 CXFA_Object::CXFA_Object(CXFA_Document* pDocument,
21 XFA_ObjectType objectType,
22 XFA_Element elementType,
23 const WideStringView& elementName,
24 std::unique_ptr<CJX_Object> jsObject)
25 : CFXJSE_HostObject(kXFA),
26 m_pDocument(pDocument),
27 m_objectType(objectType),
28 m_elementType(elementType),
29 m_elementNameHash(FX_HashCode_GetW(elementName, false)),
30 m_elementName(elementName),
31 m_pJSObject(std::move(jsObject)) {}
32
~CXFA_Object()33 CXFA_Object::~CXFA_Object() {}
34
GetSOMExpression()35 WideString CXFA_Object::GetSOMExpression() {
36 CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
37 if (!pScriptContext)
38 return WideString();
39
40 return pScriptContext->GetSomExpression(ToNode(this));
41 }
42
AsNode()43 CXFA_Node* CXFA_Object::AsNode() {
44 return IsNode() ? static_cast<CXFA_Node*>(this) : nullptr;
45 }
46
AsTreeList()47 CXFA_TreeList* CXFA_Object::AsTreeList() {
48 return IsTreeList() ? static_cast<CXFA_TreeList*>(this) : nullptr;
49 }
50
AsNode() const51 const CXFA_Node* CXFA_Object::AsNode() const {
52 return IsNode() ? static_cast<const CXFA_Node*>(this) : nullptr;
53 }
54
AsTreeList() const55 const CXFA_TreeList* CXFA_Object::AsTreeList() const {
56 return IsTreeList() ? static_cast<const CXFA_TreeList*>(this) : nullptr;
57 }
58
CreateWidgetAcc()59 void CXFA_Object::CreateWidgetAcc() {
60 acc_ = pdfium::MakeUnique<CXFA_WidgetAcc>(AsNode());
61 }
62
ToNode(CXFA_Object * pObj)63 CXFA_Node* ToNode(CXFA_Object* pObj) {
64 return pObj ? pObj->AsNode() : nullptr;
65 }
66
ToNode(const CXFA_Object * pObj)67 const CXFA_Node* ToNode(const CXFA_Object* pObj) {
68 return pObj ? pObj->AsNode() : nullptr;
69 }
70