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); | |
James Cook
2013/12/04 20:43:52
drive by from sheriff: I think this might leak if
Peter Kasting
2013/12/04 21:23:51
Yes, it will.
| |
233 if (site_chip_view_->ShouldShow()) | |
234 AddChildView(site_chip_view_); | |
230 AddChildView(browser_actions_); | 235 AddChildView(browser_actions_); |
231 AddChildView(app_menu_); | 236 AddChildView(app_menu_); |
232 | 237 |
233 LoadImages(); | 238 LoadImages(); |
234 | 239 |
235 // Add any necessary badges to the menu item based on the system state. | 240 // 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 | 241 // 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()). | 242 // needs the widget (widget found by way of app_menu_->GetWidget()). |
238 UpdateAppMenuState(); | 243 UpdateAppMenuState(); |
239 | 244 |
240 location_bar_->Init(); | 245 location_bar_->Init(); |
246 site_chip_view_->Init(); | |
241 show_home_button_.Init(prefs::kShowHomeButton, | 247 show_home_button_.Init(prefs::kShowHomeButton, |
242 browser_->profile()->GetPrefs(), | 248 browser_->profile()->GetPrefs(), |
243 base::Bind(&ToolbarView::OnShowHomeButtonChanged, | 249 base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
244 base::Unretained(this))); | 250 base::Unretained(this))); |
245 | 251 |
246 browser_actions_->Init(); | 252 browser_actions_->Init(); |
247 | 253 |
248 // Accessibility specific tooltip text. | 254 // Accessibility specific tooltip text. |
249 if (content::BrowserAccessibilityState::GetInstance()-> | 255 if (content::BrowserAccessibilityState::GetInstance()-> |
250 IsAccessibleBrowser()) { | 256 IsAccessibleBrowser()) { |
251 back_->SetTooltipText( | 257 back_->SetTooltipText( |
252 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 258 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
253 forward_->SetTooltipText( | 259 forward_->SetTooltipText( |
254 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); | 260 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); |
255 } | 261 } |
256 } | 262 } |
257 | 263 |
258 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, | 264 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, |
259 bool visible) { | 265 bool visible) { |
260 if (visible) { | 266 if (visible) { |
261 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); | 267 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); |
262 GetWidget()->RemoveObserver(this); | 268 GetWidget()->RemoveObserver(this); |
263 } | 269 } |
264 } | 270 } |
265 | 271 |
266 void ToolbarView::Update(WebContents* tab) { | 272 void ToolbarView::Update(WebContents* tab) { |
267 if (location_bar_) | 273 if (location_bar_) |
268 location_bar_->Update(tab); | 274 location_bar_->Update(tab); |
275 if (site_chip_view_->ShouldShow()) | |
276 site_chip_view_->Update(tab); | |
269 | 277 |
270 if (browser_actions_) | 278 if (browser_actions_) |
271 browser_actions_->RefreshBrowserActionViews(); | 279 browser_actions_->RefreshBrowserActionViews(); |
272 | 280 |
273 if (reload_) | 281 if (reload_) |
274 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); | 282 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); |
275 } | 283 } |
276 | 284 |
277 void ToolbarView::SetPaneFocusAndFocusAppMenu() { | 285 void ToolbarView::SetPaneFocusAndFocusAppMenu() { |
278 SetPaneFocus(app_menu_); | 286 SetPaneFocus(app_menu_); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 gfx::Size ToolbarView::GetPreferredSize() { | 488 gfx::Size ToolbarView::GetPreferredSize() { |
481 if (is_display_mode_normal()) { | 489 if (is_display_mode_normal()) { |
482 int button_spacing = GetButtonSpacing(); | 490 int button_spacing = GetButtonSpacing(); |
483 int min_width = kLeftEdgeSpacing + | 491 int min_width = kLeftEdgeSpacing + |
484 back_->GetPreferredSize().width() + button_spacing + | 492 back_->GetPreferredSize().width() + button_spacing + |
485 forward_->GetPreferredSize().width() + button_spacing + | 493 forward_->GetPreferredSize().width() + button_spacing + |
486 reload_->GetPreferredSize().width() + kStandardSpacing + | 494 reload_->GetPreferredSize().width() + kStandardSpacing + |
487 (show_home_button_.GetValue() ? | 495 (show_home_button_.GetValue() ? |
488 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 496 (home_->GetPreferredSize().width() + button_spacing) : 0) + |
489 location_bar_->GetPreferredSize().width() + | 497 location_bar_->GetPreferredSize().width() + |
498 (site_chip_view_->ShouldShow() ? | |
499 (site_chip_view_->GetPreferredSize().width() + | |
500 2 * kStandardSpacing + 2 * button_spacing) : | |
501 0) + | |
490 browser_actions_->GetPreferredSize().width() + | 502 browser_actions_->GetPreferredSize().width() + |
491 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 503 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
492 gfx::ImageSkia* normal_background = | 504 gfx::ImageSkia* normal_background = |
493 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 505 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
494 return gfx::Size(min_width, | 506 return gfx::Size(min_width, |
495 normal_background->height() - content_shadow_height()); | 507 normal_background->height() - content_shadow_height()); |
496 } | 508 } |
497 | 509 |
498 const int kPopupBottomSpacingGlass = 1; | 510 const int kPopupBottomSpacingGlass = 1; |
499 const int kPopupBottomSpacingNonGlass = 2; | 511 const int kPopupBottomSpacingNonGlass = 2; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 if (show_home_button_.GetValue()) { | 561 if (show_home_button_.GetValue()) { |
550 home_->SetVisible(true); | 562 home_->SetVisible(true); |
551 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 563 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, |
552 child_y, home_->GetPreferredSize().width(), child_height); | 564 child_y, home_->GetPreferredSize().width(), child_height); |
553 } else { | 565 } else { |
554 home_->SetVisible(false); | 566 home_->SetVisible(false); |
555 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 567 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
556 } | 568 } |
557 | 569 |
558 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 570 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); | |
559 int app_menu_width = app_menu_->GetPreferredSize().width(); | 578 int app_menu_width = app_menu_->GetPreferredSize().width(); |
560 int location_x = home_->x() + home_->width() + kStandardSpacing; | 579 int location_x = home_->x() + home_->width() + kStandardSpacing; |
561 int available_width = std::max(0, width() - kRightEdgeSpacing - | 580 int available_width = std::max(0, width() - kRightEdgeSpacing - |
562 app_menu_width - browser_actions_width - location_x); | 581 app_menu_width - browser_actions_width - location_x); |
563 | 582 |
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 | |
564 int location_height = location_bar_->GetPreferredSize().height(); | 587 int location_height = location_bar_->GetPreferredSize().height(); |
565 int location_y = (height() - location_height + 1) / 2; | 588 int location_y = (height() - location_height + 1) / 2; |
566 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 589 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
567 location_height); | 590 location_height); |
568 | 591 |
569 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, | 592 int browser_actions_x = location_bar_->x() + location_bar_->width(); |
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, | |
570 browser_actions_width, height()); | 604 browser_actions_width, height()); |
605 | |
571 // The browser actions need to do a layout explicitly, because when an | 606 // The browser actions need to do a layout explicitly, because when an |
572 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 607 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
573 // re-adds everything, regardless of whether it has a page action. For a | 608 // 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 | 609 // page action, browser action bounds do not change, as a result of which |
575 // SetBounds does not do a layout at all. | 610 // SetBounds does not do a layout at all. |
576 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 611 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
577 // required. | 612 // required. |
578 browser_actions_->Layout(); | 613 browser_actions_->Layout(); |
579 | 614 |
580 // Extend the app menu to the screen's right edge in maximized mode just like | 615 // 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 | 838 |
804 void ToolbarView::OnShowHomeButtonChanged() { | 839 void ToolbarView::OnShowHomeButtonChanged() { |
805 Layout(); | 840 Layout(); |
806 SchedulePaint(); | 841 SchedulePaint(); |
807 } | 842 } |
808 | 843 |
809 int ToolbarView::content_shadow_height() const { | 844 int ToolbarView::content_shadow_height() const { |
810 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 845 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
811 kContentShadowHeightAsh : kContentShadowHeight; | 846 kContentShadowHeightAsh : kContentShadowHeight; |
812 } | 847 } |
OLD | NEW |