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) {
let addImgFunc = (label, val) => {
if (val.primitiveType == content.CSSPrimitiveValue.CSS_URI) {
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);
}
} 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));
}
let addImgFunc = (label, urls) => {
for (let url of urls) {
addImage(url, label, strings.notSet, elem, true);
}
};
addImgFunc(strings.mediaBGImg, computedStyle.getPropertyCSSValue("background-image"));
addImgFunc(strings.mediaBorderImg, computedStyle.getPropertyCSSValue("border-image-source"));
addImgFunc(strings.mediaListImg, computedStyle.getPropertyCSSValue("list-style-image"));
addImgFunc(strings.mediaCursor, computedStyle.getPropertyCSSValue("cursor"));
// FIXME: This is missing properties. See the implementation of
// getCSSImageURLs for a list of properties.
//
// If you don't care about the message you can also pass "all" here and
// 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.

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

@ -376,18 +376,17 @@ class ContextMenu {
// Returns a "url"-type computed style attribute value, with the url() stripped.
_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 (url.length != 1) {
throw "found multiple URLs";
}
url = url[0];
if (!urls.length) {
return null;
}
return url.primitiveType == this.content.CSSPrimitiveValue.CSS_URI ?
url.getStringValue() : null;
if (urls.length != 1) {
throw "found multiple URLs";
}
return urls[0];
}
_makeURLAbsolute(aBase, aUrl) {