Lightpanda: the headless browser designed for AI and automation
fix, render: CSS getPropertyValue special width/height handling
Karl Seguin38b008976dd0
diff --git a/src/browser/webapi/css/CSSStyleDeclaration.zig b/src/browser/webapi/css/CSSStyleDeclaration.zigindex c0f2f7f49..5a6c0b9d8 100644--- a/src/browser/webapi/css/CSSStyleDeclaration.zig+++ b/src/browser/webapi/css/CSSStyleDeclaration.zig@@ -99,7 +99,20 @@ pub fn getPropertyValue(self: *const CSSStyleDeclaration, property_name: []constif (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: []constreturn 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 "";