| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string16.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 12 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
| 13 | 14 |
| 14 struct AutocompleteMatch; | 15 struct AutocompleteMatch; |
| 15 class AutocompleteResult; | 16 class AutocompleteResult; |
| 16 class GURL; | 17 class GURL; |
| 18 class InstantController; |
| 17 class OmniboxEditModel; | 19 class OmniboxEditModel; |
| 18 class OmniboxPopupModel; | 20 class OmniboxPopupModel; |
| 19 class Profile; | 21 class Profile; |
| 20 | 22 |
| 21 namespace gfx { | 23 namespace gfx { |
| 22 class Rect; | 24 class Rect; |
| 23 } | 25 } |
| 24 | 26 |
| 25 // This class controls the various services that can modify the content | 27 // This class controls the various services that can modify the content |
| 26 // for the omnibox, including AutocompleteController and InstantController. It | 28 // for the omnibox, including AutocompleteController and InstantController. It |
| 27 // is responsible of updating the omnibox content. | 29 // is responsible of updating the omnibox content. |
| 28 // TODO(beaudoin): Keep on expanding this class so that OmniboxEditModel no | 30 // TODO(beaudoin): Keep on expanding this class so that OmniboxEditModel no |
| 29 // longer needs to hold any reference to AutocompleteController. Also make | 31 // longer needs to hold any reference to AutocompleteController. Also make |
| 30 // this the point of contact between InstantController and OmniboxEditModel. | 32 // this the point of contact between InstantController and OmniboxEditModel. |
| 31 // As the refactor progresses, keep the class comment up-to-date to | 33 // As the refactor progresses, keep the class comment up-to-date to |
| 32 // precisely explain what this class is doing. | 34 // precisely explain what this class is doing. |
| 33 class OmniboxController : public AutocompleteControllerDelegate { | 35 class OmniboxController : public AutocompleteControllerDelegate { |
| 34 | 36 |
| 35 public: | 37 public: |
| 36 OmniboxController(OmniboxEditModel* omnibox_edit_model, Profile* profile); | 38 OmniboxController(OmniboxEditModel* omnibox_edit_model, |
| 39 Profile* profile, |
| 40 InstantController* instant_controller); |
| 37 virtual ~OmniboxController(); | 41 virtual ~OmniboxController(); |
| 38 | 42 |
| 43 void StartAutocomplete(string16 user_text, |
| 44 size_t cursor_position, |
| 45 bool prevent_inline_autocomplete, |
| 46 bool prefer_keyword, |
| 47 bool allow_exact_keyword_match) const; |
| 48 |
| 39 // AutocompleteControllerDelegate: | 49 // AutocompleteControllerDelegate: |
| 40 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; | 50 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; |
| 41 | 51 |
| 42 AutocompleteController* autocomplete_controller() { | 52 AutocompleteController* autocomplete_controller() { |
| 43 return autocomplete_controller_.get(); | 53 return autocomplete_controller_.get(); |
| 44 } | 54 } |
| 45 | 55 |
| 56 bool DoInstant(const AutocompleteMatch& match, |
| 57 string16 user_text, |
| 58 string16 full_text, |
| 59 size_t selection_start, |
| 60 size_t selection_end, |
| 61 bool user_input_in_progress, |
| 62 bool in_escape_handler, |
| 63 bool just_deleted_text, |
| 64 bool keyword_is_selected); |
| 65 |
| 46 void set_popup_model(OmniboxPopupModel* popup_model) { | 66 void set_popup_model(OmniboxPopupModel* popup_model) { |
| 47 popup_ = popup_model; | 67 popup_ = popup_model; |
| 48 } | 68 } |
| 49 | 69 |
| 50 // TODO(beaudoin): The edit and popup model should be siblings owned by the | 70 // TODO(beaudoin): The edit and popup model should be siblings owned by the |
| 51 // LocationBarView, making this accessor unnecessary. | 71 // LocationBarView, making this accessor unnecessary. |
| 52 OmniboxPopupModel* popup_model() const { return popup_; } | 72 OmniboxPopupModel* popup_model() const { return popup_; } |
| 53 | 73 |
| 54 // Turns off keyword mode for the current match. | 74 // Turns off keyword mode for the current match. |
| 55 void ClearPopupKeywordMode() const; | 75 void ClearPopupKeywordMode() const; |
| 56 | 76 |
| 57 const AutocompleteResult& result() const { | 77 const AutocompleteResult& result() const { |
| 58 return autocomplete_controller_->result(); | 78 return autocomplete_controller_->result(); |
| 59 } | 79 } |
| 60 | 80 |
| 61 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. | 81 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. |
| 62 void DoPreconnect(const AutocompleteMatch& match); | 82 void DoPreconnect(const AutocompleteMatch& match); |
| 63 | 83 |
| 64 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. | 84 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. |
| 65 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here | 85 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here |
| 66 // is in screen coordinates. | 86 // is in screen coordinates. |
| 67 void OnPopupBoundsChanged(const gfx::Rect& bounds); | 87 void OnPopupBoundsChanged(const gfx::Rect& bounds); |
| 68 | 88 |
| 69 private: | 89 private: |
| 90 |
| 91 // Returns true if a verbatim query should be used for Instant. A verbatim |
| 92 // query is forced in certain situations, such as pressing delete at the end |
| 93 // of the edit. |
| 94 bool UseVerbatimInstant(bool just_deleted_text) const; |
| 95 |
| 70 // Weak, it owns us. | 96 // Weak, it owns us. |
| 71 // TODO(beaudoin): Consider defining a delegate to ease unit testing. | 97 // TODO(beaudoin): Consider defining a delegate to ease unit testing. |
| 72 OmniboxEditModel* omnibox_edit_model_; | 98 OmniboxEditModel* omnibox_edit_model_; |
| 73 | 99 |
| 74 Profile* profile_; | 100 Profile* profile_; |
| 75 | 101 |
| 76 OmniboxPopupModel* popup_; | 102 OmniboxPopupModel* popup_; |
| 77 | 103 |
| 104 InstantController* instant_controller_; |
| 105 |
| 78 scoped_ptr<AutocompleteController> autocomplete_controller_; | 106 scoped_ptr<AutocompleteController> autocomplete_controller_; |
| 79 | 107 |
| 80 DISALLOW_COPY_AND_ASSIGN(OmniboxController); | 108 DISALLOW_COPY_AND_ASSIGN(OmniboxController); |
| 81 }; | 109 }; |
| 82 | 110 |
| 83 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ | 111 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ |
| OLD | NEW |