mirror of
https://github.com/servo/servo.git
synced 2025-08-26 15:48:22 +01:00
Switch z-index to use predefined integer type
This commit is contained in:
parent
b489c4ed90
commit
9233882d49
4 changed files with 17 additions and 78 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Self, ()> {
|
||||
match (*self, *other) {
|
||||
(ZIndex::Number(ref this),
|
||||
ZIndex::Number(ref other)) => {
|
||||
this.interpolate(other, progress).map(ZIndex::Number)
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Interpolate + Copy> Interpolate for Size2D<T> {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
|
|
|
@ -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<W>(&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<SpecifiedValue, ()> {
|
||||
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:longhand>
|
||||
${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/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue