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

Side by Side Diff: chrome/browser/views/tab_icon_view.cc

Issue 18392: Fix some problems with scaled icons. This allows the TabIconView to automati... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 #include <shellapi.h> 6 #include <shellapi.h>
7 7
8 #include "chrome/browser/views/tab_icon_view.h" 8 #include "chrome/browser/views/tab_icon_view.h"
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // We didn't think we were loading, but the tab is loading. Reset the 78 // We didn't think we were loading, but the tab is loading. Reset the
79 // frame and status and schedule a paint. 79 // frame and status and schedule a paint.
80 throbber_running_ = true; 80 throbber_running_ = true;
81 throbber_frame_ = 0; 81 throbber_frame_ = 0;
82 SchedulePaint(); 82 SchedulePaint();
83 } 83 }
84 } 84 }
85 85
86 void TabIconView::PaintThrobber(ChromeCanvas* canvas) { 86 void TabIconView::PaintThrobber(ChromeCanvas* canvas) {
87 int image_size = g_throbber_frames->height(); 87 int image_size = g_throbber_frames->height();
88 int image_offset = throbber_frame_ * image_size; 88 PaintIcon(canvas, is_light_ ? *g_throbber_frames_light : *g_throbber_frames,
89 canvas->DrawBitmapInt(is_light_ ? *g_throbber_frames_light : 89 throbber_frame_ * image_size, 0, image_size, image_size, false);
90 *g_throbber_frames,
91 image_offset, 0, image_size, image_size,
92 0, 0, image_size, image_size, false);
93 } 90 }
94 91
95 void TabIconView::PaintFavIcon(ChromeCanvas* canvas, const SkBitmap& bitmap) { 92 void TabIconView::PaintFavIcon(ChromeCanvas* canvas, const SkBitmap& bitmap) {
96 int bw = bitmap.width(); 93 PaintIcon(canvas, bitmap, 0, 0, bitmap.width(), bitmap.height(), true);
sky 2009/01/21 00:53:22 To match the old code you should only pass in true
Peter Kasting 2009/01/21 01:00:36 If we aren't scaling, we won't be resampling, and
97 int bh = bitmap.height(); 94 }
98 if (bw <= kFavIconSize && bh <= kFavIconSize) { 95
99 canvas->DrawBitmapInt(bitmap, (width() - kFavIconSize) / 2, 96 void TabIconView::PaintIcon(ChromeCanvas* canvas,
100 (height() - kFavIconSize) / 2); 97 const SkBitmap& bitmap,
98 int src_x,
99 int src_y,
100 int src_w,
101 int src_h,
102 bool filter) {
103 // For source images smaller than the favicon square, scale them as if they
104 // were padded to fit the favicon square, so we don't blow up tiny favicons
105 // into larger or nonproportional results.
106 float float_src_w = static_cast<float>(src_w);
107 float float_src_h = static_cast<float>(src_h);
108 float scalable_w, scalable_h;
109 if (src_w <= kFavIconSize && src_h <= kFavIconSize) {
110 scalable_w = scalable_h = kFavIconSize;
101 } else { 111 } else {
102 canvas->DrawBitmapInt(bitmap, 0, 0, bw, bh, 0, 0, width(), height(), 112 scalable_w = float_src_w;
103 true); 113 scalable_h = float_src_h;
104 } 114 }
115
116 // Scale proportionately.
117 float scale = std::min(static_cast<float>(width()) / scalable_w,
118 static_cast<float>(height()) / scalable_h);
119 int dest_w = static_cast<int>(float_src_w * scale);
120 int dest_h = static_cast<int>(float_src_h * scale);
121
122 // Center the scaled image.
123 canvas->DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h,
124 (width() - dest_w) / 2, (height() - dest_h) / 2, dest_w,
125 dest_h, filter);
105 } 126 }
106 127
107 void TabIconView::Paint(ChromeCanvas* canvas) { 128 void TabIconView::Paint(ChromeCanvas* canvas) {
108 bool rendered = false; 129 bool rendered = false;
109 130
110 if (throbber_running_) { 131 if (throbber_running_) {
111 rendered = true; 132 rendered = true;
112 PaintThrobber(canvas); 133 PaintThrobber(canvas);
113 } else { 134 } else {
114 SkBitmap favicon = model_->GetFavIconForTabIconView(); 135 SkBitmap favicon = model_->GetFavIconForTabIconView();
115 if (!favicon.isNull()) { 136 if (!favicon.isNull()) {
116 rendered = true; 137 rendered = true;
117 PaintFavIcon(canvas, favicon); 138 PaintFavIcon(canvas, favicon);
118 } 139 }
119 } 140 }
120 141
121 if (!rendered) 142 if (!rendered)
122 PaintFavIcon(canvas, *g_default_fav_icon); 143 PaintFavIcon(canvas, *g_default_fav_icon);
123 } 144 }
124 145
125 gfx::Size TabIconView::GetPreferredSize() { 146 gfx::Size TabIconView::GetPreferredSize() {
126 return gfx::Size(kFavIconSize, kFavIconSize); 147 return gfx::Size(kFavIconSize, kFavIconSize);
127 } 148 }
128 149
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698