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

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

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

Powered by Google App Engine
This is Rietveld 408576698