From ecd593fb53fb014d0768b3b3e14a8661d7a307bf Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Mon, 26 May 2025 15:08:25 +0800 Subject: [PATCH] Add dummy Element.checkVisibility `checkVisibility` currently always return true. Also, when the visibility CSS property is checked, always return 'visible'. This allows the playwright click test to pass with a working getComputedStyle. It's also probably more accurate - by default, most elements are probably visible. But it still isn't great. Add named_get to CSSStyleDeclaration (allowing things like `style.display`). --- src/browser/cssom/css_style_declaration.zig | 22 ++++++++++++++++++++- src/browser/dom/element.zig | 12 +++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/browser/cssom/css_style_declaration.zig b/src/browser/cssom/css_style_declaration.zig index 00c8f039..08361906 100644 --- a/src/browser/cssom/css_style_declaration.zig +++ b/src/browser/cssom/css_style_declaration.zig @@ -95,7 +95,16 @@ pub const CSSStyleDeclaration = struct { // TODO should handle properly shorthand properties and canonical forms pub fn _getPropertyValue(self: *const CSSStyleDeclaration, name: []const u8) []const u8 { - return if (self.store.get(name)) |prop| prop.value else ""; + if (self.store.get(name)) |prop| { + return prop.value; + } + + // default to everything being visible (unless it's been explicitly set) + if (std.mem.eql(u8, name, "visibility")) { + return "visible"; + } + + return ""; } pub fn _item(self: *const CSSStyleDeclaration, index: usize) []const u8 { @@ -127,6 +136,11 @@ pub const CSSStyleDeclaration = struct { gop.value_ptr.* = .{ .value = owned_value, .priority = is_important }; } + + pub fn named_get(self: *const CSSStyleDeclaration, name: []const u8, _: *bool) []const u8 { + std.debug.print("named_get: {s} {s}\n", .{name, self._getPropertyValue(name)}); + return self._getPropertyValue(name); + } }; const testing = @import("../../testing.zig"); @@ -164,6 +178,7 @@ test "CSSOM.CSSStyleDeclaration" { .{ "style.setProperty('color', 'green')", "undefined" }, .{ "style.getPropertyValue('color')", "green" }, .{ "style.length", "4" }, + .{ "style.color", "green"}, .{ "style.setProperty('padding', '10px', 'important')", "undefined" }, .{ "style.getPropertyValue('padding')", "10px" }, @@ -225,4 +240,9 @@ test "CSSOM.CSSStyleDeclaration" { .{ "style.setProperty('border-bottom-left-radius', '5px')", "undefined" }, .{ "style.getPropertyValue('border-bottom-left-radius')", "5px" }, }, .{}); + + try runner.testCases(&.{ + .{ "style.visibility", "visible" }, + .{ "style.getPropertyValue('visibility')", "visible" }, + }, .{}); } diff --git a/src/browser/dom/element.zig b/src/browser/dom/element.zig index dd2a863d..6ab4dbfd 100644 --- a/src/browser/dom/element.zig +++ b/src/browser/dom/element.zig @@ -407,6 +407,18 @@ pub const Element = struct { pub fn _scrollIntoViewIfNeeded(_: *parser.Element, center_if_needed: ?bool) void { _ = center_if_needed; } + + const CheckVisibilityOpts = struct { + contentVisibilityAuto: bool, + opacityProperty: bool, + visibilityProperty: bool, + }; + + pub fn _checkVisibility(self: *parser.Element, opts: ?CheckVisibilityOpts) bool { + _ = self; + _ = opts; + return true; + } }; // Tests