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

Side by Side 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: Add includes for mac tests 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 // This file defines helper functions shared by the various implementations 5 // This file defines helper functions shared by the various implementations
6 // of OmniboxView. 6 // of OmniboxView.
7 7
8 #include "components/omnibox/browser/omnibox_view.h" 8 #include "components/omnibox/browser/omnibox_view.h"
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "components/omnibox/browser/autocomplete_match.h" 16 #include "components/omnibox/browser/autocomplete_match.h"
17 #include "components/omnibox/browser/omnibox_client.h" 17 #include "components/omnibox/browser/omnibox_client.h"
18 #include "components/omnibox/browser/omnibox_edit_controller.h" 18 #include "components/omnibox/browser/omnibox_edit_controller.h"
19 #include "components/omnibox/browser/omnibox_edit_model.h"
19 #include "components/toolbar/toolbar_model.h" 20 #include "components/toolbar/toolbar_model.h"
20 #include "grit/components_scaled_resources.h" 21 #include "grit/components_scaled_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/gfx/vector_icons_public.h" 23 #include "ui/gfx/vector_icons_public.h"
23 24
24 // static 25 // static
25 base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) { 26 base::string16 OmniboxView::StripJavascriptSchemas(const base::string16& text) {
26 const base::string16 kJsPrefix( 27 const base::string16 kJsPrefix(
27 base::ASCIIToUTF16(url::kJavaScriptScheme) + base::ASCIIToUTF16(":")); 28 base::ASCIIToUTF16(url::kJavaScriptScheme) + base::ASCIIToUTF16(":"));
28 base::string16 out(text); 29 base::string16 out(text);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 160
160 bool OmniboxView::IsIndicatingQueryRefinement() const { 161 bool OmniboxView::IsIndicatingQueryRefinement() const {
161 // The default implementation always returns false. Mobile ports can override 162 // The default implementation always returns false. Mobile ports can override
162 // this method and implement as needed. 163 // this method and implement as needed.
163 return false; 164 return false;
164 } 165 }
165 166
166 void OmniboxView::OnMatchOpened(AutocompleteMatch::Type match_type) { 167 void OmniboxView::OnMatchOpened(AutocompleteMatch::Type match_type) {
167 } 168 }
168 169
170 void OmniboxView::GetState(State* state) {
171 state->text = GetText();
172 state->keyword = model()->keyword();
173 state->is_keyword_selected = model()->is_keyword_selected();
174 GetSelectionBounds(&state->sel_start, &state->sel_end);
175 }
176
177 OmniboxView::StateChanges OmniboxView::GetStateChanges(const State& before,
178 const State& after) {
179 OmniboxView::StateChanges state_changes;
180 state_changes.old_text = &before.text;
181 state_changes.new_text = &after.text;
182 state_changes.new_sel_start = after.sel_start;
183 state_changes.new_sel_end = after.sel_end;
184 const bool old_sel_empty = before.sel_start == before.sel_end;
185 const bool new_sel_empty = after.sel_start == after.sel_end;
186 const bool sel_same_ignoring_direction =
187 std::min(before.sel_start, before.sel_end) ==
188 std::min(after.sel_start, after.sel_end) &&
189 std::max(before.sel_start, before.sel_end) ==
190 std::max(after.sel_start, after.sel_end);
191 state_changes.selection_differs =
192 (!old_sel_empty || !new_sel_empty) && !sel_same_ignoring_direction;
193 state_changes.text_differs = before.text != after.text;
194 state_changes.keyword_differs =
195 (after.is_keyword_selected != before.is_keyword_selected) ||
196 (after.is_keyword_selected && before.is_keyword_selected &&
197 after.keyword != before.keyword);
198
199 // When the user has deleted text, we don't allow inline autocomplete. Make
200 // sure to not flag cases like selecting part of the text and then pasting
201 // (or typing) the prefix of that selection. (We detect these by making
202 // sure the caret, which should be after any insertion, hasn't moved
203 // forward of the old selection start.)
204 state_changes.just_deleted_text =
205 (before.text.length() > after.text.length()) &&
206 (after.sel_start <= std::min(before.sel_start, before.sel_end));
207
208 return state_changes;
209 }
210
169 OmniboxView::OmniboxView(OmniboxEditController* controller, 211 OmniboxView::OmniboxView(OmniboxEditController* controller,
170 std::unique_ptr<OmniboxClient> client) 212 std::unique_ptr<OmniboxClient> client)
171 : controller_(controller) { 213 : controller_(controller) {
172 // |client| can be null in tests. 214 // |client| can be null in tests.
173 if (client) { 215 if (client) {
174 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); 216 model_.reset(new OmniboxEditModel(this, controller, std::move(client)));
175 } 217 }
176 } 218 }
177 219
178 void OmniboxView::TextChanged() { 220 void OmniboxView::TextChanged() {
179 EmphasizeURLComponents(); 221 EmphasizeURLComponents();
180 if (model_.get()) 222 if (model_.get())
181 model_->OnChanged(); 223 model_->OnChanged();
182 } 224 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/omnibox_view.h ('k') | components/omnibox/browser/search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698