Bug 1494622 - Remove nsDOMCSSRGBColor. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 26 Sep 2018 23:06:24 +0200
changeset 438545 f3bfb76e088a2cbdd944bda1fc4724d18eca2ae4
parent 438544 31d61c73ab751904374d1bdc81c594add80b4cde
child 438546 fb7be8b4ae804709379c35f190708636c49606b1
push id34724
push userccoroiu@mozilla.com
push dateThu, 27 Sep 2018 21:36:09 +0000
treeherdermozilla-central@e1d012b989ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1494622
milestone64.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 1494622 - Remove nsDOMCSSRGBColor. r=xidorn Differential Revision: https://phabricator.services.mozilla.com/D7068
editor/libeditor/HTMLAbsPositionEditor.cpp
layout/style/moz.build
layout/style/nsComputedDOMStyle.cpp
layout/style/nsDOMCSSRGBColor.cpp
layout/style/nsDOMCSSRGBColor.h
layout/style/nsROCSSPrimitiveValue.cpp
layout/style/nsROCSSPrimitiveValue.h
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -23,17 +23,16 @@
 #include "nsCOMPtr.h"
 #include "nsComputedDOMStyle.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsROCSSPrimitiveValue.h"
 #include "nsIDOMEventListener.h"
-#include "nsDOMCSSRGBColor.h"
 #include "nsIDOMWindow.h"
 #include "nsIHTMLObjectResizer.h"
 #include "nsINode.h"
 #include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsISupportsUtils.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -50,17 +50,16 @@ EXPORTS += [
     'nsCSSKeywords.h',
     'nsCSSPropertyIDSet.h',
     'nsCSSProps.h',
     'nsCSSPseudoElementList.h',
     'nsCSSPseudoElements.h',
     'nsCSSValue.h',
     'nsDOMCSSAttrDeclaration.h',
     'nsDOMCSSDeclaration.h',
-    'nsDOMCSSRGBColor.h',
     'nsICSSDeclaration.h',
     'nsICSSLoaderObserver.h',
     'nsLayoutStylesheetCache.h',
     'nsMediaFeatures.h',
     'nsStyleAutoArray.h',
     'nsStyleConsts.h',
     'nsStyleCoord.h',
     'nsStyleStruct.h',
