apps_grid_controller.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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_COCOA_APPS_GRID_CONTROLLER_H_ 6#define UI_APP_LIST_COCOA_APPS_GRID_CONTROLLER_H_ 7 8#import <Cocoa/Cocoa.h> 9 10#include "base/memory/scoped_nsobject.h" 11#include "base/memory/scoped_ptr.h" 12#include "ui/app_list/app_list_export.h" 13#import "ui/app_list/cocoa/app_list_pager_view.h" 14#import "ui/app_list/cocoa/scroll_view_with_no_scrollbars.h" 15 16namespace app_list { 17class AppListModel; 18class AppListViewDelegate; 19class AppsGridDelegateBridge; 20} 21 22@class AppsGridViewItem; 23@protocol AppsPaginationModelObserver; 24@class AppsCollectionViewDragManager; 25 26// Controls a grid of views, representing AppListModel::Apps sub models. 27APP_LIST_EXPORT 28@interface AppsGridController : NSViewController<GestureScrollDelegate, 29 AppListPagerDelegate> { 30 @private 31 scoped_ptr<app_list::AppListModel> model_; 32 app_list::AppListViewDelegate* delegate_; // Weak. Owned by view controller. 33 scoped_ptr<app_list::AppsGridDelegateBridge> bridge_; 34 35 scoped_nsobject<AppsCollectionViewDragManager> dragManager_; 36 scoped_nsobject<NSMutableArray> pages_; 37 scoped_nsobject<NSMutableArray> items_; 38 scoped_nsobject<NSTimer> scrollWhileDraggingTimer_; 39 40 id<AppsPaginationModelObserver> paginationObserver_; 41 42 // Index of the currently visible page. 43 size_t visiblePage_; 44 // The page to which the view is currently animating a scroll. 45 size_t targetScrollPage_; 46 // The page to start scrolling to when the timer expires. 47 size_t scheduledScrollPage_; 48 49 // Whether we are currently animating a scroll to the nearest page. 50 BOOL animatingScroll_; 51} 52 53@property(assign, nonatomic) id<AppsPaginationModelObserver> paginationObserver; 54 55+ (void)setScrollAnimationDuration:(NSTimeInterval)duration; 56 57- (NSCollectionView*)collectionViewAtPageIndex:(size_t)pageIndex; 58- (size_t)pageIndexForCollectionView:(NSCollectionView*)page; 59 60- (AppsGridViewItem*)itemAtIndex:(size_t)itemIndex; 61 62- (app_list::AppListModel*)model; 63 64- (void)setModel:(scoped_ptr<app_list::AppListModel>)newModel; 65 66- (void)setDelegate:(app_list::AppListViewDelegate*)newDelegate; 67 68- (size_t)visiblePage; 69 70// Calls delegate_->ActivateAppListItem for the currently selected item by 71// simulating a click. 72- (void)activateSelection; 73 74// Return the number of pages of icons in the grid. 75- (size_t)pageCount; 76 77// Return the number of items over all pages in the grid. 78- (size_t)itemCount; 79 80// Scroll to a page in the grid view with an animation. 81- (void)scrollToPage:(size_t)pageIndex; 82 83// Start a timer to scroll to a new page, if |locationInWindow| is to the left 84// or the right of the view, or if it is over a pager segment. Cancels any 85// existing timer if the target page changes. 86- (void)maybeChangePageForPoint:(NSPoint)locationInWindow; 87 88// Cancel a timer that may have been set by maybeChangePageForPoint(). 89- (void)cancelScrollTimer; 90 91// Moves an item within the view only, for dragging or in response to model 92// changes. 93- (void)moveItemInView:(size_t)fromIndex 94 toItemIndex:(size_t)toIndex; 95 96// Moves an item in the item model. Does not adjust the view. 97- (void)moveItemWithIndex:(size_t)itemIndex 98 toModelIndex:(size_t)modelIndex; 99 100// Return the index of the selected item. 101- (NSUInteger)selectedItemIndex; 102 103// Moves the selection to the given index. 104- (void)selectItemAtIndex:(NSUInteger)index; 105 106// Handle key actions. Similar to doCommandBySelector from NSResponder but that 107// requires this class to be in the responder chain. Instead this method is 108// invoked by the AppListViewController. 109// Returns YES if this handled navigation or launched an app. 110- (BOOL)handleCommandBySelector:(SEL)command; 111 112@end 113 114@interface AppsGridController(TestingAPI) 115 116- (AppsCollectionViewDragManager*)dragManager; 117- (size_t)scheduledScrollPage; 118 119@end 120 121#endif // UI_APP_LIST_COCOA_APPS_GRID_CONTROLLER_H_ 122