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/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" | 36 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" |
37 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 37 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
38 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 38 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
40 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 40 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
41 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 41 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
42 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 42 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
43 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 43 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
44 #include "chrome/browser/ui/views/location_bar/star_view.h" | 44 #include "chrome/browser/ui/views/location_bar/star_view.h" |
45 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | 45 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
| 46 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
46 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 47 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
47 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
48 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
49 #include "chrome/common/extensions/extension_switch_utils.h" | 50 #include "chrome/common/extensions/extension_switch_utils.h" |
50 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
51 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
52 #include "content/public/browser/render_widget_host_view.h" | 53 #include "content/public/browser/render_widget_host_view.h" |
53 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
54 #include "grit/generated_resources.h" | 55 #include "grit/generated_resources.h" |
55 #include "grit/theme_resources.h" | 56 #include "grit/theme_resources.h" |
56 #include "grit/theme_resources_standard.h" | 57 #include "grit/theme_resources_standard.h" |
57 #include "ui/base/accessibility/accessible_view_state.h" | 58 #include "ui/base/accessibility/accessible_view_state.h" |
58 #include "ui/base/dragdrop/drag_drop_types.h" | 59 #include "ui/base/dragdrop/drag_drop_types.h" |
59 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
60 #include "ui/base/layout.h" | 61 #include "ui/base/layout.h" |
61 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
62 #include "ui/base/theme_provider.h" | 63 #include "ui/base/theme_provider.h" |
| 64 #include "ui/base/ui_base_switches.h" |
63 #include "ui/gfx/canvas.h" | 65 #include "ui/gfx/canvas.h" |
64 #include "ui/gfx/color_utils.h" | 66 #include "ui/gfx/color_utils.h" |
65 #include "ui/gfx/image/image.h" | 67 #include "ui/gfx/image/image.h" |
66 #include "ui/gfx/skia_util.h" | 68 #include "ui/gfx/skia_util.h" |
67 #include "ui/views/button_drag_utils.h" | 69 #include "ui/views/button_drag_utils.h" |
68 #include "ui/views/controls/label.h" | 70 #include "ui/views/controls/label.h" |
69 | 71 |
| 72 #if defined(OS_WIN) && !defined(USE_AURA) |
| 73 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 74 #endif |
| 75 |
70 #if !defined(OS_CHROMEOS) | 76 #if !defined(OS_CHROMEOS) |
71 #include "chrome/browser/ui/views/first_run_bubble.h" | 77 #include "chrome/browser/ui/views/first_run_bubble.h" |
72 #endif | 78 #endif |
73 | 79 |
74 | |
75 using content::WebContents; | 80 using content::WebContents; |
76 using views::View; | 81 using views::View; |
77 | 82 |
78 namespace { | 83 namespace { |
79 | 84 |
80 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { | 85 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { |
81 const TabContents* tab_contents = delegate->GetTabContents(); | 86 const TabContents* tab_contents = delegate->GetTabContents(); |
82 return tab_contents ? tab_contents->web_contents() : NULL; | 87 return tab_contents ? tab_contents->web_contents() : NULL; |
83 } | 88 } |
84 | 89 |
85 // A utility function to cast OmniboxView to OmniboxViewViews. | 90 bool UseOmniboxViews() { |
86 OmniboxViewViews* AsViews(OmniboxView* view) { | 91 #if defined(OS_WIN) && !defined(USE_AURA) |
87 return static_cast<OmniboxViewViews*>(view); | 92 static bool kUseOmniboxViews = CommandLine::ForCurrentProcess()-> |
| 93 HasSwitch(switches::kEnableViewsTextfield); |
| 94 return kUseOmniboxViews; |
| 95 #endif |
| 96 return true; |
88 } | 97 } |
89 | 98 |
| 99 // Return |view| as an OmniboxViewViews, or NULL if it is of a different type. |
| 100 OmniboxViewViews* GetOmniboxViewViews(OmniboxView* view) { |
| 101 return UseOmniboxViews() ? static_cast<OmniboxViewViews*>(view) : NULL; |
| 102 } |
| 103 |
| 104 #if defined(OS_WIN) && !defined(USE_AURA) |
| 105 // Return |view| as an OmniboxViewWin, or NULL if it is of a different type. |
| 106 OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view) { |
| 107 return UseOmniboxViews() ? NULL : static_cast<OmniboxViewWin*>(view); |
| 108 } |
| 109 #endif |
| 110 |
90 // Height of the location bar's round corner region. | 111 // Height of the location bar's round corner region. |
91 const int kBorderRoundCornerHeight = 5; | 112 const int kBorderRoundCornerHeight = 5; |
92 // Width of location bar's round corner region. | 113 // Width of location bar's round corner region. |
93 const int kBorderRoundCornerWidth = 4; | 114 const int kBorderRoundCornerWidth = 4; |
94 // Radius of the round corners inside the location bar. | 115 // Radius of the round corners inside the location bar. |
95 const int kBorderCornerRadius = 2; | 116 const int kBorderCornerRadius = 2; |
96 | 117 |
97 const int kDesktopItemPadding = 3; | 118 const int kDesktopItemPadding = 3; |
98 const int kDesktopEdgeItemPadding = kDesktopItemPadding; | 119 const int kDesktopEdgeItemPadding = kDesktopItemPadding; |
99 | 120 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 213 |
193 ev_bubble_view_ = | 214 ev_bubble_view_ = |
194 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, | 215 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
195 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); | 216 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); |
196 AddChildView(ev_bubble_view_); | 217 AddChildView(ev_bubble_view_); |
197 ev_bubble_view_->SetVisible(false); | 218 ev_bubble_view_->SetVisible(false); |
198 ev_bubble_view_->set_drag_controller(this); | 219 ev_bubble_view_->set_drag_controller(this); |
199 | 220 |
200 // URL edit field. | 221 // URL edit field. |
201 // View container for URL edit field. | 222 // View container for URL edit field. |
202 location_entry_.reset(OmniboxView::CreateOmniboxView( | 223 location_entry_.reset(CreateOmniboxView(this, model_, profile_, |
203 this, | 224 command_updater_, mode_ == POPUP, this)); |
204 model_, | |
205 profile_, | |
206 command_updater_, | |
207 mode_ == POPUP, | |
208 this)); | |
209 SetLocationEntryFocusable(true); | 225 SetLocationEntryFocusable(true); |
210 | 226 |
211 location_entry_view_ = location_entry_->AddToView(this); | 227 location_entry_view_ = location_entry_->AddToView(this); |
212 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); | 228 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); |
213 | 229 |
214 selected_keyword_view_ = new SelectedKeywordView( | 230 selected_keyword_view_ = new SelectedKeywordView( |
215 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, | 231 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
216 GetColor(ToolbarModel::NONE, TEXT), profile_); | 232 GetColor(ToolbarModel::NONE, TEXT), profile_); |
217 AddChildView(selected_keyword_view_); | 233 AddChildView(selected_keyword_view_); |
218 selected_keyword_view_->SetFont(font_); | 234 selected_keyword_view_->SetFont(font_); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 501 |
486 Layout(); | 502 Layout(); |
487 SchedulePaint(); | 503 SchedulePaint(); |
488 } | 504 } |
489 | 505 |
490 string16 LocationBarView::GetInstantSuggestion() const { | 506 string16 LocationBarView::GetInstantSuggestion() const { |
491 return HasValidSuggestText() ? suggested_text_view_->text() : string16(); | 507 return HasValidSuggestText() ? suggested_text_view_->text() : string16(); |
492 } | 508 } |
493 | 509 |
494 void LocationBarView::SetLocationEntryFocusable(bool focusable) { | 510 void LocationBarView::SetLocationEntryFocusable(bool focusable) { |
495 #if defined(USE_AURA) | 511 OmniboxViewViews* omnibox_views = GetOmniboxViewViews(location_entry_.get()); |
496 AsViews(location_entry_.get())->SetLocationEntryFocusable(focusable); | 512 if (omnibox_views) |
497 #else | 513 omnibox_views->SetLocationEntryFocusable(focusable); |
| 514 else |
498 set_focusable(focusable); | 515 set_focusable(focusable); |
499 #endif | |
500 } | 516 } |
501 | 517 |
502 bool LocationBarView::IsLocationEntryFocusableInRootView() const { | 518 bool LocationBarView::IsLocationEntryFocusableInRootView() const { |
503 #if defined(USE_AURA) | 519 OmniboxViewViews* omnibox_views = GetOmniboxViewViews(location_entry_.get()); |
504 return AsViews(location_entry_.get())->IsLocationEntryFocusableInRootView(); | 520 if (omnibox_views) |
505 #else | 521 return omnibox_views->IsLocationEntryFocusableInRootView(); |
506 return views::View::IsFocusable(); | 522 return views::View::IsFocusable(); |
507 #endif | |
508 } | 523 } |
509 | 524 |
510 gfx::Size LocationBarView::GetPreferredSize() { | 525 gfx::Size LocationBarView::GetPreferredSize() { |
511 return gfx::Size(0, GetThemeProvider()->GetImageSkiaNamed(mode_ == POPUP ? | 526 return gfx::Size(0, GetThemeProvider()->GetImageSkiaNamed(mode_ == POPUP ? |
512 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); | 527 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); |
513 } | 528 } |
514 | 529 |
515 void LocationBarView::Layout() { | 530 void LocationBarView::Layout() { |
516 if (!location_entry_.get()) | 531 if (!location_entry_.get()) |
517 return; | 532 return; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 } else if (event.IsRightMouseButton()) { | 873 } else if (event.IsRightMouseButton()) { |
859 msg = WM_RBUTTONUP; | 874 msg = WM_RBUTTONUP; |
860 } else { | 875 } else { |
861 NOTREACHED(); | 876 NOTREACHED(); |
862 return; | 877 return; |
863 } | 878 } |
864 OnMouseEvent(event, msg); | 879 OnMouseEvent(event, msg); |
865 } | 880 } |
866 | 881 |
867 void LocationBarView::OnMouseCaptureLost() { | 882 void LocationBarView::OnMouseCaptureLost() { |
868 GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); | 883 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); |
| 884 if (omnibox_win) |
| 885 omnibox_win->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); |
869 } | 886 } |
870 #endif | 887 #endif |
871 | 888 |
872 void LocationBarView::OnAutocompleteAccept( | 889 void LocationBarView::OnAutocompleteAccept( |
873 const GURL& url, | 890 const GURL& url, |
874 WindowOpenDisposition disposition, | 891 WindowOpenDisposition disposition, |
875 content::PageTransition transition, | 892 content::PageTransition transition, |
876 const GURL& alternate_nav_url) { | 893 const GURL& alternate_nav_url) { |
877 // WARNING: don't add an early return here. The calls after the if must | 894 // WARNING: don't add an early return here. The calls after the if must |
878 // happen. | 895 // happen. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1070 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
1054 content::Source<ExtensionAction>(action), | 1071 content::Source<ExtensionAction>(action), |
1055 content::Details<WebContents>(contents)); | 1072 content::Details<WebContents>(contents)); |
1056 } | 1073 } |
1057 } | 1074 } |
1058 } | 1075 } |
1059 } | 1076 } |
1060 | 1077 |
1061 #if defined(OS_WIN) && !defined(USE_AURA) | 1078 #if defined(OS_WIN) && !defined(USE_AURA) |
1062 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { | 1079 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { |
1063 UINT flags = event.native_event().wParam; | 1080 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); |
1064 gfx::Point screen_point(event.location()); | 1081 if (omnibox_win) { |
1065 ConvertPointToScreen(this, &screen_point); | 1082 UINT flags = event.native_event().wParam; |
1066 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | 1083 gfx::Point screen_point(event.location()); |
| 1084 ConvertPointToScreen(this, &screen_point); |
| 1085 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
| 1086 } |
1067 } | 1087 } |
1068 #endif | 1088 #endif |
1069 | 1089 |
1070 void LocationBarView::ShowFirstRunBubbleInternal() { | 1090 void LocationBarView::ShowFirstRunBubbleInternal() { |
1071 #if !defined(OS_CHROMEOS) | 1091 #if !defined(OS_CHROMEOS) |
1072 // First run bubble doesn't make sense for Chrome OS. | 1092 // First run bubble doesn't make sense for Chrome OS. |
1073 FirstRunBubble::ShowBubble(profile_, location_icon_view_); | 1093 FirstRunBubble::ShowBubble(profile_, location_icon_view_); |
1074 #endif | 1094 #endif |
1075 } | 1095 } |
1076 | 1096 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 // Return true so that focus traversal isn't attempted. The edit ends | 1140 // Return true so that focus traversal isn't attempted. The edit ends |
1121 // up doing nothing in this case. | 1141 // up doing nothing in this case. |
1122 if (location_entry_->model()->AcceptCurrentInstantPreview()) | 1142 if (location_entry_->model()->AcceptCurrentInstantPreview()) |
1123 return true; | 1143 return true; |
1124 } | 1144 } |
1125 | 1145 |
1126 #if defined(USE_AURA) | 1146 #if defined(USE_AURA) |
1127 NOTIMPLEMENTED(); | 1147 NOTIMPLEMENTED(); |
1128 return false; | 1148 return false; |
1129 #else | 1149 #else |
1130 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); | 1150 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); |
1131 #endif | 1151 if (omnibox_win) |
| 1152 return omnibox_win->SkipDefaultKeyEventProcessing(event); |
| 1153 #endif // USE_AURA |
| 1154 #endif // OS_WIN |
1132 | 1155 |
1133 #else | |
1134 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in | 1156 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
1135 // src/ui/views/focus/focus_manager.cc for details. | 1157 // src/ui/views/focus/focus_manager.cc for details. |
1136 return false; | 1158 return false; |
1137 #endif | |
1138 } | 1159 } |
1139 | 1160 |
1140 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { | 1161 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { |
1141 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; | 1162 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; |
1142 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | 1163 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); |
1143 state->value = location_entry_->GetText(); | 1164 state->value = location_entry_->GetText(); |
1144 | 1165 |
1145 string16::size_type entry_start; | 1166 string16::size_type entry_start; |
1146 string16::size_type entry_end; | 1167 string16::size_type entry_end; |
1147 location_entry_->GetSelectionBounds(&entry_start, &entry_end); | 1168 location_entry_->GetSelectionBounds(&entry_start, &entry_end); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1357 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
1337 int total_height = | 1358 int total_height = |
1338 use_preferred_size ? GetPreferredSize().height() : height(); | 1359 use_preferred_size ? GetPreferredSize().height() : height(); |
1339 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); | 1360 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); |
1340 } | 1361 } |
1341 | 1362 |
1342 bool LocationBarView::HasValidSuggestText() const { | 1363 bool LocationBarView::HasValidSuggestText() const { |
1343 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1364 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1344 !suggested_text_view_->text().empty(); | 1365 !suggested_text_view_->text().empty(); |
1345 } | 1366 } |
1346 | |
1347 #if !defined(USE_AURA) | |
1348 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | |
1349 return static_cast<OmniboxViewWin*>(location_entry_.get()); | |
1350 } | |
1351 #endif | |
OLD | NEW |