diff --git a/dom/webidl/DummyBinding.webidl b/dom/webidl/DummyBinding.webidl index 27f6b5431bf6..edbc0b2f1e7c 100644 --- a/dom/webidl/DummyBinding.webidl +++ b/dom/webidl/DummyBinding.webidl @@ -13,6 +13,7 @@ interface DummyInterface { RTCConfiguration rtcConfiguration(); CFStateChangeEventDict cfstateChangeEvent(); USSDReceivedEventDict ussdReceivedEvent(); + InspectorRGBTriple rgbTriple(); }; interface DummyInterfaceWorkers { diff --git a/dom/webidl/InspectorUtils.webidl b/dom/webidl/InspectorUtils.webidl new file mode 100644 index 000000000000..2f73a839d29a --- /dev/null +++ b/dom/webidl/InspectorUtils.webidl @@ -0,0 +1,16 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. + */ +dictionary InspectorRGBTriple { + /* + * NOTE: Using octet for RGB components is not generally OK, because + * they can be outside the 0-255 range, but for backwards-compatible + * named colors (which is what we use this dictionary for) the 0-255 + * assumption is fine. + */ + octet r = 0; + octet g = 0; + octet b = 0; +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 51759d8737ba..75e3e0e07d0f 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -119,6 +119,7 @@ webidl_files = \ HTMLUListElement.webidl \ IDBVersionChangeEvent.webidl \ ImageData.webidl \ + InspectorUtils.webidl \ LinkStyle.webidl \ LocalMediaStream.webidl \ Location.webidl \ diff --git a/layout/inspector/public/inIDOMUtils.idl b/layout/inspector/public/inIDOMUtils.idl index c24495476c61..6c2854a160d4 100644 --- a/layout/inspector/public/inIDOMUtils.idl +++ b/layout/inspector/public/inIDOMUtils.idl @@ -16,7 +16,7 @@ interface nsIDOMFontFaceList; interface nsIDOMRange; interface nsIDOMCSSStyleSheet; -[scriptable, uuid(ea7e58ad-da38-4d1e-b0fc-fd7fb5c560c9)] +[scriptable, uuid(1d9c29dc-230a-441e-bba9-49104ffa185e)] interface inIDOMUtils : nsISupports { // CSS utilities @@ -54,6 +54,10 @@ interface inIDOMUtils : nsISupports [optional] out unsigned long aCount, [retval, array, size_is(aCount)] out wstring aProps); + // Utilities for working with CSS colors + [implicit_jscontext] + jsval colorNameToRGB(in DOMString aColorName); + // DOM Node utilities boolean isIgnorableWhitespace(in nsIDOMCharacterData aDataNode); // Returns the "parent" of a node. The parent of a document node is the diff --git a/layout/inspector/src/inDOMUtils.cpp b/layout/inspector/src/inDOMUtils.cpp index ccc0c40ccb63..4dd1597ceaa2 100644 --- a/layout/inspector/src/inDOMUtils.cpp +++ b/layout/inspector/src/inDOMUtils.cpp @@ -31,6 +31,7 @@ #include "nsRuleWalker.h" #include "nsRuleProcessorData.h" #include "nsCSSRuleProcessor.h" +#include "mozilla/dom/InspectorUtilsBinding.h" using namespace mozilla; using namespace mozilla::css; @@ -414,6 +415,27 @@ inDOMUtils::GetCSSPropertyNames(uint32_t aFlags, uint32_t* aCount, return NS_OK; } +NS_IMETHODIMP +inDOMUtils::ColorNameToRGB(const nsAString& aColorName, JSContext* aCx, + JS::Value* aValue) +{ + nscolor color; + if (!NS_ColorNameToRGB(aColorName, &color)) { + return NS_ERROR_INVALID_ARG; + } + + InspectorRGBTriple triple; + triple.mR = NS_GET_R(color); + triple.mG = NS_GET_G(color); + triple.mB = NS_GET_B(color); + + if (!triple.ToObject(aCx, nullptr, aValue)) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + NS_IMETHODIMP inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval) {