Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / start_page_view.h
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 AppListViewDelegateObserver {
29  public:
30   StartPageView(AppListMainView* app_list_main_view,
31                 AppListViewDelegate* view_delegate);
32   virtual ~StartPageView();
33
34   void Reset();
35   void ShowSearchResults();
36
37   bool IsShowingSearchResults() const;
38
39   void UpdateForTesting();
40
41   const std::vector<TileItemView*>& tile_views() const { return tile_views_; }
42   SearchBoxView* dummy_search_box_view() { return search_box_view_; }
43
44   // Overridden from views::View:
45   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
46   virtual void Layout() OVERRIDE;
47
48  private:
49   enum ShowState {
50     SHOW_START_PAGE,
51     SHOW_SEARCH_RESULTS,
52   };
53
54   void InitInstantContainer();
55   void InitTilesContainer();
56
57   void SetShowState(ShowState show_state);
58   void SetModel(AppListModel* model);
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
67   // Overridden from SearchBoxViewDelegate:
68   virtual void QueryChanged(SearchBoxView* sender) OVERRIDE;
69
70   // Overridden from AppListViewDelegateObserver:
71   virtual void OnProfilesChanged() OVERRIDE;
72
73   // Overridden from ui::ListModelObserver:
74   virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE;
75   virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE;
76   virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE;
77   virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE;
78
79   // The parent view of ContentsView which is the parent of this view.
80   AppListMainView* app_list_main_view_;
81
82   AppListModel::SearchResults*
83       search_results_model_;  // Owned by AppListSyncableService.
84
85   AppListViewDelegate* view_delegate_;  // Owned by AppListView.
86
87   SearchBoxView* search_box_view_;      // Owned by views hierarchy.
88   SearchResultListView* results_view_;  // Owned by views hierarchy.
89   views::View* instant_container_;  // Owned by views hierarchy.
90   views::View* tiles_container_;    // Owned by views hierarchy.
91
92   std::vector<TileItemView*> tile_views_;
93
94   ShowState show_state_;
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
101   DISALLOW_COPY_AND_ASSIGN(StartPageView);
102 };
103
104 }  // namespace app_list
105
106 #endif  // UI_APP_LIST_VIEWS_START_PAGE_VIEW_H_