Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / app_list / views / app_list_main_view.h
blob5e51775670a587e45b910802fb7b427370d4735a
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_
8 #include <string>
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"
20 namespace views {
21 class Widget;
24 namespace app_list {
26 class AppListItem;
27 class AppListModel;
28 class AppListViewDelegate;
29 class ApplicationDragAndDropHost;
30 class ContentsView;
31 class PaginationModel;
32 class SearchBoxView;
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 {
41 public:
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();
51 void ResetForShow();
53 void Close();
55 void Prerender();
57 void ModelChanged();
59 SearchBoxView* search_box_view() const { return search_box_view_; }
61 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
62 // operations outside the application list.
63 void SetDragAndDropHostOfCurrentAppList(
64 ApplicationDragAndDropHost* drag_and_drop_host);
66 ContentsView* contents_view() const { return contents_view_; }
67 AppListModel* model() { return model_; }
68 AppListViewDelegate* view_delegate() { return delegate_; }
70 // Returns true if the app list should be centered and in landscape mode.
71 bool ShouldCenterWindow() const;
73 // Called when the search box's visibility is changed.
74 void NotifySearchBoxVisibilityChanged();
76 bool ShouldShowCustomLauncherPage() const;
77 void UpdateCustomLauncherPageVisibility();
79 // Overridden from AppListModelObserver:
80 void OnCustomLauncherPageEnabledStateChanged(bool enabled) override;
81 void OnSearchEngineIsGoogleChanged(bool is_google) override;
83 private:
84 class IconLoader;
86 // Adds the ContentsView.
87 void AddContentsViews();
89 // Gets the PaginationModel owned by the AppsGridView.
90 PaginationModel* GetAppsPaginationModel();
92 // Loads icon image for the apps in the selected page of |pagination_model_|.
93 // |parent| is used to determine the image scale factor to use.
94 void PreloadIcons(gfx::NativeView parent);
96 // Invoked when |icon_loading_wait_timer_| fires.
97 void OnIconLoadingWaitTimer();
99 // Invoked from an IconLoader when icon loading is finished.
100 void OnItemIconLoaded(IconLoader* loader);
102 // Overridden from AppsGridViewDelegate:
103 void ActivateApp(AppListItem* item, int event_flags) override;
104 void GetShortcutPathForApp(
105 const std::string& app_id,
106 const base::Callback<void(const base::FilePath&)>& callback) override;
107 void CancelDragInActiveFolder() override;
109 // Overridden from SearchBoxViewDelegate:
110 void QueryChanged(SearchBoxView* sender) override;
111 void BackButtonPressed() override;
112 void SetSearchResultSelection(bool select) override;
114 // Overridden from SearchResultListViewDelegate:
115 void OnResultInstalled(SearchResult* result) override;
117 AppListViewDelegate* delegate_; // Owned by parent view (AppListView).
118 AppListModel* model_; // Unowned; ownership is handled by |delegate_|.
120 // Created by AppListView. Owned by views hierarchy.
121 SearchBoxView* search_box_view_;
122 ContentsView* contents_view_; // Owned by views hierarchy.
124 // A timer that fires when maximum allowed time to wait for icon loading has
125 // passed.
126 base::OneShotTimer<AppListMainView> icon_loading_wait_timer_;
128 ScopedVector<IconLoader> pending_icon_loaders_;
130 base::WeakPtrFactory<AppListMainView> weak_ptr_factory_;
132 DISALLOW_COPY_AND_ASSIGN(AppListMainView);
135 } // namespace app_list
137 #endif // UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_