-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/add hybird router support (#599)
- Loading branch information
Showing
32 changed files
with
557 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,7 @@ | |
"wheel", | ||
"zoom", | ||
"intersectionchange", | ||
"gcopen" | ||
"gcopen", | ||
"hybridrouterchange" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2022-present The WebF authors. All rights reserved. | ||
*/ | ||
|
||
#include "hybrid_router_change_event.h" | ||
#include "bindings/qjs/cppgc/gc_visitor.h" | ||
#include "event_type_names.h" | ||
#include "qjs_hybrid_router_change_event.h" | ||
|
||
namespace webf { | ||
|
||
HybridRouterChangeEvent* HybridRouterChangeEvent::Create(ExecutingContext* context, ExceptionState& exception_state) { | ||
return MakeGarbageCollected<HybridRouterChangeEvent>(context, event_type_names::khybridrouterchange, exception_state); | ||
} | ||
|
||
HybridRouterChangeEvent* HybridRouterChangeEvent::Create( | ||
ExecutingContext* context, | ||
const AtomicString& type, | ||
const std::shared_ptr<HybridRouterChangeEventInit>& initializer, | ||
ExceptionState& exception_state) { | ||
return MakeGarbageCollected<HybridRouterChangeEvent>(context, type, initializer, exception_state); | ||
} | ||
|
||
HybridRouterChangeEvent::HybridRouterChangeEvent(ExecutingContext* context, | ||
const AtomicString& type, | ||
ExceptionState& exception_state) | ||
: Event(context, type) {} | ||
|
||
HybridRouterChangeEvent::HybridRouterChangeEvent(ExecutingContext* context, | ||
const AtomicString& type, | ||
const std::shared_ptr<HybridRouterChangeEventInit>& initializer, | ||
ExceptionState& exception_state) | ||
: Event(context, type), | ||
state_(initializer->hasState() ? initializer->state() : ScriptValue::Empty(ctx())), | ||
kind_(initializer->hasKind() ? initializer->kind() : AtomicString::Empty()), | ||
name_(initializer->hasName() ? initializer->name() : AtomicString::Empty()) {} | ||
|
||
HybridRouterChangeEvent::HybridRouterChangeEvent(ExecutingContext* context, | ||
const AtomicString& type, | ||
NativeHybridRouterChangeEvent* native_event) | ||
: Event(context, type, &native_event->native_event), | ||
#if ANDROID_32_BIT | ||
state_(ScriptValue::CreateJsonObject(context->ctx(), | ||
reinterpret_cast<const char*>(native_event->state), | ||
strlen(reinterpret_cast<const char*>(native_event->state)))), | ||
kind_(AtomicString( | ||
ctx(), | ||
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->kind)))), | ||
name_(AtomicString( | ||
ctx(), | ||
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->name)))) | ||
#else | ||
state_(ScriptValue::CreateJsonObject(context->ctx(), | ||
static_cast<const char*>(native_event->state), | ||
strlen(static_cast<const char*>(native_event->state)))), | ||
kind_(AtomicString( | ||
ctx(), | ||
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->kind)))), | ||
name_(AtomicString( | ||
ctx(), | ||
std::unique_ptr<AutoFreeNativeString>(reinterpret_cast<AutoFreeNativeString*>(native_event->name)))) | ||
#endif | ||
{ | ||
} | ||
|
||
ScriptValue HybridRouterChangeEvent::state() const { | ||
return state_; | ||
} | ||
|
||
AtomicString HybridRouterChangeEvent::kind() const { | ||
return kind_; | ||
} | ||
|
||
AtomicString HybridRouterChangeEvent::name() const { | ||
return name_; | ||
} | ||
|
||
bool HybridRouterChangeEvent::IsHybridRouterChangeEvent() const { | ||
return true; | ||
} | ||
|
||
void HybridRouterChangeEvent::Trace(GCVisitor* visitor) const { | ||
state_.Trace(visitor); | ||
Event::Trace(visitor); | ||
} | ||
|
||
} // namespace webf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {Event} from "../dom/events/event"; | ||
|
||
interface HybridRouterChangeEvent extends Event { | ||
readonly state: any; | ||
readonly kind: string; | ||
readonly name: string; | ||
new(): HybridRouterChangeEvent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2022-present The WebF authors. All rights reserved. | ||
*/ | ||
|
||
#ifndef WEBF_CORE_EVENTS_HYBRID_ROUTER_CHANGE_EVENT_H_ | ||
#define WEBF_CORE_EVENTS_HYBRID_ROUTER_CHANGE_EVENT_H_ | ||
|
||
#include "core/dom/events/event.h" | ||
#include "qjs_hybrid_router_change_event_init.h" | ||
|
||
namespace webf { | ||
|
||
struct NativeHybridRouterChangeEvent; | ||
|
||
class HybridRouterChangeEvent : public Event { | ||
DEFINE_WRAPPERTYPEINFO(); | ||
|
||
public: | ||
using ImplType = HybridRouterChangeEvent*; | ||
|
||
static HybridRouterChangeEvent* Create(ExecutingContext* context, ExceptionState& exception_state); | ||
|
||
static HybridRouterChangeEvent* Create(ExecutingContext* context, | ||
const AtomicString& type, | ||
const std::shared_ptr<HybridRouterChangeEventInit>& initializer, | ||
ExceptionState& exception_state); | ||
|
||
explicit HybridRouterChangeEvent(ExecutingContext* context, const AtomicString& type, ExceptionState& exception_state); | ||
|
||
explicit HybridRouterChangeEvent(ExecutingContext* context, | ||
const AtomicString& type, | ||
const std::shared_ptr<HybridRouterChangeEventInit>& initializer, | ||
ExceptionState& exception_state); | ||
|
||
explicit HybridRouterChangeEvent(ExecutingContext* context, const AtomicString& type, NativeHybridRouterChangeEvent* native_ui_event); | ||
|
||
ScriptValue state() const; | ||
AtomicString kind() const; | ||
AtomicString name() const; | ||
|
||
bool IsHybridRouterChangeEvent() const override; | ||
|
||
void Trace(GCVisitor* visitor) const override; | ||
|
||
private: | ||
ScriptValue state_; | ||
AtomicString kind_; | ||
AtomicString name_; | ||
}; | ||
|
||
template <> | ||
struct DowncastTraits<HybridRouterChangeEvent> { | ||
static bool AllowFrom(const Event& event) { return event.IsHybridRouterChangeEvent(); } | ||
}; | ||
|
||
} // namespace webf | ||
|
||
#endif // WEBF_CORE_EVENTS_HYBRID_ROUTER_CHANGE_EVENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {EventInit} from "../dom/events/event_init"; | ||
|
||
// @ts-ignore | ||
@Dictionary() | ||
export interface HybridRouterChangeEventInit extends EventInit { | ||
kind?: string; | ||
name?: string; | ||
state?: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2019-2022 The Kraken authors. All rights reserved. | ||
* Copyright (C) 2022-present The WebF authors. All rights reserved. | ||
*/ | ||
|
||
import { webf } from './webf'; | ||
|
||
class HybridHistory { | ||
get state() { | ||
return JSON.parse(webf.invokeModule('HybridHistory', 'state')); | ||
} | ||
|
||
back() { | ||
webf.invokeModule('HybridHistory', 'back'); | ||
} | ||
|
||
pushState(state: any, name: string) { | ||
if (arguments.length < 2) { | ||
throw TypeError("Failed to execute 'pushState' on 'HybridHistory': 2 arguments required, but only " + arguments.length + " present"); | ||
} | ||
|
||
webf.invokeModule('HybridHistory', 'pushState', [state, name]); | ||
} | ||
} | ||
|
||
export const hybridHistory = new HybridHistory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+79 Bytes
(100%)
integration_tests/snapshots/dom/elements/custom-element.ts.d278d6f51.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.