mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-08-01 02:06:17 -04:00
Merge pull request #2892 from lightpanda-io/getComputedStyle-width-height
fix, render: CSS getPropertyValue special width/height handling
This commit is contained in:
@@ -99,7 +99,20 @@ pub fn getPropertyValue(self: *const CSSStyleDeclaration, property_name: []const
|
||||
if (self._element) |element| {
|
||||
// Resolve inline `style=` declarations through the element's
|
||||
// parsed inline style, so computed values match `el.style`.
|
||||
if (frame._style_manager.inlineStyleValue(element, wrapped)) |value| return value;
|
||||
if (frame._style_manager.inlineStyleValue(element, wrapped)) |value| {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Computed width/height must agree with the synthetic layout
|
||||
// metrics (offsetWidth/getBoundingClientRect). Returning ""
|
||||
// makes measurement code see contradictory sizes — jQuery's
|
||||
// "shrink text until it fits" loops then never terminate.
|
||||
if (wrapped.eql(comptime .wrap("width"))) {
|
||||
return resolvedDimension(element, .width, frame);
|
||||
}
|
||||
if (wrapped.eql(comptime .wrap("height"))) {
|
||||
return resolvedDimension(element, .height, frame);
|
||||
}
|
||||
}
|
||||
return getDefaultPropertyValue(self, wrapped);
|
||||
}
|
||||
@@ -108,6 +121,18 @@ pub fn getPropertyValue(self: *const CSSStyleDeclaration, property_name: []const
|
||||
return prop._value.str();
|
||||
}
|
||||
|
||||
fn resolvedDimension(element: *Element, dimension: enum { width, height }, frame: *Frame) []const u8 {
|
||||
if (!element.checkVisibilityCached(null, frame)) {
|
||||
return "auto";
|
||||
}
|
||||
const dims = element.getElementDimensions(frame);
|
||||
const value = switch (dimension) {
|
||||
.width => dims.width,
|
||||
.height => dims.height,
|
||||
};
|
||||
return std.fmt.allocPrint(frame.local_arena, "{d}px", .{value}) catch "auto";
|
||||
}
|
||||
|
||||
pub fn getPropertyPriority(self: *const CSSStyleDeclaration, property_name: []const u8, frame: *Frame) []const u8 {
|
||||
const normalized = normalizePropertyName(property_name, &frame.buf);
|
||||
const prop = self.findProperty(.wrap(normalized)) orelse return "";
|
||||
|
||||
Reference in New Issue
Block a user