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_form.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_form.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/cppgc/allocation.h"
14#include "v8/include/v8-object.h"
15#include "v8/include/v8-primitive.h"
16#include "xfa/fxfa/cxfa_eventparam.h"
17#include "xfa/fxfa/cxfa_ffnotify.h"
18#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
19#include "xfa/fxfa/parser/cxfa_document.h"
20#include "xfa/fxfa/parser/cxfa_form.h"
21
22const CJX_MethodSpec CJX_Form::MethodSpecs[] = {
23 {"execCalculate", execCalculate_static},
24 {"execInitialize", execInitialize_static},
25 {"execValidate", execValidate_static},
26 {"formNodes", formNodes_static},
27 {"recalculate", recalculate_static},
28 {"remerge", remerge_static}};
29
30CJX_Form::CJX_Form(CXFA_Form* form) : CJX_Model(form) {
31 DefineMethods(MethodSpecs);
32}
33
34CJX_Form::~CJX_Form() = default;
35
36bool CJX_Form::DynamicTypeIs(TypeTag eType) const {
37 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
38}
39
40CJS_Result CJX_Form::formNodes(CFXJSE_Engine* runtime,
41 pdfium::span<v8::Local<v8::Value>> params) {
42 if (params.size() != 1)
44
45 CXFA_Node* pDataNode = ToNode(runtime->ToXFAObject(params[0]));
46 if (!pDataNode)
48
49 CXFA_Document* pDoc = GetDocument();
50 auto* pFormNodes = cppgc::MakeGarbageCollected<CXFA_ArrayNodeList>(
51 pDoc->GetHeap()->GetAllocationHandle(), pDoc);
53
54 v8::Local<v8::Value> value = runtime->GetOrCreateJSBindingFromMap(pFormNodes);
55 return CJS_Result::Success(value);
56}
57
58CJS_Result CJX_Form::remerge(CFXJSE_Engine* runtime,
59 pdfium::span<v8::Local<v8::Value>> params) {
60 if (!params.empty())
62
63 GetDocument()->DoDataRemerge();
65}
66
67CJS_Result CJX_Form::execInitialize(CFXJSE_Engine* runtime,
68 pdfium::span<v8::Local<v8::Value>> params) {
69 if (!params.empty())
71
72 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
73 if (pNotify)
75 true);
77}
78
79CJS_Result CJX_Form::recalculate(CFXJSE_Engine* runtime,
80 pdfium::span<v8::Local<v8::Value>> params) {
81 CXFA_EventParam* pEventParam = runtime->GetEventParam();
82 if (pEventParam && (pEventParam->m_eType == XFA_EVENT_Calculate ||
83 pEventParam->m_eType == XFA_EVENT_InitCalculate)) {
85 }
86 if (params.size() != 1)
88
89 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
90 if (!pNotify || runtime->ToInt32(params[0]) != 0)
92
97}
98
99CJS_Result CJX_Form::execCalculate(CFXJSE_Engine* runtime,
100 pdfium::span<v8::Local<v8::Value>> params) {
101 if (!params.empty())
103
104 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
105 if (pNotify)
107 true);
109}
110
111CJS_Result CJX_Form::execValidate(CFXJSE_Engine* runtime,
112 pdfium::span<v8::Local<v8::Value>> params) {
113 if (params.size() != 0)
115
116 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
117 if (!pNotify)
118 return CJS_Result::Success(runtime->NewBoolean(false));
119
123 runtime->NewBoolean(iRet != XFA_EventError::kError));
124}
125
126void CJX_Form::checksumS(v8::Isolate* pIsolate,
127 v8::Local<v8::Value>* pValue,
128 bool bSetting,
129 XFA_Attribute eAttribute) {
130 if (bSetting) {
132 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue),
133 false);
134 return;
135 }
136
137 std::optional<WideString> checksum =
138 TryAttribute(XFA_Attribute::Checksum, false);
139 *pValue = fxv8::NewStringHelper(
140 pIsolate,
141 checksum.has_value() ? checksum.value().ToUTF8().AsStringView() : "");
142}
CXFA_EventParam * GetEventParam() const
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
Definition cjx_form.cpp:36
~CJX_Form() override
bool DynamicTypeIs(TypeTag eType) const override
Definition cjx_model.cpp:29
void SetAttributeByEnum(XFA_Attribute eAttr, const WideString &wsValue, bool bNotify)
CXFA_Document * GetDocument() const
CXFA_Node * GetXFANode() const
CXFA_NodeOwner * GetNodeOwner()
XFA_EVENTTYPE m_eType
XFA_EventError ExecEventByDeepFirst(CXFA_Node *pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, bool bRecursive)
void PersistList(CXFA_List *list)
@ XFA_EVENT_InitCalculate
@ XFA_EVENT_Initialize
@ XFA_EVENT_Calculate
@ XFA_EVENT_Validate
@ XFA_EVENT_Ready
XFA_EventError
Definition fxfa.h:54
XFA_Attribute
Definition fxfa_basic.h:67
JSMessage
fxcrt::WideString WideString
Definition widestring.h:207