| 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_SEARCH_RESULT_LIST_VIEW_H_ | 5 #ifndef UI_APP_LIST_SEARCH_RESULT_LIST_VIEW_H_ |
| 6 #define UI_APP_LIST_SEARCH_RESULT_LIST_VIEW_H_ | 6 #define UI_APP_LIST_SEARCH_RESULT_LIST_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "ui/app_list/app_list_model.h" | 10 #include "ui/app_list/app_list_model.h" |
| 11 #include "ui/app_list/search_result_view_delegate.h" |
| 11 #include "ui/base/models/list_model_observer.h" | 12 #include "ui/base/models/list_model_observer.h" |
| 12 #include "ui/views/controls/button/button.h" | |
| 13 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 14 | 14 |
| 15 namespace app_list { | 15 namespace app_list { |
| 16 | 16 |
| 17 class SearchResultListViewDelegate; | 17 class SearchResultListViewDelegate; |
| 18 class SearchResultView; | 18 class SearchResultView; |
| 19 | 19 |
| 20 // SearchResultListView displays AppListModel::SearchResults with a list of | 20 // SearchResultListView displays AppListModel::SearchResults with a list of |
| 21 // SearchResultView. | 21 // SearchResultView. |
| 22 class SearchResultListView : public views::View, | 22 class SearchResultListView : public views::View, |
| 23 public views::ButtonListener, | 23 public ui::ListModelObserver, |
| 24 public ui::ListModelObserver { | 24 public SearchResultViewDelegate { |
| 25 public: | 25 public: |
| 26 explicit SearchResultListView(SearchResultListViewDelegate* delegate); | 26 explicit SearchResultListView(SearchResultListViewDelegate* delegate); |
| 27 virtual ~SearchResultListView(); | 27 virtual ~SearchResultListView(); |
| 28 | 28 |
| 29 void SetResults(AppListModel::SearchResults* results); | 29 void SetResults(AppListModel::SearchResults* results); |
| 30 | 30 |
| 31 void SetSelectedIndex(int selected_index); | 31 void SetSelectedIndex(int selected_index); |
| 32 | 32 |
| 33 bool IsResultViewSelected(const SearchResultView* result_view) const; | 33 bool IsResultViewSelected(const SearchResultView* result_view) const; |
| 34 | 34 |
| 35 // Overridden from views::View: | 35 // Overridden from views::View: |
| 36 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 36 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 // Helper function to get SearchResultView at given |index|. | 39 // Helper function to get SearchResultView at given |index|. |
| 40 SearchResultView* GetResultViewAt(int index); | 40 SearchResultView* GetResultViewAt(int index); |
| 41 | 41 |
| 42 // Updates UI with model. | 42 // Updates UI with model. |
| 43 void Update(); | 43 void Update(); |
| 44 | 44 |
| 45 // Schedules an Update call using |update_factory_|. Do nothing if there is a | 45 // Schedules an Update call using |update_factory_|. Do nothing if there is a |
| 46 // pending call. | 46 // pending call. |
| 47 void ScheduleUpdate(); | 47 void ScheduleUpdate(); |
| 48 | 48 |
| 49 // Overridden from views::ButtonListener: | |
| 50 virtual void ButtonPressed(views::Button* sender, | |
| 51 const ui::Event& event) OVERRIDE; | |
| 52 | |
| 53 // Overridden from ListModelObserver: | 49 // Overridden from ListModelObserver: |
| 54 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; | 50 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; |
| 55 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; | 51 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; |
| 56 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE; | 52 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE; |
| 57 | 53 |
| 54 // Overridden from SearchResultViewDelegate: |
| 55 virtual void SearchResultActivated(SearchResultView* view, |
| 56 const ui::Event& event) OVERRIDE; |
| 57 virtual void SearchResultActionActivated(SearchResultView* view, |
| 58 int action_index, |
| 59 const ui::Event& event) OVERRIDE; |
| 60 |
| 58 SearchResultListViewDelegate* delegate_; // Not owned. | 61 SearchResultListViewDelegate* delegate_; // Not owned. |
| 59 AppListModel::SearchResults* results_; // Owned by AppListModel. | 62 AppListModel::SearchResults* results_; // Owned by AppListModel. |
| 60 | 63 |
| 61 int last_visible_index_; | 64 int last_visible_index_; |
| 62 int selected_index_; | 65 int selected_index_; |
| 63 | 66 |
| 64 // The factory that consolidates multiple Update calls into one. | 67 // The factory that consolidates multiple Update calls into one. |
| 65 base::WeakPtrFactory<SearchResultListView> update_factory_; | 68 base::WeakPtrFactory<SearchResultListView> update_factory_; |
| 66 | 69 |
| 67 DISALLOW_COPY_AND_ASSIGN(SearchResultListView); | 70 DISALLOW_COPY_AND_ASSIGN(SearchResultListView); |
| 68 }; | 71 }; |
| 69 | 72 |
| 70 } // namespace app_ist | 73 } // namespace app_ist |
| 71 | 74 |
| 72 #endif // UI_APP_LIST_SEARCH_RESULT_LIST_VIEW_H_ | 75 #endif // UI_APP_LIST_SEARCH_RESULT_LIST_VIEW_H_ |
| OLD | NEW |