diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 9e341d96d01..18cfe6409cb 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -106,11 +106,14 @@ impl Flow for MulticolFlow { if let Either::First(column_width) = column_style.column_width { column_count = max(1, (content_inline_size + column_gap).0 / (column_width + column_gap).0); - if let Some(specified_column_count) = column_style.column_count.0 { + if let Either::First(specified_column_count) = column_style.column_count { column_count = min(column_count, specified_column_count as i32); } } else { - column_count = column_style.column_count.0.unwrap() as i32; + column_count = match column_style.column_count { + Either::First(n) => n, + _ => unreachable!(), + } } column_width = max(Au(0), (content_inline_size + column_gap) / column_count - column_gap); diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 2d6de0e70f5..b72db38f91e 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -3189,11 +3189,11 @@ clip-path pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) { use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount}; - self.gecko.mColumnCount = match v.0 { - Some(number) => unsafe { - cmp::min(number, nsStyleColumn_kMaxColumnCount) + self.gecko.mColumnCount = match v { + Either::First(number) => unsafe { + cmp::min(number as u32, nsStyleColumn_kMaxColumnCount) }, - None => NS_STYLE_COLUMN_COUNT_AUTO + Either::Second(Auto) => NS_STYLE_COLUMN_COUNT_AUTO }; } diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs index abba0e78710..1b900a7f55d 100644 --- a/components/style/properties/longhand/column.mako.rs +++ b/components/style/properties/longhand/column.mako.rs @@ -19,90 +19,14 @@ ${helpers.predefined_type("column-width", // FIXME: This prop should be animatable. -<%helpers:longhand name="column-count" experimental="True" animatable="False" extra_prefixes="moz" - spec="https://drafts.csswg.org/css-multicol/#propdef-column-count"> - use std::fmt; - use style_traits::ToCss; - use values::HasViewportPercentage; - - no_viewport_percentage!(SpecifiedValue); - - #[derive(Debug, Clone, Copy, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub enum SpecifiedValue { - Auto, - Specified(u32), - } - - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - SpecifiedValue::Auto => dest.write_str("auto"), - SpecifiedValue::Specified(count) => write!(dest, "{}", count), - } - } - } - - pub mod computed_value { - #[derive(Debug, Clone, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct T(pub Option); - } - - impl ToCss for computed_value::T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match self.0 { - None => dest.write_str("auto"), - Some(count) => write!(dest, "{}", count), - } - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T(None) - } - - #[inline] - pub fn get_initial_specified_value() -> SpecifiedValue { - SpecifiedValue::Auto - } - - impl ToComputedValue for SpecifiedValue { - type ComputedValue = computed_value::T; - - #[inline] - fn to_computed_value(&self, _context: &Context) -> computed_value::T { - match *self { - SpecifiedValue::Auto => computed_value::T(None), - SpecifiedValue::Specified(count) => - computed_value::T(Some(count)) - } - } - - #[inline] - fn from_computed_value(computed: &computed_value::T) -> Self { - match *computed { - computed_value::T(None) => SpecifiedValue::Auto, - computed_value::T(Some(count)) => - SpecifiedValue::Specified(count) - } - } - } - - pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - if input.try(|input| input.expect_ident_matching("auto")).is_ok() { - Ok(SpecifiedValue::Auto) - } else { - let count = try!(specified::parse_integer(input)); - // Zero is invalid - if count <= 0 { - return Err(()) - } - Ok(SpecifiedValue::Specified(count as u32)) - } - } - +${helpers.predefined_type("column-count", "IntegerOrAuto", + "Either::Second(Auto)", + parse_method="parse_positive", + initial_specified_value="Either::Second(Auto)", + experimental="True", + animatable="False", + extra_prefixes="moz", + spec="https://drafts.csswg.org/css-multicol/#propdef-column-count")} // FIXME: This prop should be animatable. ${helpers.predefined_type("column-gap", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 5dca7bee0cc..24e0308489e 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1536,7 +1536,10 @@ impl ComputedValues { let style = self.get_column(); match style.column_width { Either::First(_width) => true, - Either::Second(_auto) => style.column_count.0.is_some(), + Either::Second(_auto) => match style.column_count { + Either::First(_n) => true, + Either::Second(_auto) => false, + } } } diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 1eb5b75feb8..3bf2102a7ed 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -557,13 +557,12 @@ mod shorthand_serialization { #[test] fn columns_should_serialize_correctly() { - use style::properties::longhands::column_count::SpecifiedValue as ColumnCount; use style::values::{Auto, Either}; let mut properties = Vec::new(); let width = Either::Second(Auto); - let count = ColumnCount::Auto; + let count = Either::Second(Auto); properties.push(PropertyDeclaration::ColumnWidth(width)); properties.push(PropertyDeclaration::ColumnCount(count));