Bug 1427419 - Part 9: Move inIDOMUtils.getCSSValuesForProperty to InspectorUtils. r=bz

MozReview-Commit-ID: D3jf42KI7kO
This commit is contained in:
Cameron McCormack 2018-01-11 12:38:00 +08:00
Родитель 1a8d3bfd54
Коммит f5ef2d0a72
8 изменённых файлов: 50 добавлений и 53 удалений

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

@ -15,6 +15,7 @@ const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUt
const {colorUtils} = require("devtools/shared/css/color");
const {cssColors} = require("devtools/shared/css/color-db");
const InspectorUtils = require("InspectorUtils");
function isValid(colorName) {
ok(colorUtils.isValidCSSColor(colorName),
@ -52,7 +53,7 @@ function run_test() {
// Now check that platform didn't add a new name when we weren't
// looking.
let names = DOMUtils.getCSSValuesForProperty("background-color");
let names = InspectorUtils.getCSSValuesForProperty("background-color");
for (let name of names) {
if (name !== "hsl" && name !== "hsla" &&
name !== "rgb" && name !== "rgba" &&

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

@ -59,7 +59,7 @@ function generateCssProperties() {
}
// Don't send colors over RDP, these will be re-attached by the front.
let values = DOMUtils.getCSSValuesForProperty(name);
let values = InspectorUtils.getCSSValuesForProperty(name);
if (values.includes("aliceblue")) {
values = values.filter(x => !colors.includes(x));
values.unshift("COLOR");

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

@ -31,6 +31,7 @@ namespace InspectorUtils {
[TreatNullAs=EmptyString] optional DOMString pseudo = "");
boolean isInheritedProperty(DOMString property);
sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options);
[Throws] sequence<DOMString> getCSSValuesForProperty(DOMString property);
};
dictionary PropertyNamesOptions {

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

@ -109,6 +109,12 @@ public:
const PropertyNamesOptions& aOptions,
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);
private:
static already_AddRefed<nsStyleContext>
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);

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

@ -804,19 +804,23 @@ inDOMUtils::CssPropertySupportsType(const nsAString& aProperty, uint32_t aType,
return NS_OK;
}
NS_IMETHODIMP
inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
uint32_t* aLength,
char16_t*** aValues)
namespace mozilla {
namespace dom {
/* static */ void
InspectorUtils::GetCSSValuesForProperty(GlobalObject& aGlobalObject,
const nsAString& aProperty,
nsTArray<nsString>& aResult,
ErrorResult& aRv)
{
nsCSSPropertyID propertyID = nsCSSProps::
LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) {
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsTArray<nsString> array;
// We start collecting the values, BUT colors need to go in first, because array
// We start collecting the values, BUT colors need to go in first, because aResult
// needs to stay sorted, and the colors are sorted, so we just append them.
if (propertyID == eCSSPropertyExtra_variable) {
// No other values we can report.
@ -824,9 +828,9 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
// Property is longhand.
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(propertyID);
// Get colors first.
GetColorsForProperty(propertyParserVariant, array);
GetKeywordsForProperty(propertyID, array);
GetOtherValuesForProperty(propertyParserVariant, array);
GetColorsForProperty(propertyParserVariant, aResult);
GetKeywordsForProperty(propertyID, aResult);
GetOtherValuesForProperty(propertyParserVariant, aResult);
} else {
// Property is shorthand.
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
@ -834,32 +838,26 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
// Get colors (once) first.
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
if (propertyParserVariant & VARIANT_COLOR) {
GetColorsForProperty(propertyParserVariant, array);
GetColorsForProperty(propertyParserVariant, aResult);
break;
}
}
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
CSSEnabledState::eForAllContent) {
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
GetKeywordsForProperty(*subproperty, array);
GetOtherValuesForProperty(propertyParserVariant, array);
GetKeywordsForProperty(*subproperty, aResult);
GetOtherValuesForProperty(propertyParserVariant, aResult);
}
}
// All CSS properties take initial, inherit and unset.
InsertNoDuplicates(array, NS_LITERAL_STRING("initial"));
InsertNoDuplicates(array, NS_LITERAL_STRING("inherit"));
InsertNoDuplicates(array, NS_LITERAL_STRING("unset"));
*aLength = array.Length();
char16_t** ret =
static_cast<char16_t**>(moz_xmalloc(*aLength * sizeof(char16_t*)));
for (uint32_t i = 0; i < *aLength; ++i) {
ret[i] = ToNewUnicode(array[i]);
}
*aValues = ret;
return NS_OK;
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::ColorNameToRGB(const nsAString& aColorName, JSContext* aCx,
JS::MutableHandle<JS::Value> aValue)

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

@ -20,11 +20,6 @@ interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
// Get a list of all valid keywords and colors for aProperty.
void getCSSValuesForProperty(in AString aProperty,
[optional] out unsigned long aLength,
[array, size_is(aLength), retval] out wstring aValues);
// Utilities for working with CSS colors
[implicit_jscontext]
jsval colorNameToRGB(in DOMString aColorName);

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

@ -12,6 +12,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=877690
/** Test for Bug 877690 **/
const InspectorUtils = SpecialPowers.InspectorUtils;
// Returns true if values contains all and only the expected values. False otherwise.
function testValues(values, expected) {
values.sort();
@ -30,16 +32,9 @@ function testValues(values, expected) {
}
function do_test() {
var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(SpecialPowers.Ci.inIDOMUtils);
var getCSSValuesForProperty = function(prop) {
return Array.from(utils.getCSSValuesForProperty(prop));
}
// test a property with keywords and colors
var prop = "color";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
"beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood",
"cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "currentColor",
@ -65,7 +60,7 @@ function do_test() {
// test a shorthand property
var prop = "background";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
"beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue",
"chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "currentColor", "cyan", "darkblue",
@ -94,7 +89,7 @@ function do_test() {
ok(testValues(values, expected), "Shorthand property values.");
var prop = "border";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "unset", "aliceblue",
"antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet",
"brown", "burlywood", "cadetblue", "calc", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk",
@ -123,7 +118,7 @@ function do_test() {
// test keywords only
var prop = "border-top";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "thin", "medium", "thick", "none", "hidden", "dotted",
"dashed", "solid", "double", "groove", "ridge", "inset", "outset",
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black",
@ -150,13 +145,13 @@ function do_test() {
// tests no keywords or colors
var prop = "padding-bottom";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "calc" ];
ok(testValues(values, expected), "property padding-bottom's values.");
// test proprety
var prop = "display";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "none", "inline", "block", "inline-block", "list-item",
"table", "inline-table", "table-row-group", "table-header-group", "table-footer-group", "table-row",
"table-column-group", "table-column", "table-cell", "table-caption", "-moz-box", "-moz-inline-box",
@ -171,25 +166,25 @@ function do_test() {
// test property
var prop = "float";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "none", "left", "right", "inline-start", "inline-end" ];
ok(testValues(values, expected), "property float's values.");
// Test property with "auto"
var prop = "margin";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "unset", "auto", "calc", "inherit" ];
ok(testValues(values, expected), "property margin's values.");
// Test property with "normal"
var prop = "font-style";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "inherit", "unset", "italic", "normal", "oblique" ];
ok(testValues(values, expected), "property font-style's values.");
// Test property with "cubic-bezier" and "step".
var prop = "-moz-transition";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "initial", "all", "unset", "cubic-bezier", "ease", "ease-in", "ease-in-out",
"ease-out", "inherit", "linear", "none", "step-end", "step-start",
"steps" ];
@ -198,7 +193,7 @@ function do_test() {
// test invalid property
var prop = "invalidProperty";
try {
getCSSValuesForProperty(prop);
InspectorUtils.getCSSValuesForProperty(prop);
ok(false, "invalid property should throw an exception");
}
catch(e) {
@ -207,12 +202,12 @@ function do_test() {
// test border-image property, for bug 973345
var prop = "border-image";
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "inherit", "initial", "unset", "repeat", "stretch", "-moz-element", "-moz-image-rect", "url", "linear-gradient", "radial-gradient", "repeating-linear-gradient", "repeating-radial-gradient", "-moz-linear-gradient", "-moz-radial-gradient", "-moz-repeating-linear-gradient", "-moz-repeating-radial-gradient", "fill", "none", "round", "space" ];
ok(testValues(values, expected), "property border-image's values.");
var prop = "background-size"
var values = getCSSValuesForProperty(prop);
var values = InspectorUtils.getCSSValuesForProperty(prop);
var expected = [ "inherit", "initial", "unset", "contain", "cover" ];
ok(testValues(values, expected), "property background-size's values.");

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

@ -6,11 +6,12 @@
<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 = utils.getCSSValuesForProperty("color");
let colors = InspectorUtils.getCSSValuesForProperty("color");
let notColor = ["hsl", "hsla", "inherit", "initial", "rgb", "rgba",
"unset", "transparent", "currentColor"];
for (let color of colors) {