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

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

Powered by Google App Engine
This is Rietveld 408576698