OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/tab_icon_view.h" | 5 #include "chrome/browser/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 "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "app/theme_provider.h" |
13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "chrome/app/chrome_dll_resource.h" | 16 #include "chrome/app/chrome_dll_resource.h" |
16 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
17 #include "gfx/canvas.h" | 18 #include "gfx/canvas.h" |
18 #include "gfx/favicon_size.h" | 19 #include "gfx/favicon_size.h" |
19 #include "grit/app_resources.h" | 20 #include "grit/app_resources.h" |
20 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
21 | 22 |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 #include "chrome/browser/app_icon_win.h" | 24 #include "chrome/browser/app_icon_win.h" |
24 #include "gfx/icon_util.h" | 25 #include "gfx/icon_util.h" |
25 #endif | 26 #endif |
26 | 27 |
27 static bool g_initialized = false; | 28 static bool g_initialized = false; |
28 static SkBitmap* g_default_fav_icon = NULL; | 29 static SkBitmap* g_default_fav_icon = NULL; |
29 static SkBitmap* g_throbber_frames = NULL; | |
30 static SkBitmap* g_throbber_frames_light = NULL; | |
31 static int g_throbber_frame_count; | |
32 | 30 |
33 // static | 31 // static |
34 void TabIconView::InitializeIfNeeded() { | 32 void TabIconView::InitializeIfNeeded() { |
35 if (!g_initialized) { | 33 if (!g_initialized) { |
36 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 34 g_initialized = true; |
37 | 35 |
38 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
39 // The default window icon is the application icon, not the default | 37 // The default window icon is the application icon, not the default |
40 // favicon. | 38 // favicon. |
41 HICON app_icon = GetAppIcon(); | 39 HICON app_icon = GetAppIcon(); |
42 g_default_fav_icon = | 40 g_default_fav_icon = |
43 IconUtil::CreateSkBitmapFromHICON(app_icon, gfx::Size(16, 16)); | 41 IconUtil::CreateSkBitmapFromHICON(app_icon, gfx::Size(16, 16)); |
44 DestroyIcon(app_icon); | 42 DestroyIcon(app_icon); |
45 #else | 43 #else |
46 g_default_fav_icon = rb.GetBitmapNamed(IDR_PRODUCT_LOGO_16); | 44 g_default_fav_icon = |
| 45 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_PRODUCT_LOGO_16); |
47 #endif | 46 #endif |
48 | |
49 g_throbber_frames = rb.GetBitmapNamed(IDR_THROBBER); | |
50 g_throbber_frames_light = rb.GetBitmapNamed(IDR_THROBBER_LIGHT); | |
51 g_throbber_frame_count = g_throbber_frames->width() / | |
52 g_throbber_frames->height(); | |
53 | |
54 // Verify that our light and dark styles have the same number of frames. | |
55 DCHECK(g_throbber_frame_count == | |
56 g_throbber_frames_light->width() / g_throbber_frames_light->height()); | |
57 g_initialized = true; | |
58 } | 47 } |
59 } | 48 } |
60 | 49 |
61 TabIconView::TabIconView(TabIconViewModel* model) | 50 TabIconView::TabIconView(TabIconViewModel* model) |
62 : model_(model), | 51 : model_(model), |
63 throbber_running_(false), | 52 throbber_running_(false), |
64 is_light_(false), | 53 is_light_(false), |
65 throbber_frame_(0) { | 54 throbber_frame_(0) { |
66 InitializeIfNeeded(); | 55 InitializeIfNeeded(); |
67 } | 56 } |
68 | 57 |
69 TabIconView::~TabIconView() { | 58 TabIconView::~TabIconView() { |
70 } | 59 } |
71 | 60 |
72 void TabIconView::Update() { | 61 void TabIconView::Update() { |
| 62 static bool initialized = false; |
| 63 static int throbber_frame_count = 0; |
| 64 if (!initialized) { |
| 65 initialized = true; |
| 66 SkBitmap throbber( |
| 67 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_THROBBER)); |
| 68 throbber_frame_count = throbber.width() / throbber.height(); |
| 69 } |
| 70 |
73 if (throbber_running_) { | 71 if (throbber_running_) { |
74 // We think the tab is loading. | 72 // We think the tab is loading. |
75 if (!model_->ShouldTabIconViewAnimate()) { | 73 if (!model_->ShouldTabIconViewAnimate()) { |
76 // Woops, tab is invalid or not loading, reset our status and schedule | 74 // Woops, tab is invalid or not loading, reset our status and schedule |
77 // a paint. | 75 // a paint. |
78 throbber_running_ = false; | 76 throbber_running_ = false; |
79 SchedulePaint(); | 77 SchedulePaint(); |
80 } else { | 78 } else { |
81 // The tab is still loading, increment the frame. | 79 // The tab is still loading, increment the frame. |
82 throbber_frame_ = (throbber_frame_ + 1) % g_throbber_frame_count; | 80 throbber_frame_ = (throbber_frame_ + 1) % throbber_frame_count; |
83 SchedulePaint(); | 81 SchedulePaint(); |
84 } | 82 } |
85 } else if (model_->ShouldTabIconViewAnimate()) { | 83 } else if (model_->ShouldTabIconViewAnimate()) { |
86 // We didn't think we were loading, but the tab is loading. Reset the | 84 // We didn't think we were loading, but the tab is loading. Reset the |
87 // frame and status and schedule a paint. | 85 // frame and status and schedule a paint. |
88 throbber_running_ = true; | 86 throbber_running_ = true; |
89 throbber_frame_ = 0; | 87 throbber_frame_ = 0; |
90 SchedulePaint(); | 88 SchedulePaint(); |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 void TabIconView::PaintThrobber(gfx::Canvas* canvas) { | 92 void TabIconView::PaintThrobber(gfx::Canvas* canvas) { |
95 int image_size = g_throbber_frames->height(); | 93 SkBitmap throbber(*GetThemeProvider()->GetBitmapNamed( |
96 PaintIcon(canvas, is_light_ ? *g_throbber_frames_light : *g_throbber_frames, | 94 is_light_ ? IDR_THROBBER_LIGHT : IDR_THROBBER)); |
97 throbber_frame_ * image_size, 0, image_size, image_size, false); | 95 int image_size = throbber.height(); |
| 96 PaintIcon(canvas, throbber, throbber_frame_ * image_size, 0, image_size, |
| 97 image_size, false); |
98 } | 98 } |
99 | 99 |
100 void TabIconView::PaintFavIcon(gfx::Canvas* canvas, const SkBitmap& bitmap) { | 100 void TabIconView::PaintFavIcon(gfx::Canvas* canvas, const SkBitmap& bitmap) { |
101 PaintIcon(canvas, bitmap, 0, 0, bitmap.width(), bitmap.height(), true); | 101 PaintIcon(canvas, bitmap, 0, 0, bitmap.width(), bitmap.height(), true); |
102 } | 102 } |
103 | 103 |
104 void TabIconView::PaintIcon(gfx::Canvas* canvas, | 104 void TabIconView::PaintIcon(gfx::Canvas* canvas, |
105 const SkBitmap& bitmap, | 105 const SkBitmap& bitmap, |
106 int src_x, | 106 int src_x, |
107 int src_y, | 107 int src_y, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 if (!rendered) | 150 if (!rendered) |
151 PaintFavIcon(canvas, *g_default_fav_icon); | 151 PaintFavIcon(canvas, *g_default_fav_icon); |
152 } | 152 } |
153 | 153 |
154 gfx::Size TabIconView::GetPreferredSize() { | 154 gfx::Size TabIconView::GetPreferredSize() { |
155 return gfx::Size(kFavIconSize, kFavIconSize); | 155 return gfx::Size(kFavIconSize, kFavIconSize); |
156 } | 156 } |
OLD | NEW |