blob: de22ab84880f557bcf6468f9ac5a656c13b9ffe7 [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
Dan Sinclairbef4d3e2017-10-26 16:49:38 -040041void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
Dan Sinclairf7435522018-02-05 22:27:22 +000042 ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
Dan Sinclair998fee32018-02-05 21:43:19 +000043 JSConstructor<CJS_Event>, JSDestructor);
Dan Sinclair909fa2d2017-12-12 01:53:28 +000044 DefineProps(pEngine, ObjDefnID, PropertySpecs, FX_ArraySize(PropertySpecs));
Dan Sinclair89d26c82017-10-26 12:21:28 -040045}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046
Tom Sepez36aae4f2018-06-04 19:44:37 +000047CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
48 : CJS_Object(pObject, pRuntime) {}
Dan Sinclair998fee32018-02-05 21:43:19 +000049
Dan Sinclairf7435522018-02-05 22:27:22 +000050CJS_Event::~CJS_Event() = default;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051
Dan Sinclairf7435522018-02-05 22:27:22 +000052CJS_Return CJS_Event::get_change(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +000053 ASSERT(pRuntime->GetCurrentEventContext());
54
Tom Sepezd6ae2af2017-02-16 11:49:55 -080055 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -080056 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -040057 return CJS_Return(pRuntime->NewString(pEvent->Change().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -040058}
59
Dan Sinclairf7435522018-02-05 22:27:22 +000060CJS_Return CJS_Event::set_change(CJS_Runtime* pRuntime,
61 v8::Local<v8::Value> vp) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +000062 ASSERT(pRuntime->GetCurrentEventContext());
63
dan sinclaircbe23db2017-10-19 14:29:33 -040064 CJS_EventHandler* pEvent =
65 pRuntime->GetCurrentEventContext()->GetEventHandler();
66
dan sinclair80435cb2017-10-24 21:40:24 -040067 if (vp->IsString()) {
dan sinclaircbe23db2017-10-19 14:29:33 -040068 WideString& wChange = pEvent->Change();
dan sinclair80435cb2017-10-24 21:40:24 -040069 wChange = pRuntime->ToWideString(vp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 }
Dan Sinclair8f524d62017-10-25 13:30:31 -040071 return CJS_Return(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072}
73
Dan Sinclairf7435522018-02-05 22:27:22 +000074CJS_Return CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +000075 ASSERT(pRuntime->GetCurrentEventContext());
76
dan sinclaircbe23db2017-10-19 14:29:33 -040077 CJS_EventHandler* pEvent =
78 pRuntime->GetCurrentEventContext()->GetEventHandler();
79
Dan Sinclair8f524d62017-10-25 13:30:31 -040080 return CJS_Return(pRuntime->NewString(pEvent->ChangeEx().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -040081}
82
Dan Sinclairf7435522018-02-05 22:27:22 +000083CJS_Return CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
84 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -040085 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -040086}
87
Dan Sinclairf7435522018-02-05 22:27:22 +000088CJS_Return CJS_Event::get_commit_key(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +000089 ASSERT(pRuntime->GetCurrentEventContext());
90
dan sinclaircbe23db2017-10-19 14:29:33 -040091 CJS_EventHandler* pEvent =
92 pRuntime->GetCurrentEventContext()->GetEventHandler();
93
Dan Sinclair8f524d62017-10-25 13:30:31 -040094 return CJS_Return(pRuntime->NewNumber(pEvent->CommitKey()));
dan sinclaircbe23db2017-10-19 14:29:33 -040095}
96
Dan Sinclairf7435522018-02-05 22:27:22 +000097CJS_Return CJS_Event::set_commit_key(CJS_Runtime* pRuntime,
98 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -040099 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400100}
101
Dan Sinclairf7435522018-02-05 22:27:22 +0000102CJS_Return CJS_Event::get_field_full(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000103 ASSERT(pRuntime->GetCurrentEventContext());
104
dan sinclaircbe23db2017-10-19 14:29:33 -0400105 CJS_EventHandler* pEvent =
106 pRuntime->GetCurrentEventContext()->GetEventHandler();
107
108 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400109 return CJS_Return(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110
Dan Sinclair8f524d62017-10-25 13:30:31 -0400111 return CJS_Return(pRuntime->NewBoolean(pEvent->FieldFull()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400112}
113
Dan Sinclairf7435522018-02-05 22:27:22 +0000114CJS_Return CJS_Event::set_field_full(CJS_Runtime* pRuntime,
115 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400116 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400117}
118
Dan Sinclairf7435522018-02-05 22:27:22 +0000119CJS_Return CJS_Event::get_key_down(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800120 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800121 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400122 return CJS_Return(pRuntime->NewBoolean(pEvent->KeyDown()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123}
124
Dan Sinclairf7435522018-02-05 22:27:22 +0000125CJS_Return CJS_Event::set_key_down(CJS_Runtime* pRuntime,
126 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400127 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400128}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129
Dan Sinclairf7435522018-02-05 22:27:22 +0000130CJS_Return CJS_Event::get_modifier(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800131 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800132 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400133 return CJS_Return(pRuntime->NewBoolean(pEvent->Modifier()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134}
135
Dan Sinclairf7435522018-02-05 22:27:22 +0000136CJS_Return CJS_Event::set_modifier(CJS_Runtime* pRuntime,
137 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400138 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400139}
140
Dan Sinclairf7435522018-02-05 22:27:22 +0000141CJS_Return CJS_Event::get_name(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800142 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800143 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400144 return CJS_Return(pRuntime->NewString(pEvent->Name()));
tsepez4cf55152016-11-02 14:37:54 -0700145}
146
Dan Sinclairf7435522018-02-05 22:27:22 +0000147CJS_Return CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400148 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400149}
tsepez4cf55152016-11-02 14:37:54 -0700150
Dan Sinclairf7435522018-02-05 22:27:22 +0000151CJS_Return CJS_Event::get_rc(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800152 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800153 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400154 return CJS_Return(pRuntime->NewBoolean(pEvent->Rc()));
tsepez4cf55152016-11-02 14:37:54 -0700155}
156
Dan Sinclairf7435522018-02-05 22:27:22 +0000157CJS_Return CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800158 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800159 pRuntime->GetCurrentEventContext()->GetEventHandler();
dan sinclair80435cb2017-10-24 21:40:24 -0400160 pEvent->Rc() = pRuntime->ToBoolean(vp);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400161 return CJS_Return(true);
tsepez4cf55152016-11-02 14:37:54 -0700162}
163
Dan Sinclairf7435522018-02-05 22:27:22 +0000164CJS_Return CJS_Event::get_rich_change(CJS_Runtime* pRuntime) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400165 return CJS_Return(true);
tsepez4cf55152016-11-02 14:37:54 -0700166}
167
Dan Sinclairf7435522018-02-05 22:27:22 +0000168CJS_Return CJS_Event::set_rich_change(CJS_Runtime* pRuntime,
169 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400170 return CJS_Return(true);
tsepez4cf55152016-11-02 14:37:54 -0700171}
172
Dan Sinclairf7435522018-02-05 22:27:22 +0000173CJS_Return CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400174 return CJS_Return(true);
tsepez4cf55152016-11-02 14:37:54 -0700175}
176
Dan Sinclairf7435522018-02-05 22:27:22 +0000177CJS_Return CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime,
178 v8::Local<v8::Value> vp) {
179 return CJS_Return(true);
180}
181
182CJS_Return CJS_Event::get_rich_value(CJS_Runtime* pRuntime) {
183 return CJS_Return(true);
184}
185
186CJS_Return CJS_Event::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -0400187 v8::Local<v8::Value> vp) {
188 return CJS_Return(true);
tsepez4cf55152016-11-02 14:37:54 -0700189}
190
Dan Sinclairf7435522018-02-05 22:27:22 +0000191CJS_Return CJS_Event::get_sel_end(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800192 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800193 pRuntime->GetCurrentEventContext()->GetEventHandler();
tsepez4cf55152016-11-02 14:37:54 -0700194
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800195 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400196 return CJS_Return(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197
Dan Sinclair8f524d62017-10-25 13:30:31 -0400198 return CJS_Return(pRuntime->NewNumber(pEvent->SelEnd()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199}
200
Dan Sinclairf7435522018-02-05 22:27:22 +0000201CJS_Return CJS_Event::set_sel_end(CJS_Runtime* pRuntime,
202 v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800203 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800204 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800206 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400207 return CJS_Return(true);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800208
Lei Zhangfae5e262017-11-20 19:58:13 +0000209 pEvent->SetSelEnd(pRuntime->ToInt32(vp));
Dan Sinclair8f524d62017-10-25 13:30:31 -0400210 return CJS_Return(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211}
212
Dan Sinclairf7435522018-02-05 22:27:22 +0000213CJS_Return CJS_Event::get_sel_start(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800214 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800215 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216
dan sinclaircbe23db2017-10-19 14:29:33 -0400217 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400218 return CJS_Return(true);
dan sinclaircbe23db2017-10-19 14:29:33 -0400219
Dan Sinclair8f524d62017-10-25 13:30:31 -0400220 return CJS_Return(pRuntime->NewNumber(pEvent->SelStart()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221}
222
Dan Sinclairf7435522018-02-05 22:27:22 +0000223CJS_Return CJS_Event::set_sel_start(CJS_Runtime* pRuntime,
224 v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800225 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800226 pRuntime->GetCurrentEventContext()->GetEventHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227
dan sinclaircbe23db2017-10-19 14:29:33 -0400228 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400229 return CJS_Return(true);
dan sinclaircbe23db2017-10-19 14:29:33 -0400230
Lei Zhangfae5e262017-11-20 19:58:13 +0000231 pEvent->SetSelStart(pRuntime->ToInt32(vp));
Dan Sinclair8f524d62017-10-25 13:30:31 -0400232 return CJS_Return(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233}
234
Dan Sinclairf7435522018-02-05 22:27:22 +0000235CJS_Return CJS_Event::get_shift(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800236 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800237 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400238 return CJS_Return(pRuntime->NewBoolean(pEvent->Shift()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239}
240
Dan Sinclairf7435522018-02-05 22:27:22 +0000241CJS_Return CJS_Event::set_shift(CJS_Runtime* pRuntime,
242 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400243 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400244}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Dan Sinclairf7435522018-02-05 22:27:22 +0000246CJS_Return CJS_Event::get_source(CJS_Runtime* pRuntime) {
Tom Sepezb1670b52017-02-16 17:01:00 -0800247 CJS_EventHandler* pEvent =
248 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclairf7435522018-02-05 22:27:22 +0000249 return CJS_Return(pEvent->Source()->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250}
251
Dan Sinclairf7435522018-02-05 22:27:22 +0000252CJS_Return CJS_Event::set_source(CJS_Runtime* pRuntime,
253 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400254 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400255}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256
Dan Sinclairf7435522018-02-05 22:27:22 +0000257CJS_Return CJS_Event::get_target(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000258 ASSERT(pRuntime->GetCurrentEventContext());
259
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800260 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800261 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclairf7435522018-02-05 22:27:22 +0000262 return CJS_Return(pEvent->Target_Field()->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263}
264
Dan Sinclairf7435522018-02-05 22:27:22 +0000265CJS_Return CJS_Event::set_target(CJS_Runtime* pRuntime,
266 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400267 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400268}
269
Dan Sinclairf7435522018-02-05 22:27:22 +0000270CJS_Return CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000271 ASSERT(pRuntime->GetCurrentEventContext());
272
dan sinclaircbe23db2017-10-19 14:29:33 -0400273 CJS_EventHandler* pEvent =
274 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400275 return CJS_Return(pRuntime->NewString(pEvent->TargetName().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400276}
277
Dan Sinclairf7435522018-02-05 22:27:22 +0000278CJS_Return CJS_Event::set_target_name(CJS_Runtime* pRuntime,
279 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400280 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400281}
282
Dan Sinclairf7435522018-02-05 22:27:22 +0000283CJS_Return CJS_Event::get_type(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000284 ASSERT(pRuntime->GetCurrentEventContext());
285
dan sinclaircbe23db2017-10-19 14:29:33 -0400286 CJS_EventHandler* pEvent =
287 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400288 return CJS_Return(pRuntime->NewString(pEvent->Type()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400289}
290
Dan Sinclairf7435522018-02-05 22:27:22 +0000291CJS_Return CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400292 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400293}
294
Dan Sinclairf7435522018-02-05 22:27:22 +0000295CJS_Return CJS_Event::get_value(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000296 ASSERT(pRuntime->GetCurrentEventContext());
297
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800298 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800299 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400302 return CJS_Return(false);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800303
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 if (!pEvent->m_pValue)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400305 return CJS_Return(false);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800306
Dan Sinclair8f524d62017-10-25 13:30:31 -0400307 return CJS_Return(pRuntime->NewString(pEvent->Value().c_str()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308}
309
Dan Sinclairf7435522018-02-05 22:27:22 +0000310CJS_Return CJS_Event::set_value(CJS_Runtime* pRuntime,
311 v8::Local<v8::Value> vp) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000312 ASSERT(pRuntime->GetCurrentEventContext());
313
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800314 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800315 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700316
dan sinclaircbe23db2017-10-19 14:29:33 -0400317 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400318 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400319
320 if (!pEvent->m_pValue)
Dan Sinclair8f524d62017-10-25 13:30:31 -0400321 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400322
dan sinclair80435cb2017-10-24 21:40:24 -0400323 pEvent->Value() = pRuntime->ToWideString(vp);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400324 return CJS_Return(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700325}
dan sinclaircbe23db2017-10-19 14:29:33 -0400326
Dan Sinclairf7435522018-02-05 22:27:22 +0000327CJS_Return CJS_Event::get_will_commit(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000328 ASSERT(pRuntime->GetCurrentEventContext());
329
dan sinclaircbe23db2017-10-19 14:29:33 -0400330 CJS_EventHandler* pEvent =
331 pRuntime->GetCurrentEventContext()->GetEventHandler();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400332 return CJS_Return(pRuntime->NewBoolean(pEvent->WillCommit()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400333}
334
Dan Sinclairf7435522018-02-05 22:27:22 +0000335CJS_Return CJS_Event::set_will_commit(CJS_Runtime* pRuntime,
336 v8::Local<v8::Value> vp) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400337 return CJS_Return(false);
dan sinclaircbe23db2017-10-19 14:29:33 -0400338}