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 "core/fxcrt/span.h"
10#include "fxjs/cfx_v8.h"
11#include "fxjs/fxv8.h"
12#include "fxjs/js_resources.h"
13#include "fxjs/xfa/cfxjse_engine.h"
14#include "v8/include/v8-object.h"
15#include "xfa/fxfa/cxfa_eventparam.h"
16#include "xfa/fxfa/cxfa_ffnotify.h"
17#include "xfa/fxfa/fxfa.h"
18#include "xfa/fxfa/parser/cxfa_delta.h"
19#include "xfa/fxfa/parser/cxfa_document.h"
20
21const CJX_MethodSpec CJX_Subform::MethodSpecs[] = {
22 {"execCalculate", execCalculate_static},
23 {"execEvent", execEvent_static},
24 {"execInitialize", execInitialize_static},
25 {"execValidate", execValidate_static}};
26
27CJX_Subform::CJX_Subform(CXFA_Node* node) : CJX_Container(node) {
28 DefineMethods(MethodSpecs);
29}
30
31CJX_Subform::~CJX_Subform() = default;
32
33bool CJX_Subform::DynamicTypeIs(TypeTag eType) const {
34 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
35}
36
37CJS_Result CJX_Subform::execEvent(CFXJSE_Engine* runtime,
38 pdfium::span<v8::Local<v8::Value>> params) {
39 if (params.size() != 1)
41
42 execSingleEventByName(runtime->ToWideString(params[0]).AsStringView(),
43 XFA_Element::Subform);
45}
46
47CJS_Result CJX_Subform::execInitialize(
48 CFXJSE_Engine* runtime,
49 pdfium::span<v8::Local<v8::Value>> params) {
50 if (!params.empty())
52
53 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
54 if (pNotify)
56 true);
58}
59
60CJS_Result CJX_Subform::execCalculate(
61 CFXJSE_Engine* runtime,
62 pdfium::span<v8::Local<v8::Value>> params) {
63 if (!params.empty())
65
66 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
67 if (pNotify)
69 true);
71}
72
73CJS_Result CJX_Subform::execValidate(
74 CFXJSE_Engine* runtime,
75 pdfium::span<v8::Local<v8::Value>> params) {
76 if (!params.empty())
78
79 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
80 if (!pNotify)
81 return CJS_Result::Success(runtime->NewBoolean(false));
82
86 runtime->NewBoolean(iRet != XFA_EventError::kError));
87}
88
89void CJX_Subform::locale(v8::Isolate* pIsolate,
90 v8::Local<v8::Value>* pValue,
91 bool bSetting,
92 XFA_Attribute eAttribute) {
93 if (bSetting) {
95 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue), true,
96 true);
97 return;
98 }
99
100 WideString wsLocaleName = GetXFANode()->GetLocaleName().value_or(L"");
101 *pValue =
102 fxv8::NewStringHelper(pIsolate, wsLocaleName.ToUTF8().AsStringView());
103}
104
105void CJX_Subform::instanceManager(v8::Isolate* pIsolate,
106 v8::Local<v8::Value>* pValue,
107 bool bSetting,
108 XFA_Attribute eAttribute) {
109 if (bSetting) {
111 return;
112 }
113
114 WideString wsName = GetCData(XFA_Attribute::Name);
115 CXFA_Node* pInstanceMgr = nullptr;
116 for (CXFA_Node* pNode = GetXFANode()->GetPrevSibling(); pNode;
117 pNode = pNode->GetPrevSibling()) {
118 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
119 WideString wsInstMgrName =
120 pNode->JSObject()->GetCData(XFA_Attribute::Name);
121 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName[0] == '_' &&
122 wsInstMgrName.Last(wsInstMgrName.GetLength() - 1) == wsName) {
123 pInstanceMgr = pNode;
124 }
125 break;
126 }
127 }
128 *pValue = pInstanceMgr ? GetDocument()
129 ->GetScriptContext()
130 ->GetOrCreateJSBindingFromMap(pInstanceMgr)
131 .As<v8::Value>()
132 : fxv8::NewNullHelper(pIsolate).As<v8::Value>();
133}
friend class EventParamScope
static CJS_Result Success()
Definition cjs_result.h:28
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:35
bool DynamicTypeIs(TypeTag eType) const override
CJX_Container(CXFA_Node *node)
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
@ 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
fxcrt::WideString WideString
Definition widestring.h:207