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

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: Really removed call to UpdatePopup Created 4 years, 6 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // TODO(oshima): IME support 272 // TODO(oshima): IME support
273 return text(); 273 return text();
274 } 274 }
275 275
276 void OmniboxViewViews::SetUserText(const base::string16& text, 276 void OmniboxViewViews::SetUserText(const base::string16& text,
277 bool update_popup) { 277 bool update_popup) {
278 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); 278 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
279 OmniboxView::SetUserText(text, update_popup); 279 OmniboxView::SetUserText(text, update_popup);
280 } 280 }
281 281
282 void OmniboxViewViews::SetForcedQuery() { 282 void OmniboxViewViews::EnterKeywordModeForDefaultSearchProvider() {
283 const base::string16 current_text(text()); 283 // Transition the user into keyword mode using their default search provider.
284 const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16); 284 // Select their query if they typed one.
285 if (start == base::string16::npos || (current_text[start] != '?')) 285 model()->EnterKeywordModeForDefaultSearchProvider(
286 OmniboxView::SetUserText(base::ASCIIToUTF16("?")); 286 KeywordModeEntryMethod::KEYBOARD_SHORTCUT);
287 else 287 SelectRange(gfx::Range(text().size(), 0));
288 SelectRange(gfx::Range(current_text.size(), start + 1));
289 } 288 }
290 289
291 void OmniboxViewViews::GetSelectionBounds( 290 void OmniboxViewViews::GetSelectionBounds(
292 base::string16::size_type* start, 291 base::string16::size_type* start,
293 base::string16::size_type* end) const { 292 base::string16::size_type* end) const {
294 const gfx::Range range = GetSelectedRange(); 293 const gfx::Range range = GetSelectedRange();
295 *start = static_cast<size_t>(range.start()); 294 *start = static_cast<size_t>(range.start());
296 *end = static_cast<size_t>(range.end()); 295 *end = static_cast<size_t>(range.end());
297 } 296 }
298 297
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 413 }
415 } 414 }
416 415
417 bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) { 416 bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
418 // This must run before accelerator handling invokes a focus change on tab. 417 // This must run before accelerator handling invokes a focus change on tab.
419 // Note the parallel with SkipDefaultKeyEventProcessing above. 418 // Note the parallel with SkipDefaultKeyEventProcessing above.
420 if (!views::FocusManager::IsTabTraversalKeyEvent(event)) 419 if (!views::FocusManager::IsTabTraversalKeyEvent(event))
421 return false; 420 return false;
422 421
423 if (model()->is_keyword_hint() && !event.IsShiftDown()) 422 if (model()->is_keyword_hint() && !event.IsShiftDown())
424 return model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB); 423 return model()->AcceptKeyword(KeywordModeEntryMethod::TAB);
425 424
426 if (!model()->popup_model()->IsOpen()) 425 if (!model()->popup_model()->IsOpen())
427 return false; 426 return false;
428 427
429 if (event.IsShiftDown() && 428 if (event.IsShiftDown() &&
430 (model()->popup_model()->selected_line_state() == 429 (model()->popup_model()->selected_line_state() ==
431 OmniboxPopupModel::KEYWORD)) 430 OmniboxPopupModel::KEYWORD))
432 model()->ClearKeyword(); 431 model()->ClearKeyword();
433 else 432 else
434 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); 433 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 SelectRange(saved_temporary_selection_); 519 SelectRange(saved_temporary_selection_);
521 // We got here because the user hit the Escape key. We explicitly don't call 520 // We got here because the user hit the Escape key. We explicitly don't call
522 // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already 521 // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already
523 // been called by now, and it would've called TextChanged() if it was 522 // been called by now, and it would've called TextChanged() if it was
524 // warranted. 523 // warranted.
525 } 524 }
526 525
527 void OmniboxViewViews::OnBeforePossibleChange() { 526 void OmniboxViewViews::OnBeforePossibleChange() {
528 // Record our state. 527 // Record our state.
529 text_before_change_ = text(); 528 text_before_change_ = text();
529 keyword_before_change_ = model()->keyword();
Peter Kasting 2016/06/01 01:07:27 This may be worth pulling out to a separate CL, bu
Tom (Use chromium acct) 2016/06/02 19:24:40 Did both. Here's to DRY Unfortunately it's on th
530 is_keyword_selected_before_change_ = model()->is_keyword_selected();
530 sel_before_change_ = GetSelectedRange(); 531 sel_before_change_ = GetSelectedRange();
531 ime_composing_before_change_ = IsIMEComposing(); 532 ime_composing_before_change_ = IsIMEComposing();
532 } 533 }
533 534
534 bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) { 535 bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) {
535 // See if the text or selection have changed since OnBeforePossibleChange(). 536 // See if the text or selection have changed since OnBeforePossibleChange().
536 const base::string16 new_text = text(); 537 const base::string16 new_text = text();
538 const base::string16 new_keyword = model()->keyword();
539 const bool new_is_keyword_selected = model()->is_keyword_selected();
537 const gfx::Range new_sel = GetSelectedRange(); 540 const gfx::Range new_sel = GetSelectedRange();
538 const bool text_changed = (new_text != text_before_change_) || 541 const bool text_changed = (new_text != text_before_change_) ||
539 (ime_composing_before_change_ != IsIMEComposing()); 542 (ime_composing_before_change_ != IsIMEComposing());
543 const bool keyword_changed =
544 (new_is_keyword_selected != is_keyword_selected_before_change_) ||
545 (new_is_keyword_selected && is_keyword_selected_before_change_ &&
546 new_keyword != keyword_before_change_);
540 const bool selection_differs = 547 const bool selection_differs =
541 !((sel_before_change_.is_empty() && new_sel.is_empty()) || 548 !((sel_before_change_.is_empty() && new_sel.is_empty()) ||
542 sel_before_change_.EqualsIgnoringDirection(new_sel)); 549 sel_before_change_.EqualsIgnoringDirection(new_sel));
543 550
544 // When the user has deleted text, we don't allow inline autocomplete. Make 551 // When the user has deleted text, we don't allow inline autocomplete. Make
545 // sure to not flag cases like selecting part of the text and then pasting 552 // sure to not flag cases like selecting part of the text and then pasting
546 // (or typing) the prefix of that selection. (We detect these by making 553 // (or typing) the prefix of that selection. (We detect these by making
547 // sure the caret, which should be after any insertion, hasn't moved 554 // sure the caret, which should be after any insertion, hasn't moved
548 // forward of the old selection start.) 555 // forward of the old selection start.)
549 const bool just_deleted_text = 556 const bool just_deleted_text =
550 (text_before_change_.length() > new_text.length()) && 557 (text_before_change_.length() > new_text.length()) &&
551 (new_sel.start() <= sel_before_change_.GetMin()); 558 (new_sel.start() <= sel_before_change_.GetMin());
552 559
553 const bool something_changed = model()->OnAfterPossibleChange( 560 const bool something_changed = model()->OnAfterPossibleChange(
554 text_before_change_, new_text, new_sel.start(), new_sel.end(), 561 text_before_change_, new_text, new_sel.start(), new_sel.end(),
555 selection_differs, text_changed, just_deleted_text, 562 selection_differs, text_changed, keyword_changed, just_deleted_text,
556 allow_keyword_ui_change && !IsIMEComposing()); 563 allow_keyword_ui_change && !IsIMEComposing());
557 564
558 // If only selection was changed, we don't need to call model()'s 565 // If only selection was changed, we don't need to call model()'s
559 // OnChanged() method, which is called in TextChanged(). 566 // OnChanged() method, which is called in TextChanged().
560 // But we still need to call EmphasizeURLComponents() to make sure the text 567 // But we still need to call EmphasizeURLComponents() to make sure the text
561 // attributes are updated correctly. 568 // attributes are updated correctly.
562 if (something_changed && text_changed) 569 if (something_changed && (text_changed || keyword_changed))
563 TextChanged(); 570 TextChanged();
564 else if (selection_differs) 571 else if (selection_differs)
565 EmphasizeURLComponents(); 572 EmphasizeURLComponents();
566 else if (delete_at_end_pressed_) 573 else if (delete_at_end_pressed_)
567 model()->OnChanged(); 574 model()->OnChanged();
568 575
569 return something_changed; 576 return something_changed;
570 } 577 }
571 578
572 gfx::NativeView OmniboxViewViews::GetNativeView() const { 579 gfx::NativeView OmniboxViewViews::GetNativeView() const {
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 menu_contents->InsertItemWithStringIdAt( 1090 menu_contents->InsertItemWithStringIdAt(
1084 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); 1091 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL);
1085 } 1092 }
1086 1093
1087 // Minor note: We use IDC_ for command id here while the underlying textfield 1094 // Minor note: We use IDC_ for command id here while the underlying textfield
1088 // is using IDS_ for all its command ids. This is because views cannot depend 1095 // is using IDS_ for all its command ids. This is because views cannot depend
1089 // on IDC_ for now. 1096 // on IDC_ for now.
1090 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1097 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1091 IDS_EDIT_SEARCH_ENGINES); 1098 IDS_EDIT_SEARCH_ENGINES);
1092 } 1099 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698