1 // Copyright (c) 2012 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 UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ 7 8 #include <string> 9 10 #include "ui/app_list/search_box_model_observer.h" 11 #include "ui/app_list/speech_ui_model_observer.h" 12 #include "ui/views/controls/button/image_button.h" 13 #include "ui/views/controls/button/menu_button_listener.h" 14 #include "ui/views/controls/textfield/textfield_controller.h" 15 #include "ui/views/view.h" 16 17 namespace views { 18 class ImageView; 19 class MenuButton; 20 class Textfield; 21 } // namespace views 22 23 namespace app_list { 24 25 class AppListMenuViews; 26 class AppListModel; 27 class AppListViewDelegate; 28 class SearchBoxModel; 29 class SearchBoxViewDelegate; 30 31 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data 32 // model that controls what icon to display, what placeholder text to use for 33 // Textfield. The text and selection model part could be set to change the 34 // contents and selection model of the Textfield. 35 class APP_LIST_EXPORT SearchBoxView : public views::View, 36 public views::TextfieldController, 37 public views::ButtonListener, 38 public views::MenuButtonListener, 39 public SearchBoxModelObserver, 40 public SpeechUIModelObserver { 41 public: 42 SearchBoxView(SearchBoxViewDelegate* delegate, 43 AppListViewDelegate* view_delegate); 44 virtual ~SearchBoxView(); 45 46 void ModelChanged(); 47 bool HasSearch() const; 48 void ClearSearch(); 49 void InvalidateMenu(); 50 51 views::Textfield* search_box() { return search_box_; } 52 53 void set_contents_view(views::View* contents_view) { 54 contents_view_ = contents_view; 55 } 56 57 // Overridden from views::View: 58 virtual gfx::Size GetPreferredSize() const OVERRIDE; 59 virtual void Layout() OVERRIDE; 60 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; 61 62 private: 63 // Updates model text and selection model with current Textfield info. 64 void UpdateModel(); 65 66 // Fires query change notification. 67 void NotifyQueryChanged(); 68 69 // Overridden from views::TextfieldController: 70 virtual void ContentsChanged(views::Textfield* sender, 71 const base::string16& new_contents) OVERRIDE; 72 virtual bool HandleKeyEvent(views::Textfield* sender, 73 const ui::KeyEvent& key_event) OVERRIDE; 74 75 // Overridden from views::ButtonListener: 76 virtual void ButtonPressed(views::Button* sender, 77 const ui::Event& event) OVERRIDE; 78 79 // Overridden from views::MenuButtonListener: 80 virtual void OnMenuButtonClicked(View* source, 81 const gfx::Point& point) OVERRIDE; 82 83 // Overridden from SearchBoxModelObserver: 84 virtual void IconChanged() OVERRIDE; 85 virtual void SpeechRecognitionButtonPropChanged() OVERRIDE; 86 virtual void HintTextChanged() OVERRIDE; 87 virtual void SelectionModelChanged() OVERRIDE; 88 virtual void TextChanged() OVERRIDE; 89 90 // Overridden from SpeechUIModelObserver: 91 virtual void OnSpeechRecognitionStateChanged( 92 SpeechRecognitionState new_state) OVERRIDE; 93 94 SearchBoxViewDelegate* delegate_; // Not owned. 95 AppListViewDelegate* view_delegate_; // Not owned. 96 AppListModel* model_; // Owned by the profile-keyed service. 97 98 scoped_ptr<AppListMenuViews> menu_; 99 100 views::ImageView* icon_view_; // Owned by views hierarchy. 101 views::ImageButton* speech_button_; // Owned by views hierarchy. 102 views::MenuButton* menu_button_; // Owned by views hierarchy. 103 views::Textfield* search_box_; // Owned by views hierarchy. 104 views::View* contents_view_; // Owned by views hierarchy. 105 106 DISALLOW_COPY_AND_ASSIGN(SearchBoxView); 107 }; 108 109 } // namespace app_list 110 111 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ 112