Bug 470769 - Store computed styles of integer-valued properties as integers in nsROCSSPrimitiveValue, so they round-trip correctly. r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Sat, 29 Mar 2014 09:29:30 -0700
changeset 195660 b5323125a8715febb58c8f066edb193c03cf9147
parent 195604 110c1a3fc74c282d52f07bd52956c07ea832c5a3
child 195661 7c1c4f4ed61ac411474447e1fb40cc4ced3a0a2a
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs470769
milestone31.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 470769 - Store computed styles of integer-valued properties as integers in nsROCSSPrimitiveValue, so they round-trip correctly. r=bzbarsky
layout/style/nsROCSSPrimitiveValue.cpp
layout/style/nsROCSSPrimitiveValue.h
layout/style/test/test_bug470769.html
--- a/layout/style/nsROCSSPrimitiveValue.cpp
+++ b/layout/style/nsROCSSPrimitiveValue.cpp
@@ -12,23 +12,16 @@
 #include "nsStyleUtil.h"
 #include "nsDOMCSSRGBColor.h"
 #include "nsDOMCSSRect.h"
 #include "nsIURI.h"
 #include "nsError.h"
 
 using namespace mozilla;
 
-// There is no CSS_TURN constant on the CSSPrimitiveValue interface,
-// since that unit is newer than DOM Level 2 Style, and CSS OM will
-// probably expose CSS values in some other way in the future.  We
-// use this value in mType for "turn"-unit angles, but we define it
-// here to avoid exposing it to content.
-#define CSS_TURN 30U
-
 nsROCSSPrimitiveValue::nsROCSSPrimitiveValue()
   : CSSValue(), mType(CSS_PX)
 {
   mValue.mAppUnits = 0;
   SetIsDOMBinding();
 }
 
 
@@ -137,16 +130,26 @@ nsROCSSPrimitiveValue::GetCssText(nsAStr
         tmpStr.Append(char16_t('%'));
         break;
       }
     case CSS_NUMBER :
       {
         nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
         break;
       }
