Skip to content

Commit b1e37c7

Browse files
authored
Feat/add hybird router support (#599)
openwebf/rfc#8
2 parents efe0664 + c55b137 commit b1e37c7

32 files changed

+557
-33
lines changed

bridge/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
344344
core/events/input_event.cc
345345
core/events/touch_event.cc
346346
core/events/mouse_event.cc
347+
core/events/hybrid_router_change_event.cc
347348
core/events/pop_state_event.cc
348349
core/events/pointer_event.cc
349350
core/events/transition_event.cc
@@ -442,6 +443,8 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
442443
out/qjs_mutation_observer_registration.cc
443444
out/qjs_touch_event.cc
444445
out/qjs_touch_event_init.cc
446+
out/qjs_hybrid_router_change_event.cc
447+
out/qjs_hybrid_router_change_event_init.cc
445448
out/qjs_pointer_event.cc
446449
out/qjs_pointer_event_init.cc
447450
out/qjs_mouse_event.cc

bridge/bindings/qjs/binding_initializer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include "qjs_text.h"
9393
#include "qjs_touch.h"
9494
#include "qjs_touch_event.h"
95+
#include "qjs_hybrid_router_change_event.h"
9596
#include "qjs_touch_list.h"
9697
#include "qjs_transition_event.h"
9798
#include "qjs_ui_event.h"
@@ -117,6 +118,7 @@ void InstallBindings(ExecutingContext* context) {
117118
QJSMessageEvent::Install(context);
118119
QJSAnimationEvent::Install(context);
119120
QJSCloseEvent::Install(context);
121+
QJSHybridRouterChangeEvent::Install(context);
120122
QJSFocusEvent::Install(context);
121123
QJSGestureEvent::Install(context);
122124
QJSHashchangeEvent::Install(context);

bridge/bindings/qjs/wrapper_type_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum {
2929
JS_CLASS_CUSTOM_EVENT,
3030
JS_CLASS_TRANSITION_EVENT,
3131
JS_CLASS_INPUT_EVENT,
32+
JS_CLASS_HYBRID_ROUTER_CHANGE_EVENT,
3233
JS_CLASS_ANIMATION_EVENT,
3334
JS_CLASS_FOCUS_EVENT,
3435
JS_CLASS_GESTURE_EVENT,

bridge/core/dom/events/event.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ bool Event::IsHashChangeEvent() const {
306306
return false;
307307
}
308308

309+
bool Event::IsHybridRouterChangeEvent() const {
310+
return false;
311+
}
312+
309313
bool Event::IsIntersectionchangeEvent() const {
310314
return false;
311315
}

bridge/core/dom/events/event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class Event : public ScriptWrappable {
172172
virtual bool IsPopstateEvent() const;
173173
virtual bool IsIntersectionchangeEvent() const;
174174
virtual bool IsHashChangeEvent() const;
175+
virtual bool IsHybridRouterChangeEvent() const;
175176

176177
// Drag events are a subset of mouse events.
177178
virtual bool IsDragEvent() const;

bridge/core/events/dart_created_events.json5

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
},
4040
"hashchange",
4141
"input",
42+
{
43+
"class": "HybridRouterChangeEvent",
44+
"types": [
45+
"hybridrouterchange"
46+
]
47+
},
4248
{
4349
"class": "FocusEvent",
4450
"types": [

bridge/core/events/event_type_names.json5

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
"wheel",
225225
"zoom",
226226
"intersectionchange",
227-
"gcopen"
227+
"gcopen",
228+
"hybridrouterchange"
228229
]
229230
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2022-present The WebF authors. All rights reserved.
3+
*/
4+
5+
#include "hybrid_router_change_event.h"
6+
#include "bindings/qjs/cppgc/gc_visitor.h"
7+
#include "event_type_names.h"
8+
#include "qjs_hybrid_router_change_event.h"
9+
10+
namespace webf {
11+
12+
HybridRouterChangeEvent* HybridRouterChangeEvent::Create(ExecutingContext* context, ExceptionState& exception_state) {
13+
return MakeGarbageCollected<HybridRouterChangeEvent>(context, event_type_names::khybridrouterchange, exception_state);
14+
}
15+
16+
HybridRouterChangeEvent* HybridRouterChangeEvent::Create(
17+
ExecutingContext* context,
18+
const AtomicString& type,
19+
const std::shared_ptr<HybridRouterChangeEventInit>& initializer,
20+
ExceptionState& exception_state) {
21+
return MakeGarbageCollected<HybridRouterChangeEvent>(context, type, initializer, exception_state);
22+
}
23+
24+
HybridRouterChangeEvent::HybridRouterChangeEvent(ExecutingContext* context,
25+
const AtomicString& type,
26+
ExceptionState& exception_state)
27+
: Event(context, type) {}
28+
29+
HybridRouterChangeEvent::HybridRouterChangeEvent(ExecutingContext* context,
30+
const AtomicString& type,
31+
const std::shared_ptr<HybridRouterChangeEventInit>& initializer,
32+
ExceptionState& exception_state)
33+
: Event(context, type),
34+
state_(initializer->hasState() ? initializer->state() : ScriptValue::Empty(ctx())),
35+
kind_(initializer->hasKind() ? initializer->kind() : AtomicString::Empty()),
36+
name_(initializer->hasName() ? initializer->name() : AtomicString::Empty()) {}
37+
38+
HybridRouterChangeEvent::HybridRouterChangeEvent(ExecutingContext* context,
39+
const AtomicString& type,
40+
NativeHybridRouterChangeEvent* native_event)
41+
: Event(context, type, &native_event->native_event),
42+
#if ANDROID_32_BIT
43+
state_(ScriptValue::CreateJsonObject(context->ctx(),
44+
reinterpret_cast<const char*>(native_event->state),
45+
strlen(reinterpret_cast<const char*>(native_event->state)))),
46+
kind_(AtomicString(
47+
ctx(),
48+
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->kind)))),
49+
name_(AtomicString(
50+
ctx(),
51+
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->name))))
52+
#else
53+
state_(ScriptValue::CreateJsonObject(context->ctx(),
54+
static_cast<const char*>(native_event->state),
55+
strlen(static_cast<const char*>(native_event->state)))),
56+
kind_(AtomicString(
57+
ctx(),
58+
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->kind)))),
59+
name_(AtomicString(
60+
ctx(),
61+
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->name))))
62+
#endif
63+
{
64+
}
65+
66+
ScriptValue HybridRouterChangeEvent::state() const {
67+
return state_;
68+
}
69+
70+
AtomicString HybridRouterChangeEvent::kind() const {
71+
return kind_;
72+
}
73+
74+
AtomicString HybridRouterChangeEvent::name() const {
75+
return name_;
76+
}
77+
78+
bool HybridRouterChangeEvent::IsHybridRouterChangeEvent() const {
79+
return true;
80+
}
81+
82+
void HybridRouterChangeEvent::Trace(GCVisitor* visitor) const {
83+
state_.Trace(visitor);
84+
Event::Trace(visitor);
85+
}
86+
87+
} // namespace webf
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Event} from "../dom/events/event";
2+
3+
interface HybridRouterChangeEvent extends Event {
4+
readonly state: any;
5+
readonly kind: string;
6+
readonly name: string;
7+
new(): HybridRouterChangeEvent;
8+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2022-present The WebF authors. All rights reserved.
3+
*/
4+
5+
#ifndef WEBF_CORE_EVENTS_HYBRID_ROUTER_CHANGE_EVENT_H_
6+
#define WEBF_CORE_EVENTS_HYBRID_ROUTER_CHANGE_EVENT_H_
7+
8+
#include "core/dom/events/event.h"
9+
#include "qjs_hybrid_router_change_event_init.h"
10+
11+
namespace webf {
12+
13+
struct NativeHybridRouterChangeEvent;
14+
15+
class HybridRouterChangeEvent : public Event {
16+
DEFINE_WRAPPERTYPEINFO();
17+
18+
public:
19+
using ImplType = HybridRouterChangeEvent*;
20+
21+
static HybridRouterChangeEvent* Create(ExecutingContext* context, ExceptionState& exception_state);
22+
23+
static HybridRouterChangeEvent* Create(ExecutingContext* context,
24+
const AtomicString& type,
25+
const std::shared_ptr<HybridRouterChangeEventInit>& initializer,
26+
ExceptionState& exception_state);
27+
28+
explicit HybridRouterChangeEvent(ExecutingContext* context, const AtomicString& type, ExceptionState& exception_state);
29+
30+
explicit HybridRouterChangeEvent(ExecutingContext* context,
31+
const AtomicString& type,
32+
const std::shared_ptr<HybridRouterChangeEventInit>& initializer,
33+
ExceptionState& exception_state);
34+
35+
explicit HybridRouterChangeEvent(ExecutingContext* context, const AtomicString& type, NativeHybridRouterChangeEvent* native_ui_event);
36+
37+
ScriptValue state() const;
38+
AtomicString kind() const;
39+
AtomicString name() const;
40+
41+
bool IsHybridRouterChangeEvent() const override;
42+
43+
void Trace(GCVisitor* visitor) const override;
44+
45+
private:
46+
ScriptValue state_;
47+
AtomicString kind_;
48+
AtomicString name_;
49+
};
50+
51+
template <>
52+
struct DowncastTraits<HybridRouterChangeEvent> {
53+
static bool AllowFrom(const Event& event) { return event.IsHybridRouterChangeEvent(); }
54+
};
55+
56+
} // namespace webf
57+
58+
#endif // WEBF_CORE_EVENTS_HYBRID_ROUTER_CHANGE_EVENT_H_

0 commit comments

Comments
 (0)