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

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

Issue 1330423003: [Extensions Toolbar] Protect against crazy bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Peter's 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
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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 home_->SetBounds(next_element_x, child_y, 605 home_->SetBounds(next_element_x, child_y,
606 home_->GetPreferredSize().width(), child_height); 606 home_->GetPreferredSize().width(), child_height);
607 } else { 607 } else {
608 home_->SetVisible(false); 608 home_->SetVisible(false);
609 home_->SetBounds(next_element_x, child_y, 0, child_height); 609 home_->SetBounds(next_element_x, child_y, 0, child_height);
610 } 610 }
611 next_element_x = home_->bounds().right() + 611 next_element_x = home_->bounds().right() +
612 theme_provider->GetDisplayProperty( 612 theme_provider->GetDisplayProperty(
613 ThemeProperties::PROPERTY_TOOLBAR_VIEW_STANDARD_SPACING); 613 ThemeProperties::PROPERTY_TOOLBAR_VIEW_STANDARD_SPACING);
614 614
615 int browser_actions_width = browser_actions_->GetPreferredSize().width(); 615 int browser_actions_desired_width =
616 browser_actions_->GetPreferredSize().width();
616 int app_menu_width = app_menu_->GetPreferredSize().width(); 617 int app_menu_width = app_menu_->GetPreferredSize().width();
617 const int right_edge_spacing = theme_provider->GetDisplayProperty( 618 const int right_edge_spacing = theme_provider->GetDisplayProperty(
618 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); 619 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING);
619 const int location_bar_right_padding = theme_provider->GetDisplayProperty( 620 const int location_bar_right_padding = theme_provider->GetDisplayProperty(
620 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING); 621 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LOCATION_BAR_RIGHT_PADDING);
622
623 // Don't allow the omnibox to shrink to the point of non-existence, so
624 // subtract its minimum width from the available width to reserve it.
625 int minimum_location_bar_width = location_bar_->GetMinimumSize().width();
621 int available_width = std::max( 626 int available_width = std::max(
622 0, width() - right_edge_spacing - app_menu_width - browser_actions_width - 627 0, width() - right_edge_spacing - app_menu_width -
623 (browser_actions_width > 0 ? element_padding : 0) - 628 (browser_actions_desired_width > 0 ? element_padding : 0) -
624 location_bar_right_padding - next_element_x); 629 location_bar_right_padding - next_element_x -
630 minimum_location_bar_width);
631 int browser_actions_width =
632 std::min(available_width, browser_actions_desired_width);
633 available_width -= browser_actions_width;
634 // The location bar takes whatever's left, plus the minimum width we "set
635 // aside" above.
Peter Kasting 2015/09/17 00:18:04 This helps, but I think instead of subtracting the
Devlin 2015/09/17 17:00:27 Done.
636 int location_bar_width = minimum_location_bar_width + available_width;
625 637
626 int location_height = location_bar_->GetPreferredSize().height(); 638 int location_height = location_bar_->GetPreferredSize().height();
627 int location_y = CenteredChildY(height(), location_height); 639 int location_y = CenteredChildY(height(), location_height);
628 640
629 location_bar_->SetBounds(next_element_x, location_y, 641 location_bar_->SetBounds(next_element_x, location_y,
630 std::max(available_width, 0), location_height); 642 location_bar_width, location_height);
631 next_element_x = location_bar_->bounds().right() + location_bar_right_padding; 643 next_element_x = location_bar_->bounds().right() + location_bar_right_padding;
632 644
633 browser_actions_->SetBounds( 645 browser_actions_->SetBounds(
634 next_element_x, child_y, browser_actions_width, child_height); 646 next_element_x, child_y, browser_actions_width, child_height);
635 next_element_x = browser_actions_->bounds().right(); 647 next_element_x = browser_actions_->bounds().right();
636 if (browser_actions_width > 0) 648 if (browser_actions_width > 0)
637 next_element_x += element_padding; 649 next_element_x += element_padding;
638 650
639 // The browser actions need to do a layout explicitly, because when an 651 // The browser actions need to do a layout explicitly, because when an
640 // extension is loaded/unloaded/changed, BrowserActionContainer removes and 652 // extension is loaded/unloaded/changed, BrowserActionContainer removes and
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 SchedulePaint(); 864 SchedulePaint();
853 } 865 }
854 866
855 int ToolbarView::content_shadow_height() const { 867 int ToolbarView::content_shadow_height() const {
856 ui::ThemeProvider* theme_provider = GetThemeProvider(); 868 ui::ThemeProvider* theme_provider = GetThemeProvider();
857 return theme_provider->GetDisplayProperty( 869 return theme_provider->GetDisplayProperty(
858 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH 870 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
859 ? ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH 871 ? ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH
860 : ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); 872 : ThemeProperties::PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT);
861 } 873 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698