Views Omnibox: tolerate minor click-to-select-all dragging.
[chromium-blink-merge.git] / ui / app_list / views / search_box_view.h
blob8dd352a5d5ca53682dc6142d2d92ea43de3a0ad9
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 ContentsView;
29 class SearchBoxModel;
30 class SearchBoxViewDelegate;
32 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data
33 // model that controls what icon to display, what placeholder text to use for
34 // Textfield. The text and selection model part could be set to change the
35 // contents and selection model of the Textfield.
36 class SearchBoxView : public views::View,
37 public views::TextfieldController,
38 public views::ButtonListener,
39 public views::MenuButtonListener,
40 public SearchBoxModelObserver,
41 public SpeechUIModelObserver {
42 public:
43 SearchBoxView(SearchBoxViewDelegate* delegate,
44 AppListViewDelegate* view_delegate);
45 virtual ~SearchBoxView();
47 void ModelChanged();
48 bool HasSearch() const;
49 void ClearSearch();
50 void InvalidateMenu();
52 views::Textfield* search_box() { return search_box_; }
54 void set_contents_view(ContentsView* contents_view) {
55 contents_view_ = contents_view;
58 // Overridden from views::View:
59 virtual gfx::Size GetPreferredSize() OVERRIDE;
60 virtual void Layout() OVERRIDE;
61 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
63 private:
64 // Updates model text and selection model with current Textfield info.
65 void UpdateModel();
67 // Fires query change notification.
68 void NotifyQueryChanged();
70 // Overridden from views::TextfieldController:
71 virtual void ContentsChanged(views::Textfield* sender,
72 const base::string16& new_contents) OVERRIDE;
73 virtual bool HandleKeyEvent(views::Textfield* sender,
74 const ui::KeyEvent& key_event) OVERRIDE;
76 // Overridden from views::ButtonListener:
77 virtual void ButtonPressed(views::Button* sender,
78 const ui::Event& event) OVERRIDE;
80 // Overridden from views::MenuButtonListener:
81 virtual void OnMenuButtonClicked(View* source,
82 const gfx::Point& point) OVERRIDE;
84 // Overridden from SearchBoxModelObserver:
85 virtual void IconChanged() OVERRIDE;
86 virtual void SpeechRecognitionButtonPropChanged() OVERRIDE;
87 virtual void HintTextChanged() OVERRIDE;
88 virtual void SelectionModelChanged() OVERRIDE;
89 virtual void TextChanged() OVERRIDE;
91 // Overridden from SpeechUIModelObserver:
92 virtual void OnSpeechRecognitionStateChanged(
93 SpeechRecognitionState new_state) OVERRIDE;
95 SearchBoxViewDelegate* delegate_; // Not owned.
96 AppListViewDelegate* view_delegate_; // Not owned.
97 AppListModel* model_; // Owned by the profile-keyed service.
99 scoped_ptr<AppListMenuViews> menu_;
101 views::ImageView* icon_view_; // Owned by views hierarchy.
102 views::ImageButton* speech_button_; // Owned by views hierarchy.
103 views::MenuButton* menu_button_; // Owned by views hierarchy.
104 views::Textfield* search_box_; // Owned by views hierarchy.
105 ContentsView* contents_view_; // Owned by views hierarchy.
107 DISALLOW_COPY_AND_ASSIGN(SearchBoxView);
110 } // namespace app_list
112 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_