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/cfxjse_value.h"
12 #include "fxjs/js_resources.h"
13 #include "xfa/fxfa/parser/cxfa_document.h"
14 #include "xfa/fxfa/parser/cxfa_template.h"
15
16 const CJX_MethodSpec CJX_Template::MethodSpecs[] = {
17 {"execCalculate", execCalculate_static},
18 {"execInitialize", execInitialize_static},
19 {"execValidate", execValidate_static},
20 {"formNodes", formNodes_static},
21 {"recalculate", recalculate_static},
22 {"remerge", remerge_static}};
23
CJX_Template(CXFA_Template * tmpl)24 CJX_Template::CJX_Template(CXFA_Template* tmpl) : CJX_Model(tmpl) {
25 DefineMethods(MethodSpecs, FX_ArraySize(MethodSpecs));
26 }
27
~CJX_Template()28 CJX_Template::~CJX_Template() {}
29
formNodes(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)30 CJS_Return CJX_Template::formNodes(
31 CJS_V8* runtime,
32 const std::vector<v8::Local<v8::Value>>& params) {
33 if (params.size() != 1)
34 return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
35 return CJS_Return(runtime->NewBoolean(true));
36 }
37
remerge(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)38 CJS_Return CJX_Template::remerge(
39 CJS_V8* runtime,
40 const std::vector<v8::Local<v8::Value>>& params) {
41 if (!params.empty())
42 return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
43
44 GetDocument()->DoDataRemerge(true);
45 return CJS_Return(true);
46 }
47
execInitialize(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)48 CJS_Return CJX_Template::execInitialize(
49 CJS_V8* runtime,
50 const std::vector<v8::Local<v8::Value>>& params) {
51 if (!params.empty())
52 return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
53 return CJS_Return(
54 runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc()));
55 }
56
recalculate(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)57 CJS_Return CJX_Template::recalculate(
58 CJS_V8* runtime,
59 const std::vector<v8::Local<v8::Value>>& params) {
60 if (params.size() != 1)
61 return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
62 return CJS_Return(runtime->NewBoolean(true));
63 }
64
execCalculate(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)65 CJS_Return CJX_Template::execCalculate(
66 CJS_V8* runtime,
67 const std::vector<v8::Local<v8::Value>>& params) {
68 if (!params.empty())
69 return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
70 return CJS_Return(
71 runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc()));
72 }
73
execValidate(CJS_V8 * runtime,const std::vector<v8::Local<v8::Value>> & params)74 CJS_Return CJX_Template::execValidate(
75 CJS_V8* runtime,
76 const std::vector<v8::Local<v8::Value>>& params) {
77 if (!params.empty())
78 return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
79 return CJS_Return(
80 runtime->NewBoolean(!!ToNode(GetXFAObject())->GetWidgetAcc()));
81 }
82