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