Trim comments

This commit is contained in:
Adrià Arrufat committed 2026-09-24 13:40:01 +02:00
1 parent 8fb49fe507
commit 9dfeef2aef
6 files changed
+17 -32

No files matched your search

+1 -2
View File
@@ -155,8 +155,7 @@ _focus_fixup_pending: bool = false,
_style_manager: StyleManager,
// Element.documentExtent, valid while the style version and viewport it was
// computed for hold.
// Element.documentExtent cache, keyed on style version and viewport.
_document_extent: ?struct {
version: usize,
viewport_width: u32,
+3 -6
View File
@@ -337,13 +337,10 @@
testing.expectEqual(0, panel.clientHeight);
testing.expectTrue(panel.scrollHeight > 0);
// The root containers span the document rather than summing children.
// The root element's clientHeight is the viewport (CSSOM View): jstracker
// tiles clientWidth/10 cells over clientHeight and calls elementFromPoint
// per cell, which a document-sized box turned into ~5M walks.
// The root element's clientHeight is the viewport (CSSOM View); jstracker
// tiles it with elementFromPoint calls.
testing.expectEqual(document.body.clientHeight, document.body.scrollHeight);
testing.expectEqual(window.innerHeight, document.documentElement.clientHeight);
// What the viewport scrolls over: the document, or the viewport itself
testing.expectEqual(
Math.max(document.documentElement.offsetHeight, document.documentElement.clientHeight),
document.documentElement.scrollHeight,
@@ -578,7 +575,7 @@
deep.id = 'deep';
document.body.appendChild(deep);
// Room below it, or the viewport couldn't bring its top up
// Room to scroll it to the top
const room = document.createElement('div');
room.style.height = '10000px';
document.body.appendChild(room);
+1 -1
View File
@@ -70,7 +70,7 @@
document.getElementById('rad').addEventListener('click', function() { window.radClicked = true; });
document.getElementById('rad').addEventListener('change', function() { window.radChanged = true; });
</script>
<!-- Room to scroll the window: the document can't scroll past its bottom -->
<!-- Room to scroll the window -->
<div style="height: 10000px; width: 10000px"></div>
</body>
</html>
+2 -3
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<script src="testing.js"></script>
<!-- Room to scroll: the document can't scroll past its bottom -->
<!-- Room to scroll -->
<div style="height: 10000px; width: 10000px"></div>
<script id=scrollBy_exists>
@@ -56,13 +56,12 @@
window.scrollBy(0, 100);
testing.expectEqual(max, window.scrollY);
// x clamps the same way, against the widest content
const maxX = document.documentElement.scrollWidth - window.innerWidth;
testing.expectTrue(maxX > 0);
window.scrollTo(99999999, 0);
testing.expectEqual(maxX, window.scrollX);
// Content added at the bottom extends the limit
// Added content extends the limit
const more = document.createElement('div');
more.style.height = '5000px';
document.body.appendChild(more);
+10 -19
View File
@@ -1686,8 +1686,7 @@ pub fn getScrollHeight(self: *Element, frame: *Frame) f64 {
const height = self.getElementAxis(frame, .height).value;
const tag = self.getTag();
// The root containers already span the document. The one scrolling the
// viewport reports what the viewport scrolls over.
// The root scroller reports what the viewport scrolls over.
if (tag == .html or tag == .body) {
return self.rootScrollSize(frame, .height) orelse height;
}
@@ -1703,10 +1702,8 @@ pub fn getScrollWidth(self: *Element, frame: *Frame) f64 {
const width = self.getElementAxis(frame, .width).value;
const tag = self.getTag();
// The root containers keep their box: their children don't lie side by
// side on one row, and stacking them would inflate a value sites read to
// detect page overflow. The one scrolling the viewport reports what the
// viewport scrolls over.
// Roots don't sum their children side by side. The root scroller
// reports what the viewport scrolls over.
if (tag == .html or tag == .body) {
return self.rootScrollSize(frame, .width) orelse width;
}
@@ -1716,9 +1713,7 @@ pub fn getScrollWidth(self: *Element, frame: *Frame) f64 {
/// Null where we can't prove a limit, which leaves the offset unbounded:
/// without an explicit size the client and content measurements collapse onto
/// the same sum. html and body scroll the viewport, which Window.scrollTo
/// clamps. Refusing a scroll we can't prove impossible is worse than allowing
/// one too many.
/// the same sum. html and body scroll the viewport, clamped by Window.
fn scrollExtent(self: *Element, frame: *Frame, comptime axis: Axis) ?f64 {
if (self.scrollsViewport() or !self.getElementAxis(frame, axis).explicit) {
return null;
@@ -1789,8 +1784,7 @@ fn contentAxis(self: *Element, frame: *Frame, comptime axis: Axis) f64 {
return total;
}
// Unlike clientHeight, the root's offsetHeight is its box: the document
// height.
// Unlike clientHeight, the root's offsetHeight is the document height.
pub fn getOffsetHeight(self: *Element, frame: *Frame) f64 {
if (!self.isVisible(frame)) {
return 0.0;
@@ -1923,11 +1917,9 @@ fn calculateDocumentPosition(node: *Node) f64 {
pub const DocumentExtent = struct { width: f64, height: f64 };
/// The document's extent. Its height, which html and body span, fits every
/// synthetic position (calculateDocumentPosition's 5px per node) and body's
/// children stacked on top of each other. Its width is body's widest child:
/// block children don't lie side by side on one row. An inline size on body
/// stretches both.
/// The document's size. Height: enough for every synthetic position (5px per
/// node) and body's stacked children. Width: body's widest child. An inline
/// size on body stretches both.
pub fn documentExtent(frame: *Frame) DocumentExtent {
const version = frame.page.style_version;
const viewport = frame.page.getViewport();
@@ -1952,7 +1944,7 @@ pub fn documentExtent(frame: *Frame) DocumentExtent {
}
}
// Whole pixels, like the scroll offsets clamped against it
// Whole pixels, like scroll offsets
extent = .{ .width = @ceil(extent.width), .height = @ceil(extent.height) };
frame._document_extent = .{
.version = version,
@@ -1963,8 +1955,7 @@ pub fn documentExtent(frame: *Frame) DocumentExtent {
return extent;
}
/// What the viewport scrolls over: the document, but never less than the
/// viewport itself, like the root scroller's scrollWidth and scrollHeight.
/// What the viewport scrolls over: the document, at least viewport-sized.
pub fn documentScrollSize(frame: *Frame) DocumentExtent {
const extent = documentExtent(frame);
const viewport = frame.page.getViewport();
-1
View File
@@ -951,7 +951,6 @@ fn getDevicePixelRatio(_: *const Window, frame: *Frame) f32 {
pub fn scrollTo(self: *Window, opts: Element.ScrollToOpts, y: ?i32, frame: *Frame) !void {
const o = opts.offsets(y);
// The viewport can't scroll past the document's edges
const size = Element.documentScrollSize(self._frame);
const max_x = scrollLimit(size.width, self.getInnerWidth(self._frame));
const max_y = scrollLimit(size.height, self.getInnerHeight(self._frame));