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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 #else | 217 #else |
217 app_menu_ = new WrenchToolbarButton(this); | 218 app_menu_ = new WrenchToolbarButton(this); |
218 #endif | 219 #endif |
219 app_menu_->set_border(NULL); | 220 app_menu_->set_border(NULL); |
220 app_menu_->EnableCanvasFlippingForRTLUI(true); | 221 app_menu_->EnableCanvasFlippingForRTLUI(true); |
221 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); | 222 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); |
222 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); | 223 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); |
223 app_menu_->set_id(VIEW_ID_APP_MENU); | 224 app_menu_->set_id(VIEW_ID_APP_MENU); |
224 | 225 |
225 // Always add children in order from left to right, for accessibility. | 226 // Always add children in order from left to right, for accessibility. |
| 227 site_chip_view_ = new SiteChipView(this); |
| 228 chrome::OriginChipPosition origin_chip_position = |
| 229 chrome::GetOriginChipPosition(); |
226 AddChildView(back_); | 230 AddChildView(back_); |
227 AddChildView(forward_); | 231 AddChildView(forward_); |
228 AddChildView(reload_); | 232 AddChildView(reload_); |
229 AddChildView(home_); | 233 AddChildView(home_); |
| 234 if (origin_chip_position == chrome::ORIGIN_CHIP_LEADING_LOCATION_BAR) |
| 235 AddChildView(site_chip_view_); |
230 AddChildView(location_bar_); | 236 AddChildView(location_bar_); |
231 site_chip_view_ = new SiteChipView(this); | 237 if (origin_chip_position == chrome::ORIGIN_CHIP_TRAILING_LOCATION_BAR) |
232 AddChildView(site_chip_view_); | 238 AddChildView(site_chip_view_); |
233 AddChildView(browser_actions_); | 239 AddChildView(browser_actions_); |
| 240 if (origin_chip_position == chrome::ORIGIN_CHIP_LEADING_MENU_BUTTON || |
| 241 origin_chip_position == chrome::ORIGIN_CHIP_DISABLED) |
| 242 AddChildView(site_chip_view_); |
234 AddChildView(app_menu_); | 243 AddChildView(app_menu_); |
235 | 244 |
236 LoadImages(); | 245 LoadImages(); |
237 | 246 |
238 // Add any necessary badges to the menu item based on the system state. | 247 // Add any necessary badges to the menu item based on the system state. |
239 // Do this after |app_menu_| has been added as a bubble may be shown that | 248 // Do this after |app_menu_| has been added as a bubble may be shown that |
240 // needs the widget (widget found by way of app_menu_->GetWidget()). | 249 // needs the widget (widget found by way of app_menu_->GetWidget()). |
241 UpdateAppMenuState(); | 250 UpdateAppMenuState(); |
242 | 251 |
243 location_bar_->Init(); | 252 location_bar_->Init(); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 // http://crbug.com/5540 | 556 // http://crbug.com/5540 |
548 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 557 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
549 int back_width = back_->GetPreferredSize().width(); | 558 int back_width = back_->GetPreferredSize().width(); |
550 if (maximized) { | 559 if (maximized) { |
551 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); | 560 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); |
552 back_->SetLeadingMargin(kLeftEdgeSpacing); | 561 back_->SetLeadingMargin(kLeftEdgeSpacing); |
553 } else { | 562 } else { |
554 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); | 563 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); |
555 back_->SetLeadingMargin(0); | 564 back_->SetLeadingMargin(0); |
556 } | 565 } |
| 566 int button_spacing = GetButtonSpacing(); |
| 567 int next_element_x = back_->bounds().right() + button_spacing; |
557 | 568 |
558 int button_spacing = GetButtonSpacing(); | 569 forward_->SetBounds(next_element_x, child_y, |
559 forward_->SetBounds(back_->x() + back_->width() + button_spacing, | 570 forward_->GetPreferredSize().width(), child_height); |
560 child_y, forward_->GetPreferredSize().width(), child_height); | 571 next_element_x = forward_->bounds().right() + button_spacing; |
561 | 572 |
562 reload_->SetBounds(forward_->x() + forward_->width() + button_spacing, | 573 reload_->SetBounds(next_element_x, child_y, |
563 child_y, reload_->GetPreferredSize().width(), child_height); | 574 reload_->GetPreferredSize().width(), child_height); |
| 575 next_element_x = reload_->bounds().right(); |
564 | 576 |
565 if (show_home_button_.GetValue()) { | 577 if (show_home_button_.GetValue()) { |
566 home_->SetVisible(true); | 578 home_->SetVisible(true); |
567 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 579 home_->SetBounds(next_element_x + button_spacing, child_y, |
568 child_y, home_->GetPreferredSize().width(), child_height); | 580 home_->GetPreferredSize().width(), child_height); |
569 } else { | 581 } else { |
570 home_->SetVisible(false); | 582 home_->SetVisible(false); |
571 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 583 home_->SetBounds(next_element_x, child_y, 0, child_height); |
572 } | 584 } |
| 585 next_element_x = home_->bounds().right() + kStandardSpacing; |
573 | 586 |
574 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 587 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
575 | |
576 int app_menu_width = app_menu_->GetPreferredSize().width(); | 588 int app_menu_width = app_menu_->GetPreferredSize().width(); |
577 int location_x = home_->x() + home_->width() + kStandardSpacing; | |
578 int available_width = std::max(0, width() - kRightEdgeSpacing - | 589 int available_width = std::max(0, width() - kRightEdgeSpacing - |
579 app_menu_width - browser_actions_width - location_x); | 590 app_menu_width - browser_actions_width - next_element_x); |
580 | 591 |
581 // Cap site chip width at 1/2 the size available to the location bar. | 592 // Cap site chip width at 1/2 the size available to the location bar. |
582 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); | 593 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); |
583 int site_chip_width = site_chip_view_->GetPreferredSize().width(); | 594 int site_chip_width = site_chip_view_->GetPreferredSize().width(); |
584 site_chip_width = std::max(0, std::min(site_chip_width, | 595 site_chip_width = std::max(0, std::min(site_chip_width, |
585 (available_width - kStandardSpacing) / 2)); | 596 (available_width - kStandardSpacing) / 2)); |
586 if (site_chip_view_->visible()) | 597 if (site_chip_view_->visible()) |
587 available_width -= site_chip_width + kStandardSpacing; | 598 available_width -= site_chip_width + kStandardSpacing; |
588 | 599 |
| 600 chrome::OriginChipPosition origin_chip_position = |
| 601 chrome::GetOriginChipPosition(); |
| 602 if (origin_chip_position == chrome::ORIGIN_CHIP_LEADING_LOCATION_BAR) { |
| 603 site_chip_view_->SetBounds(next_element_x, child_y, |
| 604 site_chip_width, child_height); |
| 605 next_element_x = site_chip_view_->bounds().right() + kStandardSpacing; |
| 606 } |
| 607 |
589 int location_height = location_bar_->GetPreferredSize().height(); | 608 int location_height = location_bar_->GetPreferredSize().height(); |
590 int location_y = (height() - location_height + 1) / 2; | 609 int location_y = (height() - location_height + 1) / 2; |
591 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 610 location_bar_->SetBounds(next_element_x, location_y, |
592 location_height); | 611 std::max(available_width, 0), location_height); |
593 int browser_actions_x = location_bar_->bounds().right(); | 612 next_element_x = location_bar_->bounds().right(); |
594 | 613 |
595 if (site_chip_view_->visible()) { | 614 if (origin_chip_position == chrome::ORIGIN_CHIP_TRAILING_LOCATION_BAR) { |
596 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, | 615 site_chip_view_->SetBounds(next_element_x + kStandardSpacing, child_y, |
597 child_y, | 616 site_chip_width, child_height); |
598 site_chip_width, | 617 next_element_x = site_chip_view_->bounds().right(); |
599 child_height); | |
600 browser_actions_x = site_chip_view_->bounds().right(); | |
601 } | 618 } |
602 | 619 |
603 browser_actions_->SetBounds(browser_actions_x, 0, | 620 browser_actions_->SetBounds(next_element_x, 0, |
604 browser_actions_width, height()); | 621 browser_actions_width, height()); |
| 622 next_element_x = browser_actions_->bounds().right(); |
605 | 623 |
606 // The browser actions need to do a layout explicitly, because when an | 624 // The browser actions need to do a layout explicitly, because when an |
607 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 625 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
608 // re-adds everything, regardless of whether it has a page action. For a | 626 // re-adds everything, regardless of whether it has a page action. For a |
609 // page action, browser action bounds do not change, as a result of which | 627 // page action, browser action bounds do not change, as a result of which |
610 // SetBounds does not do a layout at all. | 628 // SetBounds does not do a layout at all. |
611 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 629 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
612 // required. | 630 // required. |
613 browser_actions_->Layout(); | 631 browser_actions_->Layout(); |
614 | 632 |
| 633 if (origin_chip_position == chrome::ORIGIN_CHIP_LEADING_MENU_BUTTON) { |
| 634 site_chip_view_->SetBounds(next_element_x, child_y, |
| 635 site_chip_width, child_height); |
| 636 next_element_x = site_chip_view_->bounds().right() + kStandardSpacing; |
| 637 } |
| 638 |
615 // Extend the app menu to the screen's right edge in maximized mode just like | 639 // Extend the app menu to the screen's right edge in maximized mode just like |
616 // we extend the back button to the left edge. | 640 // we extend the back button to the left edge. |
617 if (maximized) | 641 if (maximized) |
618 app_menu_width += kRightEdgeSpacing; | 642 app_menu_width += kRightEdgeSpacing; |
619 app_menu_->SetBounds(browser_actions_->x() + browser_actions_width, child_y, | 643 app_menu_->SetBounds(next_element_x, child_y, app_menu_width, child_height); |
620 app_menu_width, child_height); | |
621 } | 644 } |
622 | 645 |
623 bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { | 646 bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { |
624 // Fall through to the tab strip above us if none of |rect| intersects | 647 // Fall through to the tab strip above us if none of |rect| intersects |
625 // with this view (intersection with the top shadow edge does not | 648 // with this view (intersection with the top shadow edge does not |
626 // count as intersection with this view). | 649 // count as intersection with this view). |
627 if (rect.bottom() < content_shadow_height()) | 650 if (rect.bottom() < content_shadow_height()) |
628 return false; | 651 return false; |
629 // Otherwise let our superclass take care of it. | 652 // Otherwise let our superclass take care of it. |
630 return AccessiblePaneView::HitTestRect(rect); | 653 return AccessiblePaneView::HitTestRect(rect); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 | 833 |
811 void ToolbarView::OnShowHomeButtonChanged() { | 834 void ToolbarView::OnShowHomeButtonChanged() { |
812 Layout(); | 835 Layout(); |
813 SchedulePaint(); | 836 SchedulePaint(); |
814 } | 837 } |
815 | 838 |
816 int ToolbarView::content_shadow_height() const { | 839 int ToolbarView::content_shadow_height() const { |
817 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 840 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
818 kContentShadowHeightAsh : kContentShadowHeight; | 841 kContentShadowHeightAsh : kContentShadowHeight; |
819 } | 842 } |
OLD | NEW |