From 1583bd4cd609c0efcf64a6c16a93494c3bdd2e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Thu, 31 Aug 2017 23:18:23 -0500 Subject: [PATCH] servo: Merge #18321 - Properly set default direction of prefixed linear gradients (from canaltinova:default-linear-gradient); r=Manishearth The default linear gradient direction is `to bottom`. This correspondes to `top` keyword in prefixed linear gradients. We should preserve the default value. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix [Bug 1395189](https://bugzilla.mozilla.org/show_bug.cgi?id=1395189) Source-Repo: https://github.com/servo/servo Source-Revision: ff30f582a02133074a92786af256d09325bc9d22 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 60e2b459cad478cb42599b46db4a7aa944bbb411 --- servo/components/style/values/computed/image.rs | 7 +++++-- servo/components/style/values/generics/image.rs | 5 +++-- servo/components/style/values/specified/image.rs | 12 +++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/servo/components/style/values/computed/image.rs b/servo/components/style/values/computed/image.rs index 952e213ccb90..998216837449 100644 --- a/servo/components/style/values/computed/image.rs +++ b/servo/components/style/values/computed/image.rs @@ -78,10 +78,13 @@ pub type ColorStop = GenericColorStop; pub type MozImageRect = GenericMozImageRect; impl GenericLineDirection for LineDirection { - fn points_downwards(&self) -> bool { + fn points_downwards(&self, compat_mode: CompatMode) -> bool { match *self { LineDirection::Angle(angle) => angle.radians() == PI, - LineDirection::Vertical(Y::Bottom) => true, + 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, diff --git a/servo/components/style/values/generics/image.rs b/servo/components/style/values/generics/image.rs index b9c5a036697c..9c58569dd0bb 100644 --- a/servo/components/style/values/generics/image.rs +++ b/servo/components/style/values/generics/image.rs @@ -230,7 +230,8 @@ impl ToCss for Gradient dest.write_str(self.kind.label())?; dest.write_str("-gradient(")?; let mut skip_comma = match self.kind { - GradientKind::Linear(ref direction) if direction.points_downwards() => true, + GradientKind::Linear(ref direction) + if direction.points_downwards(self.compat_mode) => true, GradientKind::Linear(ref direction) => { direction.to_css(dest, self.compat_mode)?; false @@ -287,7 +288,7 @@ impl GradientKind { /// The direction of a linear gradient. pub trait LineDirection { /// Whether this direction points towards, and thus can be omitted. - fn points_downwards(&self) -> bool; + fn points_downwards(&self, compat_mode: CompatMode) -> bool; /// Serialises this direction according to the compatibility mode. fn to_css(&self, dest: &mut W, compat_mode: CompatMode) -> fmt::Result diff --git a/servo/components/style/values/specified/image.rs b/servo/components/style/values/specified/image.rs index 7caf67cf472f..a0d1b2260b92 100644 --- a/servo/components/style/values/specified/image.rs +++ b/servo/components/style/values/specified/image.rs @@ -526,7 +526,10 @@ impl GradientKind { input.expect_comma()?; d } else { - LineDirection::Vertical(Y::Bottom) + match *compat_mode { + CompatMode::Modern => LineDirection::Vertical(Y::Bottom), + _ => LineDirection::Vertical(Y::Top), + } }; Ok(GenericGradientKind::Linear(direction)) } @@ -615,10 +618,13 @@ impl GradientKind { } impl GenericsLineDirection for LineDirection { - fn points_downwards(&self) -> bool { + fn points_downwards(&self, compat_mode: CompatMode) -> bool { match *self { LineDirection::Angle(ref angle) => angle.radians() == PI, - LineDirection::Vertical(Y::Bottom) => true, + LineDirection::Vertical(Y::Bottom) + if compat_mode == CompatMode::Modern => true, + LineDirection::Vertical(Y::Top) + if compat_mode != CompatMode::Modern => true, _ => false, } }