Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / ui / app_list / views / search_box_view.h
blob2f7b4ec710c1ac6b3ce6ab1193decb48a33c1786
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.
5 #ifndef UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_
6 #define UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_
8 #include <string>
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"
17 namespace views {
18 class ImageView;
19 class MenuButton;
20 class Textfield;
21 } // namespace views
23 namespace app_list {
25 class AppListMenuViews;
26 class AppListModel;
27 class AppListViewDelegate;
28 class SearchBoxModel;
29 class SearchBoxViewDelegate;
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();
46 void ModelChanged();
47 bool HasSearch() const;
48 void ClearSearch();
49 void InvalidateMenu();
51 views::Textfield* search_box() { return search_box_; }
53 void set_contents_view(views::View* contents_view) {
54 contents_view_ = contents_view;
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;
62 private:
63 // Updates model text and selection model with current Textfield info.
64 void UpdateModel();
66 // Fires query change notification.
67 void NotifyQueryChanged();
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;
75 // Overridden from views::ButtonListener:
76 virtual void ButtonPressed(views::Button* sender,
77 const ui::Event& event) OVERRIDE;
79 // Overridden from views::MenuButtonListener:
80 virtual void OnMenuButtonClicked(View* source,
81 const gfx::Point& point) OVERRIDE;
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;
90 // Overridden from SpeechUIModelObserver:
91 virtual void OnSpeechRecognitionStateChanged(
92 SpeechRecognitionState new_state) OVERRIDE;
94 SearchBoxViewDelegate* delegate_; // Not owned.
95 AppListViewDelegate* view_delegate_; // Not owned.
96 AppListModel* model_; // Owned by the profile-keyed service.
98 scoped_ptr<AppListMenuViews> menu_;
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.
106 DISALLOW_COPY_AND_ASSIGN(SearchBoxView);
109 } // namespace app_list
111 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_