From dfd12d78c69291c446d69b6824607d4b7c3a1178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Thu, 28 Sep 2017 22:26:25 +0300 Subject: [PATCH] stylo: Don't serialize default position on -moz- prefixed linear gradient 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. --- components/style/values/computed/image.rs | 10 ++++++++- components/style/values/specified/image.rs | 26 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index b2604324f76..ac46798c887 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -13,6 +13,8 @@ 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}; @@ -88,7 +90,13 @@ impl GenericLineDirection for LineDirection { 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) => { + // `50% 0%` is the default value for line direction. + x == 0.5 && y == 0.0 + }, _ => false, } } diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 77368acc2a6..406f4beee3b 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -626,6 +626,32 @@ impl GenericsLineDirection for LineDirection { 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) => { + use values::computed::Percentage as ComputedPercentage; + use values::specified::transform::OriginComponent; + + // `50% 0%` is the default value for line direction. + // These percentage values can also be keywords. + let x = match *x { + OriginComponent::Center => true, + OriginComponent::Length(LengthOrPercentage::Percentage(ComputedPercentage(val))) => { + val == 0.5 + }, + _ => false, + }; + let y = match *y { + OriginComponent::Side(Y::Top) => true, + OriginComponent::Length(LengthOrPercentage::Percentage(ComputedPercentage(val))) => { + val == 0.0 + }, + _ => false, + }; + x && y + }, _ => false, } }