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

Unified Diff: components/omnibox/browser/omnibox_view.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: Factor out some code into OmniboxView and fix nits 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: components/omnibox/browser/omnibox_view.cc
diff --git a/components/omnibox/browser/omnibox_view.cc b/components/omnibox/browser/omnibox_view.cc
index cc88e37f71a508b48448853bc7f890915e5e3ddc..a50d7dd78117bebffbd6b4d5b6eaf1efa99b7add 100644
--- a/components/omnibox/browser/omnibox_view.cc
+++ b/components/omnibox/browser/omnibox_view.cc
@@ -166,6 +166,48 @@ bool OmniboxView::IsIndicatingQueryRefinement() const {
void OmniboxView::OnMatchOpened(AutocompleteMatch::Type match_type) {
}
+void OmniboxView::GetTextState(OmniboxView::TextState& state) {
+ state.text = GetText();
+ state.keyword = model()->keyword();
+ state.is_keyword_selected = model()->is_keyword_selected();
+ GetSelectionBounds(&state.sel_start, &state.sel_end);
+}
+
+OmniboxEditModel::TextStateChange OmniboxView::GetTextStateChange(
+ const TextState& before,
+ const TextState& after) {
+ OmniboxEditModel::TextStateChange state_change;
+ state_change.old_text = &before.text;
+ state_change.new_text = &after.text;
+ state_change.new_sel_start = after.sel_start;
+ state_change.new_sel_end = after.sel_end;
+ const bool old_sel_empty = before.sel_start == before.sel_end;
+ const bool new_sel_empty = after.sel_start == after.sel_end;
+ const bool sel_same_ignoring_direction =
+ std::min(before.sel_start, before.sel_end) ==
+ std::min(after.sel_start, after.sel_end) &&
+ std::max(before.sel_start, before.sel_end) ==
+ std::max(after.sel_start, after.sel_end);
+ state_change.selection_differs =
+ !((old_sel_empty && new_sel_empty) || sel_same_ignoring_direction);
Peter Kasting 2016/06/04 02:17:18 Nit: Distribute ! through
Tom (Use chromium acct) 2016/06/04 20:39:09 Done.
+ state_change.text_differs = before.text != after.text;
+ state_change.keyword_differs =
+ (after.is_keyword_selected != before.is_keyword_selected) ||
+ (after.is_keyword_selected && before.is_keyword_selected &&
+ after.keyword != before.keyword);
+
+ // When the user has deleted text, we don't allow inline autocomplete. Make
+ // sure to not flag cases like selecting part of the text and then pasting
+ // (or typing) the prefix of that selection. (We detect these by making
+ // sure the caret, which should be after any insertion, hasn't moved
+ // forward of the old selection start.)
+ state_change.just_deleted_text =
+ (before.text.length() > after.text.length()) &&
+ (before.sel_start <= std::min(before.sel_start, before.sel_end));
+
+ return state_change;
+}
+
OmniboxView::OmniboxView(OmniboxEditController* controller,
std::unique_ptr<OmniboxClient> client)
: controller_(controller) {

Powered by Google App Engine
This is Rietveld 408576698