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_template.h"
8
9 #include "core/fxcrt/span.h"
10 #include "fxjs/cfx_v8.h"
11 #include "fxjs/js_resources.h"
12 #include "fxjs/xfa/cfxjse_value.h"
13 #include "v8/include/v8-primitive.h"
14 #include "xfa/fxfa/parser/cxfa_document.h"
15 #include "xfa/fxfa/parser/cxfa_template.h"
16
17 const CJX_MethodSpec CJX_Template::MethodSpecs[] = {
18 {"execCalculate", execCalculate_static},
19 {"execInitialize", execInitialize_static},
20 {"execValidate", execValidate_static},
21 {"formNodes", formNodes_static},
22 {"recalculate", recalculate_static},
23 {"remerge", remerge_static}};
24
CJX_Template(CXFA_Template * tmpl)25 CJX_Template::CJX_Template(CXFA_Template* tmpl) : CJX_Model(tmpl) {
26 DefineMethods(MethodSpecs);
27 }
28
29 CJX_Template::~CJX_Template() = default;
30
DynamicTypeIs(TypeTag eType) const31 bool CJX_Template::DynamicTypeIs(TypeTag eType) const {
32 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
33 }
34
formNodes(CFXJSE_Engine * runtime,pdfium::span<v8::Local<v8::Value>> params)35 CJS_Result CJX_Template::formNodes(CFXJSE_Engine* runtime,
36 pdfium::span<v8::Local<v8::Value>> params) {
37 if (params.size() != 1)
38 return CJS_Result::Failure(JSMessage::kParamError);
39
40 return CJS_Result::Success(runtime->NewBoolean(true));
41 }
42
remerge(CFXJSE_Engine * runtime,pdfium::span<v8::Local<v8::Value>> params)43 CJS_Result CJX_Template::remerge(CFXJSE_Engine* runtime,
44 pdfium::span<v8::Local<v8::Value>> params) {
45 if (!params.empty())
46 return CJS_Result::Failure(JSMessage::kParamError);
47
48 GetDocument()->DoDataRemerge();
49 return CJS_Result::Success();
50 }
51
execInitialize(CFXJSE_Engine * runtime,pdfium::span<v8::Local<v8::Value>> params)52 CJS_Result CJX_Template::execInitialize(
53 CFXJSE_Engine* runtime,
54 pdfium::span<v8::Local<v8::Value>> params) {
55 if (!params.empty())
56 return CJS_Result::Failure(JSMessage::kParamError);
57
58 return CJS_Result::Success(
59 runtime->NewBoolean(GetXFANode()->IsWidgetReady()));
60 }
61
recalculate(CFXJSE_Engine * runtime,pdfium::span<v8::Local<v8::Value>> params)62 CJS_Result CJX_Template::recalculate(
63 CFXJSE_Engine* runtime,
64 pdfium::span<v8::Local<v8::Value>> params) {
65 if (params.size() != 1)
66 return CJS_Result::Failure(JSMessage::kParamError);
67
68 return CJS_Result::Success(runtime->NewBoolean(true));
69 }
70
execCalculate(CFXJSE_Engine * runtime,pdfium::span<v8::Local<v8::Value>> params)71 CJS_Result CJX_Template::execCalculate(
72 CFXJSE_Engine* runtime,
73 pdfium::span<v8::Local<v8::Value>> params) {
74 if (!params.empty())
75 return CJS_Result::Failure(JSMessage::kParamError);
76
77 return CJS_Result::Success(
78 runtime->NewBoolean(GetXFANode()->IsWidgetReady()));
79 }
80
execValidate(CFXJSE_Engine * runtime,pdfium::span<v8::Local<v8::Value>> params)81 CJS_Result CJX_Template::execValidate(
82 CFXJSE_Engine* runtime,
83 pdfium::span<v8::Local<v8::Value>> params) {
84 if (!params.empty())
85 return CJS_Result::Failure(JSMessage::kParamError);
86
87 return CJS_Result::Success(
88 runtime->NewBoolean(GetXFANode()->IsWidgetReady()));
89 }
90