From 61ca2dde2966bb5cca9f2e9bcd815cee4c409ee5 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 6 Dec 2024 02:05:54 +0100 Subject: [PATCH] Upgrade Stylo to 2024-12-04 (#34501) * Upgrade Stylo to 2024-12-04 Signed-off-by: Oriol Brufau * Fixup for https://phabricator.services.mozilla.com/D229998 Signed-off-by: Oriol Brufau * Update test expectations Signed-off-by: Oriol Brufau --------- Signed-off-by: Oriol Brufau --- Cargo.lock | 26 +++--- Cargo.toml | 18 ++-- components/layout/block.rs | 8 +- components/layout/construct.rs | 70 ++++++++------- components/layout/floats.rs | 43 +++++++-- components/layout/flow.rs | 34 +++---- components/layout/fragment.rs | 9 +- components/layout/incremental.rs | 3 +- components/layout_2020/flow/float.rs | 89 ++++++++++++------- components/layout_2020/flow/inline/mod.rs | 8 +- components/layout_2020/flow/mod.rs | 87 ++++++++++-------- components/layout_2020/tests/floats.rs | 13 ++- .../css-box/parsing/clear-computed.html.ini | 6 -- .../css-box/parsing/float-computed.html.ini | 6 -- ...ogical-values-float-clear-reftest.html.ini | 2 - .../logical-values-float-clear.html.ini | 12 --- 16 files changed, 239 insertions(+), 195 deletions(-) delete mode 100644 tests/wpt/meta/css/css-box/parsing/clear-computed.html.ini delete mode 100644 tests/wpt/meta/css/css-box/parsing/float-computed.html.ini delete mode 100644 tests/wpt/meta/css/css-logical/logical-values-float-clear-reftest.html.ini delete mode 100644 tests/wpt/meta/css/css-logical/logical-values-float-clear.html.ini diff --git a/Cargo.lock b/Cargo.lock index dc3ee0bc848bf..657b3093a9872 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1617,7 +1617,7 @@ dependencies = [ [[package]] name = "dom" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "bitflags 2.6.0", "malloc_size_of", @@ -4247,7 +4247,7 @@ dependencies = [ [[package]] name = "malloc_size_of" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "app_units", "cssparser", @@ -6196,7 +6196,7 @@ dependencies = [ [[package]] name = "selectors" version = "0.26.0" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "bitflags 2.6.0", "cssparser", @@ -6484,7 +6484,7 @@ dependencies = [ [[package]] name = "servo_arc" version = "0.4.0" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "serde", "stable_deref_trait", @@ -6493,7 +6493,7 @@ dependencies = [ [[package]] name = "servo_atoms" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "string_cache", "string_cache_codegen", @@ -6866,7 +6866,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "static_prefs" version = "0.1.0" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" [[package]] name = "strck" @@ -6925,7 +6925,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "style" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "app_units", "arrayvec", @@ -6983,7 +6983,7 @@ dependencies = [ [[package]] name = "style_config" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "lazy_static", ] @@ -6991,7 +6991,7 @@ dependencies = [ [[package]] name = "style_derive" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "darling", "proc-macro2", @@ -7021,7 +7021,7 @@ dependencies = [ [[package]] name = "style_traits" version = "0.0.1" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "app_units", "bitflags 2.6.0", @@ -7384,7 +7384,7 @@ dependencies = [ [[package]] name = "to_shmem" version = "0.1.0" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "cssparser", "servo_arc", @@ -7397,7 +7397,7 @@ dependencies = [ [[package]] name = "to_shmem_derive" version = "0.1.0" -source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e" +source = "git+https://github.com/servo/stylo?branch=2024-12-04#35e0fa29e93a7e85f44d4ad0610748634f7979b5" dependencies = [ "darling", "proc-macro2", @@ -9100,4 +9100,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" dependencies = [ "simd-adler32", -] \ No newline at end of file +] diff --git a/Cargo.toml b/Cargo.toml index aa840a7b40b01..7514c0c5926f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,25 +107,25 @@ 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", branch = "2024-11-01" } +selectors = { git = "https://github.com/servo/stylo", branch = "2024-12-04" } serde = "1.0.215" 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", branch = "2024-11-01", features = ["servo"] } -servo_atoms = { git = "https://github.com/servo/stylo", branch = "2024-11-01" } +servo_arc = { git = "https://github.com/servo/stylo", branch = "2024-12-04", features = ["servo"] } +servo_atoms = { git = "https://github.com/servo/stylo", branch = "2024-12-04" } smallbitvec = "2.5.3" smallvec = "1.13" static_assertions = "1.1" string_cache = "0.8" string_cache_codegen = "0.5" -style = { git = "https://github.com/servo/stylo", branch = "2024-11-01", features = ["servo"] } -style_config = { git = "https://github.com/servo/stylo", branch = "2024-11-01" } -style_dom = { git = "https://github.com/servo/stylo", package = "dom", branch = "2024-11-01" } -style_traits = { git = "https://github.com/servo/stylo", branch = "2024-11-01", features = ["servo"] } -style_malloc_size_of = { package = "malloc_size_of", git = "https://github.com/servo/stylo", branch = "2024-11-01", features = ["servo"] } +style = { git = "https://github.com/servo/stylo", branch = "2024-12-04", features = ["servo"] } +style_config = { git = "https://github.com/servo/stylo", branch = "2024-12-04" } +style_dom = { git = "https://github.com/servo/stylo", package = "dom", branch = "2024-12-04" } +style_traits = { git = "https://github.com/servo/stylo", branch = "2024-12-04", features = ["servo"] } +style_malloc_size_of = { package = "malloc_size_of", git = "https://github.com/servo/stylo", branch = "2024-12-04", features = ["servo"] } surfman = { git = "https://github.com/servo/surfman", rev = "c8d6b4b65aeab739ee7651602e29c8d58ceee123", features = ["chains"] } syn = { version = "2", default-features = false, features = ["clone-impls", "derive", "parsing"] } synstructure = "0.13" @@ -134,7 +134,7 @@ thin-vec = "0.2.13" tikv-jemalloc-sys = "0.6.0" tikv-jemallocator = "0.6.0" time_03 = { package = "time", version = "0.3", features = ["large-dates", "local-offset", "serde"] } -to_shmem = { git = "https://github.com/servo/stylo", branch = "2024-11-01" } +to_shmem = { git = "https://github.com/servo/stylo", branch = "2024-12-04" } tokio = "1" tokio-rustls = "0.24" tracing = "0.1.41" diff --git a/components/layout/block.rs b/components/layout/block.rs index 31f6acd243c26..003ea4bcaa54c 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1927,23 +1927,23 @@ impl BlockFlow { .flags .contains(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS), ) { - (Float::None, true) => { + (None, true) => { computation.content_intrinsic_sizes.preferred_inline_size = max( computation.content_intrinsic_sizes.preferred_inline_size, child_base.intrinsic_inline_sizes.preferred_inline_size, ); }, - (Float::None, false) => { + (None, false) => { preferred_inline_size_of_children_without_text_or_replaced_fragments = max( preferred_inline_size_of_children_without_text_or_replaced_fragments, child_base.intrinsic_inline_sizes.preferred_inline_size, ) }, - (Float::Left, _) => { + (Some(FloatKind::Left), _) => { left_float_width_accumulator += child_base.intrinsic_inline_sizes.preferred_inline_size; }, - (Float::Right, _) => { + (Some(FloatKind::Right), _) => { right_float_width_accumulator += child_base.intrinsic_inline_sizes.preferred_inline_size; }, diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 1c4eff5589874..1a864e45e64a9 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -1372,6 +1372,9 @@ where &table_style, ); } + // FIXME: this should use the writing mode of the containing block. + let wrapper_float_kind = + FloatKind::from_property_and_writing_mode(float_value, wrapper_style.writing_mode); let wrapper_fragment = Fragment::from_opaque_node_and_style( node.opaque(), PseudoElementType::Normal, @@ -1380,7 +1383,6 @@ where node.restyle_damage(), SpecificFragmentInfo::TableWrapper, ); - let wrapper_float_kind = FloatKind::from_property(float_value); let mut wrapper_flow = FlowRef::new(Arc::new( TableWrapperFlow::from_fragment_and_float_kind(wrapper_fragment, wrapper_float_kind), )); @@ -1509,8 +1511,10 @@ where node: &ConcreteThreadSafeLayoutNode, flotation: Float, ) -> ConstructionResult { - let flotation = FloatKind::from_property(flotation); - let marker_fragments = match node.style(self.style_context()).get_list().list_style_image { + // FIXME: this should use the writing mode of the containing block. + let style = node.style(self.style_context()); + let flotation = FloatKind::from_property_and_writing_mode(flotation, style.writing_mode); + let marker_fragments = match style.get_list().list_style_image { Image::Url(ref url_value) => { let image_info = Box::new(ImageFragmentInfo::new( url_value.url().cloned().map(Into::into), @@ -1529,31 +1533,31 @@ where Image::Gradient(..) | Image::PaintWorklet(..) | Image::CrossFade(..) | - Image::None => match ListStyleTypeContent::from_list_style_type( - node.style(self.style_context()).get_list().list_style_type, - ) { - ListStyleTypeContent::None => Vec::new(), - ListStyleTypeContent::StaticText(ch) => { - let text = format!("{}\u{a0}", ch); - let mut unscanned_marker_fragments = LinkedList::new(); - unscanned_marker_fragments.push_back(Fragment::new( + Image::None => { + match ListStyleTypeContent::from_list_style_type(style.get_list().list_style_type) { + ListStyleTypeContent::None => Vec::new(), + ListStyleTypeContent::StaticText(ch) => { + let text = format!("{}\u{a0}", ch); + let mut unscanned_marker_fragments = LinkedList::new(); + unscanned_marker_fragments.push_back(Fragment::new( + node, + SpecificFragmentInfo::UnscannedText(Box::new( + UnscannedTextFragmentInfo::new(Box::::from(text), None), + )), + self.layout_context, + )); + let marker_fragments = TextRunScanner::new().scan_for_runs( + &self.layout_context.font_context, + unscanned_marker_fragments, + ); + marker_fragments.fragments + }, + ListStyleTypeContent::GeneratedContent(info) => vec![Fragment::new( node, - SpecificFragmentInfo::UnscannedText(Box::new( - UnscannedTextFragmentInfo::new(Box::::from(text), None), - )), + SpecificFragmentInfo::GeneratedContent(info), self.layout_context, - )); - let marker_fragments = TextRunScanner::new().scan_for_runs( - &self.layout_context.font_context, - unscanned_marker_fragments, - ); - marker_fragments.fragments - }, - ListStyleTypeContent::GeneratedContent(info) => vec![Fragment::new( - node, - SpecificFragmentInfo::GeneratedContent(info), - self.layout_context, - )], + )], + } }, }; @@ -1564,11 +1568,7 @@ where // there. let mut initial_fragments = IntermediateInlineFragments::new(); let main_fragment = self.build_fragment_for_block(node); - let flow = match node - .style(self.style_context()) - .get_list() - .list_style_position - { + let flow = match style.get_list().list_style_position { ListStylePosition::Outside => Arc::new(ListItemFlow::from_fragments_and_flotation( main_fragment, marker_fragments, @@ -1956,7 +1956,9 @@ where // Flex items contribute flex flow construction results. (Display::Flex, float_value, _) => { - let float_kind = FloatKind::from_property(float_value); + // FIXME: this should use the writing mode of the containing block. + let float_kind = + FloatKind::from_property_and_writing_mode(float_value, style.writing_mode); let construction_result = self.build_flow_for_flex(node, float_kind); self.set_flow_construction_result(node, construction_result) }, @@ -1972,7 +1974,9 @@ where // TODO(pcwalton): Make this only trigger for blocks and handle the other `display` // properties separately. (_, float_value, _) => { - let float_kind = FloatKind::from_property(float_value); + // FIXME: this should use the writing mode of the containing block. + let float_kind = + FloatKind::from_property_and_writing_mode(float_value, style.writing_mode); // List items contribute their own special flows. let construction_result = if display.is_list_item() { self.build_flow_for_list_item(node, float_value) diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 4781e72aa1f02..ffef83c41894e 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -8,8 +8,10 @@ use std::fmt; use app_units::{Au, MAX_AU}; use log::debug; use serde::Serialize; +use style::computed_values::clear::T as StyleClear; use style::computed_values::float::T as StyleFloat; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; +use style::properties::ComputedValues; use crate::block::FormattingContextType; use crate::flow::{Flow, FlowFlags, GetBaseFlow, ImmutableFlowUtils}; @@ -23,12 +25,19 @@ pub enum FloatKind { } impl FloatKind { - pub fn from_property(property: StyleFloat) -> Option { - match property { - StyleFloat::None => None, - StyleFloat::Left => Some(FloatKind::Left), - StyleFloat::Right => Some(FloatKind::Right), - } + pub fn from_property_and_writing_mode( + property: StyleFloat, + writing_mode: WritingMode, + ) -> Option { + Some(match property { + StyleFloat::None => return None, + StyleFloat::Left => Self::Left, + StyleFloat::Right => Self::Right, + StyleFloat::InlineStart if writing_mode.is_bidi_ltr() => Self::Left, + StyleFloat::InlineStart => Self::Right, + StyleFloat::InlineEnd if writing_mode.is_bidi_ltr() => Self::Right, + StyleFloat::InlineEnd => Self::Left, + }) } } @@ -40,6 +49,22 @@ pub enum ClearType { Both, } +impl ClearType { + pub fn from_style(style: &ComputedValues) -> Option { + Some(match style.get_box().clear { + StyleClear::None => return None, + StyleClear::Left => Self::Left, + StyleClear::Right => Self::Right, + StyleClear::Both => Self::Both, + // FIXME: these should check the writing mode of the containing block. + StyleClear::InlineStart if style.writing_mode.is_bidi_ltr() => Self::Left, + StyleClear::InlineStart => Self::Right, + StyleClear::InlineEnd if style.writing_mode.is_bidi_ltr() => Self::Right, + StyleClear::InlineEnd => Self::Left, + }) + } +} + /// Information about a single float. #[derive(Clone, Copy)] struct Float { @@ -558,9 +583,9 @@ impl SpeculatedFloatPlacement { } match base_flow.flags.float_kind() { - StyleFloat::None => {}, - StyleFloat::Left => self.left += float_inline_size, - StyleFloat::Right => self.right += float_inline_size, + None => {}, + Some(FloatKind::Left) => self.left += float_inline_size, + Some(FloatKind::Right) => self.right += float_inline_size, } } diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 7f098d2a0cba7..9704248082bc7 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -38,8 +38,6 @@ use log::debug; use serde::ser::{SerializeStruct, Serializer}; use serde::Serialize; use servo_geometry::{au_rect_to_f32_rect, f32_rect_to_au_rect, MaxRect}; -use style::computed_values::clear::T as Clear; -use style::computed_values::float::T as Float; 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; @@ -57,7 +55,7 @@ use crate::display_list::{ DisplayListBuildState, StackingContextCollectionState, StackingContextId, }; use crate::flex::FlexFlow; -use crate::floats::{Floats, SpeculatedFloatPlacement}; +use crate::floats::{ClearType, FloatKind, Floats, SpeculatedFloatPlacement}; use crate::flow_list::{FlowList, FlowListIterator, MutFlowListIterator}; use crate::flow_ref::{FlowRef, WeakFlowRef}; use crate::fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow}; @@ -672,13 +670,13 @@ bitflags! { impl FlowFlags { #[inline] - pub fn float_kind(&self) -> Float { + pub fn float_kind(&self) -> Option { if self.contains(FlowFlags::FLOATS_LEFT) { - Float::Left + Some(FloatKind::Left) } else if self.contains(FlowFlags::FLOATS_RIGHT) { - Float::Right + Some(FloatKind::Right) } else { - Float::None + None } } @@ -1070,18 +1068,22 @@ impl BaseFlow { } if force_nonfloated == ForceNonfloatedFlag::FloatIfNecessary { - match style.get_box().float { - Float::None => {}, - Float::Left => flags.insert(FlowFlags::FLOATS_LEFT), - Float::Right => flags.insert(FlowFlags::FLOATS_RIGHT), + // FIXME: this should use the writing mode of the containing block. + match FloatKind::from_property_and_writing_mode( + style.get_box().float, + style.writing_mode, + ) { + None => {}, + Some(FloatKind::Left) => flags.insert(FlowFlags::FLOATS_LEFT), + Some(FloatKind::Right) => flags.insert(FlowFlags::FLOATS_RIGHT), } } - match style.get_box().clear { - Clear::None => {}, - Clear::Left => flags.insert(FlowFlags::CLEARS_LEFT), - Clear::Right => flags.insert(FlowFlags::CLEARS_RIGHT), - Clear::Both => { + match ClearType::from_style(style) { + None => {}, + Some(ClearType::Left) => flags.insert(FlowFlags::CLEARS_LEFT), + Some(ClearType::Right) => flags.insert(FlowFlags::CLEARS_RIGHT), + Some(ClearType::Both) => { flags.insert(FlowFlags::CLEARS_LEFT); flags.insert(FlowFlags::CLEARS_RIGHT); }, diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 5707154839615..6a94f4d374c2c 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -33,7 +33,6 @@ use serde::ser::{Serialize, SerializeStruct, Serializer}; use servo_url::ServoUrl; use style::computed_values::border_collapse::T as BorderCollapse; use style::computed_values::box_sizing::T as BoxSizing; -use style::computed_values::clear::T as Clear; use style::computed_values::color::T as Color; use style::computed_values::display::T as Display; use style::computed_values::mix_blend_mode::T as MixBlendMode; @@ -1507,13 +1506,7 @@ impl Fragment { /// FIXME(pcwalton): Just replace with the clear type from the style module for speed? #[inline(always)] pub fn clear(&self) -> Option { - let style = self.style(); - match style.get_box().clear { - Clear::None => None, - Clear::Left => Some(ClearType::Left), - Clear::Right => Some(ClearType::Right), - Clear::Both => Some(ClearType::Both), - } + ClearType::from_style(self.style()) } #[inline(always)] diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index 9adc6cfbe9c77..b1e12c59f1fec 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -3,7 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use bitflags::bitflags; -use style::computed_values::float::T as Float; use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage; @@ -67,7 +66,7 @@ impl dyn Flow { } let self_base = self.mut_base(); - if self_base.flags.float_kind() != Float::None && + if self_base.flags.float_kind().is_some() && self_base .restyle_damage .intersects(ServoRestyleDamage::REFLOW) diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index 307cbfc68cc12..3fb4e26edf083 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -19,7 +19,7 @@ use style::computed_values::float::T as FloatProperty; use style::computed_values::position::T as Position; use style::logical_geometry::WritingMode; use style::properties::ComputedValues; -use style::values::computed::Clear; +use style::values::computed::Clear as StyleClear; use style::values::specified::text::TextDecorationLine; use crate::context::LayoutContext; @@ -243,8 +243,8 @@ impl<'a> PlacementAmongFloats<'a> { inline: self.min_inline_start, block: self .ceiling - .max(self.float_context.clear_left_position) - .max(self.float_context.clear_right_position), + .max(self.float_context.clear_inline_start_position) + .max(self.float_context.clear_inline_end_position), }, size: LogicalVec2 { inline: self.max_inline_end - self.min_inline_start, @@ -339,10 +339,10 @@ pub struct FloatContext { /// independent block formatting context that contains all of the floats /// this `FloatContext` positions. pub containing_block_info: ContainingBlockPositionInfo, - /// The (logically) lowest margin edge of the last left float. - pub clear_left_position: Au, - /// The (logically) lowest margin edge of the last right float. - pub clear_right_position: Au, + /// The (logically) lowest margin edge of the last inline-start float. + pub clear_inline_start_position: Au, + /// The (logically) lowest margin edge of the last inline-end float. + pub clear_inline_end_position: Au, } impl FloatContext { @@ -368,8 +368,8 @@ impl FloatContext { Au::zero(), max_inline_size, ), - clear_left_position: Au::zero(), - clear_right_position: Au::zero(), + clear_inline_start_position: Au::zero(), + clear_inline_end_position: Au::zero(), } } @@ -394,11 +394,11 @@ impl FloatContext { pub(crate) fn place_object(&self, object: &PlacementInfo, ceiling: Au) -> LogicalVec2 { let ceiling = match object.clear { Clear::None => ceiling, - Clear::Left => ceiling.max(self.clear_left_position), - Clear::Right => ceiling.max(self.clear_right_position), + Clear::InlineStart => ceiling.max(self.clear_inline_start_position), + Clear::InlineEnd => ceiling.max(self.clear_inline_end_position), Clear::Both => ceiling - .max(self.clear_left_position) - .max(self.clear_right_position), + .max(self.clear_inline_start_position) + .max(self.clear_inline_end_position), }; // Find the first band this float fits in. @@ -461,11 +461,11 @@ impl FloatContext { // Update clear. match new_float.side { FloatSide::InlineStart => { - self.clear_left_position + self.clear_inline_start_position .max_assign(new_float_rect.max_block_position()); }, FloatSide::InlineEnd => { - self.clear_right_position + self.clear_inline_end_position .max_assign(new_float_rect.max_block_position()); }, } @@ -498,6 +498,32 @@ impl FloatContext { } } +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Clear { + None, + InlineStart, + InlineEnd, + Both, +} + +impl Clear { + pub(crate) fn from_style_and_container_writing_mode( + style: &ComputedValues, + container_writing_mode: WritingMode, + ) -> Self { + match style.get_box().clear { + StyleClear::None => Self::None, + StyleClear::Both => Self::Both, + StyleClear::InlineStart => Self::InlineStart, + StyleClear::InlineEnd => Self::InlineEnd, + StyleClear::Left if container_writing_mode.is_bidi_ltr() => Self::InlineStart, + StyleClear::Left => Self::InlineEnd, + StyleClear::Right if container_writing_mode.is_bidi_ltr() => Self::InlineEnd, + StyleClear::Right => Self::InlineStart, + } + } +} + /// Information needed to place an object so that it doesn't collide with existing floats. #[derive(Clone, Debug)] pub struct PlacementInfo { @@ -537,19 +563,19 @@ pub struct FloatBand { } impl FloatSide { - fn from_style_and_container_writing_mode( + pub(crate) fn from_style_and_container_writing_mode( style: &ComputedValues, container_writing_mode: WritingMode, ) -> Option { - match (style.get_box().float, container_writing_mode.is_bidi_ltr()) { - (FloatProperty::None, _) => None, - (FloatProperty::Left, true) | (FloatProperty::Right, false) => { - Some(FloatSide::InlineStart) - }, - (FloatProperty::Right, true) | (FloatProperty::Left, false) => { - Some(FloatSide::InlineEnd) - }, - } + Some(match style.get_box().float { + FloatProperty::None => return None, + FloatProperty::InlineStart => Self::InlineStart, + FloatProperty::InlineEnd => Self::InlineEnd, + FloatProperty::Left if container_writing_mode.is_bidi_ltr() => Self::InlineStart, + FloatProperty::Left => Self::InlineEnd, + FloatProperty::Right if container_writing_mode.is_bidi_ltr() => Self::InlineEnd, + FloatProperty::Right => Self::InlineStart, + }) } } @@ -1021,12 +1047,12 @@ impl SequentialLayoutState { // in that case we don't need to add clearance. let clear_position = match clear { Clear::None => unreachable!(), - Clear::Left => self.floats.clear_left_position, - Clear::Right => self.floats.clear_right_position, + Clear::InlineStart => self.floats.clear_inline_start_position, + Clear::InlineEnd => self.floats.clear_inline_end_position, Clear::Both => self .floats - .clear_left_position - .max(self.floats.clear_right_position), + .clear_inline_start_position + .max(self.floats.clear_inline_end_position), }; if hypothetical_block_position >= clear_position { None @@ -1133,7 +1159,10 @@ impl SequentialLayoutState { container_writing_mode, ) .expect("Float box wasn't floated!"), - clear: box_fragment.style.get_box().clear, + clear: Clear::from_style_and_container_writing_mode( + &box_fragment.style, + container_writing_mode, + ), }); // Re-calculate relative adjustment so that it is not lost when the BoxFragment's diff --git a/components/layout_2020/flow/inline/mod.rs b/components/layout_2020/flow/inline/mod.rs index 7e2a537cb2946..d48f765a55c5e 100644 --- a/components/layout_2020/flow/inline/mod.rs +++ b/components/layout_2020/flow/inline/mod.rs @@ -96,7 +96,6 @@ use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse; use style::context::QuirksMode; use style::properties::style_structs::InheritedText; use style::properties::ComputedValues; -use style::values::computed::Clear; use style::values::generics::box_::VerticalAlignKeyword; use style::values::generics::font::LineHeight; use style::values::specified::box_::BaselineSource; @@ -111,7 +110,7 @@ use unicode_bidi::{BidiInfo, Level}; use webrender_api::FontInstanceKey; use xi_unicode::linebreak_property; -use super::float::PlacementAmongFloats; +use super::float::{Clear, PlacementAmongFloats}; use crate::cell::ArcRefCell; use crate::context::LayoutContext; use crate::flow::float::{FloatBox, SequentialLayoutState}; @@ -721,7 +720,10 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> { .contains(FragmentFlags::IS_BR_ELEMENT) && self.deferred_br_clear == Clear::None { - self.deferred_br_clear = inline_box_state.base.style.clone_clear(); + self.deferred_br_clear = Clear::from_style_and_container_writing_mode( + &inline_box_state.base.style, + self.containing_block.style.writing_mode, + ); } if inline_box.is_first_fragment { diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index f897c223d569a..46ccf221b417e 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -12,8 +12,7 @@ use inline::InlineFormattingContext; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use serde::Serialize; use servo_arc::Arc; -use style::computed_values::clear::T as Clear; -use style::computed_values::float::T as Float; +use style::computed_values::clear::T as StyleClear; use style::properties::ComputedValues; use style::servo::selector_parser::PseudoElement; use style::values::computed::Size as StyleSize; @@ -24,7 +23,8 @@ use style::Zero; use crate::cell::ArcRefCell; use crate::context::LayoutContext; use crate::flow::float::{ - ContainingBlockPositionInfo, FloatBox, PlacementAmongFloats, SequentialLayoutState, + Clear, ContainingBlockPositionInfo, FloatBox, FloatSide, PlacementAmongFloats, + SequentialLayoutState, }; use crate::formatting_contexts::{ Baselines, IndependentFormattingContext, IndependentLayout, IndependentLayoutResult, @@ -120,7 +120,7 @@ impl BlockLevelBox { }; // FIXME: This should only return false when 'clear' causes clearance. - if style.get_box().clear != Clear::None { + if style.get_box().clear != StyleClear::None { return false; } @@ -383,11 +383,17 @@ fn calculate_inline_content_size_for_block_level_boxes( &LogicalVec2::zero(), false, /* auto_block_size_stretches_to_containing_block */ ); - let style_box = &float_box.contents.style().get_box(); + let style = &float_box.contents.style(); Some(( inline_content_sizes_result, - style_box.float, - style_box.clear, + FloatSide::from_style_and_container_writing_mode( + style, + containing_block.writing_mode, + ), + Clear::from_style_and_container_writing_mode( + style, + containing_block.writing_mode, + ), )) }, BlockLevelBox::SameFormattingContextBlock { @@ -406,7 +412,7 @@ fn calculate_inline_content_size_for_block_level_boxes( // A block in the same BFC can overlap floats, it's not moved next to them, // so we shouldn't add its size to the size of the floats. // Instead, we treat it like an independent block with 'clear: both'. - Some((inline_content_sizes_result, Float::None, Clear::Both)) + Some((inline_content_sizes_result, None, Clear::Both)) }, BlockLevelBox::Independent(ref independent) => { let inline_content_sizes_result = independent.outer_inline_content_sizes( @@ -417,8 +423,11 @@ fn calculate_inline_content_size_for_block_level_boxes( ); Some(( inline_content_sizes_result, - Float::None, - independent.style().get_box().clear, + None, + Clear::from_style_and_container_writing_mode( + independent.style(), + containing_block.writing_mode, + ), )) }, } @@ -432,31 +441,32 @@ fn calculate_inline_content_size_for_block_level_boxes( depends_on_block_constraints: bool, /// The maximum size seen so far, not including trailing uncleared floats. max_size: ContentSizes, - /// The size of the trailing uncleared floats with 'float: left'. - left_floats: ContentSizes, - /// The size of the trailing uncleared floats with 'float: right'. - right_floats: ContentSizes, + /// The size of the trailing uncleared floats on the inline-start side + /// of the containing block. + start_floats: ContentSizes, + /// The size of the trailing uncleared floats on the inline-end side + /// of the containing block. + end_floats: ContentSizes, } impl AccumulatedData { fn max_size_including_uncleared_floats(&self) -> ContentSizes { - self.max_size - .max(self.left_floats.union(&self.right_floats)) + self.max_size.max(self.start_floats.union(&self.end_floats)) } fn clear_floats(&mut self, clear: Clear) { match clear { - Clear::Left => { + Clear::InlineStart => { self.max_size = self.max_size_including_uncleared_floats(); - self.left_floats = ContentSizes::zero(); + self.start_floats = ContentSizes::zero(); }, - Clear::Right => { + Clear::InlineEnd => { self.max_size = self.max_size_including_uncleared_floats(); - self.right_floats = ContentSizes::zero(); + self.end_floats = ContentSizes::zero(); }, Clear::Both => { self.max_size = self.max_size_including_uncleared_floats(); - self.left_floats = ContentSizes::zero(); - self.right_floats = ContentSizes::zero(); + self.start_floats = ContentSizes::zero(); + self.end_floats = ContentSizes::zero(); }, Clear::None => {}, }; @@ -472,14 +482,14 @@ fn calculate_inline_content_size_for_block_level_boxes( data.depends_on_block_constraints |= depends_on_block_constraints; data.clear_floats(clear); match float { - Float::Left => data.left_floats = data.left_floats.union(&size), - Float::Right => data.right_floats = data.right_floats.union(&size), - Float::None => { + Some(FloatSide::InlineStart) => data.start_floats = data.start_floats.union(&size), + Some(FloatSide::InlineEnd) => data.end_floats = data.end_floats.union(&size), + None => { data.max_size = data .max_size - .max(data.left_floats.union(&data.right_floats).union(&size)); - data.left_floats = ContentSizes::zero(); - data.right_floats = ContentSizes::zero(); + .max(data.start_floats.union(&data.end_floats).union(&size)); + data.start_floats = ContentSizes::zero(); + data.end_floats = ContentSizes::zero(); }, } data @@ -789,6 +799,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( mut sequential_layout_state: Option<&mut SequentialLayoutState>, collapsible_with_parent_start_margin: Option, ) -> BoxFragment { + let containing_block_writing_mode = containing_block.style.writing_mode; let ContainingBlockPaddingAndBorder { containing_block: containing_block_for_children, pbm, @@ -815,6 +826,8 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( match sequential_layout_state { None => parent_containing_block_position_info = None, Some(ref mut sequential_layout_state) => { + let clear = + Clear::from_style_and_container_writing_mode(style, containing_block_writing_mode); let mut block_start_margin = CollapsedMargin::new(margin.block_start); // The block start margin may collapse with content margins, @@ -831,7 +844,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( let collapsible_with_parent_start_margin = collapsible_with_parent_start_margin.expect( "We should know whether we are collapsing the block start margin with the parent \ when laying out sequentially", - ).0 && style.get_box().clear == Clear::None; + ).0 && clear == Clear::None; if !collapsible_with_parent_start_margin && start_margin_can_collapse_with_children { if let BlockContainer::BlockLevelBoxes(child_boxes) = contents { BlockLevelBox::find_block_margin_collapsing_with_parent_from_slice( @@ -843,8 +856,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( } // Introduce clearance if necessary. - clearance = sequential_layout_state - .calculate_clearance(style.get_box().clear, &block_start_margin); + clearance = sequential_layout_state.calculate_clearance(clear, &block_start_margin); if clearance.is_some() { sequential_layout_state.collapse_margins(); } @@ -974,7 +986,6 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( }, }; - let containing_block_writing_mode = containing_block.style.writing_mode; if depends_on_block_constraints { base_fragment_info .flags @@ -1098,6 +1109,7 @@ impl NonReplacedFormattingContext { containing_block: &ContainingBlock<'_>, sequential_layout_state: &mut SequentialLayoutState, ) -> BoxFragment { + let containing_block_writing_mode = containing_block.style.writing_mode; let ContentBoxSizesAndPBMDeprecated { content_box_size, content_min_box_size, @@ -1183,7 +1195,10 @@ impl NonReplacedFormattingContext { // The code below may then add extra clearance when the element can't fit // next to floats not covered by 'clear'. let clear_position = sequential_layout_state.calculate_clear_position( - self.style.get_box().clear, + Clear::from_style_and_container_writing_mode( + &self.style, + containing_block_writing_mode, + ), &collapsed_margin_block_start, ); let ceiling = clear_position.unwrap_or_else(|| { @@ -1339,7 +1354,6 @@ impl NonReplacedFormattingContext { ); } - let containing_block_writing_mode = containing_block.style.writing_mode; BoxFragment::new( base_fragment_info, self.style.clone(), @@ -1733,7 +1747,10 @@ fn solve_clearance_and_inline_margins_avoiding_floats( ) -> (Option, (Au, Au), Au) { let (clearance, placement_rect) = sequential_layout_state .calculate_clearance_and_inline_adjustment( - style.get_box().clear, + Clear::from_style_and_container_writing_mode( + style, + containing_block.style.writing_mode, + ), block_start_margin, pbm, size, diff --git a/components/layout_2020/tests/floats.rs b/components/layout_2020/tests/floats.rs index 3a9b755eac611..a90d7effb19c1 100644 --- a/components/layout_2020/tests/floats.rs +++ b/components/layout_2020/tests/floats.rs @@ -13,12 +13,11 @@ use std::{thread, u32}; use app_units::Au; use euclid::num::Zero; use layout_2020::flow::float::{ - ContainingBlockPositionInfo, FloatBand, FloatBandNode, FloatBandTree, FloatContext, FloatSide, - PlacementInfo, + Clear, ContainingBlockPositionInfo, FloatBand, FloatBandNode, FloatBandTree, FloatContext, + FloatSide, PlacementInfo, }; use layout_2020::geom::{LogicalRect, LogicalVec2}; use quickcheck::{Arbitrary, Gen}; -use style::values::computed::Clear; static PANIC_HOOK_MUTEX: Mutex<()> = Mutex::new(()); @@ -421,8 +420,8 @@ impl Arbitrary for FloatInput { fn new_clear(value: u8) -> Clear { match value & 3 { 0 => Clear::None, - 1 => Clear::Left, - 2 => Clear::Right, + 1 => Clear::InlineStart, + 2 => Clear::InlineEnd, _ => Clear::Both, } } @@ -739,8 +738,8 @@ fn check_floats_rule_10(placement: &FloatPlacement) { } match this_float.info.clear { - Clear::Left => assert_ne!(other_float.info.side, FloatSide::InlineStart), - Clear::Right => assert_ne!(other_float.info.side, FloatSide::InlineEnd), + Clear::InlineStart => assert_ne!(other_float.info.side, FloatSide::InlineStart), + Clear::InlineEnd => assert_ne!(other_float.info.side, FloatSide::InlineEnd), Clear::Both => assert!(false), Clear::None => unreachable!(), } diff --git a/tests/wpt/meta/css/css-box/parsing/clear-computed.html.ini b/tests/wpt/meta/css/css-box/parsing/clear-computed.html.ini deleted file mode 100644 index 8e72ee8f2a28c..0000000000000 --- a/tests/wpt/meta/css/css-box/parsing/clear-computed.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[clear-computed.html] - [Property clear value 'inline-start'] - expected: FAIL - - [Property clear value 'inline-end'] - expected: FAIL diff --git a/tests/wpt/meta/css/css-box/parsing/float-computed.html.ini b/tests/wpt/meta/css/css-box/parsing/float-computed.html.ini deleted file mode 100644 index 3e7c0a24b573e..0000000000000 --- a/tests/wpt/meta/css/css-box/parsing/float-computed.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[float-computed.html] - [Property float value 'inline-start'] - expected: FAIL - - [Property float value 'inline-end'] - expected: FAIL diff --git a/tests/wpt/meta/css/css-logical/logical-values-float-clear-reftest.html.ini b/tests/wpt/meta/css/css-logical/logical-values-float-clear-reftest.html.ini deleted file mode 100644 index 626ab3427a507..0000000000000 --- a/tests/wpt/meta/css/css-logical/logical-values-float-clear-reftest.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[logical-values-float-clear-reftest.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-logical/logical-values-float-clear.html.ini b/tests/wpt/meta/css/css-logical/logical-values-float-clear.html.ini deleted file mode 100644 index a8045bfd3eba5..0000000000000 --- a/tests/wpt/meta/css/css-logical/logical-values-float-clear.html.ini +++ /dev/null @@ -1,12 +0,0 @@ -[logical-values-float-clear.html] - [Test that 'clear: inline-start' is supported.] - expected: FAIL - - [Test that 'clear: inline-end' is supported.] - expected: FAIL - - [Test that 'float: inline-start' is supported.] - expected: FAIL - - [Test that 'float: inline-end' is supported.] - expected: FAIL