OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ui/app_list/cocoa/apps_grid_controller.h" | 5 #import "ui/app_list/cocoa/apps_grid_controller.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "ui/app_list/app_list_model.h" | 8 #include "ui/app_list/app_list_model.h" |
9 #include "ui/app_list/app_list_model_observer.h" | 9 #include "ui/app_list/app_list_model_observer.h" |
10 #include "ui/app_list/app_list_view_delegate.h" | 10 #include "ui/app_list/app_list_view_delegate.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 // Preferred tile size when showing in fixed layout. These should be even | 27 // Preferred tile size when showing in fixed layout. These should be even |
28 // numbers to ensure that if they are grown 50% they remain integers. | 28 // numbers to ensure that if they are grown 50% they remain integers. |
29 const CGFloat kPreferredTileWidth = 88; | 29 const CGFloat kPreferredTileWidth = 88; |
30 const CGFloat kPreferredTileHeight = 98; | 30 const CGFloat kPreferredTileHeight = 98; |
31 | 31 |
32 const CGFloat kViewWidth = | 32 const CGFloat kViewWidth = |
33 kFixedColumns * kPreferredTileWidth + 2 * kLeftRightPadding; | 33 kFixedColumns * kPreferredTileWidth + 2 * kLeftRightPadding; |
34 const CGFloat kViewHeight = kFixedRows * kPreferredTileHeight; | 34 const CGFloat kViewHeight = kFixedRows * kPreferredTileHeight; |
35 | 35 |
36 const NSTimeInterval kScrollWhileDraggingDelay = 1.0; | |
tapted
2013/05/17 04:24:15
note: value from apps_grid_view.cc (1000ms)
| |
36 NSTimeInterval g_scroll_duration = 0.18; | 37 NSTimeInterval g_scroll_duration = 0.18; |
37 | 38 |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 @interface AppsGridController () | 41 @interface AppsGridController () |
41 | 42 |
43 - (void)scrollToPageWithTimer:(size_t)targetPage; | |
44 - (void)onTimer:(NSTimer*)theTimer; | |
45 | |
42 // Cancel a currently running scroll animation. | 46 // Cancel a currently running scroll animation. |
43 - (void)cancelScrollAnimation; | 47 - (void)cancelScrollAnimation; |
44 | 48 |
45 // Index of the page with the most content currently visible. | 49 // Index of the page with the most content currently visible. |
46 - (size_t)nearestPageIndex; | 50 - (size_t)nearestPageIndex; |
47 | 51 |
48 // Bootstrap the views this class controls. | 52 // Bootstrap the views this class controls. |
49 - (void)loadAndSetView; | 53 - (void)loadAndSetView; |
50 | 54 |
51 - (void)boundsDidChange:(NSNotification*)notification; | 55 - (void)boundsDidChange:(NSNotification*)notification; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 [[self collectionViewAtPageIndex:visiblePage_] | 242 [[self collectionViewAtPageIndex:visiblePage_] |
239 setSelectionIndexes:[NSIndexSet indexSet]]; | 243 setSelectionIndexes:[NSIndexSet indexSet]]; |
240 } | 244 } |
241 | 245 |
242 newOrigin.x = pageIndex * kViewWidth; | 246 newOrigin.x = pageIndex * kViewWidth; |
243 [NSAnimationContext beginGrouping]; | 247 [NSAnimationContext beginGrouping]; |
244 [[NSAnimationContext currentContext] setDuration:g_scroll_duration]; | 248 [[NSAnimationContext currentContext] setDuration:g_scroll_duration]; |
245 [[clipView animator] setBoundsOrigin:newOrigin]; | 249 [[clipView animator] setBoundsOrigin:newOrigin]; |
246 [NSAnimationContext endGrouping]; | 250 [NSAnimationContext endGrouping]; |
247 animatingScroll_ = YES; | 251 animatingScroll_ = YES; |
252 targetScrollPage_ = pageIndex; | |
253 [self cancelScrollTimer]; | |
254 } | |
255 | |
256 - (void)maybeChangePageForPoint:(NSPoint)locationInWindow { | |
257 NSPoint pointInView = [[self view] convertPoint:locationInWindow | |
258 fromView:nil]; | |
259 // Check if the point is outside the view on the left or right. | |
260 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.
| |
261 size_t targetPage = visiblePage_; | |
262 if (pointInView.x < 0) | |
263 targetPage -= targetPage != 0 ? 1 : 0; | |
264 else | |
265 targetPage += targetPage < [pages_ count] - 1 ? 1 : 0; | |
266 [self scrollToPageWithTimer:targetPage]; | |
267 return; | |
268 } | |
269 | |
270 if (paginationObserver_) { | |
271 NSInteger segment = | |
272 [paginationObserver_ pagerSegmentAtLocation:locationInWindow]; | |
273 if (segment >= 0 && static_cast<size_t>(segment) != targetScrollPage_) { | |
274 [self scrollToPageWithTimer:segment]; | |
275 return; | |
276 } | |
277 } | |
278 | |
279 // Otherwise the point may have moved back into the view. | |
280 [self cancelScrollTimer]; | |
281 } | |
282 | |
283 - (void)cancelScrollTimer { | |
284 scheduledScrollPage_ = targetScrollPage_; | |
285 [scrollWhileDraggingTimer_ invalidate]; | |
286 } | |
287 | |
288 - (void)scrollToPageWithTimer:(size_t)targetPage { | |
289 if (targetPage == targetScrollPage_) { | |
290 [self cancelScrollTimer]; | |
291 return; | |
292 } | |
293 | |
294 if (targetPage == scheduledScrollPage_) | |
295 return; | |
296 | |
297 scheduledScrollPage_ = targetPage; | |
298 [scrollWhileDraggingTimer_ invalidate]; | |
299 scrollWhileDraggingTimer_.reset( | |
300 [[NSTimer scheduledTimerWithTimeInterval:kScrollWhileDraggingDelay | |
301 target:self | |
302 selector:@selector(onTimer:) | |
303 userInfo:nil | |
304 repeats:NO] retain]); | |
305 } | |
306 | |
307 - (void)onTimer:(NSTimer*)theTimer { | |
308 if (scheduledScrollPage_ == targetScrollPage_) | |
309 return; // Already animating scroll. | |
310 | |
311 [self scrollToPage:scheduledScrollPage_]; | |
248 } | 312 } |
249 | 313 |
250 - (void)cancelScrollAnimation { | 314 - (void)cancelScrollAnimation { |
251 NSClipView* clipView = [[self gridScrollView] contentView]; | 315 NSClipView* clipView = [[self gridScrollView] contentView]; |
252 [NSAnimationContext beginGrouping]; | 316 [NSAnimationContext beginGrouping]; |
253 [[NSAnimationContext currentContext] setDuration:0]; | 317 [[NSAnimationContext currentContext] setDuration:0]; |
254 [[clipView animator] setBoundsOrigin:[clipView bounds].origin]; | 318 [[clipView animator] setBoundsOrigin:[clipView bounds].origin]; |
255 [NSAnimationContext endGrouping]; | 319 [NSAnimationContext endGrouping]; |
256 animatingScroll_ = NO; | 320 animatingScroll_ = NO; |
257 } | 321 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 | 525 |
462 model_->apps()->RemoveObserver(bridge_.get()); | 526 model_->apps()->RemoveObserver(bridge_.get()); |
463 model_->apps()->Move(itemIndex, modelIndex); | 527 model_->apps()->Move(itemIndex, modelIndex); |
464 model_->apps()->AddObserver(bridge_.get()); | 528 model_->apps()->AddObserver(bridge_.get()); |
465 } | 529 } |
466 | 530 |
467 - (AppsCollectionViewDragManager*)dragManager { | 531 - (AppsCollectionViewDragManager*)dragManager { |
468 return dragManager_; | 532 return dragManager_; |
469 } | 533 } |
470 | 534 |
535 - (size_t)scheduledScrollPage { | |
536 return scheduledScrollPage_; | |
537 } | |
538 | |
471 - (void)listItemsAdded:(size_t)start | 539 - (void)listItemsAdded:(size_t)start |
472 count:(size_t)count { | 540 count:(size_t)count { |
473 // Cancel any drag, to ensure the model stays consistent. | 541 // Cancel any drag, to ensure the model stays consistent. |
474 [dragManager_ cancelDrag]; | 542 [dragManager_ cancelDrag]; |
475 | 543 |
476 for (size_t i = start; i < start + count; ++i) { | 544 for (size_t i = start; i < start + count; ++i) { |
477 app_list::AppListItemModel* itemModel = model_->apps()->GetItemAt(i); | 545 app_list::AppListItemModel* itemModel = model_->apps()->GetItemAt(i); |
478 [items_ insertObject:[NSValue valueWithPointer:itemModel] | 546 [items_ insertObject:[NSValue valueWithPointer:itemModel] |
479 atIndex:i]; | 547 atIndex:i]; |
480 } | 548 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 return [self moveSelectionByDelta:-kItemsPerPage]; | 646 return [self moveSelectionByDelta:-kItemsPerPage]; |
579 | 647 |
580 if (command == @selector(pageDown:) || | 648 if (command == @selector(pageDown:) || |
581 command == @selector(scrollPageDown:)) | 649 command == @selector(scrollPageDown:)) |
582 return [self moveSelectionByDelta:kItemsPerPage]; | 650 return [self moveSelectionByDelta:kItemsPerPage]; |
583 | 651 |
584 return NO; | 652 return NO; |
585 } | 653 } |
586 | 654 |
587 @end | 655 @end |
OLD | NEW |