Commit 77c69963 authored by finnur@chromium.org's avatar finnur@chromium.org

Don't scale up small browser action icons.

When creating the canvas, take cues from the image we
just loaded and don't hard code it to 19x19. This way
we can have smaller than 19x19 icons that show up
centered within the browser icon button.

This doesn't attempt to deal with scaling down images
that are too large to fit the 19x19 canvas, but we
haven't decided how to handle those anyway.

BUG=25487
TEST=Load the api_test/browser_action_tab_specific_state
extension and click on the browser action. The red
square within the button should not grow in size as you
click.

Review URL: http://codereview.chromium.org/337026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30072 0039d316-1c4b-4281-b951-d872f2087c98
parent d665d12d
......@@ -364,20 +364,17 @@ var chrome = chrome || {};
}
sendCustomRequest(SetExtensionActionIcon, name, [details], parameters);
} else if ("path" in details) {
if (!canvas) {
var canvas = document.createElement("canvas");
canvas.width = 19;
canvas.height = 19;
}
var canvas_context = canvas.getContext('2d');
var img = new Image();
var self = this;
img.onerror = function() {
console.error("Could not load browser action icon '" + details.path +
"'.");
}
img.onload = function() {
var canvas = document.createElement("canvas");
canvas.width = img.width > 19 ? 19 : img.width;
canvas.height = img.height > 19 ? 19 : img.height;
var canvas_context = canvas.getContext('2d');
canvas_context.clearRect(0, 0, canvas.width, canvas.height);
canvas_context.drawImage(img, 0, 0, canvas.width, canvas.height);
delete details.path;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment