Replace PositiveIntegerOrAuto by ColumnCount

It was its only use.
This commit is contained in:
Anthony Ramine 2018-02-22 10:16:46 +01:00
parent 363aae6a43
commit 761689f32d
11 changed files with 94 additions and 28 deletions

View file

@ -23,6 +23,7 @@ use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::Either; use style::values::Either;
use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use style::values::generics::column::ColumnCount;
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe impl ::flow::HasBaseFlow for MulticolFlow {} unsafe impl ::flow::HasBaseFlow for MulticolFlow {}
@ -115,12 +116,12 @@ impl Flow for MulticolFlow {
let column_width = Au::from(column_width); let column_width = Au::from(column_width);
column_count = column_count =
max(1, (content_inline_size + column_gap).0 / (column_width + column_gap).0); 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); column_count = min(column_count, specified_column_count.0 as i32);
} }
} else { } else {
column_count = match column_style.column_count { column_count = match column_style.column_count {
Either::First(n) => n.0, ColumnCount::Integer(n) => n.0,
_ => unreachable!(), _ => unreachable!(),
} }
} }

View file

@ -254,6 +254,7 @@ class Longhand(object):
"BackgroundRepeat", "BackgroundRepeat",
"BorderImageRepeat", "BorderImageRepeat",
"BorderStyle", "BorderStyle",
"ColumnCount",
"Contain", "Contain",
"FontStyleAdjust", "FontStyleAdjust",
"FontSynthesis", "FontSynthesis",
@ -274,7 +275,6 @@ class Longhand(object):
"OutlineStyle", "OutlineStyle",
"OverscrollBehavior", "OverscrollBehavior",
"Percentage", "Percentage",
"PositiveIntegerOrAuto",
"SVGPaintOrder", "SVGPaintOrder",
"ScrollSnapType", "ScrollSnapType",
"TextDecorationLine", "TextDecorationLine",

View file