@@ -183,17 +182,16 @@ UNIFIED_SOURCES += [
     'nsAnimationManager.cpp',
     'nsComputedDOMStyle.cpp',
     'nsCSSKeywords.cpp',
     'nsCSSProps.cpp',
     'nsCSSValue.cpp',
     'nsDOMCSSAttrDeclaration.cpp',
     'nsDOMCSSDeclaration.cpp',
     'nsDOMCSSRect.cpp',
-    'nsDOMCSSRGBColor.cpp',
     'nsDOMCSSValueList.cpp',
     'nsFontFaceLoader.cpp',
     'nsFontFaceUtils.cpp',
     'nsHTMLCSSStyleSheet.cpp',
     'nsHTMLStyleSheet.cpp',
     'nsICSSDeclaration.cpp',
     'nsMediaFeatures.cpp',
     'nsROCSSPrimitiveValue.cpp',
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -19,17 +19,16 @@
 #include "nsIFrameInlines.h"
 #include "mozilla/ComputedStyle.h"
 #include "nsIScrollableFrame.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
 #include "nsStyleConsts.h"
 
 #include "nsDOMCSSRect.h"
-#include "nsDOMCSSRGBColor.h"
 #include "nsDOMCSSValueList.h"
 #include "nsFlexContainerFrame.h"
 #include "nsGridContainerFrame.h"
 #include "nsGkAtoms.h"
 #include "mozilla/ReflowInput.h"
 #include "nsStyleUtil.h"
 #include "nsStyleStructInlines.h"
 #include "nsROCSSPrimitiveValue.h"
@@ -1116,31 +1115,35 @@ nsComputedDOMStyle::DoGetBottom()
 {
   return GetOffsetWidthFor(eSideBottom);
 }
 
 void
 nsComputedDOMStyle::SetToRGBAColor(nsROCSSPrimitiveValue* aValue,
                                    nscolor aColor)
 {
-  nsROCSSPrimitiveValue *red   = new nsROCSSPrimitiveValue;
-  nsROCSSPrimitiveValue *green = new nsROCSSPrimitiveValue;
-  nsROCSSPrimitiveValue *blue  = new nsROCSSPrimitiveValue;
-  nsROCSSPrimitiveValue *alpha  = new nsROCSSPrimitiveValue;
-
-  uint8_t a = NS_GET_A(aColor);
-  nsDOMCSSRGBColor *rgbColor =
-    new nsDOMCSSRGBColor(red, green, blue, alpha, a < 255);
-
-  red->SetNumber(NS_GET_R(aColor));
-  green->SetNumber(NS_GET_G(aColor));
-  blue->SetNumber(NS_GET_B(aColor));
-  alpha->SetNumber(nsStyleUtil::ColorComponentToFloat(a));
-
-  aValue->SetColor(rgbColor);
+  nsAutoString string;
+  const bool hasAlpha = NS_GET_A(aColor) != 255;
+  if (hasAlpha) {
+    string.AppendLiteral("rgba(");
+  } else {
+    string.AppendLiteral("rgb(");
+  }
+  string.AppendInt(NS_GET_R(aColor));
+  string.AppendLiteral(", ");
+  string.AppendInt(NS_GET_G(aColor));
+  string.AppendLiteral(", ");
+  string.AppendInt(NS_GET_B(aColor));
+  if (hasAlpha) {
+    string.AppendLiteral(", ");
+    float alpha = nsStyleUtil::ColorComponentToFloat(NS_GET_A(aColor));
+    nsStyleUtil::AppendCSSNumber(alpha, string);
+  }
+  string.AppendLiteral(")");
+  aValue->SetString(string);
 }
 
 void
 nsComputedDOMStyle::SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
                                              const StyleComplexColor& aColor)
 {
   SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
 }
deleted file mode 100644
--- a/layout/style/nsDOMCSSRGBColor.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* DOM object representing color values in DOM computed style */
-
-#include "nsDOMCSSRGBColor.h"
-
-#include "nsROCSSPrimitiveValue.h"
-
-using namespace mozilla;
-
-nsDOMCSSRGBColor::nsDOMCSSRGBColor(nsROCSSPrimitiveValue* aRed,
-                                   nsROCSSPrimitiveValue* aGreen,
-                                   nsROCSSPrimitiveValue* aBlue,
-                                   nsROCSSPrimitiveValue* aAlpha,
-                                   bool aHasAlpha)
-  : mRed(aRed), mGreen(aGreen), mBlue(aBlue), mAlpha(aAlpha)
-  , mHasAlpha(aHasAlpha)
-{
-}
-
-nsDOMCSSRGBColor::~nsDOMCSSRGBColor() = default;
deleted file mode 100644
--- a/layout/style/nsDOMCSSRGBColor.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* DOM object representing color values in DOM computed style */
-
-#ifndef nsDOMCSSRGBColor_h__
-#define nsDOMCSSRGBColor_h__
-
-#include "mozilla/Attributes.h"
-#include "mozilla/RefCounted.h"
-#include "mozilla/RefPtr.h"
-
-class nsROCSSPrimitiveValue;
-
-class nsDOMCSSRGBColor final : public mozilla::RefCounted<nsDOMCSSRGBColor>
-{
-public:
-  MOZ_DECLARE_REFCOUNTED_TYPENAME(nsDOMCSSRGBColor);
-  nsDOMCSSRGBColor(nsROCSSPrimitiveValue* aRed,
-                   nsROCSSPrimitiveValue* aGreen,
-                   nsROCSSPrimitiveValue* aBlue,
-                   nsROCSSPrimitiveValue* aAlpha,
-                   bool aHasAlpha);
-
-  bool HasAlpha() const { return mHasAlpha; }
-
-  // RGBColor webidl interface
-  nsROCSSPrimitiveValue* Red() const
-  {
-    return mRed;
-  }
-  nsROCSSPrimitiveValue* Green() const
-  {
-    return mGreen;
-  }
-  nsROCSSPrimitiveValue* Blue() const
-  {
-    return mBlue;
-  }
-  nsROCSSPrimitiveValue* Alpha() const
-  {
-    return mAlpha;
-  }
-
-  ~nsDOMCSSRGBColor();
-
-protected:
-  RefPtr<nsROCSSPrimitiveValue> mRed;
-  RefPtr<nsROCSSPrimitiveValue> mGreen;
-  RefPtr<nsROCSSPrimitiveValue> mBlue;
-  RefPtr<nsROCSSPrimitiveValue> mAlpha;
-  bool mHasAlpha;
-};
-
-#endif // nsDOMCSSRGBColor_h__
--- a/layout/style/nsROCSSPrimitiveValue.cpp
+++ b/layout/style/nsROCSSPrimitiveValue.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* DOM object representing values in DOM computed style */
 
 #include "nsROCSSPrimitiveValue.h"
 
 #include "nsPresContext.h"
 #include "nsStyleUtil.h"
