Avoid wrapping line at the start of text run with text-wrap-mode: nowrap (#33848)

When computing the min-content size of an inline formatting context,
we could allow a soft wrap opportunity at the start of a text run.
This shouldn't happen with `text-wrap-mode: nowrap`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-10-16 12:22:11 +02:00 committed by GitHub
parent 0a71c736f0
commit 103d3aa7bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 5 deletions

View file

@ -2245,17 +2245,17 @@ impl<'layout_data> ContentSizesComputation<'layout_data> {
}, },
InlineItem::TextRun(text_run) => { InlineItem::TextRun(text_run) => {
for segment in text_run.shaped_text.iter() { for segment in text_run.shaped_text.iter() {
let style_text = text_run.parent_style.get_inherited_text();
let can_wrap = style_text.text_wrap_mode == TextWrapMode::Wrap;
// TODO: This should take account whether or not the first and last character prevent // TODO: This should take account whether or not the first and last character prevent
// linebreaks after atomics as in layout. // linebreaks after atomics as in layout.
if segment.break_at_start { if can_wrap && segment.break_at_start {
self.line_break_opportunity() self.line_break_opportunity()
} }
for run in segment.runs.iter() { for run in segment.runs.iter() {
let advance = run.glyph_store.total_advance(); let advance = run.glyph_store.total_advance();
let style_text = text_run.parent_style.get_inherited_text();
let can_wrap = style_text.text_wrap_mode == TextWrapMode::Wrap;
if run.glyph_store.is_whitespace() { if run.glyph_store.is_whitespace() {
// If this run is a forced line break, we *must* break the line // If this run is a forced line break, we *must* break the line
// and start measuring from the inline origin once more. // and start measuring from the inline origin once more.

View file

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

View file

@ -166,6 +166,16 @@ x-br::before {
<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 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 class="break-spaces nowrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
</div> </div>
<div class="container narrow">
<div class="collapse wrap" data-expected-client-width="10" data-expected-client-height="20">X <a>É</a></div>
<div class="collapse nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="preserve wrap" data-expected-client-width="10" data-expected-client-height="20">X <a>É</a></div>
<div class="preserve nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="preserve-breaks wrap" data-expected-client-width="10" data-expected-client-height="20">X <a>É</a></div>
<div class="preserve-breaks nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="break-spaces wrap" data-expected-client-width="20" data-expected-client-height="20">X <a>É</a></div>
<div class="break-spaces nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
</div>
<hr> <hr>
@ -279,6 +289,16 @@ x-br::before {
<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 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 class="break-spaces nowrap" data-expected-client-width="20" data-expected-client-height="20">X <x-br></x-br>É</div>
</div> </div>
<div class="container wide">
<div class="collapse wrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="collapse nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="preserve wrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="preserve nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="preserve-breaks wrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="preserve-breaks nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="break-spaces wrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
<div class="break-spaces nowrap" data-expected-client-width="30" data-expected-client-height="10">X <a>É</a></div>
</div>
<hr> <hr>