Bug 1427419 - Part 13: Move inIDOMUtils.isValidCSSColor to InspectorUtils. r=bz

MozReview-Commit-ID: DNRfmbDucdT
This commit is contained in:
Cameron McCormack 2018-01-11 12:38:00 +08:00
Родитель 664c1757c0
Коммит 0ef012043a
8 изменённых файлов: 53 добавлений и 56 удалений

Просмотреть файл

@ -6,13 +6,9 @@
"use strict";
var Cu = Components.utils;
var Ci = Components.interfaces;
var Cc = Components.classes;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
const {colorUtils} = require("devtools/shared/css/color");
const {cssColors} = require("devtools/shared/css/color-db");
const InspectorUtils = require("InspectorUtils");
@ -20,8 +16,8 @@ const InspectorUtils = require("InspectorUtils");
function isValid(colorName) {
ok(colorUtils.isValidCSSColor(colorName),
colorName + " is valid in database");
ok(DOMUtils.isValidCSSColor(colorName),
colorName + " is valid in DOMUtils");
ok(InspectorUtils.isValidCSSColor(colorName),
colorName + " is valid in InspectorUtils");
}
function checkOne(colorName, checkName) {

Просмотреть файл

@ -31,7 +31,7 @@ exports.CssPropertiesActor = ActorClassWithSpec(cssPropertiesSpec, {
const pseudoElements = DOMUtils.getCSSPseudoElementNames();
const supportedFeature = {
// checking for css-color-4 color function support.
"css-color-4-color-function": DOMUtils.isValidCSSColor("rgb(1 1 1 / 100%)"),
"css-color-4-color-function": InspectorUtils.isValidCSSColor("rgb(1 1 1 / 100%)"),
};
return { properties, pseudoElements, supportedFeature };

Просмотреть файл

@ -9,9 +9,12 @@
'use strict';
const {
classes: Cc,
interfaces: Ci
interfaces: Ci,
utils: Cu
} = Components;
Cu.importGlobalProperties(["InspectorUtils"]);
function ValueExtractor(aConsole, aBundle) {
this.console = aConsole;
this.domBundle = aBundle;
@ -48,10 +51,8 @@ ValueExtractor.prototype = {
},
extractColorValue(spec) {
const value = this.extractValue(spec);
const DOMUtils = Cc['@mozilla.org/inspector/dom-utils;1']
.getService(Ci.inIDOMUtils);
let color;
if (DOMUtils.isValidCSSColor(value)) {
if (InspectorUtils.isValidCSSColor(value)) {
color = value;
} else if (value) {
this.console.warn(this.domBundle.formatStringFromName("ManifestInvalidCSSColor",

Просмотреть файл

@ -34,6 +34,7 @@ namespace InspectorUtils {
[Throws] sequence<DOMString> getCSSValuesForProperty(DOMString property);
[Throws] DOMString rgbToColorName(octet r, octet g, octet b);
InspectorRGBATuple? colorToRGBA(DOMString colorString);
boolean isValidCSSColor(DOMString colorString);
};
dictionary PropertyNamesOptions {

Просмотреть файл

@ -130,6 +130,10 @@ public:
const nsAString& aColorString,
Nullable<InspectorRGBATuple>& aResult);
// Check whether a given color is a valid CSS color.
static bool IsValidCSSColor(GlobalObject& aGlobal,
const nsAString& aColorString);
private:
static already_AddRefed<nsStyleContext>
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);

Просмотреть файл

@ -903,22 +903,22 @@ InspectorUtils::ColorToRGBA(GlobalObject& aGlobalObject,
tuple.mA = nsStyleUtil::ColorComponentToFloat(NS_GET_A(color));
}
} // namespace dom
} // namespace mozilla
NS_IMETHODIMP
inDOMUtils::IsValidCSSColor(const nsAString& aColorString, bool *_retval)
/* static */ bool
InspectorUtils::IsValidCSSColor(GlobalObject& aGlobalObject,
const nsAString& aColorString)
{
#ifdef MOZ_STYLO
*_retval = ServoCSSParser::IsValidCSSColor(aColorString);
return ServoCSSParser::IsValidCSSColor(aColorString);
#else
nsCSSParser cssParser;
nsCSSValue cssValue;
*_retval = cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true);
return cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true);
#endif
return NS_OK;
}
} // namespace dom
} // namespace mozilla
NS_IMETHODIMP
inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval)
{

Просмотреть файл

@ -20,9 +20,6 @@ interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
// Check whether a given color is a valid CSS color.
bool isValidCSSColor(in AString aColorString);
// Utilities for obtaining information about a CSS property.
// Get a list of the longhands corresponding to the given CSS property. If

Просмотреть файл

@ -2,13 +2,11 @@
<html>
<head>
<meta charset="utf-8">
<title>Test inDOMUtils::isValidCSSColor</title>
<title>Test InspectorUtils::isValidCSSColor</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
const InspectorUtils = SpecialPowers.InspectorUtils;
let utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(SpecialPowers.Ci.inIDOMUtils);
// Color names
let colors = InspectorUtils.getCSSValuesForProperty("color");
@ -18,46 +16,46 @@
if (notColor.indexOf(color) !== -1) {
continue;
}
ok(utils.isValidCSSColor(color), color + " is a valid color");
ok(!utils.isValidCSSColor("xxx" + color), "xxx" + color + " is not a valid color");
ok(InspectorUtils.isValidCSSColor(color), color + " is a valid color");
ok(!InspectorUtils.isValidCSSColor("xxx" + color), "xxx" + color + " is not a valid color");
}
// rgb(a)
for (let i = 0; i <= 265; i++) {
ok(utils.isValidCSSColor("rgb(" + i + ",0,0)"), "rgb(" + i + ",0,0) is a valid color");
ok(utils.isValidCSSColor("rgb(0," + i + ",0)"), "rgb(0," + i + ",0) is a valid color");
ok(utils.isValidCSSColor("rgb(0,0," + i + ")"), "rgb(0,0," + i + ") is a valid color");
ok(utils.isValidCSSColor("rgba(" + i + ",0,0,0.2)"), "rgba(" + i + ",0,0,0.2) is a valid color");
ok(utils.isValidCSSColor("rgba(0," + i + ",0,0.5)"), "rgba(0," + i + ",0,0.5) is a valid color");
ok(utils.isValidCSSColor("rgba(0,0," + i + ",0.7)"), "rgba(0,0," + i + ",0.7) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgb(" + i + ",0,0)"), "rgb(" + i + ",0,0) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgb(0," + i + ",0)"), "rgb(0," + i + ",0) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgb(0,0," + i + ")"), "rgb(0,0," + i + ") is a valid color");
ok(InspectorUtils.isValidCSSColor("rgba(" + i + ",0,0,0.2)"), "rgba(" + i + ",0,0,0.2) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgba(0," + i + ",0,0.5)"), "rgba(0," + i + ",0,0.5) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgba(0,0," + i + ",0.7)"), "rgba(0,0," + i + ",0.7) is a valid color");
ok(!utils.isValidCSSColor("rgbxxx(" + i + ",0,0)"), "rgbxxx(" + i + ",0,0) is not a valid color");
ok(!utils.isValidCSSColor("rgbxxx(0," + i + ",0)"), "rgbxxx(0," + i + ",0) is not a valid color");
ok(!utils.isValidCSSColor("rgbxxx(0,0," + i + ")"), "rgbxxx(0,0," + i + ") is not a valid color");
ok(!InspectorUtils.isValidCSSColor("rgbxxx(" + i + ",0,0)"), "rgbxxx(" + i + ",0,0) is not a valid color");
ok(!InspectorUtils.isValidCSSColor("rgbxxx(0," + i + ",0)"), "rgbxxx(0," + i + ",0) is not a valid color");
ok(!InspectorUtils.isValidCSSColor("rgbxxx(0,0," + i + ")"), "rgbxxx(0,0," + i + ") is not a valid color");
}
// rgb(a) (%)
for (let i = 0; i <= 110; i++) {
ok(utils.isValidCSSColor("rgb(" + i + "%,0%,0%)"), "rgb(" + i + "%,0%,0%) is a valid color");
ok(utils.isValidCSSColor("rgb(0%," + i + "%,0%)"), "rgb(0%," + i + "%,0%) is a valid color");
ok(utils.isValidCSSColor("rgb(0%,0%," + i + "%)"), "rgb(0%,0%," + i + "%) is a valid color");
ok(utils.isValidCSSColor("rgba(" + i + "%,0%,0%,0.2)"), "rgba(" + i + "%,0%,0%,0.2) is a valid color");
ok(utils.isValidCSSColor("rgba(0%," + i + "%,0%,0.5)"), "rgba(0%," + i + "%,0%,0.5) is a valid color");
ok(utils.isValidCSSColor("rgba(0%,0%," + i + "%,0.7)"), "rgba(0%,0%," + i + "%,0.7) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgb(" + i + "%,0%,0%)"), "rgb(" + i + "%,0%,0%) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgb(0%," + i + "%,0%)"), "rgb(0%," + i + "%,0%) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgb(0%,0%," + i + "%)"), "rgb(0%,0%," + i + "%) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgba(" + i + "%,0%,0%,0.2)"), "rgba(" + i + "%,0%,0%,0.2) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgba(0%," + i + "%,0%,0.5)"), "rgba(0%," + i + "%,0%,0.5) is a valid color");
ok(InspectorUtils.isValidCSSColor("rgba(0%,0%," + i + "%,0.7)"), "rgba(0%,0%," + i + "%,0.7) is a valid color");
ok(!utils.isValidCSSColor("rgbaxxx(" + i + "%,0%,0%,0.2)"), "rgbaxxx(" + i + "%,0%,0%,0.2) is not a valid color");
ok(!utils.isValidCSSColor("rgbaxxx(0%," + i + "%,0%,0.5)"), "rgbaxxx(0%," + i + "%,0%,0.5) is not a valid color");
ok(!utils.isValidCSSColor("rgbaxxx(0%,0%," + i + "%,0.7)"), "rgbaxxx(0%,0%," + i + "%,0.7) is not a valid color");
ok(!InspectorUtils.isValidCSSColor("rgbaxxx(" + i + "%,0%,0%,0.2)"), "rgbaxxx(" + i + "%,0%,0%,0.2) is not a valid color");
ok(!InspectorUtils.isValidCSSColor("rgbaxxx(0%," + i + "%,0%,0.5)"), "rgbaxxx(0%," + i + "%,0%,0.5) is not a valid color");
ok(!InspectorUtils.isValidCSSColor("rgbaxxx(0%,0%," + i + "%,0.7)"), "rgbaxxx(0%,0%," + i + "%,0.7) is not a valid color");
}
// hsl(a)
for (let i = 0; i <= 370; i++) {
ok(utils.isValidCSSColor("hsl(" + i + ",30%,10%)"), "rgb(" + i + ",30%,10%) is a valid color");
ok(utils.isValidCSSColor("hsla(" + i + ",60%,70%,0.2)"), "rgba(" + i + ",60%,70%,0.2) is a valid color");
ok(InspectorUtils.isValidCSSColor("hsl(" + i + ",30%,10%)"), "rgb(" + i + ",30%,10%) is a valid color");
ok(InspectorUtils.isValidCSSColor("hsla(" + i + ",60%,70%,0.2)"), "rgba(" + i + ",60%,70%,0.2) is a valid color");
}
for (let i = 0; i <= 110; i++) {
ok(utils.isValidCSSColor("hsl(100," + i + "%,20%)"), "hsl(100," + i + "%,20%) is a valid color");
ok(utils.isValidCSSColor("hsla(100,20%," + i + "%,0.6)"), "hsla(100,20%," + i + "%,0.6) is a valid color");
ok(InspectorUtils.isValidCSSColor("hsl(100," + i + "%,20%)"), "hsl(100," + i + "%,20%) is a valid color");
ok(InspectorUtils.isValidCSSColor("hsla(100,20%," + i + "%,0.6)"), "hsla(100,20%," + i + "%,0.6) is a valid color");
}
// hex
@ -66,22 +64,22 @@
if (hex.length === 1) {
hex = 0 + hex;
}
ok(utils.isValidCSSColor("#" + hex + "7777"), "#" + hex + "7777 is a valid color");
ok(utils.isValidCSSColor("#77" + hex + "77"), "#77" + hex + "77 is a valid color");
ok(utils.isValidCSSColor("#7777" + hex), "#7777" + hex + " is a valid color");
ok(InspectorUtils.isValidCSSColor("#" + hex + "7777"), "#" + hex + "7777 is a valid color");
ok(InspectorUtils.isValidCSSColor("#77" + hex + "77"), "#77" + hex + "77 is a valid color");
ok(InspectorUtils.isValidCSSColor("#7777" + hex), "#7777" + hex + " is a valid color");
}
ok(!utils.isValidCSSColor("#kkkkkk"), "#kkkkkk is not a valid color");
ok(!InspectorUtils.isValidCSSColor("#kkkkkk"), "#kkkkkk is not a valid color");
// short hex
for (let i = 0; i <= 16; i++) {
let hex = (i).toString(16);
ok(utils.isValidCSSColor("#" + hex + hex + hex), "#" + hex + hex + hex + " is a valid color");
ok(InspectorUtils.isValidCSSColor("#" + hex + hex + hex), "#" + hex + hex + hex + " is a valid color");
}
ok(!utils.isValidCSSColor("#ggg"), "#ggg is not a valid color");
ok(!InspectorUtils.isValidCSSColor("#ggg"), "#ggg is not a valid color");
</script>
</head>
<body>
<h1>Test inDOMUtils::isValidCSSColor</h1>
<h1>Test InspectorUtils::isValidCSSColor</h1>
<p id="display"></p>
<div id="content" style="display: none">