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_
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"
25 class AppListMenuViews
;
27 class AppListViewDelegate
;
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
{
42 SearchBoxView(SearchBoxViewDelegate
* delegate
,
43 AppListViewDelegate
* view_delegate
);
44 virtual ~SearchBoxView();
47 bool HasSearch() const;
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
;
62 // Updates model text and selection model with current Textfield info.
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_