John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 7 | #include "fxjs/cjs_event.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 8 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 9 | #include "fxjs/JS_Define.h" |
| 10 | #include "fxjs/cjs_event_context.h" |
| 11 | #include "fxjs/cjs_eventhandler.h" |
| 12 | #include "fxjs/cjs_field.h" |
| 13 | #include "fxjs/cjs_object.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | |
Dan Sinclair | c94a793 | 2017-10-26 16:48:57 -0400 | [diff] [blame] | 15 | const JSPropertySpec CJS_Event::PropertySpecs[] = { |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 16 | {"change", get_change_static, set_change_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 17 | {"changeEx", get_change_ex_static, set_change_ex_static}, |
| 18 | {"commitKey", get_commit_key_static, set_commit_key_static}, |
| 19 | {"fieldFull", get_field_full_static, set_field_full_static}, |
| 20 | {"keyDown", get_key_down_static, set_key_down_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 21 | {"modifier", get_modifier_static, set_modifier_static}, |
| 22 | {"name", get_name_static, set_name_static}, |
| 23 | {"rc", get_rc_static, set_rc_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 24 | {"richChange", get_rich_change_static, set_rich_change_static}, |
| 25 | {"richChangeEx", get_rich_change_ex_static, set_rich_change_ex_static}, |
| 26 | {"richValue", get_rich_value_static, set_rich_value_static}, |
| 27 | {"selEnd", get_sel_end_static, set_sel_end_static}, |
| 28 | {"selStart", get_sel_start_static, set_sel_start_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 29 | {"shift", get_shift_static, set_shift_static}, |
| 30 | {"source", get_source_static, set_source_static}, |
| 31 | {"target", get_target_static, set_target_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 32 | {"targetName", get_target_name_static, set_target_name_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 33 | {"type", get_type_static, set_type_static}, |
| 34 | {"value", get_value_static, set_value_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 35 | {"willCommit", get_will_commit_static, set_will_commit_static}, |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 36 | {0, 0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | |
Dan Sinclair | ef29953 | 2017-10-26 16:48:30 -0400 | [diff] [blame] | 38 | int CJS_Event::ObjDefnID = -1; |
Dan Sinclair | 89d26c8 | 2017-10-26 12:21:28 -0400 | [diff] [blame] | 39 | |
Dan Sinclair | ef29953 | 2017-10-26 16:48:30 -0400 | [diff] [blame] | 40 | // static |
Dan Sinclair | bef4d3e | 2017-10-26 16:49:38 -0400 | [diff] [blame] | 41 | void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) { |
| 42 | ObjDefnID = pEngine->DefineObj("event", FXJSOBJTYPE_STATIC, |
| 43 | JSConstructor<CJS_Event, event>, |
| 44 | JSDestructor<CJS_Event>); |
Dan Sinclair | ef29953 | 2017-10-26 16:48:30 -0400 | [diff] [blame] | 45 | DefineProps(pEngine, ObjDefnID, PropertySpecs); |
Dan Sinclair | 89d26c8 | 2017-10-26 12:21:28 -0400 | [diff] [blame] | 46 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} |
| 49 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 50 | event::~event() {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 52 | CJS_Return event::get_change(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 53 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 54 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 55 | return CJS_Return(pRuntime->NewString(pEvent->Change().c_str())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 58 | CJS_Return event::set_change(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 59 | CJS_EventHandler* pEvent = |
| 60 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 61 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 62 | if (vp->IsString()) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 63 | WideString& wChange = pEvent->Change(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 64 | wChange = pRuntime->ToWideString(vp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 66 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 69 | CJS_Return event::get_change_ex(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 70 | CJS_EventHandler* pEvent = |
| 71 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 72 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 73 | return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().c_str())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 76 | CJS_Return event::set_change_ex(CJS_Runtime* pRuntime, |
| 77 | v8::Local<v8::Value> vp) { |
| 78 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 81 | CJS_Return event::get_commit_key(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 82 | CJS_EventHandler* pEvent = |
| 83 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 84 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 85 | return CJS_Return(pRuntime->NewNumber(pEvent->CommitKey())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 88 | CJS_Return event::set_commit_key(CJS_Runtime* pRuntime, |
| 89 | v8::Local<v8::Value> vp) { |
| 90 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 93 | CJS_Return event::get_field_full(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 94 | CJS_EventHandler* pEvent = |
| 95 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 96 | |
| 97 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 98 | return CJS_Return(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 100 | return CJS_Return(pRuntime->NewBoolean(pEvent->FieldFull())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 103 | CJS_Return event::set_field_full(CJS_Runtime* pRuntime, |
| 104 | v8::Local<v8::Value> vp) { |
| 105 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 108 | CJS_Return event::get_key_down(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 109 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 110 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 111 | return CJS_Return(pRuntime->NewBoolean(pEvent->KeyDown())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 114 | CJS_Return event::set_key_down(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 115 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 116 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 117 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 118 | CJS_Return event::get_modifier(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 119 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 120 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 121 | return CJS_Return(pRuntime->NewBoolean(pEvent->Modifier())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 124 | CJS_Return event::set_modifier(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 125 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 128 | CJS_Return event::get_name(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 129 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 130 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 131 | return CJS_Return(pRuntime->NewString(pEvent->Name())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 134 | CJS_Return event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 135 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 136 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 137 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 138 | CJS_Return event::get_rc(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 139 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 140 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 141 | return CJS_Return(pRuntime->NewBoolean(pEvent->Rc())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 144 | CJS_Return event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 145 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 146 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 147 | pEvent->Rc() = pRuntime->ToBoolean(vp); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 148 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 151 | CJS_Return event::get_rich_change(CJS_Runtime* pRuntime) { |
| 152 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 155 | CJS_Return event::set_rich_change(CJS_Runtime* pRuntime, |
| 156 | v8::Local<v8::Value> vp) { |
| 157 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 160 | CJS_Return event::get_rich_change_ex(CJS_Runtime* pRuntime) { |
| 161 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 164 | CJS_Return event::set_rich_change_ex(CJS_Runtime* pRuntime, |
| 165 | v8::Local<v8::Value> vp) { |
| 166 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 169 | CJS_Return event::get_rich_value(CJS_Runtime* pRuntime) { |
| 170 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 173 | CJS_Return event::set_rich_value(CJS_Runtime* pRuntime, |
| 174 | v8::Local<v8::Value> vp) { |
| 175 | return CJS_Return(true); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 178 | CJS_Return event::get_sel_end(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 179 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 180 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 181 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 182 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 183 | return CJS_Return(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 184 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 185 | return CJS_Return(pRuntime->NewNumber(pEvent->SelEnd())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 188 | CJS_Return event::set_sel_end(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 189 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 190 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 191 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 192 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 193 | return CJS_Return(true); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 194 | |
Lei Zhang | fae5e26 | 2017-11-20 19:58:13 +0000 | [diff] [blame^] | 195 | pEvent->SetSelEnd(pRuntime->ToInt32(vp)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 196 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 199 | CJS_Return event::get_sel_start(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 200 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 201 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 203 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 204 | return CJS_Return(true); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 205 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 206 | return CJS_Return(pRuntime->NewNumber(pEvent->SelStart())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 209 | CJS_Return event::set_sel_start(CJS_Runtime* pRuntime, |
| 210 | v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 211 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 212 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 214 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 215 | return CJS_Return(true); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 216 | |
Lei Zhang | fae5e26 | 2017-11-20 19:58:13 +0000 | [diff] [blame^] | 217 | pEvent->SetSelStart(pRuntime->ToInt32(vp)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 218 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 221 | CJS_Return event::get_shift(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 222 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 223 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 224 | return CJS_Return(pRuntime->NewBoolean(pEvent->Shift())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 227 | CJS_Return event::set_shift(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 228 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 229 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 231 | CJS_Return event::get_source(CJS_Runtime* pRuntime) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 232 | CJS_EventHandler* pEvent = |
| 233 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 234 | return CJS_Return(pEvent->Source()->GetJSObject()->ToV8Object()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 237 | CJS_Return event::set_source(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 238 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 239 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 240 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 241 | CJS_Return event::get_target(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 242 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 243 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 244 | return CJS_Return(pEvent->Target_Field()->GetJSObject()->ToV8Object()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 247 | CJS_Return event::set_target(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 248 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 251 | CJS_Return event::get_target_name(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 252 | CJS_EventHandler* pEvent = |
| 253 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 254 | return CJS_Return(pRuntime->NewString(pEvent->TargetName().c_str())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 257 | CJS_Return event::set_target_name(CJS_Runtime* pRuntime, |
| 258 | v8::Local<v8::Value> vp) { |
| 259 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 262 | CJS_Return event::get_type(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 263 | CJS_EventHandler* pEvent = |
| 264 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 265 | return CJS_Return(pRuntime->NewString(pEvent->Type())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 268 | CJS_Return event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
| 269 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 270 | } |
| 271 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 272 | CJS_Return event::get_value(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 273 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 274 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 277 | return CJS_Return(false); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 278 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | if (!pEvent->m_pValue) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 280 | return CJS_Return(false); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 281 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 282 | return CJS_Return(pRuntime->NewString(pEvent->Value().c_str())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 285 | CJS_Return event::set_value(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 286 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 287 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 289 | if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 290 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 291 | |
| 292 | if (!pEvent->m_pValue) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 293 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 294 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 295 | pEvent->Value() = pRuntime->ToWideString(vp); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 296 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 298 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 299 | CJS_Return event::get_will_commit(CJS_Runtime* pRuntime) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 300 | CJS_EventHandler* pEvent = |
| 301 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 302 | return CJS_Return(pRuntime->NewBoolean(pEvent->WillCommit())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 305 | CJS_Return event::set_will_commit(CJS_Runtime* pRuntime, |
| 306 | v8::Local<v8::Value> vp) { |
| 307 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 308 | } |