Skip to content

Commit ecd593f

Browse files
committed
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`).
1 parent b17f20e commit ecd593f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/browser/cssom/css_style_declaration.zig

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ pub const CSSStyleDeclaration = struct {
9595

9696
// TODO should handle properly shorthand properties and canonical forms
9797
pub fn _getPropertyValue(self: *const CSSStyleDeclaration, name: []const u8) []const u8 {
98-
return if (self.store.get(name)) |prop| prop.value else "";
98+
if (self.store.get(name)) |prop| {
99+
return prop.value;
100+
}
101+
102+
// default to everything being visible (unless it's been explicitly set)
103+
if (std.mem.eql(u8, name, "visibility")) {
104+
return "visible";
105+
}
106+
107+
return "";
99108
}
100109

101110
pub fn _item(self: *const CSSStyleDeclaration, index: usize) []const u8 {
@@ -127,6 +136,11 @@ pub const CSSStyleDeclaration = struct {
127136

128137
gop.value_ptr.* = .{ .value = owned_value, .priority = is_important };
129138
}
139+
140+
pub fn named_get(self: *const CSSStyleDeclaration, name: []const u8, _: *bool) []const u8 {
141+
std.debug.print("named_get: {s} {s}\n", .{name, self._getPropertyValue(name)});
142+
return self._getPropertyValue(name);
143+
}
130144
};
131145

132146
const testing = @import("../../testing.zig");
@@ -164,6 +178,7 @@ test "CSSOM.CSSStyleDeclaration" {
164178
.{ "style.setProperty('color', 'green')", "undefined" },
165179
.{ "style.getPropertyValue('color')", "green" },
166180
.{ "style.length", "4" },
181+
.{ "style.color", "green"},
167182

168183
.{ "style.setProperty('padding', '10px', 'important')", "undefined" },
169184
.{ "style.getPropertyValue('padding')", "10px" },
@@ -225,4 +240,9 @@ test "CSSOM.CSSStyleDeclaration" {
225240
.{ "style.setProperty('border-bottom-left-radius', '5px')", "undefined" },
226241
.{ "style.getPropertyValue('border-bottom-left-radius')", "5px" },
227242
}, .{});
243+
244+
try runner.testCases(&.{
245+
.{ "style.visibility", "visible" },
246+
.{ "style.getPropertyValue('visibility')", "visible" },
247+
}, .{});
228248
}

src/browser/dom/element.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ pub const Element = struct {
407407
pub fn _scrollIntoViewIfNeeded(_: *parser.Element, center_if_needed: ?bool) void {
408408
_ = center_if_needed;
409409
}
410+
411+
const CheckVisibilityOpts = struct {
412+
contentVisibilityAuto: bool,
413+
opacityProperty: bool,
414+
visibilityProperty: bool,
415+
};
416+
417+
pub fn _checkVisibility(self: *parser.Element, opts: ?CheckVisibilityOpts) bool {
418+
_ = self;
419+
_ = opts;
420+
return true;
421+
}
410422
};
411423

412424
// Tests

0 commit comments

Comments
 (0)