OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ | 5 #ifndef UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ |
6 #define UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ | 6 #define UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ui/app_list/search_box_model_observer.h" | 10 #include "ui/app_list/search_box_model_observer.h" |
| 11 #include "ui/app_list/views/app_list_menu_views.h" |
| 12 #include "ui/views/controls/button/menu_button_listener.h" |
11 #include "ui/views/controls/textfield/textfield_controller.h" | 13 #include "ui/views/controls/textfield/textfield_controller.h" |
12 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
13 | 15 |
14 namespace views { | 16 namespace views { |
15 class ImageView; | 17 class ImageView; |
| 18 class MenuButton; |
16 class Textfield; | 19 class Textfield; |
17 } // namespace views | 20 } // namespace views |
18 | 21 |
19 namespace app_list { | 22 namespace app_list { |
20 | 23 |
| 24 class AppListViewDelegate; |
21 class SearchBoxModel; | 25 class SearchBoxModel; |
22 class SearchBoxViewDelegate; | 26 class SearchBoxViewDelegate; |
23 | 27 |
24 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data | 28 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data |
25 // model that controls what icon to display, what placeholder text to use for | 29 // model that controls what icon to display, what placeholder text to use for |
26 // Textfield. The text and selection model part could be set to change the | 30 // Textfield. The text and selection model part could be set to change the |
27 // contents and selection model of the Textfield. | 31 // contents and selection model of the Textfield. |
28 class SearchBoxView : public views::View, | 32 class SearchBoxView : public views::View, |
29 public views::TextfieldController, | 33 public views::TextfieldController, |
| 34 public views::MenuButtonListener, |
30 public SearchBoxModelObserver { | 35 public SearchBoxModelObserver { |
31 public: | 36 public: |
32 explicit SearchBoxView(SearchBoxViewDelegate* delegate); | 37 SearchBoxView(SearchBoxViewDelegate* delegate, |
| 38 AppListViewDelegate* view_delegate); |
33 virtual ~SearchBoxView(); | 39 virtual ~SearchBoxView(); |
34 | 40 |
35 void SetModel(SearchBoxModel* model); | 41 void SetModel(SearchBoxModel* model); |
36 | 42 |
37 views::Textfield* search_box() { return search_box_; } | 43 views::Textfield* search_box() { return search_box_; } |
38 | 44 |
39 void set_contents_view(View* contents_view) { | 45 void set_contents_view(View* contents_view) { |
40 contents_view_ = contents_view; | 46 contents_view_ = contents_view; |
41 } | 47 } |
42 | 48 |
43 // Overridden from views::View: | 49 // Overridden from views::View: |
44 virtual gfx::Size GetPreferredSize() OVERRIDE; | 50 virtual gfx::Size GetPreferredSize() OVERRIDE; |
45 virtual void Layout() OVERRIDE; | 51 virtual void Layout() OVERRIDE; |
46 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; | 52 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; |
47 | 53 |
48 private: | 54 private: |
49 // Updates model text and selection model with current Textfield info. | 55 // Updates model text and selection model with current Textfield info. |
50 void UpdateModel(); | 56 void UpdateModel(); |
51 | 57 |
52 // Fires query change notification. | 58 // Fires query change notification. |
53 void NotifyQueryChanged(); | 59 void NotifyQueryChanged(); |
54 | 60 |
55 // Overridden from views::TextfieldController: | 61 // Overridden from views::TextfieldController: |
56 virtual void ContentsChanged(views::Textfield* sender, | 62 virtual void ContentsChanged(views::Textfield* sender, |
57 const string16& new_contents) OVERRIDE; | 63 const string16& new_contents) OVERRIDE; |
58 virtual bool HandleKeyEvent(views::Textfield* sender, | 64 virtual bool HandleKeyEvent(views::Textfield* sender, |
59 const ui::KeyEvent& key_event) OVERRIDE; | 65 const ui::KeyEvent& key_event) OVERRIDE; |
60 | 66 |
| 67 // Overridden from views::MenuButtonListener: |
| 68 virtual void OnMenuButtonClicked(View* source, |
| 69 const gfx::Point& point) OVERRIDE; |
| 70 |
61 // Overridden from SearchBoxModelObserver: | 71 // Overridden from SearchBoxModelObserver: |
62 virtual void IconChanged() OVERRIDE; | 72 virtual void IconChanged() OVERRIDE; |
63 virtual void HintTextChanged() OVERRIDE; | 73 virtual void HintTextChanged() OVERRIDE; |
64 virtual void SelectionModelChanged() OVERRIDE; | 74 virtual void SelectionModelChanged() OVERRIDE; |
65 virtual void TextChanged() OVERRIDE; | 75 virtual void TextChanged() OVERRIDE; |
66 virtual void UserIconChanged() OVERRIDE; | |
67 virtual void UserIconTooltipChanged() OVERRIDE; | |
68 virtual void UserIconEnabledChanged() OVERRIDE; | |
69 | 76 |
70 SearchBoxViewDelegate* delegate_; // Not owned. | 77 SearchBoxViewDelegate* delegate_; // Not owned. |
71 SearchBoxModel* model_; // Owned by AppListModel. | 78 SearchBoxModel* model_; // Owned by AppListModel. |
72 | 79 |
| 80 AppListMenuViews menu_; |
| 81 |
73 views::ImageView* icon_view_; // Owned by views hierarchy. | 82 views::ImageView* icon_view_; // Owned by views hierarchy. |
74 views::ImageView* user_icon_view_; // Owned by views hierarchy. | 83 views::MenuButton* menu_button_; // Owned by views hierarchy. |
75 views::Textfield* search_box_; // Owned by views hierarchy. | 84 views::Textfield* search_box_; // Owned by views hierarchy. |
76 views::View* contents_view_; // Owned by views hierarchy. | 85 views::View* contents_view_; // Owned by views hierarchy. |
77 | 86 |
78 DISALLOW_COPY_AND_ASSIGN(SearchBoxView); | 87 DISALLOW_COPY_AND_ASSIGN(SearchBoxView); |
79 }; | 88 }; |
80 | 89 |
81 } // namespace app_list | 90 } // namespace app_list |
82 | 91 |
83 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ | 92 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ |
OLD | NEW |