| 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 entry_method); |
| 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 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // selected keyword, or just some input text that looks like a keyword (so we | 549 // 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; | 550 // can show a hint to press <tab>). This is the keyword in either case; |
| 542 // is_keyword_hint_ (below) distinguishes the two cases. | 551 // is_keyword_hint_ (below) distinguishes the two cases. |
| 543 base::string16 keyword_; | 552 base::string16 keyword_; |
| 544 | 553 |
| 545 // True if the keyword associated with this match is merely a hint, i.e. the | 554 // 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 | 555 // 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. | 556 // keyword_ to show a "Press <tab> to search" sort of hint. |
| 548 bool is_keyword_hint_; | 557 bool is_keyword_hint_; |
| 549 | 558 |
| 559 // Indicates how the user entered keyword mode if the user is actually in |
| 560 // keyword mode. Otherwise, the value of this variable is undefined. This |
| 561 // is used to restore the user's search terms upon a call to ClearKeyword(). |
| 562 KeywordModeEntryMethod keyword_mode_entry_method_; |
| 563 |
| 550 // This is needed to properly update the SearchModel state when the user | 564 // This is needed to properly update the SearchModel state when the user |
| 551 // presses escape. | 565 // presses escape. |
| 552 bool in_revert_; | 566 bool in_revert_; |
| 553 | 567 |
| 554 // Indicates if the upcoming autocomplete search is allowed to be treated as | 568 // 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 | 569 // an exact keyword match. If this is true then keyword mode will be |
| 556 // triggered automatically if the input is "<keyword> <search string>". We | 570 // triggered automatically if the input is "<keyword> <search string>". We |
| 557 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 571 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
| 558 // This has no effect if we're already in keyword mode. | 572 // This has no effect if we're already in keyword mode. |
| 559 bool allow_exact_keyword_match_; | 573 bool allow_exact_keyword_match_; |
| 560 | 574 |
| 561 // The input that was sent to the AutocompleteController. Since no | 575 // The input that was sent to the AutocompleteController. Since no |
| 562 // autocomplete query is started after a tab switch, it is possible for this | 576 // autocomplete query is started after a tab switch, it is possible for this |
| 563 // |input_| to differ from the one currently stored in AutocompleteController. | 577 // |input_| to differ from the one currently stored in AutocompleteController. |
| 564 AutocompleteInput input_; | 578 AutocompleteInput input_; |
| 565 | 579 |
| 566 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 580 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
| 567 }; | 581 }; |
| 568 | 582 |
| 569 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ | 583 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ |
| OLD | NEW |