| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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" |
| 26 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 27 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 29 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 29 #include "chrome/browser/ui/view_ids.h" | 30 #include "chrome/browser/ui/view_ids.h" |
| 30 #include "chrome/browser/ui/views/frame/browser_view.h" | 31 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 31 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 32 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 32 #include "chrome/browser/ui/views/location_bar/star_view.h" | 33 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 33 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" | 34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" |
| 34 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" | 35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" |
| 35 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 36 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 36 #include "chrome/browser/ui/views/toolbar/home_button.h" | 37 #include "chrome/browser/ui/views/toolbar/home_button.h" |
| 37 #include "chrome/browser/ui/views/toolbar/reload_button.h" | 38 #include "chrome/browser/ui/views/toolbar/reload_button.h" |
| 39 #include "chrome/browser/ui/views/toolbar/site_chip_view.h" |
| 38 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" | 40 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
| 39 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" | 41 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" |
| 40 #include "chrome/browser/upgrade_detector.h" | 42 #include "chrome/browser/upgrade_detector.h" |
| 41 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
| 43 #include "content/public/browser/browser_accessibility_state.h" | 45 #include "content/public/browser/browser_accessibility_state.h" |
| 44 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/render_view_host.h" | 47 #include "content/public/browser/render_view_host.h" |
| 46 #include "content/public/browser/user_metrics.h" | 48 #include "content/public/browser/user_metrics.h" |
| 47 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 114 |
| 113 //////////////////////////////////////////////////////////////////////////////// | 115 //////////////////////////////////////////////////////////////////////////////// |
| 114 // ToolbarView, public: | 116 // ToolbarView, public: |
| 115 | 117 |
| 116 ToolbarView::ToolbarView(Browser* browser) | 118 ToolbarView::ToolbarView(Browser* browser) |
| 117 : back_(NULL), | 119 : back_(NULL), |
| 118 forward_(NULL), | 120 forward_(NULL), |
| 119 reload_(NULL), | 121 reload_(NULL), |
| 120 home_(NULL), | 122 home_(NULL), |
| 121 location_bar_(NULL), | 123 location_bar_(NULL), |
| 124 site_chip_view_(NULL), |
| 122 browser_actions_(NULL), | 125 browser_actions_(NULL), |
| 123 app_menu_(NULL), | 126 app_menu_(NULL), |
| 124 browser_(browser) { | 127 browser_(browser) { |
| 125 set_id(VIEW_ID_TOOLBAR); | 128 set_id(VIEW_ID_TOOLBAR); |
| 126 | 129 |
| 127 chrome::AddCommandObserver(browser_, IDC_BACK, this); | 130 chrome::AddCommandObserver(browser_, IDC_BACK, this); |
| 128 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); | 131 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); |
| 129 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); | 132 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); |
| 130 chrome::AddCommandObserver(browser_, IDC_HOME, this); | 133 chrome::AddCommandObserver(browser_, IDC_HOME, this); |
| 131 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); | 134 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 app_menu_->set_id(VIEW_ID_APP_MENU); | 224 app_menu_->set_id(VIEW_ID_APP_MENU); |
| 222 | 225 |
| 223 LoadImages(); | 226 LoadImages(); |
| 224 | 227 |
| 225 // Always add children in order from left to right, for accessibility. | 228 // Always add children in order from left to right, for accessibility. |
| 226 AddChildView(back_); | 229 AddChildView(back_); |
| 227 AddChildView(forward_); | 230 AddChildView(forward_); |
| 228 AddChildView(reload_); | 231 AddChildView(reload_); |
| 229 AddChildView(home_); | 232 AddChildView(home_); |
| 230 AddChildView(location_bar_); | 233 AddChildView(location_bar_); |
| 234 if (chrome::ShouldDisplayOriginChip()) { |
| 235 // use --force-fieldtrials=EmbeddedSearch/Group1 origin_chip:1/ to force |
| 236 site_chip_view_ = new SiteChipView(this); |
| 237 AddChildView(site_chip_view_); |
| 238 } |
| 231 AddChildView(browser_actions_); | 239 AddChildView(browser_actions_); |
| 232 AddChildView(app_menu_); | 240 AddChildView(app_menu_); |
| 233 | 241 |
| 234 // Add any necessary badges to the menu item based on the system state. | 242 // Add any necessary badges to the menu item based on the system state. |
| 235 // Do this after |app_menu_| has been added as a bubble may be shown that | 243 // Do this after |app_menu_| has been added as a bubble may be shown that |
| 236 // needs the widget (widget found by way of app_menu_->GetWidget()). | 244 // needs the widget (widget found by way of app_menu_->GetWidget()). |
| 237 UpdateAppMenuState(); | 245 UpdateAppMenuState(); |
| 238 | 246 |
| 239 location_bar_->Init(); | 247 location_bar_->Init(); |
| 248 if (site_chip_view_) |
| 249 site_chip_view_->Init(); |
| 240 show_home_button_.Init(prefs::kShowHomeButton, | 250 show_home_button_.Init(prefs::kShowHomeButton, |
| 241 browser_->profile()->GetPrefs(), | 251 browser_->profile()->GetPrefs(), |
| 242 base::Bind(&ToolbarView::OnShowHomeButtonChanged, | 252 base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
| 243 base::Unretained(this))); | 253 base::Unretained(this))); |
| 244 | 254 |
| 245 browser_actions_->Init(); | 255 browser_actions_->Init(); |
| 246 | 256 |
| 247 // Accessibility specific tooltip text. | 257 // Accessibility specific tooltip text. |
| 248 if (content::BrowserAccessibilityState::GetInstance()-> | 258 if (content::BrowserAccessibilityState::GetInstance()-> |
| 249 IsAccessibleBrowser()) { | 259 IsAccessibleBrowser()) { |
| 250 back_->SetTooltipText( | 260 back_->SetTooltipText( |
| 251 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 261 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
| 252 forward_->SetTooltipText( | 262 forward_->SetTooltipText( |
| 253 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); | 263 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); |
| 254 } | 264 } |
| 255 } | 265 } |
| 256 | 266 |
| 257 void ToolbarView::Update(WebContents* tab) { | 267 void ToolbarView::Update(WebContents* tab) { |
| 258 if (location_bar_) | 268 if (location_bar_) |
| 259 location_bar_->Update(tab); | 269 location_bar_->Update(tab); |
| 270 if (site_chip_view_) |
| 271 site_chip_view_->Update(tab); |
| 260 | 272 |
| 261 if (browser_actions_) | 273 if (browser_actions_) |
| 262 browser_actions_->RefreshBrowserActionViews(); | 274 browser_actions_->RefreshBrowserActionViews(); |
| 263 | 275 |
| 264 if (reload_) | 276 if (reload_) |
| 265 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); | 277 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); |
| 266 } | 278 } |
| 267 | 279 |
| 268 void ToolbarView::SetPaneFocusAndFocusAppMenu() { | 280 void ToolbarView::SetPaneFocusAndFocusAppMenu() { |
| 269 SetPaneFocus(app_menu_); | 281 SetPaneFocus(app_menu_); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 gfx::Size ToolbarView::GetPreferredSize() { | 483 gfx::Size ToolbarView::GetPreferredSize() { |
| 472 if (is_display_mode_normal()) { | 484 if (is_display_mode_normal()) { |
| 473 int button_spacing = GetButtonSpacing(); | 485 int button_spacing = GetButtonSpacing(); |
| 474 int min_width = kLeftEdgeSpacing + | 486 int min_width = kLeftEdgeSpacing + |
| 475 back_->GetPreferredSize().width() + button_spacing + | 487 back_->GetPreferredSize().width() + button_spacing + |
| 476 forward_->GetPreferredSize().width() + button_spacing + | 488 forward_->GetPreferredSize().width() + button_spacing + |
| 477 reload_->GetPreferredSize().width() + kStandardSpacing + | 489 reload_->GetPreferredSize().width() + kStandardSpacing + |
| 478 (show_home_button_.GetValue() ? | 490 (show_home_button_.GetValue() ? |
| 479 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 491 (home_->GetPreferredSize().width() + button_spacing) : 0) + |
| 480 location_bar_->GetPreferredSize().width() + | 492 location_bar_->GetPreferredSize().width() + |
| 493 (site_chip_view_ ? site_chip_view_->GetPreferredSize().width() : 0) + |
| 481 browser_actions_->GetPreferredSize().width() + | 494 browser_actions_->GetPreferredSize().width() + |
| 482 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 495 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
| 483 gfx::ImageSkia* normal_background = | 496 gfx::ImageSkia* normal_background = |
| 484 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 497 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
| 485 return gfx::Size(min_width, | 498 return gfx::Size(min_width, |
| 486 normal_background->height() - content_shadow_height()); | 499 normal_background->height() - content_shadow_height()); |
| 487 } | 500 } |
| 488 | 501 |
| 489 const int kPopupBottomSpacingGlass = 1; | 502 const int kPopupBottomSpacingGlass = 1; |
| 490 const int kPopupBottomSpacingNonGlass = 2; | 503 const int kPopupBottomSpacingNonGlass = 2; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (show_home_button_.GetValue()) { | 550 if (show_home_button_.GetValue()) { |
| 538 home_->SetVisible(true); | 551 home_->SetVisible(true); |
| 539 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 552 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, |
| 540 child_y, home_->GetPreferredSize().width(), child_height); | 553 child_y, home_->GetPreferredSize().width(), child_height); |
| 541 } else { | 554 } else { |
| 542 home_->SetVisible(false); | 555 home_->SetVisible(false); |
| 543 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 556 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
| 544 } | 557 } |
| 545 | 558 |
| 546 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 559 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
| 560 int site_chip_width = |
| 561 site_chip_view_ ? site_chip_view_->GetPreferredSize().width() : 0; |
| 547 int app_menu_width = app_menu_->GetPreferredSize().width(); | 562 int app_menu_width = app_menu_->GetPreferredSize().width(); |
| 548 int location_x = home_->x() + home_->width() + kStandardSpacing; | 563 int location_x = home_->x() + home_->width() + kStandardSpacing; |
| 549 int available_width = std::max(0, width() - kRightEdgeSpacing - | 564 int available_width = std::max(0, width() - kRightEdgeSpacing - |
| 550 app_menu_width - browser_actions_width - location_x); | 565 app_menu_width - browser_actions_width - location_x); |
| 551 | 566 |
| 567 // Cap site chip width at 1/2 the size available to the location bar. |
| 568 site_chip_width = std::min(site_chip_width, available_width/2); |
| 569 available_width -= site_chip_width; |
| 570 |
| 552 int location_height = location_bar_->GetPreferredSize().height(); | 571 int location_height = location_bar_->GetPreferredSize().height(); |
| 553 int location_y = (height() - location_height + 1) / 2; | 572 int location_y = (height() - location_height + 1) / 2; |
| 554 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 573 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
| 555 location_height); | 574 location_height); |
| 556 | 575 |
| 557 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, | 576 int browser_actions_x = location_bar_->x() + location_bar_->width(); |
| 577 if (site_chip_view_) { |
| 578 site_chip_view_->SetBounds(location_bar_->x() + location_bar_->width(), |
| 579 child_y, site_chip_width, child_height); |
| 580 browser_actions_x += site_chip_width; |
| 581 } |
| 582 browser_actions_->SetBounds(browser_actions_x, 0, |
| 558 browser_actions_width, height()); | 583 browser_actions_width, height()); |
| 584 |
| 559 // The browser actions need to do a layout explicitly, because when an | 585 // The browser actions need to do a layout explicitly, because when an |
| 560 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 586 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
| 561 // re-adds everything, regardless of whether it has a page action. For a | 587 // re-adds everything, regardless of whether it has a page action. For a |
| 562 // page action, browser action bounds do not change, as a result of which | 588 // page action, browser action bounds do not change, as a result of which |
| 563 // SetBounds does not do a layout at all. | 589 // SetBounds does not do a layout at all. |
| 564 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 590 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
| 565 // required. | 591 // required. |
| 566 browser_actions_->Layout(); | 592 browser_actions_->Layout(); |
| 567 | 593 |
| 568 // Extend the app menu to the screen's right edge in maximized mode just like | 594 // Extend the app menu to the screen's right edge in maximized mode just like |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 829 |
| 804 void ToolbarView::OnShowHomeButtonChanged() { | 830 void ToolbarView::OnShowHomeButtonChanged() { |
| 805 Layout(); | 831 Layout(); |
| 806 SchedulePaint(); | 832 SchedulePaint(); |
| 807 } | 833 } |
| 808 | 834 |
| 809 int ToolbarView::content_shadow_height() const { | 835 int ToolbarView::content_shadow_height() const { |
| 810 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 836 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
| 811 kContentShadowHeightAsh : kContentShadowHeight; | 837 kContentShadowHeightAsh : kContentShadowHeight; |
| 812 } | 838 } |
| OLD | NEW |