Bug 1530826 - Fix computed value clamping. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 26 Feb 2019 23:34:25 +0000
changeset 519156 17d59b664c0fca195a1169c7a62f995480617d0a
parent 519155 279a75b5a6d42a41176750f113594139060d8924
child 519157 bb361d09129fac430e1a70d0108a7e15893e6b53
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1530826
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530826 - Fix computed value clamping. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D21268
layout/style/test/test_computed_style.html
servo/components/style/values/computed/length.rs
testing/web-platform/meta/css/css-shapes/parsing/shape-margin-computed.html.ini
--- a/layout/style/test/test_computed_style.html
+++ b/layout/style/test/test_computed_style.html
@@ -177,18 +177,17 @@ var noframe_container = document.getElem
     [ "calc(3px - 3px) 0", "0px 0px", "computed 0 calc with units horizontal" ],
     [ "0 calc(3px - 3px)", "0px 0px", "computed 0 calc with units vertical" ],
     [ "calc(0%) 0", "0% 0px", "0% calc horizontal"],
     [ "0 calc(0%)", "0px 0%", "0% calc vertical"],
     [ "calc(3px + 2% - 2%) 0", "calc(0% + 3px) 0px",
                       "computed 0% calc horizontal"],
     [ "0 calc(3px + 2% - 2%)", "0px calc(0% + 3px)",
                       "computed 0% calc vertical"],
-    [ "calc(3px - 5px) calc(6px - 9px)",
-      "calc(-2px) calc(-3px)", "negative pixel width" ],
+    [ "calc(3px - 5px) calc(6px - 9px)", "0px 0px", "negative pixel width" ],
     [ "", "auto", "initial value" ],
   ];
 
   var p = document.createElement("p");
   var cs = getComputedStyle(p, "");
   frame_container.appendChild(p);
 
   for (var i = 0; i < backgroundSizes.length; ++i) {
--- a/servo/components/style/values/computed/length.rs
+++ b/servo/components/style/values/computed/length.rs
@@ -198,22 +198,17 @@ impl LengthPercentage {
 
     /// Returns the percentage component if this could be represented as a
     /// non-calc percentage.
     pub fn as_percentage(&self) -> Option<Percentage> {
         if !self.has_percentage || self.length.px() != 0. {
             return None;
         }
 
-        if self.clamping_mode.clamp(self.percentage.0) != self.percentage.0 {
-            debug_assert!(self.was_calc);
-            return None;
-        }
-
-        Some(self.percentage)
+        Some(Percentage(self.clamping_mode.clamp(self.percentage.0)))
     }
 
     /// Convert the computed value into used value.
     #[inline]
     pub fn maybe_to_used_value(&self, container_len: Option<Au>) -> Option<Au> {
         self.maybe_to_pixel_length(container_len).map(Au::from)
     }
 
@@ -428,24 +423,23 @@ impl ToComputedValue for specified::Leng
                 LengthPercentage::new(value.to_computed_value(context), None)
             },
             specified::LengthPercentage::Percentage(value) => LengthPercentage::new_percent(value),
             specified::LengthPercentage::Calc(ref calc) => (**calc).to_computed_value(context),
         }
     }
 
     fn from_computed_value(computed: &LengthPercentage) -> Self {
-        let length = computed.unclamped_length();
         if let Some(p) = computed.as_percentage() {
             return specified::LengthPercentage::Percentage(p);
         }
 
-        if !computed.has_percentage && computed.clamping_mode.clamp(length.px()) == length.px() {
+        if !computed.has_percentage {
             return specified::LengthPercentage::Length(ToComputedValue::from_computed_value(
-                &length,
+                &computed.length(),
             ));
         }
 
         specified::LengthPercentage::Calc(Box::new(ToComputedValue::from_computed_value(computed)))
     }
 }
 
 impl IsZeroLength for LengthPercentage {
deleted file mode 100644
--- a/testing/web-platform/meta/css/css-shapes/parsing/shape-margin-computed.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[shape-margin-computed.html]
-  [Property shape-margin value 'calc(10px - 0.5em)' computes to '0px']
-    expected: FAIL
-