OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 bool HasAshShell() { | 97 bool HasAshShell() { |
98 #if defined(USE_ASH) | 98 #if defined(USE_ASH) |
99 return ash::Shell::HasInstance(); | 99 return ash::Shell::HasInstance(); |
100 #else | 100 #else |
101 return false; | 101 return false; |
102 #endif // USE_ASH | 102 #endif // USE_ASH |
103 } | 103 } |
104 #endif // OS_CHROMEOS | 104 #endif // OS_CHROMEOS |
105 | 105 |
106 // Returns the y-position that will center an element of height | 106 // Returns the y-position that will center an element of height |
107 // |child_height| inside an element of height |parent_height|. For | 107 // |child_height| inside an element of height |parent_height|. Excess padding is |
108 // material design excess padding is placed below, for non-material | 108 // placed below. |
109 // it is placed above. | |
110 int CenteredChildY(int parent_height, int child_height) { | 109 int CenteredChildY(int parent_height, int child_height) { |
111 int roundoff_amount = ui::MaterialDesignController::IsModeMaterial() ? 0 : 1; | 110 return (parent_height - child_height) / 2; |
Peter Kasting
2016/09/22 23:27:25
Nit: I'd just do this inline in the two callers, n
| |
112 return (parent_height - child_height + roundoff_amount) / 2; | |
113 } | 111 } |
114 | 112 |
115 } // namespace | 113 } // namespace |
116 | 114 |
117 // static | 115 // static |
118 const char ToolbarView::kViewClassName[] = "ToolbarView"; | 116 const char ToolbarView::kViewClassName[] = "ToolbarView"; |
119 | 117 |
120 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
121 // ToolbarView, public: | 119 // ToolbarView, public: |
122 | 120 |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 //////////////////////////////////////////////////////////////////////////////// | 632 //////////////////////////////////////////////////////////////////////////////// |
635 // ToolbarView, private: | 633 // ToolbarView, private: |
636 | 634 |
637 // views::ViewTargeterDelegate: | 635 // views::ViewTargeterDelegate: |
638 bool ToolbarView::DoesIntersectRect(const views::View* target, | 636 bool ToolbarView::DoesIntersectRect(const views::View* target, |
639 const gfx::Rect& rect) const { | 637 const gfx::Rect& rect) const { |
640 CHECK_EQ(target, this); | 638 CHECK_EQ(target, this); |
641 | 639 |
642 // Fall through to the tab strip above us if none of |rect| intersects | 640 // Fall through to the tab strip above us if none of |rect| intersects |
643 // with this view (intersection with the top shadow edge does not | 641 // with this view (intersection with the top shadow edge does not |
644 // count as intersection with this view). | 642 // count as intersection with this view). |
Peter Kasting
2016/09/22 23:27:25
Nit: Does this parenthetical have meaning anymore?
| |
645 if (rect.bottom() < content_shadow_height()) | 643 if (rect.bottom() < 0) |
Peter Kasting
2016/09/22 23:27:25
Hmm, I suspect this was a slight bug? Maybe they
Evan Stade
2016/09/23 00:31:08
in fact I think we can ditch this entire function
| |
646 return false; | 644 return false; |
647 // Otherwise let our superclass take care of it. | 645 // Otherwise let our superclass take care of it. |
648 return ViewTargeterDelegate::DoesIntersectRect(this, rect); | 646 return ViewTargeterDelegate::DoesIntersectRect(this, rect); |
Peter Kasting
2016/09/22 23:27:25
Nit: Simpler:
// Fall through to the tab strip
Evan Stade
2016/09/23 00:31:08
yea, I just came to the same conclusion
| |
649 } | 647 } |
650 | 648 |
651 // AppMenuIconController::Delegate: | 649 // AppMenuIconController::Delegate: |
652 void ToolbarView::UpdateSeverity(AppMenuIconController::IconType type, | 650 void ToolbarView::UpdateSeverity(AppMenuIconController::IconType type, |
653 AppMenuIconPainter::Severity severity, | 651 AppMenuIconPainter::Severity severity, |
654 bool animate) { | 652 bool animate) { |
655 // There's no app menu in tabless windows. | 653 // There's no app menu in tabless windows. |
656 if (!app_menu_button_) | 654 if (!app_menu_button_) |
657 return; | 655 return; |
658 | 656 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 GetLayoutConstant(TOOLBAR_STANDARD_SPACING) + | 706 GetLayoutConstant(TOOLBAR_STANDARD_SPACING) + |
709 (browser_actions_width > 0 ? browser_actions_width : right_padding) + | 707 (browser_actions_width > 0 ? browser_actions_width : right_padding) + |
710 (app_menu_button_->*get_size)().width(); | 708 (app_menu_button_->*get_size)().width(); |
711 size.Enlarge(content_width, 0); | 709 size.Enlarge(content_width, 0); |
712 } | 710 } |
713 return SizeForContentSize(size); | 711 return SizeForContentSize(size); |
714 } | 712 } |
715 | 713 |
716 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { | 714 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { |
717 if (is_display_mode_normal()) { | 715 if (is_display_mode_normal()) { |
718 // For Material Design the size of the toolbar is computed using the size | 716 // The size of the toolbar is computed using the size of the location bar |
719 // of the location bar and constant padding values. For non-material the | 717 // and constant padding values. |
720 // size is based on the provided assets. | 718 int content_height = std::max(back_->GetPreferredSize().height(), |
721 if (ui::MaterialDesignController::IsModeMaterial()) { | 719 location_bar_->GetPreferredSize().height()); |
722 int content_height = std::max(back_->GetPreferredSize().height(), | 720 int padding = GetLayoutInsets(TOOLBAR).height(); |
723 location_bar_->GetPreferredSize().height()); | 721 size.SetToMax(gfx::Size(0, content_height + padding)); |
724 int padding = GetLayoutInsets(TOOLBAR).height(); | |
725 size.SetToMax(gfx::Size(0, content_height + padding)); | |
726 } else { | |
727 gfx::ImageSkia* normal_background = | |
728 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | |
729 size.SetToMax( | |
730 gfx::Size(0, normal_background->height() - content_shadow_height())); | |
731 } | |
732 } | 722 } |
733 return size; | 723 return size; |
734 } | 724 } |
735 | 725 |
736 void ToolbarView::LoadImages() { | 726 void ToolbarView::LoadImages() { |
737 const ui::ThemeProvider* tp = GetThemeProvider(); | 727 const ui::ThemeProvider* tp = GetThemeProvider(); |
738 | 728 |
739 if (ui::MaterialDesignController::IsModeMaterial()) { | 729 const SkColor normal_color = |
740 const SkColor normal_color = | 730 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); |
741 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 731 const SkColor disabled_color = |
742 const SkColor disabled_color = | 732 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE); |
743 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE); | |
744 | 733 |
745 back_->SetImage(views::Button::STATE_NORMAL, | 734 back_->SetImage(views::Button::STATE_NORMAL, |
746 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_BACK, | 735 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_BACK, |
747 normal_color)); | 736 normal_color)); |
748 back_->SetImage(views::Button::STATE_DISABLED, | 737 back_->SetImage(views::Button::STATE_DISABLED, |
749 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_BACK, | 738 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_BACK, |
750 disabled_color)); | 739 disabled_color)); |
751 forward_->SetImage( | 740 forward_->SetImage( |
752 views::Button::STATE_NORMAL, | 741 views::Button::STATE_NORMAL, |
753 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_FORWARD, | 742 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_FORWARD, |
754 normal_color)); | 743 normal_color)); |
755 forward_->SetImage( | 744 forward_->SetImage( |
756 views::Button::STATE_DISABLED, | 745 views::Button::STATE_DISABLED, |
757 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_FORWARD, | 746 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_FORWARD, |
758 disabled_color)); | 747 disabled_color)); |
759 home_->SetImage(views::Button::STATE_NORMAL, | 748 home_->SetImage(views::Button::STATE_NORMAL, |
760 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_HOME, | 749 gfx::CreateVectorIcon(gfx::VectorIconId::NAVIGATE_HOME, |
761 normal_color)); | 750 normal_color)); |
762 app_menu_button_->UpdateIcon(); | 751 app_menu_button_->UpdateIcon(); |
763 | 752 |
764 back_->set_ink_drop_base_color(normal_color); | 753 back_->set_ink_drop_base_color(normal_color); |
765 forward_->set_ink_drop_base_color(normal_color); | 754 forward_->set_ink_drop_base_color(normal_color); |
766 home_->set_ink_drop_base_color(normal_color); | 755 home_->set_ink_drop_base_color(normal_color); |
767 app_menu_button_->set_ink_drop_base_color(normal_color); | 756 app_menu_button_->set_ink_drop_base_color(normal_color); |
768 } else { | |
769 back_->SetImage(views::Button::STATE_NORMAL, | |
770 *(tp->GetImageSkiaNamed(IDR_BACK))); | |
771 back_->SetImage(views::Button::STATE_DISABLED, | |
772 *(tp->GetImageSkiaNamed(IDR_BACK_D))); | |
773 forward_->SetImage(views::Button::STATE_NORMAL, | |
774 *(tp->GetImageSkiaNamed(IDR_FORWARD))); | |
775 forward_->SetImage(views::Button::STATE_DISABLED, | |
776 *(tp->GetImageSkiaNamed(IDR_FORWARD_D))); | |
777 home_->SetImage(views::Button::STATE_NORMAL, | |
778 *(tp->GetImageSkiaNamed(IDR_HOME))); | |
779 } | |
780 | 757 |
781 reload_->LoadImages(); | 758 reload_->LoadImages(); |
782 } | 759 } |
783 | 760 |
784 void ToolbarView::ShowCriticalNotification() { | 761 void ToolbarView::ShowCriticalNotification() { |
785 #if defined(OS_WIN) | 762 #if defined(OS_WIN) |
786 views::BubbleDialogDelegateView::CreateBubble( | 763 views::BubbleDialogDelegateView::CreateBubble( |
787 new CriticalNotificationBubbleView(app_menu_button_))->Show(); | 764 new CriticalNotificationBubbleView(app_menu_button_))->Show(); |
788 #endif | 765 #endif |
789 } | 766 } |
790 | 767 |
791 void ToolbarView::ShowOutdatedInstallNotification(bool auto_update_enabled) { | 768 void ToolbarView::ShowOutdatedInstallNotification(bool auto_update_enabled) { |
792 if (OutdatedUpgradeBubbleView::IsAvailable()) { | 769 if (OutdatedUpgradeBubbleView::IsAvailable()) { |
793 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, | 770 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, |
794 auto_update_enabled); | 771 auto_update_enabled); |
795 } | 772 } |
796 } | 773 } |
797 | 774 |
798 void ToolbarView::OnShowHomeButtonChanged() { | 775 void ToolbarView::OnShowHomeButtonChanged() { |
799 Layout(); | 776 Layout(); |
800 SchedulePaint(); | 777 SchedulePaint(); |
801 } | 778 } |
802 | |
803 int ToolbarView::content_shadow_height() const { | |
804 #if defined(USE_ASH) | |
805 return GetLayoutConstant(TOOLBAR_CONTENT_SHADOW_HEIGHT_ASH); | |
806 #else | |
807 return GetLayoutConstant(TOOLBAR_CONTENT_SHADOW_HEIGHT); | |
808 #endif | |
809 } | |
OLD | NEW |