mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
layout: Count word separators as justification opportunities when trimming whitespace (#31161)
Before counting whitepsace-only `GlyphStore`s where counted as a single justification opportunity when trimming whitespace from the front and back of lines. This isn't correct, instead count the actual number of word seperators of the trimmed `GlyphStore`s. These two counts can be different in the case where whitespace collapse isn't happening yet (flexbox). In addition, using word seperators means the code is making less assumptions about the contents of the line and is more robust. This fixes some crashes in flexbox tests on debug builds. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
This commit is contained in:
parent
1d67aa44ca
commit
7de0486e2e
3 changed files with 25 additions and 19 deletions
|
@ -179,13 +179,14 @@ impl LineUnderConstruction {
|
|||
// > as well as any trailing U+1680 OGHAM SPACE MARK whose white-space
|
||||
// > property is normal, nowrap, or pre-line.
|
||||
let mut whitespace_trimmed = Length::zero();
|
||||
let mut spaces_trimmed = 0;
|
||||
let mut word_seperators_trimmed = 0;
|
||||
for item in self.line_items.iter_mut().rev() {
|
||||
if !item.trim_whitespace_at_end(&mut whitespace_trimmed, &mut spaces_trimmed) {
|
||||
if !item.trim_whitespace_at_end(&mut whitespace_trimmed, &mut word_seperators_trimmed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.justification_opportunities -= spaces_trimmed;
|
||||
|
||||
self.justification_opportunities -= word_seperators_trimmed;
|
||||
whitespace_trimmed
|
||||
}
|
||||
}
|
||||
|
@ -399,14 +400,15 @@ impl UnbreakableSegmentUnderConstruction {
|
|||
/// This prevents whitespace from being added to the beginning of a line.
|
||||
fn trim_leading_whitespace(&mut self) {
|
||||
let mut whitespace_trimmed = Length::zero();
|
||||
let mut spaces_trimmed = 0;
|
||||
let mut word_seperators_trimmed = 0;
|
||||
for item in self.line_items.iter_mut() {
|
||||
if !item.trim_whitespace_at_start(&mut whitespace_trimmed, &mut spaces_trimmed) {
|
||||
if !item.trim_whitespace_at_start(&mut whitespace_trimmed, &mut word_seperators_trimmed)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.inline_size -= whitespace_trimmed;
|
||||
self.justification_opportunities -= spaces_trimmed;
|
||||
self.justification_opportunities -= word_seperators_trimmed;
|
||||
}
|
||||
|
||||
/// Prepare this segment for placement on a new and empty line. This happens when the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue