diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-21 01:05:25 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-21 01:05:25 +0000 |
commit | ae760dca3c69caf48418c00d042df9969db3581c (patch) | |
tree | 3b573039efa9e841df1f68eecf9c22b4f9936549 /chrome/browser/views/tab_icon_view.cc | |
parent | bb97536b768ac68fcbc4605c35461a798ef6e5ff (diff) | |
download | chromium_src-ae760dca3c69caf48418c00d042df9969db3581c.zip chromium_src-ae760dca3c69caf48418c00d042df9969db3581c.tar.gz chromium_src-ae760dca3c69caf48418c00d042df9969db3581c.tar.bz2 |
Fix some problems with scaled icons. This allows the TabIconView to automatically scale the throbber and favicon to whatever size the View itself is. Notably, this does NOT change tab_renderer.cc, which _also_ draws favicons -- the former is used by app windows and the latter by standard tabs. Argh! I'm not going to bother unifying these for now even though it'd be nice, since we never scale up our tabs, just our app titlebars.
BUG=5054
Review URL: http://codereview.chromium.org/18392
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8348 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/tab_icon_view.cc')
-rw-r--r-- | chrome/browser/views/tab_icon_view.cc | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/chrome/browser/views/tab_icon_view.cc b/chrome/browser/views/tab_icon_view.cc index b9af037..8f624ac 100644 --- a/chrome/browser/views/tab_icon_view.cc +++ b/chrome/browser/views/tab_icon_view.cc @@ -85,23 +85,44 @@ void TabIconView::Update() { void TabIconView::PaintThrobber(ChromeCanvas* canvas) { int image_size = g_throbber_frames->height(); - int image_offset = throbber_frame_ * image_size; - canvas->DrawBitmapInt(is_light_ ? *g_throbber_frames_light : - *g_throbber_frames, - image_offset, 0, image_size, image_size, - 0, 0, image_size, image_size, false); + PaintIcon(canvas, is_light_ ? *g_throbber_frames_light : *g_throbber_frames, + throbber_frame_ * image_size, 0, image_size, image_size, false); } void TabIconView::PaintFavIcon(ChromeCanvas* canvas, const SkBitmap& bitmap) { - int bw = bitmap.width(); - int bh = bitmap.height(); - if (bw <= kFavIconSize && bh <= kFavIconSize) { - canvas->DrawBitmapInt(bitmap, (width() - kFavIconSize) / 2, - (height() - kFavIconSize) / 2); + PaintIcon(canvas, bitmap, 0, 0, bitmap.width(), bitmap.height(), true); +} + +void TabIconView::PaintIcon(ChromeCanvas* canvas, + const SkBitmap& bitmap, + int src_x, + int src_y, + int src_w, + int src_h, + bool filter) { + // For source images smaller than the favicon square, scale them as if they + // were padded to fit the favicon square, so we don't blow up tiny favicons + // into larger or nonproportional results. + float float_src_w = static_cast<float>(src_w); + float float_src_h = static_cast<float>(src_h); + float scalable_w, scalable_h; + if (src_w <= kFavIconSize && src_h <= kFavIconSize) { + scalable_w = scalable_h = kFavIconSize; } else { - canvas->DrawBitmapInt(bitmap, 0, 0, bw, bh, 0, 0, width(), height(), - true); + scalable_w = float_src_w; + scalable_h = float_src_h; } + + // Scale proportionately. + float scale = std::min(static_cast<float>(width()) / scalable_w, + static_cast<float>(height()) / scalable_h); + int dest_w = static_cast<int>(float_src_w * scale); + int dest_h = static_cast<int>(float_src_h * scale); + + // Center the scaled image. + canvas->DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, + (width() - dest_w) / 2, (height() - dest_h) / 2, dest_w, + dest_h, filter); } void TabIconView::Paint(ChromeCanvas* canvas) { |