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/command_updater.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 forward_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 238 forward_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
239 ui::EF_MIDDLE_MOUSE_BUTTON); | 239 ui::EF_MIDDLE_MOUSE_BUTTON); |
240 forward_->set_tag(IDC_FORWARD); | 240 forward_->set_tag(IDC_FORWARD); |
241 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); | 241 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); |
242 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); | 242 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); |
243 forward_->set_id(VIEW_ID_FORWARD_BUTTON); | 243 forward_->set_id(VIEW_ID_FORWARD_BUTTON); |
244 | 244 |
245 // Have to create this before |reload_| as |reload_|'s constructor needs it. | 245 // Have to create this before |reload_| as |reload_|'s constructor needs it. |
246 location_bar_container_ = new LocationBarContainer( | 246 location_bar_container_ = new LocationBarContainer( |
247 location_bar_parent, | 247 location_bar_parent, |
| 248 this, |
248 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())); | 249 chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())); |
249 location_bar_ = new LocationBarView( | 250 location_bar_ = new LocationBarView( |
250 browser_, | 251 browser_, |
251 browser_->profile(), | 252 browser_->profile(), |
252 browser_->command_controller()->command_updater(), | 253 browser_->command_controller()->command_updater(), |
253 model_, | 254 model_, |
254 this, | 255 this, |
255 browser_->search_model(), | 256 browser_->search_model(), |
256 (display_mode_ == DISPLAYMODE_LOCATION) ? | 257 (display_mode_ == DISPLAYMODE_LOCATION) ? |
257 LocationBarView::POPUP : LocationBarView::NORMAL); | 258 LocationBarView::POPUP : LocationBarView::NORMAL); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 LoadImages(); | 299 LoadImages(); |
299 | 300 |
300 // Always add children in order from left to right, for accessibility. | 301 // Always add children in order from left to right, for accessibility. |
301 AddChildView(back_); | 302 AddChildView(back_); |
302 AddChildView(forward_); | 303 AddChildView(forward_); |
303 AddChildView(reload_); | 304 AddChildView(reload_); |
304 AddChildView(home_); | 305 AddChildView(home_); |
305 AddChildView(browser_actions_); | 306 AddChildView(browser_actions_); |
306 AddChildView(app_menu_); | 307 AddChildView(app_menu_); |
307 | 308 |
| 309 // Put the location bar container between the home button and browser |
| 310 // actions when doing a focus search. |
| 311 home_->SetNextFocusableView(location_bar_container_); |
| 312 location_bar_container_->SetNextFocusableView(browser_actions_); |
| 313 |
308 location_bar_->Init(popup_parent_view); | 314 location_bar_->Init(popup_parent_view); |
309 show_home_button_.Init(prefs::kShowHomeButton, | 315 show_home_button_.Init(prefs::kShowHomeButton, |
310 browser_->profile()->GetPrefs(), this); | 316 browser_->profile()->GetPrefs(), this); |
311 browser_actions_->Init(); | 317 browser_actions_->Init(); |
312 | 318 |
313 // Accessibility specific tooltip text. | 319 // Accessibility specific tooltip text. |
314 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { | 320 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { |
315 back_->SetTooltipText( | 321 back_->SetTooltipText( |
316 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 322 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
317 forward_->SetTooltipText( | 323 forward_->SetTooltipText( |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 862 |
857 void ToolbarView::OnThemeChanged() { | 863 void ToolbarView::OnThemeChanged() { |
858 LoadImages(); | 864 LoadImages(); |
859 } | 865 } |
860 | 866 |
861 std::string ToolbarView::GetClassName() const { | 867 std::string ToolbarView::GetClassName() const { |
862 return kViewClassName; | 868 return kViewClassName; |
863 } | 869 } |
864 | 870 |
865 bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 871 bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
866 const views::View* focused_view = focus_manager_->GetFocusedView(); | 872 const views::View* focused_view = focus_manager()->GetFocusedView(); |
867 if (focused_view == location_bar_) | 873 if (focused_view == location_bar_) |
868 return false; // Let location bar handle all accelerator events. | 874 return false; // Let location bar handle all accelerator events. |
869 return AccessiblePaneView::AcceleratorPressed(accelerator); | 875 return AccessiblePaneView::AcceleratorPressed(accelerator); |
870 } | 876 } |
871 | 877 |
872 bool ToolbarView::IsWrenchMenuShowing() const { | 878 bool ToolbarView::IsWrenchMenuShowing() const { |
873 return wrench_menu_.get() && wrench_menu_->IsShowing(); | 879 return wrench_menu_.get() && wrench_menu_->IsShowing(); |
874 } | 880 } |
875 | 881 |
876 //////////////////////////////////////////////////////////////////////////////// | 882 //////////////////////////////////////////////////////////////////////////////// |
877 // ToolbarView, protected: | 883 // ToolbarView, protected: |
878 | 884 |
879 // Override this so that when the user presses F6 to rotate toolbar panes, | 885 // Override this so that when the user presses F6 to rotate toolbar panes, |
880 // the location bar gets focus, not the first control in the toolbar - and | 886 // the location bar gets focus, not the first control in the toolbar - and |
881 // also so that it selects all content in the location bar. | 887 // also so that it selects all content in the location bar. |
882 bool ToolbarView::SetPaneFocusAndFocusDefault() { | 888 bool ToolbarView::SetPaneFocusAndFocusDefault() { |
883 if (!location_bar_->HasFocus()) { | 889 if (!location_bar_->HasFocus()) { |
| 890 SetPaneFocus(location_bar_); |
884 location_bar_->FocusLocation(true); | 891 location_bar_->FocusLocation(true); |
885 return true; | 892 return true; |
886 } | 893 } |
887 | 894 |
888 if (!AccessiblePaneView::SetPaneFocusAndFocusDefault()) | 895 if (!AccessiblePaneView::SetPaneFocusAndFocusDefault()) |
889 return false; | 896 return false; |
890 browser_->window()->RotatePaneFocus(true); | 897 browser_->window()->RotatePaneFocus(true); |
891 return true; | 898 return true; |
892 } | 899 } |
893 | 900 |
894 void ToolbarView::RemovePaneFocus() { | 901 void ToolbarView::RemovePaneFocus() { |
895 AccessiblePaneView::RemovePaneFocus(); | 902 AccessiblePaneView::RemovePaneFocus(); |
896 location_bar_->SetShowFocusRect(false); | 903 location_bar_->SetShowFocusRect(false); |
897 } | 904 } |
898 | 905 |
| 906 views::View* ToolbarView::GetParentForFocusSearch(views::View* v) { |
| 907 if (v == location_bar_container_) |
| 908 return this; |
| 909 |
| 910 return AccessiblePaneView::GetParentForFocusSearch(v); |
| 911 } |
| 912 |
| 913 bool ToolbarView::ContainsForFocusSearch(views::View* root, |
| 914 const views::View* v) { |
| 915 if (Contains(root) && location_bar_container_->Contains(v)) |
| 916 return true; |
| 917 |
| 918 return AccessiblePaneView::ContainsForFocusSearch(root, v); |
| 919 } |
| 920 |
899 //////////////////////////////////////////////////////////////////////////////// | 921 //////////////////////////////////////////////////////////////////////////////// |
900 // ToolbarView, private: | 922 // ToolbarView, private: |
901 | 923 |
902 bool ToolbarView::ShouldShowUpgradeRecommended() { | 924 bool ToolbarView::ShouldShowUpgradeRecommended() { |
903 #if defined(OS_CHROMEOS) | 925 #if defined(OS_CHROMEOS) |
904 // In chromeos, the update recommendation is shown in the system tray. So it | 926 // In chromeos, the update recommendation is shown in the system tray. So it |
905 // should not be displayed in the wrench menu. | 927 // should not be displayed in the wrench menu. |
906 return false; | 928 return false; |
907 #else | 929 #else |
908 return (UpgradeDetector::GetInstance()->notify_upgrade()); | 930 return (UpgradeDetector::GetInstance()->notify_upgrade()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 // LocationBarContainer is not a child of the ToolbarView. | 1010 // LocationBarContainer is not a child of the ToolbarView. |
989 gfx::Point origin(bounds.origin()); | 1011 gfx::Point origin(bounds.origin()); |
990 views::View::ConvertPointToTarget(this, location_bar_container_->parent(), | 1012 views::View::ConvertPointToTarget(this, location_bar_container_->parent(), |
991 &origin); | 1013 &origin); |
992 gfx::Rect target_bounds(origin, bounds.size()); | 1014 gfx::Rect target_bounds(origin, bounds.size()); |
993 if (location_bar_container_->GetTargetBounds() != target_bounds) { | 1015 if (location_bar_container_->GetTargetBounds() != target_bounds) { |
994 location_bar_container_->SetInToolbar(true); | 1016 location_bar_container_->SetInToolbar(true); |
995 location_bar_container_->SetBoundsRect(target_bounds); | 1017 location_bar_container_->SetBoundsRect(target_bounds); |
996 } | 1018 } |
997 } | 1019 } |
OLD | NEW |