mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
keep EventTargetTBase as the dom_event_target
Mimic a dom_node by adding the refcnt field right after the vtable pointer.
This commit is contained in:
@@ -39,7 +39,7 @@ pub const EventTarget = struct {
|
|||||||
// Ideally, we'd remove this duality. Failing that, we'll need to embed
|
// Ideally, we'd remove this duality. Failing that, we'll need to embed
|
||||||
// data into the *parser.EventTarget should we need this for other types.
|
// data into the *parser.EventTarget should we need this for other types.
|
||||||
// For now, for the Window, which is a singleton, we can do this:
|
// For now, for the Window, which is a singleton, we can do this:
|
||||||
if (@intFromPtr(et) == @intFromPtr(&page.window.base.target)) {
|
if (@intFromPtr(et) == @intFromPtr(&page.window.base)) {
|
||||||
return .{ .Window = &page.window };
|
return .{ .Window = &page.window };
|
||||||
}
|
}
|
||||||
return Nod.Node.toInterface(@as(*parser.Node, @ptrCast(et)));
|
return Nod.Node.toInterface(@as(*parser.Node, @ptrCast(et)));
|
||||||
|
|||||||
@@ -775,7 +775,6 @@ pub const EventTargetTBase = extern struct {
|
|||||||
.add_event_listener = add_event_listener,
|
.add_event_listener = add_event_listener,
|
||||||
.iter_event_listener = iter_event_listener,
|
.iter_event_listener = iter_event_listener,
|
||||||
},
|
},
|
||||||
eti: c.dom_event_target_internal = c.dom_event_target_internal{ .listeners = null },
|
|
||||||
|
|
||||||
// When we dispatch the event, we need to provide a target. In reality, the
|
// When we dispatch the event, we need to provide a target. In reality, the
|
||||||
// target is the container of this EventTargetTBase. But we can't pass that
|
// target is the container of this EventTargetTBase. But we can't pass that
|
||||||
@@ -785,12 +784,9 @@ pub const EventTargetTBase = extern struct {
|
|||||||
// as the target, what happens if libdom calls dom_node_ref(window)? If
|
// as the target, what happens if libdom calls dom_node_ref(window)? If
|
||||||
// you're lucky, you'll crash. If you're unlucky, you'll increment a random
|
// you're lucky, you'll crash. If you're unlucky, you'll increment a random
|
||||||
// part of the window structure.
|
// part of the window structure.
|
||||||
target: DummyTarget = .{},
|
refcnt: u32 = 0,
|
||||||
|
|
||||||
const DummyTarget = extern struct {
|
eti: c.dom_event_target_internal = c.dom_event_target_internal{ .listeners = null },
|
||||||
vtable: usize = undefined,
|
|
||||||
refcnt: u32 = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn add_event_listener(et: [*c]c.dom_event_target, t: [*c]c.dom_string, l: ?*c.struct_dom_event_listener, capture: bool) callconv(.C) c.dom_exception {
|
pub fn add_event_listener(et: [*c]c.dom_event_target, t: [*c]c.dom_string, l: ?*c.struct_dom_event_listener, capture: bool) callconv(.C) c.dom_exception {
|
||||||
const self = @as(*Self, @ptrCast(et));
|
const self = @as(*Self, @ptrCast(et));
|
||||||
@@ -800,11 +796,11 @@ pub const EventTargetTBase = extern struct {
|
|||||||
pub fn dispatch_event(et: [*c]c.dom_event_target, evt: ?*c.struct_dom_event, res: [*c]bool) callconv(.C) c.dom_exception {
|
pub fn dispatch_event(et: [*c]c.dom_event_target, evt: ?*c.struct_dom_event, res: [*c]bool) callconv(.C) c.dom_exception {
|
||||||
const self = @as(*Self, @ptrCast(et));
|
const self = @as(*Self, @ptrCast(et));
|
||||||
// Set the event target to the target dispatched.
|
// Set the event target to the target dispatched.
|
||||||
const e = c._dom_event_set_target(evt, @ptrCast(&self.target));
|
const e = c._dom_event_set_target(evt, et);
|
||||||
if (e != c.DOM_NO_ERR) {
|
if (e != c.DOM_NO_ERR) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
return c._dom_event_target_dispatch(@ptrCast(&self.target), &self.eti, evt, c.DOM_AT_TARGET, res);
|
return c._dom_event_target_dispatch(et, &self.eti, evt, c.DOM_AT_TARGET, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_event_listener(et: [*c]c.dom_event_target, t: [*c]c.dom_string, l: ?*c.struct_dom_event_listener, capture: bool) callconv(.C) c.dom_exception {
|
pub fn remove_event_listener(et: [*c]c.dom_event_target, t: [*c]c.dom_string, l: ?*c.struct_dom_event_listener, capture: bool) callconv(.C) c.dom_exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user