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 CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_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" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 virtual ~OmniboxEditModel(); | 83 virtual ~OmniboxEditModel(); |
84 | 84 |
85 // TODO(beaudoin): Remove this accessor when the AutocompleteController has | 85 // TODO(beaudoin): Remove this accessor when the AutocompleteController has |
86 // completely moved to OmniboxController. | 86 // completely moved to OmniboxController. |
87 AutocompleteController* autocomplete_controller() const { | 87 AutocompleteController* autocomplete_controller() const { |
88 return omnibox_controller_->autocomplete_controller(); | 88 return omnibox_controller_->autocomplete_controller(); |
89 } | 89 } |
90 | 90 |
91 void set_popup_model(OmniboxPopupModel* popup_model) { | 91 void set_popup_model(OmniboxPopupModel* popup_model) { |
92 omnibox_controller_->set_popup_model(popup_model); | 92 omnibox_controller_->set_popup_model(popup_model); |
93 } | 93 } |
94 | 94 |
95 // TODO: The edit and popup should be siblings owned by the LocationBarView, | 95 // TODO: The edit and popup should be siblings owned by the LocationBarView, |
96 // making this accessor unnecessary. | 96 // making this accessor unnecessary. |
97 OmniboxPopupModel* popup_model() const { | 97 OmniboxPopupModel* popup_model() const { |
98 return omnibox_controller_->popup_model(); | 98 return omnibox_controller_->popup_model(); |
99 } | 99 } |
100 | 100 |
101 OmniboxEditController* controller() const { return controller_; } | 101 OmniboxEditController* controller() const { return controller_; } |
102 | 102 |
103 Profile* profile() const { return profile_; } | 103 Profile* profile() const { return profile_; } |
104 | 104 |
105 // Returns the current state. This assumes we are switching tabs, and changes | 105 // Returns the current state. This assumes we are switching tabs, and changes |
106 // the internal state appropriately. | 106 // the internal state appropriately. |
107 const State GetStateForTabSwitch(); | 107 const State GetStateForTabSwitch(); |
108 | 108 |
109 // Restores local state from the saved |state|. | 109 // Restores local state from the saved |state|. |
110 void RestoreState(const State& state); | 110 void RestoreState(const State& state); |
111 | 111 |
112 // Returns the match for the current text. If the user has not edited the text | 112 // Returns the match for the current text. If the user has not edited the text |
113 // this is the match corresponding to the permanent text. | 113 // this is the match corresponding to the permanent text. |
114 AutocompleteMatch CurrentMatch(); | 114 AutocompleteMatch CurrentMatch(); |
115 | 115 |
116 // Called when the user wants to export the entire current text as a URL. | 116 // Called when the user wants to export the entire current text as a URL. |
117 // Sets the url, and if known, the title and favicon. | 117 // Sets the url, and if known, the title and favicon. |
118 void GetDataForURLExport(GURL* url, string16* title, gfx::Image* favicon); | 118 void GetDataForURLExport(GURL* url, string16* title, gfx::Image* favicon); |
119 | 119 |
120 // Returns true if a verbatim query should be used for Instant. A verbatim | |
121 // query is forced in certain situations, such as pressing delete at the end | |
122 // of the edit. | |
123 bool UseVerbatimInstant(); | |
124 | |
125 // Returns true if the current edit contents will be treated as a | 120 // Returns true if the current edit contents will be treated as a |
126 // URL/navigation, as opposed to a search. | 121 // URL/navigation, as opposed to a search. |
127 bool CurrentTextIsURL() const; | 122 bool CurrentTextIsURL() const; |
128 | 123 |
129 // Returns the match type for the current edit contents. | 124 // Returns the match type for the current edit contents. |
130 AutocompleteMatch::Type CurrentTextType() const; | 125 AutocompleteMatch::Type CurrentTextType() const; |
131 | 126 |
132 // Invoked to adjust the text before writting to the clipboard for a copy | 127 // Invoked to adjust the text before writting to the clipboard for a copy |
133 // (e.g. by adding 'http' to the front). |sel_min| gives the minimum position | 128 // (e.g. by adding 'http' to the front). |sel_min| gives the minimum position |
134 // of the selection e.g. min(selection_start, selection_end). |text| is the | 129 // of the selection e.g. min(selection_start, selection_end). |text| is the |
(...skipping 17 matching lines...) Expand all Loading... | |
152 // editing or the edit does not have focus. | 147 // editing or the edit does not have focus. |
153 bool UpdatePermanentText(const string16& new_permanent_text); | 148 bool UpdatePermanentText(const string16& new_permanent_text); |
154 | 149 |
155 // Returns the URL corresponding to the permanent text. | 150 // Returns the URL corresponding to the permanent text. |
156 GURL PermanentURL(); | 151 GURL PermanentURL(); |
157 | 152 |
158 // Sets the user_text_ to |text|. Only the View should call this. | 153 // Sets the user_text_ to |text|. Only the View should call this. |
159 void SetUserText(const string16& text); | 154 void SetUserText(const string16& text); |
160 | 155 |
161 // Calls through to SearchProvider::FinalizeInstantQuery. | 156 // Calls through to SearchProvider::FinalizeInstantQuery. |
162 // If |skip_inline_autocomplete| is true then the |suggestion| text will be | |
163 // turned into final text instead of inline autocomplete suggest. | |
164 void FinalizeInstantQuery(const string16& input_text, | 157 void FinalizeInstantQuery(const string16& input_text, |
165 const InstantSuggestion& suggestion, | 158 const InstantSuggestion& suggestion); |
166 bool skip_inline_autocomplete); | |
167 | 159 |
168 // Sets the suggestion text. | 160 // Sets the suggestion text. |
169 void SetInstantSuggestion(const InstantSuggestion& suggestion); | 161 void SetInstantSuggestion(const InstantSuggestion& suggestion); |
170 | 162 |
171 // Commits the suggested text. If |skip_inline_autocomplete| is true then the | 163 // Commits the gray suggested text as if it's inputted by the user. |
Peter Kasting
2013/05/24 22:45:18
Nit: inputted -> been input
beaudoin
2013/05/27 18:10:54
Done.
| |
172 // suggested text will be committed as final text as if it's inputted by the | |
173 // user, rather than as inline autocomplete suggest. | |
174 // Returns true if the text was committed. | 164 // Returns true if the text was committed. |
175 // TODO: can the return type be void? | 165 // TODO: can the return type be void? |
176 bool CommitSuggestedText(bool skip_inline_autocomplete); | 166 bool CommitSuggestedText(); |
177 | 167 |
178 // Invoked any time the text may have changed in the edit. Updates Instant and | 168 // Invoked any time the text may have changed in the edit. Updates Instant and |
179 // notifies the controller. | 169 // notifies the controller. |
180 void OnChanged(); | 170 void OnChanged(); |
181 | 171 |
182 // Reverts the edit model back to its unedited state (permanent text showing, | 172 // Reverts the edit model back to its unedited state (permanent text showing, |
183 // no user input in progress). | 173 // no user input in progress). |
184 void Revert(); | 174 void Revert(); |
185 | 175 |
186 // Directs the popup to start autocomplete. | 176 // Directs the popup to start autocomplete. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 // AutocompleteController but resides here for now. This method is used by | 359 // AutocompleteController but resides here for now. This method is used by |
370 // AutomationProvider::AutocompleteEditIsQueryInProgress. | 360 // AutomationProvider::AutocompleteEditIsQueryInProgress. |
371 bool query_in_progress() const; | 361 bool query_in_progress() const; |
372 | 362 |
373 // Called whenever user_text_ should change. | 363 // Called whenever user_text_ should change. |
374 void InternalSetUserText(const string16& text); | 364 void InternalSetUserText(const string16& text); |
375 | 365 |
376 // Returns true if a keyword is selected. | 366 // Returns true if a keyword is selected. |
377 bool KeywordIsSelected() const; | 367 bool KeywordIsSelected() const; |
378 | 368 |
369 // Turns off keyword mode for the current match. | |
370 void ClearPopupKeywordMode() const { | |
371 omnibox_controller_->ClearPopupKeywordMode(); | |
Peter Kasting
2013/05/24 22:45:18
Nit: Don't inline non-unix_hacker()-style function
beaudoin
2013/05/27 18:10:54
Done.
| |
372 } | |
373 | |
379 // Conversion between user text and display text. User text is the text the | 374 // Conversion between user text and display text. User text is the text the |
380 // user has input. Display text is the text being shown in the edit. The | 375 // user has input. Display text is the text being shown in the edit. The |
381 // two are different if a keyword is selected. | 376 // two are different if a keyword is selected. |
382 string16 DisplayTextFromUserText(const string16& text) const; | 377 string16 DisplayTextFromUserText(const string16& text) const; |
383 string16 UserTextFromDisplayText(const string16& text) const; | 378 string16 UserTextFromDisplayText(const string16& text) const; |
384 | 379 |
385 // If there's a selected match, copies it into |match|. Else, returns the | 380 // If there's a selected match, copies it into |match|. Else, returns the |
386 // default match for the current text, as well as the alternate nav URL, if | 381 // default match for the current text, as well as the alternate nav URL, if |
387 // |alternate_nav_url| is non-NULL and there is such a URL. | 382 // |alternate_nav_url| is non-NULL and there is such a URL. |
388 void GetInfoForCurrentText(AutocompleteMatch* match, | 383 void GetInfoForCurrentText(AutocompleteMatch* match, |
(...skipping 11 matching lines...) Expand all Loading... | |
400 // Returns true if the current keyword is accepted. | 395 // Returns true if the current keyword is accepted. |
401 bool MaybeAcceptKeywordBySpace(const string16& new_text); | 396 bool MaybeAcceptKeywordBySpace(const string16& new_text); |
402 | 397 |
403 // Checks whether the user inserted a space into |old_text| and by doing so | 398 // Checks whether the user inserted a space into |old_text| and by doing so |
404 // created a |new_text| that looks like "<keyword> <search phrase>". | 399 // created a |new_text| that looks like "<keyword> <search phrase>". |
405 bool CreatedKeywordSearchByInsertingSpaceInMiddle( | 400 bool CreatedKeywordSearchByInsertingSpaceInMiddle( |
406 const string16& old_text, | 401 const string16& old_text, |
407 const string16& new_text, | 402 const string16& new_text, |
408 size_t caret_position) const; | 403 size_t caret_position) const; |
409 | 404 |
410 // Tries to start an Instant preview for |match|. Returns true if Instant | |
411 // processed the match. | |
412 bool DoInstant(const AutocompleteMatch& match); | |
413 | |
414 // Starts a DNS prefetch for the given |match|. | |
415 void DoPreconnect(const AutocompleteMatch& match); | |
416 | |
417 // Checks if a given character is a valid space character for accepting | 405 // Checks if a given character is a valid space character for accepting |
418 // keyword. | 406 // keyword. |
419 static bool IsSpaceCharForAcceptingKeyword(wchar_t c); | 407 static bool IsSpaceCharForAcceptingKeyword(wchar_t c); |
420 | 408 |
421 // Classify the current page being viewed as, for example, the new tab | 409 // Classify the current page being viewed as, for example, the new tab |
422 // page or a normal web page. Used for logging omnibox events for | 410 // page or a normal web page. Used for logging omnibox events for |
423 // UMA opted-in users. Examines the user's profile to determine if the | 411 // UMA opted-in users. Examines the user's profile to determine if the |
424 // current page is the user's home page. | 412 // current page is the user's home page. |
425 metrics::OmniboxEventProto::PageClassification ClassifyPage( | 413 metrics::OmniboxEventProto::PageClassification ClassifyPage( |
426 const GURL& gurl) const; | 414 const GURL& gurl) const; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 // an exact keyword match. If this is true then keyword mode will be | 554 // an exact keyword match. If this is true then keyword mode will be |
567 // triggered automatically if the input is "<keyword> <search string>". We | 555 // triggered automatically if the input is "<keyword> <search string>". We |
568 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 556 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
569 // This has no effect if we're already in keyword mode. | 557 // This has no effect if we're already in keyword mode. |
570 bool allow_exact_keyword_match_; | 558 bool allow_exact_keyword_match_; |
571 | 559 |
572 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 560 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
573 }; | 561 }; |
574 | 562 |
575 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 563 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |