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

Side by Side Diff: components/omnibox/browser/omnibox_edit_model.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_
6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ 6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/metrics/proto/omnibox_event.pb.h" 16 #include "components/metrics/proto/omnibox_event.pb.h"
17 #include "components/omnibox/browser/autocomplete_controller_delegate.h" 17 #include "components/omnibox/browser/autocomplete_controller_delegate.h"
18 #include "components/omnibox/browser/autocomplete_input.h" 18 #include "components/omnibox/browser/autocomplete_input.h"
19 #include "components/omnibox/browser/autocomplete_match.h" 19 #include "components/omnibox/browser/autocomplete_match.h"
20 #include "components/omnibox/browser/omnibox_controller.h" 20 #include "components/omnibox/browser/omnibox_controller.h"
21 #include "components/omnibox/browser/omnibox_view.h"
21 #include "components/omnibox/common/omnibox_focus_state.h" 22 #include "components/omnibox/common/omnibox_focus_state.h"
22 #include "ui/base/window_open_disposition.h" 23 #include "ui/base/window_open_disposition.h"
23 #include "ui/gfx/native_widget_types.h" 24 #include "ui/gfx/native_widget_types.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 class AutocompleteController; 27 class AutocompleteController;
27 class AutocompleteResult; 28 class AutocompleteResult;
28 class OmniboxClient; 29 class OmniboxClient;
29 class OmniboxEditController; 30 class OmniboxEditController;
30 class OmniboxPopupModel; 31 class OmniboxPopupModel;
31 class OmniboxView; 32 class OmniboxView;
32 33
33 namespace gfx { 34 namespace gfx {
34 class Image; 35 class Image;
35 class Rect; 36 class Rect;
36 } 37 }
37 38
38 // Reasons why the Omnibox could change into keyword mode. 39 // Reasons why the Omnibox could change into keyword mode.
39 // These numeric values are used in UMA logs; do not change them. 40 // These numeric values are used in UMA logs; do not change them.
40 enum EnteredKeywordModeMethod { 41 enum class KeywordModeEntryMethod {
41 ENTERED_KEYWORD_MODE_VIA_TAB = 0, 42 TAB = 0,
42 ENTERED_KEYWORD_MODE_VIA_SPACE_AT_END = 1, 43 SPACE_AT_END = 1,
43 ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE = 2, 44 SPACE_IN_MIDDLE = 2,
44 ENTERED_KEYWORD_MODE_NUM_ITEMS 45 KEYBOARD_SHORTCUT = 3,
46 QUESTION_MARK = 4,
47 NUM_ITEMS,
45 }; 48 };
46 49
47 class OmniboxEditModel { 50 class OmniboxEditModel {
48 public: 51 public:
49 // Did the Omnibox focus originate via the user clicking on the Omnibox or on 52 // Did the Omnibox focus originate via the user clicking on the Omnibox or on
50 // the Fakebox? 53 // the Fakebox?
51 enum FocusSource { 54 enum FocusSource {
52 INVALID = 0, 55 INVALID = 0,
53 OMNIBOX = 1, 56 OMNIBOX = 1,
54 FAKEBOX = 2 57 FAKEBOX = 2
55 }; 58 };
56 59
57 struct State { 60 struct State {
58 State(bool user_input_in_progress, 61 State(bool user_input_in_progress,
59 const base::string16& user_text, 62 const base::string16& user_text,
60 const base::string16& gray_text, 63 const base::string16& gray_text,
61 const base::string16& keyword, 64 const base::string16& keyword,
62 bool is_keyword_hint, 65 bool is_keyword_hint,
66 KeywordModeEntryMethod keyword_mode_entry_method,
63 bool url_replacement_enabled, 67 bool url_replacement_enabled,
64 OmniboxFocusState focus_state, 68 OmniboxFocusState focus_state,
65 FocusSource focus_source, 69 FocusSource focus_source,
66 const AutocompleteInput& autocomplete_input); 70 const AutocompleteInput& autocomplete_input);
67 State(const State& other); 71 State(const State& other);
68 ~State(); 72 ~State();
69 73
70 bool user_input_in_progress; 74 bool user_input_in_progress;
71 const base::string16 user_text; 75 const base::string16 user_text;
72 const base::string16 gray_text; 76 const base::string16 gray_text;
73 const base::string16 keyword; 77 const base::string16 keyword;
74 const bool is_keyword_hint; 78 const bool is_keyword_hint;
79 KeywordModeEntryMethod keyword_mode_entry_method;
75 bool url_replacement_enabled; 80 bool url_replacement_enabled;
76 OmniboxFocusState focus_state; 81 OmniboxFocusState focus_state;
77 FocusSource focus_source; 82 FocusSource focus_source;
78 const AutocompleteInput autocomplete_input; 83 const AutocompleteInput autocomplete_input;
79 }; 84 };
80 85
81 OmniboxEditModel(OmniboxView* view, 86 OmniboxEditModel(OmniboxView* view,
82 OmniboxEditController* controller, 87 OmniboxEditController* controller,
83 std::unique_ptr<OmniboxClient> client); 88 std::unique_ptr<OmniboxClient> client);
84 virtual ~OmniboxEditModel(); 89 virtual ~OmniboxEditModel();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 235
231 // Accessors for keyword-related state (see comments on keyword_ and 236 // Accessors for keyword-related state (see comments on keyword_ and
232 // is_keyword_hint_). 237 // is_keyword_hint_).
233 const base::string16& keyword() const { return keyword_; } 238 const base::string16& keyword() const { return keyword_; }
234 bool is_keyword_hint() const { return is_keyword_hint_; } 239 bool is_keyword_hint() const { return is_keyword_hint_; }
235 bool is_keyword_selected() const { 240 bool is_keyword_selected() const {
236 return !is_keyword_hint_ && !keyword_.empty(); 241 return !is_keyword_hint_ && !keyword_.empty();
237 } 242 }
238 243
239 // Accepts the current keyword hint as a keyword. It always returns true for 244 // Accepts the current keyword hint as a keyword. It always returns true for
240 // caller convenience. |entered_method| indicates how the use entered 245 // caller convenience. |entered_method| indicates how the user entered
241 // keyword mode. This parameter is only used for metrics/logging; it's not 246 // keyword mode.
242 // used to change user-visible behavior. 247 bool AcceptKeyword(KeywordModeEntryMethod entry_method);
243 bool AcceptKeyword(EnteredKeywordModeMethod entered_method); 248
249 // Sets the current keyword to that of the user's default search provider and
250 // updates the view so the user sees the keyword chip in the omnibox.
251 void EnterKeywordModeForDefaultSearchProvider(
252 KeywordModeEntryMethod entry_method);
244 253
245 // Accepts the current temporary text as the user text. 254 // Accepts the current temporary text as the user text.
246 void AcceptTemporaryTextAsUserText(); 255 void AcceptTemporaryTextAsUserText();
247 256
248 // Clears the current keyword. 257 // Clears the current keyword.
249 void ClearKeyword(); 258 void ClearKeyword();
250 259
251 // Returns the current autocomplete result. This logic should in the future 260 // Returns the current autocomplete result. This logic should in the future
252 // live in AutocompleteController but resides here for now. This method is 261 // live in AutocompleteController but resides here for now. This method is
253 // used by AutomationProvider::AutocompleteEditGetMatches. 262 // used by AutomationProvider::AutocompleteEditGetMatches.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // comments on keyword_ and is_keyword_hint_). 326 // comments on keyword_ and is_keyword_hint_).
318 void OnPopupDataChanged( 327 void OnPopupDataChanged(
319 const base::string16& text, 328 const base::string16& text,
320 GURL* destination_for_temporary_text_change, 329 GURL* destination_for_temporary_text_change,
321 const base::string16& keyword, 330 const base::string16& keyword,
322 bool is_keyword_hint); 331 bool is_keyword_hint);
323 332
324 // Called by the OmniboxView after something changes, with details about what 333 // Called by the OmniboxView after something changes, with details about what
325 // state changes occured. Updates internal state, updates the popup if 334 // state changes occured. Updates internal state, updates the popup if
326 // necessary, and returns true if any significant changes occurred. Note that 335 // necessary, and returns true if any significant changes occurred. Note that
327 // |text_differs| may be set even if |old_text| == |new_text|, e.g. if we've 336 // |text_change.text_differs| may be set even if |text_change.old_text| ==
328 // just committed an IME composition. 337 // |text_change.new_text|, e.g. if we've just committed an IME composition.
329 // 338 //
330 // If |allow_keyword_ui_change| is false then the change should not affect 339 // If |allow_keyword_ui_change| is false then the change should not affect
331 // keyword ui state, even if the text matches a keyword exactly. This value 340 // keyword ui state, even if the text matches a keyword exactly. This value
332 // may be false when the user is composing a text with an IME. 341 // may be false when the user is composing a text with an IME.
333 bool OnAfterPossibleChange(const base::string16& old_text, 342 bool OnAfterPossibleChange(const OmniboxView::StateChanges& state_changes,
334 const base::string16& new_text,
335 size_t selection_start,
336 size_t selection_end,
337 bool selection_differs,
338 bool text_differs,
339 bool just_deleted_text,
340 bool allow_keyword_ui_change); 343 bool allow_keyword_ui_change);
341 344
342 // Called when the current match has changed in the OmniboxController. 345 // Called when the current match has changed in the OmniboxController.
343 void OnCurrentMatchChanged(); 346 void OnCurrentMatchChanged();
344 347
345 // Name of the histogram tracking cut or copy omnibox commands. 348 // Name of the histogram tracking cut or copy omnibox commands.
346 static const char kCutOrCopyAllTextHistogram[]; 349 static const char kCutOrCopyAllTextHistogram[];
347 350
348 private: 351 private:
349 friend class OmniboxControllerTest; 352 friend class OmniboxControllerTest;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 // selected keyword, or just some input text that looks like a keyword (so we 543 // selected keyword, or just some input text that looks like a keyword (so we
541 // can show a hint to press <tab>). This is the keyword in either case; 544 // can show a hint to press <tab>). This is the keyword in either case;
542 // is_keyword_hint_ (below) distinguishes the two cases. 545 // is_keyword_hint_ (below) distinguishes the two cases.
543 base::string16 keyword_; 546 base::string16 keyword_;
544 547
545 // True if the keyword associated with this match is merely a hint, i.e. the 548 // True if the keyword associated with this match is merely a hint, i.e. the
546 // user hasn't actually selected a keyword yet. When this is true, we can use 549 // user hasn't actually selected a keyword yet. When this is true, we can use
547 // keyword_ to show a "Press <tab> to search" sort of hint. 550 // keyword_ to show a "Press <tab> to search" sort of hint.
548 bool is_keyword_hint_; 551 bool is_keyword_hint_;
549 552
553 // Indicates how the user entered keyword mode if the user is actually in
554 // keyword mode. Otherwise, the value of this variable is undefined. This
555 // is used to restore the user's search terms upon a call to ClearKeyword().
556 KeywordModeEntryMethod keyword_mode_entry_method_;
557
550 // This is needed to properly update the SearchModel state when the user 558 // This is needed to properly update the SearchModel state when the user
551 // presses escape. 559 // presses escape.
552 bool in_revert_; 560 bool in_revert_;
553 561
554 // Indicates if the upcoming autocomplete search is allowed to be treated as 562 // Indicates if the upcoming autocomplete search is allowed to be treated as
555 // an exact keyword match. If this is true then keyword mode will be 563 // an exact keyword match. If this is true then keyword mode will be
556 // triggered automatically if the input is "<keyword> <search string>". We 564 // triggered automatically if the input is "<keyword> <search string>". We
557 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. 565 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true.
558 // This has no effect if we're already in keyword mode. 566 // This has no effect if we're already in keyword mode.
559 bool allow_exact_keyword_match_; 567 bool allow_exact_keyword_match_;
560 568
561 // The input that was sent to the AutocompleteController. Since no 569 // The input that was sent to the AutocompleteController. Since no
562 // autocomplete query is started after a tab switch, it is possible for this 570 // autocomplete query is started after a tab switch, it is possible for this
563 // |input_| to differ from the one currently stored in AutocompleteController. 571 // |input_| to differ from the one currently stored in AutocompleteController.
564 AutocompleteInput input_; 572 AutocompleteInput input_;
565 573
566 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); 574 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel);
567 }; 575 };
568 576
569 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ 577 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_
OLDNEW
« no previous file with comments | « components/omnibox/browser/keyword_provider.cc ('k') | components/omnibox/browser/omnibox_edit_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698