mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
add top, left, bottom, right to DOMRect
This commit is contained in:
@@ -43,6 +43,10 @@ pub const Element = struct {
|
|||||||
y: f64,
|
y: f64,
|
||||||
width: f64,
|
width: f64,
|
||||||
height: f64,
|
height: f64,
|
||||||
|
bottom: f64,
|
||||||
|
right: f64,
|
||||||
|
top: f64,
|
||||||
|
left: f64,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn toInterface(e: *parser.Element) !Union {
|
pub fn toInterface(e: *parser.Element) !Union {
|
||||||
@@ -369,7 +373,16 @@ pub const Element = struct {
|
|||||||
pub fn _getBoundingClientRect(self: *parser.Element, page: *Page) !DOMRect {
|
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.
|
// 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))) {
|
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);
|
return page.renderer.getRect(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,20 +62,38 @@ const FlatRenderer = struct {
|
|||||||
gop.value_ptr.* = x;
|
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 .{
|
return .{
|
||||||
.x = @floatFromInt(x),
|
.x = _x,
|
||||||
.y = 0.0,
|
.y = y,
|
||||||
.width = 1.0,
|
.width = w,
|
||||||
.height = 1.0,
|
.height = h,
|
||||||
|
.left = _x,
|
||||||
|
.top = y,
|
||||||
|
.right = _x + w,
|
||||||
|
.bottom = y + h,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn boundingRect(self: *const FlatRenderer) Element.DOMRect {
|
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 .{
|
return .{
|
||||||
.x = 0.0,
|
.x = x,
|
||||||
.y = 0.0,
|
.y = y,
|
||||||
.width = @floatFromInt(self.width()),
|
.width = w,
|
||||||
.height = @floatFromInt(self.height()),
|
.height = h,
|
||||||
|
.left = x,
|
||||||
|
.top = y,
|
||||||
|
.right = x + w,
|
||||||
|
.bottom = y + h,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user