Home | History | Annotate | Download | only in views
      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/timer/timer.h"
     12 #include "ui/app_list/apps_grid_view_delegate.h"
     13 #include "ui/app_list/search_box_view_delegate.h"
     14 #include "ui/app_list/search_result_list_view_delegate.h"
     15 #include "ui/views/view.h"
     16 
     17 namespace views {
     18 class Widget;
     19 }
     20 
     21 namespace app_list {
     22 
     23 class ApplicationDragAndDropHost;
     24 class AppListModel;
     25 class AppListItemModel;
     26 class AppListViewDelegate;
     27 class ContentsView;
     28 class PaginationModel;
     29 class SearchBoxView;
     30 
     31 // AppListMainView contains the normal view of the app list, which is shown
     32 // when the user is signed in.
     33 class AppListMainView : public views::View,
     34                         public AppsGridViewDelegate,
     35                         public SearchBoxViewDelegate,
     36                         public SearchResultListViewDelegate {
     37  public:
     38   // Takes ownership of |delegate|.
     39   explicit AppListMainView(AppListViewDelegate* delegate,
     40                            AppListModel* model,
     41                            PaginationModel* pagination_model,
     42                            views::View* anchor);
     43   virtual ~AppListMainView();
     44 
     45   void ShowAppListWhenReady();
     46 
     47   void Close();
     48 
     49   void Prerender();
     50 
     51   SearchBoxView* search_box_view() const { return search_box_view_; }
     52 
     53   // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
     54   // operations outside the application list.
     55   void SetDragAndDropHostOfCurrentAppList(
     56       ApplicationDragAndDropHost* drag_and_drop_host);
     57 
     58  private:
     59   class IconLoader;
     60 
     61   // Loads icon image for the apps in the selected page of |pagination_model|.
     62   // |anchor| is used to determine the image scale factor to use.
     63   void PreloadIcons(PaginationModel* pagination_model,
     64                     views::View* anchor);
     65 
     66   // Invoked when |icon_loading_wait_timer_| fires.
     67   void OnIconLoadingWaitTimer();
     68 
     69   // Invoked from an IconLoader when icon loading is finished.
     70   void OnItemIconLoaded(IconLoader* loader);
     71 
     72   // Overridden from AppsGridViewDelegate:
     73   virtual void ActivateApp(AppListItemModel* item, int event_flags) OVERRIDE;
     74   virtual void GetShortcutPathForApp(
     75       const std::string& app_id,
     76       const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE;
     77 
     78   // Overridden from SearchBoxViewDelegate:
     79   virtual void QueryChanged(SearchBoxView* sender) OVERRIDE;
     80 
     81   // Overridden from SearchResultListViewDelegate:
     82   virtual void OpenResult(SearchResult* result,
     83                           int event_flags) OVERRIDE;
     84   virtual void InvokeResultAction(SearchResult* result,
     85                                   int action_index,
     86                                   int event_flags) OVERRIDE;
     87   virtual void OnResultInstalled(SearchResult* result) OVERRIDE;
     88   virtual void OnResultUninstalled(SearchResult* result) OVERRIDE;
     89 
     90   AppListViewDelegate* delegate_;
     91   AppListModel* model_;
     92 
     93   SearchBoxView* search_box_view_;  // Owned by views hierarchy.
     94   ContentsView* contents_view_;  // Owned by views hierarchy.
     95 
     96   // A timer that fires when maximum allowed time to wait for icon loading has
     97   // passed.
     98   base::OneShotTimer<AppListMainView> icon_loading_wait_timer_;
     99 
    100   ScopedVector<IconLoader> pending_icon_loaders_;
    101 
    102   DISALLOW_COPY_AND_ASSIGN(AppListMainView);
    103 };
    104 
    105 }  // namespace app_list
    106 
    107 #endif  // UI_APP_LIST_VIEWS_APP_LIST_MAIN_VIEW_H_
    108