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/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 12 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
14 | 15 |
15 struct AutocompleteMatch; | 16 struct AutocompleteMatch; |
16 class AutocompleteResult; | 17 class AutocompleteResult; |
17 class GURL; | 18 class GURL; |
18 class InstantController; | 19 class InstantController; |
| 20 struct InstantSuggestion; |
19 class OmniboxEditModel; | 21 class OmniboxEditModel; |
20 class OmniboxPopupModel; | 22 class OmniboxPopupModel; |
21 class Profile; | 23 class Profile; |
22 | 24 |
23 namespace gfx { | 25 namespace gfx { |
24 class Rect; | 26 class Rect; |
25 } | 27 } |
26 | 28 |
27 // This class controls the various services that can modify the content | 29 // This class controls the various services that can modify the content |
28 // for the omnibox, including AutocompleteController and InstantController. It | 30 // for the omnibox, including AutocompleteController and InstantController. It |
(...skipping 27 matching lines...) Expand all Loading... |
56 bool DoInstant(const AutocompleteMatch& match, | 58 bool DoInstant(const AutocompleteMatch& match, |
57 string16 user_text, | 59 string16 user_text, |
58 string16 full_text, | 60 string16 full_text, |
59 size_t selection_start, | 61 size_t selection_start, |
60 size_t selection_end, | 62 size_t selection_end, |
61 bool user_input_in_progress, | 63 bool user_input_in_progress, |
62 bool in_escape_handler, | 64 bool in_escape_handler, |
63 bool just_deleted_text, | 65 bool just_deleted_text, |
64 bool keyword_is_selected); | 66 bool keyword_is_selected); |
65 | 67 |
| 68 // Calls through to SearchProvider::FinalizeInstantQuery. |
| 69 void FinalizeInstantQuery(const string16& input_text, |
| 70 const InstantSuggestion& suggestion); |
| 71 |
| 72 // Sets the suggestion text. |
| 73 void SetInstantSuggestion(const InstantSuggestion& suggestion); |
| 74 |
| 75 // Set |current_match_| to an invalid value, indicating that we do not yet |
| 76 // have a valid match for the current text in the omnibox. |
| 77 void InvalidateCurrentMatch(); |
| 78 |
66 void set_popup_model(OmniboxPopupModel* popup_model) { | 79 void set_popup_model(OmniboxPopupModel* popup_model) { |
67 popup_ = popup_model; | 80 popup_ = popup_model; |
68 } | 81 } |
69 | 82 |
70 // TODO(beaudoin): The edit and popup model should be siblings owned by the | 83 // TODO(beaudoin): The edit and popup model should be siblings owned by the |
71 // LocationBarView, making this accessor unnecessary. | 84 // LocationBarView, making this accessor unnecessary. |
72 OmniboxPopupModel* popup_model() const { return popup_; } | 85 OmniboxPopupModel* popup_model() const { return popup_; } |
73 | 86 |
| 87 const string16& gray_suggestion() const { return gray_suggestion_; } |
| 88 |
| 89 const AutocompleteMatch& CurrentMatch(GURL* alternate_nav_url) const; |
| 90 |
74 // Turns off keyword mode for the current match. | 91 // Turns off keyword mode for the current match. |
75 void ClearPopupKeywordMode() const; | 92 void ClearPopupKeywordMode() const; |
76 | 93 |
77 const AutocompleteResult& result() const { | 94 const AutocompleteResult& result() const { |
78 return autocomplete_controller_->result(); | 95 return autocomplete_controller_->result(); |
79 } | 96 } |
80 | 97 |
81 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. | 98 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. |
82 void DoPreconnect(const AutocompleteMatch& match); | 99 void DoPreconnect(const AutocompleteMatch& match); |
83 | 100 |
84 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. | 101 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. |
85 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here | 102 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here |
86 // is in screen coordinates. | 103 // is in screen coordinates. |
87 void OnPopupBoundsChanged(const gfx::Rect& bounds); | 104 void OnPopupBoundsChanged(const gfx::Rect& bounds); |
88 | 105 |
89 private: | 106 private: |
90 | 107 |
91 // Returns true if a verbatim query should be used for Instant. A verbatim | 108 // 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 | 109 // query is forced in certain situations, such as pressing delete at the end |
93 // of the edit. | 110 // of the edit. |
94 bool UseVerbatimInstant(bool just_deleted_text) const; | 111 bool UseVerbatimInstant(bool just_deleted_text) const; |
95 | 112 |
96 // Access the instant controller from the OmniboxEditModel. We need to do this | 113 // Access the instant controller from the OmniboxEditModel. We need to do this |
97 // because the only valid pointer to InstantController is kept in Browser, | 114 // because the only valid pointer to InstantController is kept in Browser, |
98 // which OmniboxEditModel has some ways of reaching. | 115 // which OmniboxEditModel has some ways of reaching. |
99 InstantController* GetInstantController() const; | 116 InstantController* GetInstantController() const; |
100 | 117 |
| 118 // Creates an AutocompleteMatch for an instant result and sets it into |
| 119 // |current_match_|. |
| 120 void CreateAndSetInstantMatch(string16 query_string, |
| 121 string16 input_text, |
| 122 AutocompleteMatchType::Type match_type); |
101 // Weak, it owns us. | 123 // Weak, it owns us. |
102 // TODO(beaudoin): Consider defining a delegate to ease unit testing. | 124 // TODO(beaudoin): Consider defining a delegate to ease unit testing. |
103 OmniboxEditModel* omnibox_edit_model_; | 125 OmniboxEditModel* omnibox_edit_model_; |
104 | 126 |
105 Profile* profile_; | 127 Profile* profile_; |
106 | 128 |
107 OmniboxPopupModel* popup_; | 129 OmniboxPopupModel* popup_; |
108 | 130 |
| 131 InstantController* instant_controller_; |
| 132 |
109 scoped_ptr<AutocompleteController> autocomplete_controller_; | 133 scoped_ptr<AutocompleteController> autocomplete_controller_; |
110 | 134 |
| 135 // TODO(beaudoin): This AutocompleteMatch is used to let the OmniboxEditModel |
| 136 // know what it should display. Not every field is required for that purpose, |
| 137 // but the ones specifically needed are unclear. We should therefore spend |
| 138 // some time to extract these fields and use a tighter structure here. |
| 139 AutocompleteMatch current_match_; |
| 140 |
| 141 // The completion suggested by instant, displayed in gray text besides |
| 142 // |fill_into_edit|. |
| 143 string16 gray_suggestion_; |
| 144 |
111 DISALLOW_COPY_AND_ASSIGN(OmniboxController); | 145 DISALLOW_COPY_AND_ASSIGN(OmniboxController); |
112 }; | 146 }; |
113 | 147 |
114 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ | 148 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ |
OLD | NEW |