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

Side by Side Diff: components/omnibox/browser/omnibox_view.h

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, 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 the interface class OmniboxView. Each toolkit will 5 // This file defines the interface class OmniboxView. Each toolkit will
6 // implement the edit view differently, so that code is inherently platform 6 // implement the edit view differently, so that code is inherently platform
7 // specific. However, the OmniboxEditModel needs to do some communication with 7 // specific. However, the OmniboxEditModel needs to do some communication with
8 // the view. Since the model is shared between platforms, we need to define an 8 // the view. Since the model is shared between platforms, we need to define an
9 // interface that all view implementations will share. 9 // interface that all view implementations will share.
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 virtual void SetUserText(const base::string16& text, 88 virtual void SetUserText(const base::string16& text,
89 bool update_popup); 89 bool update_popup);
90 90
91 // Sets the window text and the caret position. |notify_text_changed| is true 91 // Sets the window text and the caret position. |notify_text_changed| is true
92 // if the model should be notified of the change. 92 // if the model should be notified of the change.
93 virtual void SetWindowTextAndCaretPos(const base::string16& text, 93 virtual void SetWindowTextAndCaretPos(const base::string16& text,
94 size_t caret_pos, 94 size_t caret_pos,
95 bool update_popup, 95 bool update_popup,
96 bool notify_text_changed) = 0; 96 bool notify_text_changed) = 0;
97 97
98 // Sets the edit to forced query mode. Practically speaking, this means that 98 // Transitions the user into keyword mode with their default search provider,
99 // if the edit is not in forced query mode, its text is set to "?" with the 99 // preserving and selecting the user's text if they already typed in a query.
100 // cursor at the end, and if the edit is in forced query mode (its first 100 virtual void EnterKeywordModeForDefaultSearchProvider() = 0;
101 // non-whitespace character is '?'), the text after the '?' is selected.
102 //
103 // In the future we should display the search engine UI for the default engine
104 // rather than '?'.
105 virtual void SetForcedQuery() = 0;
106 101
107 // Returns true if all text is selected or there is no text at all. 102 // Returns true if all text is selected or there is no text at all.
108 virtual bool IsSelectAll() const = 0; 103 virtual bool IsSelectAll() const = 0;
109 104
110 // Returns true if the user deleted the suggested text. 105 // Returns true if the user deleted the suggested text.
111 virtual bool DeleteAtEndPressed() = 0; 106 virtual bool DeleteAtEndPressed() = 0;
112 107
113 // Fills |start| and |end| with the indexes of the current selection's bounds. 108 // Fills |start| and |end| with the indexes of the current selection's bounds.
114 // It is not guaranteed that |*start < *end|, as the selection can be 109 // It is not guaranteed that |*start < *end|, as the selection can be
115 // directed. If there is no selection, |start| and |end| will both be equal 110 // directed. If there is no selection, |start| and |end| will both be equal
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // First, calls StripJavascriptSchemas(). Then automatically collapses 227 // First, calls StripJavascriptSchemas(). Then automatically collapses
233 // internal whitespace as follows: 228 // internal whitespace as follows:
234 // * If the only whitespace in |text| is newlines, users are most likely 229 // * If the only whitespace in |text| is newlines, users are most likely
235 // pasting in URLs split into multiple lines by terminals, email programs, 230 // pasting in URLs split into multiple lines by terminals, email programs,
236 // etc. So all newlines are removed. 231 // etc. So all newlines are removed.
237 // * Otherwise, users may be pasting in search data, e.g. street addresses. In 232 // * Otherwise, users may be pasting in search data, e.g. street addresses. In
238 // this case, runs of whitespace are collapsed down to single spaces. 233 // this case, runs of whitespace are collapsed down to single spaces.
239 static base::string16 SanitizeTextForPaste(const base::string16& text); 234 static base::string16 SanitizeTextForPaste(const base::string16& text);
240 235
241 protected: 236 protected:
237 // This state is needed by |On[Before|After]PossibleChange|.
238 struct TextState {
Peter Kasting 2016/06/04 02:17:18 Nit: I would name and document this as follows:
Tom (Use chromium acct) 2016/06/04 20:39:09 Done.
239 base::string16 text;
240 base::string16 keyword;
241 bool is_keyword_selected;
242 size_t sel_start;
243 size_t sel_end;
244 };
245
242 OmniboxView(OmniboxEditController* controller, 246 OmniboxView(OmniboxEditController* controller,
243 std::unique_ptr<OmniboxClient> client); 247 std::unique_ptr<OmniboxClient> client);
244 248
249 // Fills |state| with the current text state.
250 void GetTextState(TextState& state);
Peter Kasting 2016/06/04 02:17:18 Nit: Arguments which the function modifies must be
Tom (Use chromium acct) 2016/06/04 20:39:09 Done.
251
252 // Returns the delta between |before| and |after|. The resulting
253 // |TextStateChange| is passed to |OmniboxEditModel::OnAfterPossibleChange|.
Peter Kasting 2016/06/04 02:17:18 Nit: No || on type names. Actually, assuming you
Tom (Use chromium acct) 2016/06/04 20:39:10 Done.
254 OmniboxEditModel::TextStateChange GetTextStateChange(const TextState& before,
255 const TextState& after);
256
245 // Internally invoked whenever the text changes in some way. 257 // Internally invoked whenever the text changes in some way.
246 virtual void TextChanged(); 258 virtual void TextChanged();
247 259
248 // Return the number of characters in the current buffer. The name 260 // Return the number of characters in the current buffer. The name
249 // |GetTextLength| can't be used as the Windows override of this class 261 // |GetTextLength| can't be used as the Windows override of this class
250 // inherits from a class that defines a method with that name. 262 // inherits from a class that defines a method with that name.
251 virtual int GetOmniboxTextLength() const = 0; 263 virtual int GetOmniboxTextLength() const = 0;
252 264
253 // Try to parse the current text as a URL and colorize the components. 265 // Try to parse the current text as a URL and colorize the components.
254 virtual void EmphasizeURLComponents() = 0; 266 virtual void EmphasizeURLComponents() = 0;
255 267
256 OmniboxEditController* controller() { return controller_; } 268 OmniboxEditController* controller() { return controller_; }
257 const OmniboxEditController* controller() const { return controller_; } 269 const OmniboxEditController* controller() const { return controller_; }
258 270
259 private: 271 private:
260 friend class OmniboxViewMacTest; 272 friend class OmniboxViewMacTest;
261 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ShowURL); 273 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ShowURL);
262 274
263 // |model_| can be NULL in tests. 275 // |model_| can be NULL in tests.
264 std::unique_ptr<OmniboxEditModel> model_; 276 std::unique_ptr<OmniboxEditModel> model_;
265 OmniboxEditController* controller_; 277 OmniboxEditController* controller_;
266 278
267 DISALLOW_COPY_AND_ASSIGN(OmniboxView); 279 DISALLOW_COPY_AND_ASSIGN(OmniboxView);
268 }; 280 };
269 281
270 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_ 282 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698