From 97bc19e4ae9930df49175747cdf03a791b5993be Mon Sep 17 00:00:00 2001 From: Muki Kiboigo Date: Wed, 18 Jun 2025 11:31:43 -0700 Subject: [PATCH] clean up various imports in CSSOM --- src/browser/cssom/css_rule.zig | 3 --- src/browser/cssom/css_rule_list.zig | 2 -- src/browser/cssom/css_stylesheet.zig | 21 +++++++++------------ src/browser/cssom/stylesheet.zig | 24 ++++++++++++------------ 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/browser/cssom/css_rule.zig b/src/browser/cssom/css_rule.zig index dceff93c..857c0a8a 100644 --- a/src/browser/cssom/css_rule.zig +++ b/src/browser/cssom/css_rule.zig @@ -18,9 +18,6 @@ const std = @import("std"); -const Page = @import("../page.zig").Page; - -const CSSStyleDeclaration = @import("css_style_declaration.zig").CSSStyleDeclaration; const CSSStyleSheet = @import("css_stylesheet.zig").CSSStyleSheet; pub const Interfaces = .{ diff --git a/src/browser/cssom/css_rule_list.zig b/src/browser/cssom/css_rule_list.zig index 18993b7a..bf5222f2 100644 --- a/src/browser/cssom/css_rule_list.zig +++ b/src/browser/cssom/css_rule_list.zig @@ -18,9 +18,7 @@ const std = @import("std"); -const Page = @import("../page.zig").Page; const StyleSheet = @import("stylesheet.zig").StyleSheet; - const CSSRule = @import("css_rule.zig").CSSRule; const CSSImportRule = @import("css_rule.zig").CSSImportRule; diff --git a/src/browser/cssom/css_stylesheet.zig b/src/browser/cssom/css_stylesheet.zig index 454117ed..e18e88be 100644 --- a/src/browser/cssom/css_stylesheet.zig +++ b/src/browser/cssom/css_stylesheet.zig @@ -25,9 +25,8 @@ const CSSRuleList = @import("css_rule_list.zig").CSSRuleList; const CSSImportRule = @import("css_rule.zig").CSSImportRule; pub const CSSStyleSheet = struct { - pub const prototype = *StyleSheet; - - css_rules: *CSSRuleList, + proto: StyleSheet, + css_rules: CSSRuleList, owner_rule: ?*CSSImportRule, const CSSStyleSheetOpts = struct { @@ -36,15 +35,13 @@ pub const CSSStyleSheet = struct { disabled: bool = false, }; - pub fn constructor(_opts: ?CSSStyleSheetOpts, page: *Page) !CSSStyleSheet { + pub fn constructor(_opts: ?CSSStyleSheetOpts) !CSSStyleSheet { const opts = _opts orelse CSSStyleSheetOpts{}; - _ = opts; - - const arena = page.arena; - const rules = try arena.create(CSSRuleList); - rules.* = .constructor(); - - return .{ .css_rules = rules, .owner_rule = null }; + return .{ + .proto = StyleSheet{ .disabled = opts.disabled }, + .css_rules = .constructor(), + .owner_rule = null, + }; } pub fn get_ownerRule(_: *CSSStyleSheet) ?*CSSImportRule { @@ -52,7 +49,7 @@ pub const CSSStyleSheet = struct { } pub fn get_cssRules(self: *CSSStyleSheet) *CSSRuleList { - return self.css_rules; + return &self.css_rules; } pub fn _insertRule(self: *CSSStyleSheet, rule: []const u8, _index: ?usize, page: *Page) !usize { diff --git a/src/browser/cssom/stylesheet.zig b/src/browser/cssom/stylesheet.zig index 61fc4d40..7086063c 100644 --- a/src/browser/cssom/stylesheet.zig +++ b/src/browser/cssom/stylesheet.zig @@ -20,36 +20,36 @@ const parser = @import("../netsurf.zig"); // https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet#specifications pub const StyleSheet = struct { - disabled: bool, - href: []const u8, - owner_node: *parser.Node, - parent_stylesheet: ?*StyleSheet, - title: []const u8, - type: []const u8, + disabled: bool = false, + href: []const u8 = "", + owner_node: ?*parser.Node = null, + parent_stylesheet: ?*StyleSheet = null, + title: []const u8 = "", + type: []const u8 = "text/css", - pub fn get_disabled(self: *StyleSheet) bool { + pub fn get_disabled(self: *const StyleSheet) bool { return self.disabled; } - pub fn get_href(self: *StyleSheet) []const u8 { + pub fn get_href(self: *const StyleSheet) []const u8 { return self.href; } // TODO: media - pub fn get_ownerNode(self: *StyleSheet) *parser.Node { + pub fn get_ownerNode(self: *const StyleSheet) ?*parser.Node { return self.owner_node; } - pub fn get_parentStyleSheet(self: *StyleSheet) ?*StyleSheet { + pub fn get_parentStyleSheet(self: *const StyleSheet) ?*StyleSheet { return self.parent_stylesheet; } - pub fn get_title(self: *StyleSheet) []const u8 { + pub fn get_title(self: *const StyleSheet) []const u8 { return self.title; } - pub fn get_type(self: *StyleSheet) []const u8 { + pub fn get_type(self: *const StyleSheet) []const u8 { return self.type; } };