Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 10534153: Use OmniboxViewViews on Win with --enable-views-textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move CreateOmniboxView out of the views namespace. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 CommandLine* command_line = CommandLine::ForCurrentProcess();
sky 2012/06/14 23:04:46 This code is called alot, should we cache the resu
msw 2012/06/15 00:19:28 I've added class members |use_omnibox_view_views_|
93 return command_line->HasSwitch(switches::kEnableViewsTextfield);
94 #endif
95 return true;
88 } 96 }
89 97
98 // Return |view| as an OmniboxViewViews, or NULL if it is of a different type.
99 OmniboxViewViews* GetOmniboxViewViews(OmniboxView* view) {
100 return UseOmniboxViews() ? static_cast<OmniboxViewViews*>(view) : NULL;
101 }
102
103 #if defined(OS_WIN) && !defined(USE_AURA)
104 // Return |view| as an OmniboxViewWin, or NULL if it is of a different type.
105 OmniboxViewWin* GetOmniboxViewWin(OmniboxView* view) {
106 return UseOmniboxViews() ? NULL : static_cast<OmniboxViewWin*>(view);
107 }
108 #endif
109
90 // Height of the location bar's round corner region. 110 // Height of the location bar's round corner region.
91 const int kBorderRoundCornerHeight = 5; 111 const int kBorderRoundCornerHeight = 5;
92 // Width of location bar's round corner region. 112 // Width of location bar's round corner region.
93 const int kBorderRoundCornerWidth = 4; 113 const int kBorderRoundCornerWidth = 4;
94 // Radius of the round corners inside the location bar. 114 // Radius of the round corners inside the location bar.
95 const int kBorderCornerRadius = 2; 115 const int kBorderCornerRadius = 2;
96 116
97 const int kDesktopItemPadding = 3; 117 const int kDesktopItemPadding = 3;
98 const int kDesktopEdgeItemPadding = kDesktopItemPadding; 118 const int kDesktopEdgeItemPadding = kDesktopItemPadding;
99 119
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 212
193 ev_bubble_view_ = 213 ev_bubble_view_ =
194 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, 214 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID,
195 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); 215 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this);
196 AddChildView(ev_bubble_view_); 216 AddChildView(ev_bubble_view_);
197 ev_bubble_view_->SetVisible(false); 217 ev_bubble_view_->SetVisible(false);
198 ev_bubble_view_->set_drag_controller(this); 218 ev_bubble_view_->set_drag_controller(this);
199 219
200 // URL edit field. 220 // URL edit field.
201 // View container for URL edit field. 221 // View container for URL edit field.
202 location_entry_.reset(OmniboxView::CreateOmniboxView( 222 location_entry_.reset(CreateOmniboxView(this, model_, profile_,
203 this, 223 command_updater_, mode_ == POPUP, this));
204 model_,
205 profile_,
206 command_updater_,
207 mode_ == POPUP,
208 this));
209 SetLocationEntryFocusable(true); 224 SetLocationEntryFocusable(true);
210 225
211 location_entry_view_ = location_entry_->AddToView(this); 226 location_entry_view_ = location_entry_->AddToView(this);
212 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); 227 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE);
213 228
214 selected_keyword_view_ = new SelectedKeywordView( 229 selected_keyword_view_ = new SelectedKeywordView(
215 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, 230 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER,
216 GetColor(ToolbarModel::NONE, TEXT), profile_); 231 GetColor(ToolbarModel::NONE, TEXT), profile_);
217 AddChildView(selected_keyword_view_); 232 AddChildView(selected_keyword_view_);
218 selected_keyword_view_->SetFont(font_); 233 selected_keyword_view_->SetFont(font_);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 500
486 Layout(); 501 Layout();
487 SchedulePaint(); 502 SchedulePaint();
488 } 503 }
489 504
490 string16 LocationBarView::GetInstantSuggestion() const { 505 string16 LocationBarView::GetInstantSuggestion() const {
491 return HasValidSuggestText() ? suggested_text_view_->text() : string16(); 506 return HasValidSuggestText() ? suggested_text_view_->text() : string16();
492 } 507 }
493 508
494 void LocationBarView::SetLocationEntryFocusable(bool focusable) { 509 void LocationBarView::SetLocationEntryFocusable(bool focusable) {
495 #if defined(USE_AURA) 510 OmniboxViewViews* omnibox_views = GetOmniboxViewViews(location_entry_.get());
496 AsViews(location_entry_.get())->SetLocationEntryFocusable(focusable); 511 if (omnibox_views)
497 #else 512 omnibox_views->SetLocationEntryFocusable(focusable);
513 else
498 set_focusable(focusable); 514 set_focusable(focusable);
499 #endif
500 } 515 }
501 516
502 bool LocationBarView::IsLocationEntryFocusableInRootView() const { 517 bool LocationBarView::IsLocationEntryFocusableInRootView() const {
503 #if defined(USE_AURA) 518 OmniboxViewViews* omnibox_views = GetOmniboxViewViews(location_entry_.get());
504 return AsViews(location_entry_.get())->IsLocationEntryFocusableInRootView(); 519 if (omnibox_views)
505 #else 520 return omnibox_views->IsLocationEntryFocusableInRootView();
506 return views::View::IsFocusable(); 521 return views::View::IsFocusable();
507 #endif
508 } 522 }
509 523
510 gfx::Size LocationBarView::GetPreferredSize() { 524 gfx::Size LocationBarView::GetPreferredSize() {
511 return gfx::Size(0, GetThemeProvider()->GetImageSkiaNamed(mode_ == POPUP ? 525 return gfx::Size(0, GetThemeProvider()->GetImageSkiaNamed(mode_ == POPUP ?
512 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); 526 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height());
513 } 527 }
514 528
515 void LocationBarView::Layout() { 529 void LocationBarView::Layout() {
516 if (!location_entry_.get()) 530 if (!location_entry_.get())
517 return; 531 return;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } else if (event.IsRightMouseButton()) { 872 } else if (event.IsRightMouseButton()) {
859 msg = WM_RBUTTONUP; 873 msg = WM_RBUTTONUP;
860 } else { 874 } else {
861 NOTREACHED(); 875 NOTREACHED();
862 return; 876 return;
863 } 877 }
864 OnMouseEvent(event, msg); 878 OnMouseEvent(event, msg);
865 } 879 }
866 880
867 void LocationBarView::OnMouseCaptureLost() { 881 void LocationBarView::OnMouseCaptureLost() {
868 GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); 882 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get());
883 if (omnibox_win)
884 omnibox_win->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint());
869 } 885 }
870 #endif 886 #endif
871 887
872 void LocationBarView::OnAutocompleteAccept( 888 void LocationBarView::OnAutocompleteAccept(
873 const GURL& url, 889 const GURL& url,
874 WindowOpenDisposition disposition, 890 WindowOpenDisposition disposition,
875 content::PageTransition transition, 891 content::PageTransition transition,
876 const GURL& alternate_nav_url) { 892 const GURL& alternate_nav_url) {
877 // WARNING: don't add an early return here. The calls after the if must 893 // WARNING: don't add an early return here. The calls after the if must
878 // happen. 894 // happen.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 1069 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
1054 content::Source<ExtensionAction>(action), 1070 content::Source<ExtensionAction>(action),
1055 content::Details<WebContents>(contents)); 1071 content::Details<WebContents>(contents));
1056 } 1072 }
1057 } 1073 }
1058 } 1074 }
1059 } 1075 }
1060 1076
1061 #if defined(OS_WIN) && !defined(USE_AURA) 1077 #if defined(OS_WIN) && !defined(USE_AURA)
1062 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { 1078 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) {
1063 UINT flags = event.native_event().wParam; 1079 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get());
1064 gfx::Point screen_point(event.location()); 1080 if (omnibox_win) {
1065 ConvertPointToScreen(this, &screen_point); 1081 UINT flags = event.native_event().wParam;
1066 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); 1082 gfx::Point screen_point(event.location());
1083 ConvertPointToScreen(this, &screen_point);
1084 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT());
1085 }
1067 } 1086 }
1068 #endif 1087 #endif
1069 1088
1070 void LocationBarView::ShowFirstRunBubbleInternal() { 1089 void LocationBarView::ShowFirstRunBubbleInternal() {
1071 #if !defined(OS_CHROMEOS) 1090 #if !defined(OS_CHROMEOS)
1072 // First run bubble doesn't make sense for Chrome OS. 1091 // First run bubble doesn't make sense for Chrome OS.
1073 FirstRunBubble::ShowBubble(profile_, location_icon_view_); 1092 FirstRunBubble::ShowBubble(profile_, location_icon_view_);
1074 #endif 1093 #endif
1075 } 1094 }
1076 1095
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 // Return true so that focus traversal isn't attempted. The edit ends 1139 // Return true so that focus traversal isn't attempted. The edit ends
1121 // up doing nothing in this case. 1140 // up doing nothing in this case.
1122 if (location_entry_->model()->AcceptCurrentInstantPreview()) 1141 if (location_entry_->model()->AcceptCurrentInstantPreview())
1123 return true; 1142 return true;
1124 } 1143 }
1125 1144
1126 #if defined(USE_AURA) 1145 #if defined(USE_AURA)
1127 NOTIMPLEMENTED(); 1146 NOTIMPLEMENTED();
1128 return false; 1147 return false;
1129 #else 1148 #else
1130 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); 1149 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get());
1131 #endif 1150 if (omnibox_win)
1151 return omnibox_win->SkipDefaultKeyEventProcessing(event);
1152 #endif // USE_AURA
1153 #endif // OS_WIN
1132 1154
1133 #else
1134 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in 1155 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in
1135 // src/ui/views/focus/focus_manager.cc for details. 1156 // src/ui/views/focus/focus_manager.cc for details.
1136 return false; 1157 return false;
1137 #endif
1138 } 1158 }
1139 1159
1140 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { 1160 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) {
1141 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; 1161 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR;
1142 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); 1162 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION);
1143 state->value = location_entry_->GetText(); 1163 state->value = location_entry_->GetText();
1144 1164
1145 string16::size_type entry_start; 1165 string16::size_type entry_start;
1146 string16::size_type entry_end; 1166 string16::size_type entry_end;
1147 location_entry_->GetSelectionBounds(&entry_start, &entry_end); 1167 location_entry_->GetSelectionBounds(&entry_start, &entry_end);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 int LocationBarView::GetInternalHeight(bool use_preferred_size) { 1356 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1337 int total_height = 1357 int total_height =
1338 use_preferred_size ? GetPreferredSize().height() : height(); 1358 use_preferred_size ? GetPreferredSize().height() : height();
1339 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); 1359 return std::max(total_height - (kVerticalEdgeThickness * 2), 0);
1340 } 1360 }
1341 1361
1342 bool LocationBarView::HasValidSuggestText() const { 1362 bool LocationBarView::HasValidSuggestText() const {
1343 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1363 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1344 !suggested_text_view_->text().empty(); 1364 !suggested_text_view_->text().empty();
1345 } 1365 }
1346
1347 #if !defined(USE_AURA)
1348 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() {
1349 return static_cast<OmniboxViewWin*>(location_entry_.get());
1350 }
1351 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/location_bar/page_info_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698