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 <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/cppgc/allocation.h"
16#include "v8/include/v8-object.h"
17#include "v8/include/v8-primitive.h"
18#include "xfa/fxfa/cxfa_eventparam.h"
19#include "xfa/fxfa/cxfa_ffnotify.h"
20#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
21#include "xfa/fxfa/parser/cxfa_document.h"
22#include "xfa/fxfa/parser/cxfa_form.h"
23
24const CJX_MethodSpec CJX_Form::MethodSpecs[] = {
25 {"execCalculate", execCalculate_static},
26 {"execInitialize", execInitialize_static},
27 {"execValidate", execValidate_static},
28 {"formNodes", formNodes_static},
29 {"recalculate", recalculate_static},
30 {"remerge", remerge_static}};
31
32CJX_Form::CJX_Form(CXFA_Form* form) : CJX_Model(form) {
33 DefineMethods(MethodSpecs);
34}
35
36CJX_Form::~CJX_Form() = default;
37
38bool CJX_Form::DynamicTypeIs(TypeTag eType) const {
39 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
40}
41
42CJS_Result CJX_Form::formNodes(CFXJSE_Engine* runtime,
43 pdfium::span<v8::Local<v8::Value>> params) {
44 if (params.size() != 1)
46
47 CXFA_Node* pDataNode = ToNode(runtime->ToXFAObject(params[0]));
48 if (!pDataNode)
50
51 CXFA_Document* pDoc = GetDocument();
52 auto* pFormNodes = cppgc::MakeGarbageCollected<CXFA_ArrayNodeList>(
53 pDoc->GetHeap()->GetAllocationHandle(), pDoc);
55
56 v8::Local<v8::Value> value = runtime->GetOrCreateJSBindingFromMap(pFormNodes);
57 return CJS_Result::Success(value);
58}
59
60CJS_Result CJX_Form::remerge(CFXJSE_Engine* runtime,
61 pdfium::span<v8::Local<v8::Value>> params) {
62 if (!params.empty())
64
65 GetDocument()->DoDataRemerge();
67}
68
69CJS_Result CJX_Form::execInitialize(CFXJSE_Engine* runtime,
70 pdfium::span<v8::Local<v8::Value>> params) {
71 if (!params.empty())
73
74 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
75 if (pNotify)
77 true);
79}
80
81CJS_Result CJX_Form::recalculate(CFXJSE_Engine* runtime,
82 pdfium::span<v8::Local<v8::Value>> params) {
83 CXFA_EventParam* pEventParam = runtime->GetEventParam();
84 if (pEventParam && (pEventParam->m_eType == XFA_EVENT_Calculate ||
85 pEventParam->m_eType == XFA_EVENT_InitCalculate)) {
87 }
88 if (params.size() != 1)
90
91 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
92 if (!pNotify || runtime->ToInt32(params[0]) != 0)
94
99}
100
101CJS_Result CJX_Form::execCalculate(CFXJSE_Engine* runtime,
102 pdfium::span<v8::Local<v8::Value>> params) {
103 if (!params.empty())
105
106 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
107 if (pNotify)
109 true);
111}
112
113CJS_Result CJX_Form::execValidate(CFXJSE_Engine* runtime,
114 pdfium::span<v8::Local<v8::Value>> params) {
115 if (params.size() != 0)
117
118 CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
119 if (!pNotify)
120 return CJS_Result::Success(runtime->NewBoolean(false));
121
125 runtime->NewBoolean(iRet != XFA_EventError::kError));
126}
127
128void CJX_Form::checksumS(v8::Isolate* pIsolate,
129 v8::Local<v8::Value>* pValue,
130 bool bSetting,
131 XFA_Attribute eAttribute) {
132 if (bSetting) {
134 fxv8::ReentrantToWideStringHelper(pIsolate, *pValue),
135 false);
136 return;
137 }
138
139 absl::optional<WideString> checksum =
140 TryAttribute(XFA_Attribute::Checksum, false);
141 *pValue = fxv8::NewStringHelper(
142 pIsolate,
143 checksum.has_value() ? checksum.value().ToUTF8().AsStringView() : "");
144}
CXFA_EventParam * GetEventParam() const
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
Definition cjx_form.cpp:38
~CJX_Form() override
bool DynamicTypeIs(TypeTag eType) const override
Definition cjx_model.cpp:31
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
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