| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 306 |
| 307 bool OmniboxEditModel::UseVerbatimInstant() { | 307 bool OmniboxEditModel::UseVerbatimInstant() { |
| 308 #if defined(OS_MACOSX) | 308 #if defined(OS_MACOSX) |
| 309 // TODO(suzhe): Fix Mac port to display Instant suggest in a separated NSView, | 309 // TODO(suzhe): Fix Mac port to display Instant suggest in a separated NSView, |
| 310 // so that we can display Instant suggest along with composition text. | 310 // so that we can display Instant suggest along with composition text. |
| 311 const AutocompleteInput& input = autocomplete_controller_->input(); | 311 const AutocompleteInput& input = autocomplete_controller_->input(); |
| 312 if (input.prevent_inline_autocomplete()) | 312 if (input.prevent_inline_autocomplete()) |
| 313 return true; | 313 return true; |
| 314 #endif | 314 #endif |
| 315 | 315 |
| 316 // The value of input.prevent_inline_autocomplete() is determined by | 316 // The value of input.prevent_inline_autocomplete() is determined by the |
| 317 // following conditions: | 317 // following conditions: |
| 318 // 1. If the caret is at the end of the text (checked below). | 318 // 1. If the caret is at the end of the text. |
| 319 // 2. If it's in IME composition mode. | 319 // 2. If it's in IME composition mode. |
| 320 // As we use a separated widget for displaying the Instant suggest, it won't | 320 // We send the caret position to Instant (so it can determine #1 itself), and |
| 321 // interfere with IME composition, so we don't need to care about the value of | 321 // we use a separated widget for displaying the Instant suggest (so it doesn't |
| 322 // interfere with #2). So, we don't need to care about the value of |
| 322 // input.prevent_inline_autocomplete() here. | 323 // input.prevent_inline_autocomplete() here. |
| 323 if (view_->DeleteAtEndPressed() || (popup_->selected_line() != 0) || | 324 return view_->DeleteAtEndPressed() || popup_->selected_line() != 0 || |
| 324 just_deleted_text_ || !inline_autocomplete_text_.empty()) | 325 just_deleted_text_; |
| 325 return true; | |
| 326 | |
| 327 size_t start, end; | |
| 328 view_->GetSelectionBounds(&start, &end); | |
| 329 return (start != end) || (start != view_->GetText().length()); | |
| 330 } | 326 } |
| 331 | 327 |
| 332 string16 OmniboxEditModel::GetDesiredTLD() const { | 328 string16 OmniboxEditModel::GetDesiredTLD() const { |
| 333 // Tricky corner case: The user has typed "foo" and currently sees an inline | 329 // Tricky corner case: The user has typed "foo" and currently sees an inline |
| 334 // autocomplete suggestion of "foo.net". He now presses ctrl-a (e.g. to | 330 // autocomplete suggestion of "foo.net". He now presses ctrl-a (e.g. to |
| 335 // select all, on Windows). If we treat the ctrl press as potentially for the | 331 // select all, on Windows). If we treat the ctrl press as potentially for the |
| 336 // sake of ctrl-enter, then we risk "www.foo.com" being promoted as the best | 332 // sake of ctrl-enter, then we risk "www.foo.com" being promoted as the best |
| 337 // match. This would make the autocompleted text disappear, leaving our user | 333 // match. This would make the autocompleted text disappear, leaving our user |
| 338 // feeling very confused when the wrong text gets highlighted. | 334 // feeling very confused when the wrong text gets highlighted. |
| 339 // | 335 // |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 } | 1178 } |
| 1183 } | 1179 } |
| 1184 | 1180 |
| 1185 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { | 1181 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { |
| 1186 InstantController* instant = controller_->GetInstant(); | 1182 InstantController* instant = controller_->GetInstant(); |
| 1187 if (!instant || in_revert_) | 1183 if (!instant || in_revert_) |
| 1188 return false; | 1184 return false; |
| 1189 | 1185 |
| 1190 // The two pieces of text we want to send Instant, viz., what the user has | 1186 // The two pieces of text we want to send Instant, viz., what the user has |
| 1191 // typed, and the full omnibox text including any inline autocompletion. | 1187 // typed, and the full omnibox text including any inline autocompletion. |
| 1192 string16 user_text = user_text_; | 1188 string16 user_text = has_temporary_text_ ? |
| 1193 string16 full_text = user_text_ + inline_autocomplete_text_; | 1189 match.fill_into_edit : DisplayTextFromUserText(user_text_); |
| 1194 | 1190 string16 full_text = view_->GetText(); |
| 1195 // If there's temporary text, that overrides the user_text. In this case, we | |
| 1196 // should ignore any inline_autocomplete_text_, because it won't be visible. | |
| 1197 if (has_temporary_text_) | |
| 1198 user_text = full_text = CurrentMatch().fill_into_edit; | |
| 1199 | |
| 1200 // Remove keyword if we're in keyword mode. | |
| 1201 user_text = DisplayTextFromUserText(user_text); | |
| 1202 full_text = DisplayTextFromUserText(full_text); | |
| 1203 | 1191 |
| 1204 // Remove "?" if we're in forced query mode. | 1192 // Remove "?" if we're in forced query mode. |
| 1205 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1193 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
| 1206 autocomplete_controller_->input().type(), &user_text); | 1194 autocomplete_controller_->input().type(), &user_text); |
| 1207 AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 1195 AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
| 1208 autocomplete_controller_->input().type(), &full_text); | 1196 autocomplete_controller_->input().type(), &full_text); |
| 1209 | 1197 |
| 1210 return instant->Update(match, user_text, full_text, UseVerbatimInstant(), | 1198 size_t start, end; |
| 1211 user_input_in_progress_, popup_->IsOpen()); | 1199 view_->GetSelectionBounds(&start, &end); |
| 1200 |
| 1201 return instant->Update(match, user_text, full_text, start, end, |
| 1202 UseVerbatimInstant(), user_input_in_progress_, popup_->IsOpen()); |
| 1212 } | 1203 } |
| 1213 | 1204 |
| 1214 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) { | 1205 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) { |
| 1215 // Do not prerender if the destination URL is the same as the current URL. | 1206 // Do not prerender if the destination URL is the same as the current URL. |
| 1216 if (match.destination_url == PermanentURL()) | 1207 if (match.destination_url == PermanentURL()) |
| 1217 return; | 1208 return; |
| 1218 // It's possible the tab strip does not have an active tab contents, for | 1209 // It's possible the tab strip does not have an active tab contents, for |
| 1219 // instance if the tab has been closed or on return from a sleep state | 1210 // instance if the tab has been closed or on return from a sleep state |
| 1220 // (http://crbug.com/105689) | 1211 // (http://crbug.com/105689) |
| 1221 content::WebContents* tab = controller_->GetWebContents(); | 1212 content::WebContents* tab = controller_->GetWebContents(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 } | 1262 } |
| 1272 | 1263 |
| 1273 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1264 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
| 1274 const string16& text, | 1265 const string16& text, |
| 1275 AutocompleteMatch* match, | 1266 AutocompleteMatch* match, |
| 1276 GURL* alternate_nav_url) const { | 1267 GURL* alternate_nav_url) const { |
| 1277 DCHECK(match); | 1268 DCHECK(match); |
| 1278 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1269 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
| 1279 string16(), false, false, match, alternate_nav_url); | 1270 string16(), false, false, match, alternate_nav_url); |
| 1280 } | 1271 } |
| OLD | NEW |