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

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: 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 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
11 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_ 11 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_
12 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_ 12 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 15
16 #include <string> 16 #include <string>
17 17
18 #include "base/gtest_prod_util.h" 18 #include "base/gtest_prod_util.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "components/omnibox/browser/autocomplete_match.h" 23 #include "components/omnibox/browser/autocomplete_match.h"
24 #include "components/omnibox/browser/omnibox_edit_model.h"
25 #include "ui/base/window_open_disposition.h" 24 #include "ui/base/window_open_disposition.h"
26 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
27 26
28 class GURL; 27 class GURL;
29 class OmniboxClient; 28 class OmniboxClient;
30 class OmniboxEditController; 29 class OmniboxEditController;
31 class OmniboxViewMacTest; 30 class OmniboxViewMacTest;
32 class ToolbarModel; 31 class ToolbarModel;
32 class OmniboxEditModel;
33 33
34 namespace gfx { 34 namespace gfx {
35 enum class VectorIconId; 35 enum class VectorIconId;
36 } 36 }
37 37
38 class OmniboxView { 38 class OmniboxView {
39 public: 39 public:
40 // Represents the changes between two State objects. This is used by the
41 // model to determine how its internal state should be updated after the view
42 // state changes. See OmniboxEditModel::OnAfterPossibleChange().
43 struct StateChanges {
44 // |old_text| and |new_text| are not owned.
45 const base::string16* old_text;
46 const base::string16* new_text;
47 size_t new_sel_start;
48 size_t new_sel_end;
49 bool selection_differs;
50 bool text_differs;
51 bool keyword_differs;
52 bool just_deleted_text;
53 };
54
40 virtual ~OmniboxView(); 55 virtual ~OmniboxView();
41 56
42 // Used by the automation system for getting at the model from the view. 57 // Used by the automation system for getting at the model from the view.
43 OmniboxEditModel* model() { return model_.get(); } 58 OmniboxEditModel* model() { return model_.get(); }
44 const OmniboxEditModel* model() const { return model_.get(); } 59 const OmniboxEditModel* model() const { return model_.get(); }
45 60
46 // Shared cross-platform focus handling. 61 // Shared cross-platform focus handling.
47 void OnDidKillFocus(); 62 void OnDidKillFocus();
48 63
49 // Called when any relevant state changes other than changing tabs. 64 // Called when any relevant state changes other than changing tabs.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 virtual void SetUserText(const base::string16& text, 103 virtual void SetUserText(const base::string16& text,
89 bool update_popup); 104 bool update_popup);
90 105
91 // Sets the window text and the caret position. |notify_text_changed| is true 106 // Sets the window text and the caret position. |notify_text_changed| is true
92 // if the model should be notified of the change. 107 // if the model should be notified of the change.
93 virtual void SetWindowTextAndCaretPos(const base::string16& text, 108 virtual void SetWindowTextAndCaretPos(const base::string16& text,
94 size_t caret_pos, 109 size_t caret_pos,
95 bool update_popup, 110 bool update_popup,
96 bool notify_text_changed) = 0; 111 bool notify_text_changed) = 0;
97 112
98 // Sets the edit to forced query mode. Practically speaking, this means that 113 // 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 114 // 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 115 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 116
107 // Returns true if all text is selected or there is no text at all. 117 // Returns true if all text is selected or there is no text at all.
108 virtual bool IsSelectAll() const = 0; 118 virtual bool IsSelectAll() const = 0;
109 119
110 // Returns true if the user deleted the suggested text. 120 // Returns true if the user deleted the suggested text.
111 virtual bool DeleteAtEndPressed() = 0; 121 virtual bool DeleteAtEndPressed() = 0;
112 122
113 // Fills |start| and |end| with the indexes of the current selection's bounds. 123 // 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 124 // 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 125 // 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 242 // First, calls StripJavascriptSchemas(). Then automatically collapses
233 // internal whitespace as follows: 243 // internal whitespace as follows:
234 // * If the only whitespace in |text| is newlines, users are most likely 244 // * If the only whitespace in |text| is newlines, users are most likely
235 // pasting in URLs split into multiple lines by terminals, email programs, 245 // pasting in URLs split into multiple lines by terminals, email programs,
236 // etc. So all newlines are removed. 246 // etc. So all newlines are removed.
237 // * Otherwise, users may be pasting in search data, e.g. street addresses. In 247 // * 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. 248 // this case, runs of whitespace are collapsed down to single spaces.
239 static base::string16 SanitizeTextForPaste(const base::string16& text); 249 static base::string16 SanitizeTextForPaste(const base::string16& text);
240 250
241 protected: 251 protected:
252 // Tracks important state that may change between OnBeforePossibleChange() and
253 // OnAfterPossibleChange().
254 struct State {
255 base::string16 text;
256 base::string16 keyword;
257 bool is_keyword_selected;
258 size_t sel_start;
259 size_t sel_end;
260 };
261
242 OmniboxView(OmniboxEditController* controller, 262 OmniboxView(OmniboxEditController* controller,
243 std::unique_ptr<OmniboxClient> client); 263 std::unique_ptr<OmniboxClient> client);
244 264
265 // Fills |state| with the current text state.
266 void GetState(State* state);
267
268 // Returns the delta between |before| and |after|.
269 StateChanges GetStateChanges(const State& before,
270 const State& after);
271
245 // Internally invoked whenever the text changes in some way. 272 // Internally invoked whenever the text changes in some way.
246 virtual void TextChanged(); 273 virtual void TextChanged();
247 274
248 // Return the number of characters in the current buffer. The name 275 // Return the number of characters in the current buffer. The name
249 // |GetTextLength| can't be used as the Windows override of this class 276 // |GetTextLength| can't be used as the Windows override of this class
250 // inherits from a class that defines a method with that name. 277 // inherits from a class that defines a method with that name.
251 virtual int GetOmniboxTextLength() const = 0; 278 virtual int GetOmniboxTextLength() const = 0;
252 279
253 // Try to parse the current text as a URL and colorize the components. 280 // Try to parse the current text as a URL and colorize the components.
254 virtual void EmphasizeURLComponents() = 0; 281 virtual void EmphasizeURLComponents() = 0;
255 282
256 OmniboxEditController* controller() { return controller_; } 283 OmniboxEditController* controller() { return controller_; }
257 const OmniboxEditController* controller() const { return controller_; } 284 const OmniboxEditController* controller() const { return controller_; }
258 285
259 private: 286 private:
260 friend class OmniboxViewMacTest; 287 friend class OmniboxViewMacTest;
261 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ShowURL); 288 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ShowURL);
262 289
263 // |model_| can be NULL in tests. 290 // |model_| can be NULL in tests.
264 std::unique_ptr<OmniboxEditModel> model_; 291 std::unique_ptr<OmniboxEditModel> model_;
265 OmniboxEditController* controller_; 292 OmniboxEditController* controller_;
266 293
267 DISALLOW_COPY_AND_ASSIGN(OmniboxView); 294 DISALLOW_COPY_AND_ASSIGN(OmniboxView);
268 }; 295 };
269 296
270 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_ 297 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_
OLDNEW
« no previous file with comments | « components/omnibox/browser/omnibox_edit_unittest.cc ('k') | components/omnibox/browser/omnibox_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698