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 "components/omnibox/browser/omnibox_edit_model.h" | 5 #include "components/omnibox/browser/omnibox_edit_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 void OmniboxEditModel::Revert() { | 365 void OmniboxEditModel::Revert() { |
366 SetInputInProgress(false); | 366 SetInputInProgress(false); |
367 input_.Clear(); | 367 input_.Clear(); |
368 paste_state_ = NONE; | 368 paste_state_ = NONE; |
369 InternalSetUserText(base::string16()); | 369 InternalSetUserText(base::string16()); |
370 keyword_.clear(); | 370 keyword_.clear(); |
371 is_keyword_hint_ = false; | 371 is_keyword_hint_ = false; |
372 has_temporary_text_ = false; | 372 has_temporary_text_ = false; |
373 size_t start, end; | 373 size_t start, end; |
374 view_->GetSelectionBounds(&start, &end); | 374 view_->GetSelectionBounds(&start, &end); |
375 view_->SetWindowTextAndCaretPos(permanent_text_, 0, false, false); | 375 // First home the cursor, so view of text is scrolled to left, then correct |
376 view_->SetWindowTextAndCaretPos( | 376 // it. |SetCaretPos()| doesn't scroll the text, so doing that first wouldn't |
377 permanent_text_, std::min(permanent_text_.length(), start), false, true); | 377 // accomplish anything. |
| 378 view_->SetWindowTextAndCaretPos(permanent_text_, 0, false, true); |
| 379 view_->SetCaretPos(std::min(permanent_text_.length(), start)); |
378 client_->OnRevert(); | 380 client_->OnRevert(); |
379 } | 381 } |
380 | 382 |
381 void OmniboxEditModel::StartAutocomplete(bool has_selected_text, | 383 void OmniboxEditModel::StartAutocomplete(bool has_selected_text, |
382 bool prevent_inline_autocomplete) { | 384 bool prevent_inline_autocomplete) { |
383 const base::string16 input_text = MaybePrependKeyword(user_text_); | 385 const base::string16 input_text = MaybePrependKeyword(user_text_); |
384 | 386 |
385 size_t start, cursor_position; | 387 size_t start, cursor_position; |
386 view_->GetSelectionBounds(&start, &cursor_position); | 388 view_->GetSelectionBounds(&start, &cursor_position); |
387 | 389 |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 // Update state and notify view if the omnibox has focus and the caret | 1390 // Update state and notify view if the omnibox has focus and the caret |
1389 // visibility changed. | 1391 // visibility changed. |
1390 const bool was_caret_visible = is_caret_visible(); | 1392 const bool was_caret_visible = is_caret_visible(); |
1391 focus_state_ = state; | 1393 focus_state_ = state; |
1392 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1394 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1393 is_caret_visible() != was_caret_visible) | 1395 is_caret_visible() != was_caret_visible) |
1394 view_->ApplyCaretVisibility(); | 1396 view_->ApplyCaretVisibility(); |
1395 | 1397 |
1396 client_->OnFocusChanged(focus_state_, reason); | 1398 client_->OnFocusChanged(focus_state_, reason); |
1397 } | 1399 } |
OLD | NEW |