1 // Copyright 2014 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 "xfa/src/foxitlib.h"
8 #include "xfa/src/fxfa/src/common/xfa_utils.h"
9 #include "xfa/src/fxfa/src/common/xfa_object.h"
10 #include "xfa/src/fxfa/src/common/xfa_document.h"
11 #include "xfa/src/fxfa/src/common/xfa_parser.h"
12 #include "xfa/src/fxfa/src/common/xfa_script.h"
13 #include "xfa/src/fxfa/src/common/xfa_docdata.h"
14 #include "xfa/src/fxfa/src/common/xfa_doclayout.h"
15 #include "xfa/src/fxfa/src/common/xfa_localemgr.h"
16 #include "xfa/src/fxfa/src/common/xfa_fm2jsapi.h"
17 #include "xfa_script_eventpseudomodel.h"
CScript_EventPseudoModel(CXFA_Document * pDocument)18 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument)
19 : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_EventPseudoModel) {
20 m_uScriptHash = XFA_HASHCODE_Event;
21 }
~CScript_EventPseudoModel()22 CScript_EventPseudoModel::~CScript_EventPseudoModel() {}
Script_EventPseudoModel_StringProperty(FXJSE_HVALUE hValue,CFX_WideString & wsValue,FX_BOOL bSetting)23 void Script_EventPseudoModel_StringProperty(FXJSE_HVALUE hValue,
24 CFX_WideString& wsValue,
25 FX_BOOL bSetting) {
26 if (bSetting) {
27 CFX_ByteString bsValue;
28 FXJSE_Value_ToUTF8String(hValue, bsValue);
29 wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());
30 } else {
31 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));
32 }
33 }
Script_EventPseudoModel_InterProperty(FXJSE_HVALUE hValue,int32_t & iValue,FX_BOOL bSetting)34 void Script_EventPseudoModel_InterProperty(FXJSE_HVALUE hValue,
35 int32_t& iValue,
36 FX_BOOL bSetting) {
37 if (bSetting) {
38 iValue = FXJSE_Value_ToInteger(hValue);
39 } else {
40 FXJSE_Value_SetInteger(hValue, iValue);
41 }
42 }
Script_EventPseudoModel_BooleanProperty(FXJSE_HVALUE hValue,FX_BOOL & bValue,FX_BOOL bSetting)43 void Script_EventPseudoModel_BooleanProperty(FXJSE_HVALUE hValue,
44 FX_BOOL& bValue,
45 FX_BOOL bSetting) {
46 if (bSetting) {
47 bValue = FXJSE_Value_ToBoolean(hValue);
48 } else {
49 FXJSE_Value_SetBoolean(hValue, bValue);
50 }
51 }
Script_EventPseudoModel_Property(FXJSE_HVALUE hValue,FX_DWORD dwFlag,FX_BOOL bSetting)52 void CScript_EventPseudoModel::Script_EventPseudoModel_Property(
53 FXJSE_HVALUE hValue,
54 FX_DWORD dwFlag,
55 FX_BOOL bSetting) {
56 IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
57 if (!pScriptContext) {
58 return;
59 }
60 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
61 if (!pEventParam) {
62 return;
63 }
64 switch (dwFlag) {
65 case XFA_EVENT_CANCELACTION:
66 Script_EventPseudoModel_BooleanProperty(
67 hValue, pEventParam->m_bCancelAction, bSetting);
68 break;
69 case XFA_EVENT_CHANGE:
70 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsChange,
71 bSetting);
72 break;
73 case XFA_EVENT_COMMITKEY:
74 Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iCommitKey,
75 bSetting);
76 break;
77 case XFA_EVENT_FULLTEXT:
78 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsFullText,
79 bSetting);
80 break;
81 case XFA_EVENT_KEYDOWN:
82 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bKeyDown,
83 bSetting);
84 break;
85 case XFA_EVENT_MODIFIER:
86 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bModifier,
87 bSetting);
88 break;
89 case XFA_EVENT_NEWCONTENTTYPE:
90 Script_EventPseudoModel_StringProperty(
91 hValue, pEventParam->m_wsNewContentType, bSetting);
92 break;
93 case XFA_EVENT_NEWTEXT:
94 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsNewText,
95 bSetting);
96 break;
97 case XFA_EVENT_PREVCONTENTTYPE:
98 Script_EventPseudoModel_StringProperty(
99 hValue, pEventParam->m_wsPrevContentType, bSetting);
100 break;
101 case XFA_EVENT_PREVTEXT:
102 Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsPrevText,
103 bSetting);
104 break;
105 case XFA_EVENT_REENTER:
106 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bReenter,
107 bSetting);
108 break;
109 case XFA_EVENT_SELEND:
110 Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelEnd,
111 bSetting);
112 break;
113 case XFA_EVENT_SELSTART:
114 Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelStart,
115 bSetting);
116 break;
117 case XFA_EVENT_SHIFT:
118 Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bShift,
119 bSetting);
120 break;
121 case XFA_EVENT_SOAPFAULTCODE:
122 Script_EventPseudoModel_StringProperty(
123 hValue, pEventParam->m_wsSoapFaultCode, bSetting);
124 break;
125 case XFA_EVENT_SOAPFAULTSTRING:
126 Script_EventPseudoModel_StringProperty(
127 hValue, pEventParam->m_wsSoapFaultString, bSetting);
128 break;
129 case XFA_EVENT_TARGET:
130 break;
131 default:
132 break;
133 }
134 }
Script_EventPseudoModel_CancelAction(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)135 void CScript_EventPseudoModel::Script_EventPseudoModel_CancelAction(
136 FXJSE_HVALUE hValue,
137 FX_BOOL bSetting,
138 XFA_ATTRIBUTE eAttribute) {
139 Script_EventPseudoModel_Property(hValue, XFA_EVENT_CANCELACTION, bSetting);
140 }
Script_EventPseudoModel_Change(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)141 void CScript_EventPseudoModel::Script_EventPseudoModel_Change(
142 FXJSE_HVALUE hValue,
143 FX_BOOL bSetting,
144 XFA_ATTRIBUTE eAttribute) {
145 Script_EventPseudoModel_Property(hValue, XFA_EVENT_CHANGE, bSetting);
146 }
Script_EventPseudoModel_CommitKey(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)147 void CScript_EventPseudoModel::Script_EventPseudoModel_CommitKey(
148 FXJSE_HVALUE hValue,
149 FX_BOOL bSetting,
150 XFA_ATTRIBUTE eAttribute) {
151 Script_EventPseudoModel_Property(hValue, XFA_EVENT_COMMITKEY, bSetting);
152 }
Script_EventPseudoModel_FullText(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)153 void CScript_EventPseudoModel::Script_EventPseudoModel_FullText(
154 FXJSE_HVALUE hValue,
155 FX_BOOL bSetting,
156 XFA_ATTRIBUTE eAttribute) {
157 Script_EventPseudoModel_Property(hValue, XFA_EVENT_FULLTEXT, bSetting);
158 }
Script_EventPseudoModel_KeyDown(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)159 void CScript_EventPseudoModel::Script_EventPseudoModel_KeyDown(
160 FXJSE_HVALUE hValue,
161 FX_BOOL bSetting,
162 XFA_ATTRIBUTE eAttribute) {
163 Script_EventPseudoModel_Property(hValue, XFA_EVENT_KEYDOWN, bSetting);
164 }
Script_EventPseudoModel_Modifier(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)165 void CScript_EventPseudoModel::Script_EventPseudoModel_Modifier(
166 FXJSE_HVALUE hValue,
167 FX_BOOL bSetting,
168 XFA_ATTRIBUTE eAttribute) {
169 Script_EventPseudoModel_Property(hValue, XFA_EVENT_MODIFIER, bSetting);
170 }
Script_EventPseudoModel_NewContentType(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)171 void CScript_EventPseudoModel::Script_EventPseudoModel_NewContentType(
172 FXJSE_HVALUE hValue,
173 FX_BOOL bSetting,
174 XFA_ATTRIBUTE eAttribute) {
175 Script_EventPseudoModel_Property(hValue, XFA_EVENT_NEWCONTENTTYPE, bSetting);
176 }
Script_EventPseudoModel_NewText(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)177 void CScript_EventPseudoModel::Script_EventPseudoModel_NewText(
178 FXJSE_HVALUE hValue,
179 FX_BOOL bSetting,
180 XFA_ATTRIBUTE eAttribute) {
181 Script_EventPseudoModel_Property(hValue, XFA_EVENT_NEWTEXT, bSetting);
182 }
Script_EventPseudoModel_PrevContentType(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)183 void CScript_EventPseudoModel::Script_EventPseudoModel_PrevContentType(
184 FXJSE_HVALUE hValue,
185 FX_BOOL bSetting,
186 XFA_ATTRIBUTE eAttribute) {
187 Script_EventPseudoModel_Property(hValue, XFA_EVENT_PREVCONTENTTYPE, bSetting);
188 }
Script_EventPseudoModel_PrevText(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)189 void CScript_EventPseudoModel::Script_EventPseudoModel_PrevText(
190 FXJSE_HVALUE hValue,
191 FX_BOOL bSetting,
192 XFA_ATTRIBUTE eAttribute) {
193 Script_EventPseudoModel_Property(hValue, XFA_EVENT_PREVTEXT, bSetting);
194 }
Script_EventPseudoModel_Reenter(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)195 void CScript_EventPseudoModel::Script_EventPseudoModel_Reenter(
196 FXJSE_HVALUE hValue,
197 FX_BOOL bSetting,
198 XFA_ATTRIBUTE eAttribute) {
199 Script_EventPseudoModel_Property(hValue, XFA_EVENT_REENTER, bSetting);
200 }
Script_EventPseudoModel_SelEnd(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)201 void CScript_EventPseudoModel::Script_EventPseudoModel_SelEnd(
202 FXJSE_HVALUE hValue,
203 FX_BOOL bSetting,
204 XFA_ATTRIBUTE eAttribute) {
205 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SELEND, bSetting);
206 }
Script_EventPseudoModel_SelStart(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)207 void CScript_EventPseudoModel::Script_EventPseudoModel_SelStart(
208 FXJSE_HVALUE hValue,
209 FX_BOOL bSetting,
210 XFA_ATTRIBUTE eAttribute) {
211 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SELSTART, bSetting);
212 }
Script_EventPseudoModel_Shift(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)213 void CScript_EventPseudoModel::Script_EventPseudoModel_Shift(
214 FXJSE_HVALUE hValue,
215 FX_BOOL bSetting,
216 XFA_ATTRIBUTE eAttribute) {
217 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SHIFT, bSetting);
218 }
Script_EventPseudoModel_SoapFaultCode(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)219 void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultCode(
220 FXJSE_HVALUE hValue,
221 FX_BOOL bSetting,
222 XFA_ATTRIBUTE eAttribute) {
223 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SOAPFAULTCODE, bSetting);
224 }
Script_EventPseudoModel_SoapFaultString(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)225 void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultString(
226 FXJSE_HVALUE hValue,
227 FX_BOOL bSetting,
228 XFA_ATTRIBUTE eAttribute) {
229 Script_EventPseudoModel_Property(hValue, XFA_EVENT_SOAPFAULTSTRING, bSetting);
230 }
Script_EventPseudoModel_Target(FXJSE_HVALUE hValue,FX_BOOL bSetting,XFA_ATTRIBUTE eAttribute)231 void CScript_EventPseudoModel::Script_EventPseudoModel_Target(
232 FXJSE_HVALUE hValue,
233 FX_BOOL bSetting,
234 XFA_ATTRIBUTE eAttribute) {
235 Script_EventPseudoModel_Property(hValue, XFA_EVENT_TARGET, bSetting);
236 }
Script_EventPseudoModel_Emit(CFXJSE_Arguments * pArguments)237 void CScript_EventPseudoModel::Script_EventPseudoModel_Emit(
238 CFXJSE_Arguments* pArguments) {
239 IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
240 if (!pScriptContext) {
241 return;
242 }
243 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
244 if (!pEventParam) {
245 return;
246 }
247 IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
248 if (!pNotify) {
249 return;
250 }
251 IXFA_WidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler();
252 if (!pWidgetHandler) {
253 return;
254 }
255 pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam);
256 }
Script_EventPseudoModel_Reset(CFXJSE_Arguments * pArguments)257 void CScript_EventPseudoModel::Script_EventPseudoModel_Reset(
258 CFXJSE_Arguments* pArguments) {
259 IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
260 if (!pScriptContext) {
261 return;
262 }
263 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
264 if (!pEventParam) {
265 return;
266 }
267 pEventParam->Reset();
268 }
269