OLD | NEW |
---|---|
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> |
(...skipping 19 matching lines...) Expand all Loading... | |
30 class OmniboxPopupModel; | 30 class OmniboxPopupModel; |
31 class OmniboxView; | 31 class OmniboxView; |
32 | 32 |
33 namespace gfx { | 33 namespace gfx { |
34 class Image; | 34 class Image; |
35 class Rect; | 35 class Rect; |
36 } | 36 } |
37 | 37 |
38 // Reasons why the Omnibox could change into keyword mode. | 38 // Reasons why the Omnibox could change into keyword mode. |
39 // These numeric values are used in UMA logs; do not change them. | 39 // These numeric values are used in UMA logs; do not change them. |
40 enum EnteredKeywordModeMethod { | 40 enum class KeywordModeEntryMethod { |
41 ENTERED_KEYWORD_MODE_VIA_TAB = 0, | 41 TAB = 0, |
42 ENTERED_KEYWORD_MODE_VIA_SPACE_AT_END = 1, | 42 SPACE_AT_END = 1, |
43 ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE = 2, | 43 SPACE_IN_MIDDLE = 2, |
44 ENTERED_KEYWORD_MODE_NUM_ITEMS | 44 KEYBOARD_SHORTCUT = 3, |
45 QUESTION_MARK = 4, | |
46 NUM_ITEMS, | |
45 }; | 47 }; |
46 | 48 |
47 class OmniboxEditModel { | 49 class OmniboxEditModel { |
48 public: | 50 public: |
49 // Did the Omnibox focus originate via the user clicking on the Omnibox or on | 51 // Did the Omnibox focus originate via the user clicking on the Omnibox or on |
50 // the Fakebox? | 52 // the Fakebox? |
51 enum FocusSource { | 53 enum FocusSource { |
52 INVALID = 0, | 54 INVALID = 0, |
53 OMNIBOX = 1, | 55 OMNIBOX = 1, |
54 FAKEBOX = 2 | 56 FAKEBOX = 2 |
55 }; | 57 }; |
56 | 58 |
57 struct State { | 59 struct State { |
58 State(bool user_input_in_progress, | 60 State(bool user_input_in_progress, |
59 const base::string16& user_text, | 61 const base::string16& user_text, |
60 const base::string16& gray_text, | 62 const base::string16& gray_text, |
61 const base::string16& keyword, | 63 const base::string16& keyword, |
62 bool is_keyword_hint, | 64 bool is_keyword_hint, |
65 KeywordModeEntryMethod keyword_mode_entry_method, | |
63 bool url_replacement_enabled, | 66 bool url_replacement_enabled, |
64 OmniboxFocusState focus_state, | 67 OmniboxFocusState focus_state, |
65 FocusSource focus_source, | 68 FocusSource focus_source, |
66 const AutocompleteInput& autocomplete_input); | 69 const AutocompleteInput& autocomplete_input); |
67 State(const State& other); | 70 State(const State& other); |
68 ~State(); | 71 ~State(); |
69 | 72 |
70 bool user_input_in_progress; | 73 bool user_input_in_progress; |
71 const base::string16 user_text; | 74 const base::string16 user_text; |
72 const base::string16 gray_text; | 75 const base::string16 gray_text; |
73 const base::string16 keyword; | 76 const base::string16 keyword; |
74 const bool is_keyword_hint; | 77 const bool is_keyword_hint; |
78 KeywordModeEntryMethod keyword_mode_entry_method; | |
75 bool url_replacement_enabled; | 79 bool url_replacement_enabled; |
76 OmniboxFocusState focus_state; | 80 OmniboxFocusState focus_state; |
77 FocusSource focus_source; | 81 FocusSource focus_source; |
78 const AutocompleteInput autocomplete_input; | 82 const AutocompleteInput autocomplete_input; |
79 }; | 83 }; |
80 | 84 |
81 OmniboxEditModel(OmniboxView* view, | 85 OmniboxEditModel(OmniboxView* view, |
82 OmniboxEditController* controller, | 86 OmniboxEditController* controller, |
83 std::unique_ptr<OmniboxClient> client); | 87 std::unique_ptr<OmniboxClient> client); |
84 virtual ~OmniboxEditModel(); | 88 virtual ~OmniboxEditModel(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 234 |
231 // Accessors for keyword-related state (see comments on keyword_ and | 235 // Accessors for keyword-related state (see comments on keyword_ and |
232 // is_keyword_hint_). | 236 // is_keyword_hint_). |
233 const base::string16& keyword() const { return keyword_; } | 237 const base::string16& keyword() const { return keyword_; } |
234 bool is_keyword_hint() const { return is_keyword_hint_; } | 238 bool is_keyword_hint() const { return is_keyword_hint_; } |
235 bool is_keyword_selected() const { | 239 bool is_keyword_selected() const { |
236 return !is_keyword_hint_ && !keyword_.empty(); | 240 return !is_keyword_hint_ && !keyword_.empty(); |
237 } | 241 } |
238 | 242 |
239 // Accepts the current keyword hint as a keyword. It always returns true for | 243 // Accepts the current keyword hint as a keyword. It always returns true for |
240 // caller convenience. |entered_method| indicates how the use entered | 244 // caller convenience. |entered_method| indicates how the user entered |
241 // keyword mode. This parameter is only used for metrics/logging; it's not | 245 // keyword mode. |
242 // used to change user-visible behavior. | 246 bool AcceptKeyword(KeywordModeEntryMethod keyword_mode_entry_method); |
Peter Kasting
2016/04/28 21:24:41
Nit: For brevity I'd name the arg here and below |
Tom (Use chromium acct)
2016/04/29 01:10:21
Done.
| |
243 bool AcceptKeyword(EnteredKeywordModeMethod entered_method); | 247 |
248 // Sets the current keyword to that of the user's default search provider and | |
249 // updates the view so the user sees the keyword chip in the omnibox. | |
250 void EnterKeywordModeForDefaultSearchProvider( | |
251 KeywordModeEntryMethod keyword_mode_entry_method); | |
244 | 252 |
245 // Accepts the current temporary text as the user text. | 253 // Accepts the current temporary text as the user text. |
246 void AcceptTemporaryTextAsUserText(); | 254 void AcceptTemporaryTextAsUserText(); |
247 | 255 |
248 // Clears the current keyword. | 256 // Clears the current keyword. |
249 void ClearKeyword(); | 257 void ClearKeyword(); |
250 | 258 |
251 // Returns the current autocomplete result. This logic should in the future | 259 // Returns the current autocomplete result. This logic should in the future |
252 // live in AutocompleteController but resides here for now. This method is | 260 // live in AutocompleteController but resides here for now. This method is |
253 // used by AutomationProvider::AutocompleteEditGetMatches. | 261 // used by AutomationProvider::AutocompleteEditGetMatches. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 // | 337 // |
330 // If |allow_keyword_ui_change| is false then the change should not affect | 338 // 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 | 339 // 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. | 340 // may be false when the user is composing a text with an IME. |
333 bool OnAfterPossibleChange(const base::string16& old_text, | 341 bool OnAfterPossibleChange(const base::string16& old_text, |
334 const base::string16& new_text, | 342 const base::string16& new_text, |
335 size_t selection_start, | 343 size_t selection_start, |
336 size_t selection_end, | 344 size_t selection_end, |
337 bool selection_differs, | 345 bool selection_differs, |
338 bool text_differs, | 346 bool text_differs, |
347 bool keyword_differs, | |
339 bool just_deleted_text, | 348 bool just_deleted_text, |
340 bool allow_keyword_ui_change); | 349 bool allow_keyword_ui_change); |
341 | 350 |
342 // Called when the current match has changed in the OmniboxController. | 351 // Called when the current match has changed in the OmniboxController. |
343 void OnCurrentMatchChanged(); | 352 void OnCurrentMatchChanged(); |
344 | 353 |
345 // Name of the histogram tracking cut or copy omnibox commands. | 354 // Name of the histogram tracking cut or copy omnibox commands. |
346 static const char kCutOrCopyAllTextHistogram[]; | 355 static const char kCutOrCopyAllTextHistogram[]; |
347 | 356 |
348 private: | 357 private: |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 // Inline autocomplete is allowed if the user has not just deleted text, and | 511 // Inline autocomplete is allowed if the user has not just deleted text, and |
503 // no temporary text is showing. In this case, inline_autocomplete_text_ is | 512 // no temporary text is showing. In this case, inline_autocomplete_text_ is |
504 // appended to the user_text_ and displayed selected (at least initially). | 513 // appended to the user_text_ and displayed selected (at least initially). |
505 // | 514 // |
506 // NOTE: When the popup is closed there should never be inline autocomplete | 515 // NOTE: When the popup is closed there should never be inline autocomplete |
507 // text (actions that close the popup should either accept the text, convert | 516 // text (actions that close the popup should either accept the text, convert |
508 // it to a normal selection, or change the edit entirely). | 517 // it to a normal selection, or change the edit entirely). |
509 bool just_deleted_text_; | 518 bool just_deleted_text_; |
510 base::string16 inline_autocomplete_text_; | 519 base::string16 inline_autocomplete_text_; |
511 | 520 |
521 // Set when the user is in the process of exiting keyword mode. This is | |
522 // useful to ensure we don't toggle back into keyword mode in the process of | |
523 // handling the current event. | |
524 bool clearing_keyword_; | |
525 | |
512 // Used by OnPopupDataChanged to keep track of whether there is currently a | 526 // Used by OnPopupDataChanged to keep track of whether there is currently a |
513 // temporary text. | 527 // temporary text. |
514 // | 528 // |
515 // Example of use: If the user types "goog", then arrows down in the | 529 // Example of use: If the user types "goog", then arrows down in the |
516 // autocomplete popup until, say, "google.com" appears in the edit box, then | 530 // autocomplete popup until, say, "google.com" appears in the edit box, then |
517 // the user_text_ is still "goog", and "google.com" is "temporary text". | 531 // the user_text_ is still "goog", and "google.com" is "temporary text". |
518 // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again | 532 // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again |
519 // and the popup is closed and "goog" is replaced by the permanent_text_, | 533 // and the popup is closed and "goog" is replaced by the permanent_text_, |
520 // which is the URL of the current page. | 534 // which is the URL of the current page. |
521 // | 535 // |
(...skipping 18 matching lines...) Expand all Loading... | |
540 // selected keyword, or just some input text that looks like a keyword (so we | 554 // 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; | 555 // can show a hint to press <tab>). This is the keyword in either case; |
542 // is_keyword_hint_ (below) distinguishes the two cases. | 556 // is_keyword_hint_ (below) distinguishes the two cases. |
543 base::string16 keyword_; | 557 base::string16 keyword_; |
544 | 558 |
545 // True if the keyword associated with this match is merely a hint, i.e. the | 559 // 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 | 560 // 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. | 561 // keyword_ to show a "Press <tab> to search" sort of hint. |
548 bool is_keyword_hint_; | 562 bool is_keyword_hint_; |
549 | 563 |
564 // Indicates how the user entered keyword mode if the user is actually in | |
565 // keyword mode. Otherwise, the value of this variable is undefined. This | |
566 // is used to restore the user's search terms upon a call to ClearKeyword(). | |
567 KeywordModeEntryMethod keyword_mode_entry_method_; | |
568 | |
550 // This is needed to properly update the SearchModel state when the user | 569 // This is needed to properly update the SearchModel state when the user |
551 // presses escape. | 570 // presses escape. |
552 bool in_revert_; | 571 bool in_revert_; |
553 | 572 |
554 // Indicates if the upcoming autocomplete search is allowed to be treated as | 573 // 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 | 574 // an exact keyword match. If this is true then keyword mode will be |
556 // triggered automatically if the input is "<keyword> <search string>". We | 575 // triggered automatically if the input is "<keyword> <search string>". We |
557 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 576 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
558 // This has no effect if we're already in keyword mode. | 577 // This has no effect if we're already in keyword mode. |
559 bool allow_exact_keyword_match_; | 578 bool allow_exact_keyword_match_; |
560 | 579 |
561 // The input that was sent to the AutocompleteController. Since no | 580 // The input that was sent to the AutocompleteController. Since no |
562 // autocomplete query is started after a tab switch, it is possible for this | 581 // autocomplete query is started after a tab switch, it is possible for this |
563 // |input_| to differ from the one currently stored in AutocompleteController. | 582 // |input_| to differ from the one currently stored in AutocompleteController. |
564 AutocompleteInput input_; | 583 AutocompleteInput input_; |
565 | 584 |
566 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 585 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
567 }; | 586 }; |
568 | 587 |
569 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ | 588 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |