| 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); |
| 37 virtual ~OmniboxController(); | 40 virtual ~OmniboxController(); |
| 38 | 41 |
| 42 void StartAutocomplete(string16 user_text, |
| 43 size_t cursor_position, |
| 44 bool prevent_inline_autocomplete, |
| 45 bool prefer_keyword, |
| 46 bool allow_exact_keyword_match) const; |
| 47 |
| 39 // AutocompleteControllerDelegate: | 48 // AutocompleteControllerDelegate: |
| 40 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; | 49 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; |
| 41 | 50 |
| 42 AutocompleteController* autocomplete_controller() { | 51 AutocompleteController* autocomplete_controller() { |
| 43 return autocomplete_controller_.get(); | 52 return autocomplete_controller_.get(); |
| 44 } | 53 } |
| 45 | 54 |
| 55 bool DoInstant(const AutocompleteMatch& match, |
| 56 string16 user_text, |
| 57 string16 full_text, |
| 58 size_t selection_start, |
| 59 size_t selection_end, |
| 60 bool user_input_in_progress, |
| 61 bool in_escape_handler, |
| 62 bool just_deleted_text, |
| 63 bool keyword_is_selected); |
| 64 |
| 46 void set_popup_model(OmniboxPopupModel* popup_model) { | 65 void set_popup_model(OmniboxPopupModel* popup_model) { |
| 47 popup_ = popup_model; | 66 popup_ = popup_model; |
| 48 } | 67 } |
| 49 | 68 |
| 50 // TODO(beaudoin): The edit and popup model should be siblings owned by the | 69 // TODO(beaudoin): The edit and popup model should be siblings owned by the |
| 51 // LocationBarView, making this accessor unnecessary. | 70 // LocationBarView, making this accessor unnecessary. |
| 52 OmniboxPopupModel* popup_model() const { return popup_; } | 71 OmniboxPopupModel* popup_model() const { return popup_; } |
| 53 | 72 |
| 54 // Turns off keyword mode for the current match. | 73 // Turns off keyword mode for the current match. |
| 55 void ClearPopupKeywordMode() const; | 74 void ClearPopupKeywordMode() const; |
| 56 | 75 |
| 57 const AutocompleteResult& result() const { | 76 const AutocompleteResult& result() const { |
| 58 return autocomplete_controller_->result(); | 77 return autocomplete_controller_->result(); |
| 59 } | 78 } |
| 60 | 79 |
| 61 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. | 80 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. |
| 62 void DoPreconnect(const AutocompleteMatch& match); | 81 void DoPreconnect(const AutocompleteMatch& match); |
| 63 | 82 |
| 64 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. | 83 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. |
| 65 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here | 84 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here |
| 66 // is in screen coordinates. | 85 // is in screen coordinates. |
| 67 void OnPopupBoundsChanged(const gfx::Rect& bounds); | 86 void OnPopupBoundsChanged(const gfx::Rect& bounds); |
| 68 | 87 |
| 69 private: | 88 private: |
| 89 |
| 90 // Returns true if a verbatim query should be used for Instant. A verbatim |
| 91 // query is forced in certain situations, such as pressing delete at the end |
| 92 // of the edit. |
| 93 bool UseVerbatimInstant(bool just_deleted_text) const; |
| 94 |
| 95 // Access the instant controller from the OmniboxEditModel. We need to do this |
| 96 // because the only valid pointer to InstantController is kept in Browser, |
| 97 // which OmniboxEditModel has some ways of reaching. |
| 98 InstantController* GetInstantController() const; |
| 99 |
| 70 // Weak, it owns us. | 100 // Weak, it owns us. |
| 71 // TODO(beaudoin): Consider defining a delegate to ease unit testing. | 101 // TODO(beaudoin): Consider defining a delegate to ease unit testing. |
| 72 OmniboxEditModel* omnibox_edit_model_; | 102 OmniboxEditModel* omnibox_edit_model_; |
| 73 | 103 |
| 74 Profile* profile_; | 104 Profile* profile_; |
| 75 | 105 |
| 76 OmniboxPopupModel* popup_; | 106 OmniboxPopupModel* popup_; |
| 77 | 107 |
| 78 scoped_ptr<AutocompleteController> autocomplete_controller_; | 108 scoped_ptr<AutocompleteController> autocomplete_controller_; |
| 79 | 109 |
| 80 DISALLOW_COPY_AND_ASSIGN(OmniboxController); | 110 DISALLOW_COPY_AND_ASSIGN(OmniboxController); |
| 81 }; | 111 }; |
| 82 | 112 |
| 83 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ | 113 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ |
| OLD | NEW |