Skip to content

Commit d91327d

Browse files
committed
renderer fix & url buffer
1 parent 28e4065 commit d91327d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/browser/browser.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub const Session = struct {
192192
// can't use the page arena, because we're about to reset it
193193
// and don't want to use the session's arena, because that'll start to
194194
// look like a leak if we navigate from page to page a lot.
195-
var buf: [1024]u8 = undefined;
195+
var buf: [4096]u8 = undefined;
196196
var fba = std.heap.FixedBufferAllocator.init(&buf);
197197
const url = try self.page.?.url.resolve(fba.allocator(), url_string);
198198

@@ -817,8 +817,8 @@ const FlatRenderer = struct {
817817
const gop = try self.positions.getOrPut(self.allocator, @intFromPtr(e));
818818
var x: u32 = gop.value_ptr.*;
819819
if (gop.found_existing == false) {
820-
try elements.append(self.allocator, @intFromPtr(e));
821820
x = @intCast(elements.items.len);
821+
try elements.append(self.allocator, @intFromPtr(e));
822822
gop.value_ptr.* = x;
823823
}
824824

@@ -840,15 +840,15 @@ const FlatRenderer = struct {
840840
}
841841

842842
pub fn width(self: *const FlatRenderer) u32 {
843-
return @intCast(self.elements.items.len + 1); // +1 since x starts at 1 (use len after append)
843+
return @max(@as(u32, @intCast(self.elements.items.len)), 1); // At least 1 pixel even if empty
844844
}
845845

846846
pub fn height(_: *const FlatRenderer) u32 {
847847
return 1;
848848
}
849849

850850
pub fn getElementAtPosition(self: *const FlatRenderer, x: i32, y: i32) ?*parser.Element {
851-
if (y != 1 or x < 0) {
851+
if (y != 0 or x < 0) {
852852
return null;
853853
}
854854

src/browser/dom/element.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,24 +500,24 @@ test "Browser.DOM.Element" {
500500
.{ "document.getElementById('para').clientHeight", "1" },
501501

502502
.{ "let r1 = document.getElementById('para').getBoundingClientRect()", "undefined" },
503-
.{ "r1.x", "1" },
503+
.{ "r1.x", "0" },
504504
.{ "r1.y", "0" },
505505
.{ "r1.width", "1" },
506506
.{ "r1.height", "1" },
507507

508508
.{ "let r2 = document.getElementById('content').getBoundingClientRect()", "undefined" },
509-
.{ "r2.x", "2" },
509+
.{ "r2.x", "1" },
510510
.{ "r2.y", "0" },
511511
.{ "r2.width", "1" },
512512
.{ "r2.height", "1" },
513513

514514
.{ "let r3 = document.getElementById('para').getBoundingClientRect()", "undefined" },
515-
.{ "r3.x", "1" },
515+
.{ "r3.x", "0" },
516516
.{ "r3.y", "0" },
517517
.{ "r3.width", "1" },
518518
.{ "r3.height", "1" },
519519

520-
.{ "document.getElementById('para').clientWidth", "3" },
520+
.{ "document.getElementById('para').clientWidth", "2" },
521521
.{ "document.getElementById('para').clientHeight", "1" },
522522
}, .{});
523523

src/browser/dom/intersection_observer.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,16 @@ test "Browser.DOM.IntersectionObserver" {
247247
try runner.testCases(&.{
248248
.{ "let entry;", "undefined" },
249249
.{ "new IntersectionObserver(entries => { entry = entries[0]; }).observe(document.createElement('div'));", "undefined" },
250-
.{ "entry.boundingClientRect.x;", "1" },
250+
.{ "entry.boundingClientRect.x;", "0" },
251251
.{ "entry.intersectionRatio;", "1" },
252-
.{ "entry.intersectionRect.x;", "1" },
252+
.{ "entry.intersectionRect.x;", "0" },
253253
.{ "entry.intersectionRect.y;", "0" },
254254
.{ "entry.intersectionRect.width;", "1" },
255255
.{ "entry.intersectionRect.height;", "1" },
256256
.{ "entry.isIntersecting;", "true" },
257257
.{ "entry.rootBounds.x;", "0" },
258258
.{ "entry.rootBounds.y;", "0" },
259-
.{ "entry.rootBounds.width;", "2" },
259+
.{ "entry.rootBounds.width;", "1" },
260260
.{ "entry.rootBounds.height;", "1" },
261261
.{ "entry.target;", "[object HTMLDivElement]" },
262262
}, .{});
@@ -273,6 +273,6 @@ test "Browser.DOM.IntersectionObserver" {
273273
"undefined",
274274
},
275275
.{ "new_observer.observe(document.createElement('div'));", "undefined" },
276-
.{ "new_entry.rootBounds.x;", "2" },
276+
.{ "new_entry.rootBounds.x;", "1" },
277277
}, .{});
278278
}

0 commit comments

Comments
 (0)