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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc
diff --git a/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc b/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a6b17b6edb5006727e4875e403e64beb9169c27a
--- /dev/null
+++ b/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc
@@ -0,0 +1,119 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/touch/tabs/touch_tab_strip_controller.h"
+
+#include "chrome/browser/extensions/extension_tab_helper.h"
+#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/views/tabs/base_tab_strip.h"
+#include "chrome/browser/ui/views/tabs/tab_renderer_data.h"
+#include "skia/ext/image_operations.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/favicon_size.h"
+
+// static
sky 2011/06/10 15:38:18 Remove the comment.
Emmanuel Saint-loubert-Bié 2011/06/10 16:09:10 Done.
+static void calc_touch_icon_target_size(int* width, int* height) {
+ if (*width > kTouchTargetIconSize || *height > kTouchTargetIconSize) {
+ // Too big, resize it maintaining the aspect ratio.
+ float aspect_ratio = static_cast<float>(*width) /
+ static_cast<float>(*height);
+ *height = kTouchTargetIconSize;
+ *width = static_cast<int>(aspect_ratio * *height);
+ if (*width > kTouchTargetIconSize) {
+ *width = kTouchTargetIconSize;
+ *height = static_cast<int>(*width / aspect_ratio);
+ }
+ }
+}
+
+TouchTabStripController::TouchTabStripController(Browser* browser,
+ TabStripModel* model)
+ : BrowserTabStripController(browser, model) {
+}
+
+TouchTabStripController::~TouchTabStripController() {
+}
+
+void TouchTabStripController::TabChangedAt(TabContentsWrapper* contents,
+ int model_index,
+ TabChangeType change_type) {
+ // request a large icon if needed
+ if (change_type == LOADING_ONLY) {
+ FaviconService* favicon_service = profile()->GetFaviconService(
+ Profile::EXPLICIT_ACCESS);
+ if (favicon_service) {
+ url_canon::Replacements<char> replacements;
+ replacements.ClearUsername();
+ replacements.ClearPassword();
+ replacements.ClearQuery();
+ replacements.ClearRef();
+ GURL page_url = contents->tab_contents()->GetURL().ReplaceComponents(
+ replacements);
+ if (touch_icon_map_.find(page_url) == touch_icon_map_.end()) {
+ CancelableRequestProvider::Handle h =
+ favicon_service->GetFaviconForURL(
+ page_url,
+ history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON,
+ &consumer_,
+ NewCallback(this,
+ &TouchTabStripController::OnTouchIconAvailable));
+ gurl_vector_.push_back(RequestInfo(page_url, model_index));
+ consumer_.SetClientData(favicon_service, h, gurl_vector_.size() - 1);
+ }
+ }
+ }
+ // Finally call parent's method
+ BrowserTabStripController::TabChangedAt(contents, model_index, change_type);
+}
+
+void TouchTabStripController::SetTabRendererDataFromModel(
+ TabContents* contents,
+ int model_index,
+ TabRendererData* data) {
+ // Call parent first
+ BrowserTabStripController::SetTabRendererDataFromModel(contents, model_index,
+ data);
+ // Lookup for a touch icon
+ if (touch_icon_map_.find(data->url) != touch_icon_map_.end()) {
+ data->favicon = touch_icon_map_[data->url];
+ }
+}
+
+void TouchTabStripController::OnTouchIconAvailable(
+ FaviconService::Handle h,
+ history::FaviconData favicon) {
+ if (!favicon.is_valid()) {
+ return;
+ }
+ // The decoder will leave our bitmap empty on error.
+ SkBitmap bitmap;
+ gfx::PNGCodec::Decode(favicon.image_data->front(),
+ favicon.image_data->size(),
+ &bitmap);
+ if (bitmap.isNull())
+ return;
+ // Look up the index, sIsValidIndexcale the image and update map
+ FaviconService* favicon_service = profile()->GetFaviconService(
+ Profile::EXPLICIT_ACCESS);
+ int vector_index = consumer_.GetClientData(favicon_service, h);
+ int width = bitmap.width();
+ int height = bitmap.height();
+ if (width == kTouchTargetIconSize && height == kTouchTargetIconSize) {
+ touch_icon_map_[gurl_vector_[vector_index].first] = bitmap;
+ } else {
+ calc_touch_icon_target_size(&width, &height);
+ touch_icon_map_[gurl_vector_[vector_index].first] =
+ skia::ImageOperations::Resize(bitmap,
+ skia::ImageOperations::RESIZE_BEST, width, height);
+ }
+ // refresh
+ int model_index = gurl_vector_[vector_index].second;
+ if (IsValidIndex(model_index))
+ browser_->GetTabContentsAt(model_index)->NotifyNavigationStateChanged(
+ TabContents::INVALIDATE_TAB);
+}
+

Powered by Google App Engine
This is Rietveld 408576698