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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
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"
18 /* -------------------------- event -------------------------- */
20 BEGIN_JS_STATIC_CONST(CJS_Event)
23 BEGIN_JS_STATIC_PROP(CJS_Event)
24 JS_STATIC_PROP_ENTRY(change)
25 JS_STATIC_PROP_ENTRY(changeEx)
26 JS_STATIC_PROP_ENTRY(commitKey)
27 JS_STATIC_PROP_ENTRY(fieldFull)
28 JS_STATIC_PROP_ENTRY(keyDown)
29 JS_STATIC_PROP_ENTRY(modifier)
30 JS_STATIC_PROP_ENTRY(name)
31 JS_STATIC_PROP_ENTRY(rc)
32 JS_STATIC_PROP_ENTRY(richChange)
33 JS_STATIC_PROP_ENTRY(richChangeEx)
34 JS_STATIC_PROP_ENTRY(richValue)
35 JS_STATIC_PROP_ENTRY(selEnd)
36 JS_STATIC_PROP_ENTRY(selStart)
37 JS_STATIC_PROP_ENTRY(shift)
38 JS_STATIC_PROP_ENTRY(source)
39 JS_STATIC_PROP_ENTRY(target)
40 JS_STATIC_PROP_ENTRY(targetName)
41 JS_STATIC_PROP_ENTRY(type)
42 JS_STATIC_PROP_ENTRY(value)
43 JS_STATIC_PROP_ENTRY(willCommit)
46 BEGIN_JS_STATIC_METHOD(CJS_Event)
47 END_JS_STATIC_METHOD()
49 IMPLEMENT_JS_CLASS(CJS_Event,event)
51 event::event(CJS_Object * pJsObject) : CJS_EmbedObj(pJsObject)
59 FX_BOOL event::change(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
61 CJS_Context* pContext = (CJS_Context*)cc;
62 ASSERT(pContext != NULL);
63 CJS_EventHandler* pEvent = pContext->GetEventHandler();
64 ASSERT(pEvent != NULL);
66 CFX_WideString &wChange = pEvent->Change();
69 if (vp.GetType() == VT_string)
79 FX_BOOL event::changeEx(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
81 if (!vp.IsGetting())return FALSE;
83 CJS_Context* pContext = (CJS_Context*)cc;
84 ASSERT(pContext != NULL);
85 CJS_EventHandler* pEvent = pContext->GetEventHandler();
86 ASSERT(pEvent != NULL);
88 vp << pEvent->ChangeEx();
92 FX_BOOL event::commitKey(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
94 if (!vp.IsGetting())return FALSE;
96 CJS_Context* pContext = (CJS_Context*)cc;
97 ASSERT(pContext != NULL);
98 CJS_EventHandler* pEvent = pContext->GetEventHandler();
99 ASSERT(pEvent != NULL);
101 vp << pEvent->CommitKey();
105 FX_BOOL event::fieldFull(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
107 CJS_Context* pContext = (CJS_Context*)cc;
108 ASSERT(pContext != NULL);
109 CJS_EventHandler* pEvent = pContext->GetEventHandler();
110 ASSERT(pEvent != NULL);
112 if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
115 if (pEvent->FieldFull())
122 FX_BOOL event::keyDown(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
124 if (!vp.IsGetting())return FALSE;
126 CJS_Context* pContext = (CJS_Context*)cc;
127 ASSERT(pContext != NULL);
128 CJS_EventHandler* pEvent = pContext->GetEventHandler();
129 ASSERT(pEvent != NULL);
131 if (pEvent->KeyDown())
138 FX_BOOL event::modifier(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
140 if (!vp.IsGetting())return FALSE;
142 CJS_Context* pContext = (CJS_Context*)cc;
143 ASSERT(pContext != NULL);
144 CJS_EventHandler* pEvent = pContext->GetEventHandler();
145 ASSERT(pEvent != NULL);
147 if (pEvent->Modifier())
154 FX_BOOL event::name(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
156 if (!vp.IsGetting())return FALSE;
158 CJS_Context* pContext = (CJS_Context*)cc;
159 ASSERT(pContext != NULL);
160 CJS_EventHandler* pEvent = pContext->GetEventHandler();
161 ASSERT(pEvent != NULL);
163 vp << pEvent->Name();
167 FX_BOOL event::rc(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
169 CJS_Context* pContext = (CJS_Context*)cc;
170 ASSERT(pContext != NULL);
171 CJS_EventHandler* pEvent = pContext->GetEventHandler();
172 ASSERT(pEvent != NULL);
174 FX_BOOL &bRc = pEvent->Rc();
186 FX_BOOL event::richChange(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
199 FX_BOOL event::richChangeEx(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
213 FX_BOOL event::richValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
226 FX_BOOL event::selEnd(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
228 CJS_Context* pContext = (CJS_Context*)cc;
229 ASSERT(pContext != NULL);
230 CJS_EventHandler* pEvent = pContext->GetEventHandler();
231 ASSERT(pEvent != NULL);
233 if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
238 int &iSelEnd = pEvent->SelEnd();
250 FX_BOOL event::selStart(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
252 CJS_Context* pContext = (CJS_Context*)cc;
253 ASSERT(pContext != NULL);
254 CJS_EventHandler* pEvent = pContext->GetEventHandler();
255 ASSERT(pEvent != NULL);
257 if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
261 int &iSelStart = pEvent->SelStart();
273 FX_BOOL event::shift(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
275 if (!vp.IsGetting())return FALSE;
277 CJS_Context* pContext = (CJS_Context*)cc;
278 ASSERT(pContext != NULL);
279 CJS_EventHandler* pEvent = pContext->GetEventHandler();
280 ASSERT(pEvent != NULL);
289 FX_BOOL event::source(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
291 if (!vp.IsGetting())return FALSE;
293 CJS_Context* pContext = (CJS_Context*)cc;
294 ASSERT(pContext != NULL);
295 CJS_EventHandler* pEvent = pContext->GetEventHandler();
296 ASSERT(pEvent != NULL);
298 vp << pEvent->Source()->GetJSObject();
302 FX_BOOL event::target(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
304 if (!vp.IsGetting())return FALSE;
306 CJS_Context* pContext = (CJS_Context*)cc;
307 ASSERT(pContext != NULL);
308 CJS_EventHandler* pEvent = pContext->GetEventHandler();
309 ASSERT(pEvent != NULL);
311 vp<<pEvent->Target_Field()->GetJSObject();
315 FX_BOOL event::targetName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
317 if (!vp.IsGetting())return FALSE;
319 CJS_Context* pContext = (CJS_Context*)cc;
320 ASSERT(pContext != NULL);
321 CJS_EventHandler* pEvent = pContext->GetEventHandler();
322 ASSERT(pEvent != NULL);
324 vp << pEvent->TargetName();
328 FX_BOOL event::type(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
330 if (!vp.IsGetting())return FALSE;
332 CJS_Context* pContext = (CJS_Context*)cc;
333 ASSERT(pContext != NULL);
334 CJS_EventHandler* pEvent = pContext->GetEventHandler();
335 ASSERT(pEvent != NULL);
337 vp << pEvent->Type();
341 FX_BOOL event::value(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
343 CJS_Context* pContext = (CJS_Context*)cc;
344 ASSERT(pContext != NULL);
345 CJS_EventHandler* pEvent = pContext->GetEventHandler();
346 ASSERT(pEvent != NULL);
348 if (wcscmp((const wchar_t*)pEvent->Type(),L"Field") != 0)
350 if(!pEvent->m_pValue)
352 CFX_WideString & val = pEvent->Value();
364 FX_BOOL event::willCommit(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
366 if (!vp.IsGetting())return FALSE;
368 CJS_Context* pContext = (CJS_Context*)cc;
369 ASSERT(pContext != NULL);
370 CJS_EventHandler* pEvent = pContext->GetEventHandler();
371 ASSERT(pEvent != NULL);
373 if (pEvent->WillCommit())