Chromium Code Reviews| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 #if !defined(OS_CHROMEOS) | 95 #if !defined(OS_CHROMEOS) |
| 96 bool HasAshShell() { | 96 bool HasAshShell() { |
| 97 #if defined(USE_ASH) | 97 #if defined(USE_ASH) |
| 98 return ash::Shell::HasInstance(); | 98 return ash::Shell::HasInstance(); |
| 99 #else | 99 #else |
| 100 return false; | 100 return false; |
| 101 #endif // USE_ASH | 101 #endif // USE_ASH |
| 102 } | 102 } |
| 103 #endif // OS_CHROMEOS | 103 #endif // OS_CHROMEOS |
| 104 | 104 |
| 105 // Returns the y-position that will center an element of height | |
| 106 // |child_height| inside an element of height |parent_height|. For | |
| 107 // material design excess padding is placed below, for non-material | |
| 108 // it is placed above. | |
| 109 int CenteredChildY(int parent_height, int child_height) { | |
| 110 int child_y = (parent_height - child_height + 1) / 2; | |
|
Peter Kasting
2015/09/08 19:38:34
Nit: Why not just:
int roundoff_amount = ui::Ma
tdanderson
2015/09/09 17:23:06
Changed.
| |
| 111 if (!ui::MaterialDesignController::IsModeMaterial() || | |
| 112 parent_height - child_height % 2 == 0) { | |
| 113 return child_y; | |
| 114 } | |
| 115 return child_y - 1; | |
| 116 } | |
| 117 | |
| 105 } // namespace | 118 } // namespace |
| 106 | 119 |
| 107 // static | 120 // static |
| 108 const char ToolbarView::kViewClassName[] = "ToolbarView"; | 121 const char ToolbarView::kViewClassName[] = "ToolbarView"; |
| 109 | 122 |
| 110 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
| 111 // ToolbarView, public: | 124 // ToolbarView, public: |
| 112 | 125 |
| 113 ToolbarView::ToolbarView(Browser* browser) | 126 ToolbarView::ToolbarView(Browser* browser) |
| 114 : back_(NULL), | 127 : back_(NULL), |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 return; | 560 return; |
| 548 | 561 |
| 549 if (!is_display_mode_normal()) { | 562 if (!is_display_mode_normal()) { |
| 550 location_bar_->SetBounds(0, PopupTopSpacing(), width(), | 563 location_bar_->SetBounds(0, PopupTopSpacing(), width(), |
| 551 location_bar_->GetPreferredSize().height()); | 564 location_bar_->GetPreferredSize().height()); |
| 552 return; | 565 return; |
| 553 } | 566 } |
| 554 | 567 |
| 555 // We assume all child elements except the location bar are the same height. | 568 // We assume all child elements except the location bar are the same height. |
| 556 // Set child_y such that buttons appear vertically centered. We put any excess | 569 // Set child_y such that buttons appear vertically centered. We put any excess |
| 557 // padding above the buttons. | 570 // padding above the buttons. |
|
Peter Kasting
2015/09/08 19:38:34
Nit: Delete the last sentence here
tdanderson
2015/09/09 17:23:06
Done.
| |
| 558 int child_height = | 571 int child_height = |
| 559 std::min(back_->GetPreferredSize().height(), height()); | 572 std::min(back_->GetPreferredSize().height(), height()); |
| 560 int child_y = (height() - child_height + 1) / 2; | 573 int child_y = CenteredChildY(height(), child_height); |
| 561 | 574 |
| 562 // If the window is maximized, we extend the back button to the left so that | 575 // If the window is maximized, we extend the back button to the left so that |
| 563 // clicking on the left-most pixel will activate the back button. | 576 // clicking on the left-most pixel will activate the back button. |
| 564 // TODO(abarth): If the window becomes maximized but is not resized, | 577 // TODO(abarth): If the window becomes maximized but is not resized, |
| 565 // then Layout() might not be called and the back button | 578 // then Layout() might not be called and the back button |
| 566 // will be slightly the wrong size. We should force a | 579 // will be slightly the wrong size. We should force a |
| 567 // Layout() in this case. | 580 // Layout() in this case. |
| 568 // http://crbug.com/5540 | 581 // http://crbug.com/5540 |
| 569 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 582 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
| 570 int back_width = back_->GetPreferredSize().width(); | 583 int back_width = back_->GetPreferredSize().width(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 const int right_edge_spacing = theme_provider->GetDisplayProperty( | 622 const int right_edge_spacing = theme_provider->GetDisplayProperty( |
| 610 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); | 623 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); |
| 611 const int location_bar_right_padding = theme_provider->GetDisplayProperty( | 624 const int location_bar_right_padding = theme_provider->GetDisplayProperty( |
| 612 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING); | 625 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING); |
| 613 int available_width = std::max( | 626 int available_width = std::max( |
| 614 0, width() - right_edge_spacing - app_menu_width - browser_actions_width - | 627 0, width() - right_edge_spacing - app_menu_width - browser_actions_width - |
| 615 (browser_actions_width > 0 ? element_padding : 0) - | 628 (browser_actions_width > 0 ? element_padding : 0) - |
| 616 location_bar_right_padding - next_element_x); | 629 location_bar_right_padding - next_element_x); |
| 617 | 630 |
| 618 int location_height = location_bar_->GetPreferredSize().height(); | 631 int location_height = location_bar_->GetPreferredSize().height(); |
| 619 int location_y = (height() - location_height + 1) / 2; | 632 int location_y = CenteredChildY(height(), location_height); |
| 633 | |
| 620 location_bar_->SetBounds(next_element_x, location_y, | 634 location_bar_->SetBounds(next_element_x, location_y, |
| 621 std::max(available_width, 0), location_height); | 635 std::max(available_width, 0), location_height); |
| 622 next_element_x = location_bar_->bounds().right() + location_bar_right_padding; | 636 next_element_x = location_bar_->bounds().right() + location_bar_right_padding; |
| 623 | 637 |
| 624 browser_actions_->SetBounds( | 638 browser_actions_->SetBounds( |
| 625 next_element_x, child_y, browser_actions_width, child_height); | 639 next_element_x, child_y, browser_actions_width, child_height); |
| 626 next_element_x = browser_actions_->bounds().right(); | 640 next_element_x = browser_actions_->bounds().right(); |
| 627 if (browser_actions_width > 0) | 641 if (browser_actions_width > 0) |
| 628 next_element_x += element_padding; | 642 next_element_x += element_padding; |
| 629 | 643 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 | 771 |
| 758 int ToolbarView::PopupTopSpacing() const { | 772 int ToolbarView::PopupTopSpacing() const { |
| 759 const int kPopupTopSpacingNonGlass = 3; | 773 const int kPopupTopSpacingNonGlass = 3; |
| 760 return GetWidget()->ShouldWindowContentsBeTransparent() ? | 774 return GetWidget()->ShouldWindowContentsBeTransparent() ? |
| 761 0 : kPopupTopSpacingNonGlass; | 775 0 : kPopupTopSpacingNonGlass; |
| 762 } | 776 } |
| 763 | 777 |
| 764 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { | 778 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { |
| 765 if (is_display_mode_normal()) { | 779 if (is_display_mode_normal()) { |
| 766 // For Material Design the size of ToolbarView is encoded as a constant in | 780 // For Material Design the size of ToolbarView is encoded as a constant in |
| 767 // ThemeProperties. For non-material the size is based on the provided | 781 // ThemeProperties. For non-material the size is based on the provided |
|
Peter Kasting
2015/09/08 19:38:33
This description seems somewhat inaccurate. We do
tdanderson
2015/09/09 17:23:06
Re-worded.
| |
| 768 // assets. | 782 // assets. |
| 769 if (ui::MaterialDesignController::IsModeMaterial()) { | 783 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 770 int content_height = std::max(back_->GetPreferredSize().height(), | 784 int content_height = std::max(back_->GetPreferredSize().height(), |
| 771 location_bar_->GetPreferredSize().height()); | 785 location_bar_->GetPreferredSize().height()); |
| 772 int padding = GetThemeProvider()->GetDisplayProperty( | 786 int top_padding = GetThemeProvider()->GetDisplayProperty( |
| 773 ThemeProperties::PROPERTY_TOOLBAR_VIEW_VERTICAL_PADDING); | 787 ThemeProperties::PROPERTY_TOOLBAR_VIEW_TOP_VERTICAL_PADDING); |
| 774 size.SetToMax(gfx::Size(0, content_height + (padding * 2))); | 788 int bottom_padding = GetThemeProvider()->GetDisplayProperty( |
| 789 ThemeProperties::PROPERTY_TOOLBAR_VIEW_BOTTOM_VERTICAL_PADDING); | |
| 790 size.SetToMax( | |
| 791 gfx::Size(0, content_height + (top_padding + bottom_padding))); | |
| 775 } else { | 792 } else { |
| 776 gfx::ImageSkia* normal_background = | 793 gfx::ImageSkia* normal_background = |
| 777 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 794 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
| 778 size.SetToMax( | 795 size.SetToMax( |
| 779 gfx::Size(0, normal_background->height() - content_shadow_height())); | 796 gfx::Size(0, normal_background->height() - content_shadow_height())); |
| 780 } | 797 } |
| 781 } else if (size.height() == 0) { | 798 } else if (size.height() == 0) { |
| 782 // Location mode with a 0 height location bar. If on ash, expand by one | 799 // Location mode with a 0 height location bar. If on ash, expand by one |
| 783 // pixel to show a border in the title bar, otherwise leave the size as zero | 800 // pixel to show a border in the title bar, otherwise leave the size as zero |
| 784 // height. | 801 // height. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 SchedulePaint(); | 857 SchedulePaint(); |
| 841 } | 858 } |
| 842 | 859 |
| 843 int ToolbarView::content_shadow_height() const { | 860 int ToolbarView::content_shadow_height() const { |
| 844 ui::ThemeProvider* theme_provider = GetThemeProvider(); | 861 ui::ThemeProvider* theme_provider = GetThemeProvider(); |
| 845 return theme_provider->GetDisplayProperty( | 862 return theme_provider->GetDisplayProperty( |
| 846 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH | 863 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH |
| 847 ? ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH | 864 ? ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH |
| 848 : ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); | 865 : ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); |
| 849 } | 866 } |
| OLD | NEW |