Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / app_list / views / search_box_view.h
bloba2e3c8ae5f69159fa858e78e6cd30291e544ee4c
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 bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
61 private:
62 // Updates model text and selection model with current Textfield info.
63 void UpdateModel();
65 // Fires query change notification.
66 void NotifyQueryChanged();
68 // Overridden from views::TextfieldController:
69 virtual void ContentsChanged(views::Textfield* sender,
70 const base::string16& new_contents) OVERRIDE;
71 virtual bool HandleKeyEvent(views::Textfield* sender,
72 const ui::KeyEvent& key_event) OVERRIDE;
74 // Overridden from views::ButtonListener:
75 virtual void ButtonPressed(views::Button* sender,
76 const ui::Event& event) OVERRIDE;
78 // Overridden from views::MenuButtonListener:
79 virtual void OnMenuButtonClicked(View* source,
80 const gfx::Point& point) OVERRIDE;
82 // Overridden from SearchBoxModelObserver:
83 virtual void IconChanged() OVERRIDE;
84 virtual void SpeechRecognitionButtonPropChanged() OVERRIDE;
85 virtual void HintTextChanged() OVERRIDE;
86 virtual void SelectionModelChanged() OVERRIDE;
87 virtual void TextChanged() OVERRIDE;
89 // Overridden from SpeechUIModelObserver:
90 virtual void OnSpeechRecognitionStateChanged(
91 SpeechRecognitionState new_state) OVERRIDE;
93 SearchBoxViewDelegate* delegate_; // Not owned.
94 AppListViewDelegate* view_delegate_; // Not owned.
95 AppListModel* model_; // Owned by the profile-keyed service.
97 scoped_ptr<AppListMenuViews> menu_;
99 views::ImageView* icon_view_; // Owned by views hierarchy.
100 views::ImageButton* speech_button_; // Owned by views hierarchy.
101 views::MenuButton* menu_button_; // Owned by views hierarchy.
102 views::Textfield* search_box_; // Owned by views hierarchy.
103 views::View* contents_view_; // Owned by views hierarchy.
105 DISALLOW_COPY_AND_ASSIGN(SearchBoxView);
108 } // namespace app_list
110 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_