blob: 0895d9c00916106b7b8b668428b0b414adf35ffa [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclaire0345a42017-10-30 20:20:42 +00007#include "fxjs/cjs_event.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Dan Sinclaire0345a42017-10-30 20:20:42 +00009#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 Sepez221f0b32018-06-04 22:11:27 +000013#include "fxjs/js_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Dan Sinclairc94a7932017-10-26 16:48:57 -040015const JSPropertySpec CJS_Event::PropertySpecs[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -080016 {"change", get_change_static, set_change_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040017 {"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 Sepez4d5b8c52017-02-21 15:17:07 -080021 {"modifier", get_modifier_static, set_modifier_static},
22 {"name", get_name_static, set_name_static},
23 {"rc", get_rc_static, set_rc_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040024 {"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 Sepez4d5b8c52017-02-21 15:17:07 -080029 {"shift", get_shift_static, set_shift_static},
30 {"source", get_source_static, set_source_static},
31 {"target", get_target_static, set_target_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040032 {"targetName", get_target_name_static, set_target_name_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080033 {"type", get_type_static, set_type_static},
34 {"value", get_value_static, set_value_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +000035 {"willCommit", get_will_commit_static, set_will_commit_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
Dan Sinclairef299532017-10-26 16:48:30 -040037int CJS_Event::ObjDefnID = -1;
Dan Sinclairf7435522018-02-05 22:27:22 +000038const char CJS_Event::kName[] = "event";
Dan Sinclair89d26c82017-10-26 12:21:28 -040039
Dan Sinclairef299532017-10-26 16:48:30 -040040// static
Lei Zhangad1f7b42018-07-11 13:04:43 +000041int CJS_Event::GetObjDefnID() {
42 return ObjDefnID;
43}
44
45// static
Dan Sinclairbef4d3e2017-10-26 16:49:38 -040046void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
Dan Sinclairf7435522018-02-05 22:27:22 +000047 ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
Dan Sinclair998fee32018-02-05 21:43:19 +000048 JSConstructor<CJS_Event>, JSDestructor);
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000049 DefineProps(pEngine, ObjDefnID, PropertySpecs);
Dan Sinclair89d26c82017-10-26 12:21:28 -040050}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Tom Sepez36aae4f2018-06-04 19:44:37 +000052CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
53 : CJS_Object(pObject, pRuntime) {}
Dan Sinclair998fee32018-02-05 21:43:19 +000054
Dan Sinclairf7435522018-02-05 22:27:22 +000055CJS_Event::~CJS_Event() = default;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056
Tom Sepez3a6d0582018-08-17 19:28:52 +000057CJS_Result CJS_Event::get_change(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -080058 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -080059 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +000060 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +000061 pRuntime->NewString(pEvent->Change().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -040062}
63
Tom Sepez3a6d0582018-08-17 19:28:52 +000064CJS_Result CJS_Event::set_change(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +000065 v8::Local<v8::Value> vp) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +000066 ASSERT(pRuntime->GetCurrentEventContext());
67
dan sinclaircbe23db2017-10-19 14:29:33 -040068 CJS_EventHandler* pEvent =
69 pRuntime->GetCurrentEventContext()->GetEventHandler();
70
dan sinclair80435cb2017-10-24 21:40:24 -040071 if (vp->IsString()) {
dan sinclaircbe23db2017-10-19 14:29:33 -040072 WideString& wChange = pEvent->Change();
dan sinclair80435cb2017-10-24 21:40:24 -040073 wChange = pRuntime->ToWideString(vp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 }
Tom Sepez3a6d0582018-08-17 19:28:52 +000075 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076}
77
Tom Sepez3a6d0582018-08-17 19:28:52 +000078CJS_Result CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -040079 CJS_EventHandler* pEvent =
80 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +000081 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +000082 pRuntime->NewString(pEvent->ChangeEx().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -040083}
84
Tom Sepez3a6d0582018-08-17 19:28:52 +000085CJS_Result CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +000086 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +000087 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -040088}
89
Tom Sepez3a6d0582018-08-17 19:28:52 +000090CJS_Result CJS_Event::get_commit_key(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -040091 CJS_EventHandler* pEvent =
92 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +000093 return CJS_Result::Success(pRuntime->NewNumber(pEvent->CommitKey()));
dan sinclaircbe23db2017-10-19 14:29:33 -040094}
95
Tom Sepez3a6d0582018-08-17 19:28:52 +000096CJS_Result CJS_Event::set_commit_key(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +000097 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +000098 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -040099}
100
Tom Sepez3a6d0582018-08-17 19:28:52 +0000101CJS_Result CJS_Event::get_field_full(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400102 CJS_EventHandler* pEvent =
103 pRuntime->GetCurrentEventContext()->GetEventHandler();
dan sinclaircbe23db2017-10-19 14:29:33 -0400104 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000105 return CJS_Result::Failure(L"unrecognized event");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106
Tom Sepez3a6d0582018-08-17 19:28:52 +0000107 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->FieldFull()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400108}
109
Tom Sepez3a6d0582018-08-17 19:28:52 +0000110CJS_Result CJS_Event::set_field_full(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000111 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000112 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400113}
114
Tom Sepez3a6d0582018-08-17 19:28:52 +0000115CJS_Result CJS_Event::get_key_down(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800116 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800117 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000118 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->KeyDown()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119}
120
Tom Sepez3a6d0582018-08-17 19:28:52 +0000121CJS_Result CJS_Event::set_key_down(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000122 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000123 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400124}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Tom Sepez3a6d0582018-08-17 19:28:52 +0000126CJS_Result CJS_Event::get_modifier(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800127 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800128 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000129 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Modifier()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130}
131
Tom Sepez3a6d0582018-08-17 19:28:52 +0000132CJS_Result CJS_Event::set_modifier(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000133 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000134 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400135}
136
Tom Sepez3a6d0582018-08-17 19:28:52 +0000137CJS_Result CJS_Event::get_name(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800138 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800139 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000140 return CJS_Result::Success(pRuntime->NewString(pEvent->Name()));
tsepez4cf55152016-11-02 14:37:54 -0700141}
142
Tom Sepez3a6d0582018-08-17 19:28:52 +0000143CJS_Result CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
144 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400145}
tsepez4cf55152016-11-02 14:37:54 -0700146
Tom Sepez3a6d0582018-08-17 19:28:52 +0000147CJS_Result CJS_Event::get_rc(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800148 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800149 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000150 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Rc()));
tsepez4cf55152016-11-02 14:37:54 -0700151}
152
Tom Sepez3a6d0582018-08-17 19:28:52 +0000153CJS_Result CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800154 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800155 pRuntime->GetCurrentEventContext()->GetEventHandler();
dan sinclair80435cb2017-10-24 21:40:24 -0400156 pEvent->Rc() = pRuntime->ToBoolean(vp);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000157 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700158}
159
Tom Sepez3a6d0582018-08-17 19:28:52 +0000160CJS_Result CJS_Event::get_rich_change(CJS_Runtime* pRuntime) {
161 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700162}
163
Tom Sepez3a6d0582018-08-17 19:28:52 +0000164CJS_Result CJS_Event::set_rich_change(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000165 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000166 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700167}
168
Tom Sepez3a6d0582018-08-17 19:28:52 +0000169CJS_Result CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) {
170 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700171}
172
Tom Sepez3a6d0582018-08-17 19:28:52 +0000173CJS_Result CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000174 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000175 return CJS_Result::Success();
Dan Sinclairf7435522018-02-05 22:27:22 +0000176}
177
Tom Sepez3a6d0582018-08-17 19:28:52 +0000178CJS_Result CJS_Event::get_rich_value(CJS_Runtime* pRuntime) {
179 return CJS_Result::Success();
Dan Sinclairf7435522018-02-05 22:27:22 +0000180}
181
Tom Sepez3a6d0582018-08-17 19:28:52 +0000182CJS_Result CJS_Event::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -0400183 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000184 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700185}
186
Tom Sepez3a6d0582018-08-17 19:28:52 +0000187CJS_Result CJS_Event::get_sel_end(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800188 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800189 pRuntime->GetCurrentEventContext()->GetEventHandler();
tsepez4cf55152016-11-02 14:37:54 -0700190
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800191 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000192 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193
Tom Sepez3a6d0582018-08-17 19:28:52 +0000194 return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelEnd()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195}
196
Tom Sepez3a6d0582018-08-17 19:28:52 +0000197CJS_Result CJS_Event::set_sel_end(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000198 v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800199 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800200 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Tom Sepez20736f72018-08-17 16:44:50 +0000202 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") == 0)
203 pEvent->SetSelEnd(pRuntime->ToInt32(vp));
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800204
Tom Sepez3a6d0582018-08-17 19:28:52 +0000205 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206}
207
Tom Sepez3a6d0582018-08-17 19:28:52 +0000208CJS_Result CJS_Event::get_sel_start(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800209 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800210 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
dan sinclaircbe23db2017-10-19 14:29:33 -0400212 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000213 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400214
Tom Sepez3a6d0582018-08-17 19:28:52 +0000215 return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelStart()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216}
217
Tom Sepez3a6d0582018-08-17 19:28:52 +0000218CJS_Result CJS_Event::set_sel_start(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000219 v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800220 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800221 pRuntime->GetCurrentEventContext()->GetEventHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222
Tom Sepez20736f72018-08-17 16:44:50 +0000223 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") == 0)
224 pEvent->SetSelStart(pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -0400225
Tom Sepez3a6d0582018-08-17 19:28:52 +0000226 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
Tom Sepez3a6d0582018-08-17 19:28:52 +0000229CJS_Result CJS_Event::get_shift(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800230 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800231 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000232 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Shift()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233}
234
Tom Sepez3a6d0582018-08-17 19:28:52 +0000235CJS_Result CJS_Event::set_shift(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000236 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000237 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400238}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Tom Sepez3a6d0582018-08-17 19:28:52 +0000240CJS_Result CJS_Event::get_source(CJS_Runtime* pRuntime) {
Tom Sepezb1670b52017-02-16 17:01:00 -0800241 CJS_EventHandler* pEvent =
242 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000243 return CJS_Result::Success(pEvent->Source()->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244}
245
Tom Sepez3a6d0582018-08-17 19:28:52 +0000246CJS_Result CJS_Event::set_source(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000247 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000248 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400249}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250
Tom Sepez3a6d0582018-08-17 19:28:52 +0000251CJS_Result CJS_Event::get_target(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000252 ASSERT(pRuntime->GetCurrentEventContext());
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800253 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800254 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000255 return CJS_Result::Success(pEvent->Target_Field()->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256}
257
Tom Sepez3a6d0582018-08-17 19:28:52 +0000258CJS_Result CJS_Event::set_target(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000259 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000260 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400261}
262
Tom Sepez3a6d0582018-08-17 19:28:52 +0000263CJS_Result CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000264 ASSERT(pRuntime->GetCurrentEventContext());
dan sinclaircbe23db2017-10-19 14:29:33 -0400265 CJS_EventHandler* pEvent =
266 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000267 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +0000268 pRuntime->NewString(pEvent->TargetName().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400269}
270
Tom Sepez3a6d0582018-08-17 19:28:52 +0000271CJS_Result CJS_Event::set_target_name(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000272 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000273 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400274}
275
Tom Sepez3a6d0582018-08-17 19:28:52 +0000276CJS_Result CJS_Event::get_type(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400277 CJS_EventHandler* pEvent =
278 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000279 return CJS_Result::Success(pRuntime->NewString(pEvent->Type()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400280}
281
Tom Sepez3a6d0582018-08-17 19:28:52 +0000282CJS_Result CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
283 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400284}
285
Tom Sepez3a6d0582018-08-17 19:28:52 +0000286CJS_Result CJS_Event::get_value(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800287 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800288 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000291 return CJS_Result::Failure(L"Bad event type.");
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800292
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 if (!pEvent->m_pValue)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000294 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800295
Tom Sepez3a6d0582018-08-17 19:28:52 +0000296 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +0000297 pRuntime->NewString(pEvent->Value().AsStringView()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298}
299
Tom Sepez3a6d0582018-08-17 19:28:52 +0000300CJS_Result CJS_Event::set_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000301 v8::Local<v8::Value> vp) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000302 ASSERT(pRuntime->GetCurrentEventContext());
303
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800304 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800305 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306
dan sinclaircbe23db2017-10-19 14:29:33 -0400307 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000308 return CJS_Result::Failure(L"Bad event type.");
dan sinclaircbe23db2017-10-19 14:29:33 -0400309
310 if (!pEvent->m_pValue)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000311 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400312
dan sinclair80435cb2017-10-24 21:40:24 -0400313 pEvent->Value() = pRuntime->ToWideString(vp);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000314 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315}
dan sinclaircbe23db2017-10-19 14:29:33 -0400316
Tom Sepez3a6d0582018-08-17 19:28:52 +0000317CJS_Result CJS_Event::get_will_commit(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000318 ASSERT(pRuntime->GetCurrentEventContext());
319
dan sinclaircbe23db2017-10-19 14:29:33 -0400320 CJS_EventHandler* pEvent =
321 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000322 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->WillCommit()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400323}
324
Tom Sepez3a6d0582018-08-17 19:28:52 +0000325CJS_Result CJS_Event::set_will_commit(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000326 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000327 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400328}