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/tabs/tab.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/defaults.h" | 10 #include "chrome/browser/defaults.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 //////////////////////////////////////////////////////////////////////////////// | 296 //////////////////////////////////////////////////////////////////////////////// |
297 // Tab, views::View overrides: | 297 // Tab, views::View overrides: |
298 | 298 |
299 void Tab::OnPaint(gfx::Canvas* canvas) { | 299 void Tab::OnPaint(gfx::Canvas* canvas) { |
300 // Don't paint if we're narrower than we can render correctly. (This should | 300 // Don't paint if we're narrower than we can render correctly. (This should |
301 // only happen during animations). | 301 // only happen during animations). |
302 if (width() < GetMinimumUnselectedSize().width() && !data().mini) | 302 if (width() < GetMinimumUnselectedSize().width() && !data().mini) |
303 return; | 303 return; |
304 | 304 |
| 305 gfx::Rect clip; |
| 306 if (controller()) { |
| 307 if (!controller()->ShouldPaintTab(this, &clip)) |
| 308 return; |
| 309 if (!clip.IsEmpty()) { |
| 310 canvas->Save(); |
| 311 canvas->ClipRect(clip); |
| 312 } |
| 313 } |
| 314 |
305 // See if the model changes whether the icons should be painted. | 315 // See if the model changes whether the icons should be painted. |
306 const bool show_icon = ShouldShowIcon(); | 316 const bool show_icon = ShouldShowIcon(); |
307 const bool show_close_button = ShouldShowCloseBox(); | 317 const bool show_close_button = ShouldShowCloseBox(); |
308 if (show_icon != showing_icon_ || show_close_button != showing_close_button_) | 318 if (show_icon != showing_icon_ || show_close_button != showing_close_button_) |
309 Layout(); | 319 Layout(); |
310 | 320 |
311 PaintTabBackground(canvas); | 321 PaintTabBackground(canvas); |
312 | 322 |
313 SkColor title_color = GetThemeProvider()-> | 323 SkColor title_color = GetThemeProvider()-> |
314 GetColor(IsSelected() ? | 324 GetColor(IsSelected() ? |
315 ThemeService::COLOR_TAB_TEXT : | 325 ThemeService::COLOR_TAB_TEXT : |
316 ThemeService::COLOR_BACKGROUND_TAB_TEXT); | 326 ThemeService::COLOR_BACKGROUND_TAB_TEXT); |
317 | 327 |
318 if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) | 328 if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) |
319 PaintTitle(canvas, title_color); | 329 PaintTitle(canvas, title_color); |
320 | 330 |
321 if (show_icon) | 331 if (show_icon) |
322 PaintIcon(canvas); | 332 PaintIcon(canvas); |
323 | 333 |
324 // If the close button color has changed, generate a new one. | 334 // If the close button color has changed, generate a new one. |
325 if (!close_button_color_ || title_color != close_button_color_) { | 335 if (!close_button_color_ || title_color != close_button_color_) { |
326 close_button_color_ = title_color; | 336 close_button_color_ = title_color; |
327 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 337 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
328 close_button()->SetBackground(close_button_color_, | 338 close_button()->SetBackground(close_button_color_, |
329 rb.GetImageSkiaNamed(IDR_TAB_CLOSE), | 339 rb.GetImageSkiaNamed(IDR_TAB_CLOSE), |
330 rb.GetImageSkiaNamed(IDR_TAB_CLOSE_MASK)); | 340 rb.GetImageSkiaNamed(IDR_TAB_CLOSE_MASK)); |
331 } | 341 } |
| 342 |
| 343 if (!clip.IsEmpty()) |
| 344 canvas->Restore(); |
332 } | 345 } |
333 | 346 |
334 void Tab::Layout() { | 347 void Tab::Layout() { |
335 gfx::Rect lb = GetContentsBounds(); | 348 gfx::Rect lb = GetContentsBounds(); |
336 if (lb.IsEmpty()) | 349 if (lb.IsEmpty()) |
337 return; | 350 return; |
338 lb.Inset( | 351 lb.Inset( |
339 left_padding(), top_padding(), right_padding(), bottom_padding()); | 352 left_padding(), top_padding(), right_padding(), bottom_padding()); |
340 | 353 |
341 // The height of the content of the Tab is the largest of the favicon, | 354 // The height of the content of the Tab is the largest of the favicon, |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); | 727 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); |
715 tab_active_.l_width = tab_active_.image_l->width(); | 728 tab_active_.l_width = tab_active_.image_l->width(); |
716 tab_active_.r_width = tab_active_.image_r->width(); | 729 tab_active_.r_width = tab_active_.image_r->width(); |
717 | 730 |
718 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 731 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
719 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 732 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
720 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 733 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
721 tab_inactive_.l_width = tab_inactive_.image_l->width(); | 734 tab_inactive_.l_width = tab_inactive_.image_l->width(); |
722 tab_inactive_.r_width = tab_inactive_.image_r->width(); | 735 tab_inactive_.r_width = tab_inactive_.image_r->width(); |
723 } | 736 } |
OLD | NEW |