1 // Copyright 2013 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.
5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_
6 #define UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_
10 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h"
13 #include "ui/app_list/app_list_export.h"
14 #include "ui/app_list/views/apps_grid_view_delegate.h"
15 #include "ui/app_list/views/search_box_view_delegate.h"
16 #include "ui/app_list/views/search_result_list_view_delegate.h"
17 #include "ui/views/view.h"
27 class AppListViewDelegate
;
28 class ApplicationDragAndDropHost
;
30 class PaginationModel
;
33 // AppListMainView contains the normal view of the app list, which is shown
34 // when the user is signed in.
35 class APP_LIST_EXPORT AppListMainView
: public views::View
,
36 public AppsGridViewDelegate
,
37 public SearchBoxViewDelegate
,
38 public SearchResultListViewDelegate
{
40 // Takes ownership of |delegate|.
41 explicit AppListMainView(AppListViewDelegate
* delegate
,
42 PaginationModel
* pagination_model
,
43 gfx::NativeView parent
);
44 virtual ~AppListMainView();
46 void ShowAppListWhenReady();
54 SearchBoxView
* search_box_view() const { return search_box_view_
; }
56 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
57 // operations outside the application list.
58 void SetDragAndDropHostOfCurrentAppList(
59 ApplicationDragAndDropHost
* drag_and_drop_host
);
61 ContentsView
* contents_view() { return contents_view_
; }
66 void AddContentsView();
68 // Loads icon image for the apps in the selected page of |pagination_model_|.
69 // |parent| is used to determine the image scale factor to use.
70 void PreloadIcons(gfx::NativeView parent
);
72 // Invoked when |icon_loading_wait_timer_| fires.
73 void OnIconLoadingWaitTimer();
75 // Invoked from an IconLoader when icon loading is finished.
76 void OnItemIconLoaded(IconLoader
* loader
);
78 // Overridden from AppsGridViewDelegate:
79 virtual void ActivateApp(AppListItem
* item
, int event_flags
) OVERRIDE
;
80 virtual void GetShortcutPathForApp(
81 const std::string
& app_id
,
82 const base::Callback
<void(const base::FilePath
&)>& callback
) OVERRIDE
;
84 // Overridden from SearchBoxViewDelegate:
85 virtual void QueryChanged(SearchBoxView
* sender
) OVERRIDE
;
87 // Overridden from SearchResultListViewDelegate:
88 virtual void OpenResult(SearchResult
* result
,
89 int event_flags
) OVERRIDE
;
90 virtual void InvokeResultAction(SearchResult
* result
,
92 int event_flags
) OVERRIDE
;
93 virtual void OnResultInstalled(SearchResult
* result
) OVERRIDE
;
94 virtual void OnResultUninstalled(SearchResult
* result
) OVERRIDE
;
96 AppListViewDelegate
* delegate_
; // Owned by parent view (AppListView).
97 PaginationModel
* pagination_model_
; // Owned by AppListController.
98 AppListModel
* model_
; // Unowned; ownership is handled by |delegate_|.
100 SearchBoxView
* search_box_view_
; // Owned by views hierarchy.
101 ContentsView
* contents_view_
; // Owned by views hierarchy.
103 // A timer that fires when maximum allowed time to wait for icon loading has
105 base::OneShotTimer
<AppListMainView
> icon_loading_wait_timer_
;
107 ScopedVector
<IconLoader
> pending_icon_loaders_
;
109 base::WeakPtrFactory
<AppListMainView
> weak_ptr_factory_
;
111 DISALLOW_COPY_AND_ASSIGN(AppListMainView
);
114 } // namespace app_list
116 #endif // UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_