Skip to content

Commit 1a72bf5

Browse files
authored
Merge pull request #692 from lightpanda-io/get_computed_style
make getComptedStyle return an empty CSSStyleDeclaration
2 parents eae9f9c + b8cd0c1 commit 1a72bf5

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

src/browser/cssom/css_style_declaration.zig

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ pub const CSSStyleDeclaration = struct {
3333
store: std.StringHashMapUnmanaged(Property),
3434
order: std.ArrayListUnmanaged([]const u8),
3535

36+
pub const empty: CSSStyleDeclaration = .{
37+
.store = .empty,
38+
.order = .empty,
39+
};
40+
3641
const Property = struct {
3742
value: []const u8,
3843
priority: bool,
@@ -90,7 +95,16 @@ pub const CSSStyleDeclaration = struct {
9095

9196
// TODO should handle properly shorthand properties and canonical forms
9297
pub fn _getPropertyValue(self: *const CSSStyleDeclaration, name: []const u8) []const u8 {
93-
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 "";
94108
}
95109

96110
pub fn _item(self: *const CSSStyleDeclaration, index: usize) []const u8 {
@@ -122,6 +136,10 @@ pub const CSSStyleDeclaration = struct {
122136

123137
gop.value_ptr.* = .{ .value = owned_value, .priority = is_important };
124138
}
139+
140+
pub fn named_get(self: *const CSSStyleDeclaration, name: []const u8, _: *bool) []const u8 {
141+
return self._getPropertyValue(name);
142+
}
125143
};
126144

127145
const testing = @import("../../testing.zig");
@@ -159,6 +177,7 @@ test "CSSOM.CSSStyleDeclaration" {
159177
.{ "style.setProperty('color', 'green')", "undefined" },
160178
.{ "style.getPropertyValue('color')", "green" },
161179
.{ "style.length", "4" },
180+
.{ "style.color", "green"},
162181

163182
.{ "style.setProperty('padding', '10px', 'important')", "undefined" },
164183
.{ "style.getPropertyValue('padding')", "10px" },
@@ -220,4 +239,9 @@ test "CSSOM.CSSStyleDeclaration" {
220239
.{ "style.setProperty('border-bottom-left-radius', '5px')", "undefined" },
221240
.{ "style.getPropertyValue('border-bottom-left-radius')", "5px" },
222241
}, .{});
242+
243+
try runner.testCases(&.{
244+
.{ "style.visibility", "visible" },
245+
.{ "style.getPropertyValue('visibility')", "visible" },
246+
}, .{});
223247
}

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

src/browser/html/elements.zig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ pub const HTMLElement = struct {
109109
pub const prototype = *Element;
110110
pub const subtype = .node;
111111

112-
style: CSSStyleDeclaration = .{
113-
.store = .{},
114-
.order = .{},
115-
},
112+
style: CSSStyleDeclaration = .empty,
116113

117114
pub fn get_style(e: *parser.ElementHTML, state: *SessionState) !*CSSStyleDeclaration {
118115
const self = try state.getOrCreateNodeWrapper(HTMLElement, @ptrCast(e));

src/browser/html/window.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const Console = @import("../console/console.zig").Console;
3131
const EventTarget = @import("../dom/event_target.zig").EventTarget;
3232
const MediaQueryList = @import("media_query_list.zig").MediaQueryList;
3333
const Performance = @import("performance.zig").Performance;
34+
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
3435

3536
const storage = @import("../storage/storage.zig");
3637

@@ -237,13 +238,13 @@ pub const Window = struct {
237238
return timer_id;
238239
}
239240

240-
// NOT IMPLEMENTED - This is a dummy implementation that always returns null to deter PlayWright from using this path to solve click.js.
241-
// returns an object containing the values of all CSS properties of an element, after applying active stylesheets and resolving any basic computation those values may contain.
242-
pub fn _getComputedStyle(_: *Window, element: *parser.Element, pseudo_element: ?[]const u8) !?void {
241+
// TODO: getComputedStyle should return a read-only CSSStyleDeclaration.
242+
// We currently don't have a read-only one, so we return a new instance on
243+
// each call.
244+
pub fn _getComputedStyle(_: *Window, element: *parser.Element, pseudo_element: ?[]const u8) !CSSStyleDeclaration {
243245
_ = element;
244246
_ = pseudo_element;
245-
log.warn("Not implemented function getComputedStyle called, null returned", .{});
246-
return null;
247+
return .empty;
247248
}
248249
};
249250

0 commit comments

Comments
 (0)