12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef UI_APP_LIST_COCOA_APPS_GRID_CONTROLLER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define UI_APP_LIST_COCOA_APPS_GRID_CONTROLLER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#import <Cocoa/Cocoa.h>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/mac/scoped_nsobject.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/app_list/app_list_export.h"
13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#import "ui/app_list/cocoa/app_list_pager_view.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#import "ui/app_list/cocoa/scroll_view_with_no_scrollbars.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace app_list {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AppListModel;
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AppListViewDelegate;
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AppsGridDelegateBridge;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@class AppsGridViewItem;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@protocol AppsPaginationModelObserver;
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)@class AppsCollectionViewDragManager;
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Controls a grid of views, representing AppListItemList sub models.
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)APP_LIST_EXPORT
28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)@interface AppsGridController : NSViewController<GestureScrollDelegate,
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 AppListPagerDelegate,
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 NSCollectionViewDelegate> {
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) @private
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  app_list::AppListViewDelegate* delegate_;  // Weak. Owned by view controller.
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<app_list::AppsGridDelegateBridge> bridge_;
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<AppsCollectionViewDragManager> dragManager_;
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSMutableArray> pages_;
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSMutableArray> items_;
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSTimer> scrollWhileDraggingTimer_;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  id<AppsPaginationModelObserver> paginationObserver_;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Index of the currently visible page.
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  size_t visiblePage_;
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The page to which the view is currently animating a scroll.
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  size_t targetScrollPage_;
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The page to start scrolling to when the timer expires.
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  size_t scheduledScrollPage_;
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Whether we are currently animating a scroll to the nearest page.
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  BOOL animatingScroll_;
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@property(assign, nonatomic) id<AppsPaginationModelObserver> paginationObserver;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)+ (void)setScrollAnimationDuration:(NSTimeInterval)duration;
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// The amount the grid view has been extended to hold the sometimes present
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// invisible scroller that allows for gesture scrolling.
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)+ (CGFloat)scrollerPadding;
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (NSCollectionView*)collectionViewAtPageIndex:(size_t)pageIndex;
62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)- (size_t)pageIndexForCollectionView:(NSCollectionView*)page;
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (AppsGridViewItem*)itemAtIndex:(size_t)itemIndex;
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (app_list::AppListModel*)model;
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (void)setDelegate:(app_list::AppListViewDelegate*)newDelegate;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (size_t)visiblePage;
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Calls item->Activate for the currently selected item by simulating a click.
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (void)activateSelection;
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Return the number of pages of icons in the grid.
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (size_t)pageCount;
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Return the number of items over all pages in the grid.
79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)- (size_t)itemCount;
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Scroll to a page in the grid view with an animation.
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (void)scrollToPage:(size_t)pageIndex;
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Start a timer to scroll to a new page, if |locationInWindow| is to the left
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// or the right of the view, or if it is over a pager segment. Cancels any
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// existing timer if the target page changes.
8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)- (void)maybeChangePageForPoint:(NSPoint)locationInWindow;
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Cancel a timer that may have been set by maybeChangePageForPoint().
9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)- (void)cancelScrollTimer;
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
92b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Moves an item within the view only, for dragging or in response to model
93b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// changes.
94b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)- (void)moveItemInView:(size_t)fromIndex
95b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)           toItemIndex:(size_t)toIndex;
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Moves an item in the item model. Does not adjust the view.
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)- (void)moveItemWithIndex:(size_t)itemIndex
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)             toModelIndex:(size_t)modelIndex;
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
101a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Return the index of the selected item.
102a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)- (NSUInteger)selectedItemIndex;
103a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
104a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Moves the selection to the given index.
105a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)- (void)selectItemAtIndex:(NSUInteger)index;
106a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
107a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Handle key actions. Similar to doCommandBySelector from NSResponder but that
108a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// requires this class to be in the responder chain. Instead this method is
109a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// invoked by the AppListViewController.
110a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Returns YES if this handled navigation or launched an app.
111a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)- (BOOL)handleCommandBySelector:(SEL)command;
112a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)@end
114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)@interface AppsGridController(TestingAPI)
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)- (AppsCollectionViewDragManager*)dragManager;
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)- (size_t)scheduledScrollPage;
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@end
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // UI_APP_LIST_COCOA_APPS_GRID_CONTROLLER_H_
123