@ -57,11 +57,12 @@ use selector_parser::PseudoElement;
use servo_arc::{Arc, RawOffsetArc}; use servo_arc::{Arc, RawOffsetArc};
use std::mem::{forget, uninitialized, transmute, zeroed}; use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr}; 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::{NonNegativeLength, ToComputedValue, Percentage};
use values::computed::font::{FontSize, SingleFontFamily}; use values::computed::font::{FontSize, SingleFontFamily};
use values::computed::effects::{BoxShadow, Filter, SimpleShadow}; use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
use values::computed::outline::OutlineStyle; use values::computed::outline::OutlineStyle;
use values::generics::column::ColumnCount;
use values::generics::position::ZIndex; use values::generics::position::ZIndex;
use values::generics::transform::TransformStyle; use values::generics::transform::TransformStyle;
use computed_values::border_style; use computed_values::border_style;
@ -5399,10 +5400,10 @@ clip-path
use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount}; use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount};
self.gecko.mColumnCount = match v { self.gecko.mColumnCount = match v {
Either::First(integer) => unsafe { ColumnCount::Integer(integer) => {
cmp::min(integer.0 as u32, nsStyleColumn_kMaxColumnCount) 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 { if self.gecko.mColumnCount != NS_STYLE_COLUMN_COUNT_AUTO {
debug_assert!(self.gecko.mColumnCount >= 1 && debug_assert!(self.gecko.mColumnCount >= 1 &&
self.gecko.mColumnCount <= nsStyleColumn_kMaxColumnCount); self.gecko.mColumnCount <= nsStyleColumn_kMaxColumnCount);
Either::First((self.gecko.mColumnCount as i32).into()) ColumnCount::Integer((self.gecko.mColumnCount as i32).into())
} else { } else {
Either::Second(Auto) ColumnCount::Auto
} }
} }

View file

@ -17,15 +17,17 @@ ${helpers.predefined_type("column-width",
servo_restyle_damage="rebuild_and_reflow")} servo_restyle_damage="rebuild_and_reflow")}
${helpers.predefined_type("column-count", ${helpers.predefined_type(
"PositiveIntegerOrAuto", "column-count",
"Either::Second(Auto)", "ColumnCount",
initial_specified_value="Either::Second(Auto)", "computed::ColumnCount::auto()",
initial_specified_value="specified::ColumnCount::auto()",
servo_pref="layout.column-count.enabled", servo_pref="layout.column-count.enabled",
animation_value_type="PositiveIntegerOrAuto", animation_value_type="AnimatedColumnCount",
extra_prefixes="moz", extra_prefixes="moz",
spec="https://drafts.csswg.org/css-multicol/#propdef-column-count", spec="https://drafts.csswg.org/css-multicol/#propdef-column-count",
servo_restyle_damage="rebuild_and_reflow")} servo_restyle_damage="rebuild_and_reflow",
)}
${helpers.predefined_type("column-gap", ${helpers.predefined_type("column-gap",
"length::NonNegativeLengthOrNormal", "length::NonNegativeLengthOrNormal",

View file

@ -2292,10 +2292,7 @@ pub mod style_structs {
pub fn is_multicol(&self) -> bool { pub fn is_multicol(&self) -> bool {
match self.column_width { match self.column_width {
Either::First(_width) => true, Either::First(_width) => true,
Either::Second(_auto) => match self.column_count { Either::Second(_auto) => !self.column_count.is_auto(),
Either::First(_n) => true,
Either::Second(_auto) => false,
}
} }
} }
% endif % endif

View file

@ -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<PositiveInteger>;

View file

@ -50,6 +50,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier,
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain}; pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange}; pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset}; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::effects::{BoxShadow, Filter, SimpleShadow};
pub use self::flex::FlexBasis; pub use self::flex::FlexBasis;
@ -91,6 +92,7 @@ pub mod border;
#[path = "box.rs"] #[path = "box.rs"]
pub mod box_; pub mod box_;
pub mod color; pub mod color;
pub mod column;
pub mod counters; pub mod counters;
pub mod effects; pub mod effects;
pub mod flex; pub mod flex;
@ -548,9 +550,6 @@ impl From<CSSInteger> for PositiveInteger {
} }
} }
/// PositiveInteger | auto
pub type PositiveIntegerOrAuto = Either<PositiveInteger, Auto>;
/// <length> | <percentage> | <number> /// <length> | <percentage> | <number>
pub type LengthOrPercentageOrNumber = Either<Number, LengthOrPercentage>; pub type LengthOrPercentageOrNumber = Either<Number, LengthOrPercentage>;

View file

@ -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<PositiveInteger> {
/// A positive integer.
Integer(PositiveInteger),
/// The keyword `auto`.
Auto,
}
impl<I> ColumnCount<I> {
/// 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)
}
}

View file

@ -16,6 +16,7 @@ pub mod basic_shape;
pub mod border; pub mod border;
#[path = "box.rs"] #[path = "box.rs"]
pub mod box_; pub mod box_;
pub mod column;
pub mod counters; pub mod counters;
pub mod effects; pub mod effects;
pub mod flex; pub mod flex;

View file

@ -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<PositiveInteger>;
impl Parse for ColumnCount {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericColumnCount::Auto);
}
Ok(GenericColumnCount::Integer(PositiveInteger::parse(context, input)?))
}
}

View file

@ -34,6 +34,7 @@ pub use self::align::{AlignSelf, JustifySelf};
pub use self::background::{BackgroundRepeat, BackgroundSize}; pub use self::background::{BackgroundRepeat, BackgroundSize};
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing}; 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::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian}; pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings}; pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
@ -88,6 +89,7 @@ pub mod border;
pub mod box_; pub mod box_;
pub mod calc; pub mod calc;
pub mod color; pub mod color;
pub mod column;
pub mod counters; pub mod counters;
pub mod effects; pub mod effects;
pub mod flex; pub mod flex;
@ -529,9 +531,6 @@ impl Parse for PositiveInteger {
} }
} }
/// PositiveInteger | auto
pub type PositiveIntegerOrAuto = Either<PositiveInteger, Auto>;
#[allow(missing_docs)] #[allow(missing_docs)]
pub type UrlOrNone = Either<SpecifiedUrl, None_>; pub type UrlOrNone = Either<SpecifiedUrl, None_>;