mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 951396 - Bookmark toolbar now can show icons in HiDPI resolution using a new helper function in PlacesUIUtils.jsm. r=MattN,mak
This commit is contained in:
parent
8e634cc8d6
commit
8a2398db94
@ -1014,6 +1014,33 @@ this.PlacesUIUtils = {
|
||||
Weave.Service.engineManager.get("tabs") &&
|
||||
Weave.Service.engineManager.get("tabs").enabled;
|
||||
},
|
||||
|
||||
/**
|
||||
* 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;
|
||||
},
|
||||
};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUIUtils, "RDF",
|
||||
|
@ -362,7 +362,8 @@ PlacesViewBase.prototype = {
|
||||
|
||||
let icon = aPlacesNode.icon;
|
||||
if (icon)
|
||||
element.setAttribute("image", icon);
|
||||
element.setAttribute("image",
|
||||
PlacesUIUtils.getImageURLForResolution(window, icon));
|
||||
}
|
||||
|
||||
element._placesNode = aPlacesNode;
|
||||
@ -500,7 +501,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:
|
||||
@ -1016,7 +1018,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");
|
||||
@ -1840,7 +1843,8 @@ PlacesPanelMenuView.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("container", "true");
|
||||
|
@ -579,7 +579,12 @@ nsFaviconService::GetFaviconDataAsync(nsIURI* aFaviconURI,
|
||||
);
|
||||
NS_ENSURE_STATE(stmt);
|
||||
|
||||
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"), aFaviconURI);
|
||||
// Ignore the ref part of the URI before querying the database because
|
||||
// we may have added the #-moz-resolution ref for rendering purposes.
|
||||
|
||||
nsAutoCString faviconURI;
|
||||
aFaviconURI->GetSpecIgnoringRef(faviconURI);
|
||||
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"), faviconURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<mozIStoragePendingStatement> pendingStatement;
|
||||
|
Loading…
Reference in New Issue
Block a user