OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/parser/xfa_script_eventpseudomodel.h" | 7 #include "xfa/fxfa/parser/xfa_script_eventpseudomodel.h" |
8 | 8 |
9 #include "fxjse/include/cfxjse_arguments.h" | 9 #include "fxjse/include/cfxjse_arguments.h" |
10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
11 #include "xfa/fxfa/include/cxfa_eventparam.h" | 11 #include "xfa/fxfa/include/cxfa_eventparam.h" |
12 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" | 12 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" |
13 #include "xfa/fxfa/parser/xfa_doclayout.h" | 13 #include "xfa/fxfa/parser/xfa_doclayout.h" |
14 #include "xfa/fxfa/parser/xfa_document.h" | 14 #include "xfa/fxfa/parser/xfa_document.h" |
15 #include "xfa/fxfa/parser/xfa_localemgr.h" | 15 #include "xfa/fxfa/parser/xfa_localemgr.h" |
16 #include "xfa/fxfa/parser/xfa_object.h" | 16 #include "xfa/fxfa/parser/xfa_object.h" |
17 #include "xfa/fxfa/parser/xfa_parser.h" | 17 #include "xfa/fxfa/parser/xfa_parser.h" |
18 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 18 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
19 #include "xfa/fxfa/parser/xfa_script.h" | 19 #include "xfa/fxfa/parser/xfa_script.h" |
20 #include "xfa/fxfa/parser/xfa_script_imp.h" | 20 #include "xfa/fxfa/parser/xfa_script_imp.h" |
21 #include "xfa/fxfa/parser/xfa_utils.h" | 21 #include "xfa/fxfa/parser/xfa_utils.h" |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 void StringProperty(CFXJSE_Value* pValue, |
| 26 CFX_WideString& wsValue, |
| 27 FX_BOOL bSetting) { |
| 28 if (bSetting) { |
| 29 wsValue = pValue->ToWideString(); |
| 30 return; |
| 31 } |
| 32 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
| 33 } |
| 34 |
| 35 void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, FX_BOOL bSetting) { |
| 36 if (bSetting) { |
| 37 iValue = pValue->ToInteger(); |
| 38 return; |
| 39 } |
| 40 pValue->SetInteger(iValue); |
| 41 } |
| 42 |
| 43 void BooleanProperty(CFXJSE_Value* pValue, FX_BOOL& bValue, FX_BOOL bSetting) { |
| 44 if (bSetting) { |
| 45 bValue = pValue->ToBoolean(); |
| 46 return; |
| 47 } |
| 48 pValue->SetBoolean(bValue); |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
23 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) | 53 CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) |
24 : CXFA_Object(pDocument, | 54 : CXFA_Object(pDocument, |
25 XFA_ObjectType::Object, | 55 XFA_ObjectType::Object, |
26 XFA_Element::EventPseudoModel) {} | 56 XFA_Element::EventPseudoModel) {} |
| 57 |
27 CScript_EventPseudoModel::~CScript_EventPseudoModel() {} | 58 CScript_EventPseudoModel::~CScript_EventPseudoModel() {} |
28 void Script_EventPseudoModel_StringProperty(CFXJSE_Value* pValue, | |
29 CFX_WideString& wsValue, | |
30 FX_BOOL bSetting) { | |
31 if (bSetting) { | |
32 wsValue = pValue->ToWideString(); | |
33 } else { | |
34 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); | |
35 } | |
36 } | |
37 void Script_EventPseudoModel_InterProperty(CFXJSE_Value* pValue, | |
38 int32_t& iValue, | |
39 FX_BOOL bSetting) { | |
40 if (bSetting) { | |
41 iValue = pValue->ToInteger(); | |
42 } else { | |
43 pValue->SetInteger(iValue); | |
44 } | |
45 } | |
46 void Script_EventPseudoModel_BooleanProperty(CFXJSE_Value* pValue, | |
47 FX_BOOL& bValue, | |
48 FX_BOOL bSetting) { | |
49 if (bSetting) | |
50 bValue = pValue->ToBoolean(); | |
51 else | |
52 pValue->SetBoolean(bValue); | |
53 } | |
54 | 59 |
55 void CScript_EventPseudoModel::Script_EventPseudoModel_Property( | 60 void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue, |
56 CFXJSE_Value* pValue, | 61 XFA_Event dwFlag, |
57 XFA_Event dwFlag, | 62 FX_BOOL bSetting) { |
58 FX_BOOL bSetting) { | |
59 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 63 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
60 if (!pScriptContext) | 64 if (!pScriptContext) |
61 return; | 65 return; |
62 | 66 |
63 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | 67 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
64 if (!pEventParam) | 68 if (!pEventParam) |
65 return; | 69 return; |
66 | 70 |
67 switch (dwFlag) { | 71 switch (dwFlag) { |
68 case XFA_Event::CancelAction: | 72 case XFA_Event::CancelAction: |
69 Script_EventPseudoModel_BooleanProperty( | 73 BooleanProperty(pValue, pEventParam->m_bCancelAction, bSetting); |
70 pValue, pEventParam->m_bCancelAction, bSetting); | |
71 break; | 74 break; |
72 case XFA_Event::Change: | 75 case XFA_Event::Change: |
73 Script_EventPseudoModel_StringProperty(pValue, pEventParam->m_wsChange, | 76 StringProperty(pValue, pEventParam->m_wsChange, bSetting); |
74 bSetting); | |
75 break; | 77 break; |
76 case XFA_Event::CommitKey: | 78 case XFA_Event::CommitKey: |
77 Script_EventPseudoModel_InterProperty(pValue, pEventParam->m_iCommitKey, | 79 InterProperty(pValue, pEventParam->m_iCommitKey, bSetting); |
78 bSetting); | |
79 break; | 80 break; |
80 case XFA_Event::FullText: | 81 case XFA_Event::FullText: |
81 Script_EventPseudoModel_StringProperty(pValue, pEventParam->m_wsFullText, | 82 StringProperty(pValue, pEventParam->m_wsFullText, bSetting); |
82 bSetting); | |
83 break; | 83 break; |
84 case XFA_Event::Keydown: | 84 case XFA_Event::Keydown: |
85 Script_EventPseudoModel_BooleanProperty(pValue, pEventParam->m_bKeyDown, | 85 BooleanProperty(pValue, pEventParam->m_bKeyDown, bSetting); |
86 bSetting); | |
87 break; | 86 break; |
88 case XFA_Event::Modifier: | 87 case XFA_Event::Modifier: |
89 Script_EventPseudoModel_BooleanProperty(pValue, pEventParam->m_bModifier, | 88 BooleanProperty(pValue, pEventParam->m_bModifier, bSetting); |
90 bSetting); | |
91 break; | 89 break; |
92 case XFA_Event::NewContentType: | 90 case XFA_Event::NewContentType: |
93 Script_EventPseudoModel_StringProperty( | 91 StringProperty(pValue, pEventParam->m_wsNewContentType, bSetting); |
94 pValue, pEventParam->m_wsNewContentType, bSetting); | |
95 break; | 92 break; |
96 case XFA_Event::NewText: | 93 case XFA_Event::NewText: |
97 Script_EventPseudoModel_StringProperty(pValue, pEventParam->m_wsNewText, | 94 StringProperty(pValue, pEventParam->m_wsNewText, bSetting); |
98 bSetting); | |
99 break; | 95 break; |
100 case XFA_Event::PreviousContentType: | 96 case XFA_Event::PreviousContentType: |
101 Script_EventPseudoModel_StringProperty( | 97 StringProperty(pValue, pEventParam->m_wsPrevContentType, bSetting); |
102 pValue, pEventParam->m_wsPrevContentType, bSetting); | |
103 break; | 98 break; |
104 case XFA_Event::PreviousText: | 99 case XFA_Event::PreviousText: |
105 Script_EventPseudoModel_StringProperty(pValue, pEventParam->m_wsPrevText, | 100 StringProperty(pValue, pEventParam->m_wsPrevText, bSetting); |
106 bSetting); | |
107 break; | 101 break; |
108 case XFA_Event::Reenter: | 102 case XFA_Event::Reenter: |
109 Script_EventPseudoModel_BooleanProperty(pValue, pEventParam->m_bReenter, | 103 BooleanProperty(pValue, pEventParam->m_bReenter, bSetting); |
110 bSetting); | |
111 break; | 104 break; |
112 case XFA_Event::SelectionEnd: | 105 case XFA_Event::SelectionEnd: |
113 Script_EventPseudoModel_InterProperty(pValue, pEventParam->m_iSelEnd, | 106 InterProperty(pValue, pEventParam->m_iSelEnd, bSetting); |
114 bSetting); | |
115 break; | 107 break; |
116 case XFA_Event::SelectionStart: | 108 case XFA_Event::SelectionStart: |
117 Script_EventPseudoModel_InterProperty(pValue, pEventParam->m_iSelStart, | 109 InterProperty(pValue, pEventParam->m_iSelStart, bSetting); |
118 bSetting); | |
119 break; | 110 break; |
120 case XFA_Event::Shift: | 111 case XFA_Event::Shift: |
121 Script_EventPseudoModel_BooleanProperty(pValue, pEventParam->m_bShift, | 112 BooleanProperty(pValue, pEventParam->m_bShift, bSetting); |
122 bSetting); | |
123 break; | 113 break; |
124 case XFA_Event::SoapFaultCode: | 114 case XFA_Event::SoapFaultCode: |
125 Script_EventPseudoModel_StringProperty( | 115 StringProperty(pValue, pEventParam->m_wsSoapFaultCode, bSetting); |
126 pValue, pEventParam->m_wsSoapFaultCode, bSetting); | |
127 break; | 116 break; |
128 case XFA_Event::SoapFaultString: | 117 case XFA_Event::SoapFaultString: |
129 Script_EventPseudoModel_StringProperty( | 118 StringProperty(pValue, pEventParam->m_wsSoapFaultString, bSetting); |
130 pValue, pEventParam->m_wsSoapFaultString, bSetting); | |
131 break; | 119 break; |
132 case XFA_Event::Target: | 120 case XFA_Event::Target: |
133 break; | 121 break; |
134 default: | 122 default: |
135 break; | 123 break; |
136 } | 124 } |
137 } | 125 } |
138 void CScript_EventPseudoModel::Script_EventPseudoModel_Change( | 126 void CScript_EventPseudoModel::Change(CFXJSE_Value* pValue, |
139 CFXJSE_Value* pValue, | 127 FX_BOOL bSetting, |
140 FX_BOOL bSetting, | 128 XFA_ATTRIBUTE eAttribute) { |
141 XFA_ATTRIBUTE eAttribute) { | 129 Property(pValue, XFA_Event::Change, bSetting); |
142 Script_EventPseudoModel_Property(pValue, XFA_Event::Change, bSetting); | |
143 } | 130 } |
144 void CScript_EventPseudoModel::Script_EventPseudoModel_CommitKey( | 131 void CScript_EventPseudoModel::CommitKey(CFXJSE_Value* pValue, |
145 CFXJSE_Value* pValue, | 132 FX_BOOL bSetting, |
146 FX_BOOL bSetting, | 133 XFA_ATTRIBUTE eAttribute) { |
147 XFA_ATTRIBUTE eAttribute) { | 134 Property(pValue, XFA_Event::CommitKey, bSetting); |
148 Script_EventPseudoModel_Property(pValue, XFA_Event::CommitKey, bSetting); | |
149 } | 135 } |
150 void CScript_EventPseudoModel::Script_EventPseudoModel_FullText( | 136 void CScript_EventPseudoModel::FullText(CFXJSE_Value* pValue, |
151 CFXJSE_Value* pValue, | 137 FX_BOOL bSetting, |
152 FX_BOOL bSetting, | 138 XFA_ATTRIBUTE eAttribute) { |
153 XFA_ATTRIBUTE eAttribute) { | 139 Property(pValue, XFA_Event::FullText, bSetting); |
154 Script_EventPseudoModel_Property(pValue, XFA_Event::FullText, bSetting); | |
155 } | 140 } |
156 void CScript_EventPseudoModel::Script_EventPseudoModel_KeyDown( | 141 void CScript_EventPseudoModel::KeyDown(CFXJSE_Value* pValue, |
157 CFXJSE_Value* pValue, | 142 FX_BOOL bSetting, |
158 FX_BOOL bSetting, | 143 XFA_ATTRIBUTE eAttribute) { |
159 XFA_ATTRIBUTE eAttribute) { | 144 Property(pValue, XFA_Event::Keydown, bSetting); |
160 Script_EventPseudoModel_Property(pValue, XFA_Event::Keydown, bSetting); | |
161 } | 145 } |
162 void CScript_EventPseudoModel::Script_EventPseudoModel_Modifier( | 146 void CScript_EventPseudoModel::Modifier(CFXJSE_Value* pValue, |
163 CFXJSE_Value* pValue, | 147 FX_BOOL bSetting, |
164 FX_BOOL bSetting, | 148 XFA_ATTRIBUTE eAttribute) { |
165 XFA_ATTRIBUTE eAttribute) { | 149 Property(pValue, XFA_Event::Modifier, bSetting); |
166 Script_EventPseudoModel_Property(pValue, XFA_Event::Modifier, bSetting); | |
167 } | 150 } |
168 void CScript_EventPseudoModel::Script_EventPseudoModel_NewContentType( | 151 void CScript_EventPseudoModel::NewContentType(CFXJSE_Value* pValue, |
169 CFXJSE_Value* pValue, | 152 FX_BOOL bSetting, |
170 FX_BOOL bSetting, | 153 XFA_ATTRIBUTE eAttribute) { |
171 XFA_ATTRIBUTE eAttribute) { | 154 Property(pValue, XFA_Event::NewContentType, bSetting); |
172 Script_EventPseudoModel_Property(pValue, XFA_Event::NewContentType, bSetting); | |
173 } | 155 } |
174 void CScript_EventPseudoModel::Script_EventPseudoModel_NewText( | 156 void CScript_EventPseudoModel::NewText(CFXJSE_Value* pValue, |
175 CFXJSE_Value* pValue, | 157 FX_BOOL bSetting, |
176 FX_BOOL bSetting, | 158 XFA_ATTRIBUTE eAttribute) { |
177 XFA_ATTRIBUTE eAttribute) { | 159 Property(pValue, XFA_Event::NewText, bSetting); |
178 Script_EventPseudoModel_Property(pValue, XFA_Event::NewText, bSetting); | |
179 } | 160 } |
180 void CScript_EventPseudoModel::Script_EventPseudoModel_PrevContentType( | 161 void CScript_EventPseudoModel::PrevContentType(CFXJSE_Value* pValue, |
181 CFXJSE_Value* pValue, | 162 FX_BOOL bSetting, |
182 FX_BOOL bSetting, | 163 XFA_ATTRIBUTE eAttribute) { |
183 XFA_ATTRIBUTE eAttribute) { | 164 Property(pValue, XFA_Event::PreviousContentType, bSetting); |
184 Script_EventPseudoModel_Property(pValue, XFA_Event::PreviousContentType, | |
185 bSetting); | |
186 } | 165 } |
187 void CScript_EventPseudoModel::Script_EventPseudoModel_PrevText( | 166 void CScript_EventPseudoModel::PrevText(CFXJSE_Value* pValue, |
188 CFXJSE_Value* pValue, | 167 FX_BOOL bSetting, |
189 FX_BOOL bSetting, | 168 XFA_ATTRIBUTE eAttribute) { |
190 XFA_ATTRIBUTE eAttribute) { | 169 Property(pValue, XFA_Event::PreviousText, bSetting); |
191 Script_EventPseudoModel_Property(pValue, XFA_Event::PreviousText, bSetting); | |
192 } | 170 } |
193 void CScript_EventPseudoModel::Script_EventPseudoModel_Reenter( | 171 void CScript_EventPseudoModel::Reenter(CFXJSE_Value* pValue, |
194 CFXJSE_Value* pValue, | 172 FX_BOOL bSetting, |
195 FX_BOOL bSetting, | 173 XFA_ATTRIBUTE eAttribute) { |
196 XFA_ATTRIBUTE eAttribute) { | 174 Property(pValue, XFA_Event::Reenter, bSetting); |
197 Script_EventPseudoModel_Property(pValue, XFA_Event::Reenter, bSetting); | |
198 } | 175 } |
199 void CScript_EventPseudoModel::Script_EventPseudoModel_SelEnd( | 176 void CScript_EventPseudoModel::SelEnd(CFXJSE_Value* pValue, |
200 CFXJSE_Value* pValue, | 177 FX_BOOL bSetting, |
201 FX_BOOL bSetting, | 178 XFA_ATTRIBUTE eAttribute) { |
202 XFA_ATTRIBUTE eAttribute) { | 179 Property(pValue, XFA_Event::SelectionEnd, bSetting); |
203 Script_EventPseudoModel_Property(pValue, XFA_Event::SelectionEnd, bSetting); | |
204 } | 180 } |
205 void CScript_EventPseudoModel::Script_EventPseudoModel_SelStart( | 181 void CScript_EventPseudoModel::SelStart(CFXJSE_Value* pValue, |
206 CFXJSE_Value* pValue, | 182 FX_BOOL bSetting, |
207 FX_BOOL bSetting, | 183 XFA_ATTRIBUTE eAttribute) { |
208 XFA_ATTRIBUTE eAttribute) { | 184 Property(pValue, XFA_Event::SelectionStart, bSetting); |
209 Script_EventPseudoModel_Property(pValue, XFA_Event::SelectionStart, bSetting); | |
210 } | 185 } |
211 void CScript_EventPseudoModel::Script_EventPseudoModel_Shift( | 186 void CScript_EventPseudoModel::Shift(CFXJSE_Value* pValue, |
212 CFXJSE_Value* pValue, | 187 FX_BOOL bSetting, |
213 FX_BOOL bSetting, | 188 XFA_ATTRIBUTE eAttribute) { |
214 XFA_ATTRIBUTE eAttribute) { | 189 Property(pValue, XFA_Event::Shift, bSetting); |
215 Script_EventPseudoModel_Property(pValue, XFA_Event::Shift, bSetting); | |
216 } | 190 } |
217 void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultCode( | 191 void CScript_EventPseudoModel::SoapFaultCode(CFXJSE_Value* pValue, |
218 CFXJSE_Value* pValue, | 192 FX_BOOL bSetting, |
219 FX_BOOL bSetting, | 193 XFA_ATTRIBUTE eAttribute) { |
220 XFA_ATTRIBUTE eAttribute) { | 194 Property(pValue, XFA_Event::SoapFaultCode, bSetting); |
221 Script_EventPseudoModel_Property(pValue, XFA_Event::SoapFaultCode, bSetting); | |
222 } | 195 } |
223 void CScript_EventPseudoModel::Script_EventPseudoModel_SoapFaultString( | 196 void CScript_EventPseudoModel::SoapFaultString(CFXJSE_Value* pValue, |
224 CFXJSE_Value* pValue, | 197 FX_BOOL bSetting, |
225 FX_BOOL bSetting, | 198 XFA_ATTRIBUTE eAttribute) { |
226 XFA_ATTRIBUTE eAttribute) { | 199 Property(pValue, XFA_Event::SoapFaultString, bSetting); |
227 Script_EventPseudoModel_Property(pValue, XFA_Event::SoapFaultString, | |
228 bSetting); | |
229 } | 200 } |
230 void CScript_EventPseudoModel::Script_EventPseudoModel_Target( | 201 void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue, |
231 CFXJSE_Value* pValue, | 202 FX_BOOL bSetting, |
232 FX_BOOL bSetting, | 203 XFA_ATTRIBUTE eAttribute) { |
233 XFA_ATTRIBUTE eAttribute) { | 204 Property(pValue, XFA_Event::Target, bSetting); |
234 Script_EventPseudoModel_Property(pValue, XFA_Event::Target, bSetting); | |
235 } | 205 } |
236 void CScript_EventPseudoModel::Script_EventPseudoModel_Emit( | 206 void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) { |
237 CFXJSE_Arguments* pArguments) { | |
238 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 207 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
239 if (!pScriptContext) { | 208 if (!pScriptContext) { |
240 return; | 209 return; |
241 } | 210 } |
242 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | 211 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
243 if (!pEventParam) { | 212 if (!pEventParam) { |
244 return; | 213 return; |
245 } | 214 } |
246 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 215 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
247 if (!pNotify) { | 216 if (!pNotify) { |
248 return; | 217 return; |
249 } | 218 } |
250 CXFA_FFWidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler(); | 219 CXFA_FFWidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler(); |
251 if (!pWidgetHandler) { | 220 if (!pWidgetHandler) { |
252 return; | 221 return; |
253 } | 222 } |
254 pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); | 223 pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); |
255 } | 224 } |
256 void CScript_EventPseudoModel::Script_EventPseudoModel_Reset( | 225 void CScript_EventPseudoModel::Reset(CFXJSE_Arguments* pArguments) { |
257 CFXJSE_Arguments* pArguments) { | |
258 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 226 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
259 if (!pScriptContext) { | 227 if (!pScriptContext) { |
260 return; | 228 return; |
261 } | 229 } |
262 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); | 230 CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); |
263 if (!pEventParam) { | 231 if (!pEventParam) { |
264 return; | 232 return; |
265 } | 233 } |
266 pEventParam->Reset(); | 234 pEventParam->Reset(); |
267 } | 235 } |
OLD | NEW |