-#include "nsDOMCSSRGBColor.h"
 #include "nsDOMCSSRect.h"
 #include "nsIURI.h"
 #include "nsError.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsROCSSPrimitiveValue::nsROCSSPrimitiveValue()
@@ -152,57 +151,16 @@ nsROCSSPrimitiveValue::GetCssText(nsAStr
         tmpStr.Append(sideValue + comma);
         // get the left
         result = mValue.mRect->Left()->GetCssText(sideValue);
         if (NS_FAILED(result))
           break;
         tmpStr.Append(sideValue + NS_LITERAL_STRING(")"));
         break;
       }
-    case CSS_RGBCOLOR:
-      {
-        NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
-        ErrorResult error;
-        NS_NAMED_LITERAL_STRING(comma, ", ");
-        nsAutoString colorValue;
-        if (mValue.mColor->HasAlpha())
-          tmpStr.AssignLiteral("rgba(");
-        else
-          tmpStr.AssignLiteral("rgb(");
-
-        // get the red component
-        mValue.mColor->Red()->GetCssText(colorValue, error);
-        if (error.Failed())
-          break;
-        tmpStr.Append(colorValue + comma);
-
-        // get the green component
-        mValue.mColor->Green()->GetCssText(colorValue, error);
-        if (error.Failed())
-          break;
-        tmpStr.Append(colorValue + comma);
-
-        // get the blue component
-        mValue.mColor->Blue()->GetCssText(colorValue, error);
-        if (error.Failed())
-          break;
-        tmpStr.Append(colorValue);
-
-        if (mValue.mColor->HasAlpha()) {
-          // get the alpha component
-          mValue.mColor->Alpha()->GetCssText(colorValue, error);
-          if (error.Failed())
-            break;
-          tmpStr.Append(comma + colorValue);
-        }
-
-        tmpStr.Append(')');
-
-        break;
-      }
     case CSS_S:
       {
         nsStyleUtil::AppendCSSNumber(mValue.mFloat, tmpStr);
         tmpStr.Append('s');
         break;
       }
     case CSS_CM:
     case CSS_MM:
@@ -385,28 +343,16 @@ nsROCSSPrimitiveValue::GetRectValue(Erro
     aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     return nullptr;
   }
 
   NS_ASSERTION(mValue.mRect, "mValue.mRect should never be null");
   return mValue.mRect;
 }
 
-nsDOMCSSRGBColor*
-nsROCSSPrimitiveValue::GetRGBColorValue(ErrorResult& aRv)
-{
-  if (mType != CSS_RGBCOLOR) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
-    return nullptr;
-  }
-
-  NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
-  return mValue.mColor;
-}
-
 void
 nsROCSSPrimitiveValue::SetNumber(float aValue)
 {
   Reset();
   mValue.mFloat = aValue;
   mType = CSS_NUMBER;
 }
 
