Bug 482941 - make 'View Background Image' handle background-image lists. r=mano

This commit is contained in:
Dão Gottwald 2009-09-23 11:07:12 +02:00
parent ef0718cef5
commit a8f534133a

View File

@ -253,8 +253,8 @@ nsContextMenu.prototype = {
this.setItemAttr("context-viewvideo", "disabled", !this.mediaURL);
// View background image depends on whether there is one.
this.showItem("context-viewbgimage", shouldShow);
this.showItem("context-sep-viewbgimage", shouldShow);
this.showItem("context-viewbgimage", shouldShow && !this._hasMultipleBGImages);
this.showItem("context-sep-viewbgimage", shouldShow && !this._hasMultipleBGImages);
document.getElementById("context-viewbgimage")
.disabled = !this.hasBGImage;
},
@ -522,7 +522,13 @@ nsContextMenu.prototype = {
else if (this.target instanceof HTMLHtmlElement) {
var bodyElt = this.target.ownerDocument.body;
if (bodyElt) {
var computedURL = this.getComputedURL(bodyElt, "background-image");
let computedURL;
try {
computedURL = this.getComputedURL(bodyElt, "background-image");
this._hasMultipleBGImages = false;
} catch (e) {
this._hasMultipleBGImages = true;
}
if (computedURL) {
this.hasBGImage = true;
this.bgImageURL = makeURLAbsolute(bodyElt.baseURI,
@ -576,8 +582,15 @@ nsContextMenu.prototype = {
// Background image? Don't bother if we've already found a
// background image further down the hierarchy. Otherwise,
// we look for the computed background-image style.
if (!this.hasBGImage) {
var bgImgUrl = this.getComputedURL( elem, "background-image" );
if (!this.hasBGImage &&
!this._hasMultipleBGImages) {
let bgImgUrl;
try {
bgImgUrl = this.getComputedURL(elem, "background-image");
this._hasMultipleBGImages = false;
} catch (e) {
this._hasMultipleBGImages = true;
}
if (bgImgUrl) {
this.hasBGImage = true;
this.bgImageURL = makeURLAbsolute(elem.baseURI,
@ -651,6 +664,11 @@ nsContextMenu.prototype = {
var url = aElem.ownerDocument
.defaultView.getComputedStyle(aElem, "")
.getPropertyCSSValue(aProp);
if (url instanceof CSSValueList) {
if (url.length != 1)
throw "found multiple URLs";
url = url[0];
}
return url.primitiveType == CSSPrimitiveValue.CSS_URI ?
url.getStringValue() : null;
},