Chromium Code Reviews| 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/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 action_predictor->ClearTransitionalMatches(); | 449 action_predictor->ClearTransitionalMatches(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 void OmniboxEditModel::StartAutocomplete( | 452 void OmniboxEditModel::StartAutocomplete( |
| 453 bool has_selected_text, | 453 bool has_selected_text, |
| 454 bool prevent_inline_autocomplete) const { | 454 bool prevent_inline_autocomplete) const { |
| 455 ClearPopupKeywordMode(); | 455 ClearPopupKeywordMode(); |
| 456 | 456 |
| 457 bool keyword_is_selected = KeywordIsSelected(); | 457 bool keyword_is_selected = KeywordIsSelected(); |
| 458 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); | 458 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
| 459 | |
| 460 size_t cursor_position; | |
| 461 if (inline_autocomplete_text_.empty()) { | |
| 462 // Cursor position is equivalent to the current selection's end. | |
| 463 size_t start; | |
| 464 view_->GetSelectionBounds(&start, &cursor_position); | |
| 465 } else { | |
| 466 // There are some cases where StartAutocomplete() may be called | |
| 467 // with non-empty |inline_autocomplete_text_|. In such cases, we cannot | |
| 468 // use the current selection, because it could result with the cursor | |
| 469 // position past the last character from the user text. Instead, | |
|
Peter Kasting
2012/12/18 03:01:01
In theory, inline autocompletions are supposed to
Bart N.
2012/12/18 23:47:39
Yes. See http://crbug.com/165961. I've updated the
| |
| 470 // we assume that the cursor is simply at the end of input. | |
| 471 // One example is when user presses Ctrl key while having a highlighted | |
| 472 // inline autocomplete text. | |
| 473 // TODO: Rethink how we are going to handle this case to avoid | |
| 474 // inconsistent behavior when user presses Ctrl key. | |
| 475 cursor_position = user_text_.length(); | |
| 476 } | |
| 477 | |
| 459 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as | 478 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as |
| 460 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. | 479 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. |
| 461 autocomplete_controller_->Start( | 480 autocomplete_controller_->Start(AutocompleteInput( |
| 462 user_text_, GetDesiredTLD(), | 481 user_text_, cursor_position, GetDesiredTLD(), |
| 463 prevent_inline_autocomplete || just_deleted_text_ || | 482 prevent_inline_autocomplete || just_deleted_text_ || |
| 464 (has_selected_text && inline_autocomplete_text_.empty()) || | 483 (has_selected_text && inline_autocomplete_text_.empty()) || |
| 465 (paste_state_ != NONE), keyword_is_selected, | 484 (paste_state_ != NONE), keyword_is_selected, |
| 466 keyword_is_selected || allow_exact_keyword_match_, | 485 keyword_is_selected || allow_exact_keyword_match_, |
| 467 AutocompleteInput::ALL_MATCHES); | 486 AutocompleteInput::ALL_MATCHES)); |
| 468 } | 487 } |
| 469 | 488 |
| 470 void OmniboxEditModel::StopAutocomplete() { | 489 void OmniboxEditModel::StopAutocomplete() { |
| 471 autocomplete_controller_->Stop(true); | 490 autocomplete_controller_->Stop(true); |
| 472 } | 491 } |
| 473 | 492 |
| 474 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { | 493 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { |
| 475 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) | 494 if (!view_->command_updater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) |
| 476 return false; | 495 return false; |
| 477 | 496 |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 instant->OmniboxFocusChanged(state, reason, NULL); | 1335 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1317 | 1336 |
| 1318 // Update state and notify view if the omnibox has focus and the caret | 1337 // Update state and notify view if the omnibox has focus and the caret |
| 1319 // visibility changed. | 1338 // visibility changed. |
| 1320 const bool was_caret_visible = is_caret_visible(); | 1339 const bool was_caret_visible = is_caret_visible(); |
| 1321 focus_state_ = state; | 1340 focus_state_ = state; |
| 1322 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1341 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1323 is_caret_visible() != was_caret_visible) | 1342 is_caret_visible() != was_caret_visible) |
| 1324 view_->ApplyCaretVisibility(); | 1343 view_->ApplyCaretVisibility(); |
| 1325 } | 1344 } |
| OLD | NEW |