@@ -524,32 +470,16 @@ nsROCSSPrimitiveValue::SetURI(nsIURI *aU
 {
   Reset();
   mValue.mURI = aURI;
   NS_IF_ADDREF(mValue.mURI);
   mType = CSS_URI;
 }
 
 void
-nsROCSSPrimitiveValue::SetColor(nsDOMCSSRGBColor* aColor)
-{
-  MOZ_ASSERT(aColor, "Null RGBColor being set!");
-
-  Reset();
-  mValue.mColor = aColor;
-  if (mValue.mColor) {
-    NS_ADDREF(mValue.mColor);
-    mType = CSS_RGBCOLOR;
-  }
-  else {
-    mType = CSS_UNKNOWN;
-  }
-}
-
-void
 nsROCSSPrimitiveValue::SetRect(nsDOMCSSRect* aRect)
 {
   MOZ_ASSERT(aRect, "Null rect being set!");
 
   Reset();
   mValue.mRect = aRect;
   if (mValue.mRect) {
     NS_ADDREF(mValue.mRect);
@@ -583,20 +513,16 @@ nsROCSSPrimitiveValue::Reset()
       break;
     case CSS_URI:
       NS_IF_RELEASE(mValue.mURI);
       break;
     case CSS_RECT:
       NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
       NS_RELEASE(mValue.mRect);
       break;
-    case CSS_RGBCOLOR:
-      NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
-      NS_RELEASE(mValue.mColor);
-      break;
   }
 
   mType = CSS_UNKNOWN;
 }
 
 uint16_t
 nsROCSSPrimitiveValue::PrimitiveType()
 {
--- a/layout/style/nsROCSSPrimitiveValue.h
+++ b/layout/style/nsROCSSPrimitiveValue.h
@@ -11,17 +11,16 @@
 
 #include "nsCSSKeywords.h"
 #include "CSSValue.h"
 #include "nsCOMPtr.h"
 #include "nsCoord.h"
 
 class nsIURI;
 class nsDOMCSSRect;
-class nsDOMCSSRGBColor;
 
 /**
  * Read-only CSS primitive value - a DOM object representing values in DOM
  * computed style.
  */
 class nsROCSSPrimitiveValue final : public mozilla::dom::CSSValue
 {
 public:
@@ -67,17 +66,16 @@ public:
   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);
   void SetStringValue(uint16_t aUnitType, const nsAString& aString,
                       mozilla::ErrorResult& aRv);
   void GetCounterValue(mozilla::ErrorResult& aRv);
   nsDOMCSSRect* GetRectValue(mozilla::ErrorResult& aRv);
-  nsDOMCSSRGBColor *GetRGBColorValue(mozilla::ErrorResult& aRv);
 
   // nsROCSSPrimitiveValue
   nsROCSSPrimitiveValue();
 
   nsresult GetCssText(nsAString& aText);
   void SetNumber(float aValue);
   void SetNumber(int32_t aValue);
   void SetNumber(uint32_t aValue);
@@ -89,33 +87,31 @@ public:
   void SetAppUnits(nscoord aValue);
   void SetAppUnits(float aValue);
   void SetIdent(nsCSSKeyword aKeyword);
   // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
   void SetString(const nsACString& aString, uint16_t aType = CSS_STRING);
   // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
   void SetString(const nsAString& aString, uint16_t aType = CSS_STRING);
   void SetURI(nsIURI *aURI);
-  void SetColor(nsDOMCSSRGBColor* aColor);
   void SetRect(nsDOMCSSRect* aRect);
   void SetTime(float aValue);
   void Reset();
 
   virtual ~nsROCSSPrimitiveValue();
 protected:
 
   uint16_t mType;
 
   union {
     nscoord         mAppUnits;
     float           mFloat;
     int32_t         mInt32;
     uint32_t        mUint32;
     // These can't be nsCOMPtr/nsRefPtr's because they are used inside a union.
-    nsDOMCSSRGBColor* MOZ_OWNING_REF mColor;
     nsDOMCSSRect* MOZ_OWNING_REF mRect;
     char16_t*      mString;
     nsIURI* MOZ_OWNING_REF mURI;
     nsCSSKeyword    mKeyword;
   } mValue;
 };
 
 inline nsROCSSPrimitiveValue*