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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_view.cc

Issue 1322323006: Change toolbar height for material design on Ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: only changed frame for Ash Created 5 years, 3 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
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 roundoff_amount = ui::MaterialDesignController::IsModeMaterial() ? 0 : 1;
111 return (parent_height - child_height + roundoff_amount) / 2;
112 }
113
105 } // namespace 114 } // namespace
106 115
107 // static 116 // static
108 const char ToolbarView::kViewClassName[] = "ToolbarView"; 117 const char ToolbarView::kViewClassName[] = "ToolbarView";
109 118
110 //////////////////////////////////////////////////////////////////////////////// 119 ////////////////////////////////////////////////////////////////////////////////
111 // ToolbarView, public: 120 // ToolbarView, public:
112 121
113 ToolbarView::ToolbarView(Browser* browser) 122 ToolbarView::ToolbarView(Browser* browser)
114 : back_(NULL), 123 : back_(NULL),
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 if (back_ == NULL) 555 if (back_ == NULL)
547 return; 556 return;
548 557
549 if (!is_display_mode_normal()) { 558 if (!is_display_mode_normal()) {
550 location_bar_->SetBounds(0, PopupTopSpacing(), width(), 559 location_bar_->SetBounds(0, PopupTopSpacing(), width(),
551 location_bar_->GetPreferredSize().height()); 560 location_bar_->GetPreferredSize().height());
552 return; 561 return;
553 } 562 }
554 563
555 // We assume all child elements except the location bar are the same height. 564 // 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 565 // Set child_y such that buttons appear vertically centered.
557 // padding above the buttons.
558 int child_height = 566 int child_height =
559 std::min(back_->GetPreferredSize().height(), height()); 567 std::min(back_->GetPreferredSize().height(), height());
560 int child_y = (height() - child_height + 1) / 2; 568 int child_y = CenteredChildY(height(), child_height);
561 569
562 // If the window is maximized, we extend the back button to the left so that 570 // 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. 571 // clicking on the left-most pixel will activate the back button.
564 // TODO(abarth): If the window becomes maximized but is not resized, 572 // TODO(abarth): If the window becomes maximized but is not resized,
565 // then Layout() might not be called and the back button 573 // then Layout() might not be called and the back button
566 // will be slightly the wrong size. We should force a 574 // will be slightly the wrong size. We should force a
567 // Layout() in this case. 575 // Layout() in this case.
568 // http://crbug.com/5540 576 // http://crbug.com/5540
569 bool maximized = browser_->window() && browser_->window()->IsMaximized(); 577 bool maximized = browser_->window() && browser_->window()->IsMaximized();
570 int back_width = back_->GetPreferredSize().width(); 578 int back_width = back_->GetPreferredSize().width();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 const int right_edge_spacing = theme_provider->GetDisplayProperty( 617 const int right_edge_spacing = theme_provider->GetDisplayProperty(
610 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); 618 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING);
611 const int location_bar_right_padding = theme_provider->GetDisplayProperty( 619 const int location_bar_right_padding = theme_provider->GetDisplayProperty(
612 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING); 620 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING);
613 int available_width = std::max( 621 int available_width = std::max(
614 0, width() - right_edge_spacing - app_menu_width - browser_actions_width - 622 0, width() - right_edge_spacing - app_menu_width - browser_actions_width -
615 (browser_actions_width > 0 ? element_padding : 0) - 623 (browser_actions_width > 0 ? element_padding : 0) -
616 location_bar_right_padding - next_element_x); 624 location_bar_right_padding - next_element_x);
617 625
618 int location_height = location_bar_->GetPreferredSize().height(); 626 int location_height = location_bar_->GetPreferredSize().height();
619 int location_y = (height() - location_height + 1) / 2; 627 int location_y = CenteredChildY(height(), location_height);
628
620 location_bar_->SetBounds(next_element_x, location_y, 629 location_bar_->SetBounds(next_element_x, location_y,
621 std::max(available_width, 0), location_height); 630 std::max(available_width, 0), location_height);
622 next_element_x = location_bar_->bounds().right() + location_bar_right_padding; 631 next_element_x = location_bar_->bounds().right() + location_bar_right_padding;
623 632
624 browser_actions_->SetBounds( 633 browser_actions_->SetBounds(
625 next_element_x, child_y, browser_actions_width, child_height); 634 next_element_x, child_y, browser_actions_width, child_height);
626 next_element_x = browser_actions_->bounds().right(); 635 next_element_x = browser_actions_->bounds().right();
627 if (browser_actions_width > 0) 636 if (browser_actions_width > 0)
628 next_element_x += element_padding; 637 next_element_x += element_padding;
629 638
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 } 765 }
757 766
758 int ToolbarView::PopupTopSpacing() const { 767 int ToolbarView::PopupTopSpacing() const {
759 const int kPopupTopSpacingNonGlass = 3; 768 const int kPopupTopSpacingNonGlass = 3;
760 return GetWidget()->ShouldWindowContentsBeTransparent() ? 769 return GetWidget()->ShouldWindowContentsBeTransparent() ?
761 0 : kPopupTopSpacingNonGlass; 770 0 : kPopupTopSpacingNonGlass;
762 } 771 }
763 772
764 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { 773 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const {
765 if (is_display_mode_normal()) { 774 if (is_display_mode_normal()) {
766 // For Material Design the size of ToolbarView is encoded as a constant in 775 // For Material Design the size of the toolbar is computed using the size
767 // ThemeProperties. For non-material the size is based on the provided 776 // of the location bar and constant padding values. For non-material the
768 // assets. 777 // size is based on the provided assets.
769 if (ui::MaterialDesignController::IsModeMaterial()) { 778 if (ui::MaterialDesignController::IsModeMaterial()) {
770 int content_height = std::max(back_->GetPreferredSize().height(), 779 int content_height = std::max(back_->GetPreferredSize().height(),
771 location_bar_->GetPreferredSize().height()); 780 location_bar_->GetPreferredSize().height());
772 int padding = GetThemeProvider()->GetDisplayProperty( 781 int top_padding = GetThemeProvider()->GetDisplayProperty(
773 ThemeProperties::PROPERTY_TOOLBAR_VIEW_VERTICAL_PADDING); 782 ThemeProperties::PROPERTY_TOOLBAR_VIEW_TOP_VERTICAL_PADDING);
774 size.SetToMax(gfx::Size(0, content_height + (padding * 2))); 783 int bottom_padding = GetThemeProvider()->GetDisplayProperty(
784 ThemeProperties::PROPERTY_TOOLBAR_VIEW_BOTTOM_VERTICAL_PADDING);
785 size.SetToMax(
786 gfx::Size(0, content_height + top_padding + bottom_padding));
775 } else { 787 } else {
776 gfx::ImageSkia* normal_background = 788 gfx::ImageSkia* normal_background =
777 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); 789 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
778 size.SetToMax( 790 size.SetToMax(
779 gfx::Size(0, normal_background->height() - content_shadow_height())); 791 gfx::Size(0, normal_background->height() - content_shadow_height()));
780 } 792 }
781 } else if (size.height() == 0) { 793 } else if (size.height() == 0) {
782 // Location mode with a 0 height location bar. If on ash, expand by one 794 // 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 795 // pixel to show a border in the title bar, otherwise leave the size as zero
784 // height. 796 // height.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 SchedulePaint(); 852 SchedulePaint();
841 } 853 }
842 854
843 int ToolbarView::content_shadow_height() const { 855 int ToolbarView::content_shadow_height() const {
844 ui::ThemeProvider* theme_provider = GetThemeProvider(); 856 ui::ThemeProvider* theme_provider = GetThemeProvider();
845 return theme_provider->GetDisplayProperty( 857 return theme_provider->GetDisplayProperty(
846 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH 858 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
847 ? ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH 859 ? ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH
848 : ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); 860 : ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT);
849 } 861 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698