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/cjs_event_context.h" |
| 10 | #include "fxjs/cjs_eventhandler.h" |
| 11 | #include "fxjs/cjs_field.h" |
| 12 | #include "fxjs/cjs_object.h" |
Tom Sepez | 221f0b3 | 2018-06-04 22:11:27 +0000 | [diff] [blame] | 13 | #include "fxjs/js_define.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 | 909fa2d | 2017-12-12 01:53:28 +0000 | [diff] [blame] | 35 | {"willCommit", get_will_commit_static, set_will_commit_static}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
Dan Sinclair | ef29953 | 2017-10-26 16:48:30 -0400 | [diff] [blame] | 37 | int CJS_Event::ObjDefnID = -1; |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 38 | const char CJS_Event::kName[] = "event"; |
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) { |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 42 | ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC, |
Dan Sinclair | 998fee3 | 2018-02-05 21:43:19 +0000 | [diff] [blame] | 43 | JSConstructor<CJS_Event>, JSDestructor); |
Dan Sinclair | 909fa2d | 2017-12-12 01:53:28 +0000 | [diff] [blame] | 44 | DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs)); |
Dan Sinclair | 89d26c8 | 2017-10-26 12:21:28 -0400 | [diff] [blame] | 45 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 47 | CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime) |
| 48 | : CJS_Object(pObject, pRuntime) {} |
Dan Sinclair | 998fee3 | 2018-02-05 21:43:19 +0000 | [diff] [blame] | 49 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 50 | CJS_Event::~CJS_Event() = default; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 52 | CJS_Return CJS_Event::get_change(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 53 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 54 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 55 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 56 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 57 | return CJS_Return(pRuntime->NewString(pEvent->Change().c_str())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 60 | CJS_Return CJS_Event::set_change(CJS_Runtime* pRuntime, |
| 61 | v8::Local<v8::Value> vp) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 62 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 63 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 64 | CJS_EventHandler* pEvent = |
| 65 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 66 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 67 | if (vp->IsString()) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 68 | WideString& wChange = pEvent->Change(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 69 | wChange = pRuntime->ToWideString(vp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | } |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 71 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 74 | CJS_Return CJS_Event::get_change_ex(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 75 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 76 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 77 | CJS_EventHandler* pEvent = |
| 78 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 79 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 80 | return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().c_str())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 83 | CJS_Return CJS_Event::set_change_ex(CJS_Runtime* pRuntime, |
| 84 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 85 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 88 | CJS_Return CJS_Event::get_commit_key(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 89 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 90 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 91 | CJS_EventHandler* pEvent = |
| 92 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 93 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 94 | return CJS_Return(pRuntime->NewNumber(pEvent->CommitKey())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 97 | CJS_Return CJS_Event::set_commit_key(CJS_Runtime* pRuntime, |
| 98 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 99 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 102 | CJS_Return CJS_Event::get_field_full(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 103 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 104 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 105 | CJS_EventHandler* pEvent = |
| 106 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
| 107 | |
| 108 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 109 | return CJS_Return(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 111 | return CJS_Return(pRuntime->NewBoolean(pEvent->FieldFull())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 114 | CJS_Return CJS_Event::set_field_full(CJS_Runtime* pRuntime, |
| 115 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 116 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 119 | CJS_Return CJS_Event::get_key_down(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 120 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 121 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 122 | return CJS_Return(pRuntime->NewBoolean(pEvent->KeyDown())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 125 | CJS_Return CJS_Event::set_key_down(CJS_Runtime* pRuntime, |
| 126 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 127 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 128 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 130 | CJS_Return CJS_Event::get_modifier(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 131 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 132 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 133 | return CJS_Return(pRuntime->NewBoolean(pEvent->Modifier())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 136 | CJS_Return CJS_Event::set_modifier(CJS_Runtime* pRuntime, |
| 137 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 138 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 139 | } |
| 140 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 141 | CJS_Return CJS_Event::get_name(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 142 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 143 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 144 | return CJS_Return(pRuntime->NewString(pEvent->Name())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 147 | CJS_Return CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 148 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 149 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 150 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 151 | CJS_Return CJS_Event::get_rc(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 152 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 153 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 154 | return CJS_Return(pRuntime->NewBoolean(pEvent->Rc())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 157 | CJS_Return CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 158 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 159 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 160 | pEvent->Rc() = pRuntime->ToBoolean(vp); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 161 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 164 | CJS_Return CJS_Event::get_rich_change(CJS_Runtime* pRuntime) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 165 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 168 | CJS_Return CJS_Event::set_rich_change(CJS_Runtime* pRuntime, |
| 169 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 170 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 173 | CJS_Return CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 174 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 177 | CJS_Return CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime, |
| 178 | v8::Local<v8::Value> vp) { |
| 179 | return CJS_Return(true); |
| 180 | } |
| 181 | |
| 182 | CJS_Return CJS_Event::get_rich_value(CJS_Runtime* pRuntime) { |
| 183 | return CJS_Return(true); |
| 184 | } |
| 185 | |
| 186 | CJS_Return CJS_Event::set_rich_value(CJS_Runtime* pRuntime, |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 187 | v8::Local<v8::Value> vp) { |
| 188 | return CJS_Return(true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 191 | CJS_Return CJS_Event::get_sel_end(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 192 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 193 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 194 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 195 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 196 | return CJS_Return(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 198 | return CJS_Return(pRuntime->NewNumber(pEvent->SelEnd())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 201 | CJS_Return CJS_Event::set_sel_end(CJS_Runtime* pRuntime, |
| 202 | v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 203 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 204 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 205 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 206 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 207 | return CJS_Return(true); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 208 | |
Lei Zhang | fae5e26 | 2017-11-20 19:58:13 +0000 | [diff] [blame] | 209 | pEvent->SetSelEnd(pRuntime->ToInt32(vp)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 210 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 213 | CJS_Return CJS_Event::get_sel_start(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 214 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 215 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 216 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 217 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 218 | return CJS_Return(true); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 219 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 220 | return CJS_Return(pRuntime->NewNumber(pEvent->SelStart())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 223 | CJS_Return CJS_Event::set_sel_start(CJS_Runtime* pRuntime, |
| 224 | v8::Local<v8::Value> vp) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 225 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 226 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 228 | if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 229 | return CJS_Return(true); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 230 | |
Lei Zhang | fae5e26 | 2017-11-20 19:58:13 +0000 | [diff] [blame] | 231 | pEvent->SetSelStart(pRuntime->ToInt32(vp)); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 232 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 235 | CJS_Return CJS_Event::get_shift(CJS_Runtime* pRuntime) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 236 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 237 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 238 | return CJS_Return(pRuntime->NewBoolean(pEvent->Shift())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 241 | CJS_Return CJS_Event::set_shift(CJS_Runtime* pRuntime, |
| 242 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 243 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 244 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 245 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 246 | CJS_Return CJS_Event::get_source(CJS_Runtime* pRuntime) { |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 247 | CJS_EventHandler* pEvent = |
| 248 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 249 | return CJS_Return(pEvent->Source()->ToV8Object()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 252 | CJS_Return CJS_Event::set_source(CJS_Runtime* pRuntime, |
| 253 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 254 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 255 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 256 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 257 | CJS_Return CJS_Event::get_target(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 258 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 259 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 260 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 261 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 262 | return CJS_Return(pEvent->Target_Field()->ToV8Object()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 265 | CJS_Return CJS_Event::set_target(CJS_Runtime* pRuntime, |
| 266 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 267 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 270 | CJS_Return CJS_Event::get_target_name(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 271 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 272 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 273 | CJS_EventHandler* pEvent = |
| 274 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 275 | return CJS_Return(pRuntime->NewString(pEvent->TargetName().c_str())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 278 | CJS_Return CJS_Event::set_target_name(CJS_Runtime* pRuntime, |
| 279 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 280 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 283 | CJS_Return CJS_Event::get_type(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 284 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 285 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 286 | CJS_EventHandler* pEvent = |
| 287 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 288 | return CJS_Return(pRuntime->NewString(pEvent->Type())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 291 | CJS_Return CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 292 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 295 | CJS_Return CJS_Event::get_value(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 296 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 297 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 298 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 299 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 300 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 302 | return CJS_Return(false); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 303 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | if (!pEvent->m_pValue) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 305 | return CJS_Return(false); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 306 | |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 307 | return CJS_Return(pRuntime->NewString(pEvent->Value().c_str())); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 310 | CJS_Return CJS_Event::set_value(CJS_Runtime* pRuntime, |
| 311 | v8::Local<v8::Value> vp) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 312 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 313 | |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 314 | CJS_EventHandler* pEvent = |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 315 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 316 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 317 | if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 318 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 319 | |
| 320 | if (!pEvent->m_pValue) |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 321 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 322 | |
dan sinclair | 80435cb | 2017-10-24 21:40:24 -0400 | [diff] [blame] | 323 | pEvent->Value() = pRuntime->ToWideString(vp); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 324 | return CJS_Return(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 325 | } |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 326 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 327 | CJS_Return CJS_Event::get_will_commit(CJS_Runtime* pRuntime) { |
Dan Sinclair | e9f7db9 | 2018-06-05 18:24:12 +0000 | [diff] [blame^] | 328 | ASSERT(pRuntime->GetCurrentEventContext()); |
| 329 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 330 | CJS_EventHandler* pEvent = |
| 331 | pRuntime->GetCurrentEventContext()->GetEventHandler(); |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 332 | return CJS_Return(pRuntime->NewBoolean(pEvent->WillCommit())); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Dan Sinclair | f743552 | 2018-02-05 22:27:22 +0000 | [diff] [blame] | 335 | CJS_Return CJS_Event::set_will_commit(CJS_Runtime* pRuntime, |
| 336 | v8::Local<v8::Value> vp) { |
Dan Sinclair | 8f524d6 | 2017-10-25 13:30:31 -0400 | [diff] [blame] | 337 | return CJS_Return(false); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 338 | } |