mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibWeb: Use available size in calculate_inner_height()
Although the parameter is named "available size," it is always supposed to represent the containing block size whenever it has a definite value. Therefore, it is possible to simply use this value instead of performing a containing block lookup. This change actually improves correctness for grid items whose containing block is defined by the grid area, as `Node::containing_block()` does not account for this.
This commit is contained in:
parent
e3499c7953
commit
6481ef821d
Notes:
github-actions[bot]
2024-09-15 16:01:00 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/6481ef821dd Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1407
|
@ -0,0 +1,11 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (1,1) content-size 798x220 [BFC] children: not-inline
|
||||
BlockContainer <body> at (10,10) content-size 780x202 children: not-inline
|
||||
Box <div.grid> at (11,11) content-size 200x200 positioned [GFC] children: not-inline
|
||||
BlockContainer <div.abspos-item> at (112,12) content-size 50x100 positioned [BFC] children: not-inline
|
||||
|
||||
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x222]
|
||||
PaintableWithLines (BlockContainer<BODY>) [9,9 782x204]
|
||||
PaintableBox (Box<DIV>.grid) [10,10 202x202]
|
||||
PaintableWithLines (BlockContainer<DIV>.abspos-item) [111,11 52x102]
|
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html><style>
|
||||
* {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: 100px 100px;
|
||||
grid-template-rows: 100px 100px;
|
||||
grid-template-areas: "a b"
|
||||
"a b";
|
||||
position: relative;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.abspos-item {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 50%;
|
||||
height: 50%;
|
||||
grid-area: b;
|
||||
}
|
||||
</style><div class="grid"><div class="abspos-item"></div></div>
|
|
@ -1639,19 +1639,10 @@ CSSPixels FormattingContext::calculate_inner_width(Layout::Box const& box, Avail
|
|||
return width.resolved(box, width_of_containing_block).to_px(box);
|
||||
}
|
||||
|
||||
CSSPixels FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const&, CSS::Size const& height) const
|
||||
CSSPixels FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const& available_height, CSS::Size const& height) const
|
||||
{
|
||||
VERIFY(!height.is_auto());
|
||||
|
||||
auto const* containing_block = box.non_anonymous_containing_block();
|
||||
auto const& containing_block_state = m_state.get(*containing_block);
|
||||
auto height_of_containing_block = containing_block_state.content_height();
|
||||
if (box.computed_values().position() == CSS::Positioning::Absolute) {
|
||||
// https://www.w3.org/TR/css-position-3/#def-cb
|
||||
// If the box has position: absolute, then the containing block is formed by the padding edge of the ancestor
|
||||
height_of_containing_block += containing_block_state.padding_top + containing_block_state.padding_bottom;
|
||||
}
|
||||
|
||||
auto height_of_containing_block = available_height.to_px_or_zero();
|
||||
auto& computed_values = box.computed_values();
|
||||
if (computed_values.box_sizing() == CSS::BoxSizing::BorderBox) {
|
||||
auto width_of_containing_block = containing_block_width_for(box);
|
||||
|
|
Loading…
Reference in a new issue