Clear self.pending_whitespace.max_content in forced_line_break() (#33469)

If we encountered a preserved line break after some whitespace, we were
including the space in the max-content size of the following line.

So just like `line_break_opportunity()` was already clearing
`self.pending_whitespace.min_content`, `forced_line_break()` needs to
clear `self.pending_whitespace.max_content` too.

Also some cosmetic refactoring.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-09-16 12:57:56 +02:00 committed by GitHub
parent 10c64820e8
commit 5b6a9110c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 9 deletions

View file

@ -2354,7 +2354,6 @@ impl<'layout_data> ContentSizesComputation<'layout_data> {
// and start measuring from the inline origin once more.
if run.is_single_preserved_newline() {
self.forced_line_break();
self.current_line = ContentSizes::zero();
continue;
}
if !matches!(
@ -2430,18 +2429,19 @@ impl<'layout_data> ContentSizesComputation<'layout_data> {
// it needs to either hang or be removed. If that isn't the case,
// `commit_pending_whitespace()` should be called first.
self.pending_whitespace.min_content = Au::zero();
self.paragraph.min_content =
std::cmp::max(self.paragraph.min_content, self.current_line.min_content);
self.current_line.min_content = Au::zero();
let current_min_content = mem::take(&mut self.current_line.min_content);
self.paragraph.min_content.max_assign(current_min_content);
self.had_content_yet_for_min_content = false;
}
fn forced_line_break(&mut self) {
// Handle the line break for min-content sizes.
self.line_break_opportunity();
self.paragraph.max_content =
std::cmp::max(self.paragraph.max_content, self.current_line.max_content);
self.current_line.max_content = Au::zero();
self.had_content_yet_for_min_content = false;
// Repeat the same logic, but now for max-content sizes.
self.pending_whitespace.max_content = Au::zero();
let current_max_content = mem::take(&mut self.current_line.max_content);
self.paragraph.max_content.max_assign(current_max_content);
self.had_content_yet_for_max_content = false;
}

View file

@ -567209,7 +567209,7 @@
]
],
"white-space-intrinsic-size-021.html": [
"a209f72c30a5a48ed4c185f9d3962abeb68399fb",
"f9c246d4899b58dbcf2dc08655c8bc1f39995e5a",
[
null,
{}

View file

@ -26,6 +26,10 @@
hr {
clear: both;
}
x-br::before {
content: "\a";
white-space: preserve-breaks;
}
.collapse.wrap {
white-space: normal;
}
@ -152,6 +156,16 @@ hr {
<div class="break-spaces wrap" data-expected-client-width="20" data-expected-client-height="20">X É</div>
<div class="break-spaces nowrap" data-expected-client-width="40" data-expected-client-height="10">X É</div>
</div>
<div class="container narrow">
<div class="collapse wrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="collapse nowrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve wrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve nowrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve-breaks wrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve-breaks nowrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="break-spaces wrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="break-spaces nowrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
</div>
<hr>
@ -255,6 +269,16 @@ hr {
<div class="break-spaces wrap" data-expected-client-width="40" data-expected-client-height="10">X É</div>
<div class="break-spaces nowrap" data-expected-client-width="40" data-expected-client-height="10">X É</div>
</div>
<div class="container wide">
<div class="collapse wrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="collapse nowrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve wrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve nowrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve-breaks wrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="preserve-breaks nowrap" data-expected-client-width="10" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="break-spaces wrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
<div class="break-spaces nowrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
</div>
<hr>