Bug 532721: less conservative detection of gradients with size dependence. r=dbaron
authorZack Weinberg <zweinberg@mozilla.com>
Tue, 15 Dec 2009 12:34:19 -0800
changeset 36225 8090e6b588031ac988da972e0c5d3716965ccd39
parent 36224 3b2fec6aa462aae722557cdb8056fe0c299e8ceb
child 36226 b78d999d215d0cae404ecd1f7657eeed727fcea5
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs532721
milestone1.9.3a1pre
Bug 532721: less conservative detection of gradients with size dependence. r=dbaron
layout/reftests/css-gradients/height-dependence-3-ref.html
layout/reftests/css-gradients/height-dependence-3.html
layout/reftests/css-gradients/reftest.list
layout/style/nsStyleStruct.h
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-gradients/height-dependence-3-ref.html
@@ -0,0 +1,44 @@
+<!doctype html>
+<html><head>
+<style>
+html {
+  background-image: -moz-linear-gradient(black, white 20%);
+  background-repeat: repeat-x;
+  -moz-background-size: 1px 80%;
+}
+body {
+  font-size: 1em;
+  padding: 2em;
+  margin: 50px auto;
+  width: 14em;
+  border: 1px solid black;
+  background-color: white;
+}
+</style>
+</head><body>
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-gradients/height-dependence-3.html
@@ -0,0 +1,54 @@
+<!doctype html>
+<html class="reftest-wait"><head>
+<style>
+html {
+  background-image: -moz-linear-gradient(black, white 20%);
+  background-repeat: repeat-x;
+  -moz-background-size: 1px 80%;
+}
+body {
+  font-size: 1em;
+  padding: 2em;
+  margin: 50px auto;
+  width: 28em;
+  border: 1px solid black;
+  background-color: white;
+}
+</style>
+<script>
+window.onload = function() {
+  setTimeout(function() {
+    document.body.style.width = "14em";
+    setTimeout(function() {
+      document.documentElement.removeAttribute("class");
+    }, 100);
+  }, 100);
+}
+</script>
+</head><body>
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+pad pad pad pad pad pad pad pad
+</body>
+</html>
--- a/layout/reftests/css-gradients/reftest.list
+++ b/layout/reftests/css-gradients/reftest.list
@@ -82,8 +82,9 @@ fails == aja-linear-2d.html aja-linear-2
 == aja-linear-3b.html aja-linear-3-ref.html
 == aja-linear-4a.html aja-linear-4-ref.html
 == aja-linear-4b.html aja-linear-4-ref.html
 == aja-linear-5a.html aja-linear-5-ref.html
 fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") == aja-linear-6a.html aja-linear-6-ref.html # bug 526708
 fails == aja-linear-6b.html aja-linear-6-ref.html # bug 522607
 == height-dependence-1.html height-dependence-1-ref.html
 == height-dependence-2.html height-dependence-2-ref.html
+== height-dependence-3.html height-dependence-3-ref.html
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -408,20 +408,29 @@ struct nsStyleBackground {
       ePercentage,
 
       eAuto,
       eLength,
       eDimensionType_COUNT
     };
     PRUint8 mWidthType, mHeightType;
 
-    // True if the effective image size described by this depends on the size
-    // of the corresponding frame.
-    PRBool DependsOnFrameSize() const {
-      return mWidthType <= ePercentage || mHeightType <= ePercentage;
+    // True if the effective image size described by this depends on
+    // the size of the corresponding frame.  Gradients depend on the
+    // frame size when their dimensions are 'auto', images don't; both
+    // types depend on the frame size when their dimensions are
+    // 'contain', 'cover', or a percentage.
+    PRBool DependsOnFrameSize(nsStyleImageType aType) const {
+      if (aType == eStyleImageType_Image) {
+        return mWidthType <= ePercentage || mHeightType <= ePercentage;
+      } else if (aType == eStyleImageType_Gradient) {
+        return mWidthType <= eAuto || mHeightType <= eAuto;
+      } else {
+        NS_NOTREACHED("unrecognized image type");
+      }
     }
 
     // Initialize nothing
     Size() {}
 
     // Initialize to initial values
     void SetInitialValues();
 
@@ -451,19 +460,18 @@ struct nsStyleBackground {
     // True if the rendering of this layer might change when the size
     // of the corresponding frame changes.  This is true for any
     // non-solid-color background whose position or size depends on
     // the frame size (that is, was specified with percentages) and is
     // also true for nearly all gradients.  We don't currently bother
     // trying to identify gradients that don't depend on the frame size.
     PRBool RenderingMightDependOnFrameSize() const {
       return (!mImage.IsEmpty() &&
-              (mImage.GetType() == eStyleImageType_Gradient ||
-               mPosition.DependsOnFrameSize() ||
-               mSize.DependsOnFrameSize()));
+              (mPosition.DependsOnFrameSize() ||
+               mSize.DependsOnFrameSize(mImage.GetType())));
     }
 
     // An equality operator that compares the images using URL-equality
     // rather than pointer-equality.
     PRBool operator==(const Layer& aOther) const;
     PRBool operator!=(const Layer& aOther) const {
       return !(*this == aOther);
     }