wire up CSSStyleSheet.ownerNode to the style element

This commit is contained in:
egrs
2026-02-18 12:41:31 +01:00
parent 54d6eed740
commit 488e72ef4e
3 changed files with 14 additions and 4 deletions

View File

@@ -38,6 +38,11 @@
testing.expectEqual(true, tempStyle.sheet instanceof CSSStyleSheet); testing.expectEqual(true, tempStyle.sheet instanceof CSSStyleSheet);
document.head.removeChild(tempStyle); document.head.removeChild(tempStyle);
testing.expectEqual(null, tempStyle.sheet); testing.expectEqual(null, tempStyle.sheet);
// ownerNode points back to the style element
const ownStyle = document.createElement('style');
document.head.appendChild(ownStyle);
testing.expectEqual(true, ownStyle.sheet.ownerNode === ownStyle);
} }
</script> </script>

View File

@@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const js = @import("../../js/js.zig"); const js = @import("../../js/js.zig");
const Page = @import("../../Page.zig"); const Page = @import("../../Page.zig");
const Element = @import("../Element.zig");
const CSSRuleList = @import("CSSRuleList.zig"); const CSSRuleList = @import("CSSRuleList.zig");
const CSSRule = @import("CSSRule.zig"); const CSSRule = @import("CSSRule.zig");
@@ -11,14 +12,18 @@ _title: []const u8 = "",
_disabled: bool = false, _disabled: bool = false,
_css_rules: ?*CSSRuleList = null, _css_rules: ?*CSSRuleList = null,
_owner_rule: ?*CSSRule = null, _owner_rule: ?*CSSRule = null,
_owner_node: ?*Element = null,
pub fn init(page: *Page) !*CSSStyleSheet { pub fn init(page: *Page) !*CSSStyleSheet {
return page._factory.create(CSSStyleSheet{}); return page._factory.create(CSSStyleSheet{});
} }
pub fn getOwnerNode(self: *const CSSStyleSheet) ?*CSSStyleSheet { pub fn initWithOwner(owner: *Element, page: *Page) !*CSSStyleSheet {
_ = self; return page._factory.create(CSSStyleSheet{ ._owner_node = owner });
return null; }
pub fn getOwnerNode(self: *const CSSStyleSheet) ?*Element {
return self._owner_node;
} }
pub fn getHref(self: *const CSSStyleSheet) ?[]const u8 { pub fn getHref(self: *const CSSStyleSheet) ?[]const u8 {

View File

@@ -92,7 +92,7 @@ pub fn getSheet(self: *Style, page: *Page) !?*CSSStyleSheet {
} }
if (self._sheet) |sheet| return sheet; if (self._sheet) |sheet| return sheet;
const sheet = try CSSStyleSheet.init(page); const sheet = try CSSStyleSheet.initWithOwner(self.asElement(), page);
self._sheet = sheet; self._sheet = sheet;
return sheet; return sheet;
} }