+    case CSS_NUMBER_INT32 :
+      {
+        tmpStr.AppendInt(mValue.mInt32);
+        break;
+      }
+    case CSS_NUMBER_UINT32 :
+      {
+        tmpStr.AppendInt(mValue.mUint32);
+        break;
+      }
     case CSS_DEG :
       {
         nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
         tmpStr.AppendLiteral("deg");
         break;
       }
     case CSS_GRAD :
       {
@@ -312,17 +315,17 @@ nsROCSSPrimitiveValue::CssValueType() co
 
 
 // nsIDOMCSSPrimitiveValue
 
 NS_IMETHODIMP
 nsROCSSPrimitiveValue::GetPrimitiveType(uint16_t* aPrimitiveType)
 {
   NS_ENSURE_ARG_POINTER(aPrimitiveType);
-  *aPrimitiveType = mType;
+  *aPrimitiveType = PrimitiveType();
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsROCSSPrimitiveValue::SetFloatValue(uint16_t aUnitType, float aFloatValue)
 {
@@ -385,16 +388,22 @@ nsROCSSPrimitiveValue::GetFloatValue(uin
         return mValue.mFloat * 100;
       }
 
       break;
     case CSS_NUMBER :
       if (mType == CSS_NUMBER) {
         return mValue.mFloat;
       }
+      if (mType == CSS_NUMBER_INT32) {
+        return mValue.mInt32;
+      }
+      if (mType == CSS_NUMBER_UINT32) {
+        return mValue.mUint32;
+      }
 
       break;
     case CSS_UNKNOWN :
     case CSS_EMS :
     case CSS_EXS :
     case CSS_DEG :
     case CSS_RAD :
     case CSS_GRAD :
@@ -524,26 +533,26 @@ nsROCSSPrimitiveValue::SetNumber(float a
     mValue.mFloat = aValue;
     mType = CSS_NUMBER;
 }
 
 void
 nsROCSSPrimitiveValue::SetNumber(int32_t aValue)
 {
   Reset();
-  mValue.mFloat = float(aValue);
-  mType = CSS_NUMBER;
+  mValue.mInt32 = aValue;
+  mType = CSS_NUMBER_INT32;
 }
 
 void
 nsROCSSPrimitiveValue::SetNumber(uint32_t aValue)
 {
   Reset();
-  mValue.mFloat = float(aValue);
-  mType = CSS_NUMBER;
+  mValue.mUint32 = aValue;
+  mType = CSS_NUMBER_UINT32;
 }
 
 void
 nsROCSSPrimitiveValue::SetPercent(float aValue)
 {
   Reset();
   mValue.mFloat = aValue;
   mType = CSS_PERCENTAGE;
--- a/layout/style/nsROCSSPrimitiveValue.h
+++ b/layout/style/nsROCSSPrimitiveValue.h
@@ -14,16 +14,27 @@
 #include "CSSValue.h"
 #include "nsCOMPtr.h"
 #include "nsCoord.h"
 
 class nsIURI;
 class nsDOMCSSRect;
 class nsDOMCSSRGBColor;
 
+// There is no CSS_TURN constant on the CSSPrimitiveValue interface,
+// since that unit is newer than DOM Level 2 Style, and CSS OM will
+// probably expose CSS values in some other way in the future.  We
+// use this value in mType for "turn"-unit angles, but we define it
+// here to avoid exposing it to content.
+#define CSS_TURN 30U
+// Likewise we have some internal aliases for CSS_NUMBER that we don't
+// want to expose.
+#define CSS_NUMBER_INT32 31U
+#define CSS_NUMBER_UINT32 32U
+
 /**
  * Read-only CSS primitive value - a DOM object representing values in DOM
  * computed style.
  */
 class nsROCSSPrimitiveValue MOZ_FINAL : public mozilla::dom::CSSValue,
   public nsIDOMCSSPrimitiveValue
 {
 public:
@@ -42,16 +53,19 @@ public:
   virtual uint16_t CssValueType() const MOZ_OVERRIDE MOZ_FINAL;
 
   // CSSPrimitiveValue
   uint16_t PrimitiveType()
   {
     // New value types were introduced but not added to CSS OM.
     // Return CSS_UNKNOWN to avoid exposing CSS_TURN to content.
     if (mType > CSS_RGBCOLOR) {
+      if (mType == CSS_NUMBER_INT32 || mType == CSS_NUMBER_UINT32) {
+        return CSS_NUMBER;
+      }
       return CSS_UNKNOWN;
     }
     return mType;
   }
   void SetFloatValue(uint16_t aUnitType, float aValue,
                      mozilla::ErrorResult& aRv);
   float GetFloatValue(uint16_t aUnitType, mozilla::ErrorResult& aRv);
   void GetStringValue(nsString& aString, mozilla::ErrorResult& aRv);
@@ -95,16 +109,18 @@ public:
                                JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
 private:
   uint16_t mType;
 
   union {
     nscoord         mAppUnits;
     float           mFloat;
+    int32_t         mInt32;
+    uint32_t        mUint32;
     nsDOMCSSRGBColor* mColor;
     nsDOMCSSRect*     mRect;
     char16_t*      mString;
     nsIURI*         mURI;
     nsCSSKeyword    mKeyword;
   } mValue;
 };
 
--- a/layout/style/test/test_bug470769.html
+++ b/layout/style/test/test_bug470769.html
@@ -17,15 +17,15 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 470769 **/
 
 var e = document.getElementById("display");
 e.setAttribute("style", "z-index: 2147483647"); // maximum signed 32-bit
 is(e.style.zIndex, "2147483647", "element.style should roundtrip correctly");
-todo_is(window.getComputedStyle(e, "").zIndex, "2147483647",
+is(window.getComputedStyle(e, "").zIndex, "2147483647",
    "getComputedStyle should roundtrip correctly");
 
 </script>
 </pre>
 </body>
 </html>