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 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION))); | 174 UTF16ToWide(l10n_util::GetStringUTF16(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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 | 760 |
775 InstantController* instant = delegate_->GetInstant(); | 761 InstantController* instant = delegate_->GetInstant(); |
776 if (instant) | 762 if (instant) |
777 instant->OnAutocompleteLostFocus(view_gaining_focus); | 763 instant->OnAutocompleteLostFocus(view_gaining_focus); |
778 } | 764 } |
779 | 765 |
780 void LocationBarView::OnAutocompleteWillAccept() { | 766 void LocationBarView::OnAutocompleteWillAccept() { |
781 update_instant_ = false; | 767 update_instant_ = false; |
782 } | 768 } |
783 | 769 |
784 bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { | 770 bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { |
James Su
2011/01/06 23:01:35
How about remove this method's parameter? The type
oshima
2011/01/07 01:49:39
Which assumes that controller has these informatio
| |
785 InstantController* instant = delegate_->GetInstant(); | 771 InstantController* instant = delegate_->GetInstant(); |
786 if (!instant) | 772 if (!instant) |
787 return false; | 773 return false; |
788 | 774 std::wstring suggestion; |
789 #if defined(OS_WIN) | 775 #if defined(OS_WIN) |
790 if (!HasValidSuggestText()) | 776 if (!HasValidSuggestText()) |
791 return false; | 777 return false; |
792 location_entry_->model()->FinalizeInstantQuery( | 778 suggestion = suggested_text_view_->GetText(); |
793 typed_text, | |
794 suggested_text_view_->GetText()); | |
795 return true; | |
796 #else | |
797 return location_entry_->CommitInstantSuggestion(); | |
798 #endif | 779 #endif |
780 return location_entry_->CommitInstantSuggestion(typed_text, suggestion); | |
799 } | 781 } |
800 | 782 |
801 bool LocationBarView::AcceptCurrentInstantPreview() { | 783 bool LocationBarView::AcceptCurrentInstantPreview() { |
802 return InstantController::CommitIfCurrent(delegate_->GetInstant()); | 784 return InstantController::CommitIfCurrent(delegate_->GetInstant()); |
803 } | 785 } |
804 | 786 |
805 void LocationBarView::OnSetSuggestedSearchText(const string16& suggested_text) { | 787 void LocationBarView::OnSetSuggestedSearchText(const string16& suggested_text) { |
806 SetSuggestedText(suggested_text); | 788 SetSuggestedText(suggested_text); |
807 } | 789 } |
808 | 790 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 // harmless. | 822 // harmless. |
841 delete fetcher; | 823 delete fetcher; |
842 } else { | 824 } else { |
843 // The navigation controller will delete the fetcher. | 825 // The navigation controller will delete the fetcher. |
844 } | 826 } |
845 } | 827 } |
846 } | 828 } |
847 } | 829 } |
848 | 830 |
849 if (delegate_->GetInstant() && | 831 if (delegate_->GetInstant() && |
850 !location_entry_->model()->popup_model()->IsOpen()) { | 832 !location_entry_->model()->popup_model()->IsOpen()) |
851 delegate_->GetInstant()->DestroyPreviewContents(); | 833 delegate_->GetInstant()->DestroyPreviewContents(); |
852 } | |
853 | 834 |
854 update_instant_ = true; | 835 update_instant_ = true; |
855 } | 836 } |
856 | 837 |
857 void LocationBarView::OnChanged() { | 838 void LocationBarView::OnChanged() { |
858 location_icon_view_->SetImage( | 839 location_icon_view_->SetImage( |
859 ResourceBundle::GetSharedInstance().GetBitmapNamed( | 840 ResourceBundle::GetSharedInstance().GetBitmapNamed( |
860 location_entry_->GetIcon())); | 841 location_entry_->GetIcon())); |
861 Layout(); | 842 Layout(); |
862 SchedulePaint(); | 843 SchedulePaint(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1165 } else if (suggested_text_view_) { | 1146 } else if (suggested_text_view_) { |
1166 delete suggested_text_view_; | 1147 delete suggested_text_view_; |
1167 suggested_text_view_ = NULL; | 1148 suggested_text_view_ = NULL; |
1168 } else { | 1149 } else { |
1169 return; | 1150 return; |
1170 } | 1151 } |
1171 | 1152 |
1172 Layout(); | 1153 Layout(); |
1173 SchedulePaint(); | 1154 SchedulePaint(); |
1174 #else | 1155 #else |
1175 location_entry_->SetInstantSuggestion(UTF16ToUTF8(input)); | 1156 location_entry_->SetInstantSuggestion(input); |
1176 #endif | 1157 #endif |
1177 } | 1158 } |
1178 | 1159 |
1179 std::wstring LocationBarView::GetInputString() const { | 1160 std::wstring LocationBarView::GetInputString() const { |
1180 return location_input_; | 1161 return location_input_; |
1181 } | 1162 } |
1182 | 1163 |
1183 WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const { | 1164 WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const { |
1184 return disposition_; | 1165 return disposition_; |
1185 } | 1166 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1265 template_url_model_ = NULL; | 1246 template_url_model_ = NULL; |
1266 ShowFirstRunBubble(bubble_type_); | 1247 ShowFirstRunBubble(bubble_type_); |
1267 } | 1248 } |
1268 | 1249 |
1269 #if defined(OS_WIN) | 1250 #if defined(OS_WIN) |
1270 bool LocationBarView::HasValidSuggestText() { | 1251 bool LocationBarView::HasValidSuggestText() { |
1271 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1252 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1272 !suggested_text_view_->GetText().empty(); | 1253 !suggested_text_view_->GetText().empty(); |
1273 } | 1254 } |
1274 #endif | 1255 #endif |
OLD | NEW |