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. 4 5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_ 7 8 #include <string> 9 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" 18 19 namespace views { 20 class Widget; 21 } 22 23 namespace app_list { 24 25 class AppListItem; 26 class AppListModel; 27 class AppListViewDelegate; 28 class ApplicationDragAndDropHost; 29 class ContentsSwitcherView; 30 class ContentsView; 31 class PaginationModel; 32 class SearchBoxView; 33 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 SearchBoxViewDelegate, 39 public SearchResultListViewDelegate { 40 public: 41 // Takes ownership of |delegate|. 42 explicit AppListMainView(AppListViewDelegate* delegate, 43 int initial_apps_page, 44 gfx::NativeView parent); 45 virtual ~AppListMainView(); 46 47 void ShowAppListWhenReady(); 48 49 void ResetForShow(); 50 51 void Close(); 52 53 void Prerender(); 54 55 void ModelChanged(); 56 57 void UpdateSearchBoxVisibility(); 58 59 void OnStartPageSearchTextfieldChanged(const base::string16& new_contents); 60 search_box_view()61 SearchBoxView* search_box_view() const { return search_box_view_; } 62 63 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop 64 // operations outside the application list. 65 void SetDragAndDropHostOfCurrentAppList( 66 ApplicationDragAndDropHost* drag_and_drop_host); 67 contents_view()68 ContentsView* contents_view() const { return contents_view_; } contents_switcher_view()69 ContentsSwitcherView* contents_switcher_view() const { 70 return contents_switcher_view_; 71 } model()72 AppListModel* model() { return model_; } 73 74 // Returns true if the app list should be centered and in landscape mode. 75 bool ShouldCenterWindow() const; 76 77 // Called when the search box's visibility is changed. 78 void NotifySearchBoxVisibilityChanged(); 79 80 private: 81 class IconLoader; 82 83 // Adds the ContentsView and the ContentsSwitcherView. 84 void AddContentsViews(); 85 86 // Gets the PaginationModel owned by the AppsGridView. 87 PaginationModel* GetAppsPaginationModel(); 88 89 // Loads icon image for the apps in the selected page of |pagination_model_|. 90 // |parent| is used to determine the image scale factor to use. 91 void PreloadIcons(gfx::NativeView parent); 92 93 // Invoked when |icon_loading_wait_timer_| fires. 94 void OnIconLoadingWaitTimer(); 95 96 // Invoked from an IconLoader when icon loading is finished. 97 void OnItemIconLoaded(IconLoader* loader); 98 99 // Overridden from AppsGridViewDelegate: 100 virtual void ActivateApp(AppListItem* item, int event_flags) OVERRIDE; 101 virtual void GetShortcutPathForApp( 102 const std::string& app_id, 103 const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE; 104 virtual void CancelDragInActiveFolder() OVERRIDE; 105 106 // Overridden from SearchBoxViewDelegate: 107 virtual void QueryChanged(SearchBoxView* sender) OVERRIDE; 108 109 // Overridden from SearchResultListViewDelegate: 110 virtual void OnResultInstalled(SearchResult* result) OVERRIDE; 111 virtual void OnResultUninstalled(SearchResult* result) OVERRIDE; 112 113 AppListViewDelegate* delegate_; // Owned by parent view (AppListView). 114 AppListModel* model_; // Unowned; ownership is handled by |delegate_|. 115 116 SearchBoxView* search_box_view_; // Owned by views hierarchy. 117 ContentsView* contents_view_; // Owned by views hierarchy. 118 119 // Owned by views hierarchy. NULL in the non-experimental app list. 120 ContentsSwitcherView* contents_switcher_view_; 121 122 // A timer that fires when maximum allowed time to wait for icon loading has 123 // passed. 124 base::OneShotTimer<AppListMainView> icon_loading_wait_timer_; 125 126 ScopedVector<IconLoader> pending_icon_loaders_; 127 128 base::WeakPtrFactory<AppListMainView> weak_ptr_factory_; 129 130 DISALLOW_COPY_AND_ASSIGN(AppListMainView); 131 }; 132 133 } // namespace app_list 134 135 #endif // UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_ 136