Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 // static | 118 // static |
| 119 const char ToolbarView::kViewClassName[] = "ToolbarView"; | 119 const char ToolbarView::kViewClassName[] = "ToolbarView"; |
| 120 | 120 |
| 121 //////////////////////////////////////////////////////////////////////////////// | 121 //////////////////////////////////////////////////////////////////////////////// |
| 122 // ToolbarView, public: | 122 // ToolbarView, public: |
| 123 | 123 |
| 124 ToolbarView::ToolbarView(Browser* browser) | 124 ToolbarView::ToolbarView(Browser* browser) |
| 125 : back_(NULL), | 125 : back_(nullptr), |
| 126 forward_(NULL), | 126 forward_(nullptr), |
| 127 reload_(NULL), | 127 reload_(nullptr), |
| 128 home_(NULL), | 128 home_(nullptr), |
| 129 location_bar_(NULL), | 129 location_bar_(nullptr), |
| 130 browser_actions_(NULL), | 130 browser_actions_(nullptr), |
| 131 app_menu_button_(NULL), | 131 app_menu_button_(nullptr), |
| 132 browser_(browser), | 132 browser_(browser), |
| 133 badge_controller_(browser->profile(), this) { | 133 badge_controller_(browser->profile(), this), |
| 134 display_mode_(browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) | |
| 135 ? DISPLAYMODE_NORMAL | |
| 136 : DISPLAYMODE_LOCATION) { | |
| 134 set_id(VIEW_ID_TOOLBAR); | 137 set_id(VIEW_ID_TOOLBAR); |
| 135 | 138 |
| 136 SetEventTargeter( | 139 SetEventTargeter( |
| 137 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 140 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 138 | 141 |
| 139 chrome::AddCommandObserver(browser_, IDC_BACK, this); | 142 chrome::AddCommandObserver(browser_, IDC_BACK, this); |
| 140 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); | 143 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); |
| 141 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); | 144 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); |
| 142 chrome::AddCommandObserver(browser_, IDC_HOME, this); | 145 chrome::AddCommandObserver(browser_, IDC_HOME, this); |
| 143 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); | 146 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); |
| 144 | 147 |
| 145 display_mode_ = DISPLAYMODE_LOCATION; | |
| 146 if (browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)) | |
| 147 display_mode_ = DISPLAYMODE_NORMAL; | |
| 148 | |
| 149 if (OutdatedUpgradeBubbleView::IsAvailable()) { | 148 if (OutdatedUpgradeBubbleView::IsAvailable()) { |
| 150 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL, | 149 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL, |
| 151 content::NotificationService::AllSources()); | 150 content::NotificationService::AllSources()); |
| 152 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU, | 151 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU, |
| 153 content::NotificationService::AllSources()); | 152 content::NotificationService::AllSources()); |
| 154 } | 153 } |
| 155 #if defined(OS_WIN) | 154 #if defined(OS_WIN) |
| 156 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED, | 155 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED, |
| 157 content::NotificationService::AllSources()); | 156 content::NotificationService::AllSources()); |
| 158 #endif | 157 #endif |
| 159 } | 158 } |
| 160 | 159 |
| 161 ToolbarView::~ToolbarView() { | 160 ToolbarView::~ToolbarView() { |
| 162 // NOTE: Don't remove the command observers here. This object gets destroyed | 161 // NOTE: Don't remove the command observers here. This object gets destroyed |
| 163 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is | 162 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is |
| 164 // already gone. | 163 // already gone. |
| 165 } | 164 } |
| 166 | 165 |
| 167 void ToolbarView::Init() { | 166 void ToolbarView::Init() { |
| 167 location_bar_ = new LocationBarView( | |
| 168 browser_, browser_->profile(), | |
| 169 browser_->command_controller()->command_updater(), this, | |
| 170 !is_display_mode_normal()); | |
| 171 | |
| 172 if (!is_display_mode_normal()) { | |
| 173 AddChildView(location_bar_); | |
| 174 location_bar_->Init(); | |
| 175 return; | |
| 176 } | |
| 177 | |
| 168 GetWidget()->AddObserver(this); | 178 GetWidget()->AddObserver(this); |
|
Peter Kasting
2016/02/03 00:02:08
Don't we still need to do this? It seems like wit
Evan Stade
2016/02/03 00:04:36
+Devlin to answer that
I kind of assumed that if
Devlin
2016/02/03 01:02:41
Yes, it works, and ideally, yes, it should be pres
Evan Stade
2016/02/03 01:21:44
do you have an example of an extension that uses t
Devlin
2016/02/03 02:50:43
Any extension can have a keybinding associated wit
| |
| 169 | 179 |
| 170 back_ = new BackButton( | 180 back_ = new BackButton( |
| 171 browser_->profile(), this, | 181 browser_->profile(), this, |
| 172 new BackForwardMenuModel(browser_, BackForwardMenuModel::BACKWARD_MENU)); | 182 new BackForwardMenuModel(browser_, BackForwardMenuModel::BACKWARD_MENU)); |
| 173 back_->set_triggerable_event_flags( | 183 back_->set_triggerable_event_flags( |
| 174 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); | 184 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); |
| 175 back_->set_tag(IDC_BACK); | 185 back_->set_tag(IDC_BACK); |
| 176 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); | 186 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); |
| 177 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); | 187 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); |
| 178 back_->set_id(VIEW_ID_BACK_BUTTON); | 188 back_->set_id(VIEW_ID_BACK_BUTTON); |
| 179 back_->Init(); | 189 back_->Init(); |
| 180 | 190 |
| 181 forward_ = new ToolbarButton( | 191 forward_ = new ToolbarButton( |
| 182 browser_->profile(), this, | 192 browser_->profile(), this, |
| 183 new BackForwardMenuModel(browser_, BackForwardMenuModel::FORWARD_MENU)); | 193 new BackForwardMenuModel(browser_, BackForwardMenuModel::FORWARD_MENU)); |
| 184 forward_->set_triggerable_event_flags( | 194 forward_->set_triggerable_event_flags( |
| 185 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); | 195 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); |
| 186 forward_->set_tag(IDC_FORWARD); | 196 forward_->set_tag(IDC_FORWARD); |
| 187 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); | 197 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); |
| 188 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); | 198 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); |
| 189 forward_->set_id(VIEW_ID_FORWARD_BUTTON); | 199 forward_->set_id(VIEW_ID_FORWARD_BUTTON); |
| 190 forward_->Init(); | 200 forward_->Init(); |
| 191 | 201 |
| 192 location_bar_ = new LocationBarView( | |
| 193 browser_, browser_->profile(), | |
| 194 browser_->command_controller()->command_updater(), this, | |
| 195 display_mode_ == DISPLAYMODE_LOCATION); | |
| 196 | |
| 197 reload_ = new ReloadButton(browser_->profile(), | 202 reload_ = new ReloadButton(browser_->profile(), |
| 198 browser_->command_controller()->command_updater()); | 203 browser_->command_controller()->command_updater()); |
| 199 reload_->set_triggerable_event_flags( | 204 reload_->set_triggerable_event_flags( |
| 200 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); | 205 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); |
| 201 reload_->set_tag(IDC_RELOAD); | 206 reload_->set_tag(IDC_RELOAD); |
| 202 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); | 207 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); |
| 203 reload_->set_id(VIEW_ID_RELOAD_BUTTON); | 208 reload_->set_id(VIEW_ID_RELOAD_BUTTON); |
| 204 reload_->Init(); | 209 reload_->Init(); |
| 205 | 210 |
| 206 home_ = new HomeButton(this, browser_); | 211 home_ = new HomeButton(this, browser_); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 gfx::Size ToolbarView::GetPreferredSize() const { | 487 gfx::Size ToolbarView::GetPreferredSize() const { |
| 483 return GetSizeInternal(&View::GetPreferredSize); | 488 return GetSizeInternal(&View::GetPreferredSize); |
| 484 } | 489 } |
| 485 | 490 |
| 486 gfx::Size ToolbarView::GetMinimumSize() const { | 491 gfx::Size ToolbarView::GetMinimumSize() const { |
| 487 return GetSizeInternal(&View::GetMinimumSize); | 492 return GetSizeInternal(&View::GetMinimumSize); |
| 488 } | 493 } |
| 489 | 494 |
| 490 void ToolbarView::Layout() { | 495 void ToolbarView::Layout() { |
| 491 // If we have not been initialized yet just do nothing. | 496 // If we have not been initialized yet just do nothing. |
| 492 if (back_ == NULL) | 497 if (!location_bar_) |
| 493 return; | 498 return; |
| 494 | 499 |
| 495 if (!is_display_mode_normal()) { | 500 if (!is_display_mode_normal()) { |
| 496 location_bar_->SetBounds(0, PopupTopSpacing(), width(), | 501 location_bar_->SetBounds(0, PopupTopSpacing(), width(), |
| 497 location_bar_->GetPreferredSize().height()); | 502 location_bar_->GetPreferredSize().height()); |
| 498 return; | 503 return; |
| 499 } | 504 } |
| 500 | 505 |
| 501 // We assume all child elements except the location bar are the same height. | 506 // We assume all child elements except the location bar are the same height. |
| 502 // Set child_y such that buttons appear vertically centered. | 507 // Set child_y such that buttons appear vertically centered. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 // Extend the app menu to the screen's right edge in maximized mode just like | 596 // Extend the app menu to the screen's right edge in maximized mode just like |
| 592 // we extend the back button to the left edge. | 597 // we extend the back button to the left edge. |
| 593 if (maximized) | 598 if (maximized) |
| 594 app_menu_width += insets.right(); | 599 app_menu_width += insets.right(); |
| 595 app_menu_button_->SetBounds(next_element_x, child_y, app_menu_width, | 600 app_menu_button_->SetBounds(next_element_x, child_y, app_menu_width, |
| 596 child_height); | 601 child_height); |
| 597 app_menu_button_->SetTrailingMargin(maximized ? insets.right() : 0); | 602 app_menu_button_->SetTrailingMargin(maximized ? insets.right() : 0); |
| 598 } | 603 } |
| 599 | 604 |
| 600 void ToolbarView::OnThemeChanged() { | 605 void ToolbarView::OnThemeChanged() { |
| 601 LoadImages(); | 606 if (is_display_mode_normal()) |
| 607 LoadImages(); | |
| 602 } | 608 } |
| 603 | 609 |
| 604 const char* ToolbarView::GetClassName() const { | 610 const char* ToolbarView::GetClassName() const { |
| 605 return kViewClassName; | 611 return kViewClassName; |
| 606 } | 612 } |
| 607 | 613 |
| 608 bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 614 bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 609 const views::View* focused_view = focus_manager()->GetFocusedView(); | 615 const views::View* focused_view = focus_manager()->GetFocusedView(); |
| 610 if (focused_view && (focused_view->id() == VIEW_ID_OMNIBOX)) | 616 if (focused_view && (focused_view->id() == VIEW_ID_OMNIBOX)) |
| 611 return false; // Let the omnibox handle all accelerator events. | 617 return false; // Let the omnibox handle all accelerator events. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 void ToolbarView::OnShowHomeButtonChanged() { | 817 void ToolbarView::OnShowHomeButtonChanged() { |
| 812 Layout(); | 818 Layout(); |
| 813 SchedulePaint(); | 819 SchedulePaint(); |
| 814 } | 820 } |
| 815 | 821 |
| 816 int ToolbarView::content_shadow_height() const { | 822 int ToolbarView::content_shadow_height() const { |
| 817 return GetLayoutConstant( | 823 return GetLayoutConstant( |
| 818 (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) ? | 824 (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) ? |
| 819 TOOLBAR_CONTENT_SHADOW_HEIGHT_ASH : TOOLBAR_CONTENT_SHADOW_HEIGHT); | 825 TOOLBAR_CONTENT_SHADOW_HEIGHT_ASH : TOOLBAR_CONTENT_SHADOW_HEIGHT); |
| 820 } | 826 } |
| OLD | NEW |