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