Bug 1427419 - Part 11: Move inIDOMUtils.rgbToColorName to InspectorUtils. r=bz
authorCameron McCormack <cam@mcc.id.au>
Thu, 11 Jan 2018 12:38:00 +0800
changeset 450473 044e1b16df7658754e2fabfecf2adae9b3863550
parent 450472 b7386d96d8b2a219c922bc8e08fda5ccd051557a
child 450474 87e619f7e97c1bd5088fdb94091f31123d010f69
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1427419
milestone59.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 1427419 - Part 11: Move inIDOMUtils.rgbToColorName to InspectorUtils. r=bz MozReview-Commit-ID: LZcGUEO4Ois
devtools/client/shared/test/unit/test_cssColorDatabase.js
dom/webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.h
layout/inspector/inDOMUtils.cpp
layout/inspector/inIDOMUtils.idl
--- a/devtools/client/shared/test/unit/test_cssColorDatabase.js
+++ b/devtools/client/shared/test/unit/test_cssColorDatabase.js
@@ -33,17 +33,17 @@ function checkOne(colorName, checkName) 
 
   if (checkName) {
     let {r, g, b} = ours;
 
     // The color we got might not map back to the same name; but our
     // implementation should agree with DOMUtils about which name is
     // canonical.
     let ourName = colorUtils.rgbToColorName(r, g, b);
-    let domName = DOMUtils.rgbToColorName(r, g, b);
+    let domName = InspectorUtils.rgbToColorName(r, g, b);
 
     equal(ourName, domName,
           colorName + " canonical name agrees with DOMUtils");
   }
 }
 
 function run_test() {
   for (let name in cssColors) {
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -27,16 +27,17 @@ namespace InspectorUtils {
   [Throws] boolean selectorMatchesElement(
       Element element,
       CSSStyleRule rule,
       unsigned long selectorIndex,
       [TreatNullAs=EmptyString] optional DOMString pseudo = "");
   boolean isInheritedProperty(DOMString property);
   sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options);
   [Throws] sequence<DOMString> getCSSValuesForProperty(DOMString property);
+  [Throws] DOMString rgbToColorName(octet r, octet g, octet b);
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
 };
 
 dictionary InspectorRGBATuple {
   /*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -110,16 +110,22 @@ public:
                                   nsTArray<nsString>& aResult);
 
   // Get a list of all valid keywords and colors for aProperty.
   static void GetCSSValuesForProperty(GlobalObject& aGlobal,
                                       const nsAString& aPropertyName,
                                       nsTArray<nsString>& aResult,
                                       ErrorResult& aRv);
 
+  // Utilities for working with CSS colors
+  static void RgbToColorName(GlobalObject& aGlobal,
+                             uint8_t aR, uint8_t aG, uint8_t aB,
+                             nsAString& aResult,
+                             ErrorResult& aRv);
+
 private:
   static already_AddRefed<nsStyleContext>
     GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -850,33 +850,35 @@ InspectorUtils::GetCSSValuesForProperty(
     }
   }
   // All CSS properties take initial, inherit and unset.
   InsertNoDuplicates(aResult, NS_LITERAL_STRING("initial"));
   InsertNoDuplicates(aResult, NS_LITERAL_STRING("inherit"));
   InsertNoDuplicates(aResult, NS_LITERAL_STRING("unset"));
 }
 
-} // namespace dom
-} // namespace mozilla
-
-NS_IMETHODIMP
-inDOMUtils::RgbToColorName(uint8_t aR, uint8_t aG, uint8_t aB,
-                           nsAString& aColorName)
+/* static */ void
+InspectorUtils::RgbToColorName(GlobalObject& aGlobalObject,
+                               uint8_t aR, uint8_t aG, uint8_t aB,
+                               nsAString& aColorName,
+                               ErrorResult& aRv)
 {
   const char* color = NS_RGBToColorName(NS_RGB(aR, aG, aB));
   if (!color) {
     aColorName.Truncate();
-    return NS_ERROR_INVALID_ARG;
+    aRv.Throw(NS_ERROR_INVALID_ARG);
+    return;
   }
 
   aColorName.AssignASCII(color);
-  return NS_OK;
 }
 
+} // namespace dom
+} // namespace mozilla
+
 NS_IMETHODIMP
 inDOMUtils::ColorToRGBA(const nsAString& aColorString, JSContext* aCx,
                         JS::MutableHandle<JS::Value> aValue)
 {
   nscolor color = NS_RGB(0, 0, 0);
 
 #ifdef MOZ_STYLO
   if (!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0), aColorString,
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,19 +15,16 @@ interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
-  // Utilities for working with CSS colors
-  AString rgbToColorName(in octet aR, in octet aG, in octet aB);
-
   // Convert a given CSS color string to rgba. Returns null on failure or an
   // InspectorRGBATuple on success.
   //
   // NOTE: Converting a color to RGBA may be lossy when converting from some
   // formats e.g. CMYK.
   [implicit_jscontext]
   jsval colorToRGBA(in DOMString aColorString);