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();
56 void OnContentsViewShowStateChanged();
58 void OnStartPageSearchButtonPressed();
60 SearchBoxView
* search_box_view() const { return search_box_view_
; }
62 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
63 // operations outside the application list.
64 void SetDragAndDropHostOfCurrentAppList(
65 ApplicationDragAndDropHost
* drag_and_drop_host
);
67 ContentsView
* contents_view() const { return contents_view_
; }
69 // Returns true if the app list should be centered and in landscape mode.
70 bool ShouldCenterWindow() const;
75 void AddContentsView();
77 // Loads icon image for the apps in the selected page of |pagination_model_|.
78 // |parent| is used to determine the image scale factor to use.
79 void PreloadIcons(gfx::NativeView parent
);
81 // Invoked when |icon_loading_wait_timer_| fires.
82 void OnIconLoadingWaitTimer();
84 // Invoked from an IconLoader when icon loading is finished.
85 void OnItemIconLoaded(IconLoader
* loader
);
87 // Overridden from views::View:
88 virtual void ChildVisibilityChanged(views::View
* child
) OVERRIDE
;
90 // Overridden from AppsGridViewDelegate:
91 virtual void ActivateApp(AppListItem
* item
, int event_flags
) OVERRIDE
;
92 virtual void GetShortcutPathForApp(
93 const std::string
& app_id
,
94 const base::Callback
<void(const base::FilePath
&)>& callback
) OVERRIDE
;
96 // Overridden from SearchBoxViewDelegate:
97 virtual void QueryChanged(SearchBoxView
* sender
) OVERRIDE
;
99 // Overridden from SearchResultListViewDelegate:
100 virtual void OnResultInstalled(SearchResult
* result
) OVERRIDE
;
101 virtual void OnResultUninstalled(SearchResult
* result
) OVERRIDE
;
103 AppListViewDelegate
* delegate_
; // Owned by parent view (AppListView).
104 PaginationModel
* pagination_model_
; // Owned by AppListController.
105 AppListModel
* model_
; // Unowned; ownership is handled by |delegate_|.
107 SearchBoxView
* search_box_view_
; // Owned by views hierarchy.
108 ContentsView
* contents_view_
; // Owned by views hierarchy.
110 // A timer that fires when maximum allowed time to wait for icon loading has
112 base::OneShotTimer
<AppListMainView
> icon_loading_wait_timer_
;
114 ScopedVector
<IconLoader
> pending_icon_loaders_
;
116 base::WeakPtrFactory
<AppListMainView
> weak_ptr_factory_
;
118 DISALLOW_COPY_AND_ASSIGN(AppListMainView
);
121 } // namespace app_list
123 #endif // UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_