mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-15 15:58:57 +00:00
create proper navigate event
This commit is contained in:
@@ -40,6 +40,7 @@ const MessageEvent = @import("../dom/MessageChannel.zig").MessageEvent;
|
|||||||
const PopStateEvent = @import("../html/History.zig").PopStateEvent;
|
const PopStateEvent = @import("../html/History.zig").PopStateEvent;
|
||||||
const CompositionEvent = @import("composition_event.zig").CompositionEvent;
|
const CompositionEvent = @import("composition_event.zig").CompositionEvent;
|
||||||
const NavigationCurrentEntryChangeEvent = @import("../navigation/root.zig").NavigationCurrentEntryChangeEvent;
|
const NavigationCurrentEntryChangeEvent = @import("../navigation/root.zig").NavigationCurrentEntryChangeEvent;
|
||||||
|
const NavigateEvent = @import("../navigation/root.zig").NavigateEvent;
|
||||||
|
|
||||||
// Event interfaces
|
// Event interfaces
|
||||||
pub const Interfaces = .{
|
pub const Interfaces = .{
|
||||||
@@ -53,6 +54,7 @@ pub const Interfaces = .{
|
|||||||
PopStateEvent,
|
PopStateEvent,
|
||||||
CompositionEvent,
|
CompositionEvent,
|
||||||
NavigationCurrentEntryChangeEvent,
|
NavigationCurrentEntryChangeEvent,
|
||||||
|
NavigateEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Union = generate.Union(Interfaces);
|
pub const Union = generate.Union(Interfaces);
|
||||||
@@ -85,6 +87,7 @@ pub const Event = struct {
|
|||||||
.navigation_current_entry_change_event => .{
|
.navigation_current_entry_change_event => .{
|
||||||
.NavigationCurrentEntryChangeEvent = @as(*NavigationCurrentEntryChangeEvent, @ptrCast(evt)).*,
|
.NavigationCurrentEntryChangeEvent = @as(*NavigationCurrentEntryChangeEvent, @ptrCast(evt)).*,
|
||||||
},
|
},
|
||||||
|
.navigate_event => .{ .NavigateEvent = @as(*NavigateEvent, @ptrCast(evt)).* },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -208,18 +208,18 @@ pub const NavigationCurrentEntryChangeEvent = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const NavigationNavigateEvent = struct {
|
pub const NavigateEvent = struct {
|
||||||
pub const prototype = *Event;
|
pub const prototype = *Event;
|
||||||
pub const union_make_copy = true;
|
pub const union_make_copy = true;
|
||||||
|
|
||||||
pub const EventInit = struct {
|
pub const EventInit = struct {
|
||||||
canInterpret: ?bool = false,
|
canIntercept: ?bool = false,
|
||||||
// todo: destination
|
// todo: destination
|
||||||
downloadRequest: ?[]const u8 = null,
|
downloadRequest: ?[]const u8 = null,
|
||||||
// todo: formData
|
// todo: formData
|
||||||
hashChange: ?bool = false,
|
hashChange: ?bool = false,
|
||||||
hasUAVisualTransition: ?bool = false,
|
hasUAVisualTransition: ?bool = false,
|
||||||
info: ?js.Value,
|
// info: ?js.Value,
|
||||||
navigationType: ?NavigationType = .push,
|
navigationType: ?NavigationType = .push,
|
||||||
// todo: signal
|
// todo: signal
|
||||||
// todo: sourceElement
|
// todo: sourceElement
|
||||||
@@ -228,32 +228,33 @@ pub const NavigationNavigateEvent = struct {
|
|||||||
|
|
||||||
proto: parser.Event,
|
proto: parser.Event,
|
||||||
can_intercept: bool,
|
can_intercept: bool,
|
||||||
download_request: []const u8,
|
download_request: ?[]const u8,
|
||||||
// todo: desintation
|
// todo: desintation
|
||||||
hash_change: bool,
|
hash_change: bool,
|
||||||
has_ua_visual_transition: bool,
|
has_ua_visual_transition: bool,
|
||||||
info: js.Value,
|
info: []const u8,
|
||||||
navigation_type: NavigationType,
|
navigation_type: NavigationType,
|
||||||
// todo: signal
|
// todo: signal
|
||||||
// todo: sourceElement
|
// todo: sourceElement
|
||||||
user_initiated: bool,
|
user_initiated: bool,
|
||||||
|
|
||||||
pub fn constructor(event_type: []const u8, opts: EventInit) !NavigationNavigateEvent {
|
pub fn constructor(event_type: []const u8, opts: EventInit) !NavigateEvent {
|
||||||
const event = try parser.eventCreate();
|
const event = try parser.eventCreate();
|
||||||
defer parser.eventDestroy(event);
|
defer parser.eventDestroy(event);
|
||||||
|
|
||||||
try parser.eventInit(event, event_type, .{});
|
try parser.eventInit(event, event_type, .{});
|
||||||
parser.eventSetInternalType(event, .navigation_current_entry_change_event);
|
parser.eventSetInternalType(event, .navigate_event);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.proto = event.*,
|
.proto = event.*,
|
||||||
.can_intercept = opts.canIntercept,
|
.can_intercept = opts.canIntercept orelse false,
|
||||||
.download_request = opts.downloadRequest,
|
.download_request = opts.downloadRequest orelse null,
|
||||||
.hash_change = opts.hashChange,
|
.hash_change = opts.hashChange orelse false,
|
||||||
.has_ua_visual_transition = opts.hasUAVisualTransition,
|
.has_ua_visual_transition = opts.hasUAVisualTransition orelse false,
|
||||||
.info = opts.info,
|
.info = undefined,
|
||||||
.navigation_type = opts.navigationType,
|
.navigation_type = opts.navigationType orelse .push,
|
||||||
.user_initiated = opts.userInitiated,
|
// .info = if (opts.info) |info| try info.toString(page.arena) else null,
|
||||||
|
.user_initiated = opts.userInitiated orelse false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +269,7 @@ pub const NavigationNavigateEvent = struct {
|
|||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/intercept
|
// https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/intercept
|
||||||
pub fn intercept(
|
pub fn intercept(
|
||||||
self: *NavigationNavigateEvent,
|
self: *NavigateEvent,
|
||||||
opts: ?InterceptOptions,
|
opts: ?InterceptOptions,
|
||||||
_: *Page,
|
_: *Page,
|
||||||
) !void {
|
) !void {
|
||||||
@@ -280,7 +281,7 @@ pub const NavigationNavigateEvent = struct {
|
|||||||
return error.InvalidState;
|
return error.InvalidState;
|
||||||
}
|
}
|
||||||
|
|
||||||
try parser.eventPreventDefault(&self.proto);
|
// try parser.eventPreventDefault(&self.proto);
|
||||||
|
|
||||||
if (opts) |options| {
|
if (opts) |options| {
|
||||||
if (options.precommitHandler) |handler| {
|
if (options.precommitHandler) |handler| {
|
||||||
@@ -303,7 +304,7 @@ pub const NavigationNavigateEvent = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scroll(self: *NavigationNavigateEvent) !void {
|
pub fn scroll(self: *NavigateEvent) !void {
|
||||||
_ = self;
|
_ = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +314,7 @@ pub const NavigationNavigateEvent = struct {
|
|||||||
.source = "navigation",
|
.source = "navigation",
|
||||||
});
|
});
|
||||||
|
|
||||||
var evt = NavigationNavigateEvent.constructor(
|
var evt = NavigateEvent.constructor(
|
||||||
"navigate",
|
"navigate",
|
||||||
.{ .from = from, .navigationType = typ },
|
.{ .from = from, .navigationType = typ },
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
|
|||||||
@@ -561,6 +561,7 @@ pub const EventType = enum(u8) {
|
|||||||
pop_state = 9,
|
pop_state = 9,
|
||||||
composition_event = 10,
|
composition_event = 10,
|
||||||
navigation_current_entry_change_event = 11,
|
navigation_current_entry_change_event = 11,
|
||||||
|
navigate_event = 12,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const MutationEvent = c.dom_mutation_event;
|
pub const MutationEvent = c.dom_mutation_event;
|
||||||
|
|||||||
Reference in New Issue
Block a user