blob: 4bcdcce3a0b610218a5878c0d1e2faa5f3c2b23f [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../../include/javascript/JavaScript.h"
8#include "../../include/javascript/IJavaScript.h"
9#include "../../include/javascript/JS_Define.h"
10#include "../../include/javascript/JS_Object.h"
11#include "../../include/javascript/JS_Value.h"
12#include "../../include/javascript/JS_EventHandler.h"
13//#include "../include/JS_ResMgr.h"
14#include "../../include/javascript/JS_Context.h"
15#include "../../include/javascript/event.h"
16#include "../../include/javascript/Field.h"
17
18/* -------------------------- event -------------------------- */
19
20BEGIN_JS_STATIC_CONST(CJS_Event)
21END_JS_STATIC_CONST()
22
23BEGIN_JS_STATIC_PROP(CJS_Event)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024JS_STATIC_PROP_ENTRY(change)
25JS_STATIC_PROP_ENTRY(changeEx)
26JS_STATIC_PROP_ENTRY(commitKey)
27JS_STATIC_PROP_ENTRY(fieldFull)
28JS_STATIC_PROP_ENTRY(keyDown)
29JS_STATIC_PROP_ENTRY(modifier)
30JS_STATIC_PROP_ENTRY(name)
31JS_STATIC_PROP_ENTRY(rc)
32JS_STATIC_PROP_ENTRY(richChange)
33JS_STATIC_PROP_ENTRY(richChangeEx)
34JS_STATIC_PROP_ENTRY(richValue)
35JS_STATIC_PROP_ENTRY(selEnd)
36JS_STATIC_PROP_ENTRY(selStart)
37JS_STATIC_PROP_ENTRY(shift)
38JS_STATIC_PROP_ENTRY(source)
39JS_STATIC_PROP_ENTRY(target)
40JS_STATIC_PROP_ENTRY(targetName)
41JS_STATIC_PROP_ENTRY(type)
42JS_STATIC_PROP_ENTRY(value)
43JS_STATIC_PROP_ENTRY(willCommit)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044END_JS_STATIC_PROP()
45
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070046BEGIN_JS_STATIC_METHOD(CJS_Event)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047END_JS_STATIC_METHOD()
48
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049IMPLEMENT_JS_CLASS(CJS_Event, event)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {}
52
53event::~event(void) {}
54
55FX_BOOL event::change(IFXJS_Context* cc,
56 CJS_PropValue& vp,
57 CFX_WideString& sError) {
58 CJS_Context* pContext = (CJS_Context*)cc;
59 ASSERT(pContext != NULL);
60 CJS_EventHandler* pEvent = pContext->GetEventHandler();
61 ASSERT(pEvent != NULL);
62
63 CFX_WideString& wChange = pEvent->Change();
64 if (vp.IsSetting()) {
65 if (vp.GetType() == VT_string)
66 vp >> wChange;
67 } else {
68 vp << wChange;
69 }
70 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073FX_BOOL event::changeEx(IFXJS_Context* cc,
74 CJS_PropValue& vp,
75 CFX_WideString& sError) {
76 if (!vp.IsGetting())
77 return FALSE;
78
79 CJS_Context* pContext = (CJS_Context*)cc;
80 ASSERT(pContext != NULL);
81 CJS_EventHandler* pEvent = pContext->GetEventHandler();
82 ASSERT(pEvent != NULL);
83
84 vp << pEvent->ChangeEx();
85 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086}
87
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088FX_BOOL event::commitKey(IFXJS_Context* cc,
89 CJS_PropValue& vp,
90 CFX_WideString& sError) {
91 if (!vp.IsGetting())
92 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 CJS_Context* pContext = (CJS_Context*)cc;
95 ASSERT(pContext != NULL);
96 CJS_EventHandler* pEvent = pContext->GetEventHandler();
97 ASSERT(pEvent != NULL);
98
99 vp << pEvent->CommitKey();
100 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101}
102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103FX_BOOL event::fieldFull(IFXJS_Context* cc,
104 CJS_PropValue& vp,
105 CFX_WideString& sError) {
106 CJS_Context* pContext = (CJS_Context*)cc;
107 ASSERT(pContext != NULL);
108 CJS_EventHandler* pEvent = pContext->GetEventHandler();
109 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 if (!vp.IsGetting() &&
112 wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
113 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 if (pEvent->FieldFull())
116 vp << TRUE;
117 else
118 vp << FALSE;
119 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120}
121
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122FX_BOOL event::keyDown(IFXJS_Context* cc,
123 CJS_PropValue& vp,
124 CFX_WideString& sError) {
125 if (!vp.IsGetting())
126 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 CJS_Context* pContext = (CJS_Context*)cc;
129 ASSERT(pContext != NULL);
130 CJS_EventHandler* pEvent = pContext->GetEventHandler();
131 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 if (pEvent->KeyDown())
134 vp << TRUE;
135 else
136 vp << FALSE;
137 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700138}
139
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140FX_BOOL event::modifier(IFXJS_Context* cc,
141 CJS_PropValue& vp,
142 CFX_WideString& sError) {
143 if (!vp.IsGetting())
144 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 CJS_Context* pContext = (CJS_Context*)cc;
147 ASSERT(pContext != NULL);
148 CJS_EventHandler* pEvent = pContext->GetEventHandler();
149 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 if (pEvent->Modifier())
152 vp << TRUE;
153 else
154 vp << FALSE;
155 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156}
157
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158FX_BOOL event::name(IFXJS_Context* cc,
159 CJS_PropValue& vp,
160 CFX_WideString& sError) {
161 if (!vp.IsGetting())
162 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 CJS_Context* pContext = (CJS_Context*)cc;
165 ASSERT(pContext != NULL);
166 CJS_EventHandler* pEvent = pContext->GetEventHandler();
167 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 vp << pEvent->Name();
170 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171}
172
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173FX_BOOL event::rc(IFXJS_Context* cc,
174 CJS_PropValue& vp,
175 CFX_WideString& sError) {
176 CJS_Context* pContext = (CJS_Context*)cc;
177 ASSERT(pContext != NULL);
178 CJS_EventHandler* pEvent = pContext->GetEventHandler();
179 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 FX_BOOL& bRc = pEvent->Rc();
182 if (vp.IsSetting()) {
183 vp >> bRc;
184 } else {
185 vp << bRc;
186 }
187 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188}
189
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190FX_BOOL event::richChange(IFXJS_Context* cc,
191 CJS_PropValue& vp,
192 CFX_WideString& sError) {
193 return TRUE;
194 if (vp.IsSetting()) {
195 } else {
196 ;
197 }
198 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199}
200
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201FX_BOOL event::richChangeEx(IFXJS_Context* cc,
202 CJS_PropValue& vp,
203 CFX_WideString& sError) {
204 return TRUE;
205 if (vp.IsSetting()) {
206 } else {
207 ;
208 }
209 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212FX_BOOL event::richValue(IFXJS_Context* cc,
213 CJS_PropValue& vp,
214 CFX_WideString& sError) {
215 return TRUE;
216 if (vp.IsSetting()) {
217 } else {
218 ;
219 }
220 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221}
222
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223FX_BOOL event::selEnd(IFXJS_Context* cc,
224 CJS_PropValue& vp,
225 CFX_WideString& sError) {
226 CJS_Context* pContext = (CJS_Context*)cc;
227 ASSERT(pContext != NULL);
228 CJS_EventHandler* pEvent = pContext->GetEventHandler();
229 ASSERT(pEvent != NULL);
230
231 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) {
232 return TRUE;
233 }
234
235 int& iSelEnd = pEvent->SelEnd();
236 if (vp.IsSetting()) {
237 vp >> iSelEnd;
238 } else {
239 vp << iSelEnd;
240 }
241 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242}
243
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244FX_BOOL event::selStart(IFXJS_Context* cc,
245 CJS_PropValue& vp,
246 CFX_WideString& sError) {
247 CJS_Context* pContext = (CJS_Context*)cc;
248 ASSERT(pContext != NULL);
249 CJS_EventHandler* pEvent = pContext->GetEventHandler();
250 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) {
253 return TRUE;
254 }
255 int& iSelStart = pEvent->SelStart();
256 if (vp.IsSetting()) {
257 vp >> iSelStart;
258 } else {
259 vp << iSelStart;
260 }
261 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262}
263
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264FX_BOOL event::shift(IFXJS_Context* cc,
265 CJS_PropValue& vp,
266 CFX_WideString& sError) {
267 if (!vp.IsGetting())
268 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 CJS_Context* pContext = (CJS_Context*)cc;
271 ASSERT(pContext != NULL);
272 CJS_EventHandler* pEvent = pContext->GetEventHandler();
273 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 if (pEvent->Shift())
276 vp << TRUE;
277 else
278 vp << FALSE;
279 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700280}
281
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282FX_BOOL event::source(IFXJS_Context* cc,
283 CJS_PropValue& vp,
284 CFX_WideString& sError) {
285 if (!vp.IsGetting())
286 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 CJS_Context* pContext = (CJS_Context*)cc;
289 ASSERT(pContext != NULL);
290 CJS_EventHandler* pEvent = pContext->GetEventHandler();
291 ASSERT(pEvent != NULL);
292
293 vp << pEvent->Source()->GetJSObject();
294 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295}
296
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297FX_BOOL event::target(IFXJS_Context* cc,
298 CJS_PropValue& vp,
299 CFX_WideString& sError) {
300 if (!vp.IsGetting())
301 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 CJS_Context* pContext = (CJS_Context*)cc;
304 ASSERT(pContext != NULL);
305 CJS_EventHandler* pEvent = pContext->GetEventHandler();
306 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700307
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308 vp << pEvent->Target_Field()->GetJSObject();
309 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310}
311
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312FX_BOOL event::targetName(IFXJS_Context* cc,
313 CJS_PropValue& vp,
314 CFX_WideString& sError) {
315 if (!vp.IsGetting())
316 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 CJS_Context* pContext = (CJS_Context*)cc;
319 ASSERT(pContext != NULL);
320 CJS_EventHandler* pEvent = pContext->GetEventHandler();
321 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700322
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 vp << pEvent->TargetName();
324 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700325}
326
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327FX_BOOL event::type(IFXJS_Context* cc,
328 CJS_PropValue& vp,
329 CFX_WideString& sError) {
330 if (!vp.IsGetting())
331 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700332
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 CJS_Context* pContext = (CJS_Context*)cc;
334 ASSERT(pContext != NULL);
335 CJS_EventHandler* pEvent = pContext->GetEventHandler();
336 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700337
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 vp << pEvent->Type();
339 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700340}
341
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342FX_BOOL event::value(IFXJS_Context* cc,
343 CJS_PropValue& vp,
344 CFX_WideString& sError) {
345 CJS_Context* pContext = (CJS_Context*)cc;
346 ASSERT(pContext != NULL);
347 CJS_EventHandler* pEvent = pContext->GetEventHandler();
348 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
351 return FALSE;
352 if (!pEvent->m_pValue)
353 return FALSE;
354 CFX_WideString& val = pEvent->Value();
355 if (vp.IsSetting()) {
356 vp >> val;
357 } else {
358 vp << val;
359 }
360 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700361}
362
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363FX_BOOL event::willCommit(IFXJS_Context* cc,
364 CJS_PropValue& vp,
365 CFX_WideString& sError) {
366 if (!vp.IsGetting())
367 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 CJS_Context* pContext = (CJS_Context*)cc;
370 ASSERT(pContext != NULL);
371 CJS_EventHandler* pEvent = pContext->GetEventHandler();
372 ASSERT(pEvent != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 if (pEvent->WillCommit())
375 vp << TRUE;
376 else
377 vp << FALSE;
378 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700379}