Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / app_list / views / search_box_view.h
blob82fc162fa7a80f985c5a02378e4ceafff21c3e4f
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/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"
18 namespace views {
19 class ImageView;
20 class MenuButton;
21 class Textfield;
22 } // namespace views
24 namespace app_list {
26 // Possible locations for partial keyboard focus (but note that the search
27 // box always handles typing).
28 enum SearchBoxFocus {
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;
36 class AppListModel;
37 class AppListViewDelegate;
38 class SearchBoxModel;
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 {
52 public:
53 SearchBoxView(SearchBoxViewDelegate* delegate,
54 AppListViewDelegate* view_delegate);
55 ~SearchBoxView() override;
57 void ModelChanged();
58 bool HasSearch() const;
59 void ClearSearch();
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 // Overridden from views::View:
84 gfx::Size GetPreferredSize() const override;
85 bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
86 void OnEnabledChanged() override;
88 private:
89 // Updates model text and selection model with current Textfield info.
90 void UpdateModel();
92 // Fires query change notification.
93 void NotifyQueryChanged();
95 // Overridden from views::TextfieldController:
96 void ContentsChanged(views::Textfield* sender,
97 const base::string16& new_contents) override;
98 bool HandleKeyEvent(views::Textfield* sender,
99 const ui::KeyEvent& key_event) override;
101 // Overridden from views::ButtonListener:
102 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
104 // Overridden from views::MenuButtonListener:
105 void OnMenuButtonClicked(View* source, const gfx::Point& point) override;
107 // Overridden from SearchBoxModelObserver:
108 void IconChanged() override;
109 void SpeechRecognitionButtonPropChanged() override;
110 void HintTextChanged() override;
111 void SelectionModelChanged() override;
112 void TextChanged() override;
114 // Overridden from SpeechUIModelObserver:
115 void OnSpeechRecognitionStateChanged(
116 SpeechRecognitionState new_state) override;
118 SearchBoxViewDelegate* delegate_; // Not owned.
119 AppListViewDelegate* view_delegate_; // Not owned.
120 AppListModel* model_; // Owned by the profile-keyed service.
122 scoped_ptr<AppListMenuViews> menu_;
124 views::View* content_container_; // Owned by views hierarchy.
125 views::ImageView* icon_view_; // Owned by views hierarchy.
126 SearchBoxImageButton* back_button_; // Owned by views hierarchy.
127 SearchBoxImageButton* speech_button_; // Owned by views hierarchy.
128 views::MenuButton* menu_button_; // Owned by views hierarchy.
129 views::Textfield* search_box_; // Owned by views hierarchy.
130 views::View* contents_view_; // Owned by views hierarchy.
132 SearchBoxFocus focused_view_; // Which element has TAB'd focus.
134 DISALLOW_COPY_AND_ASSIGN(SearchBoxView);
137 } // namespace app_list
139 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_