diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 1008c4f1a0b..51976521428 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -42,14 +42,14 @@ use std::sync::{Arc, Mutex}; use style::arc_ptr_eq; use style::computed_values::{border_collapse, box_sizing, clear, color, display, mix_blend_mode}; use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration_line, transform}; -use style::computed_values::{transform_style, vertical_align, white_space, word_break, z_index}; +use style::computed_values::{transform_style, vertical_align, white_space, word_break}; use style::computed_values::content::ContentItem; use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize, WritingMode}; use style::properties::ServoComputedValues; use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::RECONSTRUCT_FLOW; use style::str::char_is_whitespace; -use style::values::{self, Either}; +use style::values::{self, Either, Auto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use text; use text::TextRunScanner; @@ -2512,15 +2512,15 @@ impl Fragment { self.style().get_box().overflow_x, self.style().get_box().overflow_y.0) { (position::T::absolute, - z_index::T::Auto, + Either::Second(Auto), overflow_x::T::visible, overflow_x::T::visible) | (position::T::fixed, - z_index::T::Auto, + Either::Second(Auto), overflow_x::T::visible, overflow_x::T::visible) | (position::T::relative, - z_index::T::Auto, + Either::Second(Auto), overflow_x::T::visible, overflow_x::T::visible) => false, (position::T::absolute, _, _, _) | @@ -2536,15 +2536,15 @@ impl Fragment { pub fn effective_z_index(&self) -> i32 { match self.style().get_box().position { position::T::static_ => {}, - _ => return self.style().get_position().z_index.number_or_zero(), + _ => return self.style().get_position().z_index.integer_or(0), } if self.style().get_box().transform.0.is_some() { - return self.style().get_position().z_index.number_or_zero(); + return self.style().get_position().z_index.integer_or(0); } match self.style().get_box().display { - display::T::flex => self.style().get_position().z_index.number_or_zero(), + display::T::flex => self.style().get_position().z_index.integer_or(0), _ => 0, } } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index bce244dbd75..2d6de0e70f5 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -962,10 +962,9 @@ fn static_assert() { % endfor pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) { - use properties::longhands::z_index::computed_value::T; match v { - T::Auto => self.gecko.mZIndex.set_value(CoordDataValue::Auto), - T::Number(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)), + Either::First(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)), + Either::Second(Auto) => self.gecko.mZIndex.set_value(CoordDataValue::Auto), } } @@ -980,13 +979,12 @@ fn static_assert() { } pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T { - use properties::longhands::z_index::computed_value::T; return match self.gecko.mZIndex.as_value() { - CoordDataValue::Auto => T::Auto, - CoordDataValue::Integer(n) => T::Number(n), + CoordDataValue::Integer(n) => Either::First(n), + CoordDataValue::Auto => Either::Second(Auto), _ => { debug_assert!(false); - T::Number(0) + Either::First(0) } } } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index be4aa518fd8..86ad47dba32 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -22,7 +22,6 @@ use properties::longhands::transform::computed_value::ComputedOperation as Trans use properties::longhands::transform::computed_value::T as TransformList; use properties::longhands::vertical_align::computed_value::T as VerticalAlign; use properties::longhands::visibility::computed_value::T as Visibility; -use properties::longhands::z_index::computed_value::T as ZIndex; #[cfg(feature = "gecko")] use properties::{PropertyDeclarationId, LonghandId}; use std::cmp; use std::fmt; @@ -472,20 +471,6 @@ impl Interpolate for Visibility { } } -/// https://drafts.csswg.org/css-transitions/#animtype-integer -impl Interpolate for ZIndex { - #[inline] - fn interpolate(&self, other: &Self, progress: f64) -> Result { - match (*self, *other) { - (ZIndex::Number(ref this), - ZIndex::Number(ref other)) => { - this.interpolate(other, progress).map(ZIndex::Number) - } - _ => Err(()), - } - } -} - impl Interpolate for Size2D { #[inline] fn interpolate(&self, other: &Self, progress: f64) -> Result { diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index faf70897717..fad896f3359 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -23,54 +23,10 @@ animatable=True, logical=True)} % endfor -<%helpers:longhand name="z-index" spec="https://www.w3.org/TR/CSS2/visuren.html#z-index" animatable="True"> - use values::HasViewportPercentage; - use values::computed::ComputedValueAsSpecified; - - impl ComputedValueAsSpecified for SpecifiedValue {} - no_viewport_percentage!(SpecifiedValue); - pub type SpecifiedValue = computed_value::T; - pub mod computed_value { - use std::fmt; - use style_traits::ToCss; - - #[derive(PartialEq, Clone, Eq, Copy, Debug)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub enum T { - Auto, - Number(i32), - } - - impl ToCss for T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - T::Auto => dest.write_str("auto"), - T::Number(number) => write!(dest, "{}", number), - } - } - } - - impl T { - pub fn number_or_zero(self) -> i32 { - match self { - T::Auto => 0, - T::Number(value) => value, - } - } - } - } - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T::Auto - } - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - if input.try(|input| input.expect_ident_matching("auto")).is_ok() { - Ok(computed_value::T::Auto) - } else { - specified::parse_integer(input).map(computed_value::T::Number) - } - } - +${helpers.predefined_type("z-index", "IntegerOrAuto", + "Either::Second(Auto)", + spec="https://www.w3.org/TR/CSS2/visuren.html#z-index", + animatable="True")} // CSS Flexible Box Layout Module Level 1 // http://www.w3.org/TR/css3-flexbox/