Bug 848745 part 1. Add a scriptable API for converting CSS color names to RGB triples. r=dbaron,miker

This commit is contained in:
Boris Zbarsky 2013-03-14 15:43:00 -04:00
parent 9aa75cd3a1
commit 29e37ca132
5 changed files with 45 additions and 1 deletions

View File

@ -13,6 +13,7 @@ interface DummyInterface {
RTCConfiguration rtcConfiguration();
CFStateChangeEventDict cfstateChangeEvent();
USSDReceivedEventDict ussdReceivedEvent();
InspectorRGBTriple rgbTriple();
};
interface DummyInterfaceWorkers {

View File

@ -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;
};

View File

@ -119,6 +119,7 @@ webidl_files = \
HTMLUListElement.webidl \
IDBVersionChangeEvent.webidl \
ImageData.webidl \
InspectorUtils.webidl \
LinkStyle.webidl \
LocalMediaStream.webidl \
Location.webidl \

View File

@ -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

View File

@ -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)
{