| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 #if !defined(OS_CHROMEOS) | 99 #if !defined(OS_CHROMEOS) |
| 100 bool HasAshShell() { | 100 bool HasAshShell() { |
| 101 #if defined(USE_ASH) | 101 #if defined(USE_ASH) |
| 102 return ash::Shell::HasInstance(); | 102 return ash::Shell::HasInstance(); |
| 103 #else | 103 #else |
| 104 return false; | 104 return false; |
| 105 #endif // USE_ASH | 105 #endif // USE_ASH |
| 106 } | 106 } |
| 107 #endif // OS_CHROMEOS | 107 #endif // OS_CHROMEOS |
| 108 | 108 |
| 109 int GetToolbarHorizontalPadding() { |
| 110 using Md = ui::MaterialDesignController; |
| 111 return Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; |
| 112 } |
| 113 |
| 109 } // namespace | 114 } // namespace |
| 110 | 115 |
| 111 // static | 116 // static |
| 112 const char ToolbarView::kViewClassName[] = "ToolbarView"; | 117 const char ToolbarView::kViewClassName[] = "ToolbarView"; |
| 113 | 118 |
| 114 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 115 // ToolbarView, public: | 120 // ToolbarView, public: |
| 116 | 121 |
| 117 ToolbarView::ToolbarView(Browser* browser) | 122 ToolbarView::ToolbarView(Browser* browser) |
| 118 : back_(nullptr), | 123 : back_(nullptr), |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // If the window is maximized, we extend the back button to the left so that | 529 // If the window is maximized, we extend the back button to the left so that |
| 525 // clicking on the left-most pixel will activate the back button. | 530 // clicking on the left-most pixel will activate the back button. |
| 526 // TODO(abarth): If the window becomes maximized but is not resized, | 531 // TODO(abarth): If the window becomes maximized but is not resized, |
| 527 // then Layout() might not be called and the back button | 532 // then Layout() might not be called and the back button |
| 528 // will be slightly the wrong size. We should force a | 533 // will be slightly the wrong size. We should force a |
| 529 // Layout() in this case. | 534 // Layout() in this case. |
| 530 // http://crbug.com/5540 | 535 // http://crbug.com/5540 |
| 531 const bool maximized = | 536 const bool maximized = |
| 532 browser_->window() && browser_->window()->IsMaximized(); | 537 browser_->window() && browser_->window()->IsMaximized(); |
| 533 const int back_width = back_->GetPreferredSize().width(); | 538 const int back_width = back_->GetPreferredSize().width(); |
| 534 const gfx::Insets insets(GetLayoutInsets(TOOLBAR)); | 539 // The padding at either end of the toolbar. |
| 540 const int end_padding = GetToolbarHorizontalPadding(); |
| 535 if (maximized) { | 541 if (maximized) { |
| 536 back_->SetBounds(0, child_y, back_width + insets.left(), child_height); | 542 back_->SetBounds(0, child_y, back_width + end_padding, child_height); |
| 537 back_->SetLeadingMargin(insets.left()); | 543 back_->SetLeadingMargin(end_padding); |
| 538 } else { | 544 } else { |
| 539 back_->SetBounds(insets.left(), child_y, back_width, child_height); | 545 back_->SetBounds(end_padding, child_y, back_width, child_height); |
| 540 back_->SetLeadingMargin(0); | 546 back_->SetLeadingMargin(0); |
| 541 } | 547 } |
| 542 const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); | 548 const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); |
| 543 int next_element_x = back_->bounds().right() + element_padding; | 549 int next_element_x = back_->bounds().right() + element_padding; |
| 544 | 550 |
| 545 forward_->SetBounds(next_element_x, child_y, | 551 forward_->SetBounds(next_element_x, child_y, |
| 546 forward_->GetPreferredSize().width(), child_height); | 552 forward_->GetPreferredSize().width(), child_height); |
| 547 next_element_x = forward_->bounds().right() + element_padding; | 553 next_element_x = forward_->bounds().right() + element_padding; |
| 548 | 554 |
| 549 reload_->SetBounds(next_element_x, child_y, | 555 reload_->SetBounds(next_element_x, child_y, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 566 int app_menu_width = app_menu_button_->GetPreferredSize().width(); | 572 int app_menu_width = app_menu_button_->GetPreferredSize().width(); |
| 567 const int right_padding = | 573 const int right_padding = |
| 568 GetLayoutConstant(TOOLBAR_LOCATION_BAR_RIGHT_PADDING); | 574 GetLayoutConstant(TOOLBAR_LOCATION_BAR_RIGHT_PADDING); |
| 569 | 575 |
| 570 // Note that the browser actions container has its own internal left and right | 576 // Note that the browser actions container has its own internal left and right |
| 571 // padding to visually separate it from the location bar and app menu button. | 577 // padding to visually separate it from the location bar and app menu button. |
| 572 // However if the container is empty we must account for the |right_padding| | 578 // However if the container is empty we must account for the |right_padding| |
| 573 // value used to visually separate the location bar and app menu button. | 579 // value used to visually separate the location bar and app menu button. |
| 574 int available_width = std::max( | 580 int available_width = std::max( |
| 575 0, | 581 0, |
| 576 width() - insets.right() - app_menu_width - | 582 width() - end_padding - app_menu_width - |
| 577 (browser_actions_->GetPreferredSize().IsEmpty() ? right_padding : 0) - | 583 (browser_actions_->GetPreferredSize().IsEmpty() ? right_padding : 0) - |
| 578 next_element_x); | 584 next_element_x); |
| 579 // Don't allow the omnibox to shrink to the point of non-existence, so | 585 // Don't allow the omnibox to shrink to the point of non-existence, so |
| 580 // subtract its minimum width from the available width to reserve it. | 586 // subtract its minimum width from the available width to reserve it. |
| 581 const int browser_actions_width = browser_actions_->GetWidthForMaxWidth( | 587 const int browser_actions_width = browser_actions_->GetWidthForMaxWidth( |
| 582 available_width - location_bar_->GetMinimumSize().width()); | 588 available_width - location_bar_->GetMinimumSize().width()); |
| 583 available_width -= browser_actions_width; | 589 available_width -= browser_actions_width; |
| 584 const int location_bar_width = available_width; | 590 const int location_bar_width = available_width; |
| 585 | 591 |
| 586 const int location_height = location_bar_->GetPreferredSize().height(); | 592 const int location_height = location_bar_->GetPreferredSize().height(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 601 // re-adds everything, regardless of whether it has a page action. For a | 607 // re-adds everything, regardless of whether it has a page action. For a |
| 602 // page action, browser action bounds do not change, as a result of which | 608 // page action, browser action bounds do not change, as a result of which |
| 603 // SetBounds does not do a layout at all. | 609 // SetBounds does not do a layout at all. |
| 604 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 610 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
| 605 // required. | 611 // required. |
| 606 browser_actions_->Layout(); | 612 browser_actions_->Layout(); |
| 607 | 613 |
| 608 // Extend the app menu to the screen's right edge in maximized mode just like | 614 // Extend the app menu to the screen's right edge in maximized mode just like |
| 609 // we extend the back button to the left edge. | 615 // we extend the back button to the left edge. |
| 610 if (maximized) | 616 if (maximized) |
| 611 app_menu_width += insets.right(); | 617 app_menu_width += end_padding; |
| 612 app_menu_button_->SetBounds(next_element_x, child_y, app_menu_width, | 618 app_menu_button_->SetBounds(next_element_x, child_y, app_menu_width, |
| 613 child_height); | 619 child_height); |
| 614 app_menu_button_->SetTrailingMargin(maximized ? insets.right() : 0); | 620 app_menu_button_->SetTrailingMargin(maximized ? end_padding : 0); |
| 615 } | 621 } |
| 616 | 622 |
| 617 void ToolbarView::OnThemeChanged() { | 623 void ToolbarView::OnThemeChanged() { |
| 618 if (is_display_mode_normal()) | 624 if (is_display_mode_normal()) |
| 619 LoadImages(); | 625 LoadImages(); |
| 620 } | 626 } |
| 621 | 627 |
| 622 const char* ToolbarView::GetClassName() const { | 628 const char* ToolbarView::GetClassName() const { |
| 623 return kViewClassName; | 629 return kViewClassName; |
| 624 } | 630 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 gfx::Size ToolbarView::GetSizeInternal( | 706 gfx::Size ToolbarView::GetSizeInternal( |
| 701 gfx::Size (View::*get_size)() const) const { | 707 gfx::Size (View::*get_size)() const) const { |
| 702 gfx::Size size((location_bar_->*get_size)()); | 708 gfx::Size size((location_bar_->*get_size)()); |
| 703 if (is_display_mode_normal()) { | 709 if (is_display_mode_normal()) { |
| 704 const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); | 710 const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); |
| 705 const int browser_actions_width = | 711 const int browser_actions_width = |
| 706 (browser_actions_->*get_size)().width(); | 712 (browser_actions_->*get_size)().width(); |
| 707 const int right_padding = | 713 const int right_padding = |
| 708 GetLayoutConstant(TOOLBAR_LOCATION_BAR_RIGHT_PADDING); | 714 GetLayoutConstant(TOOLBAR_LOCATION_BAR_RIGHT_PADDING); |
| 709 const int content_width = | 715 const int content_width = |
| 710 GetLayoutInsets(TOOLBAR).width() + | 716 2 * GetToolbarHorizontalPadding() + (back_->*get_size)().width() + |
| 711 (back_->*get_size)().width() + element_padding + | 717 element_padding + (forward_->*get_size)().width() + element_padding + |
| 712 (forward_->*get_size)().width() + element_padding + | |
| 713 (reload_->*get_size)().width() + | 718 (reload_->*get_size)().width() + |
| 714 (show_home_button_.GetValue() | 719 (show_home_button_.GetValue() |
| 715 ? element_padding + (home_->*get_size)().width() | 720 ? element_padding + (home_->*get_size)().width() |
| 716 : 0) + | 721 : 0) + |
| 717 GetLayoutConstant(TOOLBAR_STANDARD_SPACING) + | 722 GetLayoutConstant(TOOLBAR_STANDARD_SPACING) + |
| 718 (browser_actions_width > 0 ? browser_actions_width : right_padding) + | 723 (browser_actions_width > 0 ? browser_actions_width : right_padding) + |
| 719 (app_menu_button_->*get_size)().width(); | 724 (app_menu_button_->*get_size)().width(); |
| 720 size.Enlarge(content_width, 0); | 725 size.Enlarge(content_width, 0); |
| 721 } | 726 } |
| 722 return SizeForContentSize(size); | 727 return SizeForContentSize(size); |
| 723 } | 728 } |
| 724 | 729 |
| 725 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { | 730 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { |
| 726 if (is_display_mode_normal()) { | 731 if (is_display_mode_normal()) { |
| 727 // The size of the toolbar is computed using the size of the location bar | 732 // The size of the toolbar is computed using the size of the location bar |
| 728 // and constant padding values. | 733 // and constant padding values. |
| 729 int content_height = std::max(back_->GetPreferredSize().height(), | 734 int content_height = std::max(back_->GetPreferredSize().height(), |
| 730 location_bar_->GetPreferredSize().height()); | 735 location_bar_->GetPreferredSize().height()); |
| 731 int padding = GetLayoutInsets(TOOLBAR).height(); | 736 const int kExtraVerticalSpace = 9; |
| 732 size.SetToMax(gfx::Size(0, content_height + padding)); | 737 size.SetToMax(gfx::Size(0, content_height + kExtraVerticalSpace)); |
| 733 } | 738 } |
| 734 return size; | 739 return size; |
| 735 } | 740 } |
| 736 | 741 |
| 737 void ToolbarView::LoadImages() { | 742 void ToolbarView::LoadImages() { |
| 738 const ui::ThemeProvider* tp = GetThemeProvider(); | 743 const ui::ThemeProvider* tp = GetThemeProvider(); |
| 739 | 744 |
| 740 const SkColor normal_color = | 745 const SkColor normal_color = |
| 741 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 746 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); |
| 742 const SkColor disabled_color = | 747 const SkColor disabled_color = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 if (OutdatedUpgradeBubbleView::IsAvailable()) { | 783 if (OutdatedUpgradeBubbleView::IsAvailable()) { |
| 779 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, | 784 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, |
| 780 auto_update_enabled); | 785 auto_update_enabled); |
| 781 } | 786 } |
| 782 } | 787 } |
| 783 | 788 |
| 784 void ToolbarView::OnShowHomeButtonChanged() { | 789 void ToolbarView::OnShowHomeButtonChanged() { |
| 785 Layout(); | 790 Layout(); |
| 786 SchedulePaint(); | 791 SchedulePaint(); |
| 787 } | 792 } |
| OLD | NEW |