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