OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/location_bar/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 ev_bubble_view_->SetVisible(false); | 155 ev_bubble_view_->SetVisible(false); |
156 ev_bubble_view_->SetDragController(this); | 156 ev_bubble_view_->SetDragController(this); |
157 | 157 |
158 // URL edit field. | 158 // URL edit field. |
159 // View container for URL edit field. | 159 // View container for URL edit field. |
160 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
161 location_entry_.reset(new AutocompleteEditViewWin(font_, this, model_, this, | 161 location_entry_.reset(new AutocompleteEditViewWin(font_, this, model_, this, |
162 GetWidget()->GetNativeView(), profile_, command_updater_, | 162 GetWidget()->GetNativeView(), profile_, command_updater_, |
163 mode_ == POPUP, this)); | 163 mode_ == POPUP, this)); |
164 #else | 164 #else |
165 location_entry_.reset(new AutocompleteEditViewGtk(this, model_, profile_, | 165 location_entry_.reset( |
166 command_updater_, mode_ == POPUP, this)); | 166 AutocompleteEditViewGtk::Create( |
167 location_entry_->Init(); | 167 this, model_, profile_, |
168 // Make all the children of the widget visible. NOTE: this won't display | 168 command_updater_, mode_ == POPUP, this)); |
169 // anything, it just toggles the visible flag. | 169 #endif |
170 gtk_widget_show_all(location_entry_->GetNativeView()); | |
171 // Hide the widget. NativeViewHostGtk will make it visible again as | |
172 // necessary. | |
173 gtk_widget_hide(location_entry_->GetNativeView()); | |
174 | 170 |
175 // Associate an accessible name with the location entry. | 171 location_entry_view_ = location_entry_->AddToView(this); |
176 accessible_widget_helper_.reset(new AccessibleWidgetHelper( | |
177 location_entry_->text_view(), profile_)); | |
178 accessible_widget_helper_->SetWidgetName( | |
179 location_entry_->text_view(), | |
180 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION)); | |
181 #endif | |
182 location_entry_view_ = new views::NativeViewHost; | |
183 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); | 172 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); |
184 AddChildView(location_entry_view_); | |
185 location_entry_view_->set_focus_view(this); | |
186 location_entry_view_->Attach(location_entry_->GetNativeView()); | |
187 location_entry_view_->SetAccessibleName( | 173 location_entry_view_->SetAccessibleName( |
188 l10n_util::GetString(IDS_ACCNAME_LOCATION)); | 174 l10n_util::GetString(IDS_ACCNAME_LOCATION)); |
189 | 175 |
190 selected_keyword_view_ = new SelectedKeywordView( | 176 selected_keyword_view_ = new SelectedKeywordView( |
191 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, | 177 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
192 GetColor(ToolbarModel::NONE, TEXT), profile_), | 178 GetColor(ToolbarModel::NONE, TEXT), profile_), |
193 AddChildView(selected_keyword_view_); | 179 AddChildView(selected_keyword_view_); |
194 selected_keyword_view_->SetFont(font_); | 180 selected_keyword_view_->SetFont(font_); |
195 selected_keyword_view_->SetVisible(false); | 181 selected_keyword_view_->SetVisible(false); |
196 | 182 |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 if (instant) | 761 if (instant) |
776 instant->OnAutocompleteLostFocus(view_gaining_focus); | 762 instant->OnAutocompleteLostFocus(view_gaining_focus); |
777 } | 763 } |
778 | 764 |
779 void LocationBarView::OnAutocompleteWillAccept() { | 765 void LocationBarView::OnAutocompleteWillAccept() { |
780 update_instant_ = false; | 766 update_instant_ = false; |
781 } | 767 } |
782 | 768 |
783 bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { | 769 bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { |
784 InstantController* instant = delegate_->GetInstant(); | 770 InstantController* instant = delegate_->GetInstant(); |
785 if (!instant) | 771 if (!instant || !HasValidSuggestText()) |
786 return false; | 772 return false; |
787 | |
788 #if defined(OS_WIN) | 773 #if defined(OS_WIN) |
Peter Kasting
2011/01/06 02:06:48
Nit: While I like const locals, most Chrome code a
oshima
2011/01/06 19:43:35
Done.
| |
789 if (!HasValidSuggestText()) | 774 const std::wstring suggestion = suggested_text_view_->GetText(); |
790 return false; | |
791 location_entry_->model()->FinalizeInstantQuery( | |
792 typed_text, | |
793 suggested_text_view_->GetText()); | |
794 return true; | |
795 #else | 775 #else |
796 return location_entry_->CommitInstantSuggestion(); | 776 const std::wstring suggestion; |
797 #endif | 777 #endif |
778 return location_entry_->CommitInstantSuggestion(typed_text, suggestion); | |
798 } | 779 } |
799 | 780 |
800 bool LocationBarView::AcceptCurrentInstantPreview() { | 781 bool LocationBarView::AcceptCurrentInstantPreview() { |
801 return InstantController::CommitIfCurrent(delegate_->GetInstant()); | 782 return InstantController::CommitIfCurrent(delegate_->GetInstant()); |
802 } | 783 } |
803 | 784 |
804 void LocationBarView::OnSetSuggestedSearchText(const string16& suggested_text) { | 785 void LocationBarView::OnSetSuggestedSearchText(const string16& suggested_text) { |
805 SetSuggestedText(suggested_text); | 786 SetSuggestedText(suggested_text); |
806 } | 787 } |
807 | 788 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1162 } else if (suggested_text_view_) { | 1143 } else if (suggested_text_view_) { |
1163 delete suggested_text_view_; | 1144 delete suggested_text_view_; |
1164 suggested_text_view_ = NULL; | 1145 suggested_text_view_ = NULL; |
1165 } else { | 1146 } else { |
1166 return; | 1147 return; |
1167 } | 1148 } |
1168 | 1149 |
1169 Layout(); | 1150 Layout(); |
1170 SchedulePaint(); | 1151 SchedulePaint(); |
1171 #else | 1152 #else |
1172 location_entry_->SetInstantSuggestion(UTF16ToUTF8(input)); | 1153 location_entry_->SetInstantSuggestion(input); |
1173 #endif | 1154 #endif |
1174 } | 1155 } |
1175 | 1156 |
1176 std::wstring LocationBarView::GetInputString() const { | 1157 std::wstring LocationBarView::GetInputString() const { |
1177 return location_input_; | 1158 return location_input_; |
1178 } | 1159 } |
1179 | 1160 |
1180 WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const { | 1161 WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const { |
1181 return disposition_; | 1162 return disposition_; |
1182 } | 1163 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 | 1237 |
1257 NOTREACHED(); | 1238 NOTREACHED(); |
1258 } | 1239 } |
1259 | 1240 |
1260 void LocationBarView::OnTemplateURLModelChanged() { | 1241 void LocationBarView::OnTemplateURLModelChanged() { |
1261 template_url_model_->RemoveObserver(this); | 1242 template_url_model_->RemoveObserver(this); |
1262 template_url_model_ = NULL; | 1243 template_url_model_ = NULL; |
1263 ShowFirstRunBubble(bubble_type_); | 1244 ShowFirstRunBubble(bubble_type_); |
1264 } | 1245 } |
1265 | 1246 |
1247 bool LocationBarView::HasValidSuggestText() { | |
1266 #if defined(OS_WIN) | 1248 #if defined(OS_WIN) |
1267 bool LocationBarView::HasValidSuggestText() { | |
1268 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1249 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1269 !suggested_text_view_->GetText().empty(); | 1250 !suggested_text_view_->GetText().empty(); |
1251 #else | |
1252 return true; | |
Peter Kasting
2011/01/06 02:06:48
Nit: Wouldn't it be better to call the Autocomplet
oshima
2011/01/06 19:43:35
Thank you for suggestion. Yes, i'm planning to ref
| |
1253 #endif | |
1270 } | 1254 } |
1271 #endif | |
OLD | NEW |