Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.h

Issue 15003002: Omnibox refactor. Move StartAutocomplete and DoInstant to controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FIxed NIT Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 been input by the user.
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // this. 318 // this.
329 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here 319 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here
330 // is in screen coordinates. 320 // is in screen coordinates.
331 void OnPopupBoundsChanged(const gfx::Rect& bounds) { 321 void OnPopupBoundsChanged(const gfx::Rect& bounds) {
332 omnibox_controller_->OnPopupBoundsChanged(bounds); 322 omnibox_controller_->OnPopupBoundsChanged(bounds);
333 } 323 }
334 324
335 // Called when the results have changed in the OmniboxController. 325 // Called when the results have changed in the OmniboxController.
336 void OnResultChanged(bool default_match_changed); 326 void OnResultChanged(bool default_match_changed);
337 327
328 // TODO(beaudoin): We need this to allow OmniboxController access the
329 // InstantController via OmniboxEditController, because the only valid pointer
330 // to InstantController is kept in Browser. We should try to get rid of this,
331 // maybe by ensuring InstantController lives as long as Browser.
332 InstantController* GetInstantController() const;
333
338 private: 334 private:
339 friend class InstantTestBase; 335 friend class InstantTestBase;
340 friend class OmniboxControllerTest; 336 friend class OmniboxControllerTest;
341 337
342 enum PasteState { 338 enum PasteState {
343 NONE, // Most recent edit was not a paste. 339 NONE, // Most recent edit was not a paste.
344 PASTING, // In the middle of doing a paste. We need this intermediate 340 PASTING, // In the middle of doing a paste. We need this intermediate
345 // state because OnPaste() does the actual detection of 341 // state because OnPaste() does the actual detection of
346 // paste, but OnAfterPossibleChange() has to update the 342 // paste, but OnAfterPossibleChange() has to update the
347 // paste state for every edit. If OnPaste() set the state 343 // paste state for every edit. If OnPaste() set the state
(...skipping 21 matching lines...) Expand all
369 // AutocompleteController but resides here for now. This method is used by 365 // AutocompleteController but resides here for now. This method is used by
370 // AutomationProvider::AutocompleteEditIsQueryInProgress. 366 // AutomationProvider::AutocompleteEditIsQueryInProgress.
371 bool query_in_progress() const; 367 bool query_in_progress() const;
372 368
373 // Called whenever user_text_ should change. 369 // Called whenever user_text_ should change.
374 void InternalSetUserText(const string16& text); 370 void InternalSetUserText(const string16& text);
375 371
376 // Returns true if a keyword is selected. 372 // Returns true if a keyword is selected.
377 bool KeywordIsSelected() const; 373 bool KeywordIsSelected() const;
378 374
375 // Turns off keyword mode for the current match.
376 void ClearPopupKeywordMode() const;
377
379 // Conversion between user text and display text. User text is the text the 378 // 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 379 // user has input. Display text is the text being shown in the edit. The
381 // two are different if a keyword is selected. 380 // two are different if a keyword is selected.
382 string16 DisplayTextFromUserText(const string16& text) const; 381 string16 DisplayTextFromUserText(const string16& text) const;
383 string16 UserTextFromDisplayText(const string16& text) const; 382 string16 UserTextFromDisplayText(const string16& text) const;
384 383
385 // If there's a selected match, copies it into |match|. Else, returns the 384 // 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 385 // 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. 386 // |alternate_nav_url| is non-NULL and there is such a URL.
388 void GetInfoForCurrentText(AutocompleteMatch* match, 387 void GetInfoForCurrentText(AutocompleteMatch* match,
(...skipping 11 matching lines...) Expand all
400 // Returns true if the current keyword is accepted. 399 // Returns true if the current keyword is accepted.
401 bool MaybeAcceptKeywordBySpace(const string16& new_text); 400 bool MaybeAcceptKeywordBySpace(const string16& new_text);
402 401
403 // Checks whether the user inserted a space into |old_text| and by doing so 402 // 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>". 403 // created a |new_text| that looks like "<keyword> <search phrase>".
405 bool CreatedKeywordSearchByInsertingSpaceInMiddle( 404 bool CreatedKeywordSearchByInsertingSpaceInMiddle(
406 const string16& old_text, 405 const string16& old_text,
407 const string16& new_text, 406 const string16& new_text,
408 size_t caret_position) const; 407 size_t caret_position) const;
409 408
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 409 // Checks if a given character is a valid space character for accepting
418 // keyword. 410 // keyword.
419 static bool IsSpaceCharForAcceptingKeyword(wchar_t c); 411 static bool IsSpaceCharForAcceptingKeyword(wchar_t c);
420 412
421 // Classify the current page being viewed as, for example, the new tab 413 // 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 414 // 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 415 // UMA opted-in users. Examines the user's profile to determine if the
424 // current page is the user's home page. 416 // current page is the user's home page.
425 metrics::OmniboxEventProto::PageClassification ClassifyPage( 417 metrics::OmniboxEventProto::PageClassification ClassifyPage(
426 const GURL& gurl) const; 418 const GURL& gurl) const;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // an exact keyword match. If this is true then keyword mode will be 558 // an exact keyword match. If this is true then keyword mode will be
567 // triggered automatically if the input is "<keyword> <search string>". We 559 // triggered automatically if the input is "<keyword> <search string>". We
568 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. 560 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true.
569 // This has no effect if we're already in keyword mode. 561 // This has no effect if we're already in keyword mode.
570 bool allow_exact_keyword_match_; 562 bool allow_exact_keyword_match_;
571 563
572 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); 564 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel);
573 }; 565 };
574 566
575 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ 567 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_controller_unittest.cc ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698