Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjx_subform.cpp
Go to the documentation of this file.
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 "fxjs/xfa/cjx_subform.h"
8
9#include <vector>
10
11#include "fxjs/cfx_v8.h"
12#include "fxjs/fxv8.h"
13#include "fxjs/js_resources.h"
14#include "fxjs/xfa/cfxjse_engine.h"
15#include "third_party/base/containers/span.h"
16#include "v8/include/v8-object.h"
17#include "xfa/fxfa/cxfa_eventparam.h"
18#include "xfa/fxfa/cxfa_ffnotify.h"
19#include "xfa/fxfa/fxfa.h"
20#include "xfa/fxfa/parser/cxfa_delta.h"
21#include "xfa/fxfa/parser/cxfa_document.h"
22
23const CJX_MethodSpec CJX_Subform::MethodSpecs[] = {
24 {"execCalculate", execCalculate_static},
25 {"execEvent", execEvent_static},
26 {"execInitialize", execInitialize_static},
27 {"execValidate", execValidate_static}};
28
29CJX_Subform::CJX_Subform(CXFA_Node* node) : CJX_Container(node) {
30 DefineMethods(MethodSpecs);
31}
32
33CJX_Subform::~CJX_Subform() = default;
34
35bool CJX_Subform::DynamicTypeIs(TypeTag eType) const {
36 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
37}
38
39CJS_Result CJX_Subform::execEvent(CFXJSE_Engine* runtime,
40 pdfium::span<v8::Local<v8::Value>> params) {
41 if (params.size() != 1)
43
44 execSingleEventByName(runtime->ToWideString(params[0]).AsStringView(),
45 XFA_Element::Subform);
47}
48
49CJS_Result CJX_Subform::execInitialize(
50 CFXJSE_Engine* runtime,
51 pdfium::span<v8::Local<v8::Value>> params) {
52 if (!params.empty())
54
55 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
56 if (pNotify)
58 true);
60}
61
62CJS_Result CJX_Subform::execCalculate(
63 CFXJSE_Engine* runtime,
64 pdfium::span<v8::Local<v8::Value>> params) {
65 if (!params.empty())
67
68 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
69 if (pNotify)
71 true);
73}
74
75CJS_Result CJX_Subform::execValidate(
76 CFXJSE_Engine* runtime,
77 pdfium::span<v8::Local<v8::Value>> params) {
78 if (!params.empty())
80
81 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
82 if (!pNotify)
83 return CJS_Result::Success(runtime->NewBoolean(false));
84
88 runtime->NewBoolean(iRet != XFA_EventError::kError));
89}
90
91void CJX_Subform::locale(v8::Isolate* pIsolate,
92 v8::Local<v8::Value>* pValue,
93 bool bSetting,
94 XFA_Attribute eAttribute) {
95 if (bSetting) {
97 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue), true,
98 true);
99 return;
100 }
101
102 WideString wsLocaleName = GetXFANode()->GetLocaleName().value_or(L"");
103 *pValue =
104 fxv8::NewStringHelper(pIsolate, wsLocaleName.ToUTF8().AsStringView());
105}
106
107void CJX_Subform::instanceManager(v8::Isolate* pIsolate,
108 v8::Local<v8::Value>* pValue,
109 bool bSetting,
110 XFA_Attribute eAttribute) {
111 if (bSetting) {
113 return;
114 }
115
116 WideString wsName = GetCData(XFA_Attribute::Name);
117 CXFA_Node* pInstanceMgr = nullptr;
118 for (CXFA_Node* pNode = GetXFANode()->GetPrevSibling(); pNode;
119 pNode = pNode->GetPrevSibling()) {
120 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
121 WideString wsInstMgrName =
122 pNode->JSObject()->GetCData(XFA_Attribute::Name);
123 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' &&
124 wsInstMgrName.Last(wsInstMgrName.GetLength() - 1) == wsName) {
125 pInstanceMgr = pNode;
126 }
127 break;
128 }
129 }
130 *pValue = pInstanceMgr ? GetDocument()
131 ->GetScriptContext()
132 ->GetOrCreateJSBindingFromMap(pInstanceMgr)
133 .As<v8::Value>()
134 : fxv8::NewNullHelper(pIsolate).As<v8::Value>();
135}
friend class EventParamScope
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
bool DynamicTypeIs(TypeTag eType) const override
CJX_Container(CXFA_Node *node)
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
void SetCDataImpl(XFA_Attribute eAttr, const WideString &wsValue, bool bNotify, bool bScriptModify)
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
CXFA_Document * GetDocument() const
WideString GetCData(XFA_Attribute eAttr) const
CXFA_Node * GetXFANode() const
~CJX_Subform() override
bool DynamicTypeIs(TypeTag eType) const override
XFA_EventError ExecEventByDeepFirst(CXFA_Node *pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, bool bRecursive)
XFA_Element GetElementType() const
Definition cxfa_object.h:91
ByteString ToUTF8() const
CharType operator[](const size_t index) const
Definition widestring.h:146
@ XFA_EVENT_Initialize
@ XFA_EVENT_Calculate
@ XFA_EVENT_Validate
XFA_EventError
Definition fxfa.h:54
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
JSMessage