Skip to content

Commit

Permalink
browser: dispatch DOMContentLoaded event
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed Feb 5, 2024
1 parent 9050f25 commit 5aef5a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/browser/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,13 @@ pub const Page = struct {

// TODO wait for deferred scripts

// TODO dispatch DOMContentLoaded before the transition to "complete",
// dispatch DOMContentLoaded before the transition to "complete",
// at the point where all subresources apart from async script elements
// have loaded.
// https://html.spec.whatwg.org/#reporting-document-loading-status
const evt = try parser.eventCreate();
try parser.eventInit(evt, "DOMContentLoaded", .{ .bubbles = true, .cancelable = true });
_ = try parser.eventTargetDispatchEvent(parser.toEventTarget(parser.DocumentHTML, html_doc), evt);

// eval async scripts.
for (sasync.items) |e| {
Expand Down
5 changes: 5 additions & 0 deletions src/netsurf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ fn eventTargetVtable(et: *EventTarget) c.dom_event_target_vtable {
return getVtable(c.dom_event_target_vtable, EventTarget, et);
}

pub inline fn toEventTarget(comptime T: type, v: *T) *EventTarget {
const node_aligned: *align(@alignOf(NodeExternal)) T = @alignCast(v);
return @as(*EventTarget, @ptrCast(node_aligned));
}

pub fn eventTargetHasListener(
et: *EventTarget,
typ: []const u8,
Expand Down

0 comments on commit 5aef5a2

Please sign in to comment.