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

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: ' 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/touch/tabs/touch_tab.h"
13 #include "chrome/browser/ui/views/tabs/base_tab_strip.h"
14 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h"
15 #include "skia/ext/image_operations.h"
16 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/favicon_size.h"
18
19 // static
sky 2011/06/16 15:43:41 Only use '// static' for class member definitions.
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done. My bad this was a cut and paste from ui/gfx/
20 static void calc_touch_icon_target_size(int* width, int* height) {
tfarina 2011/06/16 15:52:44 Also wrap these static/private functions into an u
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Thanks, also a cut and paste from ui/gfx/favicon_s
21 if (*width > kTouchTargetIconSize || *height > kTouchTargetIconSize) {
22 // Too big, resize it maintaining the aspect ratio.
23 float aspect_ratio = static_cast<float>(*width) /
24 static_cast<float>(*height);
25 *height = kTouchTargetIconSize;
26 *width = static_cast<int>(aspect_ratio * *height);
27 if (*width > kTouchTargetIconSize) {
28 *width = kTouchTargetIconSize;
29 *height = static_cast<int>(*width / aspect_ratio);
30 }
31 }
32 }
33
34 // static
35 static GURL gurl_without_fragment(const GURL& gurl)
tfarina 2011/06/16 15:52:44 the function name should be CamelCase.
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
36 {
sky 2011/06/16 15:43:41 { on 35.
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
37 url_canon::Replacements<char> replacements;
38 replacements.ClearUsername();
39 replacements.ClearPassword();
40 replacements.ClearQuery();
41 replacements.ClearRef();
42 return gurl.ReplaceComponents(replacements);
43 }
44
45 TouchTabStripController::TouchTabStripController(Browser* browser,
46 TabStripModel* model)
47 : BrowserTabStripController(browser, model) {
48 }
49
50 TouchTabStripController::~TouchTabStripController() {
51 }
52
53 void TouchTabStripController::TabChangedAt(TabContentsWrapper* contents,
54 int model_index,
55 TabChangeType change_type) {
56 // Clear the large icon if we are loading a different URL in the same tab.
57 if (change_type == LOADING_ONLY) {
58 BaseTab* tab = tabstrip_->GetBaseTabAtModelIndex(model_index);
sky 2011/06/16 15:43:41 You do this cast a couple of times. You should add
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
59 TouchTab* touch_tab = static_cast<TouchTab*>(tab);
60 if (touch_tab && !touch_tab->get_touch_icon().isNull()) {
sky 2011/06/16 15:43:41 You shouldn't have to check touch_tab. If you feel
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
61 GURL existing_tab_url = gurl_without_fragment(touch_tab->data().url);
62 GURL page_url = gurl_without_fragment(contents->tab_contents()->GetURL());
63 // reset touch icon if the url are different
64 if (existing_tab_url != page_url)
65 touch_tab->set_touch_icon(SkBitmap());
66 }
67 }
68
69 // Always 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 bool new_tab) {
78 // Call parent first.
79 BrowserTabStripController::SetTabRendererDataFromModel(contents, model_index,
80 data, new_tab);
sky 2011/06/16 15:43:41 indent to align with ( on 79.
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
81 if (new_tab)
82 return;
83
84 // Use the touch icon if any.
85 BaseTab* tab = tabstrip_->GetBaseTabAtModelIndex(model_index);
86 TouchTab* touch_tab = static_cast<TouchTab*>(tab);
87 if (touch_tab && !touch_tab->get_touch_icon().isNull()) {
88 data->favicon = touch_tab->get_touch_icon();
89 return;
90 }
91
92 // Request touch icon.
93 TabContentsWrapper* wrapper =
94 TabContentsWrapper::GetCurrentWrapperForContents(contents);
95 GURL page_url = gurl_without_fragment(wrapper->tab_contents()->GetURL());
sky 2011/06/16 15:43:41 Remove wrapper and change this to: gurl_wihout_fra
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
96 FaviconService* favicon_service = profile()->GetFaviconService(
97 Profile::EXPLICIT_ACCESS);
98 if (favicon_service) {
99 CancelableRequestProvider::Handle h =
100 favicon_service->GetFaviconForURL(
101 page_url,
102 history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON,
103 &consumer_,
104 NewCallback(this, &TouchTabStripController::OnTouchIconAvailable));
105 consumer_.SetClientData(favicon_service, h, touch_tab);
106 }
107 }
108
109 void TouchTabStripController::OnTouchIconAvailable(
110 FaviconService::Handle h,
111 history::FaviconData favicon) {
112 // Abandon the request when there is no valid favicon.
113 if (!favicon.is_valid())
114 return;
115
116 // Retrieve the model_index from the TouchTab pointer received.
117 FaviconService* favicon_service = profile()->GetFaviconService(
118 Profile::EXPLICIT_ACCESS);
119 TouchTab* touch_tab = consumer_.GetClientData(favicon_service, h);
sky 2011/06/16 15:43:41 117-119 can be replaced with consumer_.GetClientDa
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
120 int model_index = tabstrip_->GetModelIndexOfBaseTab(touch_tab);
121 if (model_index == -1 || !IsValidIndex(model_index))
122 return;
123
124 // Try to decode the favicon, return on failure.
125 SkBitmap bitmap;
126 gfx::PNGCodec::Decode(favicon.image_data->front(),
127 favicon.image_data->size(),
sky 2011/06/16 15:43:41 nit: align 127,128 with ( on 126.
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Done.
128 &bitmap);
129 if (bitmap.isNull())
130 return;
131
132 // Rescale output, if needed, and assign to the TouchTab instance.
133 int width = bitmap.width();
134 int height = bitmap.height();
135 if (width == kTouchTargetIconSize && height == kTouchTargetIconSize) {
136 touch_tab->set_touch_icon(bitmap);
137 } else {
138 calc_touch_icon_target_size(&width, &height);
139 touch_tab->set_touch_icon(skia::ImageOperations::Resize(bitmap,
140 skia::ImageOperations::RESIZE_BEST, width, height));
141 }
142
143 // Refresh UI since favicon changed
144 browser_->GetTabContentsAt(model_index)->NotifyNavigationStateChanged(
sky 2011/06/16 15:43:41 I believe instead of this you want: touch_tab->Sch
Emmanuel Saint-loubert-Bié 2011/06/17 00:01:44 Actually that does not cause the refresh, so I lef
145 TabContents::INVALIDATE_TAB);
146 }
147
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698