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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 1855423003: Interpret '?' and Ctrl-K or Ctrl-E as putting omnibox in keyword search mode for Default Search Pro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted autocomplete_text_field* Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 void OmniboxViewViews::SetUserText(const base::string16& text, 272 void OmniboxViewViews::SetUserText(const base::string16& text,
273 const base::string16& display_text, 273 const base::string16& display_text,
274 bool update_popup) { 274 bool update_popup) {
275 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); 275 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
276 OmniboxView::SetUserText(text, display_text, update_popup); 276 OmniboxView::SetUserText(text, display_text, update_popup);
277 } 277 }
278 278
279 void OmniboxViewViews::SetForcedQuery() { 279 void OmniboxViewViews::SetForcedQuery() {
280 const base::string16 current_text(text()); 280 // If the user is already in keyword mode (for any search platform, not just
281 const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16); 281 // their default one), highlight their search only. If the user is not in
282 if (start == base::string16::npos || (current_text[start] != '?')) 282 // keyword mode, keep what they've typed and transition them into keyword mode
283 OmniboxView::SetUserText(base::ASCIIToUTF16("?")); 283 // using their default search platform.
Peter Kasting 2016/04/08 00:39:56 Nit: platform -> provider
Tom (Use chromium acct) 2016/04/12 20:03:05 Done.
284 if (model()->is_keyword_selected())
285 SelectRange(gfx::Range(text().size(), 0));
284 else 286 else
285 SelectRange(gfx::Range(current_text.size(), start + 1)); 287 model()->SetKeywordWithDefaultSearchProvider(
288 ENTERED_KEYWORD_MODE_VIA_KEYBOARD_SHORTCUT);
286 } 289 }
287 290
288 void OmniboxViewViews::GetSelectionBounds( 291 void OmniboxViewViews::GetSelectionBounds(
289 base::string16::size_type* start, 292 base::string16::size_type* start,
290 base::string16::size_type* end) const { 293 base::string16::size_type* end) const {
291 const gfx::Range range = GetSelectedRange(); 294 const gfx::Range range = GetSelectedRange();
292 *start = static_cast<size_t>(range.start()); 295 *start = static_cast<size_t>(range.start());
293 *end = static_cast<size_t>(range.end()); 296 *end = static_cast<size_t>(range.end());
294 } 297 }
295 298
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 SelectRange(saved_temporary_selection_); 520 SelectRange(saved_temporary_selection_);
518 // We got here because the user hit the Escape key. We explicitly don't call 521 // We got here because the user hit the Escape key. We explicitly don't call
519 // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already 522 // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already
520 // been called by now, and it would've called TextChanged() if it was 523 // been called by now, and it would've called TextChanged() if it was
521 // warranted. 524 // warranted.
522 } 525 }
523 526
524 void OmniboxViewViews::OnBeforePossibleChange() { 527 void OmniboxViewViews::OnBeforePossibleChange() {
525 // Record our state. 528 // Record our state.
526 text_before_change_ = text(); 529 text_before_change_ = text();
530 keyword_before_change_ = model()->keyword();
531 is_keyword_selected_before_change_ = model()->is_keyword_selected();
527 sel_before_change_ = GetSelectedRange(); 532 sel_before_change_ = GetSelectedRange();
528 ime_composing_before_change_ = IsIMEComposing(); 533 ime_composing_before_change_ = IsIMEComposing();
529 } 534 }
530 535
531 bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) { 536 bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) {
532 // See if the text or selection have changed since OnBeforePossibleChange(). 537 // See if the text or selection have changed since OnBeforePossibleChange().
533 const base::string16 new_text = text(); 538 const base::string16 new_text = text();
539 const base::string16 new_keyword = model()->keyword();
540 const bool new_is_keyword_selected = model()->is_keyword_selected();
534 const gfx::Range new_sel = GetSelectedRange(); 541 const gfx::Range new_sel = GetSelectedRange();
535 const bool text_changed = (new_text != text_before_change_) || 542 const bool text_changed = (new_text != text_before_change_) ||
536 (ime_composing_before_change_ != IsIMEComposing()); 543 (ime_composing_before_change_ != IsIMEComposing());
544 const bool keyword_changed =
545 (new_is_keyword_selected != is_keyword_selected_before_change_) ||
546 (new_is_keyword_selected && is_keyword_selected_before_change_ &&
547 new_keyword != keyword_before_change_);
537 const bool selection_differs = 548 const bool selection_differs =
538 !((sel_before_change_.is_empty() && new_sel.is_empty()) || 549 !((sel_before_change_.is_empty() && new_sel.is_empty()) ||
539 sel_before_change_.EqualsIgnoringDirection(new_sel)); 550 sel_before_change_.EqualsIgnoringDirection(new_sel));
540 551
541 // When the user has deleted text, we don't allow inline autocomplete. Make 552 // When the user has deleted text, we don't allow inline autocomplete. Make
542 // sure to not flag cases like selecting part of the text and then pasting 553 // sure to not flag cases like selecting part of the text and then pasting
543 // (or typing) the prefix of that selection. (We detect these by making 554 // (or typing) the prefix of that selection. (We detect these by making
544 // sure the caret, which should be after any insertion, hasn't moved 555 // sure the caret, which should be after any insertion, hasn't moved
545 // forward of the old selection start.) 556 // forward of the old selection start.)
546 const bool just_deleted_text = 557 const bool just_deleted_text =
547 (text_before_change_.length() > new_text.length()) && 558 (text_before_change_.length() > new_text.length()) &&
548 (new_sel.start() <= sel_before_change_.GetMin()); 559 (new_sel.start() <= sel_before_change_.GetMin());
549 560
550 const bool something_changed = model()->OnAfterPossibleChange( 561 const bool something_changed = model()->OnAfterPossibleChange(
551 text_before_change_, new_text, new_sel.start(), new_sel.end(), 562 text_before_change_, new_text, new_sel.start(), new_sel.end(),
552 selection_differs, text_changed, just_deleted_text, 563 selection_differs, text_changed, keyword_changed, just_deleted_text,
553 allow_keyword_ui_change && !IsIMEComposing()); 564 allow_keyword_ui_change && !IsIMEComposing());
554 565
555 // If only selection was changed, we don't need to call model()'s 566 // If only selection was changed, we don't need to call model()'s
556 // OnChanged() method, which is called in TextChanged(). 567 // OnChanged() method, which is called in TextChanged().
557 // But we still need to call EmphasizeURLComponents() to make sure the text 568 // But we still need to call EmphasizeURLComponents() to make sure the text
558 // attributes are updated correctly. 569 // attributes are updated correctly.
559 if (something_changed && text_changed) 570 if (something_changed && (text_changed || keyword_changed))
560 TextChanged(); 571 TextChanged();
561 else if (selection_differs) 572 else if (selection_differs)
562 EmphasizeURLComponents(); 573 EmphasizeURLComponents();
563 else if (delete_at_end_pressed_) 574 else if (delete_at_end_pressed_)
564 model()->OnChanged(); 575 model()->OnChanged();
565 576
566 return something_changed; 577 return something_changed;
567 } 578 }
568 579
569 gfx::NativeView OmniboxViewViews::GetNativeView() const { 580 gfx::NativeView OmniboxViewViews::GetNativeView() const {
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 menu_contents->InsertItemWithStringIdAt( 1085 menu_contents->InsertItemWithStringIdAt(
1075 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); 1086 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL);
1076 } 1087 }
1077 1088
1078 // Minor note: We use IDC_ for command id here while the underlying textfield 1089 // Minor note: We use IDC_ for command id here while the underlying textfield
1079 // is using IDS_ for all its command ids. This is because views cannot depend 1090 // is using IDS_ for all its command ids. This is because views cannot depend
1080 // on IDC_ for now. 1091 // on IDC_ for now.
1081 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1092 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1082 IDS_EDIT_SEARCH_ENGINES); 1093 IDS_EDIT_SEARCH_ENGINES);
1083 } 1094 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698