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/gfx/shadow_value.h"
13 #include "ui/views/controls/button/image_button.h"
14 #include "ui/views/controls/button/menu_button_listener.h"
15 #include "ui/views/controls/textfield/textfield_controller.h"
16 #include "ui/views/view.h"
26 // Possible locations for partial keyboard focus (but note that the search
27 // box always handles typing).
29 FOCUS_BACK_BUTTON
, // Back button, only responds to ENTER
30 FOCUS_SEARCH_BOX
, // Nothing else has partial focus
31 FOCUS_MIC_BUTTON
, // Mic button, only responds to ENTER
32 FOCUS_CONTENTS_VIEW
, // Something outside the SearchBox is selected
35 class AppListMenuViews
;
37 class AppListViewDelegate
;
39 class SearchBoxViewDelegate
;
40 class SearchBoxImageButton
;
42 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data
43 // model that controls what icon to display, what placeholder text to use for
44 // Textfield. The text and selection model part could be set to change the
45 // contents and selection model of the Textfield.
46 class APP_LIST_EXPORT SearchBoxView
: public views::View
,
47 public views::TextfieldController
,
48 public views::ButtonListener
,
49 public views::MenuButtonListener
,
50 public SearchBoxModelObserver
,
51 public SpeechUIModelObserver
{
53 SearchBoxView(SearchBoxViewDelegate
* delegate
,
54 AppListViewDelegate
* view_delegate
);
55 ~SearchBoxView() override
;
58 bool HasSearch() const;
60 void InvalidateMenu();
62 // Sets the shadow border of the search box.
63 void SetShadow(const gfx::ShadowValue
& shadow
);
65 // Returns the bounds to use for the view (including the shadow) given the
66 // desired bounds of the search box contents.
67 gfx::Rect
GetViewBoundsForSearchBoxContentsBounds(
68 const gfx::Rect
& rect
) const;
70 views::ImageButton
* back_button();
71 views::Textfield
* search_box() { return search_box_
; }
73 void set_contents_view(views::View
* contents_view
) {
74 contents_view_
= contents_view
;
77 // Moves focus forward/backwards in response to TAB.
78 bool MoveTabFocus(bool move_backwards
);
80 // Moves focus to contents or SearchBox and unselects buttons.
81 void ResetTabFocus(bool on_contents
);
83 // Sets voice label for Back button depending on whether a folder is open.
84 void SetBackButtonLabel(bool folder
);
86 // Overridden from views::View:
87 gfx::Size
GetPreferredSize() const override
;
88 bool OnMouseWheel(const ui::MouseWheelEvent
& event
) override
;
89 void OnEnabledChanged() override
;
92 // Updates model text and selection model with current Textfield info.
95 // Fires query change notification.
96 void NotifyQueryChanged();
98 // Overridden from views::TextfieldController:
99 void ContentsChanged(views::Textfield
* sender
,
100 const base::string16
& new_contents
) override
;
101 bool HandleKeyEvent(views::Textfield
* sender
,
102 const ui::KeyEvent
& key_event
) override
;
104 // Overridden from views::ButtonListener:
105 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
107 // Overridden from views::MenuButtonListener:
108 void OnMenuButtonClicked(View
* source
, const gfx::Point
& point
) override
;
110 // Overridden from SearchBoxModelObserver:
111 void IconChanged() override
;
112 void SpeechRecognitionButtonPropChanged() override
;
113 void HintTextChanged() override
;
114 void SelectionModelChanged() override
;
115 void TextChanged() override
;
117 // Overridden from SpeechUIModelObserver:
118 void OnSpeechRecognitionStateChanged(
119 SpeechRecognitionState new_state
) override
;
121 SearchBoxViewDelegate
* delegate_
; // Not owned.
122 AppListViewDelegate
* view_delegate_
; // Not owned.
123 AppListModel
* model_
; // Owned by the profile-keyed service.
125 scoped_ptr
<AppListMenuViews
> menu_
;
127 views::View
* content_container_
; // Owned by views hierarchy.
128 views::ImageView
* icon_view_
; // Owned by views hierarchy.
129 SearchBoxImageButton
* back_button_
; // Owned by views hierarchy.
130 SearchBoxImageButton
* speech_button_
; // Owned by views hierarchy.
131 views::MenuButton
* menu_button_
; // Owned by views hierarchy.
132 views::Textfield
* search_box_
; // Owned by views hierarchy.
133 views::View
* contents_view_
; // Owned by views hierarchy.
135 SearchBoxFocus focused_view_
; // Which element has TAB'd focus.
137 DISALLOW_COPY_AND_ASSIGN(SearchBoxView
);
140 } // namespace app_list
142 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_