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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/strings/string16.h" 12 #include "chrome/browser/autocomplete/autocomplete_controller.h" 13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 14 #include "chrome/browser/autocomplete/autocomplete_input.h" 15 #include "chrome/browser/autocomplete/autocomplete_match.h" 16 17 struct AutocompleteMatch; 18 class AutocompleteResult; 19 class GURL; 20 class InstantController; 21 class OmniboxEditModel; 22 class OmniboxPopupModel; 23 class Profile; 24 25 namespace gfx { 26 class Rect; 27 } 28 29 // This class controls the various services that can modify the content 30 // for the omnibox, including AutocompleteController and InstantController. It 31 // is responsible of updating the omnibox content. 32 // TODO(beaudoin): Keep on expanding this class so that OmniboxEditModel no 33 // longer needs to hold any reference to AutocompleteController. Also make 34 // this the point of contact between InstantController and OmniboxEditModel. 35 // As the refactor progresses, keep the class comment up-to-date to 36 // precisely explain what this class is doing. 37 class OmniboxController : public AutocompleteControllerDelegate { 38 public: 39 OmniboxController(OmniboxEditModel* omnibox_edit_model, 40 Profile* profile); 41 virtual ~OmniboxController(); 42 43 // |current_url| is only set for mobile ports. 44 void StartAutocomplete( 45 base::string16 user_text, 46 size_t cursor_position, 47 const GURL& current_url, 48 AutocompleteInput::PageClassification current_page_classification, 49 bool prevent_inline_autocomplete, 50 bool prefer_keyword, 51 bool allow_exact_keyword_match) const; 52 53 // AutocompleteControllerDelegate: 54 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; 55 autocomplete_controller()56 AutocompleteController* autocomplete_controller() { 57 return autocomplete_controller_.get(); 58 } 59 60 // Set |current_match_| to an invalid value, indicating that we do not yet 61 // have a valid match for the current text in the omnibox. 62 void InvalidateCurrentMatch(); 63 set_popup_model(OmniboxPopupModel * popup_model)64 void set_popup_model(OmniboxPopupModel* popup_model) { 65 popup_ = popup_model; 66 } 67 68 // TODO(beaudoin): The edit and popup model should be siblings owned by the 69 // LocationBarView, making this accessor unnecessary. popup_model()70 OmniboxPopupModel* popup_model() const { return popup_; } 71 current_match()72 const AutocompleteMatch& current_match() const { return current_match_; } 73 74 // Turns off keyword mode for the current match. 75 void ClearPopupKeywordMode() const; 76 result()77 const AutocompleteResult& result() const { 78 return autocomplete_controller_->result(); 79 } 80 81 // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it. 82 void DoPreconnect(const AutocompleteMatch& match); 83 84 private: 85 // Weak, it owns us. 86 // TODO(beaudoin): Consider defining a delegate to ease unit testing. 87 OmniboxEditModel* omnibox_edit_model_; 88 89 Profile* profile_; 90 91 OmniboxPopupModel* popup_; 92 93 scoped_ptr<AutocompleteController> autocomplete_controller_; 94 95 // TODO(beaudoin): This AutocompleteMatch is used to let the OmniboxEditModel 96 // know what it should display. Not every field is required for that purpose, 97 // but the ones specifically needed are unclear. We should therefore spend 98 // some time to extract these fields and use a tighter structure here. 99 AutocompleteMatch current_match_; 100 101 DISALLOW_COPY_AND_ASSIGN(OmniboxController); 102 }; 103 104 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_ 105