Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjs_event.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fxjs/cjs_event.h"
8
9#include "fxjs/cjs_event_context.h"
10#include "fxjs/cjs_field.h"
11#include "fxjs/cjs_object.h"
12#include "fxjs/js_define.h"
13
14const JSPropertySpec CJS_Event::PropertySpecs[] = {
15 {"change", get_change_static, set_change_static},
16 {"changeEx", get_change_ex_static, set_change_ex_static},
17 {"commitKey", get_commit_key_static, set_commit_key_static},
18 {"fieldFull", get_field_full_static, set_field_full_static},
19 {"keyDown", get_key_down_static, set_key_down_static},
20 {"modifier", get_modifier_static, set_modifier_static},
21 {"name", get_name_static, set_name_static},
22 {"rc", get_rc_static, set_rc_static},
23 {"richChange", get_rich_change_static, set_rich_change_static},
24 {"richChangeEx", get_rich_change_ex_static, set_rich_change_ex_static},
25 {"richValue", get_rich_value_static, set_rich_value_static},
26 {"selEnd", get_sel_end_static, set_sel_end_static},
27 {"selStart", get_sel_start_static, set_sel_start_static},
28 {"shift", get_shift_static, set_shift_static},
29 {"source", get_source_static, set_source_static},
30 {"target", get_target_static, set_target_static},
31 {"targetName", get_target_name_static, set_target_name_static},
32 {"type", get_type_static, set_type_static},
33 {"value", get_value_static, set_value_static},
34 {"willCommit", get_will_commit_static, set_will_commit_static}};
35
36uint32_t CJS_Event::ObjDefnID = 0;
37const char CJS_Event::kName[] = "event";
38
39// static
40uint32_t CJS_Event::GetObjDefnID() {
41 return ObjDefnID;
42}
43
44// static
45void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
46 ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
47 JSConstructor<CJS_Event>, JSDestructor);
48 DefineProps(pEngine, ObjDefnID, PropertySpecs);
49}
50
51CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
52 : CJS_Object(pObject, pRuntime) {}
53
54CJS_Event::~CJS_Event() = default;
55
56CJS_Result CJS_Event::get_change(CJS_Runtime* pRuntime) {
57 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
59 pRuntime->NewString(pEvent->Change().AsStringView()));
60}
61
62CJS_Result CJS_Event::set_change(CJS_Runtime* pRuntime,
63 v8::Local<v8::Value> vp) {
64 if (vp->IsString()) {
65 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
66 pEvent->Change() = pRuntime->ToWideString(vp);
67 }
69}
70
71CJS_Result CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
72 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
74 pRuntime->NewString(pEvent->ChangeEx().AsStringView()));
75}
76
77CJS_Result CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
78 v8::Local<v8::Value> vp) {
80}
81
82CJS_Result CJS_Event::get_commit_key(CJS_Runtime* pRuntime) {
83 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
84 return CJS_Result::Success(pRuntime->NewNumber(pEvent->CommitKey()));
85}
86
87CJS_Result CJS_Event::set_commit_key(CJS_Runtime* pRuntime,
88 v8::Local<v8::Value> vp) {
90}
91
92CJS_Result CJS_Event::get_field_full(CJS_Runtime* pRuntime) {
93 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
94 if (pEvent->Name() != "Keystroke")
95 return CJS_Result::Failure(L"unrecognized event");
96
97 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->FieldFull()));
98}
99
100CJS_Result CJS_Event::set_field_full(CJS_Runtime* pRuntime,
101 v8::Local<v8::Value> vp) {
103}
104
105CJS_Result CJS_Event::get_key_down(CJS_Runtime* pRuntime) {
106 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
107 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->KeyDown()));
108}
109
110CJS_Result CJS_Event::set_key_down(CJS_Runtime* pRuntime,
111 v8::Local<v8::Value> vp) {
113}
114
115CJS_Result CJS_Event::get_modifier(CJS_Runtime* pRuntime) {
116 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
117 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Modifier()));
118}
119
120CJS_Result CJS_Event::set_modifier(CJS_Runtime* pRuntime,
121 v8::Local<v8::Value> vp) {
123}
124
125CJS_Result CJS_Event::get_name(CJS_Runtime* pRuntime) {
126 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
127 return CJS_Result::Success(pRuntime->NewString(pEvent->Name()));
128}
129
130CJS_Result CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
132}
133
134CJS_Result CJS_Event::get_rc(CJS_Runtime* pRuntime) {
135 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
136 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Rc()));
137}
138
139CJS_Result CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
140 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
141 pEvent->Rc() = pRuntime->ToBoolean(vp);
143}
144
145CJS_Result CJS_Event::get_rich_change(CJS_Runtime* pRuntime) {
147}
148
149CJS_Result CJS_Event::set_rich_change(CJS_Runtime* pRuntime,
150 v8::Local<v8::Value> vp) {
152}
153
154CJS_Result CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) {
156}
157
158CJS_Result CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime,
159 v8::Local<v8::Value> vp) {
161}
162
163CJS_Result CJS_Event::get_rich_value(CJS_Runtime* pRuntime) {
165}
166
167CJS_Result CJS_Event::set_rich_value(CJS_Runtime* pRuntime,
168 v8::Local<v8::Value> vp) {
170}
171
172CJS_Result CJS_Event::get_sel_end(CJS_Runtime* pRuntime) {
173 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
174 if (pEvent->Name() != "Keystroke")
176
177 return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelEnd()));
178}
179
180CJS_Result CJS_Event::set_sel_end(CJS_Runtime* pRuntime,
181 v8::Local<v8::Value> vp) {
182 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
183 if (pEvent->Name() == "Keystroke")
184 pEvent->SetSelEnd(pRuntime->ToInt32(vp));
185
187}
188
189CJS_Result CJS_Event::get_sel_start(CJS_Runtime* pRuntime) {
190 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
191 if (pEvent->Name() != "Keystroke")
193
194 return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelStart()));
195}
196
197CJS_Result CJS_Event::set_sel_start(CJS_Runtime* pRuntime,
198 v8::Local<v8::Value> vp) {
199 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
200 if (pEvent->Name() == "Keystroke")
201 pEvent->SetSelStart(pRuntime->ToInt32(vp));
202
204}
205
206CJS_Result CJS_Event::get_shift(CJS_Runtime* pRuntime) {
207 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
208 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Shift()));
209}
210
211CJS_Result CJS_Event::set_shift(CJS_Runtime* pRuntime,
212 v8::Local<v8::Value> vp) {
214}
215
216CJS_Result CJS_Event::get_source(CJS_Runtime* pRuntime) {
217 CJS_Field* pField = pRuntime->GetCurrentEventContext()->SourceField();
218 if (!pField)
220 return CJS_Result::Success(pField->ToV8Object());
221}
222
223CJS_Result CJS_Event::set_source(CJS_Runtime* pRuntime,
224 v8::Local<v8::Value> vp) {
226}
227
228CJS_Result CJS_Event::get_target(CJS_Runtime* pRuntime) {
229 CJS_Field* pField = pRuntime->GetCurrentEventContext()->TargetField();
230 if (!pField)
232 return CJS_Result::Success(pField->ToV8Object());
233}
234
235CJS_Result CJS_Event::set_target(CJS_Runtime* pRuntime,
236 v8::Local<v8::Value> vp) {
238}
239
240CJS_Result CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
241 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
243 pRuntime->NewString(pEvent->TargetName().AsStringView()));
244}
245
246CJS_Result CJS_Event::set_target_name(CJS_Runtime* pRuntime,
247 v8::Local<v8::Value> vp) {
249}
250
251CJS_Result CJS_Event::get_type(CJS_Runtime* pRuntime) {
252 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
253 return CJS_Result::Success(pRuntime->NewString(pEvent->Type()));
254}
255
256CJS_Result CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
258}
259
260CJS_Result CJS_Event::get_value(CJS_Runtime* pRuntime) {
261 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
262 if (pEvent->Type() != "Field")
263 return CJS_Result::Failure(L"Bad event type.");
264
265 if (!pEvent->HasValue())
267
269 pRuntime->NewString(pEvent->Value().AsStringView()));
270}
271
272CJS_Result CJS_Event::set_value(CJS_Runtime* pRuntime,
273 v8::Local<v8::Value> vp) {
274 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
275 if (pEvent->Type() != "Field")
276 return CJS_Result::Failure(L"Bad event type.");
277
278 if (!pEvent->HasValue())
280
281 if (vp.IsEmpty())
283
284 if (vp->IsNullOrUndefined() || vp->IsBoolean())
286
287 pEvent->Value() = pRuntime->ToWideString(vp);
289}
290
291CJS_Result CJS_Event::get_will_commit(CJS_Runtime* pRuntime) {
292 CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
293
294 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->WillCommit()));
295}
296
297CJS_Result CJS_Event::set_will_commit(CJS_Runtime* pRuntime,
298 v8::Local<v8::Value> vp) {
300}
@ FXJSOBJTYPE_STATIC
CJS_Field * TargetField()
WideString ChangeEx() const
WideString TargetName() const
ByteStringView Name() const
ByteStringView Type() const
void SetSelEnd(int value)
CJS_Field * SourceField()
WideString & Value()
bool WillCommit() const
void SetSelStart(int value)
~CJS_Event() override
static void DefineJSObjects(CFXJS_Engine *pEngine)
Definition cjs_event.cpp:45
CJS_Event(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
Definition cjs_event.cpp:51
static uint32_t GetObjDefnID()
Definition cjs_event.cpp:40
static void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
static CJS_Result Failure(const WideString &str)
Definition cjs_result.h:31
CJS_EventContext * GetCurrentEventContext() const
JSMessage
@ kNotSupportedError
@ kInvalidSetError