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