| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/tab_icon_view.h" | 5 #include "chrome/browser/ui/views/tab_icon_view.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/ui/views/tab_icon_view_model.h" | 15 #include "chrome/browser/ui/views/tab_icon_view_model.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/base/theme_provider.h" | 18 #include "ui/base/theme_provider.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/favicon_size.h" | 20 #include "ui/gfx/favicon_size.h" |
| 21 #include "ui/resources/grit/ui_resources.h" | 21 #include "ui/resources/grit/ui_resources.h" |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "chrome/browser/app_icon_win.h" | 24 #include "chrome/browser/app_icon_win.h" |
| 25 #include "ui/gfx/icon_util.h" | 25 #include "ui/gfx/icon_util.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 static bool g_initialized = false; | 28 namespace { |
| 29 static gfx::ImageSkia* g_default_favicon = NULL; | 29 |
| 30 bool g_initialized = false; |
| 31 gfx::ImageSkia* g_default_favicon = nullptr; |
| 32 |
| 33 } // namespace |
| 30 | 34 |
| 31 // static | 35 // static |
| 32 void TabIconView::InitializeIfNeeded() { | 36 void TabIconView::InitializeIfNeeded() { |
| 33 if (!g_initialized) { | 37 if (!g_initialized) { |
| 34 g_initialized = true; | 38 g_initialized = true; |
| 35 | 39 |
| 36 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 37 // The default window icon is the application icon, not the default | 41 // The default window icon is the application icon, not the default |
| 38 // favicon. | 42 // favicon. |
| 39 HICON app_icon = GetAppIcon(); | 43 HICON app_icon = GetAppIcon(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 static_cast<float>(height()) / scalable_h); | 134 static_cast<float>(height()) / scalable_h); |
| 131 int dest_w = static_cast<int>(float_src_w * scale); | 135 int dest_w = static_cast<int>(float_src_w * scale); |
| 132 int dest_h = static_cast<int>(float_src_h * scale); | 136 int dest_h = static_cast<int>(float_src_h * scale); |
| 133 | 137 |
| 134 // Center the scaled image. | 138 // Center the scaled image. |
| 135 canvas->DrawImageInt(image, src_x, src_y, src_w, src_h, | 139 canvas->DrawImageInt(image, src_x, src_y, src_w, src_h, |
| 136 (width() - dest_w) / 2, (height() - dest_h) / 2, dest_w, | 140 (width() - dest_w) / 2, (height() - dest_h) / 2, dest_w, |
| 137 dest_h, filter); | 141 dest_h, filter); |
| 138 } | 142 } |
| 139 | 143 |
| 144 gfx::Size TabIconView::GetPreferredSize() const { |
| 145 return gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
| 146 } |
| 147 |
| 148 const char* TabIconView::GetClassName() const { |
| 149 return "TabIconView"; |
| 150 } |
| 151 |
| 140 void TabIconView::OnPaint(gfx::Canvas* canvas) { | 152 void TabIconView::OnPaint(gfx::Canvas* canvas) { |
| 141 bool rendered = false; | 153 bool rendered = false; |
| 142 | 154 |
| 143 if (throbber_running_) { | 155 if (throbber_running_) { |
| 144 rendered = true; | 156 rendered = true; |
| 145 PaintThrobber(canvas); | 157 PaintThrobber(canvas); |
| 146 } else { | 158 } else { |
| 147 gfx::ImageSkia favicon = model_->GetFaviconForTabIconView(); | 159 gfx::ImageSkia favicon = model_->GetFaviconForTabIconView(); |
| 148 if (!favicon.isNull()) { | 160 if (!favicon.isNull()) { |
| 149 rendered = true; | 161 rendered = true; |
| 150 PaintFavicon(canvas, favicon); | 162 PaintFavicon(canvas, favicon); |
| 151 } | 163 } |
| 152 } | 164 } |
| 153 | 165 |
| 154 if (!rendered) | 166 if (!rendered) |
| 155 PaintFavicon(canvas, *g_default_favicon); | 167 PaintFavicon(canvas, *g_default_favicon); |
| 156 } | 168 } |
| 157 | |
| 158 gfx::Size TabIconView::GetPreferredSize() const { | |
| 159 return gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | |
| 160 } | |
| OLD | NEW |