diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index f7da86f85a1..6eb8ac6ecae 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -23,6 +23,7 @@ use style::logical_geometry::LogicalSize; use style::properties::ComputedValues; use style::values::Either; use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; +use style::values::generics::column::ColumnCount; #[allow(unsafe_code)] unsafe impl ::flow::HasBaseFlow for MulticolFlow {} @@ -115,12 +116,12 @@ impl Flow for MulticolFlow { let column_width = Au::from(column_width); column_count = max(1, (content_inline_size + column_gap).0 / (column_width + column_gap).0); - if let Either::First(specified_column_count) = column_style.column_count { + if let ColumnCount::Integer(specified_column_count) = column_style.column_count { column_count = min(column_count, specified_column_count.0 as i32); } } else { column_count = match column_style.column_count { - Either::First(n) => n.0, + ColumnCount::Integer(n) => n.0, _ => unreachable!(), } } diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 419377ea01d..e2c68964cb0 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -254,6 +254,7 @@ class Longhand(object): "BackgroundRepeat", "BorderImageRepeat", "BorderStyle", + "ColumnCount", "Contain", "FontStyleAdjust", "FontSynthesis", @@ -274,7 +275,6 @@ class Longhand(object): "OutlineStyle", "OverscrollBehavior", "Percentage", - "PositiveIntegerOrAuto", "SVGPaintOrder", "ScrollSnapType", "TextDecorationLine", diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index aea141323ce..3ce1ab001f0 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -57,11 +57,12 @@ use selector_parser::PseudoElement; use servo_arc::{Arc, RawOffsetArc}; use std::mem::{forget, uninitialized, transmute, zeroed}; use std::{cmp, ops, ptr}; -use values::{self, Auto, CustomIdent, Either, KeyframesName, None_}; +use values::{self, CustomIdent, Either, KeyframesName, None_}; use values::computed::{NonNegativeLength, ToComputedValue, Percentage}; use values::computed::font::{FontSize, SingleFontFamily}; use values::computed::effects::{BoxShadow, Filter, SimpleShadow}; use values::computed::outline::OutlineStyle; +use values::generics::column::ColumnCount; use values::generics::position::ZIndex; use values::generics::transform::TransformStyle; use computed_values::border_style; @@ -5399,10 +5400,10 @@ clip-path use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount}; self.gecko.mColumnCount = match v { - Either::First(integer) => unsafe { - cmp::min(integer.0 as u32, nsStyleColumn_kMaxColumnCount) + ColumnCount::Integer(integer) => { + cmp::min(integer.0 as u32, unsafe { nsStyleColumn_kMaxColumnCount }) }, - Either::Second(Auto) => NS_STYLE_COLUMN_COUNT_AUTO + ColumnCount::Auto => NS_STYLE_COLUMN_COUNT_AUTO }; } @@ -5413,9 +5414,9 @@ clip-path if self.gecko.mColumnCount != NS_STYLE_COLUMN_COUNT_AUTO { debug_assert!(self.gecko.mColumnCount >= 1 && self.gecko.mColumnCount <= nsStyleColumn_kMaxColumnCount); - Either::First((self.gecko.mColumnCount as i32).into()) + ColumnCount::Integer((self.gecko.mColumnCount as i32).into()) } else { - Either::Second(Auto) + ColumnCount::Auto } } diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs index 68fcb2edc83..77ede60f28e 100644 --- a/components/style/properties/longhand/column.mako.rs +++ b/components/style/properties/longhand/column.mako.rs @@ -17,15 +17,17 @@ ${helpers.predefined_type("column-width", servo_restyle_damage="rebuild_and_reflow")} -${helpers.predefined_type("column-count", - "PositiveIntegerOrAuto", - "Either::Second(Auto)", - initial_specified_value="Either::Second(Auto)", - servo_pref="layout.column-count.enabled", - animation_value_type="PositiveIntegerOrAuto", - extra_prefixes="moz", - spec="https://drafts.csswg.org/css-multicol/#propdef-column-count", - servo_restyle_damage="rebuild_and_reflow")} +${helpers.predefined_type( + "column-count", + "ColumnCount", + "computed::ColumnCount::auto()", + initial_specified_value="specified::ColumnCount::auto()", + servo_pref="layout.column-count.enabled", + animation_value_type="AnimatedColumnCount", + extra_prefixes="moz", + spec="https://drafts.csswg.org/css-multicol/#propdef-column-count", + servo_restyle_damage="rebuild_and_reflow", +)} ${helpers.predefined_type("column-gap", "length::NonNegativeLengthOrNormal", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 6ae1bead5ee..d3b6687b5e3 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2292,10 +2292,7 @@ pub mod style_structs { pub fn is_multicol(&self) -> bool { match self.column_width { Either::First(_width) => true, - Either::Second(_auto) => match self.column_count { - Either::First(_n) => true, - Either::Second(_auto) => false, - } + Either::Second(_auto) => !self.column_count.is_auto(), } } % endif diff --git a/components/style/values/computed/column.rs b/components/style/values/computed/column.rs new file mode 100644 index 00000000000..6e283fb1bac --- /dev/null +++ b/components/style/values/computed/column.rs @@ -0,0 +1,11 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Computed types for the column properties. + +use values::computed::PositiveInteger; +use values::generics::column::ColumnCount as GenericColumnCount; + +/// A computed type for `column-count` values. +pub type ColumnCount = GenericColumnCount; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index c67ae7aea98..36d70e7ea3e 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -50,6 +50,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain}; pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; +pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; @@ -91,6 +92,7 @@ pub mod border; #[path = "box.rs"] pub mod box_; pub mod color; +pub mod column; pub mod counters; pub mod effects; pub mod flex; @@ -548,9 +550,6 @@ impl From for PositiveInteger { } } -/// PositiveInteger | auto -pub type PositiveIntegerOrAuto = Either; - /// | | pub type LengthOrPercentageOrNumber = Either; diff --git a/components/style/values/generics/column.rs b/components/style/values/generics/column.rs new file mode 100644 index 00000000000..212eb28b110 --- /dev/null +++ b/components/style/values/generics/column.rs @@ -0,0 +1,29 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Generic types for the column properties. + +/// A generic type for `column-count` values. +#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] +#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] +pub enum ColumnCount { + /// A positive integer. + Integer(PositiveInteger), + /// The keyword `auto`. + Auto, +} + +impl ColumnCount { + /// Returns `auto`. + #[inline] + pub fn auto() -> Self { + ColumnCount::Auto + } + + /// Returns whether this value is `auto`. + #[inline] + pub fn is_auto(self) -> bool { + matches!(self, ColumnCount::Auto) + } +} diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 682736f8013..a69d51da0ba 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -16,6 +16,7 @@ pub mod basic_shape; pub mod border; #[path = "box.rs"] pub mod box_; +pub mod column; pub mod counters; pub mod effects; pub mod flex; diff --git a/components/style/values/specified/column.rs b/components/style/values/specified/column.rs new file mode 100644 index 00000000000..738e6637768 --- /dev/null +++ b/components/style/values/specified/column.rs @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Specified types for the column properties. + +use cssparser::Parser; +use parser::{Parse, ParserContext}; +use style_traits::ParseError; +use values::generics::column::ColumnCount as GenericColumnCount; +use values::specified::PositiveInteger; + +/// A specified type for `column-count` values. +pub type ColumnCount = GenericColumnCount; + +impl Parse for ColumnCount { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + return Ok(GenericColumnCount::Auto); + } + Ok(GenericColumnCount::Integer(PositiveInteger::parse(context, input)?)) + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 9b728dbe585..b0c0c1cffba 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -34,6 +34,7 @@ pub use self::align::{AlignSelf, JustifySelf}; pub use self::background::{BackgroundRepeat, BackgroundSize}; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing}; +pub use self::column::ColumnCount; pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates}; pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian}; pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings}; @@ -88,6 +89,7 @@ pub mod border; pub mod box_; pub mod calc; pub mod color; +pub mod column; pub mod counters; pub mod effects; pub mod flex; @@ -529,9 +531,6 @@ impl Parse for PositiveInteger { } } -/// PositiveInteger | auto -pub type PositiveIntegerOrAuto = Either; - #[allow(missing_docs)] pub type UrlOrNone = Either;