diff --git a/src/browser/renderer.zig b/src/browser/renderer.zig
index 5871b69e..8355e79f 100644
--- a/src/browser/renderer.zig
+++ b/src/browser/renderer.zig
@@ -41,6 +41,10 @@ const FlatRenderer = struct {
const Element = @import("dom/element.zig").Element;
+ // Define the size of each element in the grid.
+ const default_w = 5;
+ const default_h = 5;
+
// we expect allocator to be an arena
pub fn init(allocator: Allocator) FlatRenderer {
return .{
@@ -62,10 +66,10 @@ const FlatRenderer = struct {
gop.value_ptr.* = x;
}
- const _x: f64 = @floatFromInt(x);
+ const _x: f64 = @floatFromInt(x * default_w);
const y: f64 = 0.0;
- const w: f64 = 1.0;
- const h: f64 = 1.0;
+ const w: f64 = default_w;
+ const h: f64 = default_h;
return .{
.x = _x,
@@ -98,18 +102,20 @@ const FlatRenderer = struct {
}
pub fn width(self: *const FlatRenderer) u32 {
- return @max(@as(u32, @intCast(self.elements.items.len)), 1); // At least 1 pixel even if empty
+ return @max(@as(u32, @intCast(self.elements.items.len * default_w)), default_w); // At least default width pixels even if empty
}
pub fn height(_: *const FlatRenderer) u32 {
- return 1;
+ return 5;
}
- pub fn getElementAtPosition(self: *const FlatRenderer, x: i32, y: i32) ?*parser.Element {
- if (y != 0 or x < 0) {
+ pub fn getElementAtPosition(self: *const FlatRenderer, _x: i32, y: i32) ?*parser.Element {
+ if (y < 0 or y > default_h or _x < 0) {
return null;
}
+ const x = @divFloor(_x, default_w);
+
const elements = self.elements.items;
return if (x < elements.len) @ptrFromInt(elements[@intCast(x)]) else null;
}
diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig
index 0f0ff8f8..3bf894c8 100644
--- a/src/cdp/domains/dom.zig
+++ b/src/cdp/domains/dom.zig
@@ -663,11 +663,11 @@ test "cdp.dom: getBoxModel" {
.params = .{ .nodeId = 6 },
});
try ctx.expectSentResult(.{ .model = BoxModel{
- .content = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
- .padding = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
- .border = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
- .margin = Quad{ 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 },
- .width = 1,
- .height = 1,
+ .content = Quad{ 0.0, 0.0, 5.0, 0.0, 5.0, 5.0, 0.0, 5.0 },
+ .padding = Quad{ 0.0, 0.0, 5.0, 0.0, 5.0, 5.0, 0.0, 5.0 },
+ .border = Quad{ 0.0, 0.0, 5.0, 0.0, 5.0, 5.0, 0.0, 5.0 },
+ .margin = Quad{ 0.0, 0.0, 5.0, 0.0, 5.0, 5.0, 0.0, 5.0 },
+ .width = 5,
+ .height = 5,
} }, .{ .id = 5 });
}
diff --git a/src/tests/dom/element.html b/src/tests/dom/element.html
index d5794fa2..3255b7d2 100644
--- a/src/tests/dom/element.html
+++ b/src/tests/dom/element.html
@@ -168,35 +168,35 @@