mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Merge pull request #894 from lightpanda-io/HTMLStyleElement_get_sheet
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
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 parser = @import("netsurf.zig");
|
||||||
const DataSet = @import("html/DataSet.zig");
|
const DataSet = @import("html/DataSet.zig");
|
||||||
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
|
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
|
||||||
|
const StyleSheet = @import("cssom/stylesheet.zig").StyleSheet;
|
||||||
const CSSStyleDeclaration = @import("cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
const CSSStyleDeclaration = @import("cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
||||||
|
|
||||||
// for HTMLScript (but probably needs to be added to more)
|
// for HTMLScript (but probably needs to be added to more)
|
||||||
@@ -39,10 +40,17 @@ onerror: ?Env.Function = null,
|
|||||||
// for HTMLElement
|
// for HTMLElement
|
||||||
style: CSSStyleDeclaration = .empty,
|
style: CSSStyleDeclaration = .empty,
|
||||||
dataset: ?DataSet = null,
|
dataset: ?DataSet = null,
|
||||||
|
template_content: ?*parser.DocumentFragment = null,
|
||||||
|
|
||||||
|
// For dom/element
|
||||||
|
shadow_root: ?*ShadowRoot = null,
|
||||||
|
|
||||||
// for html/document
|
// for html/document
|
||||||
ready_state: ReadyState = .loading,
|
ready_state: ReadyState = .loading,
|
||||||
|
|
||||||
|
// for html/HTMLStyleElement
|
||||||
|
style_sheet: ?*StyleSheet = null,
|
||||||
|
|
||||||
// for dom/document
|
// for dom/document
|
||||||
active_element: ?*parser.Element = null,
|
active_element: ?*parser.Element = null,
|
||||||
|
|
||||||
@@ -61,10 +69,6 @@ active_element: ?*parser.Element = null,
|
|||||||
// default (by returning selectedIndex == 0).
|
// default (by returning selectedIndex == 0).
|
||||||
explicit_index_set: bool = false,
|
explicit_index_set: bool = false,
|
||||||
|
|
||||||
template_content: ?*parser.DocumentFragment = null,
|
|
||||||
|
|
||||||
shadow_root: ?*ShadowRoot = null,
|
|
||||||
|
|
||||||
const ReadyState = enum {
|
const ReadyState = enum {
|
||||||
loading,
|
loading,
|
||||||
interactive,
|
interactive,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const Node = @import("../dom/node.zig").Node;
|
|||||||
const Element = @import("../dom/element.zig").Element;
|
const Element = @import("../dom/element.zig").Element;
|
||||||
const DataSet = @import("DataSet.zig");
|
const DataSet = @import("DataSet.zig");
|
||||||
|
|
||||||
|
const StyleSheet = @import("../cssom/stylesheet.zig").StyleSheet;
|
||||||
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
||||||
|
|
||||||
// HTMLElement interfaces
|
// HTMLElement interfaces
|
||||||
@@ -1012,6 +1013,18 @@ pub const HTMLStyleElement = struct {
|
|||||||
pub const Self = parser.Style;
|
pub const Self = parser.Style;
|
||||||
pub const prototype = *HTMLElement;
|
pub const prototype = *HTMLElement;
|
||||||
pub const subtype = .node;
|
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 {
|
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 {
|
const Check = struct {
|
||||||
input: []const u8,
|
input: []const u8,
|
||||||
expected: ?[]const u8 = null, // Needed when input != expected
|
expected: ?[]const u8 = null, // Needed when input != expected
|
||||||
|
|||||||
Reference in New Issue
Block a user