mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-11-23 01:49:32 +08:00
Keep body's height its own
html and body both took the document's extent, which now includes html's
declared height, so `html { height: 100% }` gave an empty body the
viewport's height. Chrome and Firefox give it 0. body now takes its
content or its own declared height, and html keeps the extent. A
document without a body yet also counts html's declared height.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<meta name=lp-mode content=test>
|
||||
<style>body { height: 100%; }</style>
|
||||
<body>
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=percent_of_auto_html>
|
||||
{
|
||||
// html's height is auto, so body's 100% has nothing to be a percentage of
|
||||
testing.expectEqual(0, document.body.offsetHeight);
|
||||
testing.expectEqual(0, document.body.getBoundingClientRect().height);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<meta name=lp-mode content=test>
|
||||
<style>html { height: 100%; }</style>
|
||||
<body>
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=body_keeps_its_own_height>
|
||||
{
|
||||
// From #4724's review: html's height isn't body's
|
||||
testing.expectEqual(innerHeight, document.documentElement.offsetHeight);
|
||||
testing.expectEqual(0, document.body.offsetHeight);
|
||||
testing.expectEqual(0, document.body.getBoundingClientRect().height);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
@@ -513,13 +513,12 @@ pub fn extent(self: *Document) Extent {
|
||||
const style_manager = &frame._style_manager;
|
||||
var size: Extent = .{ .width = 0, .height = 0 };
|
||||
|
||||
// Content heights only: html's and body's own heights are this extent.
|
||||
// html's own height is this extent
|
||||
const html_body = if (self.is(HTMLDocument) != null) self.getBody() else null;
|
||||
if (html_body) |b| {
|
||||
const body = b.asElement();
|
||||
// Only grows it: positions laid out past a shorter one must still fit
|
||||
const declared = @max(style_manager.rootHeight(body) orelse 0, if (self.getDocumentElement()) |html| style_manager.rootHeight(html) orelse 0 else 0);
|
||||
size.height = @max(layout.contentHeight(body, frame), declared);
|
||||
const html_declared = if (self.getDocumentElement()) |html| style_manager.rootHeight(html) orelse 0 else 0;
|
||||
size.height = @max(self.bodyHeight(body), html_declared);
|
||||
size.width = style_manager.inlineSize(body, .width) orelse 0;
|
||||
var children: TreeWalker.FlatChildren = .init(body.asNode(), .{ .frame = frame });
|
||||
while (children.next()) |node| {
|
||||
@@ -529,7 +528,7 @@ pub fn extent(self: *Document) Extent {
|
||||
}
|
||||
}
|
||||
} else if (self.getDocumentElement()) |root| {
|
||||
size.height = layout.contentHeight(root, frame);
|
||||
size.height = @max(layout.contentHeight(root, frame), style_manager.rootHeight(root) orelse 0);
|
||||
}
|
||||
|
||||
// Whole pixels, like scroll offsets
|
||||
@@ -541,6 +540,15 @@ pub fn extent(self: *Document) Extent {
|
||||
return size;
|
||||
}
|
||||
|
||||
/// The root body's height: its content, or its declared height when taller (a
|
||||
/// declared height only grows it, so positions laid out past it still fit).
|
||||
/// Not html's: `html { height: 100% }` leaves an empty body 0px tall.
|
||||
pub fn bodyHeight(self: *Document, body: *Element) f64 {
|
||||
const frame = self._frame orelse return 0;
|
||||
const declared = frame._style_manager.rootHeight(body) orelse 0;
|
||||
return @ceil(@max(layout.contentHeight(body, frame), declared));
|
||||
}
|
||||
|
||||
/// What the viewport scrolls over: the document, at least viewport-sized.
|
||||
pub fn scrollSize(self: *Document) Extent {
|
||||
const frame = self._frame orelse return .{ .width = 0, .height = 0 };
|
||||
|
||||
@@ -1675,11 +1675,12 @@ pub fn getElementAxis(self: *Element, frame: *Frame, comptime axis: Axis) Axis.S
|
||||
}
|
||||
}
|
||||
|
||||
// Root containers span the document, see Document.extent.
|
||||
// Root containers span the document, see Document.extent
|
||||
if (root) {
|
||||
const doc = self.asNode().ownerDocument(frame) orelse return .{ .value = 0.0 };
|
||||
return .{ .value = switch (axis) {
|
||||
.width => 1920.0,
|
||||
.height => if (self.asNode().ownerDocument(frame)) |doc| doc.extent().height else 0.0,
|
||||
.height => if (tag == .body) doc.bodyHeight(self) else doc.extent().height,
|
||||
} };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user