mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
Merge pull request #692 from lightpanda-io/get_computed_style
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
make getComptedStyle return an empty CSSStyleDeclaration
This commit is contained in:
@@ -33,6 +33,11 @@ pub const CSSStyleDeclaration = struct {
|
|||||||
store: std.StringHashMapUnmanaged(Property),
|
store: std.StringHashMapUnmanaged(Property),
|
||||||
order: std.ArrayListUnmanaged([]const u8),
|
order: std.ArrayListUnmanaged([]const u8),
|
||||||
|
|
||||||
|
pub const empty: CSSStyleDeclaration = .{
|
||||||
|
.store = .empty,
|
||||||
|
.order = .empty,
|
||||||
|
};
|
||||||
|
|
||||||
const Property = struct {
|
const Property = struct {
|
||||||
value: []const u8,
|
value: []const u8,
|
||||||
priority: bool,
|
priority: bool,
|
||||||
@@ -90,7 +95,16 @@ pub const CSSStyleDeclaration = struct {
|
|||||||
|
|
||||||
// TODO should handle properly shorthand properties and canonical forms
|
// TODO should handle properly shorthand properties and canonical forms
|
||||||
pub fn _getPropertyValue(self: *const CSSStyleDeclaration, name: []const u8) []const u8 {
|
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 {
|
pub fn _item(self: *const CSSStyleDeclaration, index: usize) []const u8 {
|
||||||
@@ -122,6 +136,10 @@ pub const CSSStyleDeclaration = struct {
|
|||||||
|
|
||||||
gop.value_ptr.* = .{ .value = owned_value, .priority = is_important };
|
gop.value_ptr.* = .{ .value = owned_value, .priority = is_important };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn named_get(self: *const CSSStyleDeclaration, name: []const u8, _: *bool) []const u8 {
|
||||||
|
return self._getPropertyValue(name);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const testing = @import("../../testing.zig");
|
const testing = @import("../../testing.zig");
|
||||||
@@ -159,6 +177,7 @@ test "CSSOM.CSSStyleDeclaration" {
|
|||||||
.{ "style.setProperty('color', 'green')", "undefined" },
|
.{ "style.setProperty('color', 'green')", "undefined" },
|
||||||
.{ "style.getPropertyValue('color')", "green" },
|
.{ "style.getPropertyValue('color')", "green" },
|
||||||
.{ "style.length", "4" },
|
.{ "style.length", "4" },
|
||||||
|
.{ "style.color", "green"},
|
||||||
|
|
||||||
.{ "style.setProperty('padding', '10px', 'important')", "undefined" },
|
.{ "style.setProperty('padding', '10px', 'important')", "undefined" },
|
||||||
.{ "style.getPropertyValue('padding')", "10px" },
|
.{ "style.getPropertyValue('padding')", "10px" },
|
||||||
@@ -220,4 +239,9 @@ test "CSSOM.CSSStyleDeclaration" {
|
|||||||
.{ "style.setProperty('border-bottom-left-radius', '5px')", "undefined" },
|
.{ "style.setProperty('border-bottom-left-radius', '5px')", "undefined" },
|
||||||
.{ "style.getPropertyValue('border-bottom-left-radius')", "5px" },
|
.{ "style.getPropertyValue('border-bottom-left-radius')", "5px" },
|
||||||
}, .{});
|
}, .{});
|
||||||
|
|
||||||
|
try runner.testCases(&.{
|
||||||
|
.{ "style.visibility", "visible" },
|
||||||
|
.{ "style.getPropertyValue('visibility')", "visible" },
|
||||||
|
}, .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -407,6 +407,18 @@ pub const Element = struct {
|
|||||||
pub fn _scrollIntoViewIfNeeded(_: *parser.Element, center_if_needed: ?bool) void {
|
pub fn _scrollIntoViewIfNeeded(_: *parser.Element, center_if_needed: ?bool) void {
|
||||||
_ = center_if_needed;
|
_ = 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
|
// Tests
|
||||||
|
|||||||
@@ -109,10 +109,7 @@ pub const HTMLElement = struct {
|
|||||||
pub const prototype = *Element;
|
pub const prototype = *Element;
|
||||||
pub const subtype = .node;
|
pub const subtype = .node;
|
||||||
|
|
||||||
style: CSSStyleDeclaration = .{
|
style: CSSStyleDeclaration = .empty,
|
||||||
.store = .{},
|
|
||||||
.order = .{},
|
|
||||||
},
|
|
||||||
|
|
||||||
pub fn get_style(e: *parser.ElementHTML, state: *SessionState) !*CSSStyleDeclaration {
|
pub fn get_style(e: *parser.ElementHTML, state: *SessionState) !*CSSStyleDeclaration {
|
||||||
const self = try state.getOrCreateNodeWrapper(HTMLElement, @ptrCast(e));
|
const self = try state.getOrCreateNodeWrapper(HTMLElement, @ptrCast(e));
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const Console = @import("../console/console.zig").Console;
|
|||||||
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
||||||
const MediaQueryList = @import("media_query_list.zig").MediaQueryList;
|
const MediaQueryList = @import("media_query_list.zig").MediaQueryList;
|
||||||
const Performance = @import("performance.zig").Performance;
|
const Performance = @import("performance.zig").Performance;
|
||||||
|
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
|
||||||
|
|
||||||
const storage = @import("../storage/storage.zig");
|
const storage = @import("../storage/storage.zig");
|
||||||
|
|
||||||
@@ -237,13 +238,13 @@ pub const Window = struct {
|
|||||||
return timer_id;
|
return timer_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOT IMPLEMENTED - This is a dummy implementation that always returns null to deter PlayWright from using this path to solve click.js.
|
// TODO: getComputedStyle should return a read-only CSSStyleDeclaration.
|
||||||
// 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.
|
// We currently don't have a read-only one, so we return a new instance on
|
||||||
pub fn _getComputedStyle(_: *Window, element: *parser.Element, pseudo_element: ?[]const u8) !?void {
|
// each call.
|
||||||
|
pub fn _getComputedStyle(_: *Window, element: *parser.Element, pseudo_element: ?[]const u8) !CSSStyleDeclaration {
|
||||||
_ = element;
|
_ = element;
|
||||||
_ = pseudo_element;
|
_ = pseudo_element;
|
||||||
log.warn("Not implemented function getComputedStyle called, null returned", .{});
|
return .empty;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user