Bug 1396102 - stylo: Don't serialize default position on -moz- prefixed linear gradient r?Manishearth draft
authorNazım Can Altınova <canaltinova@gmail.com>
Mon, 25 Sep 2017 22:09:04 +0300
changeset 670847 f57ae72fb453b7a4840c0223e1b2fa3e9685c044
parent 669742 5f3f19824efa14cc6db546baf59c54a0fc15ddc9
child 670848 5e6225fa854cb9333a8339b3010d359142e7d44b
push id81738
push userbmo:canaltinova@gmail.com
push dateTue, 26 Sep 2017 23:43:20 +0000
reviewersManishearth
bugs1396102
milestone58.0a1
Bug 1396102 - stylo: Don't serialize default position on -moz- prefixed linear gradient r?Manishearth Normally, we should not serialize if the line direction points downwards. Unprefixed and -webkit- prefixed syntaxes use only Keyword enum for line direction and we check them already. But -moz- prefixed linear gradients can store position too. Therefore it's stored inside `LineDirection::MozPosition` and we should check that for consistency between other gradients. MozReview-Commit-ID: 1Fs84uiKCu5
servo/components/style/values/computed/image.rs
servo/components/style/values/specified/image.rs
--- a/servo/components/style/values/computed/image.rs
+++ b/servo/components/style/values/computed/image.rs
@@ -8,16 +8,18 @@
 //! [image]: https://drafts.csswg.org/css-images/#image-values
 
 use cssparser::RGBA;
 use std::f32::consts::PI;
 use std::fmt;
 use style_traits::ToCss;
 use values::{Either, None_};
 use values::computed::{Angle, ComputedUrl, Context, Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue};
+#[cfg(feature = "gecko")]
+use values::computed::Percentage;
 use values::computed::position::Position;
 use values::generics::image::{CompatMode, ColorStop as GenericColorStop, EndingShape as GenericEndingShape};
 use values::generics::image::{Gradient as GenericGradient, GradientItem as GenericGradientItem};
 use values::generics::image::{Image as GenericImage, GradientKind as GenericGradientKind};
 use values::generics::image::{LineDirection as GenericLineDirection, MozImageRect as GenericMozImageRect};
 use values::specified::image::LineDirection as SpecifiedLineDirection;
 use values::specified::position::{X, Y};
 
@@ -73,27 +75,32 @@ pub type EndingShape = GenericEndingShap
 pub type GradientItem = GenericGradientItem<RGBA, LengthOrPercentage>;
 
 /// A computed color stop.
 pub type ColorStop = GenericColorStop<RGBA, LengthOrPercentage>;
 
 /// Computed values for `-moz-image-rect(...)`.
 pub type MozImageRect = GenericMozImageRect<NumberOrPercentage, ComputedUrl>;
 
+// TODO(canaltinova): Add a generic LineDirection and reduce these
+// multiple GenericLineDirection impls.
 impl GenericLineDirection for LineDirection {
     fn points_downwards(&self, compat_mode: CompatMode) -> bool {
         match *self {
             LineDirection::Angle(angle) => angle.radians() == PI,
             LineDirection::Vertical(Y::Bottom)
                 if compat_mode == CompatMode::Modern => true,
             LineDirection::Vertical(Y::Top)
                 if compat_mode != CompatMode::Modern => true,
             LineDirection::Corner(..) => false,
             #[cfg(feature = "gecko")]
-            LineDirection::MozPosition(_, _) => false,
+            LineDirection::MozPosition(Some(Position {
+                horizontal: LengthOrPercentage::Percentage(Percentage(x)),
+                vertical: LengthOrPercentage::Percentage(Percentage(y)),
+            }), None) if x == 0.5 && y == 0.0 => true,
             _ => false,
         }
     }
 
     fn to_css<W>(&self, dest: &mut W, compat_mode: CompatMode) -> fmt::Result
         where W: fmt::Write
     {
         match *self {
--- a/servo/components/style/values/specified/image.rs
+++ b/servo/components/style/values/specified/image.rs
@@ -15,27 +15,31 @@ use selectors::parser::SelectorParseErro
 #[cfg(feature = "servo")]
 use servo_url::ServoUrl;
 use std::cmp::Ordering;
 use std::f32::consts::PI;
 use std::fmt;
 use style_traits::{ToCss, ParseError, StyleParseError};
 use values::{Either, None_};
 #[cfg(feature = "gecko")]
-use values::computed::{Context, Position as ComputedPosition, ToComputedValue};
+use values::computed::{Context, Percentage as ComputedPercentage, Position as ComputedPosition};
+#[cfg(feature = "gecko")]
+use values::computed::ToComputedValue;
 use values::generics::image::{Circle, CompatMode, Ellipse, ColorStop as GenericColorStop};
 use values::generics::image::{EndingShape as GenericEndingShape, Gradient as GenericGradient};
 use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind};
 use values::generics::image::{Image as GenericImage, LineDirection as GenericsLineDirection};
 use values::generics::image::{MozImageRect as GenericMozImageRect, ShapeExtent};
 use values::generics::image::PaintWorklet;
 use values::generics::position::Position as GenericPosition;
 use values::specified::{Angle, Color, Length, LengthOrPercentage};
 use values::specified::{Number, NumberOrPercentage, Percentage, RGBAColor};
 use values::specified::position::{LegacyPosition, Position, PositionComponent, Side, X, Y};
+#[cfg(feature = "gecko")]
+use values::specified::transform::OriginComponent;
 use values::specified::url::SpecifiedUrl;
 
 /// A specified image layer.
 pub type ImageLayer = Either<None_, Image>;
 
 /// Specified values for an image according to CSS-IMAGES.
 /// https://drafts.csswg.org/css-images/#image-values
 pub type Image = GenericImage<Gradient, MozImageRect, SpecifiedUrl>;
@@ -621,16 +625,35 @@ impl GradientKind {
 impl GenericsLineDirection for LineDirection {
     fn points_downwards(&self, compat_mode: CompatMode) -> bool {
         match *self {
             LineDirection::Angle(ref angle) => angle.radians() == PI,
             LineDirection::Vertical(Y::Bottom)
                 if compat_mode == CompatMode::Modern => true,
             LineDirection::Vertical(Y::Top)
                 if compat_mode != CompatMode::Modern => true,
+            #[cfg(feature = "gecko")]
+            LineDirection::MozPosition(Some(LegacyPosition {
+                horizontal: ref x,
+                vertical: ref y,
+            }), None) => {
+                let x = match *x {
+                    OriginComponent::Center => true,
+                    OriginComponent::Length(LengthOrPercentage::Percentage(ComputedPercentage(val)))
+                     if val == 0.5 => true,
+                    _ => false,
+                };
+                let y = match *y {
+                    OriginComponent::Side(Y::Top) => true,
+                    OriginComponent::Length(LengthOrPercentage::Percentage(ComputedPercentage(val)))
+                     if val == 0.0 => true,
+                    _ => false,
+                };
+                x && y
+            },
             _ => false,
         }
     }
 
     fn to_css<W>(&self, dest: &mut W, compat_mode: CompatMode) -> fmt::Result
         where W: fmt::Write
     {
         match *self {