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 1377f40c4ff2a4f5bc90832f9e6182a6104189dd..c3e8d35dfe789aa150554b421f4f7c99dc9f00dd 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 supportedScaleFactors = []; |
+ if (cr.isMac || cr.isChromeOS) { |
+ supportedScaleFactors.push(1); |
+ supportedScaleFactors.push(2); |
+ } else { |
+ // Windows must be restarted to display at a different scale factor. |
+ supportedScaleFactors.push(window.devicePixelRatio); |
+ } |
+ return supportedScaleFactors; |
+} |
+ |
+/** |
* 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,36 @@ 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 supportedScaleFactors = getSupportedScaleFactors(); |
+ |
+ var replaceStartIndex = path.indexOf('scalefactor'); |
+ if (replaceStartIndex < 0) |
+ return url(path); |
+ |
+ var s = ''; |
+ for (var i = 0; i < supportedScaleFactors.length; ++i) { |
+ var scaleFactor = supportedScaleFactors[i]; |
+ var pathWithScaleFactor = path.substr(0, replaceStartIndex) + scaleFactor + |
+ path.substr(replaceStartIndex + 11); |
Evan Stade
2013/01/04 21:43:44
what is this magic 11? use 'scalefactor'.length
pkotwicz
2013/01/04 23:06:53
Done.
|
+ |
+ s += url(pathWithScaleFactor) + ' ' + scaleFactor + 'x'; |
Evan Stade
2013/01/04 21:43:44
indentation is wrong here
pkotwicz
2013/01/04 23:06:53
Done.
|
+ |
+ if (i != supportedScaleFactors.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,18 +274,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, opt_sessionFavicon) { |
+function get1xFaviconUrl(url, opt_size, opt_sessionFavicon) { |
Evan Stade
2013/01/04 21:43:44
not a fan of this function name. Can you call it U
pkotwicz
2013/01/04 23:06:53
Renamed to getFaviconUrlForDevicePixelRatio().
Did
|
var size = opt_size || 16; |
var type = opt_sessionFavicon ? 'session-favicon' : 'favicon'; |
- return 'chrome://' + type + '/size/' + size + '@' + |
- window.devicePixelRatio + 'x/' + url; |
+ return 'chrome://' + type + '/size/' + size + '@1x/' + url; |
} |
/** |