OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_START_PAGE_VIEW_H_ | 5 #ifndef UI_APP_LIST_VIEWS_START_PAGE_VIEW_H_ |
6 #define UI_APP_LIST_VIEWS_START_PAGE_VIEW_H_ | 6 #define UI_APP_LIST_VIEWS_START_PAGE_VIEW_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "ui/app_list/app_list_model_observer.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "ui/app_list/app_list_export.h" |
| 11 #include "ui/app_list/app_list_model.h" |
10 #include "ui/app_list/app_list_view_delegate_observer.h" | 12 #include "ui/app_list/app_list_view_delegate_observer.h" |
11 #include "ui/app_list/views/search_box_view_delegate.h" | 13 #include "ui/app_list/views/search_box_view_delegate.h" |
| 14 #include "ui/base/models/list_model_observer.h" |
12 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
13 | 16 |
14 namespace app_list { | 17 namespace app_list { |
15 | 18 |
16 class AppListMainView; | 19 class AppListMainView; |
17 class AppListModel; | |
18 class AppListViewDelegate; | 20 class AppListViewDelegate; |
19 class SearchResultListView; | 21 class SearchResultListView; |
20 class TileItemView; | 22 class TileItemView; |
21 | 23 |
22 // The start page for the experimental app list. | 24 // The start page for the experimental app list. |
23 class StartPageView : public views::View, | 25 class APP_LIST_EXPORT StartPageView : public views::View, |
24 public SearchBoxViewDelegate, | 26 public ui::ListModelObserver, |
25 public AppListViewDelegateObserver, | 27 public SearchBoxViewDelegate, |
26 public AppListModelObserver { | 28 public AppListViewDelegateObserver { |
27 public: | 29 public: |
28 StartPageView(AppListMainView* app_list_main_view, | 30 StartPageView(AppListMainView* app_list_main_view, |
29 AppListViewDelegate* view_delegate); | 31 AppListViewDelegate* view_delegate); |
30 virtual ~StartPageView(); | 32 virtual ~StartPageView(); |
31 | 33 |
32 void Reset(); | 34 void Reset(); |
33 void ShowSearchResults(); | 35 void ShowSearchResults(); |
34 | 36 |
35 bool IsShowingSearchResults() const; | 37 bool IsShowingSearchResults() const; |
36 | 38 |
| 39 void UpdateForTesting(); |
| 40 |
37 const std::vector<TileItemView*>& tile_views() const { return tile_views_; } | 41 const std::vector<TileItemView*>& tile_views() const { return tile_views_; } |
38 SearchBoxView* dummy_search_box_view() { return search_box_view_; } | 42 SearchBoxView* dummy_search_box_view() { return search_box_view_; } |
39 | 43 |
40 // Overridden from views::View: | 44 // Overridden from views::View: |
41 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 45 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
42 virtual void Layout() OVERRIDE; | 46 virtual void Layout() OVERRIDE; |
43 | 47 |
44 private: | 48 private: |
45 enum ShowState { | 49 enum ShowState { |
46 SHOW_START_PAGE, | 50 SHOW_START_PAGE, |
47 SHOW_SEARCH_RESULTS, | 51 SHOW_SEARCH_RESULTS, |
48 }; | 52 }; |
49 | 53 |
50 void InitInstantContainer(); | 54 void InitInstantContainer(); |
51 void InitTilesContainer(); | 55 void InitTilesContainer(); |
52 | 56 |
53 void SetShowState(ShowState show_state); | 57 void SetShowState(ShowState show_state); |
54 void SetModel(AppListModel* model); | 58 void SetModel(AppListModel* model); |
55 | 59 |
| 60 // Updates UI with model. |
| 61 void Update(); |
| 62 |
| 63 // Schedules an Update() call using |update_factory_|. Does nothing if there |
| 64 // is a pending call. |
| 65 void ScheduleUpdate(); |
| 66 |
56 // Overridden from SearchBoxViewDelegate: | 67 // Overridden from SearchBoxViewDelegate: |
57 virtual void QueryChanged(SearchBoxView* sender) OVERRIDE; | 68 virtual void QueryChanged(SearchBoxView* sender) OVERRIDE; |
58 | 69 |
59 // Overridden from AppListViewDelegateObserver: | 70 // Overridden from AppListViewDelegateObserver: |
60 virtual void OnProfilesChanged() OVERRIDE; | 71 virtual void OnProfilesChanged() OVERRIDE; |
61 | 72 |
62 // Overridden from AppListModelObserver: | 73 // Overridden from ui::ListModelObserver: |
63 virtual void OnAppListModelStatusChanged() OVERRIDE; | 74 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE; |
64 virtual void OnAppListItemAdded(AppListItem* item) OVERRIDE; | 75 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE; |
65 virtual void OnAppListItemDeleted() OVERRIDE; | 76 virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE; |
66 virtual void OnAppListItemUpdated(AppListItem* item) OVERRIDE; | 77 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE; |
67 | 78 |
68 // The parent view of ContentsView which is the parent of this view. | 79 // The parent view of ContentsView which is the parent of this view. |
69 AppListMainView* app_list_main_view_; | 80 AppListMainView* app_list_main_view_; |
70 | 81 |
71 AppListModel* model_; // Owned by AppListSyncableService. | 82 AppListModel::SearchResults* |
| 83 search_results_model_; // Owned by AppListSyncableService. |
72 | 84 |
73 AppListViewDelegate* view_delegate_; // Owned by AppListView. | 85 AppListViewDelegate* view_delegate_; // Owned by AppListView. |
74 | 86 |
75 SearchBoxView* search_box_view_; // Owned by views hierarchy. | 87 SearchBoxView* search_box_view_; // Owned by views hierarchy. |
76 SearchResultListView* results_view_; // Owned by views hierarchy. | 88 SearchResultListView* results_view_; // Owned by views hierarchy. |
77 views::View* instant_container_; // Owned by views hierarchy. | 89 views::View* instant_container_; // Owned by views hierarchy. |
78 views::View* tiles_container_; // Owned by views hierarchy. | 90 views::View* tiles_container_; // Owned by views hierarchy. |
79 | 91 |
80 std::vector<TileItemView*> tile_views_; | 92 std::vector<TileItemView*> tile_views_; |
81 | 93 |
82 ShowState show_state_; | 94 ShowState show_state_; |
83 | 95 |
| 96 // ScheduleUpdate() generates a single weak pointer; if one exists then an |
| 97 // update is pending. Further calls to ScheduleUpdate() will have no effect. |
| 98 // Once the Update() completes, the weak pointer is invalidated. |
| 99 base::WeakPtrFactory<StartPageView> update_factory_; |
| 100 |
84 DISALLOW_COPY_AND_ASSIGN(StartPageView); | 101 DISALLOW_COPY_AND_ASSIGN(StartPageView); |
85 }; | 102 }; |
86 | 103 |
87 } // namespace app_list | 104 } // namespace app_list |
88 | 105 |
89 #endif // UI_APP_LIST_VIEWS_START_PAGE_VIEW_H_ | 106 #endif // UI_APP_LIST_VIEWS_START_PAGE_VIEW_H_ |
OLD | NEW |