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