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`).
This commit is contained in:
Karl Seguin
2025-05-26 15:08:25 +08:00
parent b17f20e2c5
commit ecd593fb53
2 changed files with 33 additions and 1 deletions

View File

@@ -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" },
}, .{});
}

View File

@@ -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