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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 ClearPopupKeywordMode(); | 458 ClearPopupKeywordMode(); |
| 459 | 459 |
| 460 bool keyword_is_selected = KeywordIsSelected(); | 460 bool keyword_is_selected = KeywordIsSelected(); |
| 461 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); | 461 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
| 462 | 462 |
| 463 size_t cursor_position; | 463 size_t cursor_position; |
| 464 if (inline_autocomplete_text_.empty()) { | 464 if (inline_autocomplete_text_.empty()) { |
| 465 // Cursor position is equivalent to the current selection's end. | 465 // Cursor position is equivalent to the current selection's end. |
| 466 size_t start; | 466 size_t start; |
| 467 view_->GetSelectionBounds(&start, &cursor_position); | 467 view_->GetSelectionBounds(&start, &cursor_position); |
| 468 // Adjust cursor position taking into account possible keyword in the | |
| 469 // user text. We rely on DisplayTextFromUserText method which is consistent | |
|
sky
2013/02/05 20:54:08
Add () after comments referencing functions, eg Di
Bart N.
2013/02/05 21:18:24
Done.
| |
| 470 // with keyword extraction done in KeywordProvider/SearchProvider. | |
| 471 const size_t cursor_offset = | |
| 472 user_text_.length() - DisplayTextFromUserText(user_text_).length(); | |
| 473 cursor_position += cursor_offset; | |
| 468 } else { | 474 } else { |
| 469 // There are some cases where StartAutocomplete() may be called | 475 // There are some cases where StartAutocomplete() may be called |
| 470 // with non-empty |inline_autocomplete_text_|. In such cases, we cannot | 476 // with non-empty |inline_autocomplete_text_|. In such cases, we cannot |
| 471 // use the current selection, because it could result with the cursor | 477 // use the current selection, because it could result with the cursor |
| 472 // position past the last character from the user text. Instead, | 478 // position past the last character from the user text. Instead, |
| 473 // we assume that the cursor is simply at the end of input. | 479 // we assume that the cursor is simply at the end of input. |
| 474 // One example is when user presses Ctrl key while having a highlighted | 480 // One example is when user presses Ctrl key while having a highlighted |
| 475 // inline autocomplete text. | 481 // inline autocomplete text. |
| 476 // TODO: Rethink how we are going to handle this case to avoid | 482 // TODO: Rethink how we are going to handle this case to avoid |
| 477 // inconsistent behavior when user presses Ctrl key. | 483 // inconsistent behavior when user presses Ctrl key. |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1342 instant->OmniboxFocusChanged(state, reason, NULL); | 1348 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1343 | 1349 |
| 1344 // Update state and notify view if the omnibox has focus and the caret | 1350 // Update state and notify view if the omnibox has focus and the caret |
| 1345 // visibility changed. | 1351 // visibility changed. |
| 1346 const bool was_caret_visible = is_caret_visible(); | 1352 const bool was_caret_visible = is_caret_visible(); |
| 1347 focus_state_ = state; | 1353 focus_state_ = state; |
| 1348 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1354 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1349 is_caret_visible() != was_caret_visible) | 1355 is_caret_visible() != was_caret_visible) |
| 1350 view_->ApplyCaretVisibility(); | 1356 view_->ApplyCaretVisibility(); |
| 1351 } | 1357 } |
| OLD | NEW |