Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Unified Diff: ui/app_list/cocoa/apps_grid_controller.mm

Issue 14999013: Allow pages on the OSX app launcher to be turned while dragging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tests! Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/app_list/cocoa/apps_grid_controller.mm
diff --git a/ui/app_list/cocoa/apps_grid_controller.mm b/ui/app_list/cocoa/apps_grid_controller.mm
index fc101554647474ddaeb572f90343581a779539b2..c098938773a0275d3afc7c02ba90aae3086a45eb 100644
--- a/ui/app_list/cocoa/apps_grid_controller.mm
+++ b/ui/app_list/cocoa/apps_grid_controller.mm
@@ -33,12 +33,16 @@ const CGFloat kViewWidth =
kFixedColumns * kPreferredTileWidth + 2 * kLeftRightPadding;
const CGFloat kViewHeight = kFixedRows * kPreferredTileHeight;
+const NSTimeInterval kScrollWhileDraggingDelay = 1.0;
tapted 2013/05/17 04:24:15 note: value from apps_grid_view.cc (1000ms)
NSTimeInterval g_scroll_duration = 0.18;
} // namespace
@interface AppsGridController ()
+- (void)scrollToPageWithTimer:(size_t)targetPage;
+- (void)onTimer:(NSTimer*)theTimer;
+
// Cancel a currently running scroll animation.
- (void)cancelScrollAnimation;
@@ -245,6 +249,66 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
[[clipView animator] setBoundsOrigin:newOrigin];
[NSAnimationContext endGrouping];
animatingScroll_ = YES;
+ targetScrollPage_ = pageIndex;
+ [self cancelScrollTimer];
+}
+
+- (void)maybeChangePageForPoint:(NSPoint)locationInWindow {
+ NSPoint pointInView = [[self view] convertPoint:locationInWindow
+ fromView:nil];
+ // Check if the point is outside the view on the left or right.
+ if (pointInView.x < 0 || pointInView.x > [[self view] bounds].size.width) {
sail 2013/05/17 19:16:13 NSWidth also should it be >=?
tapted 2013/05/17 23:25:29 Done.
+ size_t targetPage = visiblePage_;
+ if (pointInView.x < 0)
+ targetPage -= targetPage != 0 ? 1 : 0;
+ else
+ targetPage += targetPage < [pages_ count] - 1 ? 1 : 0;
+ [self scrollToPageWithTimer:targetPage];
+ return;
+ }
+
+ if (paginationObserver_) {
+ NSInteger segment =
+ [paginationObserver_ pagerSegmentAtLocation:locationInWindow];
+ if (segment >= 0 && static_cast<size_t>(segment) != targetScrollPage_) {
+ [self scrollToPageWithTimer:segment];
+ return;
+ }
+ }
+
+ // Otherwise the point may have moved back into the view.
+ [self cancelScrollTimer];
+}
+
+- (void)cancelScrollTimer {
+ scheduledScrollPage_ = targetScrollPage_;
+ [scrollWhileDraggingTimer_ invalidate];
+}
+
+- (void)scrollToPageWithTimer:(size_t)targetPage {
+ if (targetPage == targetScrollPage_) {
+ [self cancelScrollTimer];
+ return;
+ }
+
+ if (targetPage == scheduledScrollPage_)
+ return;
+
+ scheduledScrollPage_ = targetPage;
+ [scrollWhileDraggingTimer_ invalidate];
+ scrollWhileDraggingTimer_.reset(
+ [[NSTimer scheduledTimerWithTimeInterval:kScrollWhileDraggingDelay
+ target:self
+ selector:@selector(onTimer:)
+ userInfo:nil
+ repeats:NO] retain]);
+}
+
+- (void)onTimer:(NSTimer*)theTimer {
+ if (scheduledScrollPage_ == targetScrollPage_)
+ return; // Already animating scroll.
+
+ [self scrollToPage:scheduledScrollPage_];
}
- (void)cancelScrollAnimation {
@@ -468,6 +532,10 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
return dragManager_;
}
+- (size_t)scheduledScrollPage {
+ return scheduledScrollPage_;
+}
+
- (void)listItemsAdded:(size_t)start
count:(size_t)count {
// Cancel any drag, to ensure the model stays consistent.

Powered by Google App Engine
This is Rietveld 408576698