clean up various imports in CSSOM

This commit is contained in:
Muki Kiboigo
2025-06-18 11:31:43 -07:00
parent 2656cc7842
commit 97bc19e4ae
4 changed files with 21 additions and 29 deletions

View File

@@ -18,9 +18,6 @@
const std = @import("std"); 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; const CSSStyleSheet = @import("css_stylesheet.zig").CSSStyleSheet;
pub const Interfaces = .{ pub const Interfaces = .{

View File

@@ -18,9 +18,7 @@
const std = @import("std"); const std = @import("std");
const Page = @import("../page.zig").Page;
const StyleSheet = @import("stylesheet.zig").StyleSheet; const StyleSheet = @import("stylesheet.zig").StyleSheet;
const CSSRule = @import("css_rule.zig").CSSRule; const CSSRule = @import("css_rule.zig").CSSRule;
const CSSImportRule = @import("css_rule.zig").CSSImportRule; const CSSImportRule = @import("css_rule.zig").CSSImportRule;

View File

@@ -25,9 +25,8 @@ const CSSRuleList = @import("css_rule_list.zig").CSSRuleList;
const CSSImportRule = @import("css_rule.zig").CSSImportRule; const CSSImportRule = @import("css_rule.zig").CSSImportRule;
pub const CSSStyleSheet = struct { pub const CSSStyleSheet = struct {
pub const prototype = *StyleSheet; proto: StyleSheet,
css_rules: CSSRuleList,
css_rules: *CSSRuleList,
owner_rule: ?*CSSImportRule, owner_rule: ?*CSSImportRule,
const CSSStyleSheetOpts = struct { const CSSStyleSheetOpts = struct {
@@ -36,15 +35,13 @@ pub const CSSStyleSheet = struct {
disabled: bool = false, disabled: bool = false,
}; };
pub fn constructor(_opts: ?CSSStyleSheetOpts, page: *Page) !CSSStyleSheet { pub fn constructor(_opts: ?CSSStyleSheetOpts) !CSSStyleSheet {
const opts = _opts orelse CSSStyleSheetOpts{}; const opts = _opts orelse CSSStyleSheetOpts{};
_ = opts; return .{
.proto = StyleSheet{ .disabled = opts.disabled },
const arena = page.arena; .css_rules = .constructor(),
const rules = try arena.create(CSSRuleList); .owner_rule = null,
rules.* = .constructor(); };
return .{ .css_rules = rules, .owner_rule = null };
} }
pub fn get_ownerRule(_: *CSSStyleSheet) ?*CSSImportRule { pub fn get_ownerRule(_: *CSSStyleSheet) ?*CSSImportRule {
@@ -52,7 +49,7 @@ pub const CSSStyleSheet = struct {
} }
pub fn get_cssRules(self: *CSSStyleSheet) *CSSRuleList { 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 { pub fn _insertRule(self: *CSSStyleSheet, rule: []const u8, _index: ?usize, page: *Page) !usize {

View File

@@ -20,36 +20,36 @@ const parser = @import("../netsurf.zig");
// https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet#specifications // https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet#specifications
pub const StyleSheet = struct { pub const StyleSheet = struct {
disabled: bool, disabled: bool = false,
href: []const u8, href: []const u8 = "",
owner_node: *parser.Node, owner_node: ?*parser.Node = null,
parent_stylesheet: ?*StyleSheet, parent_stylesheet: ?*StyleSheet = null,
title: []const u8, title: []const u8 = "",
type: []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; return self.disabled;
} }
pub fn get_href(self: *StyleSheet) []const u8 { pub fn get_href(self: *const StyleSheet) []const u8 {
return self.href; return self.href;
} }
// TODO: media // TODO: media
pub fn get_ownerNode(self: *StyleSheet) *parser.Node { pub fn get_ownerNode(self: *const StyleSheet) ?*parser.Node {
return self.owner_node; return self.owner_node;
} }
pub fn get_parentStyleSheet(self: *StyleSheet) ?*StyleSheet { pub fn get_parentStyleSheet(self: *const StyleSheet) ?*StyleSheet {
return self.parent_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; return self.title;
} }
pub fn get_type(self: *StyleSheet) []const u8 { pub fn get_type(self: *const StyleSheet) []const u8 {
return self.type; return self.type;
} }
}; };