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_exclgroup.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_exclgroup.h"
8
9#include <vector>
10
11#include "fxjs/fxv8.h"
12#include "fxjs/js_resources.h"
13#include "fxjs/xfa/cfxjse_engine.h"
14#include "third_party/base/containers/span.h"
15#include "v8/include/v8-object.h"
16#include "v8/include/v8-primitive.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_document.h"
21#include "xfa/fxfa/parser/cxfa_exclgroup.h"
22
23const CJX_MethodSpec CJX_ExclGroup::MethodSpecs[] = {
24 {"execCalculate", execCalculate_static},
25 {"execEvent", execEvent_static},
26 {"execInitialize", execInitialize_static},
27 {"execValidate", execValidate_static},
28 {"selectedMember", selectedMember_static}};
29
30CJX_ExclGroup::CJX_ExclGroup(CXFA_ExclGroup* group) : CJX_Node(group) {
31 DefineMethods(MethodSpecs);
32}
33
34CJX_ExclGroup::~CJX_ExclGroup() = default;
35
36bool CJX_ExclGroup::DynamicTypeIs(TypeTag eType) const {
37 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
38}
39
40CJS_Result CJX_ExclGroup::execEvent(CFXJSE_Engine* runtime,
41 pdfium::span<v8::Local<v8::Value>> params) {
42 if (params.size() != 1)
44
45 execSingleEventByName(runtime->ToWideString(params[0]).AsStringView(),
46 XFA_Element::ExclGroup);
48}
49
50CJS_Result CJX_ExclGroup::execInitialize(
51 CFXJSE_Engine* runtime,
52 pdfium::span<v8::Local<v8::Value>> params) {
53 if (!params.empty())
55
56 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
57 if (pNotify)
59 true);
61}
62
63CJS_Result CJX_ExclGroup::execCalculate(
64 CFXJSE_Engine* runtime,
65 pdfium::span<v8::Local<v8::Value>> params) {
66 if (!params.empty())
68
69 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
70 if (pNotify)
72 true);
74}
75
76CJS_Result CJX_ExclGroup::execValidate(
77 CFXJSE_Engine* runtime,
78 pdfium::span<v8::Local<v8::Value>> params) {
79 if (!params.empty())
81
82 CXFA_FFNotify* notify = GetDocument()->GetNotify();
83 if (!notify)
84 return CJS_Result::Success(runtime->NewBoolean(false));
85
89 runtime->NewBoolean(iRet != XFA_EventError::kError));
90}
91
92CJS_Result CJX_ExclGroup::selectedMember(
93 CFXJSE_Engine* runtime,
94 pdfium::span<v8::Local<v8::Value>> params) {
95 if (!params.empty())
97
98 CXFA_Node* node = GetXFANode();
99 if (!node->IsWidgetReady())
100 return CJS_Result::Success(runtime->NewNull());
101
102 CXFA_Node* pReturnNode = nullptr;
103 if (params.empty()) {
104 pReturnNode = node->GetSelectedMember();
105 } else {
106 pReturnNode = node->SetSelectedMember(
107 runtime->ToWideString(params[0]).AsStringView());
108 }
109 if (!pReturnNode)
110 return CJS_Result::Success(runtime->NewNull());
111
112 return CJS_Result::Success(runtime->GetOrCreateJSBindingFromMap(pReturnNode));
113}
114
115void CJX_ExclGroup::defaultValue(v8::Isolate* pIsolate,
116 v8::Local<v8::Value>* pValue,
117 bool bSetting,
118 XFA_Attribute eAttribute) {
119 CXFA_Node* node = GetXFANode();
120 if (!node->IsWidgetReady())
121 return;
122
123 if (bSetting) {
125 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue).AsStringView(),
126 true, true, true);
127 return;
128 }
129
130 WideString wsValue = GetContent(true);
131 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
132 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
133 *pValue = fxv8::NewNullHelper(pIsolate);
134 return;
135 }
136 *pValue = fxv8::NewStringHelper(pIsolate, wsValue.ToUTF8().AsStringView());
137}
138
139void CJX_ExclGroup::rawValue(v8::Isolate* pIsolate,
140 v8::Local<v8::Value>* pValue,
141 bool bSetting,
142 XFA_Attribute eAttribute) {
143 defaultValue(pIsolate, pValue, bSetting, eAttribute);
144}
145
146void CJX_ExclGroup::transient(v8::Isolate* pIsolate,
147 v8::Local<v8::Value>* pValue,
148 bool bSetting,
149 XFA_Attribute eAttribute) {}
150
151void CJX_ExclGroup::errorText(v8::Isolate* pIsolate,
152 v8::Local<v8::Value>* pValue,
153 bool bSetting,
154 XFA_Attribute eAttribute) {
155 if (bSetting)
157}
friend class EventParamScope
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
~CJX_ExclGroup() override
bool DynamicTypeIs(TypeTag eType) const override
bool DynamicTypeIs(TypeTag eType) const override
Definition cjx_node.cpp:112
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
WideString GetContent(bool bScriptModify) const
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
CXFA_Document * GetDocument() const
CXFA_Node * GetXFANode() const
XFA_EventError ExecEventByDeepFirst(CXFA_Node *pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, bool bRecursive)
void SetSelectedMemberByValue(WideStringView wsValue, bool bNotify, bool bScriptModify, bool bSyncData)
CXFA_Node * GetSelectedMember()
bool IsWidgetReady() const
Definition cxfa_node.h:327
ByteString ToUTF8() const
bool IsEmpty() const
Definition widestring.h:118
XFA_VERSION
@ XFA_VERSION_300
@ XFA_EVENT_Initialize
@ XFA_EVENT_Calculate
@ XFA_EVENT_Validate
XFA_EventError
Definition fxfa.h:54
XFA_Attribute
Definition fxfa_basic.h:67
JSMessage