Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2480)

Unified Diff: chrome/browser/resources/shared/js/util.js

Issue 11762004: Make favicons for about:history and about:bookmarks switch from lodpi to hidpi when dragging browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/shared/js/util.js
diff --git a/chrome/browser/resources/shared/js/util.js b/chrome/browser/resources/shared/js/util.js
index 29cdd96b442971e52461f4b4c869138e24396ba5..bfe1e1482b1ff3093f7d29dc9dfc90b3c554b037 100644
--- a/chrome/browser/resources/shared/js/util.js
+++ b/chrome/browser/resources/shared/js/util.js
@@ -38,6 +38,22 @@ function chromeSend(name, params, callbackName, callback) {
}
/**
+ * Returns the scale factors supported by this platform.
+ * @return {array} The supported scale factors.
+ */
+function getSupportedScaleFactors() {
+ var supported_scale_factors = new Array();
kevers 2013/01/04 20:21:10 Using C++ naming convention here and below. Shoul
pkotwicz 2013/01/04 21:21:39 Done.
Dan Beam 2013/01/04 21:34:28 This is not just style, [] always invokes the buil
+ if (cr.isMac || cr.isChromeOS) {
+ supported_scale_factors.push(1);
+ supported_scale_factors.push(2);
+ } else {
+ // Windows must be restarted to display at a different scale factor.
+ supported_scale_factors.push(window.devicePixelRatio);
+ }
+ return supported_scale_factors;
+}
+
+/**
* Generates a CSS url string.
* @param {string} s The URL to generate the CSS url for.
* @return {string} The CSS url string.
@@ -57,6 +73,37 @@ function url(s) {
}
/**
+ * Generates a CSS -webkit-image-set for a chrome:// url.
+ * An entry in the image set is added for each of getSupportedScaleFactors().
+ * The scale-factor-specific url is generated by replacing the first instance of
+ * 'scalefactor' in |path| with the numeric scale factor.
+ * @param {string} path The URL to generate an image set for.
+ * 'scalefactor' should be a substring of |path|.
+ * @return {string} The CSS -webkit-image-set.
+ */
+function imageset(path) {
+ var supported_scale_factors = getSupportedScaleFactors();
+
+ var replace_start_index = path.indexOf('scalefactor');
+ if (replace_start_index < 0)
+ return;
+
+ var s = '';
+ for (var i = 0; i < supported_scale_factors.length; ++i) {
+ var scale_factor = supported_scale_factors[i];
+ var path_with_scale_factor =
+ path.substr(0, replace_start_index) + scale_factor +
+ path.substr(replace_start_index + 11);
+
+ s += url(path_with_scale_factor) + ' ' + scale_factor + 'x';
+
+ if (i != supported_scale_factors.length - 1)
+ s += ', ';
+ }
+ return '-webkit-image-set(' + s + ')';
+}
+
+/**
* Parses query parameters from Location.
* @param {string} location The URL to generate the CSS url for.
* @return {object} Dictionary containing name value pairs for URL
@@ -228,15 +275,32 @@ function appendParam(url, key, value) {
}
/**
- * Creates a new URL for a favicon request.
+ * Creates a CSS -webkit-image-set for a favicon request.
+ * @param {string} url The url for the favicon.
+ * @param {number=} opt_size Optional preferred size of the favicon.
+ * @param {boolean=} opt_sessionFavicon Optional flag to indicate if
+ * requesting a session favicon.
+ * @return {string} -webkit-image-set for the favicon.
+ */
+function getFaviconImageSet(url, opt_size, opt_sessionFavicon) {
+ var size = opt_size || 16;
+ var type = opt_sessionFavicon ? 'session-favicon' : 'favicon';
+ return imageset(
+ 'chrome://' + type + '/size/' + size + '@scalefactorx/' + url);
+}
+
+/**
+ * Creates a new URL for a request of the 1x favicon.
* @param {string} url The url for the favicon.
* @param {number=} opt_size Optional preferred size of the favicon.
+ * @param {boolean=} opt_sessionFavicon Optional flag to indicate if
+ * requesting a session favicon.
* @return {string} Updated URL for the favicon.
*/
-function getFaviconUrl(url, opt_size) {
+function get1xFaviconUrl(url, opt_size, opt_sessionFavicon) {
var size = opt_size || 16;
- return 'chrome://favicon/size/' + size + '@' +
- window.devicePixelRatio + 'x/' + url;
+ var type = opt_sessionFavicon ? 'session-favicon' : 'favicon';
+ return 'chrome://' + type + '/size/' + size + '@1x/' + url;
}
/**

Powered by Google App Engine
This is Rietveld 408576698