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

Side by Side Diff: ui/app_list/cocoa/apps_collection_view_drag_manager.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: respond to comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_collection_view_drag_manager.h" 5 #import "ui/app_list/cocoa/apps_collection_view_drag_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #import "ui/app_list/cocoa/apps_grid_controller.h" 9 #import "ui/app_list/cocoa/apps_grid_controller.h"
10 #import "ui/app_list/cocoa/apps_grid_view_item.h" 10 #import "ui/app_list/cocoa/apps_grid_view_item.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return NSNotFound; 138 return NSNotFound;
139 } 139 }
140 140
141 - (void)initiateDrag:(NSEvent*)theEvent { 141 - (void)initiateDrag:(NSEvent*)theEvent {
142 DCHECK_LT(itemHitIndex_, [gridController_ itemCount]); 142 DCHECK_LT(itemHitIndex_, [gridController_ itemCount]);
143 dragging_ = YES; 143 dragging_ = YES;
144 144
145 if (!itemDragController_) { 145 if (!itemDragController_) {
146 itemDragController_.reset( 146 itemDragController_.reset(
147 [[ItemDragController alloc] initWithGridCellSize:cellSize_]); 147 [[ItemDragController alloc] initWithGridCellSize:cellSize_]);
148 [[gridController_ view] addSubview:[itemDragController_ view]]; 148 [[[gridController_ view] superview] addSubview:[itemDragController_ view]];
149 } 149 }
150 150
151 [itemDragController_ initiate:[gridController_ itemAtIndex:itemHitIndex_] 151 [itemDragController_ initiate:[gridController_ itemAtIndex:itemHitIndex_]
152 mouseDownLocation:mouseDownLocation_ 152 mouseDownLocation:mouseDownLocation_
153 currentLocation:[theEvent locationInWindow] 153 currentLocation:[theEvent locationInWindow]
154 timestamp:[theEvent timestamp]]; 154 timestamp:[theEvent timestamp]];
155 155
156 itemDragIndex_ = itemHitIndex_; 156 itemDragIndex_ = itemHitIndex_;
157 [self updateDrag:theEvent]; 157 [self updateDrag:theEvent];
158 } 158 }
159 159
160 - (void)updateDrag:(NSEvent*)theEvent { 160 - (void)updateDrag:(NSEvent*)theEvent {
161 [itemDragController_ update:[theEvent locationInWindow] 161 [itemDragController_ update:[theEvent locationInWindow]
162 timestamp:[theEvent timestamp]]; 162 timestamp:[theEvent timestamp]];
163 [gridController_ maybeChangePageForPoint:[theEvent locationInWindow]];
164
163 size_t visiblePage = [gridController_ visiblePage]; 165 size_t visiblePage = [gridController_ visiblePage];
164 size_t itemIndexOver = [self itemIndexForPage:visiblePage 166 size_t itemIndexOver = [self itemIndexForPage:visiblePage
165 hitWithEvent:theEvent]; 167 hitWithEvent:theEvent];
166 DCHECK_NE(0u, [gridController_ itemCount]); 168 DCHECK_NE(0u, [gridController_ itemCount]);
167 if (itemIndexOver == NSNotFound) { 169 if (itemIndexOver == NSNotFound) {
168 if (visiblePage != [gridController_ pageCount] - 1) 170 if (visiblePage != [gridController_ pageCount] - 1)
169 return; 171 return;
170 172
171 // If nothing was hit, but the last page is shown, move to the end. 173 // If nothing was hit, but the last page is shown, move to the end.
172 itemIndexOver = [gridController_ itemCount] - 1; 174 itemIndexOver = [gridController_ itemCount] - 1;
(...skipping 15 matching lines...) Expand all
188 190
189 [gridController_ moveItemInView:itemDragIndex_ 191 [gridController_ moveItemInView:itemDragIndex_
190 toItemIndex:itemHitIndex_]; 192 toItemIndex:itemHitIndex_];
191 itemDragIndex_ = itemHitIndex_; 193 itemDragIndex_ = itemHitIndex_;
192 [self completeDrag]; 194 [self completeDrag];
193 itemHitIndex_ = NSNotFound; // Ignore future mouse events for this drag. 195 itemHitIndex_ = NSNotFound; // Ignore future mouse events for this drag.
194 } 196 }
195 197
196 - (void)completeDrag { 198 - (void)completeDrag {
197 DCHECK_GE(itemDragIndex_, 0u); 199 DCHECK_GE(itemDragIndex_, 0u);
200 [gridController_ cancelScrollTimer];
198 AppsGridViewItem* item = [gridController_ itemAtIndex:itemDragIndex_]; 201 AppsGridViewItem* item = [gridController_ itemAtIndex:itemDragIndex_];
199 202
200 // The item could still be animating in the NSCollectionView, so ask it where 203 // The item could still be animating in the NSCollectionView, so ask it where
201 // it would place the item. 204 // it would place the item.
202 NSCollectionView* pageView = base::mac::ObjCCastStrict<NSCollectionView>( 205 NSCollectionView* pageView = base::mac::ObjCCastStrict<NSCollectionView>(
203 [[item view] superview]); 206 [[item view] superview]);
204 size_t indexInPage = itemDragIndex_ % (rows_ * columns_); 207 size_t indexInPage = itemDragIndex_ % (rows_ * columns_);
205 NSPoint targetOrigin = [[gridController_ view] 208 NSPoint targetOrigin = [[[itemDragController_ view] superview]
206 convertPoint:[pageView frameForItemAtIndex:indexInPage].origin 209 convertPoint:[pageView frameForItemAtIndex:indexInPage].origin
207 fromView:pageView]; 210 fromView:pageView];
208 211
209 [itemDragController_ complete:item 212 [itemDragController_ complete:item
210 targetOrigin:targetOrigin]; 213 targetOrigin:targetOrigin];
211 [gridController_ moveItemWithIndex:itemHitIndex_ 214 [gridController_ moveItemWithIndex:itemHitIndex_
212 toModelIndex:itemDragIndex_]; 215 toModelIndex:itemDragIndex_];
213 216
214 dragging_ = NO; 217 dragging_ = NO;
215 } 218 }
(...skipping 15 matching lines...) Expand all
231 234
232 - (void)mouseUp:(NSEvent*)theEvent { 235 - (void)mouseUp:(NSEvent*)theEvent {
233 [factory_ onMouseUp:theEvent]; 236 [factory_ onMouseUp:theEvent];
234 } 237 }
235 238
236 - (BOOL)acceptsFirstResponder { 239 - (BOOL)acceptsFirstResponder {
237 return NO; 240 return NO;
238 } 241 }
239 242
240 @end 243 @end
OLDNEW
« no previous file with comments | « ui/app_list/cocoa/app_list_view_controller_unittest.mm ('k') | ui/app_list/cocoa/apps_grid_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698