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 | |
246 site_chip_view_->Init(); | |
247 site_chip_view_->SetEnabled(site_chip_view_->ShouldShow()); | |
Peter Kasting
2013/12/05 00:03:48
Is this call necessary? It seems like the site ch
Greg Billock
2013/12/05 00:34:00
Done.
| |
248 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); | |
Peter Kasting
2013/12/05 00:03:48
Do this in Layout() in the same place where we set
Greg Billock
2013/12/05 00:34:00
Done.
| |
249 | |
241 show_home_button_.Init(prefs::kShowHomeButton, | 250 show_home_button_.Init(prefs::kShowHomeButton, |
242 browser_->profile()->GetPrefs(), | 251 browser_->profile()->GetPrefs(), |
243 base::Bind(&ToolbarView::OnShowHomeButtonChanged, | 252 base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
244 base::Unretained(this))); | 253 base::Unretained(this))); |
245 | 254 |
246 browser_actions_->Init(); | 255 browser_actions_->Init(); |
247 | 256 |
248 // Accessibility specific tooltip text. | 257 // Accessibility specific tooltip text. |
249 if (content::BrowserAccessibilityState::GetInstance()-> | 258 if (content::BrowserAccessibilityState::GetInstance()-> |
250 IsAccessibleBrowser()) { | 259 IsAccessibleBrowser()) { |
251 back_->SetTooltipText( | 260 back_->SetTooltipText( |
252 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 261 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
253 forward_->SetTooltipText( | 262 forward_->SetTooltipText( |
254 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); | 263 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); |
255 } | 264 } |
256 } | 265 } |
257 | 266 |
258 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, | 267 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, |
259 bool visible) { | 268 bool visible) { |
260 if (visible) { | 269 if (visible) { |
261 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); | 270 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); |
262 GetWidget()->RemoveObserver(this); | 271 GetWidget()->RemoveObserver(this); |
263 } | 272 } |
264 } | 273 } |
265 | 274 |
266 void ToolbarView::Update(WebContents* tab) { | 275 void ToolbarView::Update(WebContents* tab) { |
267 if (location_bar_) | 276 if (location_bar_) |
268 location_bar_->Update(tab); | 277 location_bar_->Update(tab); |
278 if (site_chip_view_->ShouldShow()) | |
279 site_chip_view_->Update(tab); | |
269 | 280 |
270 if (browser_actions_) | 281 if (browser_actions_) |
271 browser_actions_->RefreshBrowserActionViews(); | 282 browser_actions_->RefreshBrowserActionViews(); |
272 | 283 |
273 if (reload_) | 284 if (reload_) |
274 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); | 285 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); |
275 } | 286 } |
276 | 287 |
277 void ToolbarView::SetPaneFocusAndFocusAppMenu() { | 288 void ToolbarView::SetPaneFocusAndFocusAppMenu() { |
278 SetPaneFocus(app_menu_); | 289 SetPaneFocus(app_menu_); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 gfx::Size ToolbarView::GetPreferredSize() { | 491 gfx::Size ToolbarView::GetPreferredSize() { |
481 if (is_display_mode_normal()) { | 492 if (is_display_mode_normal()) { |
482 int button_spacing = GetButtonSpacing(); | 493 int button_spacing = GetButtonSpacing(); |
483 int min_width = kLeftEdgeSpacing + | 494 int min_width = kLeftEdgeSpacing + |
484 back_->GetPreferredSize().width() + button_spacing + | 495 back_->GetPreferredSize().width() + button_spacing + |
485 forward_->GetPreferredSize().width() + button_spacing + | 496 forward_->GetPreferredSize().width() + button_spacing + |
486 reload_->GetPreferredSize().width() + kStandardSpacing + | 497 reload_->GetPreferredSize().width() + kStandardSpacing + |
487 (show_home_button_.GetValue() ? | 498 (show_home_button_.GetValue() ? |
488 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 499 (home_->GetPreferredSize().width() + button_spacing) : 0) + |
489 location_bar_->GetPreferredSize().width() + | 500 location_bar_->GetPreferredSize().width() + |
501 (site_chip_view_->ShouldShow() ? | |
502 (site_chip_view_->GetPreferredSize().width() + | |
503 2 * kStandardSpacing + 2 * button_spacing) : | |
504 0) + | |
490 browser_actions_->GetPreferredSize().width() + | 505 browser_actions_->GetPreferredSize().width() + |
491 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 506 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
492 gfx::ImageSkia* normal_background = | 507 gfx::ImageSkia* normal_background = |
493 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 508 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
494 return gfx::Size(min_width, | 509 return gfx::Size(min_width, |
495 normal_background->height() - content_shadow_height()); | 510 normal_background->height() - content_shadow_height()); |
496 } | 511 } |
497 | 512 |
498 const int kPopupBottomSpacingGlass = 1; | 513 const int kPopupBottomSpacingGlass = 1; |
499 const int kPopupBottomSpacingNonGlass = 2; | 514 const int kPopupBottomSpacingNonGlass = 2; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 if (show_home_button_.GetValue()) { | 564 if (show_home_button_.GetValue()) { |
550 home_->SetVisible(true); | 565 home_->SetVisible(true); |
551 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 566 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, |
552 child_y, home_->GetPreferredSize().width(), child_height); | 567 child_y, home_->GetPreferredSize().width(), child_height); |
553 } else { | 568 } else { |
554 home_->SetVisible(false); | 569 home_->SetVisible(false); |
555 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 570 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
556 } | 571 } |
557 | 572 |
558 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 573 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
574 | |
575 // Note: spacing from location bar to site chip is 1 pixel less than | |
576 // kStandardSpacing given the edge thickness of the chip. | |
577 int site_chip_width = | |
578 (site_chip_view_->ShouldShow() ? | |
579 site_chip_view_->GetPreferredSize().width() + | |
580 kStandardSpacing : 0); | |
559 int app_menu_width = app_menu_->GetPreferredSize().width(); | 581 int app_menu_width = app_menu_->GetPreferredSize().width(); |
560 int location_x = home_->x() + home_->width() + kStandardSpacing; | 582 int location_x = home_->x() + home_->width() + kStandardSpacing; |
561 int available_width = std::max(0, width() - kRightEdgeSpacing - | 583 int available_width = std::max(0, width() - kRightEdgeSpacing - |
562 app_menu_width - browser_actions_width - location_x); | 584 app_menu_width - browser_actions_width - location_x); |
563 | 585 |
586 // Cap site chip width at 1/2 the size available to the location bar. | |
587 site_chip_width = std::min(site_chip_width, available_width / 2); | |
588 available_width -= site_chip_width; | |
589 | |
564 int location_height = location_bar_->GetPreferredSize().height(); | 590 int location_height = location_bar_->GetPreferredSize().height(); |
565 int location_y = (height() - location_height + 1) / 2; | 591 int location_y = (height() - location_height + 1) / 2; |
566 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 592 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
567 location_height); | 593 location_height); |
568 | 594 |
569 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, | 595 int browser_actions_x = location_bar_->x() + location_bar_->width(); |
596 | |
597 if (site_chip_view_->ShouldShow()) { | |
598 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, | |
599 child_y, | |
600 site_chip_view_->GetPreferredSize().width(), | |
601 child_height); | |
602 browser_actions_x += | |
603 site_chip_view_->GetPreferredSize().width() + kStandardSpacing; | |
604 } | |
605 | |
606 browser_actions_->SetBounds(browser_actions_x, 0, | |
570 browser_actions_width, height()); | 607 browser_actions_width, height()); |
608 | |
571 // The browser actions need to do a layout explicitly, because when an | 609 // The browser actions need to do a layout explicitly, because when an |
572 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 610 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
573 // re-adds everything, regardless of whether it has a page action. For a | 611 // 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 | 612 // page action, browser action bounds do not change, as a result of which |
575 // SetBounds does not do a layout at all. | 613 // SetBounds does not do a layout at all. |
576 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 614 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
577 // required. | 615 // required. |
578 browser_actions_->Layout(); | 616 browser_actions_->Layout(); |
579 | 617 |
580 // Extend the app menu to the screen's right edge in maximized mode just like | 618 // 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 | 841 |
804 void ToolbarView::OnShowHomeButtonChanged() { | 842 void ToolbarView::OnShowHomeButtonChanged() { |
805 Layout(); | 843 Layout(); |
806 SchedulePaint(); | 844 SchedulePaint(); |
807 } | 845 } |
808 | 846 |
809 int ToolbarView::content_shadow_height() const { | 847 int ToolbarView::content_shadow_height() const { |
810 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 848 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
811 kContentShadowHeightAsh : kContentShadowHeight; | 849 kContentShadowHeightAsh : kContentShadowHeight; |
812 } | 850 } |
OLD | NEW |