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