bug 821593 - add downcasting from CSSValue to nsROCSSPrimitiveValue r=bz
authorTrevor Saunders <trev.saunders@gmail.com>
Wed, 24 Oct 2012 19:38:52 -0400
changeset 126049 08fb8e6e898659be0ae5c792da228b484ef67c5a
parent 126048 5823e4df1ab0af9eb8ba9d9423fb67318392c5ff
child 126050 e238a2c12230f13e6adf62295c1c69ae8a9c747e
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs821593
milestone20.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 821593 - add downcasting from CSSValue to nsROCSSPrimitiveValue r=bz
layout/style/CSSValue.h
layout/style/nsROCSSPrimitiveValue.h
--- a/layout/style/CSSValue.h
+++ b/layout/style/CSSValue.h
@@ -26,14 +26,22 @@ namespace dom {
 class CSSValue : public nsISupports,
                  public nsWrapperCache
 {
 public:
   // CSSValue
   virtual void GetCssText(nsString& aText, mozilla::ErrorResult& aRv) = 0;
   virtual void SetCssText(const nsAString& aText, mozilla::ErrorResult& aRv) = 0;
   virtual uint16_t CssValueType() const = 0;
+
+  // Downcasting
+
+  /**
+   * Return this as a nsROCSSPrimitiveValue* if its a primitive value, and null
+   * otherwise.
+   */
+  nsROCSSPrimitiveValue *AsPrimitiveValue();
 };
 
 }
 }
 
 #endif
--- a/layout/style/nsROCSSPrimitiveValue.h
+++ b/layout/style/nsROCSSPrimitiveValue.h
@@ -94,10 +94,16 @@ private:
     nsDOMCSSRGBColor* mColor;
     nsIDOMRect*     mRect;
     PRUnichar*      mString;
     nsIURI*         mURI;
     nsCSSKeyword    mKeyword;
   } mValue;
 };
 
+inline nsROCSSPrimitiveValue *mozilla::dom::CSSValue::AsPrimitiveValue()
+{
+  return CssValueType() == nsIDOMCSSValue::CSS_PRIMITIVE_VALUE ?
+    static_cast<nsROCSSPrimitiveValue*>(this) : nullptr;
+}
+
 #endif /* nsROCSSPrimitiveValue_h___ */