Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/toolbar_view.cc |
| diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.cc b/chrome/browser/ui/views/toolbar/toolbar_view.cc |
| index 0df0bed6514691766823d571342e84d1ad3976ed..16f63f41c4cd5502b708109015ba409257bd486d 100644 |
| --- a/chrome/browser/ui/views/toolbar/toolbar_view.cc |
| +++ b/chrome/browser/ui/views/toolbar/toolbar_view.cc |
| @@ -13,6 +13,7 @@ |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/command_updater.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/search/search.h" |
| #include "chrome/browser/themes/theme_service.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_command_controller.h" |
| @@ -37,6 +38,7 @@ |
| #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| #include "chrome/browser/ui/views/toolbar/home_button.h" |
| #include "chrome/browser/ui/views/toolbar/reload_button.h" |
| +#include "chrome/browser/ui/views/toolbar/site_chip_view.h" |
| #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
| #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" |
| @@ -121,6 +123,7 @@ ToolbarView::ToolbarView(Browser* browser) |
| reload_(NULL), |
| home_(NULL), |
| location_bar_(NULL), |
| + site_chip_view_(NULL), |
| browser_actions_(NULL), |
| app_menu_(NULL), |
| browser_(browser) { |
| @@ -227,6 +230,8 @@ void ToolbarView::Init() { |
| AddChildView(reload_); |
| AddChildView(home_); |
| AddChildView(location_bar_); |
| + site_chip_view_ = new SiteChipView(this); |
| + AddChildView(site_chip_view_); |
| AddChildView(browser_actions_); |
| AddChildView(app_menu_); |
| @@ -238,6 +243,7 @@ void ToolbarView::Init() { |
| UpdateAppMenuState(); |
| location_bar_->Init(); |
| + site_chip_view_->Init(); |
| show_home_button_.Init(prefs::kShowHomeButton, |
| browser_->profile()->GetPrefs(), |
| base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
| @@ -266,6 +272,8 @@ void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, |
| void ToolbarView::Update(WebContents* tab) { |
| if (location_bar_) |
| location_bar_->Update(tab); |
| + if (site_chip_view_) |
| + site_chip_view_->Update(tab); |
| if (browser_actions_) |
| browser_actions_->RefreshBrowserActionViews(); |
| @@ -480,6 +488,7 @@ bool ToolbarView::GetAcceleratorForCommandId(int command_id, |
| gfx::Size ToolbarView::GetPreferredSize() { |
| if (is_display_mode_normal()) { |
| int button_spacing = GetButtonSpacing(); |
| + int site_chip_spacing = kStandardSpacing - 1; |
|
Peter Kasting
2013/12/03 00:58:10
Nit: Don't calculate this value in two different p
Greg Billock
2013/12/03 17:35:08
This is just an artifact of how the images are pro
|
| int min_width = kLeftEdgeSpacing + |
| back_->GetPreferredSize().width() + button_spacing + |
| forward_->GetPreferredSize().width() + button_spacing + |
| @@ -487,6 +496,9 @@ gfx::Size ToolbarView::GetPreferredSize() { |
| (show_home_button_.GetValue() ? |
| (home_->GetPreferredSize().width() + button_spacing) : 0) + |
| location_bar_->GetPreferredSize().width() + |
| + (site_chip_view_->ShouldShow() ? |
| + site_chip_view_->GetPreferredSize().width() + |
| + 2*site_chip_spacing + 2*button_spacing : 0) + |
|
Peter Kasting
2013/12/03 00:58:10
Nit: Spaces around operators
Indent this line 4 m
Greg Billock
2013/12/03 17:35:08
Done.
|
| browser_actions_->GetPreferredSize().width() + |
| app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
| gfx::ImageSkia* normal_background = |
| @@ -556,18 +568,43 @@ void ToolbarView::Layout() { |
| } |
| int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
| + |
| + // Note: spacing from location bar to site chip is 1 pixel less than |
| + // kStandardSpacing given the edge thickness of the chip. |
| + int site_chip_spacing = kStandardSpacing - 1; |
| + int site_chip_width = |
| + (site_chip_view_->ShouldShow() ? |
| + site_chip_view_->GetPreferredSize().width() + |
| + 2 * site_chip_spacing : 0); |
| int app_menu_width = app_menu_->GetPreferredSize().width(); |
| int location_x = home_->x() + home_->width() + kStandardSpacing; |
| int available_width = std::max(0, width() - kRightEdgeSpacing - |
| app_menu_width - browser_actions_width - location_x); |
| + // Cap site chip width at 1/2 the size available to the location bar. |
| + site_chip_width = std::min(site_chip_width, available_width / 2); |
| + available_width -= site_chip_width; |
| + |
| int location_height = location_bar_->GetPreferredSize().height(); |
| int location_y = (height() - location_height + 1) / 2; |
| location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
| location_height); |
| - browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, |
| + int browser_actions_x = location_bar_->x() + location_bar_->width(); |
|
Peter Kasting
2013/12/03 00:58:10
So we put the browser actions flush against the lo
Greg Billock
2013/12/03 17:35:08
The browser actions are borderless, so this is giv
|
| + |
| + if (site_chip_view_->ShouldShow()) { |
| + site_chip_view_->SetBounds(location_bar_->x() + location_bar_->width() + |
|
Peter Kasting
2013/12/03 00:58:10
Nit: Replace first two terms with "browser_actions
Greg Billock
2013/12/03 17:35:08
Done.
|
| + site_chip_spacing, |
| + child_y, |
| + site_chip_view_->GetPreferredSize().width(), |
| + child_height); |
| + browser_actions_x += site_chip_view_->GetPreferredSize().width() + |
|
Peter Kasting
2013/12/03 00:58:10
Nit: Break after "+=" instead to avoid wrapping th
Greg Billock
2013/12/03 17:35:08
Done.
|
| + site_chip_spacing; |
| + } |
| + |
| + browser_actions_->SetBounds(browser_actions_x, 0, |
| browser_actions_width, height()); |
| + |
| // The browser actions need to do a layout explicitly, because when an |
| // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
| // re-adds everything, regardless of whether it has a page action. For a |