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

Side by Side Diff: chrome/browser/ui/touch/tabs/touch_tab.cc

Issue 7065052: Improve large tab strip by leveraging touch icons when present (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ' Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/touch/tabs/touch_tab.h" 5 #include "chrome/browser/ui/touch/tabs/touch_tab.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/themes/theme_service.h" 8 #include "chrome/browser/themes/theme_service.h"
9 #include "grit/app_resources.h" 9 #include "grit/app_resources.h"
10 #include "grit/theme_resources.h" 10 #include "grit/theme_resources.h"
11 #include "grit/theme_resources_standard.h" 11 #include "grit/theme_resources_standard.h"
12 #include "skia/ext/image_operations.h"
12 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/canvas_skia.h" 14 #include "ui/gfx/canvas_skia.h"
14 #include "ui/gfx/favicon_size.h" 15 #include "ui/gfx/favicon_size.h"
15 #include "ui/gfx/path.h" 16 #include "ui/gfx/path.h"
16 #include "ui/gfx/skbitmap_operations.h" 17 #include "ui/gfx/skbitmap_operations.h"
17 18
18 static const int kLeftPadding = 16; 19 static const int kLeftPadding = 16;
19 static const int kRightPadding = 15; 20 static const int kRightPadding = 15;
20 static const int kDropShadowHeight = 2; 21 static const int kDropShadowHeight = 2;
21 22
22 // The size of the favicon touch area. This generally would be the same as
23 // kFaviconSize in ui/gfx/favicon_size.h
24 static const int kTouchTabIconSize = 32;
25
26 TouchTab::TouchTabImage TouchTab::tab_alpha = {0}; 23 TouchTab::TouchTabImage TouchTab::tab_alpha = {0};
27 TouchTab::TouchTabImage TouchTab::tab_active = {0}; 24 TouchTab::TouchTabImage TouchTab::tab_active = {0};
28 TouchTab::TouchTabImage TouchTab::tab_inactive = {0}; 25 TouchTab::TouchTabImage TouchTab::tab_inactive = {0};
29 26
30 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
31 // TouchTab, public: 28 // TouchTab, public:
32 29
33 TouchTab::TouchTab(TabController* controller) 30 TouchTab::TouchTab(TabController* controller)
34 : BaseTab(controller) { 31 : BaseTab(controller) {
35 InitTabResources(); 32 InitTabResources();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 170
174 // Now draw the highlights/shadows around the tab edge. 171 // Now draw the highlights/shadows around the tab edge.
175 canvas->DrawBitmapInt(*tab_image->image_l, 0, y_base); 172 canvas->DrawBitmapInt(*tab_image->image_l, 0, y_base);
176 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, y_base, 173 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, y_base,
177 width() - tab_image->l_width - tab_image->r_width, image_height); 174 width() - tab_image->l_width - tab_image->r_width, image_height);
178 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 175 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width,
179 y_base); 176 y_base);
180 } 177 }
181 178
182 void TouchTab::PaintIcon(gfx::Canvas* canvas) { 179 void TouchTab::PaintIcon(gfx::Canvas* canvas) {
183 // TODO(wyck): use thumbnailer to get better page images
184 int x = favicon_bounds_.x(); 180 int x = favicon_bounds_.x();
185 int y = favicon_bounds_.y(); 181 int y = favicon_bounds_.y();
186 182
187 TouchTabImage* tab_image = &tab_active; 183 TouchTabImage* tab_image = &tab_active;
188 int x_base = tab_image->image_l->width(); 184 int x_base = tab_image->image_l->width();
189 185
190 x += x_base; 186 x += x_base;
191 187
192 if (base::i18n::IsRTL()) { 188 if (base::i18n::IsRTL()) {
193 x = width() - x - 189 x = width() - x - (data().favicon.isNull()
194 (data().favicon.isNull() ? kFaviconSize : data().favicon.width()); 190 ? kTouchTargetIconSize : data().favicon.width());
195 } 191 }
196 192
197 int favicon_x = x;
198 if (!data().favicon.isNull() && data().favicon.width() != kFaviconSize)
199 favicon_x += (data().favicon.width() - kFaviconSize) / 2;
200
201 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { 193 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
202 ui::ThemeProvider* tp = GetThemeProvider(); 194 ui::ThemeProvider* tp = GetThemeProvider();
203 SkBitmap frames(*tp->GetBitmapNamed( 195 SkBitmap frames(*tp->GetBitmapNamed(
204 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? 196 (data().network_state == TabRendererData::NETWORK_STATE_WAITING)
205 IDR_THROBBER_WAITING : IDR_THROBBER)); 197 ? IDR_THROBBER_WAITING : IDR_THROBBER));
206 int image_size = frames.height(); 198 int image_size = frames.height();
207 int image_offset = loading_animation_frame() * image_size; 199 int image_offset = loading_animation_frame() * image_size;
208 canvas->DrawBitmapInt(frames, image_offset, 0, image_size, image_size, x, y, 200 canvas->DrawBitmapInt(frames, image_offset, 0, image_size, image_size, x,
209 kTouchTabIconSize, kTouchTabIconSize, false); 201 y, kTouchTargetIconSize, kTouchTargetIconSize, false);
210 } else { 202 } else {
211 canvas->Save(); 203 canvas->Save();
212 canvas->ClipRectInt(0, 0, width(), height()); 204 canvas->ClipRectInt(0, 0, width(), height());
213 if (should_display_crashed_favicon()) { 205 if (should_display_crashed_favicon()) {
214 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 206 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
215 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON)); 207 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON));
216 canvas->DrawBitmapInt(crashed_favicon, 0, 0, crashed_favicon.width(), 208 canvas->DrawBitmapInt(crashed_favicon, 0, 0, crashed_favicon.width(),
217 crashed_favicon.height(), x, y + favicon_hiding_offset(), 209 crashed_favicon.height(), x, y + favicon_hiding_offset(),
218 kTouchTabIconSize, kTouchTabIconSize, true); 210 kTouchTargetIconSize, kTouchTargetIconSize, true);
219 } else { 211 } else {
220 if (!data().favicon.isNull()) { 212 if (!data().favicon.isNull()) {
221 213 // At this stage small favicons (16x16) are copied from NavigationEntry
222 if ((data().favicon.width() == kTouchTabIconSize) && 214 // and need to be scaled every time, touch icons on the other hand
223 (data().favicon.height() == kTouchTabIconSize)) { 215 // should have been rescaled properly (to 32x32) in method:
224 canvas->DrawBitmapInt(data().favicon, 0, 0, 216 // TouchTabStripController::OnTouchIconAvailable().
225 data().favicon.width(), data().favicon.height(), 217 if (data().favicon.width() == kFaviconSize
226 x, y + favicon_hiding_offset(), 218 && data().favicon.height() == kFaviconSize) {
sky 2011/06/16 15:43:41 && should be on the previous line. Also, you shoul
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
227 kTouchTabIconSize, kTouchTabIconSize, true); 219 SkBitmap scaled_image = skia::ImageOperations::Resize(data().favicon,
220 skia::ImageOperations::RESIZE_BEST, kTouchTargetIconSize,
221 kTouchTargetIconSize);
222 canvas->DrawBitmapInt(scaled_image, 0, 0, kTouchTargetIconSize,
223 kTouchTargetIconSize, x, y + favicon_hiding_offset(),
224 kTouchTargetIconSize, kTouchTargetIconSize, true);
228 } else { 225 } else {
229 // Draw a background around target touch area in case the favicon
230 // is smaller than touch area (e.g www.google.com is 16x16 now)
231 canvas->DrawRectInt(
232 GetThemeProvider()->GetColor(
233 ThemeService::COLOR_BUTTON_BACKGROUND),
234 x, y, kTouchTabIconSize, kTouchTabIconSize);
235
236 // We center the image
237 // TODO(saintlou): later request larger image from HistoryService
238 canvas->DrawBitmapInt(data().favicon, 0, 0, data().favicon.width(), 226 canvas->DrawBitmapInt(data().favicon, 0, 0, data().favicon.width(),
239 data().favicon.height(), 227 data().favicon.height(), x, y + favicon_hiding_offset(),
240 x + ((kTouchTabIconSize - data().favicon.width()) / 2), 228 kTouchTargetIconSize, kTouchTargetIconSize, true);
241 y + ((kTouchTabIconSize - data().favicon.height()) / 2) +
242 favicon_hiding_offset(),
243 data().favicon.width(), data().favicon.height(), true);
244 } 229 }
245 } 230 }
246 } 231 }
247 canvas->Restore(); 232 canvas->Restore();
248 } 233 }
249 } 234 }
250 235
251 // static 236 // static
252 void TouchTab::InitTabResources() { 237 void TouchTab::InitTabResources() {
253 static bool initialized = false; 238 static bool initialized = false;
254 if (initialized) 239 if (initialized)
255 return; 240 return;
256 241
257 initialized = true; 242 initialized = true;
258 243
259 // Load the tab images once now, and maybe again later if the theme changes. 244 // Load the tab images once now, and maybe again later if the theme changes.
260 LoadTabImages(); 245 LoadTabImages();
261 } 246 }
262 247
263
264 // static 248 // static
265 void TouchTab::LoadTabImages() { 249 void TouchTab::LoadTabImages() {
266 // We're not letting people override tab images just yet. 250 // We're not letting people override tab images just yet.
267 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 251 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
268 252
269 tab_alpha.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); 253 tab_alpha.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT);
270 tab_alpha.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); 254 tab_alpha.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT);
271 255
272 tab_active.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); 256 tab_active.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT);
273 tab_active.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER); 257 tab_active.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER);
274 tab_active.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); 258 tab_active.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT);
275 tab_active.l_width = tab_active.image_l->width(); 259 tab_active.l_width = tab_active.image_l->width();
276 tab_active.r_width = tab_active.image_r->width(); 260 tab_active.r_width = tab_active.image_r->width();
277 261
278 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 262 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT);
279 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); 263 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER);
280 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); 264 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT);
281 tab_inactive.l_width = tab_inactive.image_l->width(); 265 tab_inactive.l_width = tab_inactive.image_l->width();
282 tab_inactive.r_width = tab_inactive.image_r->width(); 266 tab_inactive.r_width = tab_inactive.image_r->width();
283 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698