blob: 2362c01287397653ceb42cdc2be4b2258375a52b [file] [log] [blame]
Svet Ganove6986e12015-06-04 14:52:15 -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.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -08004
Svet Ganove6986e12015-06-04 14:52:15 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -08007#include "event.h"
8
9#include "Field.h"
10#include "JS_Context.h"
11#include "JS_Define.h"
12#include "JS_EventHandler.h"
13#include "JS_Object.h"
14#include "JS_Value.h"
15#include "fpdfsdk/include/javascript/IJavaScript.h"
Svet Ganove6986e12015-06-04 14:52:15 -070016
17/* -------------------------- event -------------------------- */
18
19BEGIN_JS_STATIC_CONST(CJS_Event)
20END_JS_STATIC_CONST()
21
22BEGIN_JS_STATIC_PROP(CJS_Event)
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080023JS_STATIC_PROP_ENTRY(change)
24JS_STATIC_PROP_ENTRY(changeEx)
25JS_STATIC_PROP_ENTRY(commitKey)
26JS_STATIC_PROP_ENTRY(fieldFull)
27JS_STATIC_PROP_ENTRY(keyDown)
28JS_STATIC_PROP_ENTRY(modifier)
29JS_STATIC_PROP_ENTRY(name)
30JS_STATIC_PROP_ENTRY(rc)
31JS_STATIC_PROP_ENTRY(richChange)
32JS_STATIC_PROP_ENTRY(richChangeEx)
33JS_STATIC_PROP_ENTRY(richValue)
34JS_STATIC_PROP_ENTRY(selEnd)
35JS_STATIC_PROP_ENTRY(selStart)
36JS_STATIC_PROP_ENTRY(shift)
37JS_STATIC_PROP_ENTRY(source)
38JS_STATIC_PROP_ENTRY(target)
39JS_STATIC_PROP_ENTRY(targetName)
40JS_STATIC_PROP_ENTRY(type)
41JS_STATIC_PROP_ENTRY(value)
42JS_STATIC_PROP_ENTRY(willCommit)
Svet Ganove6986e12015-06-04 14:52:15 -070043END_JS_STATIC_PROP()
44
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080045BEGIN_JS_STATIC_METHOD(CJS_Event)
Svet Ganove6986e12015-06-04 14:52:15 -070046END_JS_STATIC_METHOD()
47
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080048IMPLEMENT_JS_CLASS(CJS_Event, event)
Svet Ganove6986e12015-06-04 14:52:15 -070049
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080050event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {}
51
52event::~event() {
Svet Ganove6986e12015-06-04 14:52:15 -070053}
54
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080055FX_BOOL event::change(IJS_Context* cc,
56 CJS_PropValue& vp,
57 CFX_WideString& sError) {
58 CJS_Context* pContext = (CJS_Context*)cc;
59 CJS_EventHandler* pEvent = pContext->GetEventHandler();
60 CFX_WideString& wChange = pEvent->Change();
61 if (vp.IsSetting()) {
62 if (vp.GetType() == CJS_Value::VT_string)
63 vp >> wChange;
64 } else {
65 vp << wChange;
66 }
67 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -070068}
69
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080070FX_BOOL event::changeEx(IJS_Context* cc,
71 CJS_PropValue& vp,
72 CFX_WideString& sError) {
73 if (!vp.IsGetting())
74 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -070075
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080076 CJS_Context* pContext = (CJS_Context*)cc;
77 CJS_EventHandler* pEvent = pContext->GetEventHandler();
78
79 vp << pEvent->ChangeEx();
80 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -070081}
82
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080083FX_BOOL event::commitKey(IJS_Context* cc,
84 CJS_PropValue& vp,
85 CFX_WideString& sError) {
86 if (!vp.IsGetting())
87 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -070088
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080089 CJS_Context* pContext = (CJS_Context*)cc;
90 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -070091
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080092 vp << pEvent->CommitKey();
93 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -070094}
95
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080096FX_BOOL event::fieldFull(IJS_Context* cc,
97 CJS_PropValue& vp,
98 CFX_WideString& sError) {
99 CJS_Context* pContext = (CJS_Context*)cc;
100 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700101
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800102 if (!vp.IsGetting() &&
103 wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
104 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700105
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800106 if (pEvent->FieldFull())
107 vp << TRUE;
108 else
109 vp << FALSE;
110 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700111}
112
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800113FX_BOOL event::keyDown(IJS_Context* cc,
114 CJS_PropValue& vp,
115 CFX_WideString& sError) {
116 if (!vp.IsGetting())
117 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700118
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800119 CJS_Context* pContext = (CJS_Context*)cc;
120 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700121
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800122 if (pEvent->KeyDown())
123 vp << TRUE;
124 else
125 vp << FALSE;
126 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700127}
128
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800129FX_BOOL event::modifier(IJS_Context* cc,
130 CJS_PropValue& vp,
131 CFX_WideString& sError) {
132 if (!vp.IsGetting())
133 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700134
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800135 CJS_Context* pContext = (CJS_Context*)cc;
136 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700137
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800138 if (pEvent->Modifier())
139 vp << TRUE;
140 else
141 vp << FALSE;
142 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700143}
144
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800145FX_BOOL event::name(IJS_Context* cc,
146 CJS_PropValue& vp,
147 CFX_WideString& sError) {
148 if (!vp.IsGetting())
149 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700150
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800151 CJS_Context* pContext = (CJS_Context*)cc;
152 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700153
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800154 vp << pEvent->Name();
155 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700156}
157
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800158FX_BOOL event::rc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
159 CJS_Context* pContext = (CJS_Context*)cc;
160 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700161
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800162 FX_BOOL& bRc = pEvent->Rc();
163 if (vp.IsSetting()) {
164 vp >> bRc;
165 } else {
166 vp << bRc;
167 }
168 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700169}
170
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800171FX_BOOL event::richChange(IJS_Context* cc,
172 CJS_PropValue& vp,
173 CFX_WideString& sError) {
174 return TRUE;
175 if (vp.IsSetting()) {
176 } else {
177 ;
178 }
179 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700180}
181
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800182FX_BOOL event::richChangeEx(IJS_Context* cc,
183 CJS_PropValue& vp,
184 CFX_WideString& sError) {
185 return TRUE;
186 if (vp.IsSetting()) {
187 } else {
188 ;
189 }
190 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700191}
192
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800193FX_BOOL event::richValue(IJS_Context* cc,
194 CJS_PropValue& vp,
195 CFX_WideString& sError) {
196 return TRUE;
197 if (vp.IsSetting()) {
198 } else {
199 ;
200 }
201 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700202}
203
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800204FX_BOOL event::selEnd(IJS_Context* cc,
205 CJS_PropValue& vp,
206 CFX_WideString& sError) {
207 CJS_Context* pContext = (CJS_Context*)cc;
208 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700209
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800210 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) {
211 return TRUE;
212 }
213
214 int& iSelEnd = pEvent->SelEnd();
215 if (vp.IsSetting()) {
216 vp >> iSelEnd;
217 } else {
218 vp << iSelEnd;
219 }
220 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700221}
222
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800223FX_BOOL event::selStart(IJS_Context* cc,
224 CJS_PropValue& vp,
225 CFX_WideString& sError) {
226 CJS_Context* pContext = (CJS_Context*)cc;
227 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700228
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800229 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) {
230 return TRUE;
231 }
232 int& iSelStart = pEvent->SelStart();
233 if (vp.IsSetting()) {
234 vp >> iSelStart;
235 } else {
236 vp << iSelStart;
237 }
238 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700239}
240
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800241FX_BOOL event::shift(IJS_Context* cc,
242 CJS_PropValue& vp,
243 CFX_WideString& sError) {
244 if (!vp.IsGetting())
245 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700246
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800247 CJS_Context* pContext = (CJS_Context*)cc;
248 CJS_EventHandler* pEvent = pContext->GetEventHandler();
249
250 if (pEvent->Shift())
251 vp << TRUE;
252 else
253 vp << FALSE;
254 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700255}
256
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800257FX_BOOL event::source(IJS_Context* cc,
258 CJS_PropValue& vp,
259 CFX_WideString& sError) {
260 if (!vp.IsGetting())
261 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700262
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800263 CJS_Context* pContext = (CJS_Context*)cc;
264 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700265
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800266 vp << pEvent->Source()->GetJSObject();
267 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700268}
269
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800270FX_BOOL event::target(IJS_Context* cc,
271 CJS_PropValue& vp,
272 CFX_WideString& sError) {
273 if (!vp.IsGetting())
274 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700275
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800276 CJS_Context* pContext = (CJS_Context*)cc;
277 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700278
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800279 vp << pEvent->Target_Field()->GetJSObject();
280 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700281}
282
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800283FX_BOOL event::targetName(IJS_Context* cc,
284 CJS_PropValue& vp,
285 CFX_WideString& sError) {
286 if (!vp.IsGetting())
287 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700288
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800289 CJS_Context* pContext = (CJS_Context*)cc;
290 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700291
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800292 vp << pEvent->TargetName();
293 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700294}
295
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800296FX_BOOL event::type(IJS_Context* cc,
297 CJS_PropValue& vp,
298 CFX_WideString& sError) {
299 if (!vp.IsGetting())
300 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700301
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800302 CJS_Context* pContext = (CJS_Context*)cc;
303 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700304
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800305 vp << pEvent->Type();
306 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700307}
308
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800309FX_BOOL event::value(IJS_Context* cc,
310 CJS_PropValue& vp,
311 CFX_WideString& sError) {
312 CJS_Context* pContext = (CJS_Context*)cc;
313 CJS_EventHandler* pEvent = pContext->GetEventHandler();
Svet Ganove6986e12015-06-04 14:52:15 -0700314
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800315 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
316 return FALSE;
317 if (!pEvent->m_pValue)
318 return FALSE;
319 CFX_WideString& val = pEvent->Value();
320 if (vp.IsSetting()) {
321 vp >> val;
322 } else {
323 vp << val;
324 }
325 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700326}
327
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800328FX_BOOL event::willCommit(IJS_Context* cc,
329 CJS_PropValue& vp,
330 CFX_WideString& sError) {
331 if (!vp.IsGetting())
332 return FALSE;
Svet Ganove6986e12015-06-04 14:52:15 -0700333
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800334 CJS_Context* pContext = (CJS_Context*)cc;
335 CJS_EventHandler* pEvent = pContext->GetEventHandler();
336
337 if (pEvent->WillCommit())
338 vp << TRUE;
339 else
340 vp << FALSE;
341 return TRUE;
Svet Ganove6986e12015-06-04 14:52:15 -0700342}