Chromium Code Reviews| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/command_updater.h" | 14 #include "chrome/browser/command_updater.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search/search.h" | |
| 16 #include "chrome/browser/themes/theme_service.h" | 17 #include "chrome/browser/themes/theme_service.h" |
| 17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_command_controller.h" | 19 #include "chrome/browser/ui/browser_command_controller.h" |
| 19 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 20 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 21 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
| 21 #include "chrome/browser/ui/browser_instant_controller.h" | 22 #include "chrome/browser/ui/browser_instant_controller.h" |
| 22 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/global_error/global_error_service.h" | 25 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 25 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 26 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 #else | 222 #else |
| 222 app_menu_ = new WrenchToolbarButton(this); | 223 app_menu_ = new WrenchToolbarButton(this); |
| 223 #endif | 224 #endif |
| 224 app_menu_->set_border(NULL); | 225 app_menu_->set_border(NULL); |
| 225 app_menu_->EnableCanvasFlippingForRTLUI(true); | 226 app_menu_->EnableCanvasFlippingForRTLUI(true); |
| 226 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); | 227 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); |
| 227 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); | 228 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); |
| 228 app_menu_->set_id(VIEW_ID_APP_MENU); | 229 app_menu_->set_id(VIEW_ID_APP_MENU); |
| 229 | 230 |
| 230 // Always add children in order from left to right, for accessibility. | 231 // Always add children in order from left to right, for accessibility. |
| 232 site_chip_view_ = new SiteChipView(this); | |
| 233 chrome::OriginChipPosition origin_chip_position = | |
| 234 chrome::GetOriginChipPosition(); | |
| 231 AddChildView(back_); | 235 AddChildView(back_); |
| 232 AddChildView(forward_); | 236 AddChildView(forward_); |
| 233 AddChildView(reload_); | 237 AddChildView(reload_); |
| 234 AddChildView(home_); | 238 AddChildView(home_); |
| 239 if (origin_chip_position == chrome::ORIGIN_CHIP_LEFT_OF_LOCATION_BAR) | |
| 240 AddChildView(site_chip_view_); | |
| 235 AddChildView(location_bar_); | 241 AddChildView(location_bar_); |
| 236 site_chip_view_ = new SiteChipView(this); | 242 if (origin_chip_position == chrome::ORIGIN_CHIP_RIGHT_OF_LOCATION_BAR) |
| 237 AddChildView(site_chip_view_); | 243 AddChildView(site_chip_view_); |
| 238 AddChildView(browser_actions_); | 244 AddChildView(browser_actions_); |
| 245 if (origin_chip_position == chrome::ORIGIN_CHIP_LEFT_OF_MENU || | |
| 246 origin_chip_position == chrome::ORIGIN_CHIP_DISABLED) | |
| 247 AddChildView(site_chip_view_); | |
| 239 AddChildView(app_menu_); | 248 AddChildView(app_menu_); |
| 240 | 249 |
| 241 LoadImages(); | 250 LoadImages(); |
| 242 | 251 |
| 243 // Add any necessary badges to the menu item based on the system state. | 252 // Add any necessary badges to the menu item based on the system state. |
| 244 // Do this after |app_menu_| has been added as a bubble may be shown that | 253 // Do this after |app_menu_| has been added as a bubble may be shown that |
| 245 // needs the widget (widget found by way of app_menu_->GetWidget()). | 254 // needs the widget (widget found by way of app_menu_->GetWidget()). |
| 246 UpdateAppMenuState(); | 255 UpdateAppMenuState(); |
| 247 | 256 |
| 248 location_bar_->Init(); | 257 location_bar_->Init(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 // http://crbug.com/5540 | 561 // http://crbug.com/5540 |
| 553 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 562 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
| 554 int back_width = back_->GetPreferredSize().width(); | 563 int back_width = back_->GetPreferredSize().width(); |
| 555 if (maximized) { | 564 if (maximized) { |
| 556 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); | 565 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); |
| 557 back_->SetLeadingMargin(kLeftEdgeSpacing); | 566 back_->SetLeadingMargin(kLeftEdgeSpacing); |
| 558 } else { | 567 } else { |
| 559 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); | 568 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); |
| 560 back_->SetLeadingMargin(0); | 569 back_->SetLeadingMargin(0); |
| 561 } | 570 } |
| 571 int button_spacing = GetButtonSpacing(); | |
| 572 int next_element_x = back_->bounds().right() + button_spacing; | |
| 562 | 573 |
| 563 int button_spacing = GetButtonSpacing(); | 574 forward_->SetBounds(next_element_x, child_y, |
| 564 forward_->SetBounds(back_->x() + back_->width() + button_spacing, | 575 forward_->GetPreferredSize().width(), child_height); |
| 565 child_y, forward_->GetPreferredSize().width(), child_height); | 576 next_element_x = forward_->bounds().right() + button_spacing; |
| 566 | 577 |
| 567 reload_->SetBounds(forward_->x() + forward_->width() + button_spacing, | 578 reload_->SetBounds(next_element_x, child_y, |
| 568 child_y, reload_->GetPreferredSize().width(), child_height); | 579 reload_->GetPreferredSize().width(), child_height); |
| 580 next_element_x = reload_->bounds().right(); | |
| 569 | 581 |
| 570 if (show_home_button_.GetValue()) { | 582 if (show_home_button_.GetValue()) { |
| 571 home_->SetVisible(true); | 583 home_->SetVisible(true); |
| 572 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 584 home_->SetBounds(next_element_x + button_spacing, child_y, |
| 573 child_y, home_->GetPreferredSize().width(), child_height); | 585 home_->GetPreferredSize().width(), child_height); |
| 574 } else { | 586 } else { |
| 575 home_->SetVisible(false); | 587 home_->SetVisible(false); |
| 576 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 588 home_->SetBounds(next_element_x, child_y, 0, child_height); |
| 577 } | 589 } |
| 590 next_element_x = home_->bounds().right() + kStandardSpacing; | |
| 578 | 591 |
| 579 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 592 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
| 580 | |
| 581 int app_menu_width = app_menu_->GetPreferredSize().width(); | 593 int app_menu_width = app_menu_->GetPreferredSize().width(); |
| 582 int location_x = home_->x() + home_->width() + kStandardSpacing; | |
| 583 int available_width = std::max(0, width() - kRightEdgeSpacing - | 594 int available_width = std::max(0, width() - kRightEdgeSpacing - |
| 584 app_menu_width - browser_actions_width - location_x); | 595 app_menu_width - browser_actions_width - next_element_x); |
| 585 | 596 |
| 586 // Cap site chip width at 1/2 the size available to the location bar. | 597 // Cap site chip width at 1/2 the size available to the location bar. |
| 587 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); | 598 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); |
| 588 int site_chip_width = site_chip_view_->GetPreferredSize().width(); | 599 int site_chip_width = site_chip_view_->GetPreferredSize().width(); |
| 589 site_chip_width = std::max(0, std::min(site_chip_width, | 600 site_chip_width = std::max(0, std::min(site_chip_width, |
| 590 (available_width - kStandardSpacing) / 2)); | 601 (available_width - kStandardSpacing) / 2)); |
| 591 if (site_chip_view_->visible()) | 602 if (site_chip_view_->visible()) |
| 592 available_width -= site_chip_width + kStandardSpacing; | 603 available_width -= site_chip_width + kStandardSpacing; |
| 593 | 604 |
| 605 chrome::OriginChipPosition origin_chip_position = | |
| 606 chrome::GetOriginChipPosition(); | |
| 607 if (origin_chip_position == chrome::ORIGIN_CHIP_LEFT_OF_LOCATION_BAR) { | |
| 608 site_chip_view_->SetBounds(next_element_x, child_y, | |
| 609 site_chip_width, child_height); | |
| 610 next_element_x = site_chip_view_->bounds().right() + kStandardSpacing; | |
| 611 } | |
| 612 | |
| 594 int location_height = location_bar_->GetPreferredSize().height(); | 613 int location_height = location_bar_->GetPreferredSize().height(); |
| 595 int location_y = (height() - location_height + 1) / 2; | 614 int location_y = (height() - location_height + 1) / 2; |
| 596 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 615 location_bar_->SetBounds(next_element_x, location_y, |
| 597 location_height); | 616 std::max(available_width, 0), location_height); |
| 598 int browser_actions_x = location_bar_->bounds().right(); | 617 next_element_x = location_bar_->bounds().right(); |
| 599 | 618 |
| 600 if (site_chip_view_->visible()) { | 619 if (origin_chip_position == chrome::ORIGIN_CHIP_RIGHT_OF_LOCATION_BAR) { |
| 601 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, | 620 site_chip_view_->SetBounds(next_element_x + kStandardSpacing, child_y, |
| 602 child_y, | 621 site_chip_width, child_height); |
| 603 site_chip_width, | 622 next_element_x = site_chip_view_->bounds().right(); |
| 604 child_height); | |
| 605 browser_actions_x = site_chip_view_->bounds().right(); | |
| 606 } | 623 } |
| 607 | 624 |
| 608 browser_actions_->SetBounds(browser_actions_x, 0, | 625 browser_actions_->SetBounds(next_element_x, 0, |
| 609 browser_actions_width, height()); | 626 browser_actions_width, height()); |
| 627 next_element_x = browser_actions_->bounds().right(); | |
| 610 | 628 |
| 611 // The browser actions need to do a layout explicitly, because when an | 629 // The browser actions need to do a layout explicitly, because when an |
| 612 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 630 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
| 613 // re-adds everything, regardless of whether it has a page action. For a | 631 // re-adds everything, regardless of whether it has a page action. For a |
| 614 // page action, browser action bounds do not change, as a result of which | 632 // page action, browser action bounds do not change, as a result of which |
| 615 // SetBounds does not do a layout at all. | 633 // SetBounds does not do a layout at all. |
| 616 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 634 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
| 617 // required. | 635 // required. |
| 618 browser_actions_->Layout(); | 636 browser_actions_->Layout(); |
| 619 | 637 |
| 638 if (origin_chip_position == chrome::ORIGIN_CHIP_LEFT_OF_MENU) { | |
| 639 site_chip_view_->SetBounds(next_element_x, child_y, | |
| 640 site_chip_width, child_height); | |
| 641 next_element_x = site_chip_view_->bounds().right() + kStandardSpacing; | |
|
msw
2014/01/10 18:26:04
nit: why add spacing between the origin chip and m
Justin Donnelly
2014/01/10 20:11:31
Yes, the browser actions container adds the spacin
| |
| 642 } | |
| 643 | |
| 620 // Extend the app menu to the screen's right edge in maximized mode just like | 644 // Extend the app menu to the screen's right edge in maximized mode just like |
| 621 // we extend the back button to the left edge. | 645 // we extend the back button to the left edge. |
| 622 if (maximized) | 646 if (maximized) |
| 623 app_menu_width += kRightEdgeSpacing; | 647 app_menu_width += kRightEdgeSpacing; |
| 624 app_menu_->SetBounds(browser_actions_->x() + browser_actions_width, child_y, | 648 app_menu_->SetBounds(next_element_x, child_y, app_menu_width, child_height); |
| 625 app_menu_width, child_height); | |
| 626 } | 649 } |
| 627 | 650 |
| 628 bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { | 651 bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { |
| 629 // Fall through to the tab strip above us if none of |rect| intersects | 652 // Fall through to the tab strip above us if none of |rect| intersects |
| 630 // with this view (intersection with the top shadow edge does not | 653 // with this view (intersection with the top shadow edge does not |
| 631 // count as intersection with this view). | 654 // count as intersection with this view). |
| 632 if (rect.bottom() < content_shadow_height()) | 655 if (rect.bottom() < content_shadow_height()) |
| 633 return false; | 656 return false; |
| 634 // Otherwise let our superclass take care of it. | 657 // Otherwise let our superclass take care of it. |
| 635 return AccessiblePaneView::HitTestRect(rect); | 658 return AccessiblePaneView::HitTestRect(rect); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 | 838 |
| 816 void ToolbarView::OnShowHomeButtonChanged() { | 839 void ToolbarView::OnShowHomeButtonChanged() { |
| 817 Layout(); | 840 Layout(); |
| 818 SchedulePaint(); | 841 SchedulePaint(); |
| 819 } | 842 } |
| 820 | 843 |
| 821 int ToolbarView::content_shadow_height() const { | 844 int ToolbarView::content_shadow_height() const { |
| 822 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 845 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
| 823 kContentShadowHeightAsh : kContentShadowHeight; | 846 kContentShadowHeightAsh : kContentShadowHeight; |
| 824 } | 847 } |
| OLD | NEW |