Truly independent web browser
LibWeb: Size orthogonal flows within the nearest scrollport
Andreas Klinge031ff485317
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 8ec299c9ac3..772e82606d4 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -3499,17 +3499,47 @@ impl<'pass> SizingContext<'pass> {// - the nearest ancestor scrollport’s inner size if that is fixed, else / capped by its inner max size if// that is fixed, floored by its inner min size if that is fixed// - the initial containing block’s size- // FIXME: Consider the nearest ancestor scrollport.+ let fixed_size = |size: &ComputedSize| {+ (size.is_length_percentage() && !size.contains_percentage()).then(|| size.to_px(CssPixels::default()))+ };+ let containing_block = self.callbacks.in_flow_containing_block(node);+ let mut scrollport_size = None;+ let mut ancestor = containing_block;+ while !ancestor.is_invalid() {+ if self.facts(ancestor).is_scroll_container() {+ let style = self.style(ancestor);+ let inner = |size: CssPixels| {+ if style.box_sizing() == box_sizing::BORDER_BOX {+ (size+ - style.border_left_width()+ - style.border_right_width()+ - style.padding_left().to_px(CssPixels::default())+ - style.padding_right().to_px(CssPixels::default()))+ .max(CssPixels::default())+ } else {+ size+ }+ };+ let maximum = fixed_size(style.max_width()).map(inner);+ let minimum = fixed_size(style.min_width()).map(inner);+ scrollport_size = fixed_size(style.width())+ .map(inner)+ .map(|size| maximum.map_or(size, |maximum| size.min(maximum)))+ .or(maximum)+ .map(|size| minimum.map_or(size, |minimum| size.max(minimum)));+ break;+ }+ ancestor = self.callbacks.parent(ancestor);+ }+ let scrollport_and_initial_containing_block_size = scrollport_size+ .map_or(initial_containing_block_size, |size| {+ size.min(initial_containing_block_size)+ });// NB: An intrinsic size measurement of the box has no available space, but its containing block's size, which// the available space is when it is definite, still arrives as the percentage basis.let available_inline_size = match (available_space.inline_size, constraints.percentage_basis_inline_size) {(AvailableSize::Definite(size), _) | (_, Some(size)) => size,_ => {- let containing_block = self.callbacks.in_flow_containing_block(node);- let fixed_size = |size: &ComputedSize| {- (size.is_length_percentage() && !size.contains_percentage())- .then(|| size.to_px(CssPixels::default()))- };let containing_block_max_size = (!containing_block.is_invalid()).then(|| {let style = self.style(containing_block);@@ -3518,8 +3548,8 @@ impl<'pass> SizingContext<'pass> {})}).flatten();- containing_block_max_size.map_or(initial_containing_block_size, |maximum| {- maximum.min(initial_containing_block_size)+ containing_block_max_size.map_or(scrollport_and_initial_containing_block_size, |maximum| {+ maximum.min(scrollport_and_initial_containing_block_size)})}};@@ -3542,7 +3572,7 @@ impl<'pass> SizingContext<'pass> {// FIXME: Lay out the box in columns of that width where its content overflows its block size.let constraint = self.calculate_stretch_fit_inline_size(node,- AvailableSize::definite(available_inline_size.min(initial_containing_block_size)),+ AvailableSize::definite(available_inline_size.min(scrollport_and_initial_containing_block_size)),);let max_content = self.calculate_max_content_inline_size(node, constraints);if max_content <= constraint {diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-003.htmlnew file mode 100644index 00000000000..513c1f3a51b--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-003.html@@ -0,0 +1,46 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Testing Available Space in Orthogonal Flows / height / content height</title>+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">+<link rel="help" href="https://www.w3.org/TR/css-writing-modes-3/#orthogonal-auto">+<link rel="match" href="../../../../expected/wpt-import/css/css-writing-modes/reference/available-size-001-ref.html">+<meta name="assert" content="When an orthogonal flow's parent doesn't have a definite block size and the nearest ancestor scroller does have a fixed height, use that, making sure you stick with the content height.">+<style>+#scroller {+ font-family: monospace; /* to be able to reliably measure things in ch*/+ font-size: 20px;+ height: 8ch;+ width: 300px; /* Shrinkwrapping this div is not what we're interested in testing here, so give it a width. See nested-orthogonal-001.html for that. */+ overflow: hidden;+ color: transparent;+ position: relative; /* to act as a container of #red */+ padding: 1ch 0;+}++#parent { padding-bottom: 2ch; } /* so that the content height of the parent and of the fixed size scrolling ancestor are different */+#ortho { writing-mode: vertical-rl; }++span {+ background: green;+ display: inline-block; /* This should not change it's size or position, but makes the size of the background predictable*/+}++#red { /* Not necessary when when comparing to the reference, but makes human judgement easier */+ position: absolute;+ background: red;+ left: 0; top: 1ch;+ writing-mode: vertical-rl;+ z-index: -1;+}+</style>++<p>Test passes if there is a <strong>green rectangle</strong> below and <strong>no red</strong>.++<div id=scroller>+ <aside id=red>0</aside>+ <div id=parent>+ <div id=ortho>0 0 0 0 <span>0</span> 0 0 0</div>+ <!-- If this div take its height from the height of its scrollable ancestor,+ it should wrap just right for the green 0 to overlap with the red one. -->+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-005.htmlnew file mode 100644index 00000000000..e85c43af800--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-005.html@@ -0,0 +1,54 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Testing Available Space in Orthogonal Flows / height / not remaining size</title>+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">+<link rel="help" href="https://www.w3.org/TR/css-writing-modes-3/#orthogonal-auto">+<link rel="match" href="../../../../expected/wpt-import/css/css-writing-modes/reference/available-size-001-ref.html">+<meta name="assert" content="When an orthogonal flow's parent doesn't have a definite block size and the nearest ancestor scroller does a have fixed height, use that whole height, even if some other content already consumes some of it.">+<style>+#scroller {+ font-family: monospace; /* to be able to reliably measure things in ch*/+ font-size: 20px;+ height: 8ch;+ width: 300px; /* Shrinkwrapping this div is not what we're interested in testing here, so give it a width. See nested-orthogonal-001.html for that. */+ overflow: hidden;+ color: transparent;+ position: relative; /* to act as a container of #red */+}++#parent { padding-bottom: 2ch; } /* so that the content height of the parent and of the fixed size scrolling ancestor are different */+#ortho { writing-mode: vertical-rl; }++span {+ background: green;+ display: inline-block; /* This should not change it's size or position, but makes the size of the background predictable*/+}++#red { /* Not necessary when when comparing to the reference, but makes human judgement easier */+ position: absolute;+ background: red;+ left: 0;+ writing-mode: vertical-rl;+ z-index: -1;+ top: 1ch;+}+#spacer { /* shrinks the remaining space of the parent div. */+ height: 1ch;+ width: 100%;+}+</style>++<p>Test passes if there is a <strong>green rectangle</strong> below and <strong>no red</strong>.++<div id=scroller>+ <aside id="red">0</aside>+ <div id=parent>+ <aside id=spacer></aside>+ <div id=ortho>0 0 0 0 <span>0</span> 0 0 0</div>+ </div>+ <!-- If the inner div take its height from the height of its scrollable+ ancestor, it should wrap just right for the green 0 to overlap with the red+ one. If instead it takes it size from the remaining height after having+ removed #spacer, or does some other calculation that takes #spacer into+ account, it won't line up with #red.-->+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-013.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-013.htmlnew file mode 100644index 00000000000..296b3eff5c3--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-013.html@@ -0,0 +1,47 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Testing Available Space in Orthogonal Flows / height + min-height/ content height</title>+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">+<link rel="help" href="https://www.w3.org/TR/css-writing-modes-3/#orthogonal-auto">+<link rel="match" href="../../../../expected/wpt-import/css/css-writing-modes/reference/available-size-001-ref.html">+<meta name="assert" content="When an orthogonal flow's parent doesn't have a definite block size and the nearest ancestor scroller does have a fixed height, use that, increased by the min-height if it is set and is larger (same as -003, with min-height).">+<style>+#scroller {+ font-family: monospace; /* to be able to reliably measure things in ch*/+ font-size: 20px;+ height: 4ch;+ min-height: 8ch;+ width: 300px; /* Shrinkwrapping this div is not what we're interested in testing here, so give it a width. See nested-orthogonal-001.html for that. */+ overflow: hidden;+ color: transparent;+ position: relative; /* to act as a container of #red */+ padding: 1ch 0;+}++#parent { padding-bottom: 2ch; } /* so that the content height of the parent and of the fixed size scrolling ancestor are different */+#ortho { writing-mode: vertical-rl; }++span {+ background: green;+ display: inline-block; /* This should not change it's size or position, but makes the size of the background predictable*/+}++#red { /* Not necessary when when comparing to the reference, but makes human judgement easier */+ position: absolute;+ background: red;+ left: 0; top: 1ch;+ writing-mode: vertical-rl;+ z-index: -1;+}+</style>++<p>Test passes if there is a <strong>green rectangle</strong> below and <strong>no red</strong>.++<div id=scroller>+ <aside id=red>0</aside>+ <div id=parent>+ <div id=ortho>0 0 0 0 <span>0</span> 0 0 0</div>+ <!-- If this div take its height from the height of its scrollable ancestor,+ it should wrap just right for the green 0 to overlap with the red one. -->+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-014.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-014.htmlnew file mode 100644index 00000000000..031b1265474--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-writing-modes/available-size-014.html@@ -0,0 +1,55 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Testing Available Space in Orthogonal Flows / height + min-height / not remaining size</title>+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">+<link rel="help" href="https://www.w3.org/TR/css-writing-modes-3/#orthogonal-auto">+<link rel="match" href="../../../../expected/wpt-import/css/css-writing-modes/reference/available-size-001-ref.html">+<meta name="assert" content="When an orthogonal flow's parent doesn't have a definite block size and the nearest ancestor scroller does a have fixed height, use that whole height increased by min-height if that's larger, even if some other content already consumes some of it (same as -005, with min-height).">+<style>+#scroller {+ font-family: monospace; /* to be able to reliably measure things in ch*/+ font-size: 20px;+ height: 4ch;+ min-height: 8ch;+ width: 300px; /* Shrinkwrapping this div is not what we're interested in testing here, so give it a width. See nested-orthogonal-001.html for that. */+ overflow: hidden;+ color: transparent;+ position: relative; /* to act as a container of #red */+}++#parent { padding-bottom: 2ch; } /* so that the content height of the parent and of the fixed size scrolling ancestor are different */+#ortho { writing-mode: vertical-rl; }++span {+ background: green;+ display: inline-block; /* This should not change it's size or position, but makes the size of the background predictable*/+}++#red { /* Not necessary when when comparing to the reference, but makes human judgement easier */+ position: absolute;+ background: red;+ left: 0;+ writing-mode: vertical-rl;+ z-index: -1;+ top: 1ch;+}+#spacer { /* shrinks the remaining space of the parent div. */+ height: 1ch;+ width: 100%;+}+</style>++<p>Test passes if there is a <strong>green rectangle</strong> below and <strong>no red</strong>.++<div id=scroller>+ <aside id="red">0</aside>+ <div id=parent>+ <aside id=spacer></aside>+ <div id=ortho>0 0 0 0 <span>0</span> 0 0 0</div>+ </div>+ <!-- If the inner div take its height from the height of its scrollable+ ancestor, it should wrap just right for the green 0 to overlap with the red+ one. If instead it takes it size from the remaining height after having+ removed #spacer, or does some other calculation that takes #spacer into+ account, it won't line up with #red.-->+</div>