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