OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_view.h" | 5 #include "chrome/browser/ui/views/toolbar_view.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/event_disposition.h" | 10 #include "chrome/browser/event_disposition.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_command_controller.h" |
15 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
16 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 17 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/global_error_service.h" | 19 #include "chrome/browser/ui/global_error_service.h" |
19 #include "chrome/browser/ui/global_error_service_factory.h" | 20 #include "chrome/browser/ui/global_error_service_factory.h" |
20 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 21 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
21 #include "chrome/browser/ui/search/search.h" | 22 #include "chrome/browser/ui/search/search.h" |
22 #include "chrome/browser/ui/search/search_model.h" | 23 #include "chrome/browser/ui/search/search_model.h" |
23 #include "chrome/browser/ui/search/search_tab_helper.h" | 24 #include "chrome/browser/ui/search/search_tab_helper.h" |
24 #include "chrome/browser/ui/search/search_types.h" | 25 #include "chrome/browser/ui/search/search_types.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 reload_(NULL), | 146 reload_(NULL), |
146 home_(NULL), | 147 home_(NULL), |
147 location_bar_(NULL), | 148 location_bar_(NULL), |
148 location_bar_container_(NULL), | 149 location_bar_container_(NULL), |
149 browser_actions_(NULL), | 150 browser_actions_(NULL), |
150 app_menu_(NULL), | 151 app_menu_(NULL), |
151 browser_(browser), | 152 browser_(browser), |
152 profiles_menu_contents_(NULL) { | 153 profiles_menu_contents_(NULL) { |
153 set_id(VIEW_ID_TOOLBAR); | 154 set_id(VIEW_ID_TOOLBAR); |
154 | 155 |
155 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 156 chrome::AddCommandObserver(browser_, IDC_BACK, this); |
156 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 157 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); |
157 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); | 158 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); |
158 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 159 chrome::AddCommandObserver(browser_, IDC_HOME, this); |
159 browser_->command_updater()->AddCommandObserver(IDC_LOAD_NEW_TAB_PAGE, this); | 160 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); |
160 | 161 |
161 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? | 162 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? |
162 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; | 163 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; |
163 | 164 |
164 if (!kPopupBackgroundEdge) { | 165 if (!kPopupBackgroundEdge) { |
165 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 166 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
166 kPopupBackgroundEdge = rb.GetImageSkiaNamed(IDR_LOCATIONBG_POPUPMODE_EDGE); | 167 kPopupBackgroundEdge = rb.GetImageSkiaNamed(IDR_LOCATIONBG_POPUPMODE_EDGE); |
167 } | 168 } |
168 | 169 |
169 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 170 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); | 214 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); |
214 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); | 215 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); |
215 forward_->set_id(VIEW_ID_FORWARD_BUTTON); | 216 forward_->set_id(VIEW_ID_FORWARD_BUTTON); |
216 | 217 |
217 // Have to create this before |reload_| as |reload_|'s constructor needs it. | 218 // Have to create this before |reload_| as |reload_|'s constructor needs it. |
218 location_bar_container_ = new LocationBarContainer( | 219 location_bar_container_ = new LocationBarContainer( |
219 location_bar_parent, | 220 location_bar_parent, |
220 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())); | 221 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())); |
221 location_bar_ = new LocationBarView( | 222 location_bar_ = new LocationBarView( |
222 browser_->profile(), | 223 browser_->profile(), |
223 browser_->command_updater(), | 224 browser_->command_controller()->command_updater(), |
224 model_, | 225 model_, |
225 this, | 226 this, |
226 (display_mode_ == DISPLAYMODE_LOCATION) ? | 227 (display_mode_ == DISPLAYMODE_LOCATION) ? |
227 LocationBarView::POPUP : LocationBarView::NORMAL); | 228 LocationBarView::POPUP : LocationBarView::NORMAL); |
228 // TODO(sky): if we want this to work on windows we need to make sure the | 229 // TODO(sky): if we want this to work on windows we need to make sure the |
229 // LocationBarContainer gets focus. This will involve tweaking view_ids. | 230 // LocationBarContainer gets focus. This will involve tweaking view_ids. |
230 // location_bar_->set_view_to_focus(location_bar_container_); | 231 // location_bar_->set_view_to_focus(location_bar_container_); |
231 location_bar_container_->SetLocationBarView(location_bar_); | 232 location_bar_container_->SetLocationBarView(location_bar_); |
232 | 233 |
233 reload_ = new ReloadButton(location_bar_, browser_->command_updater()); | 234 reload_ = new ReloadButton(location_bar_, |
| 235 browser_->command_controller()->command_updater()); |
234 reload_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 236 reload_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
235 ui::EF_MIDDLE_MOUSE_BUTTON); | 237 ui::EF_MIDDLE_MOUSE_BUTTON); |
236 reload_->set_tag(IDC_RELOAD); | 238 reload_->set_tag(IDC_RELOAD); |
237 reload_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD)); | 239 reload_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD)); |
238 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); | 240 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); |
239 reload_->set_id(VIEW_ID_RELOAD_BUTTON); | 241 reload_->set_id(VIEW_ID_RELOAD_BUTTON); |
240 | 242 |
241 home_ = new views::ImageButton(this); | 243 home_ = new views::ImageButton(this); |
242 home_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 244 home_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
243 ui::EF_MIDDLE_MOUSE_BUTTON); | 245 ui::EF_MIDDLE_MOUSE_BUTTON); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // view based on toolbar mode change. | 468 // view based on toolbar mode change. |
467 if (mode.is_ntp()) | 469 if (mode.is_ntp()) |
468 location_bar_->Layout(); | 470 location_bar_->Layout(); |
469 | 471 |
470 Layout(); | 472 Layout(); |
471 LayoutForSearch(); | 473 LayoutForSearch(); |
472 SchedulePaint(); | 474 SchedulePaint(); |
473 } | 475 } |
474 | 476 |
475 //////////////////////////////////////////////////////////////////////////////// | 477 //////////////////////////////////////////////////////////////////////////////// |
476 // ToolbarView, CommandUpdater::CommandObserver implementation: | 478 // ToolbarView, CommandObserver implementation: |
477 | 479 |
478 void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { | 480 void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { |
479 // Special case the reload button at the NTP for extended instant. | 481 // Special case the reload button at the NTP for extended instant. |
480 if (id == IDC_RELOAD && | 482 if (id == IDC_RELOAD && |
481 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) && | 483 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) && |
482 browser_->search_model()->mode().is_ntp()) { | 484 browser_->search_model()->mode().is_ntp()) { |
483 reload_->SetEnabled(false); | 485 reload_->SetEnabled(false); |
484 return; | 486 return; |
485 } | 487 } |
486 | 488 |
(...skipping 21 matching lines...) Expand all Loading... |
508 int command = sender->tag(); | 510 int command = sender->tag(); |
509 WindowOpenDisposition disposition = | 511 WindowOpenDisposition disposition = |
510 browser::DispositionFromEventFlags(sender->mouse_event_flags()); | 512 browser::DispositionFromEventFlags(sender->mouse_event_flags()); |
511 if ((disposition == CURRENT_TAB) && | 513 if ((disposition == CURRENT_TAB) && |
512 ((command == IDC_BACK) || (command == IDC_FORWARD))) { | 514 ((command == IDC_BACK) || (command == IDC_FORWARD))) { |
513 // Forcibly reset the location bar, since otherwise it won't discard any | 515 // Forcibly reset the location bar, since otherwise it won't discard any |
514 // ongoing user edits, since it doesn't realize this is a user-initiated | 516 // ongoing user edits, since it doesn't realize this is a user-initiated |
515 // action. | 517 // action. |
516 location_bar_->Revert(); | 518 location_bar_->Revert(); |
517 } | 519 } |
518 browser_->ExecuteCommandWithDisposition(command, disposition); | 520 chrome::ExecuteCommandWithDisposition(browser_, command, disposition); |
519 } | 521 } |
520 | 522 |
521 //////////////////////////////////////////////////////////////////////////////// | 523 //////////////////////////////////////////////////////////////////////////////// |
522 // ToolbarView, content::NotificationObserver implementation: | 524 // ToolbarView, content::NotificationObserver implementation: |
523 | 525 |
524 void ToolbarView::Observe(int type, | 526 void ToolbarView::Observe(int type, |
525 const content::NotificationSource& source, | 527 const content::NotificationSource& source, |
526 const content::NotificationDetails& details) { | 528 const content::NotificationDetails& details) { |
527 switch (type) { | 529 switch (type) { |
528 case chrome::NOTIFICATION_PREF_CHANGED: { | 530 case chrome::NOTIFICATION_PREF_CHANGED: { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 available_width, available_height); | 694 available_width, available_height); |
693 | 695 |
694 // In NTP mode, the location bar needs content area's bounds to layout within | 696 // In NTP mode, the location bar needs content area's bounds to layout within |
695 // it, so we skip doing that here. When the browser view finished setting the | 697 // it, so we skip doing that here. When the browser view finished setting the |
696 // tab content bounds, we then layout the NTP location bar over it. | 698 // tab content bounds, we then layout the NTP location bar over it. |
697 const chrome::search::Mode& si_mode(browser_->search_model()->mode()); | 699 const chrome::search::Mode& si_mode(browser_->search_model()->mode()); |
698 if (si_mode.is_ntp()) { | 700 if (si_mode.is_ntp()) { |
699 // Force the reload button to go into disabled mode to display the grey | 701 // Force the reload button to go into disabled mode to display the grey |
700 // circle and not the grey cross. The disabled reload state only exists for | 702 // circle and not the grey cross. The disabled reload state only exists for |
701 // ntp pages. | 703 // ntp pages. |
702 browser_->command_updater()->UpdateCommandEnabled(IDC_RELOAD, false); | 704 chrome::UpdateCommandEnabled(browser_, IDC_RELOAD, false); |
703 } else { | 705 } else { |
704 // Start the location bar animation. | 706 // Start the location bar animation. |
705 if (si_mode.animate && si_mode.is_search() && | 707 if (si_mode.animate && si_mode.is_search() && |
706 !location_bar_container_->IsAnimating()) { | 708 !location_bar_container_->IsAnimating()) { |
707 gfx::Point location_bar_origin(location_bar_bounds.origin()); | 709 gfx::Point location_bar_origin(location_bar_bounds.origin()); |
708 views::View::ConvertPointToView(this, location_bar_container_->parent(), | 710 views::View::ConvertPointToView(this, location_bar_container_->parent(), |
709 &location_bar_origin); | 711 &location_bar_origin); |
710 location_bar_container_->AnimateTo( | 712 location_bar_container_->AnimateTo( |
711 gfx::Rect(location_bar_origin, location_bar_bounds.size())); | 713 gfx::Rect(location_bar_origin, location_bar_bounds.size())); |
712 } else { | 714 } else { |
713 SetLocationBarContainerBounds(location_bar_bounds); | 715 SetLocationBarContainerBounds(location_bar_bounds); |
714 } | 716 } |
715 browser_->command_updater()->UpdateCommandEnabled(IDC_RELOAD, true); | 717 chrome::UpdateCommandEnabled(browser_, IDC_RELOAD, true); |
716 } | 718 } |
717 | 719 |
718 browser_actions_->SetBounds(location_bar_bounds.right(), 0, | 720 browser_actions_->SetBounds(location_bar_bounds.right(), 0, |
719 browser_actions_width, height()); | 721 browser_actions_width, height()); |
720 // The browser actions need to do a layout explicitly, because when an | 722 // The browser actions need to do a layout explicitly, because when an |
721 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 723 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
722 // re-adds everything, regardless of whether it has a page action. For a | 724 // re-adds everything, regardless of whether it has a page action. For a |
723 // page action, browser action bounds do not change, as a result of which | 725 // page action, browser action bounds do not change, as a result of which |
724 // SetBounds does not do a layout at all. | 726 // SetBounds does not do a layout at all. |
725 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 727 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 // LocationBarContainer is not a child of the ToolbarView. | 996 // LocationBarContainer is not a child of the ToolbarView. |
995 gfx::Point origin(bounds.origin()); | 997 gfx::Point origin(bounds.origin()); |
996 views::View::ConvertPointToView(this, location_bar_container_->parent(), | 998 views::View::ConvertPointToView(this, location_bar_container_->parent(), |
997 &origin); | 999 &origin); |
998 gfx::Rect target_bounds(origin, bounds.size()); | 1000 gfx::Rect target_bounds(origin, bounds.size()); |
999 if (location_bar_container_->GetTargetBounds() != target_bounds) { | 1001 if (location_bar_container_->GetTargetBounds() != target_bounds) { |
1000 location_bar_container_->SetInToolbar(true); | 1002 location_bar_container_->SetInToolbar(true); |
1001 location_bar_container_->SetBoundsRect(target_bounds); | 1003 location_bar_container_->SetBoundsRect(target_bounds); |
1002 } | 1004 } |
1003 } | 1005 } |
OLD | NEW |