OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/touch/tabs/touch_tab.h" | 5 #include "chrome/browser/ui/touch/tabs/touch_tab.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/themes/theme_service.h" | 8 #include "chrome/browser/themes/theme_service.h" |
9 #include "grit/app_resources.h" | 9 #include "grit/app_resources.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
11 #include "grit/theme_resources_standard.h" | 11 #include "grit/theme_resources_standard.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas_skia.h" |
14 #include "ui/gfx/favicon_size.h" | 14 #include "ui/gfx/favicon_size.h" |
15 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
16 #include "ui/gfx/skbitmap_operations.h" | 16 #include "ui/gfx/skbitmap_operations.h" |
17 | 17 |
18 static const int kLeftPadding = 16; | 18 static const int kLeftPadding = 16; |
19 static const int kRightPadding = 15; | 19 static const int kRightPadding = 15; |
20 static const int kDropShadowHeight = 2; | 20 static const int kDropShadowHeight = 2; |
21 | 21 |
22 // The size of the favicon touch area. This generally would be the same as | |
23 // kFaviconSize in ui/gfx/favicon_size.h | |
24 static const int kTouchTabIconSize = 32; | |
25 | |
26 TouchTab::TouchTabImage TouchTab::tab_alpha = {0}; | 22 TouchTab::TouchTabImage TouchTab::tab_alpha = {0}; |
27 TouchTab::TouchTabImage TouchTab::tab_active = {0}; | 23 TouchTab::TouchTabImage TouchTab::tab_active = {0}; |
28 TouchTab::TouchTabImage TouchTab::tab_inactive = {0}; | 24 TouchTab::TouchTabImage TouchTab::tab_inactive = {0}; |
29 | 25 |
30 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
31 // TouchTab, public: | 27 // TouchTab, public: |
32 | 28 |
33 TouchTab::TouchTab(TabController* controller) | 29 TouchTab::TouchTab(TabController* controller) |
34 : BaseTab(controller) { | 30 : BaseTab(controller) { |
35 InitTabResources(); | 31 InitTabResources(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 169 |
174 // Now draw the highlights/shadows around the tab edge. | 170 // Now draw the highlights/shadows around the tab edge. |
175 canvas->DrawBitmapInt(*tab_image->image_l, 0, y_base); | 171 canvas->DrawBitmapInt(*tab_image->image_l, 0, y_base); |
176 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, y_base, | 172 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, y_base, |
177 width() - tab_image->l_width - tab_image->r_width, image_height); | 173 width() - tab_image->l_width - tab_image->r_width, image_height); |
178 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, | 174 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, |
179 y_base); | 175 y_base); |
180 } | 176 } |
181 | 177 |
182 void TouchTab::PaintIcon(gfx::Canvas* canvas) { | 178 void TouchTab::PaintIcon(gfx::Canvas* canvas) { |
183 // TODO(wyck): use thumbnailer to get better page images | |
184 int x = favicon_bounds_.x(); | 179 int x = favicon_bounds_.x(); |
185 int y = favicon_bounds_.y(); | 180 int y = favicon_bounds_.y(); |
186 | 181 |
187 TouchTabImage* tab_image = &tab_active; | 182 TouchTabImage* tab_image = &tab_active; |
188 int x_base = tab_image->image_l->width(); | 183 int x_base = tab_image->image_l->width(); |
189 | 184 |
190 x += x_base; | 185 x += x_base; |
191 | 186 |
192 if (base::i18n::IsRTL()) { | 187 if (base::i18n::IsRTL()) { |
193 x = width() - x - | 188 x = width() - x - (data().favicon.isNull() |
194 (data().favicon.isNull() ? kFaviconSize : data().favicon.width()); | 189 ? kTouchTargetIconSize : data().favicon.width()); |
195 } | 190 } |
196 | 191 |
197 int favicon_x = x; | |
198 if (!data().favicon.isNull() && data().favicon.width() != kFaviconSize) | |
199 favicon_x += (data().favicon.width() - kFaviconSize) / 2; | |
200 | |
201 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 192 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
202 ui::ThemeProvider* tp = GetThemeProvider(); | 193 ui::ThemeProvider* tp = GetThemeProvider(); |
203 SkBitmap frames(*tp->GetBitmapNamed( | 194 SkBitmap frames(*tp->GetBitmapNamed( |
204 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? | 195 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) |
205 IDR_THROBBER_WAITING : IDR_THROBBER)); | 196 ? IDR_THROBBER_WAITING : IDR_THROBBER)); |
206 int image_size = frames.height(); | 197 int image_size = frames.height(); |
207 int image_offset = loading_animation_frame() * image_size; | 198 int image_offset = loading_animation_frame() * image_size; |
208 canvas->DrawBitmapInt(frames, image_offset, 0, image_size, image_size, x, y, | 199 canvas->DrawBitmapInt(frames, image_offset, 0, image_size, image_size, x, |
209 kTouchTabIconSize, kTouchTabIconSize, false); | 200 y, kTouchTargetIconSize, kTouchTargetIconSize, false); |
210 } else { | 201 } else { |
211 canvas->Save(); | 202 canvas->Save(); |
212 canvas->ClipRectInt(0, 0, width(), height()); | 203 canvas->ClipRectInt(0, 0, width(), height()); |
213 if (should_display_crashed_favicon()) { | 204 if (should_display_crashed_favicon()) { |
214 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 205 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
215 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON)); | 206 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON)); |
216 canvas->DrawBitmapInt(crashed_favicon, 0, 0, crashed_favicon.width(), | 207 canvas->DrawBitmapInt(crashed_favicon, 0, 0, crashed_favicon.width(), |
217 crashed_favicon.height(), x, y + favicon_hiding_offset(), | 208 crashed_favicon.height(), x, y + favicon_hiding_offset(), |
218 kTouchTabIconSize, kTouchTabIconSize, true); | 209 kTouchTargetIconSize, kTouchTargetIconSize, true); |
219 } else { | 210 } else { |
220 if (!data().favicon.isNull()) { | 211 if (!data().favicon.isNull()) { |
221 | 212 // We center the image since it might not be square |
222 if ((data().favicon.width() == kTouchTabIconSize) && | 213 canvas->DrawBitmapInt(data().favicon, |
223 (data().favicon.height() == kTouchTabIconSize)) { | 214 0, 0, data().favicon.width(), data().favicon.height(), |
224 canvas->DrawBitmapInt(data().favicon, 0, 0, | 215 x + ((kTouchTargetIconSize - data().favicon.width()) / 2), |
225 data().favicon.width(), data().favicon.height(), | 216 y + ((kTouchTargetIconSize - data().favicon.height()) / 2) + |
226 x, y + favicon_hiding_offset(), | 217 favicon_hiding_offset(), |
227 kTouchTabIconSize, kTouchTabIconSize, true); | 218 data().favicon.width(), data().favicon.height(), true); |
228 } else { | |
229 // Draw a background around target touch area in case the favicon | |
230 // is smaller than touch area (e.g www.google.com is 16x16 now) | |
231 canvas->DrawRectInt( | |
232 GetThemeProvider()->GetColor( | |
233 ThemeService::COLOR_BUTTON_BACKGROUND), | |
234 x, y, kTouchTabIconSize, kTouchTabIconSize); | |
235 | |
236 // We center the image | |
237 // TODO(saintlou): later request larger image from HistoryService | |
238 canvas->DrawBitmapInt(data().favicon, 0, 0, data().favicon.width(), | |
239 data().favicon.height(), | |
240 x + ((kTouchTabIconSize - data().favicon.width()) / 2), | |
241 y + ((kTouchTabIconSize - data().favicon.height()) / 2) + | |
242 favicon_hiding_offset(), | |
243 data().favicon.width(), data().favicon.height(), true); | |
244 } | |
245 } | 219 } |
246 } | 220 } |
247 canvas->Restore(); | 221 canvas->Restore(); |
248 } | 222 } |
249 } | 223 } |
250 | 224 |
251 // static | 225 // static |
252 void TouchTab::InitTabResources() { | 226 void TouchTab::InitTabResources() { |
253 static bool initialized = false; | 227 static bool initialized = false; |
254 if (initialized) | 228 if (initialized) |
255 return; | 229 return; |
256 | 230 |
257 initialized = true; | 231 initialized = true; |
258 | 232 |
259 // Load the tab images once now, and maybe again later if the theme changes. | 233 // Load the tab images once now, and maybe again later if the theme changes. |
260 LoadTabImages(); | 234 LoadTabImages(); |
261 } | 235 } |
262 | 236 |
263 | |
264 // static | 237 // static |
265 void TouchTab::LoadTabImages() { | 238 void TouchTab::LoadTabImages() { |
266 // We're not letting people override tab images just yet. | 239 // We're not letting people override tab images just yet. |
267 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 240 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
268 | 241 |
269 tab_alpha.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); | 242 tab_alpha.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); |
270 tab_alpha.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); | 243 tab_alpha.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); |
271 | 244 |
272 tab_active.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); | 245 tab_active.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); |
273 tab_active.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER); | 246 tab_active.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER); |
274 tab_active.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); | 247 tab_active.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); |
275 tab_active.l_width = tab_active.image_l->width(); | 248 tab_active.l_width = tab_active.image_l->width(); |
276 tab_active.r_width = tab_active.image_r->width(); | 249 tab_active.r_width = tab_active.image_r->width(); |
277 | 250 |
278 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 251 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
279 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 252 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
280 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 253 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
281 tab_inactive.l_width = tab_inactive.image_l->width(); | 254 tab_inactive.l_width = tab_inactive.image_l->width(); |
282 tab_inactive.r_width = tab_inactive.image_r->width(); | 255 tab_inactive.r_width = tab_inactive.image_r->width(); |
283 } | 256 } |
OLD | NEW |