Skip to content

Commit bd65e40

Browse files
committed
renderer fix & url buffer
1 parent a2a9977 commit bd65e40

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
@@ -193,7 +193,7 @@ pub const Session = struct {
193193
// can't use the page arena, because we're about to reset it
194194
// and don't want to use the session's arena, because that'll start to
195195
// look like a leak if we navigate from page to page a lot.
196-
var buf: [1024]u8 = undefined;
196+
var buf: [4096]u8 = undefined;
197197
var fba = std.heap.FixedBufferAllocator.init(&buf);
198198
const url = try self.page.?.url.resolve(fba.allocator(), url_string);
199199

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

@@ -841,15 +841,15 @@ const FlatRenderer = struct {
841841
}
842842

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

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

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

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)