mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
dispatch Style element's load event from nodeIsReady
This commit is contained in:
@@ -1053,6 +1053,29 @@ pub fn linkAddedCallback(self: *Page, link: *Element.Html.Link) !void {
|
|||||||
try self._to_load.append(self.arena, link._proto);
|
try self._to_load.append(self.arena, link._proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn styleAddedCallback(self: *Page, style: *Element.Html.Style) !void {
|
||||||
|
// if we're planning on navigating to another page, don't trigger load event.
|
||||||
|
if (self.isGoingAway()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try self._to_load.append(self.arena, style._proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn imageAddedCallback(self: *Page, image: *Element.Html.Image) !void {
|
||||||
|
// if we're planning on navigating to another page, don't trigger load event.
|
||||||
|
if (self.isGoingAway()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const element = image.asElement();
|
||||||
|
// Exit if src not set.
|
||||||
|
const src = element.getAttributeSafe(comptime .wrap("src")) orelse return;
|
||||||
|
if (src.len == 0) return;
|
||||||
|
|
||||||
|
try self._to_load.append(self.arena, image._proto);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn domChanged(self: *Page) void {
|
pub fn domChanged(self: *Page) void {
|
||||||
self.version += 1;
|
self.version += 1;
|
||||||
|
|
||||||
@@ -2867,6 +2890,11 @@ fn nodeIsReady(self: *Page, comptime from_parser: bool, node: *Node) !void {
|
|||||||
log.err(.page, "page.nodeIsReady", .{ .err = err, .element = "link", .type = self._type });
|
log.err(.page, "page.nodeIsReady", .{ .err = err, .element = "link", .type = self._type });
|
||||||
return error.LinkLoadError;
|
return error.LinkLoadError;
|
||||||
};
|
};
|
||||||
|
} else if (node.is(Element.Html.Style)) |style| {
|
||||||
|
self.styleAddedCallback(style) catch |err| {
|
||||||
|
log.err(.page, "page.nodeIsReady", .{ .err = err, .element = "style", .type = self._type });
|
||||||
|
return error.StyleLoadError;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -723,6 +723,7 @@ const CloneError = error{
|
|||||||
IFrameLoadError,
|
IFrameLoadError,
|
||||||
TooManyContexts,
|
TooManyContexts,
|
||||||
LinkLoadError,
|
LinkLoadError,
|
||||||
|
StyleLoadError,
|
||||||
};
|
};
|
||||||
pub fn cloneNode(self: *Node, deep_: ?bool, page: *Page) CloneError!*Node {
|
pub fn cloneNode(self: *Node, deep_: ?bool, page: *Page) CloneError!*Node {
|
||||||
const deep = deep_ orelse false;
|
const deep = deep_ orelse false;
|
||||||
|
|||||||
@@ -113,13 +113,6 @@ pub const JsApi = struct {
|
|||||||
pub const sheet = bridge.accessor(Style.getSheet, null, .{});
|
pub const sheet = bridge.accessor(Style.getSheet, null, .{});
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Build = struct {
|
|
||||||
pub fn created(node: *Node, page: *Page) !void {
|
|
||||||
// Push to `_to_load` to dispatch load event just before window load event.
|
|
||||||
return page._to_load.append(page.arena, node.as(Element.Html));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const testing = @import("../../../../testing.zig");
|
const testing = @import("../../../../testing.zig");
|
||||||
test "WebApi: Style" {
|
test "WebApi: Style" {
|
||||||
try testing.htmlRunner("element/html/style.html", .{});
|
try testing.htmlRunner("element/html/style.html", .{});
|
||||||
|
|||||||
Reference in New Issue
Block a user