Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: components/omnibox/browser/omnibox_edit_model.cc

Issue 2435103002: Omnibox: Preserve display text and select all on a focus search (Closed)
Patch Set: Add browser tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 408
409 void OmniboxEditModel::StartAutocomplete(bool has_selected_text, 409 void OmniboxEditModel::StartAutocomplete(bool has_selected_text,
410 bool prevent_inline_autocomplete) { 410 bool prevent_inline_autocomplete) {
411 const base::string16 input_text = MaybePrependKeyword(user_text_); 411 const base::string16 input_text = MaybePrependKeyword(user_text_);
412 412
413 // Compute the cursor position. There are three cases: 413 // Compute the cursor position. There are three cases:
414 // 1. The user is in the midst of typing; there is no inline autocompletion. 414 // 1. The user is in the midst of typing; there is no inline autocompletion.
415 // 2. The user is in the midst of typing; there is inline autocompletion. 415 // 2. The user is in the midst of typing; there is inline autocompletion.
416 // 3. The user is not in the midst of typing, but is triggering this some 416 // 3. The user is not in the midst of typing, but is triggering this some
417 // other way, e.g. hitting ctrl-K while the view is showing the permanent 417 // other way, e.g. hitting ctrl-K while the view is showing the permanent
418 // or temporary text. 418 // or temporary text.
Peter Kasting 2016/10/20 21:42:00 We need to touch this function. Because you're ch
Tom (Use chromium acct) 2016/10/25 02:11:08 I couldn't really figure out a way to make this wo
419 size_t cursor_position; 419 size_t cursor_position;
420 if (!has_temporary_text_ && (user_text_ == view_->GetText())) { 420 if (!has_temporary_text_ && (user_text_ == view_->GetText())) {
421 // Case 1 above. In this case there's a meaningful current cursor position, 421 // Case 1 above. In this case there's a meaningful current cursor position,
422 // so we read it from the view. (Note that if there is a selected range, 422 // so we read it from the view. (Note that if there is a selected range,
423 // the "cursor position" is considered to be the selection's end.) 423 // the "cursor position" is considered to be the selection's end.)
424 size_t start; 424 size_t start;
425 view_->GetSelectionBounds(&start, &cursor_position); 425 view_->GetSelectionBounds(&start, &cursor_position);
426 426
427 // For keyword searches, the text that AutocompleteInput expects is of the 427 // For keyword searches, the text that AutocompleteInput expects is of the
428 // form "<keyword> <query>", where our query is |user_text_|. So we need to 428 // form "<keyword> <query>", where our query is |user_text_|. So we need to
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 553
554 DCHECK(popup_model()); 554 DCHECK(popup_model());
555 view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(), 555 view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(),
556 popup_model()->selected_line()); 556 popup_model()->selected_line());
557 } 557 }
558 558
559 void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider( 559 void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider(
560 KeywordModeEntryMethod entry_method) { 560 KeywordModeEntryMethod entry_method) {
561 autocomplete_controller()->Stop(false); 561 autocomplete_controller()->Stop(false);
562 562
563 user_text_ = user_input_in_progress_ ? view_->GetText() : base::string16();
563 user_input_in_progress_ = true; 564 user_input_in_progress_ = true;
Tom (Use chromium acct) 2016/10/20 20:34:54 Should this be SetInputInProgress(true)?
Peter Kasting 2016/10/20 21:42:00 Yes, I think so. You should consider using SetUse
564 keyword_ = client_->GetTemplateURLService()-> 565 keyword_ = client_->GetTemplateURLService()->
565 GetDefaultSearchProvider()->keyword(); 566 GetDefaultSearchProvider()->keyword();
566 is_keyword_hint_ = false; 567 is_keyword_hint_ = false;
567 keyword_mode_entry_method_ = entry_method; 568 keyword_mode_entry_method_ = entry_method;
568 569
569 StartAutocomplete(false, false); 570 StartAutocomplete(false, false);
570 571
571 UMA_HISTOGRAM_ENUMERATION( 572 UMA_HISTOGRAM_ENUMERATION(
572 kEnteredKeywordModeHistogram, static_cast<int>(entry_method), 573 kEnteredKeywordModeHistogram, static_cast<int>(entry_method),
573 static_cast<int>(KeywordModeEntryMethod::NUM_ITEMS)); 574 static_cast<int>(KeywordModeEntryMethod::NUM_ITEMS));
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 // Update state and notify view if the omnibox has focus and the caret 1432 // Update state and notify view if the omnibox has focus and the caret
1432 // visibility changed. 1433 // visibility changed.
1433 const bool was_caret_visible = is_caret_visible(); 1434 const bool was_caret_visible = is_caret_visible();
1434 focus_state_ = state; 1435 focus_state_ = state;
1435 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1436 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1436 is_caret_visible() != was_caret_visible) 1437 is_caret_visible() != was_caret_visible)
1437 view_->ApplyCaretVisibility(); 1438 view_->ApplyCaretVisibility();
1438 1439
1439 client_->OnFocusChanged(focus_state_, reason); 1440 client_->OnFocusChanged(focus_state_, reason);
1440 } 1441 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698