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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 8852dfe48c57321a8a6cbf13ad68624259255622..bae2143f14691b5bbfe6757ad76d205d67f2de8b 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -279,13 +279,12 @@ void OmniboxViewViews::SetUserText(const base::string16& text,
OmniboxView::SetUserText(text, update_popup);
}
-void OmniboxViewViews::SetForcedQuery() {
- const base::string16 current_text(text());
- const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16);
- if (start == base::string16::npos || (current_text[start] != '?'))
- OmniboxView::SetUserText(base::ASCIIToUTF16("?"));
- else
- SelectRange(gfx::Range(current_text.size(), start + 1));
+void OmniboxViewViews::EnterKeywordModeForDefaultSearchProvider() {
+ // Transition the user into keyword mode using their default search provider.
+ // Select their query if they typed one.
+ model()->EnterKeywordModeForDefaultSearchProvider(
+ KeywordModeEntryMethod::KEYBOARD_SHORTCUT);
+ SelectRange(gfx::Range(text().size(), 0));
}
void OmniboxViewViews::GetSelectionBounds(
@@ -421,7 +420,7 @@ bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
return false;
if (model()->is_keyword_hint() && !event.IsShiftDown())
- return model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB);
+ return model()->AcceptKeyword(KeywordModeEntryMethod::TAB);
if (!model()->popup_model()->IsOpen())
return false;
@@ -527,6 +526,8 @@ void OmniboxViewViews::OnRevertTemporaryText() {
void OmniboxViewViews::OnBeforePossibleChange() {
// Record our state.
text_before_change_ = text();
+ 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
+ is_keyword_selected_before_change_ = model()->is_keyword_selected();
sel_before_change_ = GetSelectedRange();
ime_composing_before_change_ = IsIMEComposing();
}
@@ -534,9 +535,15 @@ void OmniboxViewViews::OnBeforePossibleChange() {
bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) {
// See if the text or selection have changed since OnBeforePossibleChange().
const base::string16 new_text = text();
+ const base::string16 new_keyword = model()->keyword();
+ const bool new_is_keyword_selected = model()->is_keyword_selected();
const gfx::Range new_sel = GetSelectedRange();
const bool text_changed = (new_text != text_before_change_) ||
(ime_composing_before_change_ != IsIMEComposing());
+ const bool keyword_changed =
+ (new_is_keyword_selected != is_keyword_selected_before_change_) ||
+ (new_is_keyword_selected && is_keyword_selected_before_change_ &&
+ new_keyword != keyword_before_change_);
const bool selection_differs =
!((sel_before_change_.is_empty() && new_sel.is_empty()) ||
sel_before_change_.EqualsIgnoringDirection(new_sel));
@@ -552,14 +559,14 @@ bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) {
const bool something_changed = model()->OnAfterPossibleChange(
text_before_change_, new_text, new_sel.start(), new_sel.end(),
- selection_differs, text_changed, just_deleted_text,
+ selection_differs, text_changed, keyword_changed, just_deleted_text,
allow_keyword_ui_change && !IsIMEComposing());
// If only selection was changed, we don't need to call model()'s
// OnChanged() method, which is called in TextChanged().
// But we still need to call EmphasizeURLComponents() to make sure the text
// attributes are updated correctly.
- if (something_changed && text_changed)
+ if (something_changed && (text_changed || keyword_changed))
TextChanged();
else if (selection_differs)
EmphasizeURLComponents();

Powered by Google App Engine
This is Rietveld 408576698