1 // Copyright 2017 PDFium Authors. All rights reserved.
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 <vector>
10
11 #include "fxjs/cfx_v8.h"
12 #include "fxjs/js_resources.h"
13 #include "fxjs/xfa/cfxjse_value.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
~CJX_Template()29 CJX_Template::~CJX_Template() {}
30
DynamicTypeIs(TypeTag eType) const31 bool CJX_Template::DynamicTypeIs(TypeTag eType) const {
32 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
33 }
34
formNodes(CFX_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)35 CJS_Result CJX_Template::formNodes(
36 CFX_V8* runtime,
37 const std::vector<v8::Local<v8::Value>>& params) {
38 if (params.size() != 1)
39 return CJS_Result::Failure(JSMessage::kParamError);
40
41 return CJS_Result::Success(runtime->NewBoolean(true));
42 }
43
remerge(CFX_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)44 CJS_Result CJX_Template::remerge(
45 CFX_V8* runtime,
46 const std::vector<v8::Local<v8::Value>>& params) {
47 if (!params.empty())
48 return CJS_Result::Failure(JSMessage::kParamError);
49
50 GetDocument()->DoDataRemerge(true);
51 return CJS_Result::Success();
52 }
53
execInitialize(CFX_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)54 CJS_Result CJX_Template::execInitialize(
55 CFX_V8* runtime,
56 const std::vector<v8::Local<v8::Value>>& params) {
57 if (!params.empty())
58 return CJS_Result::Failure(JSMessage::kParamError);
59
60 return CJS_Result::Success(
61 runtime->NewBoolean(GetXFANode()->IsWidgetReady()));
62 }
63
recalculate(CFX_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)64 CJS_Result CJX_Template::recalculate(
65 CFX_V8* runtime,
66 const std::vector<v8::Local<v8::Value>>& params) {
67 if (params.size() != 1)
68 return CJS_Result::Failure(JSMessage::kParamError);
69
70 return CJS_Result::Success(runtime->NewBoolean(true));
71 }
72
execCalculate(CFX_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)73 CJS_Result CJX_Template::execCalculate(
74 CFX_V8* runtime,
75 const std::vector<v8::Local<v8::Value>>& params) {
76 if (!params.empty())
77 return CJS_Result::Failure(JSMessage::kParamError);
78
79 return CJS_Result::Success(
80 runtime->NewBoolean(GetXFANode()->IsWidgetReady()));
81 }
82
execValidate(CFX_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)83 CJS_Result CJX_Template::execValidate(
84 CFX_V8* runtime,
85 const std::vector<v8::Local<v8::Value>>& params) {
86 if (!params.empty())
87 return CJS_Result::Failure(JSMessage::kParamError);
88
89 return CJS_Result::Success(
90 runtime->NewBoolean(GetXFANode()->IsWidgetReady()));
91 }
92