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