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/app_list_model_observer.h"
15 #include "ui/app_list/views/apps_grid_view_delegate.h"
16 #include "ui/app_list/views/search_box_view_delegate.h"
17 #include "ui/app_list/views/search_result_list_view_delegate.h"
18 #include "ui/views/view.h"
28 class AppListViewDelegate
;
29 class ApplicationDragAndDropHost
;
31 class PaginationModel
;
34 // AppListMainView contains the normal view of the app list, which is shown
35 // when the user is signed in.
36 class APP_LIST_EXPORT AppListMainView
: public views::View
,
37 public AppsGridViewDelegate
,
38 public AppListModelObserver
,
39 public SearchBoxViewDelegate
,
40 public SearchResultListViewDelegate
{
42 explicit AppListMainView(AppListViewDelegate
* delegate
);
43 ~AppListMainView() override
;
45 void Init(gfx::NativeView parent
,
46 int initial_apps_page
,
47 SearchBoxView
* search_box_view
);
49 void ShowAppListWhenReady();
59 SearchBoxView
* search_box_view() const { return search_box_view_
; }
61 // Gets the invisible widget that sits partly over the bottom of the app list,
62 // covering the collapsed-state custom page. May return nullptr, if the widget
63 // has not been initialized or has already been destroyed.
64 views::Widget
* GetCustomPageClickzone() const;
66 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
67 // operations outside the application list.
68 void SetDragAndDropHostOfCurrentAppList(
69 ApplicationDragAndDropHost
* drag_and_drop_host
);
71 ContentsView
* contents_view() const { return contents_view_
; }
72 AppListModel
* model() { return model_
; }
73 AppListViewDelegate
* view_delegate() { return delegate_
; }
75 // Returns true if the app list should be centered and in landscape mode.
76 bool ShouldCenterWindow() const;
78 // Called when the search box's visibility is changed.
79 void NotifySearchBoxVisibilityChanged();
81 // Initialize widgets that live inside the app list's main widget.
84 // Overridden from AppListModelObserver:
85 void OnCustomLauncherPageEnabledStateChanged(bool enabled
) override
;
90 // Adds the ContentsView.
91 void AddContentsViews();
93 // Gets the PaginationModel owned by the AppsGridView.
94 PaginationModel
* GetAppsPaginationModel();
96 // Loads icon image for the apps in the selected page of |pagination_model_|.
97 // |parent| is used to determine the image scale factor to use.
98 void PreloadIcons(gfx::NativeView parent
);
100 // Invoked when |icon_loading_wait_timer_| fires.
101 void OnIconLoadingWaitTimer();
103 // Invoked from an IconLoader when icon loading is finished.
104 void OnItemIconLoaded(IconLoader
* loader
);
106 // Overridden from AppsGridViewDelegate:
107 void ActivateApp(AppListItem
* item
, int event_flags
) override
;
108 void GetShortcutPathForApp(
109 const std::string
& app_id
,
110 const base::Callback
<void(const base::FilePath
&)>& callback
) override
;
111 void CancelDragInActiveFolder() override
;
113 // Overridden from SearchBoxViewDelegate:
114 void QueryChanged(SearchBoxView
* sender
) override
;
115 void BackButtonPressed() override
;
117 // Overridden from SearchResultListViewDelegate:
118 void OnResultInstalled(SearchResult
* result
) override
;
120 AppListViewDelegate
* delegate_
; // Owned by parent view (AppListView).
121 AppListModel
* model_
; // Unowned; ownership is handled by |delegate_|.
123 // Created by AppListView. Owned by views hierarchy.
124 SearchBoxView
* search_box_view_
;
125 ContentsView
* contents_view_
; // Owned by views hierarchy.
127 // Invisible widget that sits partly over the bottom of the app list, covering
128 // the collapsed-state custom page, and intercepts click events. Always use
129 // GetCustomPageClickzone() to access this (do not access it directly).
130 views::Widget
* custom_page_clickzone_
; // Owned by the app list widget.
132 // A timer that fires when maximum allowed time to wait for icon loading has
134 base::OneShotTimer
<AppListMainView
> icon_loading_wait_timer_
;
136 ScopedVector
<IconLoader
> pending_icon_loaders_
;
138 base::WeakPtrFactory
<AppListMainView
> weak_ptr_factory_
;
140 DISALLOW_COPY_AND_ASSIGN(AppListMainView
);
143 } // namespace app_list
145 #endif // UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_