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