Turn white-space into a shorthand (#32146)

Bumps Stylo to servo/stylo#37

`white-space` is split into `white-space-collapse` and `text-wrap-mode`:

| white-space | white-space-collapse | text-wrap-mode |
| ----------- | -------------------- | -------------- |
| normal      | collapse             | wrap           |
| nowrap      | collapse             | nowrap         |
| pre-wrap    | preserve             | wrap           |
| pre         | preserve             | nowrap         |
| pre-line    | preserve-breaks      | wrap           |
| -           | preserve-breaks      | nowrap         |

Note this introduces a combination that wasn't previously possible,
but I think the existing logic can handle it well enough.

The old `allow_wrap()` is replaced by checking whether `text-wrap-mode`
is set to `wrap`.

The old `preserve_newlines()` is replaced by checking whether
`white-space-collapse` is *not* set to `collapse`.

The old `preserve_spaces()` is replaced by checking whether
`white-space-collapse` is set to `preserve`.
This commit is contained in:
Oriol Brufau 2024-04-29 12:40:44 +02:00 committed by GitHub
parent a1f8c19355
commit d490fdf83c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 141 additions and 454 deletions

26
Cargo.lock generated
View file

@ -1206,7 +1206,7 @@ dependencies = [
[[package]]
name = "derive_common"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"darling",
"proc-macro2",
@ -3550,7 +3550,7 @@ dependencies = [
[[package]]
name = "malloc_size_of"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"accountable-refcell",
"app_units",
@ -5168,7 +5168,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.24.0"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"bitflags 2.5.0",
"cssparser",
@ -5456,7 +5456,7 @@ dependencies = [
[[package]]
name = "servo_arc"
version = "0.2.0"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"nodrop",
"serde",
@ -5466,7 +5466,7 @@ dependencies = [
[[package]]
name = "servo_atoms"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"string_cache",
"string_cache_codegen",
@ -5664,7 +5664,7 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "size_of_test"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"static_assertions",
]
@ -5789,7 +5789,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "static_prefs"
version = "0.1.0"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
[[package]]
name = "strict-num"
@ -5826,7 +5826,7 @@ dependencies = [
[[package]]
name = "style"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"app_units",
"arrayvec",
@ -5885,7 +5885,7 @@ dependencies = [
[[package]]
name = "style_config"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"lazy_static",
]
@ -5893,7 +5893,7 @@ dependencies = [
[[package]]
name = "style_derive"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"darling",
"derive_common",
@ -5924,7 +5924,7 @@ dependencies = [
[[package]]
name = "style_traits"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"app_units",
"bitflags 2.5.0",
@ -6287,7 +6287,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "to_shmem"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"cssparser",
"servo_arc",
@ -6300,7 +6300,7 @@ dependencies = [
[[package]]
name = "to_shmem_derive"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?rev=6faedad67ac2e320b51ac72a165b0ceb52caf918#6faedad67ac2e320b51ac72a165b0ceb52caf918"
source = "git+https://github.com/servo/stylo?branch=2024-04-16#a4a43436640986bbec6e9646ecdeedd607622bc1"
dependencies = [
"darling",
"derive_common",

View file

@ -64,7 +64,7 @@ keyboard-types = "0.6"
lazy_static = "1.4"
libc = "0.2"
log = "0.4"
malloc_size_of = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918", features = ["servo"] }
malloc_size_of = { git = "https://github.com/servo/stylo", branch = "2024-04-16", features = ["servo"] }
malloc_size_of_derive = "0.1"
mime = "0.3.13"
mime_guess = "2.0.3"
@ -87,31 +87,31 @@ rustls = { version = "0.21.12", features = ["dangerous_configuration"] }
rustls-pemfile = "1.0.4"
script_layout_interface = { path = "components/shared/script_layout" }
script_traits = { path = "components/shared/script" }
selectors = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918" }
selectors = { git = "https://github.com/servo/stylo", branch = "2024-04-16" }
serde = "1.0.198"
serde_bytes = "0.11"
serde_json = "1.0"
servo-media = { git = "https://github.com/servo/media" }
servo-media-dummy = { git = "https://github.com/servo/media" }
servo-media-gstreamer = { git = "https://github.com/servo/media" }
servo_arc = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918" }
servo_atoms = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918" }
size_of_test = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918" }
servo_arc = { git = "https://github.com/servo/stylo", branch = "2024-04-16" }
servo_atoms = { git = "https://github.com/servo/stylo", branch = "2024-04-16" }
size_of_test = { git = "https://github.com/servo/stylo", branch = "2024-04-16" }
smallbitvec = "2.5.3"
smallvec = "1.13"
sparkle = "0.1.26"
string_cache = "0.8"
string_cache_codegen = "0.5"
style = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918", features = ["servo"] }
style_config = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918" }
style_traits = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918", features = ["servo"] }
style = { git = "https://github.com/servo/stylo", branch = "2024-04-16", features = ["servo"] }
style_config = { git = "https://github.com/servo/stylo", branch = "2024-04-16" }
style_traits = { git = "https://github.com/servo/stylo", branch = "2024-04-16", features = ["servo"] }
# NOTE: the sm-angle feature only 2024-03-01rms!
surfman = { version = "0.9", features = ["chains", "sm-angle", "sm-angle-default"] }
syn = { version = "2", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = "0.13"
thin-vec = "0.2.13"
time = "0.1.41"
to_shmem = { git = "https://github.com/servo/stylo", rev = "6faedad67ac2e320b51ac72a165b0ceb52caf918" }
to_shmem = { git = "https://github.com/servo/stylo", branch = "2024-04-16" }
tokio = "1"
tokio-rustls = "0.24"
tungstenite = "0.20"

View file

@ -41,8 +41,9 @@ use style::computed_values::overflow_wrap::T as OverflowWrap;
use style::computed_values::overflow_x::T as StyleOverflow;
use style::computed_values::position::T as Position;
use style::computed_values::text_decoration_line::T as TextDecorationLine;
use style::computed_values::text_wrap_mode::T as TextWrapMode;
use style::computed_values::transform_style::T as TransformStyle;
use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::computed_values::word_break::T as WordBreak;
use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues;
@ -1539,8 +1540,12 @@ impl Fragment {
&self.selected_style
}
pub fn white_space(&self) -> WhiteSpace {
self.style().get_inherited_text().white_space
pub fn white_space_collapse(&self) -> WhiteSpaceCollapse {
self.style().get_inherited_text().white_space_collapse
}
pub fn text_wrap_mode(&self) -> TextWrapMode {
self.style().get_inherited_text().text_wrap_mode
}
pub fn color(&self) -> Color {
@ -1586,7 +1591,7 @@ impl Fragment {
/// Returns true if this element can be split. This is true for text fragments, unless
/// `white-space: pre` or `white-space: nowrap` is set.
pub fn can_split(&self) -> bool {
self.is_scanned_text_fragment() && self.white_space().allow_wrap()
self.is_scanned_text_fragment() && self.text_wrap_mode() == TextWrapMode::Wrap
}
/// Returns true if and only if this fragment is a generated content fragment.
@ -1703,7 +1708,7 @@ impl Fragment {
.metrics_for_range(range)
.advance_width;
let min_line_inline_size = if self_.white_space().allow_wrap() {
let min_line_inline_size = if self_.text_wrap_mode() == TextWrapMode::Wrap {
text_fragment_info.run.min_width_for_range(range)
} else {
max_line_inline_size
@ -1968,7 +1973,7 @@ impl Fragment {
// see if we're going to overflow the line. If so, perform a best-effort split.
let mut remaining_range = slice.text_run_range();
let split_is_empty = inline_start_range.is_empty() &&
(self.white_space().allow_wrap() ||
(self.text_wrap_mode() == TextWrapMode::Wrap ||
!self.requires_line_break_afterward_if_wrapping_on_newlines());
if split_is_empty {
// We're going to overflow the line.
@ -2520,7 +2525,8 @@ impl Fragment {
// FIXME: Should probably use a whitelist of styles that can safely differ (#3165)
if self.style().get_font() != other.style().get_font() ||
self.text_decoration_line() != other.text_decoration_line() ||
self.white_space() != other.white_space() ||
self.white_space_collapse() != other.white_space_collapse() ||
self.text_wrap_mode() != other.text_wrap_mode() ||
self.color() != other.color()
{
return false;
@ -2893,7 +2899,7 @@ impl Fragment {
}
pub fn strip_leading_whitespace_if_necessary(&mut self) -> WhitespaceStrippingResult {
if self.white_space().preserve_spaces() {
if self.white_space_collapse() == WhiteSpaceCollapse::Preserve {
return WhitespaceStrippingResult::RetainFragment;
}
@ -2963,7 +2969,7 @@ impl Fragment {
/// Returns true if the entire fragment was stripped.
pub fn strip_trailing_whitespace_if_necessary(&mut self) -> WhitespaceStrippingResult {
if self.white_space().preserve_spaces() {
if self.white_space_collapse() == WhiteSpaceCollapse::Preserve {
return WhitespaceStrippingResult::RetainFragment;
}

View file

@ -22,7 +22,8 @@ use style::computed_values::overflow_x::T as StyleOverflow;
use style::computed_values::position::T as Position;
use style::computed_values::text_align::T as TextAlign;
use style::computed_values::text_justify::T as TextJustify;
use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::text_wrap_mode::T as TextWrapMode;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage;
@ -622,7 +623,7 @@ impl LineBreaker {
if fragment.suppress_line_break_before() || !fragment.is_on_glyph_run_boundary() {
false
} else {
fragment.white_space().allow_wrap()
fragment.text_wrap_mode() == TextWrapMode::Wrap
}
};
@ -663,7 +664,7 @@ impl LineBreaker {
// If we must flush the line after finishing this fragment due to `white-space: pre`,
// detect that.
let line_flush_mode = if fragment.white_space().preserve_newlines() {
let line_flush_mode = if fragment.white_space_collapse() != WhiteSpaceCollapse::Collapse {
if fragment.requires_line_break_afterward_if_wrapping_on_newlines() {
LineFlushMode::Flush
} else {
@ -687,7 +688,7 @@ impl LineBreaker {
// If the wrapping mode prevents us from splitting, then back up and split at the last
// known good split point.
if !fragment.white_space().allow_wrap() {
if fragment.text_wrap_mode() == TextWrapMode::Nowrap {
debug!(
"LineBreaker: fragment can't split; falling back to last known good split point"
);
@ -1494,10 +1495,16 @@ impl Flow for InlineFlow {
let mut intrinsic_sizes_for_nonbroken_run = IntrinsicISizesContribution::new();
for fragment in &mut self.fragments.fragments {
let intrinsic_sizes_for_fragment = fragment.compute_intrinsic_inline_sizes().finish();
match fragment.style.get_inherited_text().white_space {
WhiteSpace::Nowrap => intrinsic_sizes_for_nonbroken_run
.union_nonbreaking_inline(&intrinsic_sizes_for_fragment),
WhiteSpace::Pre => {
let style_text = fragment.style.get_inherited_text();
match (style_text.white_space_collapse, style_text.text_wrap_mode) {
(WhiteSpaceCollapse::Collapse, TextWrapMode::Nowrap) => {
intrinsic_sizes_for_nonbroken_run
.union_nonbreaking_inline(&intrinsic_sizes_for_fragment)
},
(
WhiteSpaceCollapse::Preserve | WhiteSpaceCollapse::PreserveBreaks,
TextWrapMode::Nowrap,
) => {
intrinsic_sizes_for_nonbroken_run
.union_nonbreaking_inline(&intrinsic_sizes_for_fragment);
@ -1512,7 +1519,10 @@ impl Flow for InlineFlow {
intrinsic_sizes_for_inline_run = IntrinsicISizesContribution::new();
}
},
WhiteSpace::PreWrap | WhiteSpace::PreLine => {
(
WhiteSpaceCollapse::Preserve | WhiteSpaceCollapse::PreserveBreaks,
TextWrapMode::Wrap,
) => {
// Flush the intrinsic sizes we were gathering up for the nonbroken run, if
// necessary.
intrinsic_sizes_for_inline_run
@ -1532,7 +1542,7 @@ impl Flow for InlineFlow {
intrinsic_sizes_for_inline_run = IntrinsicISizesContribution::new();
}
},
WhiteSpace::Normal => {
(WhiteSpaceCollapse::Collapse, TextWrapMode::Wrap) => {
// Flush the intrinsic sizes we were gathering up for the nonbroken run, if
// necessary.
intrinsic_sizes_for_inline_run

View file

@ -17,7 +17,7 @@ use gfx::text::util::{self, CompressionMode};
use log::{debug, warn};
use range::Range;
use style::computed_values::text_rendering::T as TextRendering;
use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::computed_values::word_break::T as WordBreak;
use style::logical_geometry::{LogicalSize, WritingMode};
use style::properties::style_structs::Font as FontStyleStruct;
@ -46,7 +46,7 @@ fn text(fragments: &LinkedList<Fragment>) -> String {
for fragment in fragments {
if let SpecificFragmentInfo::UnscannedText(ref info) = fragment.specific {
if fragment.white_space().preserve_newlines() {
if fragment.white_space_collapse() != WhiteSpaceCollapse::Collapse {
text.push_str(&info.text);
} else {
text.push_str(&info.text.replace('\n', " "));
@ -190,12 +190,10 @@ impl TextRunScanner {
let font_style = in_fragment.style().clone_font();
let inherited_text_style = in_fragment.style().get_inherited_text();
font_group = font_context.font_group(font_style);
compression = match in_fragment.white_space() {
WhiteSpace::Normal | WhiteSpace::Nowrap => {
CompressionMode::CompressWhitespaceNewline
},
WhiteSpace::Pre | WhiteSpace::PreWrap => CompressionMode::CompressNone,
WhiteSpace::PreLine => CompressionMode::CompressWhitespace,
compression = match in_fragment.white_space_collapse() {
WhiteSpaceCollapse::Collapse => CompressionMode::CompressWhitespaceNewline,
WhiteSpaceCollapse::Preserve => CompressionMode::CompressNone,
WhiteSpaceCollapse::PreserveBreaks => CompressionMode::CompressWhitespace,
};
text_transform = inherited_text_style.text_transform;
letter_spacing = inherited_text_style.letter_spacing;
@ -568,7 +566,7 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm
let string_before;
let selection_before;
{
if !first_fragment.white_space().preserve_newlines() {
if first_fragment.white_space_collapse() == WhiteSpaceCollapse::Collapse {
return;
}

View file

@ -77,10 +77,12 @@ use gfx::font::FontMetrics;
use gfx::text::glyph::GlyphStore;
use serde::Serialize;
use servo_arc::Arc;
use style::computed_values::text_wrap_mode::T as TextWrapMode;
use style::computed_values::vertical_align::T as VerticalAlign;
use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::context::QuirksMode;
use style::logical_geometry::WritingMode;
use style::properties::style_structs::InheritedText;
use style::properties::ComputedValues;
use style::values::computed::{Clear, Length};
use style::values::generics::box_::VerticalAlignKeyword;
@ -659,11 +661,17 @@ pub(super) struct InlineFormattingContextState<'a, 'b> {
/// Whether or not this InlineFormattingContext has processed any in flow content at all.
had_inflow_content: bool,
/// The currently white-space setting of this line. This is stored on the
/// The currently white-space-collapse setting of this line. This is stored on the
/// [`InlineFormattingContextState`] because when a soft wrap opportunity is defined
/// by the boundary between two characters, the white-space property of their nearest
/// by the boundary between two characters, the white-space-collapse property of their
/// nearest common ancestor is used.
white_space_collapse: WhiteSpaceCollapse,
/// The currently text-wrap-mode setting of this line. This is stored on the
/// [`InlineFormattingContextState`] because when a soft wrap opportunity is defined
/// by the boundary between two characters, the text-wrap-mode property of their nearest
/// common ancestor is used.
white_space: WhiteSpace,
text_wrap_mode: TextWrapMode,
/// The offset of the first and last baselines in the inline formatting context that we
/// are laying out. This is used to propagate baselines to the ancestors of
@ -697,7 +705,9 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
Some(inline_box_state) => &inline_box_state.base.style,
None => self.containing_block.style,
};
self.white_space = style.get_inherited_text().white_space;
let style_text = style.get_inherited_text();
self.white_space_collapse = style_text.white_space_collapse;
self.text_wrap_mode = style_text.text_wrap_mode;
}
fn processing_br_element(&self) -> bool {
@ -1286,7 +1296,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
) {
let inline_advance = Length::from(glyph_store.total_advance());
let flags = if glyph_store.is_whitespace() {
SegmentContentFlags::from(text_run.parent_style.get_inherited_text().white_space)
SegmentContentFlags::from(text_run.parent_style.get_inherited_text())
} else {
SegmentContentFlags::empty()
};
@ -1394,7 +1404,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
if self.current_line_segment.line_items.is_empty() {
return;
}
if !self.white_space.allow_wrap() {
if self.text_wrap_mode == TextWrapMode::Nowrap {
return;
}
@ -1498,13 +1508,13 @@ impl SegmentContentFlags {
}
}
impl From<WhiteSpace> for SegmentContentFlags {
fn from(white_space: WhiteSpace) -> Self {
impl From<&InheritedText> for SegmentContentFlags {
fn from(style_text: &InheritedText) -> Self {
let mut flags = Self::empty();
if !white_space.preserve_spaces() {
if style_text.white_space_collapse != WhiteSpaceCollapse::Preserve {
flags.insert(Self::COLLAPSIBLE_WHITESPACE);
}
if white_space.allow_wrap() {
if style_text.text_wrap_mode == TextWrapMode::Wrap {
flags.insert(Self::WRAPPABLE_WHITESPACE);
}
flags
@ -1633,6 +1643,7 @@ impl InlineFormattingContext {
.map(|font| font.borrow().metrics.clone())
});
let style_text = containing_block.style.get_inherited_text();
let mut ifc = InlineFormattingContextState {
positioning_context,
containing_block,
@ -1658,7 +1669,8 @@ impl InlineFormattingContext {
have_deferred_soft_wrap_opportunity: false,
prevent_soft_wrap_opportunity_before_next_atomic: false,
had_inflow_content: false,
white_space: containing_block.style.get_inherited_text().white_space,
white_space_collapse: style_text.white_space_collapse,
text_wrap_mode: style_text.text_wrap_mode,
baselines: Baselines::default(),
};
@ -2143,7 +2155,7 @@ impl IndependentFormattingContext {
&mut ifc.prevent_soft_wrap_opportunity_before_next_atomic,
false,
);
if ifc.white_space.allow_wrap() && !soft_wrap_opportunity_prevented {
if ifc.text_wrap_mode == TextWrapMode::Wrap && !soft_wrap_opportunity_prevented {
ifc.process_soft_wrap_opportunity();
}
@ -2403,10 +2415,9 @@ impl<'a> ContentSizesComputation<'a> {
continue;
}
let white_space =
text_run.parent_style.get_inherited_text().white_space;
if !white_space.preserve_spaces() {
// TODO: need to handle !white_space.allow_wrap().
let style_text = text_run.parent_style.get_inherited_text();
if style_text.white_space_collapse != WhiteSpaceCollapse::Preserve {
// TODO: need to handle TextWrapMode::Nowrap.
self.line_break_opportunity();
// Discard any leading whitespace in the line. This will always be trimmed.
if self.had_content_yet {
@ -2416,7 +2427,7 @@ impl<'a> ContentSizesComputation<'a> {
}
continue;
}
if white_space.allow_wrap() {
if style_text.text_wrap_mode == TextWrapMode::Wrap {
self.commit_pending_whitespace();
self.line_break_opportunity();
self.current_line.max_content += advance;

View file

@ -9,6 +9,7 @@ use atomic_refcell::AtomicRef;
use gfx::font::FontMetrics;
use gfx::text::glyph::GlyphStore;
use servo_arc::Arc;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::properties::ComputedValues;
use style::values::computed::Length;
use style::values::generics::box_::{GenericVerticalAlign, VerticalAlignKeyword};
@ -151,11 +152,8 @@ pub(super) struct TextRunLineItem {
impl TextRunLineItem {
fn trim_whitespace_at_end(&mut self, whitespace_trimmed: &mut Length) -> bool {
if self
.parent_style
.get_inherited_text()
.white_space
.preserve_spaces()
if self.parent_style.get_inherited_text().white_space_collapse ==
WhiteSpaceCollapse::Preserve
{
return false;
}
@ -179,11 +177,8 @@ impl TextRunLineItem {
}
fn trim_whitespace_at_start(&mut self, whitespace_trimmed: &mut Length) -> bool {
if self
.parent_style
.get_inherited_text()
.white_space
.preserve_spaces()
if self.parent_style.get_inherited_text().white_space_collapse ==
WhiteSpaceCollapse::Preserve
{
return false;
}

View file

@ -16,7 +16,7 @@ use range::Range;
use serde::Serialize;
use servo_arc::Arc;
use style::computed_values::text_rendering::T as TextRendering;
use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::computed_values::word_break::T as WordBreak;
use style::properties::ComputedValues;
use style::values::specified::text::TextTransformCase;
@ -189,8 +189,8 @@ impl TextRun {
/// Whether or not this [`TextRun`] has uncollapsible content. This is used
/// to determine if an [`super::InlineFormattingContext`] is considered empty or not.
pub(super) fn has_uncollapsible_content(&self) -> bool {
let white_space = self.parent_style.clone_white_space();
if white_space.preserve_spaces() && !self.text.is_empty() {
let white_space_collapse = self.parent_style.clone_white_space_collapse();
if white_space_collapse == WhiteSpaceCollapse::Preserve && !self.text.is_empty() {
return true;
}
@ -198,7 +198,7 @@ impl TextRun {
if !character.is_ascii_whitespace() {
return true;
}
if character == '\n' && white_space.preserve_newlines() {
if character == '\n' && white_space_collapse != WhiteSpaceCollapse::Collapse {
return true;
}
}
@ -291,10 +291,10 @@ impl TextRun {
// TODO: Eventually the text should come directly from the Cow strings of the DOM nodes.
let text = std::mem::take(&mut self.text);
let white_space = self.parent_style.clone_white_space();
let white_space_collapse = self.parent_style.clone_white_space_collapse();
let collapsed = WhitespaceCollapse::new(
text.as_str().chars(),
white_space,
white_space_collapse,
*last_inline_box_ended_with_collapsible_white_space,
);
@ -327,7 +327,7 @@ impl TextRun {
*on_word_boundary = character.is_whitespace();
*last_inline_box_ended_with_collapsible_white_space =
*on_word_boundary && !white_space.preserve_spaces();
*on_word_boundary && white_space_collapse != WhiteSpaceCollapse::Preserve;
let prevents_soft_wrap_opportunity =
char_prevents_soft_wrap_opportunity_when_before_or_after_atomic(character);
@ -437,11 +437,8 @@ impl TextRun {
if !run.glyph_store.is_whitespace() || run.range.length() != ByteIndex(1) {
return false;
}
if !self
.parent_style
.get_inherited_text()
.white_space
.preserve_newlines()
if self.parent_style.get_inherited_text().white_space_collapse ==
WhiteSpaceCollapse::Collapse
{
return false;
}
@ -526,7 +523,7 @@ fn preserve_segment_break() -> bool {
pub struct WhitespaceCollapse<InputIterator> {
char_iterator: InputIterator,
white_space: WhiteSpace,
white_space_collapse: WhiteSpaceCollapse,
/// Whether or not we should collapse white space completely at the start of the string.
/// This is true when the last character handled in our owning [`super::InlineFormattingContext`]
@ -555,12 +552,12 @@ pub struct WhitespaceCollapse<InputIterator> {
impl<InputIterator> WhitespaceCollapse<InputIterator> {
pub fn new(
char_iterator: InputIterator,
white_space: WhiteSpace,
white_space_collapse: WhiteSpaceCollapse,
trim_beginning_white_space: bool,
) -> Self {
Self {
char_iterator,
white_space,
white_space_collapse,
remove_collapsible_white_space_at_start: trim_beginning_white_space,
inside_white_space: false,
following_newline: false,
@ -594,7 +591,7 @@ where
// > characters are considered collapsible
// If whitespace is not considered collapsible, it is preserved entirely, which
// means that we can simply return the input string exactly.
if self.white_space.preserve_spaces() {
if self.white_space_collapse == WhiteSpaceCollapse::Preserve {
return self.char_iterator.next();
}
@ -623,7 +620,7 @@ where
//
// > When white-space is pre, pre-wrap, or pre-line, segment breaks are not
// > collapsible and are instead transformed into a preserved line feed"
if self.white_space == WhiteSpace::PreLine {
if self.white_space_collapse != WhiteSpaceCollapse::Collapse {
self.inside_white_space = false;
self.following_newline = true;
return Some(character);

View file

@ -4,52 +4,60 @@
mod text {
use layout_2020::flow::text_run::WhitespaceCollapse;
use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
#[test]
fn test_collapse_whitespace() {
let collapse = |input: &str, white_space, trim_beginning_white_space| {
WhitespaceCollapse::new(input.chars(), white_space, trim_beginning_white_space)
let collapse = |input: &str, white_space_collapse, trim_beginning_white_space| {
WhitespaceCollapse::new(
input.chars(),
white_space_collapse,
trim_beginning_white_space,
)
.collect::<String>()
};
let output = collapse("H ", WhiteSpace::Normal, false);
let output = collapse("H ", WhiteSpaceCollapse::Collapse, false);
assert_eq!(output, "H ");
let output = collapse(" W", WhiteSpace::Normal, true);
let output = collapse(" W", WhiteSpaceCollapse::Collapse, true);
assert_eq!(output, "W");
let output = collapse(" W", WhiteSpace::Normal, false);
let output = collapse(" W", WhiteSpaceCollapse::Collapse, false);
assert_eq!(output, " W");
let output = collapse(" H W", WhiteSpace::Normal, false);
let output = collapse(" H W", WhiteSpaceCollapse::Collapse, false);
assert_eq!(output, " H W");
let output = collapse("\n H \n \t W", WhiteSpace::Normal, false);
let output = collapse("\n H \n \t W", WhiteSpaceCollapse::Collapse, false);
assert_eq!(output, " H W");
let output = collapse("\n H \n \t W \n", WhiteSpace::Pre, false);
let output = collapse("\n H \n \t W \n", WhiteSpaceCollapse::Preserve, false);
assert_eq!(output, "\n H \n \t W \n");
let output = collapse("\n H \n \t W \n ", WhiteSpace::PreLine, false);
let output = collapse(
"\n H \n \t W \n ",
WhiteSpaceCollapse::PreserveBreaks,
false,
);
assert_eq!(output, "\nH\nW\n");
let output = collapse("Hello \n World", WhiteSpace::PreLine, true);
let output = collapse("Hello \n World", WhiteSpaceCollapse::PreserveBreaks, true);
assert_eq!(output, "Hello\nWorld");
let output = collapse(" \n World", WhiteSpace::PreLine, true);
let output = collapse(" \n World", WhiteSpaceCollapse::PreserveBreaks, true);
assert_eq!(output, "\nWorld");
let output = collapse(" ", WhiteSpace::Normal, true);
let output = collapse(" ", WhiteSpaceCollapse::Collapse, true);
assert_eq!(output, "");
let output = collapse(" ", WhiteSpace::Normal, false);
let output = collapse(" ", WhiteSpaceCollapse::Collapse, false);
assert_eq!(output, " ");
let output = collapse("\n ", WhiteSpace::Normal, true);
let output = collapse("\n ", WhiteSpaceCollapse::Collapse, true);
assert_eq!(output, "");
let output = collapse("\n ", WhiteSpace::Normal, false);
let output = collapse("\n ", WhiteSpaceCollapse::Collapse, false);
assert_eq!(output, " ");
}
}

View file

@ -23,6 +23,7 @@ use script_layout_interface::{
use servo_arc::Arc;
use servo_url::ServoUrl;
use style;
use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse;
use style::context::SharedStyleContext;
use style::dom::{NodeInfo, TElement, TNode, TShadowRoot};
use style::properties::ComputedValues;
@ -337,11 +338,10 @@ impl<'dom> ThreadSafeLayoutNode<'dom> for ServoThreadSafeLayoutNode<'dom> {
//
// If you implement other values for this property, you will almost certainly
// want to update this check.
!self
.style(context)
self.style(context)
.get_inherited_text()
.white_space
.preserve_newlines()
.white_space_collapse ==
WhiteSpaceCollapse::Collapse
}
}

View file

@ -35,18 +35,6 @@
[Property text-wrap inherits]
expected: FAIL
[Property white-space-collapse has initial value collapse]
expected: FAIL
[Property white-space-collapse inherits]
expected: FAIL
[Property text-wrap-mode has initial value wrap]
expected: FAIL
[Property text-wrap-mode inherits]
expected: FAIL
[Property text-wrap-style has initial value auto]
expected: FAIL

View file

@ -1,6 +0,0 @@
[text-wrap-mode-computed.html]
[Property text-wrap-mode value 'wrap']
expected: FAIL
[Property text-wrap-mode value 'nowrap']
expected: FAIL

View file

@ -1,21 +0,0 @@
[text-wrap-mode-valid.html]
[e.style['text-wrap-mode'\] = "wrap" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "nowrap" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "initial" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "inherit" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "unset" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "revert" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "revert-layer" should set the property value]
expected: FAIL

View file

@ -1,12 +1,3 @@
[white-space-collapse-computed.html]
[Property white-space-collapse value 'collapse']
expected: FAIL
[Property white-space-collapse value 'preserve']
expected: FAIL
[Property white-space-collapse value 'preserve-breaks']
expected: FAIL
[Property white-space-collapse value 'break-spaces']
expected: FAIL

View file

@ -1,27 +1,3 @@
[white-space-collapse-valid.html]
[e.style['white-space-collapse'\] = "collapse" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "preserve" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "preserve-breaks" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "break-spaces" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "initial" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "inherit" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "unset" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "revert" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "revert-layer" should set the property value]
expected: FAIL

View file

@ -1,70 +1,4 @@
[white-space-shorthand.html]
[e.style['white-space'\] = "collapse" should set the property value]
expected: FAIL
[Property white-space value 'collapse']
expected: FAIL
[e.style['white-space'\] = "wrap" should set the property value]
expected: FAIL
[Property white-space value 'wrap']
expected: FAIL
[e.style['white-space'\] = "collapse wrap" should set the property value]
expected: FAIL
[Property white-space value 'collapse wrap']
expected: FAIL
[e.style['white-space'\] = "wrap collapse" should set the property value]
expected: FAIL
[Property white-space value 'wrap collapse']
expected: FAIL
[e.style['white-space'\] = "preserve nowrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve nowrap']
expected: FAIL
[e.style['white-space'\] = "nowrap preserve" should set the property value]
expected: FAIL
[Property white-space value 'nowrap preserve']
expected: FAIL
[e.style['white-space'\] = "collapse nowrap" should set the property value]
expected: FAIL
[Property white-space value 'collapse nowrap']
expected: FAIL
[e.style['white-space'\] = "nowrap collapse" should set the property value]
expected: FAIL
[Property white-space value 'nowrap collapse']
expected: FAIL
[e.style['white-space'\] = "preserve" should set the property value]
expected: FAIL
[Property white-space value 'preserve']
expected: FAIL
[e.style['white-space'\] = "preserve wrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve wrap']
expected: FAIL
[e.style['white-space'\] = "wrap preserve" should set the property value]
expected: FAIL
[Property white-space value 'wrap preserve']
expected: FAIL
[e.style['white-space'\] = "break-spaces" should set the property value]
expected: FAIL
@ -83,36 +17,6 @@
[Property white-space value 'wrap break-spaces']
expected: FAIL
[e.style['white-space'\] = "preserve-breaks" should set the property value]
expected: FAIL
[Property white-space value 'preserve-breaks']
expected: FAIL
[e.style['white-space'\] = "preserve-breaks wrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve-breaks wrap']
expected: FAIL
[e.style['white-space'\] = "wrap preserve-breaks" should set the property value]
expected: FAIL
[Property white-space value 'wrap preserve-breaks']
expected: FAIL
[e.style['white-space'\] = "preserve-breaks nowrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve-breaks nowrap']
expected: FAIL
[e.style['white-space'\] = "nowrap preserve-breaks" should set the property value]
expected: FAIL
[Property white-space value 'nowrap preserve-breaks']
expected: FAIL
[e.style['white-space'\] = "balance" should set the property value]
expected: FAIL

View file

@ -1,2 +0,0 @@
[white-space-collapse-preserve-breaks-001.xht]
expected: FAIL

View file

@ -53,18 +53,6 @@
[Property word-wrap inherits]
expected: FAIL
[Property white-space-collapse has initial value collapse]
expected: FAIL
[Property white-space-collapse inherits]
expected: FAIL
[Property text-wrap-mode has initial value wrap]
expected: FAIL
[Property text-wrap-mode inherits]
expected: FAIL
[Property text-wrap-style has initial value auto]
expected: FAIL

View file

@ -1,6 +0,0 @@
[text-wrap-mode-computed.html]
[Property text-wrap-mode value 'wrap']
expected: FAIL
[Property text-wrap-mode value 'nowrap']
expected: FAIL

View file

@ -1,21 +0,0 @@
[text-wrap-mode-valid.html]
[e.style['text-wrap-mode'\] = "wrap" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "nowrap" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "initial" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "inherit" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "unset" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "revert" should set the property value]
expected: FAIL
[e.style['text-wrap-mode'\] = "revert-layer" should set the property value]
expected: FAIL

View file

@ -1,12 +1,3 @@
[white-space-collapse-computed.html]
[Property white-space-collapse value 'collapse']
expected: FAIL
[Property white-space-collapse value 'preserve']
expected: FAIL
[Property white-space-collapse value 'preserve-breaks']
expected: FAIL
[Property white-space-collapse value 'break-spaces']
expected: FAIL

View file

@ -1,27 +1,3 @@
[white-space-collapse-valid.html]
[e.style['white-space-collapse'\] = "collapse" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "preserve" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "preserve-breaks" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "break-spaces" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "initial" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "inherit" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "unset" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "revert" should set the property value]
expected: FAIL
[e.style['white-space-collapse'\] = "revert-layer" should set the property value]
expected: FAIL

View file

@ -1,70 +1,4 @@
[white-space-shorthand.html]
[e.style['white-space'\] = "collapse" should set the property value]
expected: FAIL
[Property white-space value 'collapse']
expected: FAIL
[e.style['white-space'\] = "wrap" should set the property value]
expected: FAIL
[Property white-space value 'wrap']
expected: FAIL
[e.style['white-space'\] = "collapse wrap" should set the property value]
expected: FAIL
[Property white-space value 'collapse wrap']
expected: FAIL
[e.style['white-space'\] = "wrap collapse" should set the property value]
expected: FAIL
[Property white-space value 'wrap collapse']
expected: FAIL
[e.style['white-space'\] = "preserve nowrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve nowrap']
expected: FAIL
[e.style['white-space'\] = "nowrap preserve" should set the property value]
expected: FAIL
[Property white-space value 'nowrap preserve']
expected: FAIL
[e.style['white-space'\] = "collapse nowrap" should set the property value]
expected: FAIL
[Property white-space value 'collapse nowrap']
expected: FAIL
[e.style['white-space'\] = "nowrap collapse" should set the property value]
expected: FAIL
[Property white-space value 'nowrap collapse']
expected: FAIL
[e.style['white-space'\] = "preserve" should set the property value]
expected: FAIL
[Property white-space value 'preserve']
expected: FAIL
[e.style['white-space'\] = "preserve wrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve wrap']
expected: FAIL
[e.style['white-space'\] = "wrap preserve" should set the property value]
expected: FAIL
[Property white-space value 'wrap preserve']
expected: FAIL
[e.style['white-space'\] = "break-spaces" should set the property value]
expected: FAIL
@ -83,36 +17,6 @@
[Property white-space value 'wrap break-spaces']
expected: FAIL
[e.style['white-space'\] = "preserve-breaks" should set the property value]
expected: FAIL
[Property white-space value 'preserve-breaks']
expected: FAIL
[e.style['white-space'\] = "preserve-breaks wrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve-breaks wrap']
expected: FAIL
[e.style['white-space'\] = "wrap preserve-breaks" should set the property value]
expected: FAIL
[Property white-space value 'wrap preserve-breaks']
expected: FAIL
[e.style['white-space'\] = "preserve-breaks nowrap" should set the property value]
expected: FAIL
[Property white-space value 'preserve-breaks nowrap']
expected: FAIL
[e.style['white-space'\] = "nowrap preserve-breaks" should set the property value]
expected: FAIL
[Property white-space value 'nowrap preserve-breaks']
expected: FAIL
[e.style['white-space'\] = "balance" should set the property value]
expected: FAIL