aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-02-26 15:46:41 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2018-02-26 22:32:06 +0100
commit260e05320c7bad593ff8d98b2bcb7ca2b4b775ac (patch)
tree1337d305311c4ab3f2defb31d7fcc6f4ea49c5d4
parent4a98fa70bf42653249daffc086a0bda16175c42e (diff)
downloadservo-260e05320c7bad593ff8d98b2bcb7ca2b4b775ac.tar.gz
servo-260e05320c7bad593ff8d98b2bcb7ca2b4b775ac.zip
Replace LengthOrNone by a specific type for the perspective property
This was its only use, and it was bugged: AFAIK this didn't properly clamp animated values below 0.
-rw-r--r--components/layout/fragment.rs9
-rw-r--r--components/style/gecko/values.rs22
-rw-r--r--components/style/properties/gecko.mako.rs2
-rw-r--r--components/style/properties/longhand/box.mako.rs21
-rw-r--r--components/style/values/computed/box.rs6
-rw-r--r--components/style/values/computed/length.rs5
-rw-r--r--components/style/values/computed/mod.rs7
-rw-r--r--components/style/values/generics/box.rs18
-rw-r--r--components/style/values/specified/box.rs18
-rw-r--r--components/style/values/specified/length.rs5
-rw-r--r--components/style/values/specified/mod.rs7
11 files changed, 88 insertions, 32 deletions
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs
index 48764b625df..68d5c7f6199 100644
--- a/components/layout/fragment.rs
+++ b/components/layout/fragment.rs
@@ -59,10 +59,9 @@ use style::properties::ComputedValues;
use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace;
-use style::values::{self, Either};
use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::counters::ContentItem;
-use style::values::generics::box_::VerticalAlign;
+use style::values::generics::box_::{Perspective, VerticalAlign};
use style::values::generics::transform;
use text;
use text::TextRunScanner;
@@ -2477,7 +2476,7 @@ impl Fragment {
pub fn has_filter_transform_or_perspective(&self) -> bool {
!self.style().get_box().transform.0.is_empty() ||
!self.style().get_effects().filter.0.is_empty() ||
- self.style().get_box().perspective != Either::Second(values::None_)
+ self.style().get_box().perspective != Perspective::None
}
/// Returns true if this fragment establishes a new stacking context and false otherwise.
@@ -2899,7 +2898,7 @@ impl Fragment {
/// Returns the 4D matrix representing this fragment's perspective.
pub fn perspective_matrix(&self, stacking_relative_border_box: &Rect<Au>) -> Option<LayoutTransform> {
match self.style().get_box().perspective {
- Either::First(length) => {
+ Perspective::Length(length) => {
let perspective_origin = self.style().get_box().perspective_origin;
let perspective_origin =
Point2D::new(
@@ -2923,7 +2922,7 @@ impl Fragment {
Some(pre_transform.pre_mul(&perspective_matrix).pre_mul(&post_transform))
}
- Either::Second(values::None_) => {
+ Perspective::None => {
None
}
}
diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs
index 0695f1e5144..322fcdf2d1b 100644
--- a/components/style/gecko/values.rs
+++ b/components/style/gecko/values.rs
@@ -24,6 +24,7 @@ use values::computed::{NonNegativeLength, NonNegativeLengthOrPercentage, NonNega
use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use values::generics::{CounterStyleOrNone, NonNegative};
use values::generics::basic_shape::ShapeRadius;
+use values::generics::box_::Perspective;
use values::generics::gecko::ScrollSnapPoint;
use values::generics::grid::{TrackBreadth, TrackKeyword};
@@ -422,6 +423,27 @@ impl GeckoStyleCoordConvertible for ScrollSnapPoint<LengthOrPercentage> {
}
}
+impl<L> GeckoStyleCoordConvertible for Perspective<L>
+where
+ L: GeckoStyleCoordConvertible,
+{
+ fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
+ match *self {
+ Perspective::None => coord.set_value(CoordDataValue::None),
+ Perspective::Length(ref l) => l.to_gecko_style_coord(coord),
+ };
+ }
+
+ fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
+ use gecko_bindings::structs::root::nsStyleUnit;
+
+ if coord.unit() == nsStyleUnit::eStyleUnit_None {
+ return Some(Perspective::None);
+ }
+ Some(Perspective::Length(L::from_gecko_style_coord(coord)?))
+ }
+}
+
/// Convert a given RGBA value to `nscolor`.
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
((rgba.alpha as u32) << 24) |
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 481ea4e9222..ca96e3fcb13 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -1455,7 +1455,6 @@ impl Clone for ${style_struct.gecko_struct_name} {
"length::NonNegativeLengthOrAuto": impl_style_coord,
"length::NonNegativeLengthOrNormal": impl_style_coord,
"Length": impl_absolute_length,
- "LengthOrNone": impl_style_coord,
"LengthOrNormal": impl_style_coord,
"LengthOrPercentage": impl_style_coord,
"LengthOrPercentageOrAuto": impl_style_coord,
@@ -1468,6 +1467,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
"NonNegativeNumber": impl_simple,
"Number": impl_simple,
"Opacity": impl_simple,
+ "Perspective": impl_style_coord,
"Position": impl_position,
"RGBAColor": impl_rgba_color,
"SVGLength": impl_svg_length,
diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs
index daf2abd0abe..62bc86e856d 100644
--- a/components/style/properties/longhand/box.mako.rs
+++ b/components/style/properties/longhand/box.mako.rs
@@ -507,16 +507,17 @@ ${helpers.single_keyword("resize",
flags="APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete")}
-
-${helpers.predefined_type("perspective",
- "LengthOrNone",
- "Either::Second(None_)",
- gecko_ffi_name="mChildPerspective",
- spec="https://drafts.csswg.org/css-transforms/#perspective",
- extra_prefixes="moz webkit",
- flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
- animation_value_type="ComputedValue",
- servo_restyle_damage = "reflow_out_of_flow")}
+${helpers.predefined_type(
+ "perspective",
+ "Perspective",
+ "computed::Perspective::none()",
+ gecko_ffi_name="mChildPerspective",
+ spec="https://drafts.csswg.org/css-transforms/#perspective",
+ extra_prefixes="moz webkit",
+ flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
+ animation_value_type="AnimatedPerspective",
+ servo_restyle_damage = "reflow_out_of_flow",
+)}
${helpers.predefined_type("perspective-origin",
"position::Position",
diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs
index eeeede9c33a..72d309b707f 100644
--- a/components/style/values/computed/box.rs
+++ b/components/style/values/computed/box.rs
@@ -5,8 +5,9 @@
//! Computed types for box properties.
use values::computed::Number;
-use values::computed::length::LengthOrPercentage;
+use values::computed::length::{LengthOrPercentage, NonNegativeLength};
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
+use values::generics::box_::Perspective as GenericPerspective;
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
pub use values::specified::box_::{AnimationName, Display, OverflowClipBox, Contain};
@@ -25,3 +26,6 @@ impl AnimationIterationCount {
GenericAnimationIterationCount::Number(1.0)
}
}
+
+/// A computed value for the `perspective` property.
+pub type Perspective = GenericPerspective<NonNegativeLength>;
diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs
index 002e863f757..e52e01fbdc6 100644
--- a/components/style/values/computed/length.rs
+++ b/components/style/values/computed/length.rs
@@ -13,7 +13,7 @@ use std::ops::{Add, Neg};
use style_traits::{CssWriter, ToCss};
use style_traits::values::specified::AllowedNumericType;
use super::{Number, ToComputedValue, Context, Percentage};
-use values::{Auto, CSSFloat, Either, None_, Normal, specified};
+use values::{Auto, CSSFloat, Either, Normal, specified};
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::computed::NonNegativeNumber;
use values::distance::{ComputeSquaredDistance, SquaredDistance};
@@ -792,9 +792,6 @@ impl From<Au> for CSSPixelLength {
/// An alias of computed `<length>` value.
pub type Length = CSSPixelLength;
-/// Either a computed `<length>` or the `none` keyword.
-pub type LengthOrNone = Either<Length, None_>;
-
/// Either a computed `<length>` or the `auto` keyword.
pub type LengthOrAuto = Either<Length, Auto>;
diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs
index 36d70e7ea3e..542c3f5a7e1 100644
--- a/components/style/values/computed/mod.rs
+++ b/components/style/values/computed/mod.rs
@@ -47,8 +47,9 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
-pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
-pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
+pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
+pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
+pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
@@ -61,7 +62,7 @@ pub use self::gecko::ScrollSnapPoint;
pub use self::rect::LengthOrNumberRect;
pub use super::{Auto, Either, None_};
pub use super::specified::{BorderStyle, TextDecorationLine};
-pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
+pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage};
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength, NonNegativeLengthOrPercentage};
pub use self::list::{ListStyleImage, Quotes};
diff --git a/components/style/values/generics/box.rs b/components/style/values/generics/box.rs
index b9b09fd6534..224b8b44c97 100644
--- a/components/style/values/generics/box.rs
+++ b/components/style/values/generics/box.rs
@@ -55,3 +55,21 @@ pub enum AnimationIterationCount<Number> {
/// The `infinite` keyword.
Infinite,
}
+
+/// A generic value for the `perspective` property.
+#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
+#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
+pub enum Perspective<NonNegativeLength> {
+ /// A non-negative length.
+ Length(NonNegativeLength),
+ /// The keyword `none`.
+ None,
+}
+
+impl<L> Perspective<L> {
+ /// Returns `none`.
+ #[inline]
+ pub fn none() -> Self {
+ Perspective::None
+ }
+}
diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs
index 3bf64452072..731b0ee18d6 100644
--- a/components/style/values/specified/box.rs
+++ b/components/style/values/specified/box.rs
@@ -13,9 +13,10 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use values::CustomIdent;
use values::KeyframesName;
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
+use values::generics::box_::Perspective as GenericPerspective;
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
use values::specified::{AllowQuirks, Number};
-use values::specified::length::LengthOrPercentage;
+use values::specified::length::{LengthOrPercentage, NonNegativeLength};
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
@@ -588,3 +589,18 @@ impl Parse for Contain {
}
}
}
+
+/// A specified value for the `perspective` property.
+pub type Perspective = GenericPerspective<NonNegativeLength>;
+
+impl Parse for Perspective {
+ fn parse<'i, 't>(
+ context: &ParserContext,
+ input: &mut Parser<'i, 't>
+ ) -> Result<Self, ParseError<'i>> {
+ if input.try(|i| i.expect_ident_matching("none")).is_ok() {
+ return Ok(GenericPerspective::None);
+ }
+ Ok(GenericPerspective::Length(NonNegativeLength::parse(context, input)?))
+ }
+}
diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs
index aa2ac34e61e..3ed3b4f5d30 100644
--- a/components/style/values/specified/length.rs
+++ b/components/style/values/specified/length.rs
@@ -17,7 +17,7 @@ use std::ops::{Add, Mul};
use style_traits::{ParseError, StyleParseErrorKind};
use style_traits::values::specified::AllowedNumericType;
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
-use values::{Auto, CSSFloat, Either, None_, Normal};
+use values::{Auto, CSSFloat, Either, Normal};
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
use values::generics::NonNegative;
use values::specified::NonNegativeNumber;
@@ -1062,9 +1062,6 @@ impl NonNegativeLengthOrPercentage {
}
}
-/// Either a `<length>` or the `none` keyword.
-pub type LengthOrNone = Either<Length, None_>;
-
/// Either a `<length>` or the `normal` keyword.
pub type LengthOrNormal = Either<Length, Normal>;
diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs
index b0c0c1cffba..5177025efa3 100644
--- a/components/style/values/specified/mod.rs
+++ b/components/style/values/specified/mod.rs
@@ -39,8 +39,9 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
-pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
-pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
+pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
+pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
+pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
@@ -51,7 +52,7 @@ pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
pub use self::inherited_box::ImageOrientation;
pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
-pub use self::length::{FontRelativeLength, Length, LengthOrNone, LengthOrNumber};
+pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{NoCalcLength, ViewportPercentageLength};