Bug 1424963: Replace remaining consumers of getPropertyCSSValue for getCSSImageURLs. r=florian,bz

The context-menu change is technically not idempotent, since something like:

  background-image: url(foo), linear-gradient(..);

Would throw before. But that didn't seem like a great deal to me.

MozReview-Commit-ID: 70pD1EyXDB
This commit is contained in:
Emilio Cobos Álvarez 2018-03-08 20:02:05 +01:00
Родитель 6400343bb7
Коммит b17e217c07
2 изменённых файлов: 20 добавлений и 30 удалений

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

@ -960,29 +960,20 @@ var PageInfoListener = {
}; };
if (computedStyle) { if (computedStyle) {
let addImgFunc = (label, val) => { let addImgFunc = (label, urls) => {
if (val.primitiveType == content.CSSPrimitiveValue.CSS_URI) { for (let url of urls) {
addImage(val.getStringValue(), label, strings.notSet, elem, true);
} else if (val.primitiveType == content.CSSPrimitiveValue.CSS_STRING) {
// This is for -moz-image-rect.
// TODO: Reimplement once bug 714757 is fixed.
let strVal = val.getStringValue();
if (strVal.search(/^.*url\(\"?/) > -1) {
let url = strVal.replace(/^.*url\(\"?/, "").replace(/\"?\).*$/, "");
addImage(url, label, strings.notSet, elem, true); addImage(url, label, strings.notSet, elem, true);
} }
} else if (val.cssValueType == content.CSSValue.CSS_VALUE_LIST) {
// Recursively resolve multiple nested CSS value lists.
for (let i = 0; i < val.length; i++) {
addImgFunc(label, val.item(i));
}
}
}; };
// FIXME: This is missing properties. See the implementation of
addImgFunc(strings.mediaBGImg, computedStyle.getPropertyCSSValue("background-image")); // getCSSImageURLs for a list of properties.
addImgFunc(strings.mediaBorderImg, computedStyle.getPropertyCSSValue("border-image-source")); //
addImgFunc(strings.mediaListImg, computedStyle.getPropertyCSSValue("list-style-image")); // If you don't care about the message you can also pass "all" here and
addImgFunc(strings.mediaCursor, computedStyle.getPropertyCSSValue("cursor")); // get all the ones the browser knows about.
addImgFunc(strings.mediaBGImg, computedStyle.getCSSImageURLs("background-image"));
addImgFunc(strings.mediaBorderImg, computedStyle.getCSSImageURLs("border-image-source"));
addImgFunc(strings.mediaListImg, computedStyle.getCSSImageURLs("list-style-image"));
addImgFunc(strings.mediaCursor, computedStyle.getCSSImageURLs("cursor"));
} }
// One swi^H^H^Hif-else to rule them all. // One swi^H^H^Hif-else to rule them all.

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

@ -376,18 +376,17 @@ class ContextMenu {
// Returns a "url"-type computed style attribute value, with the url() stripped. // Returns a "url"-type computed style attribute value, with the url() stripped.
_getComputedURL(aElem, aProp) { _getComputedURL(aElem, aProp) {
let url = aElem.ownerGlobal.getComputedStyle(aElem).getPropertyCSSValue(aProp); let urls = aElem.ownerGlobal.getComputedStyle(aElem).getCSSImageURLs(aProp);
if (url instanceof this.content.CSSValueList) { if (!urls.length) {
if (url.length != 1) { return null;
}
if (urls.length != 1) {
throw "found multiple URLs"; throw "found multiple URLs";
} }
url = url[0]; return urls[0];
}
return url.primitiveType == this.content.CSSPrimitiveValue.CSS_URI ?
url.getStringValue() : null;
} }
_makeURLAbsolute(aBase, aUrl) { _makeURLAbsolute(aBase, aUrl) {