mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
add HTMLStyleElement.get_sheet
This commit is contained in:
@@ -30,6 +30,7 @@ const Env = @import("env.zig").Env;
|
||||
const parser = @import("netsurf.zig");
|
||||
const DataSet = @import("html/DataSet.zig");
|
||||
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
|
||||
const StyleSheet = @import("cssom/stylesheet.zig").StyleSheet;
|
||||
const CSSStyleDeclaration = @import("cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
||||
|
||||
// for HTMLScript (but probably needs to be added to more)
|
||||
@@ -39,10 +40,17 @@ onerror: ?Env.Function = null,
|
||||
// for HTMLElement
|
||||
style: CSSStyleDeclaration = .empty,
|
||||
dataset: ?DataSet = null,
|
||||
template_content: ?*parser.DocumentFragment = null,
|
||||
|
||||
// For dom/element
|
||||
shadow_root: ?*ShadowRoot = null,
|
||||
|
||||
// for html/document
|
||||
ready_state: ReadyState = .loading,
|
||||
|
||||
// for html/HTMLStyleElement
|
||||
style_sheet: ?*StyleSheet = null,
|
||||
|
||||
// for dom/document
|
||||
active_element: ?*parser.Element = null,
|
||||
|
||||
@@ -61,10 +69,6 @@ active_element: ?*parser.Element = null,
|
||||
// default (by returning selectedIndex == 0).
|
||||
explicit_index_set: bool = false,
|
||||
|
||||
template_content: ?*parser.DocumentFragment = null,
|
||||
|
||||
shadow_root: ?*ShadowRoot = null,
|
||||
|
||||
const ReadyState = enum {
|
||||
loading,
|
||||
interactive,
|
||||
|
||||
@@ -29,6 +29,7 @@ const Node = @import("../dom/node.zig").Node;
|
||||
const Element = @import("../dom/element.zig").Element;
|
||||
const DataSet = @import("DataSet.zig");
|
||||
|
||||
const StyleSheet = @import("../cssom/stylesheet.zig").StyleSheet;
|
||||
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
||||
|
||||
// HTMLElement interfaces
|
||||
@@ -1012,6 +1013,18 @@ pub const HTMLStyleElement = struct {
|
||||
pub const Self = parser.Style;
|
||||
pub const prototype = *HTMLElement;
|
||||
pub const subtype = .node;
|
||||
|
||||
pub fn get_sheet(self: *parser.Style, page: *Page) !*StyleSheet {
|
||||
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
|
||||
if (state.style_sheet) |ss| {
|
||||
return ss;
|
||||
}
|
||||
|
||||
const ss = try page.arena.create(StyleSheet);
|
||||
ss.* = .{};
|
||||
state.style_sheet = ss;
|
||||
return ss;
|
||||
}
|
||||
};
|
||||
|
||||
pub const HTMLTableElement = struct {
|
||||
@@ -1453,6 +1466,18 @@ test "Browser.HTML.HTMLTemplateElement" {
|
||||
}, .{});
|
||||
}
|
||||
|
||||
test "Browser.HTML.HTMLStyleElement" {
|
||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = "" });
|
||||
defer runner.deinit();
|
||||
|
||||
try runner.testCases(&.{
|
||||
.{ "let s = document.createElement('style')", null },
|
||||
.{ "s.sheet.type", "text/css" },
|
||||
.{ "s.sheet == s.sheet", "true" },
|
||||
.{ "document.createElement('style').sheet == s.sheet", "false" },
|
||||
}, .{});
|
||||
}
|
||||
|
||||
const Check = struct {
|
||||
input: []const u8,
|
||||
expected: ?[]const u8 = null, // Needed when input != expected
|
||||
|
||||
Reference in New Issue
Block a user