From 8a2398db94348282dd2635b11cc44660c66a0baa Mon Sep 17 00:00:00 2001 From: "Bernardo P. Rittmeyer" Date: Thu, 31 Jul 2014 19:29:57 -0700 Subject: [PATCH] Bug 951396 - Bookmark toolbar now can show icons in HiDPI resolution using a new helper function in PlacesUIUtils.jsm. r=MattN,mak --- browser/components/places/PlacesUIUtils.jsm | 27 +++++++++++++++++++ .../places/content/browserPlacesViews.js | 12 ++++++--- .../components/places/nsFaviconService.cpp | 7 ++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/browser/components/places/PlacesUIUtils.jsm b/browser/components/places/PlacesUIUtils.jsm index 3bcdd7a6c8c6..bcf5cd691bf9 100644 --- a/browser/components/places/PlacesUIUtils.jsm +++ b/browser/components/places/PlacesUIUtils.jsm @@ -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", diff --git a/browser/components/places/content/browserPlacesViews.js b/browser/components/places/content/browserPlacesViews.js index bb17a5c7a0d6..ef02a7e0e43c 100644 --- a/browser/components/places/content/browserPlacesViews.js +++ b/browser/components/places/content/browserPlacesViews.js @@ -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"); diff --git a/toolkit/components/places/nsFaviconService.cpp b/toolkit/components/places/nsFaviconService.cpp index 2306c96375cb..389c8c230308 100644 --- a/toolkit/components/places/nsFaviconService.cpp +++ b/toolkit/components/places/nsFaviconService.cpp @@ -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 pendingStatement;