1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2017 The PDFium Authors
2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file.
4*3ac0a46fSAndroid Build Coastguard Worker
5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6*3ac0a46fSAndroid Build Coastguard Worker
7*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/xfa/cjx_eventpseudomodel.h"
8*3ac0a46fSAndroid Build Coastguard Worker
9*3ac0a46fSAndroid Build Coastguard Worker #include <algorithm>
10*3ac0a46fSAndroid Build Coastguard Worker #include <vector>
11*3ac0a46fSAndroid Build Coastguard Worker
12*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/fxv8.h"
13*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/xfa/cfxjse_engine.h"
14*3ac0a46fSAndroid Build Coastguard Worker #include "third_party/base/notreached.h"
15*3ac0a46fSAndroid Build Coastguard Worker #include "third_party/base/numerics/safe_conversions.h"
16*3ac0a46fSAndroid Build Coastguard Worker #include "v8/include/v8-primitive.h"
17*3ac0a46fSAndroid Build Coastguard Worker #include "xfa/fxfa/cxfa_eventparam.h"
18*3ac0a46fSAndroid Build Coastguard Worker #include "xfa/fxfa/cxfa_ffnotify.h"
19*3ac0a46fSAndroid Build Coastguard Worker #include "xfa/fxfa/parser/cscript_eventpseudomodel.h"
20*3ac0a46fSAndroid Build Coastguard Worker
21*3ac0a46fSAndroid Build Coastguard Worker namespace {
22*3ac0a46fSAndroid Build Coastguard Worker
StringProperty(v8::Isolate * pIsolate,v8::Local<v8::Value> * pReturn,WideString * wsValue,bool bSetting)23*3ac0a46fSAndroid Build Coastguard Worker void StringProperty(v8::Isolate* pIsolate,
24*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pReturn,
25*3ac0a46fSAndroid Build Coastguard Worker WideString* wsValue,
26*3ac0a46fSAndroid Build Coastguard Worker bool bSetting) {
27*3ac0a46fSAndroid Build Coastguard Worker if (bSetting) {
28*3ac0a46fSAndroid Build Coastguard Worker *wsValue = fxv8::ReentrantToWideStringHelper(pIsolate, *pReturn);
29*3ac0a46fSAndroid Build Coastguard Worker return;
30*3ac0a46fSAndroid Build Coastguard Worker }
31*3ac0a46fSAndroid Build Coastguard Worker *pReturn = fxv8::NewStringHelper(pIsolate, wsValue->ToUTF8().AsStringView());
32*3ac0a46fSAndroid Build Coastguard Worker }
33*3ac0a46fSAndroid Build Coastguard Worker
IntegerProperty(v8::Isolate * pIsolate,v8::Local<v8::Value> * pReturn,int32_t * iValue,bool bSetting)34*3ac0a46fSAndroid Build Coastguard Worker void IntegerProperty(v8::Isolate* pIsolate,
35*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pReturn,
36*3ac0a46fSAndroid Build Coastguard Worker int32_t* iValue,
37*3ac0a46fSAndroid Build Coastguard Worker bool bSetting) {
38*3ac0a46fSAndroid Build Coastguard Worker if (bSetting) {
39*3ac0a46fSAndroid Build Coastguard Worker *iValue = fxv8::ReentrantToInt32Helper(pIsolate, *pReturn);
40*3ac0a46fSAndroid Build Coastguard Worker return;
41*3ac0a46fSAndroid Build Coastguard Worker }
42*3ac0a46fSAndroid Build Coastguard Worker *pReturn = fxv8::NewNumberHelper(pIsolate, *iValue);
43*3ac0a46fSAndroid Build Coastguard Worker }
44*3ac0a46fSAndroid Build Coastguard Worker
BooleanProperty(v8::Isolate * pIsolate,v8::Local<v8::Value> * pReturn,bool * bValue,bool bSetting)45*3ac0a46fSAndroid Build Coastguard Worker void BooleanProperty(v8::Isolate* pIsolate,
46*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pReturn,
47*3ac0a46fSAndroid Build Coastguard Worker bool* bValue,
48*3ac0a46fSAndroid Build Coastguard Worker bool bSetting) {
49*3ac0a46fSAndroid Build Coastguard Worker if (bSetting) {
50*3ac0a46fSAndroid Build Coastguard Worker *bValue = fxv8::ReentrantToBooleanHelper(pIsolate, *pReturn);
51*3ac0a46fSAndroid Build Coastguard Worker return;
52*3ac0a46fSAndroid Build Coastguard Worker }
53*3ac0a46fSAndroid Build Coastguard Worker *pReturn = fxv8::NewBooleanHelper(pIsolate, *bValue);
54*3ac0a46fSAndroid Build Coastguard Worker }
55*3ac0a46fSAndroid Build Coastguard Worker
56*3ac0a46fSAndroid Build Coastguard Worker } // namespace
57*3ac0a46fSAndroid Build Coastguard Worker
58*3ac0a46fSAndroid Build Coastguard Worker const CJX_MethodSpec CJX_EventPseudoModel::MethodSpecs[] = {
59*3ac0a46fSAndroid Build Coastguard Worker {"emit", emit_static},
60*3ac0a46fSAndroid Build Coastguard Worker {"reset", reset_static}};
61*3ac0a46fSAndroid Build Coastguard Worker
CJX_EventPseudoModel(CScript_EventPseudoModel * model)62*3ac0a46fSAndroid Build Coastguard Worker CJX_EventPseudoModel::CJX_EventPseudoModel(CScript_EventPseudoModel* model)
63*3ac0a46fSAndroid Build Coastguard Worker : CJX_Object(model) {
64*3ac0a46fSAndroid Build Coastguard Worker DefineMethods(MethodSpecs);
65*3ac0a46fSAndroid Build Coastguard Worker }
66*3ac0a46fSAndroid Build Coastguard Worker
67*3ac0a46fSAndroid Build Coastguard Worker CJX_EventPseudoModel::~CJX_EventPseudoModel() = default;
68*3ac0a46fSAndroid Build Coastguard Worker
DynamicTypeIs(TypeTag eType) const69*3ac0a46fSAndroid Build Coastguard Worker bool CJX_EventPseudoModel::DynamicTypeIs(TypeTag eType) const {
70*3ac0a46fSAndroid Build Coastguard Worker return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
71*3ac0a46fSAndroid Build Coastguard Worker }
72*3ac0a46fSAndroid Build Coastguard Worker
cancelAction(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)73*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::cancelAction(v8::Isolate* pIsolate,
74*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
75*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
76*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
77*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::CancelAction, bSetting);
78*3ac0a46fSAndroid Build Coastguard Worker }
79*3ac0a46fSAndroid Build Coastguard Worker
change(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)80*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::change(v8::Isolate* pIsolate,
81*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
82*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
83*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
84*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::Change, bSetting);
85*3ac0a46fSAndroid Build Coastguard Worker }
86*3ac0a46fSAndroid Build Coastguard Worker
commitKey(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)87*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::commitKey(v8::Isolate* pIsolate,
88*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
89*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
90*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
91*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::CommitKey, bSetting);
92*3ac0a46fSAndroid Build Coastguard Worker }
93*3ac0a46fSAndroid Build Coastguard Worker
fullText(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)94*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::fullText(v8::Isolate* pIsolate,
95*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
96*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
97*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
98*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::FullText, bSetting);
99*3ac0a46fSAndroid Build Coastguard Worker }
100*3ac0a46fSAndroid Build Coastguard Worker
keyDown(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)101*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::keyDown(v8::Isolate* pIsolate,
102*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
103*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
104*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
105*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::Keydown, bSetting);
106*3ac0a46fSAndroid Build Coastguard Worker }
107*3ac0a46fSAndroid Build Coastguard Worker
modifier(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)108*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::modifier(v8::Isolate* pIsolate,
109*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
110*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
111*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
112*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::Modifier, bSetting);
113*3ac0a46fSAndroid Build Coastguard Worker }
114*3ac0a46fSAndroid Build Coastguard Worker
newContentType(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)115*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::newContentType(v8::Isolate* pIsolate,
116*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
117*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
118*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
119*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::NewContentType, bSetting);
120*3ac0a46fSAndroid Build Coastguard Worker }
121*3ac0a46fSAndroid Build Coastguard Worker
newText(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)122*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::newText(v8::Isolate* pIsolate,
123*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
124*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
125*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
126*3ac0a46fSAndroid Build Coastguard Worker if (bSetting)
127*3ac0a46fSAndroid Build Coastguard Worker return;
128*3ac0a46fSAndroid Build Coastguard Worker
129*3ac0a46fSAndroid Build Coastguard Worker CXFA_EventParam* pEventParam =
130*3ac0a46fSAndroid Build Coastguard Worker GetDocument()->GetScriptContext()->GetEventParam();
131*3ac0a46fSAndroid Build Coastguard Worker if (!pEventParam)
132*3ac0a46fSAndroid Build Coastguard Worker return;
133*3ac0a46fSAndroid Build Coastguard Worker
134*3ac0a46fSAndroid Build Coastguard Worker *pValue = fxv8::NewStringHelper(
135*3ac0a46fSAndroid Build Coastguard Worker pIsolate, pEventParam->GetNewText().ToUTF8().AsStringView());
136*3ac0a46fSAndroid Build Coastguard Worker }
137*3ac0a46fSAndroid Build Coastguard Worker
prevContentType(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)138*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::prevContentType(v8::Isolate* pIsolate,
139*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
140*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
141*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
142*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::PreviousContentType, bSetting);
143*3ac0a46fSAndroid Build Coastguard Worker }
144*3ac0a46fSAndroid Build Coastguard Worker
prevText(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)145*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::prevText(v8::Isolate* pIsolate,
146*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
147*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
148*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
149*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::PreviousText, bSetting);
150*3ac0a46fSAndroid Build Coastguard Worker }
151*3ac0a46fSAndroid Build Coastguard Worker
reenter(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)152*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::reenter(v8::Isolate* pIsolate,
153*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
154*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
155*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
156*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::Reenter, bSetting);
157*3ac0a46fSAndroid Build Coastguard Worker }
158*3ac0a46fSAndroid Build Coastguard Worker
selEnd(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)159*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::selEnd(v8::Isolate* pIsolate,
160*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
161*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
162*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
163*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::SelectionEnd, bSetting);
164*3ac0a46fSAndroid Build Coastguard Worker }
165*3ac0a46fSAndroid Build Coastguard Worker
selStart(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)166*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::selStart(v8::Isolate* pIsolate,
167*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
168*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
169*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
170*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::SelectionStart, bSetting);
171*3ac0a46fSAndroid Build Coastguard Worker }
172*3ac0a46fSAndroid Build Coastguard Worker
shift(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)173*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::shift(v8::Isolate* pIsolate,
174*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
175*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
176*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
177*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::Shift, bSetting);
178*3ac0a46fSAndroid Build Coastguard Worker }
179*3ac0a46fSAndroid Build Coastguard Worker
soapFaultCode(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)180*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::soapFaultCode(v8::Isolate* pIsolate,
181*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
182*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
183*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
184*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::SoapFaultCode, bSetting);
185*3ac0a46fSAndroid Build Coastguard Worker }
186*3ac0a46fSAndroid Build Coastguard Worker
soapFaultString(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)187*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::soapFaultString(v8::Isolate* pIsolate,
188*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
189*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
190*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
191*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::SoapFaultString, bSetting);
192*3ac0a46fSAndroid Build Coastguard Worker }
193*3ac0a46fSAndroid Build Coastguard Worker
target(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)194*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::target(v8::Isolate* pIsolate,
195*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
196*3ac0a46fSAndroid Build Coastguard Worker bool bSetting,
197*3ac0a46fSAndroid Build Coastguard Worker XFA_Attribute eAttribute) {
198*3ac0a46fSAndroid Build Coastguard Worker Property(pIsolate, pValue, XFA_Event::Target, bSetting);
199*3ac0a46fSAndroid Build Coastguard Worker }
200*3ac0a46fSAndroid Build Coastguard Worker
emit(CFXJSE_Engine * runtime,const std::vector<v8::Local<v8::Value>> & params)201*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJX_EventPseudoModel::emit(
202*3ac0a46fSAndroid Build Coastguard Worker CFXJSE_Engine* runtime,
203*3ac0a46fSAndroid Build Coastguard Worker const std::vector<v8::Local<v8::Value>>& params) {
204*3ac0a46fSAndroid Build Coastguard Worker CXFA_EventParam* pEventParam = runtime->GetEventParam();
205*3ac0a46fSAndroid Build Coastguard Worker if (!pEventParam)
206*3ac0a46fSAndroid Build Coastguard Worker return CJS_Result::Success();
207*3ac0a46fSAndroid Build Coastguard Worker
208*3ac0a46fSAndroid Build Coastguard Worker CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
209*3ac0a46fSAndroid Build Coastguard Worker if (!pNotify)
210*3ac0a46fSAndroid Build Coastguard Worker return CJS_Result::Success();
211*3ac0a46fSAndroid Build Coastguard Worker
212*3ac0a46fSAndroid Build Coastguard Worker pNotify->HandleWidgetEvent(runtime->GetEventTarget(), pEventParam);
213*3ac0a46fSAndroid Build Coastguard Worker return CJS_Result::Success();
214*3ac0a46fSAndroid Build Coastguard Worker }
215*3ac0a46fSAndroid Build Coastguard Worker
reset(CFXJSE_Engine * runtime,const std::vector<v8::Local<v8::Value>> & params)216*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJX_EventPseudoModel::reset(
217*3ac0a46fSAndroid Build Coastguard Worker CFXJSE_Engine* runtime,
218*3ac0a46fSAndroid Build Coastguard Worker const std::vector<v8::Local<v8::Value>>& params) {
219*3ac0a46fSAndroid Build Coastguard Worker CXFA_EventParam* pEventParam = runtime->GetEventParam();
220*3ac0a46fSAndroid Build Coastguard Worker if (pEventParam)
221*3ac0a46fSAndroid Build Coastguard Worker *pEventParam = CXFA_EventParam();
222*3ac0a46fSAndroid Build Coastguard Worker
223*3ac0a46fSAndroid Build Coastguard Worker return CJS_Result::Success();
224*3ac0a46fSAndroid Build Coastguard Worker }
225*3ac0a46fSAndroid Build Coastguard Worker
Property(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,XFA_Event dwFlag,bool bSetting)226*3ac0a46fSAndroid Build Coastguard Worker void CJX_EventPseudoModel::Property(v8::Isolate* pIsolate,
227*3ac0a46fSAndroid Build Coastguard Worker v8::Local<v8::Value>* pValue,
228*3ac0a46fSAndroid Build Coastguard Worker XFA_Event dwFlag,
229*3ac0a46fSAndroid Build Coastguard Worker bool bSetting) {
230*3ac0a46fSAndroid Build Coastguard Worker // Only the cancelAction, selStart, selEnd and change properties are writable.
231*3ac0a46fSAndroid Build Coastguard Worker if (bSetting && dwFlag != XFA_Event::CancelAction &&
232*3ac0a46fSAndroid Build Coastguard Worker dwFlag != XFA_Event::SelectionStart &&
233*3ac0a46fSAndroid Build Coastguard Worker dwFlag != XFA_Event::SelectionEnd && dwFlag != XFA_Event::Change) {
234*3ac0a46fSAndroid Build Coastguard Worker return;
235*3ac0a46fSAndroid Build Coastguard Worker }
236*3ac0a46fSAndroid Build Coastguard Worker
237*3ac0a46fSAndroid Build Coastguard Worker CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
238*3ac0a46fSAndroid Build Coastguard Worker CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
239*3ac0a46fSAndroid Build Coastguard Worker if (!pEventParam)
240*3ac0a46fSAndroid Build Coastguard Worker return;
241*3ac0a46fSAndroid Build Coastguard Worker
242*3ac0a46fSAndroid Build Coastguard Worker switch (dwFlag) {
243*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::CancelAction:
244*3ac0a46fSAndroid Build Coastguard Worker BooleanProperty(pIsolate, pValue, &pEventParam->m_bCancelAction,
245*3ac0a46fSAndroid Build Coastguard Worker bSetting);
246*3ac0a46fSAndroid Build Coastguard Worker break;
247*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::Change:
248*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsChange, bSetting);
249*3ac0a46fSAndroid Build Coastguard Worker break;
250*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::CommitKey:
251*3ac0a46fSAndroid Build Coastguard Worker IntegerProperty(pIsolate, pValue, &pEventParam->m_iCommitKey, bSetting);
252*3ac0a46fSAndroid Build Coastguard Worker break;
253*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::FullText:
254*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsFullText, bSetting);
255*3ac0a46fSAndroid Build Coastguard Worker break;
256*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::Keydown:
257*3ac0a46fSAndroid Build Coastguard Worker BooleanProperty(pIsolate, pValue, &pEventParam->m_bKeyDown, bSetting);
258*3ac0a46fSAndroid Build Coastguard Worker break;
259*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::Modifier:
260*3ac0a46fSAndroid Build Coastguard Worker BooleanProperty(pIsolate, pValue, &pEventParam->m_bModifier, bSetting);
261*3ac0a46fSAndroid Build Coastguard Worker break;
262*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::NewContentType:
263*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsNewContentType,
264*3ac0a46fSAndroid Build Coastguard Worker bSetting);
265*3ac0a46fSAndroid Build Coastguard Worker break;
266*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::NewText:
267*3ac0a46fSAndroid Build Coastguard Worker NOTREACHED();
268*3ac0a46fSAndroid Build Coastguard Worker break;
269*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::PreviousContentType:
270*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsPrevContentType,
271*3ac0a46fSAndroid Build Coastguard Worker bSetting);
272*3ac0a46fSAndroid Build Coastguard Worker break;
273*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::PreviousText:
274*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsPrevText, bSetting);
275*3ac0a46fSAndroid Build Coastguard Worker break;
276*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::Reenter:
277*3ac0a46fSAndroid Build Coastguard Worker BooleanProperty(pIsolate, pValue, &pEventParam->m_bReenter, bSetting);
278*3ac0a46fSAndroid Build Coastguard Worker break;
279*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::SelectionEnd:
280*3ac0a46fSAndroid Build Coastguard Worker IntegerProperty(pIsolate, pValue, &pEventParam->m_iSelEnd, bSetting);
281*3ac0a46fSAndroid Build Coastguard Worker
282*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelEnd = std::max(0, pEventParam->m_iSelEnd);
283*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelEnd = std::min(
284*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelEnd, pdfium::base::checked_cast<int32_t>(
285*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_wsPrevText.GetLength()));
286*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelStart =
287*3ac0a46fSAndroid Build Coastguard Worker std::min(pEventParam->m_iSelStart, pEventParam->m_iSelEnd);
288*3ac0a46fSAndroid Build Coastguard Worker break;
289*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::SelectionStart:
290*3ac0a46fSAndroid Build Coastguard Worker IntegerProperty(pIsolate, pValue, &pEventParam->m_iSelStart, bSetting);
291*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelStart = std::max(0, pEventParam->m_iSelStart);
292*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelStart = std::min(
293*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelStart, pdfium::base::checked_cast<int32_t>(
294*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_wsPrevText.GetLength()));
295*3ac0a46fSAndroid Build Coastguard Worker pEventParam->m_iSelEnd =
296*3ac0a46fSAndroid Build Coastguard Worker std::max(pEventParam->m_iSelStart, pEventParam->m_iSelEnd);
297*3ac0a46fSAndroid Build Coastguard Worker break;
298*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::Shift:
299*3ac0a46fSAndroid Build Coastguard Worker BooleanProperty(pIsolate, pValue, &pEventParam->m_bShift, bSetting);
300*3ac0a46fSAndroid Build Coastguard Worker break;
301*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::SoapFaultCode:
302*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsSoapFaultCode,
303*3ac0a46fSAndroid Build Coastguard Worker bSetting);
304*3ac0a46fSAndroid Build Coastguard Worker break;
305*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::SoapFaultString:
306*3ac0a46fSAndroid Build Coastguard Worker StringProperty(pIsolate, pValue, &pEventParam->m_wsSoapFaultString,
307*3ac0a46fSAndroid Build Coastguard Worker bSetting);
308*3ac0a46fSAndroid Build Coastguard Worker break;
309*3ac0a46fSAndroid Build Coastguard Worker case XFA_Event::Target:
310*3ac0a46fSAndroid Build Coastguard Worker break;
311*3ac0a46fSAndroid Build Coastguard Worker }
312*3ac0a46fSAndroid Build Coastguard Worker }
313