mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Bubble events to the Window
This commit is contained in:
@@ -148,8 +148,22 @@ pub const EventTarget = struct {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn _dispatchEvent(self: *parser.EventTarget, event: *parser.Event) !bool {
|
||||
return try parser.eventTargetDispatchEvent(self, event);
|
||||
pub fn _dispatchEvent(self: *parser.EventTarget, event: *parser.Event, page: *Page) !bool {
|
||||
const res = try parser.eventTargetDispatchEvent(self, event);
|
||||
|
||||
// TODO: If we get this working, we should also create a getter to check
|
||||
// stopPropagation and not bubble to window if true.
|
||||
if (!parser.eventBubbles(event)) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// I think this mutates `event`, which means any JavaScript that captured
|
||||
// it will be mutated incorrectly.
|
||||
const Window = @import("../html/window.zig").Window;
|
||||
return parser.eventTargetDispatchEvent(
|
||||
parser.toEventTarget(Window, &page.window),
|
||||
event,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -604,7 +604,7 @@ fn eventTargetVtable(et: *EventTarget) c.dom_event_target_vtable {
|
||||
return @as([*c]const c.dom_event_target_vtable, @ptrCast(vtable_aligned)).*;
|
||||
}
|
||||
|
||||
pub inline fn toEventTarget(comptime T: type, v: *T) *EventTarget {
|
||||
pub fn toEventTarget(comptime T: type, v: *T) *EventTarget {
|
||||
if (comptime eventTargetTBaseFieldName(T)) |field| {
|
||||
const et_aligned: *align(@alignOf(EventTarget)) EventTargetTBase = @alignCast(&@field(v, field));
|
||||
return @as(*EventTarget, @ptrCast(et_aligned));
|
||||
|
||||
@@ -13,4 +13,12 @@
|
||||
|
||||
el.dispatchEvent(new CustomEvent('c2', {detail: {over: 9000}}));
|
||||
testing.expectEqual("c2-9000", capture);
|
||||
|
||||
let window_calls = 0;
|
||||
window.addEventListener('c1', () => {
|
||||
window_calls += 1;
|
||||
});
|
||||
|
||||
el.dispatchEvent(new CustomEvent('c1', {bubbles: true}));
|
||||
testing.expectEqual(1, window_calls);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user