From 833b4d10bd0fbc6c46d3b056bb87bbd9fe7413c6 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Wed, 18 Jun 2025 08:21:33 -0700 Subject: [PATCH] add top, left, bottom, right to DOMRect --- src/browser/dom/element.zig | 15 ++++++++++++++- src/browser/renderer.zig | 34 ++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/browser/dom/element.zig b/src/browser/dom/element.zig index d63e5d2c..45cce475 100644 --- a/src/browser/dom/element.zig +++ b/src/browser/dom/element.zig @@ -43,6 +43,10 @@ pub const Element = struct { y: f64, width: f64, height: f64, + bottom: f64, + right: f64, + top: f64, + left: f64, }; pub fn toInterface(e: *parser.Element) !Union { @@ -369,7 +373,16 @@ pub const Element = struct { pub fn _getBoundingClientRect(self: *parser.Element, page: *Page) !DOMRect { // Since we are lazy rendering we need to do this check. We could store the renderer in a viewport such that it could cache these, but it would require tracking changes. if (!try page.isNodeAttached(parser.elementToNode(self))) { - return DOMRect{ .x = 0, .y = 0, .width = 0, .height = 0 }; + return DOMRect{ + .x = 0, + .y = 0, + .width = 0, + .height = 0, + .bottom = 0, + .right = 0, + .top = 0, + .left = 0, + }; } return page.renderer.getRect(self); } diff --git a/src/browser/renderer.zig b/src/browser/renderer.zig index f9c8ca42..5871b69e 100644 --- a/src/browser/renderer.zig +++ b/src/browser/renderer.zig @@ -62,20 +62,38 @@ const FlatRenderer = struct { gop.value_ptr.* = x; } + const _x: f64 = @floatFromInt(x); + const y: f64 = 0.0; + const w: f64 = 1.0; + const h: f64 = 1.0; + return .{ - .x = @floatFromInt(x), - .y = 0.0, - .width = 1.0, - .height = 1.0, + .x = _x, + .y = y, + .width = w, + .height = h, + .left = _x, + .top = y, + .right = _x + w, + .bottom = y + h, }; } pub fn boundingRect(self: *const FlatRenderer) Element.DOMRect { + const x: f64 = 0.0; + const y: f64 = 0.0; + const w: f64 = @floatFromInt(self.width()); + const h: f64 = @floatFromInt(self.width()); + return .{ - .x = 0.0, - .y = 0.0, - .width = @floatFromInt(self.width()), - .height = @floatFromInt(self.height()), + .x = x, + .y = y, + .width = w, + .height = h, + .left = x, + .top = y, + .right = x + w, + .bottom = y + h, }; }