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

Side by Side Diff: chrome/browser/ui/touch/tabs/touch_tab_strip_controller.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: Fixed URL to ignore fragment and changed item handling 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/touch/tabs/touch_tab_strip_controller.h"
6
7 #include "chrome/browser/extensions/extension_tab_helper.h"
8 #include "chrome/browser/favicon/favicon_tab_helper.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/browser/ui/views/tabs/base_tab_strip.h"
13 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h"
14 #include "skia/ext/image_operations.h"
15 #include "ui/gfx/codec/png_codec.h"
16 #include "ui/gfx/favicon_size.h"
17
18 // static
sky 2011/06/10 15:38:18 Remove the comment.
Emmanuel Saint-loubert-Bié 2011/06/10 16:09:10 Done.
19 static void calc_touch_icon_target_size(int* width, int* height) {
20 if (*width > kTouchTargetIconSize || *height > kTouchTargetIconSize) {
21 // Too big, resize it maintaining the aspect ratio.
22 float aspect_ratio = static_cast<float>(*width) /
23 static_cast<float>(*height);
24 *height = kTouchTargetIconSize;
25 *width = static_cast<int>(aspect_ratio * *height);
26 if (*width > kTouchTargetIconSize) {
27 *width = kTouchTargetIconSize;
28 *height = static_cast<int>(*width / aspect_ratio);
29 }
30 }
31 }
32
33 TouchTabStripController::TouchTabStripController(Browser* browser,
34 TabStripModel* model)
35 : BrowserTabStripController(browser, model) {
36 }
37
38 TouchTabStripController::~TouchTabStripController() {
39 }
40
41 void TouchTabStripController::TabChangedAt(TabContentsWrapper* contents,
42 int model_index,
43 TabChangeType change_type) {
44 // request a large icon if needed
45 if (change_type == LOADING_ONLY) {
46 FaviconService* favicon_service = profile()->GetFaviconService(
47 Profile::EXPLICIT_ACCESS);
48 if (favicon_service) {
49 url_canon::Replacements<char> replacements;
50 replacements.ClearUsername();
51 replacements.ClearPassword();
52 replacements.ClearQuery();
53 replacements.ClearRef();
54 GURL page_url = contents->tab_contents()->GetURL().ReplaceComponents(
55 replacements);
56 if (touch_icon_map_.find(page_url) == touch_icon_map_.end()) {
57 CancelableRequestProvider::Handle h =
58 favicon_service->GetFaviconForURL(
59 page_url,
60 history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON,
61 &consumer_,
62 NewCallback(this,
63 &TouchTabStripController::OnTouchIconAvailable));
64 gurl_vector_.push_back(RequestInfo(page_url, model_index));
65 consumer_.SetClientData(favicon_service, h, gurl_vector_.size() - 1);
66 }
67 }
68 }
69 // Finally call parent's method
70 BrowserTabStripController::TabChangedAt(contents, model_index, change_type);
71 }
72
73 void TouchTabStripController::SetTabRendererDataFromModel(
74 TabContents* contents,
75 int model_index,
76 TabRendererData* data) {
77 // Call parent first
78 BrowserTabStripController::SetTabRendererDataFromModel(contents, model_index,
79 data);
80 // Lookup for a touch icon
81 if (touch_icon_map_.find(data->url) != touch_icon_map_.end()) {
82 data->favicon = touch_icon_map_[data->url];
83 }
84 }
85
86 void TouchTabStripController::OnTouchIconAvailable(
87 FaviconService::Handle h,
88 history::FaviconData favicon) {
89 if (!favicon.is_valid()) {
90 return;
91 }
92 // The decoder will leave our bitmap empty on error.
93 SkBitmap bitmap;
94 gfx::PNGCodec::Decode(favicon.image_data->front(),
95 favicon.image_data->size(),
96 &bitmap);
97 if (bitmap.isNull())
98 return;
99 // Look up the index, sIsValidIndexcale the image and update map
100 FaviconService* favicon_service = profile()->GetFaviconService(
101 Profile::EXPLICIT_ACCESS);
102 int vector_index = consumer_.GetClientData(favicon_service, h);
103 int width = bitmap.width();
104 int height = bitmap.height();
105 if (width == kTouchTargetIconSize && height == kTouchTargetIconSize) {
106 touch_icon_map_[gurl_vector_[vector_index].first] = bitmap;
107 } else {
108 calc_touch_icon_target_size(&width, &height);
109 touch_icon_map_[gurl_vector_[vector_index].first] =
110 skia::ImageOperations::Resize(bitmap,
111 skia::ImageOperations::RESIZE_BEST, width, height);
112 }
113 // refresh
114 int model_index = gurl_vector_[vector_index].second;
115 if (IsValidIndex(model_index))
116 browser_->GetTabContentsAt(model_index)->NotifyNavigationStateChanged(
117 TabContents::INVALIDATE_TAB);
118 }
119
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698