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

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 323993002: Use labels to display views tab titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; update tests. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 17 matching lines...) Expand all
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/models/list_selection_model.h" 29 #include "ui/base/models/list_selection_model.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/base/theme_provider.h" 31 #include "ui/base/theme_provider.h"
32 #include "ui/gfx/animation/animation_container.h" 32 #include "ui/gfx/animation/animation_container.h"
33 #include "ui/gfx/animation/multi_animation.h" 33 #include "ui/gfx/animation/multi_animation.h"
34 #include "ui/gfx/animation/throb_animation.h" 34 #include "ui/gfx/animation/throb_animation.h"
35 #include "ui/gfx/canvas.h" 35 #include "ui/gfx/canvas.h"
36 #include "ui/gfx/color_analysis.h" 36 #include "ui/gfx/color_analysis.h"
37 #include "ui/gfx/favicon_size.h" 37 #include "ui/gfx/favicon_size.h"
38 #include "ui/gfx/font.h"
39 #include "ui/gfx/image/image_skia_operations.h" 38 #include "ui/gfx/image/image_skia_operations.h"
40 #include "ui/gfx/path.h" 39 #include "ui/gfx/path.h"
41 #include "ui/gfx/rect_conversions.h" 40 #include "ui/gfx/rect_conversions.h"
42 #include "ui/gfx/skia_util.h" 41 #include "ui/gfx/skia_util.h"
43 #include "ui/gfx/text_elider.h" 42 #include "ui/gfx/text_elider.h"
44 #include "ui/views/border.h" 43 #include "ui/views/border.h"
45 #include "ui/views/controls/button/image_button.h" 44 #include "ui/views/controls/button/image_button.h"
45 #include "ui/views/controls/label.h"
46 #include "ui/views/rect_based_targeting_utils.h" 46 #include "ui/views/rect_based_targeting_utils.h"
47 #include "ui/views/widget/tooltip_manager.h" 47 #include "ui/views/widget/tooltip_manager.h"
48 #include "ui/views/widget/widget.h" 48 #include "ui/views/widget/widget.h"
49 #include "ui/views/window/non_client_view.h" 49 #include "ui/views/window/non_client_view.h"
50 50
51 #if defined(USE_ASH) 51 #if defined(USE_ASH)
52 #include "ui/aura/env.h" 52 #include "ui/aura/env.h"
53 #endif 53 #endif
54 54
55 namespace { 55 namespace {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // Tab, statics: 368 // Tab, statics:
369 369
370 // static 370 // static
371 const char Tab::kViewClassName[] = "Tab"; 371 const char Tab::kViewClassName[] = "Tab";
372 372
373 // static 373 // static
374 Tab::TabImage Tab::tab_alpha_ = {0}; 374 Tab::TabImage Tab::tab_alpha_ = {0};
375 Tab::TabImage Tab::tab_active_ = {0}; 375 Tab::TabImage Tab::tab_active_ = {0};
376 Tab::TabImage Tab::tab_inactive_ = {0}; 376 Tab::TabImage Tab::tab_inactive_ = {0};
377 // static 377 // static
378 gfx::Font* Tab::font_ = NULL;
379 // static
380 int Tab::font_height_ = 0;
381 // static
382 Tab::ImageCache* Tab::image_cache_ = NULL; 378 Tab::ImageCache* Tab::image_cache_ = NULL;
383 379
384 //////////////////////////////////////////////////////////////////////////////// 380 ////////////////////////////////////////////////////////////////////////////////
385 // Tab, public: 381 // Tab, public:
386 382
387 Tab::Tab(TabController* controller) 383 Tab::Tab(TabController* controller)
388 : controller_(controller), 384 : controller_(controller),
389 closing_(false), 385 closing_(false),
390 dragging_(false), 386 dragging_(false),
391 favicon_hiding_offset_(0), 387 favicon_hiding_offset_(0),
392 loading_animation_frame_(0), 388 loading_animation_frame_(0),
393 immersive_loading_step_(0), 389 immersive_loading_step_(0),
394 should_display_crashed_favicon_(false), 390 should_display_crashed_favicon_(false),
395 animating_media_state_(TAB_MEDIA_STATE_NONE), 391 animating_media_state_(TAB_MEDIA_STATE_NONE),
392 close_button_(NULL),
393 title_(new views::Label()),
396 tab_activated_with_last_gesture_begin_(false), 394 tab_activated_with_last_gesture_begin_(false),
397 hover_controller_(this), 395 hover_controller_(this),
398 showing_icon_(false), 396 showing_icon_(false),
399 showing_media_indicator_(false), 397 showing_media_indicator_(false),
400 showing_close_button_(false), 398 showing_close_button_(false),
401 close_button_color_(0) { 399 close_button_color_(0) {
402 DCHECK(controller); 400 DCHECK(controller);
403 InitTabResources(); 401 InitTabResources();
404 402
405 // So we get don't get enter/exit on children and don't prematurely stop the 403 // So we get don't get enter/exit on children and don't prematurely stop the
406 // hover. 404 // hover.
407 set_notify_enter_exit_on_child(true); 405 set_notify_enter_exit_on_child(true);
408 406
409 set_id(VIEW_ID_TAB); 407 set_id(VIEW_ID_TAB);
410 408
409 title_->set_directionality_mode(gfx::DIRECTIONALITY_FROM_TEXT);
410 title_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
411 title_->SetElideBehavior(gfx::FADE_TAIL);
412
411 // Add the Close Button. 413 // Add the Close Button.
412 close_button_ = new TabCloseButton(this); 414 close_button_ = new TabCloseButton(this);
413 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 415 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
414 close_button_->SetImage(views::CustomButton::STATE_NORMAL, 416 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
415 rb.GetImageSkiaNamed(IDR_CLOSE_1)); 417 rb.GetImageSkiaNamed(IDR_CLOSE_1));
416 close_button_->SetImage(views::CustomButton::STATE_HOVERED, 418 close_button_->SetImage(views::CustomButton::STATE_HOVERED,
417 rb.GetImageSkiaNamed(IDR_CLOSE_1_H)); 419 rb.GetImageSkiaNamed(IDR_CLOSE_1_H));
418 close_button_->SetImage(views::CustomButton::STATE_PRESSED, 420 close_button_->SetImage(views::CustomButton::STATE_PRESSED,
419 rb.GetImageSkiaNamed(IDR_CLOSE_1_P)); 421 rb.GetImageSkiaNamed(IDR_CLOSE_1_P));
420 close_button_->SetAccessibleName( 422 close_button_->SetAccessibleName(
(...skipping 22 matching lines...) Expand all
443 return controller_->IsTabSelected(this); 445 return controller_->IsTabSelected(this);
444 } 446 }
445 447
446 void Tab::SetData(const TabRendererData& data) { 448 void Tab::SetData(const TabRendererData& data) {
447 if (data_.Equals(data)) 449 if (data_.Equals(data))
448 return; 450 return;
449 451
450 TabRendererData old(data_); 452 TabRendererData old(data_);
451 data_ = data; 453 data_ = data;
452 454
455 base::string16 title = data_.title;
456 if (title.empty()) {
457 title = data_.loading ?
458 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) :
459 CoreTabHelper::GetDefaultTitle();
460 } else {
461 Browser::FormatTitleForDisplay(&title);
462 }
463 title_->SetText(title);
464
453 if (data_.IsCrashed()) { 465 if (data_.IsCrashed()) {
454 if (!should_display_crashed_favicon_ && !IsPerformingCrashAnimation()) { 466 if (!should_display_crashed_favicon_ && !IsPerformingCrashAnimation()) {
455 data_.media_state = TAB_MEDIA_STATE_NONE; 467 data_.media_state = TAB_MEDIA_STATE_NONE;
456 #if defined(OS_CHROMEOS) 468 #if defined(OS_CHROMEOS)
457 // On Chrome OS, we reload killed tabs automatically when the user 469 // On Chrome OS, we reload killed tabs automatically when the user
458 // switches to them. Don't display animations for these unless they're 470 // switches to them. Don't display animations for these unless they're
459 // selected (i.e. in the foreground) -- we won't reload these 471 // selected (i.e. in the foreground) -- we won't reload these
460 // automatically since we don't want to get into a crash loop. 472 // automatically since we don't want to get into a crash loop.
461 if (IsSelected() || 473 if (IsSelected() ||
462 data_.crashed_status != base::TERMINATION_STATUS_PROCESS_WAS_KILLED) 474 data_.crashed_status != base::TERMINATION_STATUS_PROCESS_WAS_KILLED)
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 691
680 void Tab::Layout() { 692 void Tab::Layout() {
681 gfx::Rect lb = GetContentsBounds(); 693 gfx::Rect lb = GetContentsBounds();
682 if (lb.IsEmpty()) 694 if (lb.IsEmpty())
683 return; 695 return;
684 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); 696 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding);
685 697
686 // The height of the content of the Tab is the largest of the favicon, 698 // The height of the content of the Tab is the largest of the favicon,
687 // the title text and the close button graphic. 699 // the title text and the close button graphic.
688 const int kTabIconSize = gfx::kFaviconSize; 700 const int kTabIconSize = gfx::kFaviconSize;
689 int content_height = std::max(kTabIconSize, font_height_); 701 const int font_height = title_->font_list().GetHeight();
702 int content_height = std::max(kTabIconSize, font_height);
690 close_button_->SetBorder(views::Border::NullBorder()); 703 close_button_->SetBorder(views::Border::NullBorder());
691 gfx::Size close_button_size(close_button_->GetPreferredSize()); 704 gfx::Size close_button_size(close_button_->GetPreferredSize());
692 content_height = std::max(content_height, close_button_size.height()); 705 content_height = std::max(content_height, close_button_size.height());
693 706
694 // Size the Favicon. 707 // Size the Favicon.
695 showing_icon_ = ShouldShowIcon(); 708 showing_icon_ = ShouldShowIcon();
696 if (showing_icon_) { 709 if (showing_icon_) {
697 // Use the size of the favicon as apps use a bigger favicon size. 710 // Use the size of the favicon as apps use a bigger favicon size.
698 int favicon_top = kTopPadding + content_height / 2 - kTabIconSize / 2; 711 int favicon_top = kTopPadding + content_height / 2 - kTabIconSize / 2;
699 int favicon_left = lb.x(); 712 int favicon_left = lb.x();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 std::max(lb.x(), right - media_indicator_bounds_.width())); 764 std::max(lb.x(), right - media_indicator_bounds_.width()));
752 MaybeAdjustLeftForMiniTab(&media_indicator_bounds_); 765 MaybeAdjustLeftForMiniTab(&media_indicator_bounds_);
753 } else { 766 } else {
754 media_indicator_bounds_.SetRect(lb.x(), lb.y(), 0, 0); 767 media_indicator_bounds_.SetRect(lb.x(), lb.y(), 0, 0);
755 } 768 }
756 769
757 const int title_text_offset = is_host_desktop_type_ash ? 770 const int title_text_offset = is_host_desktop_type_ash ?
758 kTitleTextOffsetYAsh : kTitleTextOffsetY; 771 kTitleTextOffsetYAsh : kTitleTextOffsetY;
759 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing; 772 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing;
760 int title_top = kTopPadding + title_text_offset + 773 int title_top = kTopPadding + title_text_offset +
761 (content_height - font_height_) / 2; 774 (content_height - font_height) / 2;
775 gfx::Rect title_bounds(title_left, title_top, 0, 0);
762 // Size the Title text to fill the remaining space. 776 // Size the Title text to fill the remaining space.
763 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) { 777 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) {
764 // If the user has big fonts, the title will appear rendered too far down 778 // If the user has big fonts, the title will appear rendered too far down
765 // on the y-axis if we use the regular top padding, so we need to adjust it 779 // on the y-axis if we use the regular top padding, so we need to adjust it
766 // so that the text appears centered. 780 // so that the text appears centered.
767 gfx::Size minimum_size = GetMinimumUnselectedSize(); 781 gfx::Size minimum_size = GetMinimumUnselectedSize();
768 int text_height = title_top + font_height_ + kBottomPadding; 782 int text_height = title_top + font_height + kBottomPadding;
769 if (text_height > minimum_size.height()) 783 if (text_height > minimum_size.height())
770 title_top -= (text_height - minimum_size.height()) / 2; 784 title_top -= (text_height - minimum_size.height()) / 2;
771 785
772 int title_width; 786 int title_width;
773 if (showing_media_indicator_) { 787 if (showing_media_indicator_) {
774 title_width = media_indicator_bounds_.x() - kTitleCloseButtonSpacing - 788 title_width = media_indicator_bounds_.x() - kTitleCloseButtonSpacing -
775 title_left; 789 title_left;
776 } else if (close_button_->visible()) { 790 } else if (close_button_->visible()) {
777 // The close button has an empty border with some padding (see details 791 // The close button has an empty border with some padding (see details
778 // above where the close-button's bounds is set). Allow the title to 792 // above where the close-button's bounds is set). Allow the title to
779 // overlap the empty padding. 793 // overlap the empty padding.
780 title_width = close_button_->x() + close_button_->GetInsets().left() - 794 title_width = close_button_->x() + close_button_->GetInsets().left() -
781 kTitleCloseButtonSpacing - title_left; 795 kTitleCloseButtonSpacing - title_left;
782 } else { 796 } else {
783 title_width = lb.width() - title_left; 797 title_width = lb.width() - title_left;
784 } 798 }
785 title_width = std::max(title_width, 0); 799 title_width = std::max(title_width, 0);
786 title_bounds_.SetRect(title_left, title_top, title_width, font_height_); 800 title_bounds.SetRect(title_left, title_top, title_width, font_height);
787 } else {
788 title_bounds_.SetRect(title_left, title_top, 0, 0);
789 } 801 }
790 802
791 // Certain UI elements within the Tab (the favicon, etc.) are not represented 803 title_bounds.set_x(GetMirroredXForRect(title_bounds));
792 // as child Views (which is the preferred method). Instead, these UI elements 804 title_->SetBoundsRect(title_bounds);
793 // are drawn directly on the canvas from within Tab::OnPaint(). The Tab's
794 // child Views (for example, the Tab's close button which is a views::Button
795 // instance) are automatically mirrored by the mirroring infrastructure in
796 // views. The elements Tab draws directly on the canvas need to be manually
797 // mirrored if the View's layout is right-to-left.
798 title_bounds_.set_x(GetMirroredXForRect(title_bounds_));
799 } 805 }
800 806
801 void Tab::OnThemeChanged() { 807 void Tab::OnThemeChanged() {
802 LoadTabImages(); 808 LoadTabImages();
803 } 809 }
804 810
805 const char* Tab::GetClassName() const { 811 const char* Tab::GetClassName() const {
806 return kViewClassName; 812 return kViewClassName;
807 } 813 }
808 814
(...skipping 24 matching lines...) Expand all
833 } 839 }
834 840
835 bool Tab::GetTooltipText(const gfx::Point& p, base::string16* tooltip) const { 841 bool Tab::GetTooltipText(const gfx::Point& p, base::string16* tooltip) const {
836 // Note: Anything that affects the tooltip text should be accounted for when 842 // Note: Anything that affects the tooltip text should be accounted for when
837 // calling TooltipTextChanged() from Tab::DataChanged(). 843 // calling TooltipTextChanged() from Tab::DataChanged().
838 *tooltip = chrome::AssembleTabTooltipText(data_.title, data_.media_state); 844 *tooltip = chrome::AssembleTabTooltipText(data_.title, data_.media_state);
839 return !tooltip->empty(); 845 return !tooltip->empty();
840 } 846 }
841 847
842 bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) const { 848 bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) const {
843 origin->set_x(title_bounds_.x() + 10); 849 origin->set_x(title_->x() + 10);
844 origin->set_y(-views::TooltipManager::GetTooltipHeight() - 4); 850 origin->set_y(-views::TooltipManager::GetTooltipHeight() - 4);
845 return true; 851 return true;
846 } 852 }
847 853
848 bool Tab::OnMousePressed(const ui::MouseEvent& event) { 854 bool Tab::OnMousePressed(const ui::MouseEvent& event) {
849 controller_->OnMouseEventInTab(this, event); 855 controller_->OnMouseEventInTab(this, event);
850 856
851 // Allow a right click from touch to drag, which corresponds to a long click. 857 // Allow a right click from touch to drag, which corresponds to a long click.
852 if (event.IsOnlyLeftMouseButton() || 858 if (event.IsOnlyLeftMouseButton() ||
853 (event.IsOnlyRightMouseButton() && event.flags() & ui::EF_FROM_TOUCH)) { 859 (event.IsOnlyRightMouseButton() && event.flags() & ui::EF_FROM_TOUCH)) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 982 }
977 983
978 void Tab::GetAccessibleState(ui::AXViewState* state) { 984 void Tab::GetAccessibleState(ui::AXViewState* state) {
979 state->role = ui::AX_ROLE_TAB; 985 state->role = ui::AX_ROLE_TAB;
980 state->name = data_.title; 986 state->name = data_.title;
981 } 987 }
982 988
983 //////////////////////////////////////////////////////////////////////////////// 989 ////////////////////////////////////////////////////////////////////////////////
984 // Tab, private 990 // Tab, private
985 991
986 const gfx::Rect& Tab::GetTitleBounds() const {
987 return title_bounds_;
988 }
989
990 const gfx::Rect& Tab::GetIconBounds() const {
991 return favicon_bounds_;
992 }
993
994 void Tab::MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const { 992 void Tab::MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const {
995 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) 993 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth)
996 return; 994 return;
997 const int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); 995 const int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth();
998 const int ideal_delta = width() - GetMiniWidth(); 996 const int ideal_delta = width() - GetMiniWidth();
999 const int ideal_x = (GetMiniWidth() - bounds->width()) / 2; 997 const int ideal_x = (GetMiniWidth() - bounds->width()) / 2;
1000 bounds->set_x(bounds->x() + static_cast<int>( 998 bounds->set_x(bounds->x() + static_cast<int>(
1001 (1 - static_cast<float>(ideal_delta) / static_cast<float>(mini_delta)) * 999 (1 - static_cast<float>(ideal_delta) / static_cast<float>(mini_delta)) *
1002 (ideal_x - bounds->x()))); 1000 (ideal_x - bounds->x())));
1003 } 1001 }
(...skipping 17 matching lines...) Expand all
1021 const bool show_media_indicator = ShouldShowMediaIndicator(); 1019 const bool show_media_indicator = ShouldShowMediaIndicator();
1022 const bool show_close_button = ShouldShowCloseBox(); 1020 const bool show_close_button = ShouldShowCloseBox();
1023 if (show_icon != showing_icon_ || 1021 if (show_icon != showing_icon_ ||
1024 show_media_indicator != showing_media_indicator_ || 1022 show_media_indicator != showing_media_indicator_ ||
1025 show_close_button != showing_close_button_) { 1023 show_close_button != showing_close_button_) {
1026 Layout(); 1024 Layout();
1027 } 1025 }
1028 1026
1029 PaintTabBackground(canvas); 1027 PaintTabBackground(canvas);
1030 1028
1031 SkColor title_color = GetThemeProvider()-> 1029 const SkColor title_color = GetThemeProvider()->GetColor(IsSelected() ?
1032 GetColor(IsSelected() ? 1030 ThemeProperties::COLOR_TAB_TEXT :
1033 ThemeProperties::COLOR_TAB_TEXT : 1031 ThemeProperties::COLOR_BACKGROUND_TAB_TEXT);
1034 ThemeProperties::COLOR_BACKGROUND_TAB_TEXT); 1032 if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) {
1035 1033 title_->SetEnabledColor(title_color);
1036 if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) 1034 title_->Paint(canvas, views::CullSet());
1037 PaintTitle(canvas, title_color); 1035 }
1038 1036
1039 if (show_icon) 1037 if (show_icon)
1040 PaintIcon(canvas); 1038 PaintIcon(canvas);
1041 1039
1042 if (show_media_indicator) 1040 if (show_media_indicator)
1043 PaintMediaIndicator(canvas); 1041 PaintMediaIndicator(canvas);
1044 1042
1045 // If the close button color has changed, generate a new one. 1043 // If the close button color has changed, generate a new one.
1046 if (!close_button_color_ || title_color != close_button_color_) { 1044 if (!close_button_color_ || title_color != close_button_color_) {
1047 close_button_color_ = title_color; 1045 close_button_color_ = title_color;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 height() - kDropShadowHeight); 1322 height() - kDropShadowHeight);
1325 1323
1326 // Now draw the highlights/shadows around the tab edge. 1324 // Now draw the highlights/shadows around the tab edge.
1327 canvas->DrawImageInt(*tab_image->image_l, 0, 0); 1325 canvas->DrawImageInt(*tab_image->image_l, 0, 0);
1328 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, 1326 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0,
1329 width() - tab_image->l_width - tab_image->r_width, height()); 1327 width() - tab_image->l_width - tab_image->r_width, height());
1330 canvas->DrawImageInt(*tab_image->image_r, width() - tab_image->r_width, 0); 1328 canvas->DrawImageInt(*tab_image->image_r, width() - tab_image->r_width, 0);
1331 } 1329 }
1332 1330
1333 void Tab::PaintIcon(gfx::Canvas* canvas) { 1331 void Tab::PaintIcon(gfx::Canvas* canvas) {
1334 gfx::Rect bounds = GetIconBounds(); 1332 gfx::Rect bounds = favicon_bounds_;
1335 if (bounds.IsEmpty()) 1333 if (bounds.IsEmpty())
1336 return; 1334 return;
1337 1335
1338 bounds.set_x(GetMirroredXForRect(bounds)); 1336 bounds.set_x(GetMirroredXForRect(bounds));
1339 1337
1340 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { 1338 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
1341 // Paint network activity (aka throbber) animation frame. 1339 // Paint network activity (aka throbber) animation frame.
1342 ui::ThemeProvider* tp = GetThemeProvider(); 1340 ui::ThemeProvider* tp = GetThemeProvider();
1343 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( 1341 gfx::ImageSkia frames(*tp->GetImageSkiaNamed(
1344 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? 1342 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ?
1345 IDR_THROBBER_WAITING : IDR_THROBBER)); 1343 IDR_THROBBER_WAITING : IDR_THROBBER));
1346 1344
1347 int icon_size = frames.height(); 1345 int icon_size = frames.height();
1348 int image_offset = loading_animation_frame_ * icon_size; 1346 int image_offset = loading_animation_frame_ * icon_size;
1349 DrawIconCenter(canvas, frames, image_offset, 1347 DrawIconCenter(canvas, frames, image_offset,
1350 icon_size, icon_size, 1348 icon_size, icon_size,
1351 bounds, false, SkPaint()); 1349 bounds, false, SkPaint());
1352 } else if (should_display_crashed_favicon_) { 1350 } else if (should_display_crashed_favicon_) {
1353 // Paint crash favicon. 1351 // Paint crash favicon.
1354 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1352 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1355 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); 1353 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON));
1356 bounds.set_y(bounds.y() + favicon_hiding_offset_); 1354 bounds.set_y(bounds.y() + favicon_hiding_offset_);
1357 DrawIconCenter(canvas, crashed_favicon, 0, 1355 DrawIconCenter(canvas, crashed_favicon, 0,
1358 crashed_favicon.width(), 1356 crashed_favicon.width(),
1359 crashed_favicon.height(), 1357 crashed_favicon.height(),
1360 bounds, true, SkPaint()); 1358 bounds, true, SkPaint());
1361 } else if (!data().favicon.isNull()) { 1359 } else if (!data().favicon.isNull()) {
1362 // Paint the normal favicon. 1360 // Paint the normal favicon.
1363 DrawIconCenter(canvas, data().favicon, 0, 1361 DrawIconCenter(canvas, data().favicon, 0,
1364 data().favicon.width(), 1362 data().favicon.width(),
1365 data().favicon.height(), 1363 data().favicon.height(),
1366 bounds, true, SkPaint()); 1364 bounds, true, SkPaint());
1367 } 1365 }
1368 } 1366 }
1369 1367
1370 void Tab::PaintMediaIndicator(gfx::Canvas* canvas) { 1368 void Tab::PaintMediaIndicator(gfx::Canvas* canvas) {
(...skipping 11 matching lines...) Expand all
1382 paint.setAlpha(opaqueness * SK_AlphaOPAQUE); 1380 paint.setAlpha(opaqueness * SK_AlphaOPAQUE);
1383 1381
1384 const gfx::ImageSkia& media_indicator_image = 1382 const gfx::ImageSkia& media_indicator_image =
1385 *(chrome::GetTabMediaIndicatorImage(animating_media_state_). 1383 *(chrome::GetTabMediaIndicatorImage(animating_media_state_).
1386 ToImageSkia()); 1384 ToImageSkia());
1387 DrawIconAtLocation(canvas, media_indicator_image, 0, 1385 DrawIconAtLocation(canvas, media_indicator_image, 0,
1388 bounds.x(), bounds.y(), media_indicator_image.width(), 1386 bounds.x(), bounds.y(), media_indicator_image.width(),
1389 media_indicator_image.height(), true, paint); 1387 media_indicator_image.height(), true, paint);
1390 } 1388 }
1391 1389
1392 void Tab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
1393 // Paint the Title.
1394 base::string16 title = data().title;
1395 if (title.empty()) {
1396 title = data().loading ?
1397 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) :
1398 CoreTabHelper::GetDefaultTitle();
1399 } else {
1400 Browser::FormatTitleForDisplay(&title);
1401 }
1402
1403 canvas->DrawFadedString(title, gfx::FontList(*font_), title_color,
1404 GetTitleBounds(), 0);
1405 }
1406
1407 void Tab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, 1390 void Tab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
1408 TabRendererData::NetworkState state) { 1391 TabRendererData::NetworkState state) {
1409 static bool initialized = false; 1392 static bool initialized = false;
1410 static int loading_animation_frame_count = 0; 1393 static int loading_animation_frame_count = 0;
1411 static int waiting_animation_frame_count = 0; 1394 static int waiting_animation_frame_count = 0;
1412 static int waiting_to_loading_frame_count_ratio = 0; 1395 static int waiting_to_loading_frame_count_ratio = 0;
1413 if (!initialized) { 1396 if (!initialized) {
1414 initialized = true; 1397 initialized = true;
1415 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1398 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1416 gfx::ImageSkia loading_animation(*rb.GetImageSkiaNamed(IDR_THROBBER)); 1399 gfx::ImageSkia loading_animation(*rb.GetImageSkiaNamed(IDR_THROBBER));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 } 1522 }
1540 1523
1541 void Tab::StartMediaIndicatorAnimation() { 1524 void Tab::StartMediaIndicatorAnimation() {
1542 media_indicator_animation_ = 1525 media_indicator_animation_ =
1543 chrome::CreateTabMediaIndicatorFadeAnimation(data_.media_state); 1526 chrome::CreateTabMediaIndicatorFadeAnimation(data_.media_state);
1544 media_indicator_animation_->set_delegate(this); 1527 media_indicator_animation_->set_delegate(this);
1545 media_indicator_animation_->Start(); 1528 media_indicator_animation_->Start();
1546 } 1529 }
1547 1530
1548 void Tab::ScheduleIconPaint() { 1531 void Tab::ScheduleIconPaint() {
1549 gfx::Rect bounds = GetIconBounds(); 1532 gfx::Rect bounds = favicon_bounds_;
1550 if (bounds.IsEmpty()) 1533 if (bounds.IsEmpty())
1551 return; 1534 return;
1552 1535
1553 // Extends the area to the bottom when sad_favicon is 1536 // Extends the area to the bottom when sad_favicon is animating.
1554 // animating.
1555 if (IsPerformingCrashAnimation()) 1537 if (IsPerformingCrashAnimation())
1556 bounds.set_height(height() - bounds.y()); 1538 bounds.set_height(height() - bounds.y());
1557 bounds.set_x(GetMirroredXForRect(bounds)); 1539 bounds.set_x(GetMirroredXForRect(bounds));
1558 SchedulePaintInRect(bounds); 1540 SchedulePaintInRect(bounds);
1559 } 1541 }
1560 1542
1561 gfx::Rect Tab::GetImmersiveBarRect() const { 1543 gfx::Rect Tab::GetImmersiveBarRect() const {
1562 // The main bar is as wide as the normal tab's horizontal top line. 1544 // The main bar is as wide as the normal tab's horizontal top line.
1563 // This top line of the tab extends a few pixels left and right of the 1545 // This top line of the tab extends a few pixels left and right of the
1564 // center image due to pixels in the rounded corner images. 1546 // center image due to pixels in the rounded corner images.
(...skipping 23 matching lines...) Expand all
1588 //////////////////////////////////////////////////////////////////////////////// 1570 ////////////////////////////////////////////////////////////////////////////////
1589 // Tab, private static: 1571 // Tab, private static:
1590 1572
1591 // static 1573 // static
1592 void Tab::InitTabResources() { 1574 void Tab::InitTabResources() {
1593 static bool initialized = false; 1575 static bool initialized = false;
1594 if (initialized) 1576 if (initialized)
1595 return; 1577 return;
1596 1578
1597 initialized = true; 1579 initialized = true;
1598
1599 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1600 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont));
1601 font_height_ = font_->GetHeight();
1602
1603 image_cache_ = new ImageCache(); 1580 image_cache_ = new ImageCache();
1604 1581
1605 // Load the tab images once now, and maybe again later if the theme changes. 1582 // Load the tab images once now, and maybe again later if the theme changes.
1606 LoadTabImages(); 1583 LoadTabImages();
1607 } 1584 }
1608 1585
1609 // static 1586 // static
1610 void Tab::LoadTabImages() { 1587 void Tab::LoadTabImages() {
1611 // We're not letting people override tab images just yet. 1588 // We're not letting people override tab images just yet.
1612 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1589 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 const gfx::ImageSkia& image) { 1624 const gfx::ImageSkia& image) {
1648 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1625 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1649 ImageCacheEntry entry; 1626 ImageCacheEntry entry;
1650 entry.resource_id = resource_id; 1627 entry.resource_id = resource_id;
1651 entry.scale_factor = scale_factor; 1628 entry.scale_factor = scale_factor;
1652 entry.image = image; 1629 entry.image = image;
1653 image_cache_->push_front(entry); 1630 image_cache_->push_front(entry);
1654 if (image_cache_->size() > kMaxImageCacheSize) 1631 if (image_cache_->size() > kMaxImageCacheSize)
1655 image_cache_->pop_back(); 1632 image_cache_->pop_back();
1656 } 1633 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698