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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h" | 30 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h" |
31 #include "chrome/browser/ui/views/frame/browser_view.h" | 31 #include "chrome/browser/ui/views/frame/browser_view.h" |
32 #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" |
33 #include "chrome/browser/ui/views/location_bar/star_view.h" | 33 #include "chrome/browser/ui/views/location_bar/star_view.h" |
34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" | 34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" |
35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" | 35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" |
36 #include "chrome/browser/ui/views/toolbar/back_button.h" | 36 #include "chrome/browser/ui/views/toolbar/back_button.h" |
37 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 37 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
38 #include "chrome/browser/ui/views/toolbar/home_button.h" | 38 #include "chrome/browser/ui/views/toolbar/home_button.h" |
39 #include "chrome/browser/ui/views/toolbar/reload_button.h" | 39 #include "chrome/browser/ui/views/toolbar/reload_button.h" |
40 #include "chrome/browser/ui/views/toolbar/site_chip_view.h" | |
41 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" | 40 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
42 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" | 41 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
43 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" | 42 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" |
44 #include "chrome/browser/upgrade_detector.h" | 43 #include "chrome/browser/upgrade_detector.h" |
45 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
46 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
47 #include "content/public/browser/browser_accessibility_state.h" | 46 #include "content/public/browser/browser_accessibility_state.h" |
48 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
49 #include "content/public/browser/render_view_host.h" | 48 #include "content/public/browser/render_view_host.h" |
50 #include "content/public/browser/user_metrics.h" | 49 #include "content/public/browser/user_metrics.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 114 |
116 //////////////////////////////////////////////////////////////////////////////// | 115 //////////////////////////////////////////////////////////////////////////////// |
117 // ToolbarView, public: | 116 // ToolbarView, public: |
118 | 117 |
119 ToolbarView::ToolbarView(Browser* browser) | 118 ToolbarView::ToolbarView(Browser* browser) |
120 : back_(NULL), | 119 : back_(NULL), |
121 forward_(NULL), | 120 forward_(NULL), |
122 reload_(NULL), | 121 reload_(NULL), |
123 home_(NULL), | 122 home_(NULL), |
124 location_bar_(NULL), | 123 location_bar_(NULL), |
125 site_chip_view_(NULL), | |
126 browser_actions_(NULL), | 124 browser_actions_(NULL), |
127 app_menu_(NULL), | 125 app_menu_(NULL), |
128 browser_(browser) { | 126 browser_(browser) { |
129 set_id(VIEW_ID_TOOLBAR); | 127 set_id(VIEW_ID_TOOLBAR); |
130 | 128 |
131 chrome::AddCommandObserver(browser_, IDC_BACK, this); | 129 chrome::AddCommandObserver(browser_, IDC_BACK, this); |
132 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); | 130 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); |
133 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); | 131 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); |
134 chrome::AddCommandObserver(browser_, IDC_HOME, this); | 132 chrome::AddCommandObserver(browser_, IDC_HOME, this); |
135 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); | 133 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); | 220 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); |
223 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); | 221 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); |
224 app_menu_->set_id(VIEW_ID_APP_MENU); | 222 app_menu_->set_id(VIEW_ID_APP_MENU); |
225 | 223 |
226 // Always add children in order from left to right, for accessibility. | 224 // Always add children in order from left to right, for accessibility. |
227 AddChildView(back_); | 225 AddChildView(back_); |
228 AddChildView(forward_); | 226 AddChildView(forward_); |
229 AddChildView(reload_); | 227 AddChildView(reload_); |
230 AddChildView(home_); | 228 AddChildView(home_); |
231 AddChildView(location_bar_); | 229 AddChildView(location_bar_); |
232 site_chip_view_ = new SiteChipView(this); | |
233 if (site_chip_view_->ShouldShow()) | |
234 AddChildView(site_chip_view_); | |
235 AddChildView(browser_actions_); | 230 AddChildView(browser_actions_); |
236 AddChildView(app_menu_); | 231 AddChildView(app_menu_); |
237 | 232 |
238 LoadImages(); | 233 LoadImages(); |
239 | 234 |
240 // Add any necessary badges to the menu item based on the system state. | 235 // Add any necessary badges to the menu item based on the system state. |
241 // Do this after |app_menu_| has been added as a bubble may be shown that | 236 // Do this after |app_menu_| has been added as a bubble may be shown that |
242 // needs the widget (widget found by way of app_menu_->GetWidget()). | 237 // needs the widget (widget found by way of app_menu_->GetWidget()). |
243 UpdateAppMenuState(); | 238 UpdateAppMenuState(); |
244 | 239 |
245 location_bar_->Init(); | 240 location_bar_->Init(); |
246 site_chip_view_->Init(); | |
247 show_home_button_.Init(prefs::kShowHomeButton, | 241 show_home_button_.Init(prefs::kShowHomeButton, |
248 browser_->profile()->GetPrefs(), | 242 browser_->profile()->GetPrefs(), |
249 base::Bind(&ToolbarView::OnShowHomeButtonChanged, | 243 base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
250 base::Unretained(this))); | 244 base::Unretained(this))); |
251 | 245 |
252 browser_actions_->Init(); | 246 browser_actions_->Init(); |
253 | 247 |
254 // Accessibility specific tooltip text. | 248 // Accessibility specific tooltip text. |
255 if (content::BrowserAccessibilityState::GetInstance()-> | 249 if (content::BrowserAccessibilityState::GetInstance()-> |
256 IsAccessibleBrowser()) { | 250 IsAccessibleBrowser()) { |
257 back_->SetTooltipText( | 251 back_->SetTooltipText( |
258 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 252 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
259 forward_->SetTooltipText( | 253 forward_->SetTooltipText( |
260 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); | 254 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); |
261 } | 255 } |
262 } | 256 } |
263 | 257 |
264 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, | 258 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, |
265 bool visible) { | 259 bool visible) { |
266 if (visible) { | 260 if (visible) { |
267 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); | 261 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); |
268 GetWidget()->RemoveObserver(this); | 262 GetWidget()->RemoveObserver(this); |
269 } | 263 } |
270 } | 264 } |
271 | 265 |
272 void ToolbarView::Update(WebContents* tab) { | 266 void ToolbarView::Update(WebContents* tab) { |
273 if (location_bar_) | 267 if (location_bar_) |
274 location_bar_->Update(tab); | 268 location_bar_->Update(tab); |
275 if (site_chip_view_->ShouldShow()) | |
276 site_chip_view_->Update(tab); | |
277 | 269 |
278 if (browser_actions_) | 270 if (browser_actions_) |
279 browser_actions_->RefreshBrowserActionViews(); | 271 browser_actions_->RefreshBrowserActionViews(); |
280 | 272 |
281 if (reload_) | 273 if (reload_) |
282 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); | 274 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); |
283 } | 275 } |
284 | 276 |
285 void ToolbarView::SetPaneFocusAndFocusAppMenu() { | 277 void ToolbarView::SetPaneFocusAndFocusAppMenu() { |
286 SetPaneFocus(app_menu_); | 278 SetPaneFocus(app_menu_); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 gfx::Size ToolbarView::GetPreferredSize() { | 480 gfx::Size ToolbarView::GetPreferredSize() { |
489 if (is_display_mode_normal()) { | 481 if (is_display_mode_normal()) { |
490 int button_spacing = GetButtonSpacing(); | 482 int button_spacing = GetButtonSpacing(); |
491 int min_width = kLeftEdgeSpacing + | 483 int min_width = kLeftEdgeSpacing + |
492 back_->GetPreferredSize().width() + button_spacing + | 484 back_->GetPreferredSize().width() + button_spacing + |
493 forward_->GetPreferredSize().width() + button_spacing + | 485 forward_->GetPreferredSize().width() + button_spacing + |
494 reload_->GetPreferredSize().width() + kStandardSpacing + | 486 reload_->GetPreferredSize().width() + kStandardSpacing + |
495 (show_home_button_.GetValue() ? | 487 (show_home_button_.GetValue() ? |
496 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 488 (home_->GetPreferredSize().width() + button_spacing) : 0) + |
497 location_bar_->GetPreferredSize().width() + | 489 location_bar_->GetPreferredSize().width() + |
498 (site_chip_view_->ShouldShow() ? | |
499 (site_chip_view_->GetPreferredSize().width() + | |
500 2 * kStandardSpacing + 2 * button_spacing) : | |
501 0) + | |
502 browser_actions_->GetPreferredSize().width() + | 490 browser_actions_->GetPreferredSize().width() + |
503 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 491 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
504 gfx::ImageSkia* normal_background = | 492 gfx::ImageSkia* normal_background = |
505 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 493 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
506 return gfx::Size(min_width, | 494 return gfx::Size(min_width, |
507 normal_background->height() - content_shadow_height()); | 495 normal_background->height() - content_shadow_height()); |
508 } | 496 } |
509 | 497 |
510 const int kPopupBottomSpacingGlass = 1; | 498 const int kPopupBottomSpacingGlass = 1; |
511 const int kPopupBottomSpacingNonGlass = 2; | 499 const int kPopupBottomSpacingNonGlass = 2; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 if (show_home_button_.GetValue()) { | 549 if (show_home_button_.GetValue()) { |
562 home_->SetVisible(true); | 550 home_->SetVisible(true); |
563 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 551 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, |
564 child_y, home_->GetPreferredSize().width(), child_height); | 552 child_y, home_->GetPreferredSize().width(), child_height); |
565 } else { | 553 } else { |
566 home_->SetVisible(false); | 554 home_->SetVisible(false); |
567 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 555 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
568 } | 556 } |
569 | 557 |
570 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 558 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
571 | |
572 // Note: spacing from location bar to site chip is 1 pixel less than | |
573 // kStandardSpacing given the edge thickness of the chip. | |
574 int site_chip_width = | |
575 (site_chip_view_->ShouldShow() ? | |
576 site_chip_view_->GetPreferredSize().width() + | |
577 kStandardSpacing : 0); | |
578 int app_menu_width = app_menu_->GetPreferredSize().width(); | 559 int app_menu_width = app_menu_->GetPreferredSize().width(); |
579 int location_x = home_->x() + home_->width() + kStandardSpacing; | 560 int location_x = home_->x() + home_->width() + kStandardSpacing; |
580 int available_width = std::max(0, width() - kRightEdgeSpacing - | 561 int available_width = std::max(0, width() - kRightEdgeSpacing - |
581 app_menu_width - browser_actions_width - location_x); | 562 app_menu_width - browser_actions_width - location_x); |
582 | 563 |
583 // Cap site chip width at 1/2 the size available to the location bar. | |
584 site_chip_width = std::min(site_chip_width, available_width / 2); | |
585 available_width -= site_chip_width; | |
586 | |
587 int location_height = location_bar_->GetPreferredSize().height(); | 564 int location_height = location_bar_->GetPreferredSize().height(); |
588 int location_y = (height() - location_height + 1) / 2; | 565 int location_y = (height() - location_height + 1) / 2; |
589 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 566 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
590 location_height); | 567 location_height); |
591 | 568 |
592 int browser_actions_x = location_bar_->x() + location_bar_->width(); | 569 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, |
593 | |
594 if (site_chip_view_->ShouldShow()) { | |
595 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, | |
596 child_y, | |
597 site_chip_view_->GetPreferredSize().width(), | |
598 child_height); | |
599 browser_actions_x += | |
600 site_chip_view_->GetPreferredSize().width() + kStandardSpacing; | |
601 } | |
602 | |
603 browser_actions_->SetBounds(browser_actions_x, 0, | |
604 browser_actions_width, height()); | 570 browser_actions_width, height()); |
605 | |
606 // The browser actions need to do a layout explicitly, because when an | 571 // The browser actions need to do a layout explicitly, because when an |
607 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 572 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
608 // re-adds everything, regardless of whether it has a page action. For a | 573 // 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 | 574 // page action, browser action bounds do not change, as a result of which |
610 // SetBounds does not do a layout at all. | 575 // SetBounds does not do a layout at all. |
611 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 576 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
612 // required. | 577 // required. |
613 browser_actions_->Layout(); | 578 browser_actions_->Layout(); |
614 | 579 |
615 // Extend the app menu to the screen's right edge in maximized mode just like | 580 // Extend the app menu to the screen's right edge in maximized mode just like |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 | 803 |
839 void ToolbarView::OnShowHomeButtonChanged() { | 804 void ToolbarView::OnShowHomeButtonChanged() { |
840 Layout(); | 805 Layout(); |
841 SchedulePaint(); | 806 SchedulePaint(); |
842 } | 807 } |
843 | 808 |
844 int ToolbarView::content_shadow_height() const { | 809 int ToolbarView::content_shadow_height() const { |
845 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 810 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
846 kContentShadowHeightAsh : kContentShadowHeight; | 811 kContentShadowHeightAsh : kContentShadowHeight; |
847 } | 812 } |
OLD | NEW |