Skip to content

Commit ac759a6

Browse files
Merge pull request #793 from lightpanda-io/domrect-bottom
add top, left, bottom, right to DOMRect
2 parents 1839b34 + 833b4d1 commit ac759a6

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/browser/dom/element.zig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub const Element = struct {
4343
y: f64,
4444
width: f64,
4545
height: f64,
46+
bottom: f64,
47+
right: f64,
48+
top: f64,
49+
left: f64,
4650
};
4751

4852
pub fn toInterface(e: *parser.Element) !Union {
@@ -369,7 +373,16 @@ pub const Element = struct {
369373
pub fn _getBoundingClientRect(self: *parser.Element, page: *Page) !DOMRect {
370374
// 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.
371375
if (!try page.isNodeAttached(parser.elementToNode(self))) {
372-
return DOMRect{ .x = 0, .y = 0, .width = 0, .height = 0 };
376+
return DOMRect{
377+
.x = 0,
378+
.y = 0,
379+
.width = 0,
380+
.height = 0,
381+
.bottom = 0,
382+
.right = 0,
383+
.top = 0,
384+
.left = 0,
385+
};
373386
}
374387
return page.renderer.getRect(self);
375388
}

src/browser/renderer.zig

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,38 @@ const FlatRenderer = struct {
6262
gop.value_ptr.* = x;
6363
}
6464

65+
const _x: f64 = @floatFromInt(x);
66+
const y: f64 = 0.0;
67+
const w: f64 = 1.0;
68+
const h: f64 = 1.0;
69+
6570
return .{
66-
.x = @floatFromInt(x),
67-
.y = 0.0,
68-
.width = 1.0,
69-
.height = 1.0,
71+
.x = _x,
72+
.y = y,
73+
.width = w,
74+
.height = h,
75+
.left = _x,
76+
.top = y,
77+
.right = _x + w,
78+
.bottom = y + h,
7079
};
7180
}
7281

7382
pub fn boundingRect(self: *const FlatRenderer) Element.DOMRect {
83+
const x: f64 = 0.0;
84+
const y: f64 = 0.0;
85+
const w: f64 = @floatFromInt(self.width());
86+
const h: f64 = @floatFromInt(self.width());
87+
7488
return .{
75-
.x = 0.0,
76-
.y = 0.0,
77-
.width = @floatFromInt(self.width()),
78-
.height = @floatFromInt(self.height()),
89+
.x = x,
90+
.y = y,
91+
.width = w,
92+
.height = h,
93+
.left = x,
94+
.top = y,
95+
.right = x + w,
96+
.bottom = y + h,
7997
};
8098
}
8199

0 commit comments

Comments
 (0)