| 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 "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/app_list/search_box_model_observer.h" | 11 #include "ui/app_list/search_box_model_observer.h" |
| 12 #include "ui/app_list/speech_ui_model_observer.h" | 12 #include "ui/app_list/speech_ui_model_observer.h" |
| 13 #include "ui/gfx/shadow_value.h" | 13 #include "ui/gfx/shadow_value.h" |
| 14 #include "ui/views/controls/button/image_button.h" | 14 #include "ui/views/controls/button/image_button.h" |
| 15 #include "ui/views/controls/button/menu_button_listener.h" | |
| 16 #include "ui/views/controls/textfield/textfield_controller.h" | 15 #include "ui/views/controls/textfield/textfield_controller.h" |
| 17 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
| 18 | 17 |
| 19 namespace views { | 18 namespace views { |
| 20 class ImageView; | 19 class ImageView; |
| 21 class MenuButton; | |
| 22 class Textfield; | 20 class Textfield; |
| 23 } // namespace views | 21 } // namespace views |
| 24 | 22 |
| 25 namespace app_list { | 23 namespace app_list { |
| 26 | 24 |
| 27 // Possible locations for partial keyboard focus (but note that the search | 25 // Possible locations for partial keyboard focus (but note that the search |
| 28 // box always handles typing). | 26 // box always handles typing). |
| 29 enum SearchBoxFocus { | 27 enum SearchBoxFocus { |
| 30 FOCUS_BACK_BUTTON, // Back button, only responds to ENTER | 28 FOCUS_BACK_BUTTON, // Back button, only responds to ENTER |
| 31 FOCUS_SEARCH_BOX, // Nothing else has partial focus | 29 FOCUS_SEARCH_BOX, // Nothing else has partial focus |
| 32 FOCUS_MIC_BUTTON, // Mic button, only responds to ENTER | 30 FOCUS_MIC_BUTTON, // Mic button, only responds to ENTER |
| 33 FOCUS_CONTENTS_VIEW, // Something outside the SearchBox is selected | 31 FOCUS_CONTENTS_VIEW, // Something outside the SearchBox is selected |
| 34 }; | 32 }; |
| 35 | 33 |
| 36 class AppListMenuViews; | |
| 37 class AppListModel; | 34 class AppListModel; |
| 38 class AppListViewDelegate; | 35 class AppListViewDelegate; |
| 39 class SearchBoxModel; | 36 class SearchBoxModel; |
| 40 class SearchBoxViewDelegate; | 37 class SearchBoxViewDelegate; |
| 41 class SearchBoxImageButton; | 38 class SearchBoxImageButton; |
| 42 | 39 |
| 43 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data | 40 // SearchBoxView consists of an icon and a Textfield. SearchBoxModel is its data |
| 44 // model that controls what icon to display, what placeholder text to use for | 41 // model that controls what icon to display, what placeholder text to use for |
| 45 // Textfield. The text and selection model part could be set to change the | 42 // Textfield. The text and selection model part could be set to change the |
| 46 // contents and selection model of the Textfield. | 43 // contents and selection model of the Textfield. |
| 47 class APP_LIST_EXPORT SearchBoxView : public views::View, | 44 class APP_LIST_EXPORT SearchBoxView : public views::View, |
| 48 public views::TextfieldController, | 45 public views::TextfieldController, |
| 49 public views::ButtonListener, | 46 public views::ButtonListener, |
| 50 public views::MenuButtonListener, | |
| 51 public SearchBoxModelObserver, | 47 public SearchBoxModelObserver, |
| 52 public SpeechUIModelObserver { | 48 public SpeechUIModelObserver { |
| 53 public: | 49 public: |
| 54 SearchBoxView(SearchBoxViewDelegate* delegate, | 50 SearchBoxView(SearchBoxViewDelegate* delegate, |
| 55 AppListViewDelegate* view_delegate); | 51 AppListViewDelegate* view_delegate); |
| 56 ~SearchBoxView() override; | 52 ~SearchBoxView() override; |
| 57 | 53 |
| 58 void ModelChanged(); | 54 void ModelChanged(); |
| 59 bool HasSearch() const; | 55 bool HasSearch() const; |
| 60 void ClearSearch(); | 56 void ClearSearch(); |
| 61 void InvalidateMenu(); | |
| 62 | 57 |
| 63 // Sets the shadow border of the search box. | 58 // Sets the shadow border of the search box. |
| 64 void SetShadow(const gfx::ShadowValue& shadow); | 59 void SetShadow(const gfx::ShadowValue& shadow); |
| 65 | 60 |
| 66 // Returns the bounds to use for the view (including the shadow) given the | 61 // Returns the bounds to use for the view (including the shadow) given the |
| 67 // desired bounds of the search box contents. | 62 // desired bounds of the search box contents. |
| 68 gfx::Rect GetViewBoundsForSearchBoxContentsBounds( | 63 gfx::Rect GetViewBoundsForSearchBoxContentsBounds( |
| 69 const gfx::Rect& rect) const; | 64 const gfx::Rect& rect) const; |
| 70 | 65 |
| 71 views::ImageButton* back_button(); | 66 views::ImageButton* back_button(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 98 | 93 |
| 99 // Overridden from views::TextfieldController: | 94 // Overridden from views::TextfieldController: |
| 100 void ContentsChanged(views::Textfield* sender, | 95 void ContentsChanged(views::Textfield* sender, |
| 101 const base::string16& new_contents) override; | 96 const base::string16& new_contents) override; |
| 102 bool HandleKeyEvent(views::Textfield* sender, | 97 bool HandleKeyEvent(views::Textfield* sender, |
| 103 const ui::KeyEvent& key_event) override; | 98 const ui::KeyEvent& key_event) override; |
| 104 | 99 |
| 105 // Overridden from views::ButtonListener: | 100 // Overridden from views::ButtonListener: |
| 106 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 101 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 107 | 102 |
| 108 // Overridden from views::MenuButtonListener: | |
| 109 void OnMenuButtonClicked(views::MenuButton* source, | |
| 110 const gfx::Point& point, | |
| 111 const ui::Event* event) override; | |
| 112 | |
| 113 // Overridden from SearchBoxModelObserver: | 103 // Overridden from SearchBoxModelObserver: |
| 114 void IconChanged() override; | 104 void IconChanged() override; |
| 115 void SpeechRecognitionButtonPropChanged() override; | 105 void SpeechRecognitionButtonPropChanged() override; |
| 116 void HintTextChanged() override; | 106 void HintTextChanged() override; |
| 117 void SelectionModelChanged() override; | 107 void SelectionModelChanged() override; |
| 118 void TextChanged() override; | 108 void TextChanged() override; |
| 119 | 109 |
| 120 // Overridden from SpeechUIModelObserver: | 110 // Overridden from SpeechUIModelObserver: |
| 121 void OnSpeechRecognitionStateChanged( | 111 void OnSpeechRecognitionStateChanged( |
| 122 SpeechRecognitionState new_state) override; | 112 SpeechRecognitionState new_state) override; |
| 123 | 113 |
| 124 SearchBoxViewDelegate* delegate_; // Not owned. | 114 SearchBoxViewDelegate* delegate_; // Not owned. |
| 125 AppListViewDelegate* view_delegate_; // Not owned. | 115 AppListViewDelegate* view_delegate_; // Not owned. |
| 126 AppListModel* model_; // Owned by the profile-keyed service. | 116 AppListModel* model_; // Owned by the profile-keyed service. |
| 127 | 117 |
| 128 std::unique_ptr<AppListMenuViews> menu_; | |
| 129 | |
| 130 views::View* content_container_; // Owned by views hierarchy. | 118 views::View* content_container_; // Owned by views hierarchy. |
| 131 views::ImageView* icon_view_; // Owned by views hierarchy. | 119 views::ImageView* icon_view_; // Owned by views hierarchy. |
| 132 SearchBoxImageButton* back_button_; // Owned by views hierarchy. | 120 SearchBoxImageButton* back_button_; // Owned by views hierarchy. |
| 133 SearchBoxImageButton* speech_button_; // Owned by views hierarchy. | 121 SearchBoxImageButton* speech_button_; // Owned by views hierarchy. |
| 134 views::MenuButton* menu_button_; // Owned by views hierarchy. | |
| 135 views::Textfield* search_box_; // Owned by views hierarchy. | 122 views::Textfield* search_box_; // Owned by views hierarchy. |
| 136 views::View* contents_view_; // Owned by views hierarchy. | 123 views::View* contents_view_; // Owned by views hierarchy. |
| 137 | 124 |
| 138 SearchBoxFocus focused_view_; // Which element has TAB'd focus. | 125 SearchBoxFocus focused_view_; // Which element has TAB'd focus. |
| 139 | 126 |
| 140 DISALLOW_COPY_AND_ASSIGN(SearchBoxView); | 127 DISALLOW_COPY_AND_ASSIGN(SearchBoxView); |
| 141 }; | 128 }; |
| 142 | 129 |
| 143 } // namespace app_list | 130 } // namespace app_list |
| 144 | 131 |
| 145 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ | 132 #endif // UI_APP_LIST_VIEWS_SEARCH_BOX_VIEW_H_ |
| OLD | NEW |