Add a helper function in PlacesUIUtils.jsm to cater to HiDPI favicon display with #-moz-resolution=w,h

This commit is contained in:
wolfbeast 2018-06-06 14:24:03 +02:00 committed by Roy Tam
commit 302f069f68
2 changed files with 33 additions and 3 deletions

View file

@ -1136,6 +1136,33 @@ this.PlacesUIUtils = {
}
}
return queryName;
},
/**
* Returns the passed URL with a #moz-resolution fragment
* for the specified dimensions and devicePixelRatio.
*
* @param aWindow
* A window from where we want to get the device
* pixel Ratio
*
* @param aURL
* The URL where we should add the fragment
*
* @param aWidth
* The target image width
*
* @param aHeight
* The target image height
*
* @return The URL with the fragment at the end
*/
getImageURLForResolution:
function PUIU_getImageURLForResolution(aWindow, aURL, aWidth = 16, aHeight = 16) {
let width = Math.round(aWidth * aWindow.devicePixelRatio);
let height = Math.round(aHeight * aWindow.devicePixelRatio);
return aURL + (aURL.contains("#") ? "&" : "#") +
"-moz-resolution=" + width + "," + height;
}
};

View file

@ -338,7 +338,8 @@ PlacesViewBase.prototype = {
let icon = aPlacesNode.icon;
if (icon)
element.setAttribute("image", icon);
element.setAttribute("image",
PlacesUIUtils.getImageURLForResolution(window, icon));
}
element._placesNode = aPlacesNode;
@ -464,7 +465,8 @@ PlacesViewBase.prototype = {
if (!icon)
elt.removeAttribute("image");
else if (icon != elt.getAttribute("image"))
elt.setAttribute("image", icon);
elt.setAttribute("image",
PlacesUIUtils.getImageURLForResolution(window, icon));
},
nodeAnnotationChanged:
@ -966,7 +968,8 @@ PlacesToolbar.prototype = {
button.setAttribute("label", aChild.title || "");
let icon = aChild.icon;
if (icon)
button.setAttribute("image", icon);
button.setAttribute("image",
PlacesUIUtils.getImageURLForResolution(window, icon));
if (PlacesUtils.containerTypes.indexOf(type) != -1) {
button.setAttribute("type", "menu");