Chromium Code Reviews| 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 |
| 85 // Used by |OnAfterPossibleChange|. | |
| 86 struct TextStateChange { | |
|
Peter Kasting
2016/06/04 02:17:18
Nit: I think this should be defined in OmniboxView
Tom (Use chromium acct)
2016/06/04 20:39:09
Done, but unfortunately you cannot forward-declare
| |
| 87 // |old_text| and |new_text| are not owned. | |
| 88 const base::string16* old_text; | |
| 89 const base::string16* new_text; | |
| 90 size_t new_sel_start; | |
| 91 size_t new_sel_end; | |
| 92 bool selection_differs; | |
| 93 bool text_differs; | |
| 94 bool keyword_differs; | |
| 95 bool just_deleted_text; | |
| 96 }; | |
| 97 | |
| 81 OmniboxEditModel(OmniboxView* view, | 98 OmniboxEditModel(OmniboxView* view, |
| 82 OmniboxEditController* controller, | 99 OmniboxEditController* controller, |
| 83 std::unique_ptr<OmniboxClient> client); | 100 std::unique_ptr<OmniboxClient> client); |
| 84 virtual ~OmniboxEditModel(); | 101 virtual ~OmniboxEditModel(); |
| 85 | 102 |
| 86 // TODO(beaudoin): Remove this accessor when the AutocompleteController has | 103 // TODO(beaudoin): Remove this accessor when the AutocompleteController has |
| 87 // completely moved to OmniboxController. | 104 // completely moved to OmniboxController. |
| 88 AutocompleteController* autocomplete_controller() const { | 105 AutocompleteController* autocomplete_controller() const { |
| 89 return omnibox_controller_->autocomplete_controller(); | 106 return omnibox_controller_->autocomplete_controller(); |
| 90 } | 107 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 247 |
| 231 // Accessors for keyword-related state (see comments on keyword_ and | 248 // Accessors for keyword-related state (see comments on keyword_ and |
| 232 // is_keyword_hint_). | 249 // is_keyword_hint_). |
| 233 const base::string16& keyword() const { return keyword_; } | 250 const base::string16& keyword() const { return keyword_; } |
| 234 bool is_keyword_hint() const { return is_keyword_hint_; } | 251 bool is_keyword_hint() const { return is_keyword_hint_; } |
| 235 bool is_keyword_selected() const { | 252 bool is_keyword_selected() const { |
| 236 return !is_keyword_hint_ && !keyword_.empty(); | 253 return !is_keyword_hint_ && !keyword_.empty(); |
| 237 } | 254 } |
| 238 | 255 |
| 239 // Accepts the current keyword hint as a keyword. It always returns true for | 256 // Accepts the current keyword hint as a keyword. It always returns true for |
| 240 // caller convenience. |entered_method| indicates how the use entered | 257 // caller convenience. |entered_method| indicates how the user entered |
| 241 // keyword mode. This parameter is only used for metrics/logging; it's not | 258 // keyword mode. |
| 242 // used to change user-visible behavior. | 259 bool AcceptKeyword(KeywordModeEntryMethod entry_method); |
| 243 bool AcceptKeyword(EnteredKeywordModeMethod entered_method); | 260 |
| 261 // Sets the current keyword to that of the user's default search provider and | |
| 262 // updates the view so the user sees the keyword chip in the omnibox. | |
| 263 void EnterKeywordModeForDefaultSearchProvider( | |
| 264 KeywordModeEntryMethod entry_method); | |
| 244 | 265 |
| 245 // Accepts the current temporary text as the user text. | 266 // Accepts the current temporary text as the user text. |
| 246 void AcceptTemporaryTextAsUserText(); | 267 void AcceptTemporaryTextAsUserText(); |
| 247 | 268 |
| 248 // Clears the current keyword. | 269 // Clears the current keyword. |
| 249 void ClearKeyword(); | 270 void ClearKeyword(); |
| 250 | 271 |
| 251 // Returns the current autocomplete result. This logic should in the future | 272 // Returns the current autocomplete result. This logic should in the future |
| 252 // live in AutocompleteController but resides here for now. This method is | 273 // live in AutocompleteController but resides here for now. This method is |
| 253 // used by AutomationProvider::AutocompleteEditGetMatches. | 274 // used by AutomationProvider::AutocompleteEditGetMatches. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 // comments on keyword_ and is_keyword_hint_). | 338 // comments on keyword_ and is_keyword_hint_). |
| 318 void OnPopupDataChanged( | 339 void OnPopupDataChanged( |
| 319 const base::string16& text, | 340 const base::string16& text, |
| 320 GURL* destination_for_temporary_text_change, | 341 GURL* destination_for_temporary_text_change, |
| 321 const base::string16& keyword, | 342 const base::string16& keyword, |
| 322 bool is_keyword_hint); | 343 bool is_keyword_hint); |
| 323 | 344 |
| 324 // Called by the OmniboxView after something changes, with details about what | 345 // Called by the OmniboxView after something changes, with details about what |
| 325 // state changes occured. Updates internal state, updates the popup if | 346 // state changes occured. Updates internal state, updates the popup if |
| 326 // necessary, and returns true if any significant changes occurred. Note that | 347 // 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 | 348 // |text_change.text_differs| may be set even if |text_change.old_text| == |
| 328 // just committed an IME composition. | 349 // |text_change.new_text|, e.g. if we've just committed an IME composition. |
| 329 // | 350 // |
| 330 // If |allow_keyword_ui_change| is false then the change should not affect | 351 // 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 | 352 // 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. | 353 // may be false when the user is composing a text with an IME. |
| 333 bool OnAfterPossibleChange(const base::string16& old_text, | 354 bool OnAfterPossibleChange(const TextStateChange& text_change, |
| 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); | 355 bool allow_keyword_ui_change); |
| 341 | 356 |
| 342 // Called when the current match has changed in the OmniboxController. | 357 // Called when the current match has changed in the OmniboxController. |
| 343 void OnCurrentMatchChanged(); | 358 void OnCurrentMatchChanged(); |
| 344 | 359 |
| 345 // Name of the histogram tracking cut or copy omnibox commands. | 360 // Name of the histogram tracking cut or copy omnibox commands. |
| 346 static const char kCutOrCopyAllTextHistogram[]; | 361 static const char kCutOrCopyAllTextHistogram[]; |
| 347 | 362 |
| 348 private: | 363 private: |
| 349 friend class OmniboxControllerTest; | 364 friend class OmniboxControllerTest; |
| (...skipping 190 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 | 555 // 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; | 556 // can show a hint to press <tab>). This is the keyword in either case; |
| 542 // is_keyword_hint_ (below) distinguishes the two cases. | 557 // is_keyword_hint_ (below) distinguishes the two cases. |
| 543 base::string16 keyword_; | 558 base::string16 keyword_; |
| 544 | 559 |
| 545 // True if the keyword associated with this match is merely a hint, i.e. the | 560 // 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 | 561 // 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. | 562 // keyword_ to show a "Press <tab> to search" sort of hint. |
| 548 bool is_keyword_hint_; | 563 bool is_keyword_hint_; |
| 549 | 564 |
| 565 // Indicates how the user entered keyword mode if the user is actually in | |
| 566 // keyword mode. Otherwise, the value of this variable is undefined. This | |
| 567 // is used to restore the user's search terms upon a call to ClearKeyword(). | |
| 568 KeywordModeEntryMethod keyword_mode_entry_method_; | |
| 569 | |
| 550 // This is needed to properly update the SearchModel state when the user | 570 // This is needed to properly update the SearchModel state when the user |
| 551 // presses escape. | 571 // presses escape. |
| 552 bool in_revert_; | 572 bool in_revert_; |
| 553 | 573 |
| 554 // Indicates if the upcoming autocomplete search is allowed to be treated as | 574 // 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 | 575 // an exact keyword match. If this is true then keyword mode will be |
| 556 // triggered automatically if the input is "<keyword> <search string>". We | 576 // triggered automatically if the input is "<keyword> <search string>". We |
| 557 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 577 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
| 558 // This has no effect if we're already in keyword mode. | 578 // This has no effect if we're already in keyword mode. |
| 559 bool allow_exact_keyword_match_; | 579 bool allow_exact_keyword_match_; |
| 560 | 580 |
| 561 // The input that was sent to the AutocompleteController. Since no | 581 // The input that was sent to the AutocompleteController. Since no |
| 562 // autocomplete query is started after a tab switch, it is possible for this | 582 // autocomplete query is started after a tab switch, it is possible for this |
| 563 // |input_| to differ from the one currently stored in AutocompleteController. | 583 // |input_| to differ from the one currently stored in AutocompleteController. |
| 564 AutocompleteInput input_; | 584 AutocompleteInput input_; |
| 565 | 585 |
| 566 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 586 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
| 567 }; | 587 }; |
| 568 | 588 |
| 569 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ | 589 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EDIT_MODEL_H_ |
| OLD | NEW |