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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 home_->SetVisible(true); | 586 home_->SetVisible(true); |
587 home_->SetBounds(next_element_x, child_y, | 587 home_->SetBounds(next_element_x, child_y, |
588 home_->GetPreferredSize().width(), child_height); | 588 home_->GetPreferredSize().width(), child_height); |
589 } else { | 589 } else { |
590 home_->SetVisible(false); | 590 home_->SetVisible(false); |
591 home_->SetBounds(next_element_x, child_y, 0, child_height); | 591 home_->SetBounds(next_element_x, child_y, 0, child_height); |
592 } | 592 } |
593 next_element_x = home_->bounds().right() + | 593 next_element_x = home_->bounds().right() + |
594 GetLayoutConstant(TOOLBAR_VIEW_STANDARD_SPACING); | 594 GetLayoutConstant(TOOLBAR_VIEW_STANDARD_SPACING); |
595 | 595 |
596 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 596 int browser_actions_desired_width = |
| 597 browser_actions_->GetPreferredSize().width(); |
597 int app_menu_width = app_menu_->GetPreferredSize().width(); | 598 int app_menu_width = app_menu_->GetPreferredSize().width(); |
598 const int location_bar_right_padding = | 599 const int location_bar_right_padding = |
599 GetLayoutConstant(TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING); | 600 GetLayoutConstant(TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING); |
| 601 |
600 int available_width = std::max( | 602 int available_width = std::max( |
601 0, width() - insets.right() - app_menu_width - browser_actions_width - | 603 0, width() - insets.right() - app_menu_width - |
602 (browser_actions_width > 0 ? element_padding : 0) - | 604 (browser_actions_desired_width > 0 ? element_padding : 0) - |
603 location_bar_right_padding - next_element_x); | 605 location_bar_right_padding - next_element_x); |
| 606 // Don't allow the omnibox to shrink to the point of non-existence, so |
| 607 // subtract its minimum width from the available width to reserve it. |
| 608 int minimum_location_bar_width = location_bar_->GetMinimumSize().width(); |
| 609 int browser_actions_width = |
| 610 std::min(std::max(available_width - minimum_location_bar_width, 0), |
| 611 browser_actions_desired_width); |
| 612 available_width -= browser_actions_width; |
| 613 int location_bar_width = available_width; |
604 | 614 |
605 int location_height = location_bar_->GetPreferredSize().height(); | 615 int location_height = location_bar_->GetPreferredSize().height(); |
606 int location_y = CenteredChildY(height(), location_height); | 616 int location_y = CenteredChildY(height(), location_height); |
607 | 617 |
608 location_bar_->SetBounds(next_element_x, location_y, | 618 location_bar_->SetBounds(next_element_x, location_y, |
609 std::max(available_width, 0), location_height); | 619 location_bar_width, location_height); |
610 next_element_x = location_bar_->bounds().right() + location_bar_right_padding; | 620 next_element_x = location_bar_->bounds().right() + location_bar_right_padding; |
611 | 621 |
612 browser_actions_->SetBounds( | 622 browser_actions_->SetBounds( |
613 next_element_x, child_y, browser_actions_width, child_height); | 623 next_element_x, child_y, browser_actions_width, child_height); |
614 next_element_x = browser_actions_->bounds().right(); | 624 next_element_x = browser_actions_->bounds().right(); |
615 if (browser_actions_width > 0) | 625 if (browser_actions_width > 0) |
616 next_element_x += element_padding; | 626 next_element_x += element_padding; |
617 | 627 |
618 // The browser actions need to do a layout explicitly, because when an | 628 // The browser actions need to do a layout explicitly, because when an |
619 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 629 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 Layout(); | 836 Layout(); |
827 SchedulePaint(); | 837 SchedulePaint(); |
828 } | 838 } |
829 | 839 |
830 int ToolbarView::content_shadow_height() const { | 840 int ToolbarView::content_shadow_height() const { |
831 return GetLayoutConstant( | 841 return GetLayoutConstant( |
832 (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 842 (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
833 ? TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH | 843 ? TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH |
834 : TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); | 844 : TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); |
835 } | 845 } |
OLD | NEW |