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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm

Issue 1854223002: mac: Fix bookmark drag and drop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp37_dnd
Patch Set: Fix memory leak. Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 18 matching lines...) Expand all
29 static const CGFloat kDragImageOpacity = 0.7; 29 static const CGFloat kDragImageOpacity = 0.7;
30 30
31 namespace { 31 namespace {
32 // We need a class variable to track the current dragged button to enable 32 // We need a class variable to track the current dragged button to enable
33 // proper live animated dragging behavior, and can't do it in the 33 // proper live animated dragging behavior, and can't do it in the
34 // delegate/controller since you can drag a button from one domain to the 34 // delegate/controller since you can drag a button from one domain to the
35 // other (from a "folder" menu, to the main bar, or vice versa). 35 // other (from a "folder" menu, to the main bar, or vice versa).
36 BookmarkButton* gDraggedButton = nil; // Weak 36 BookmarkButton* gDraggedButton = nil; // Weak
37 }; 37 };
38 38
39 @interface BookmarkButton() <NSPasteboardItemDataProvider> 39 @interface BookmarkButton()
40
41 // NSPasteboardItemDataProvider:
42 - (void)pasteboard:(NSPasteboard*)sender
43 item:(NSPasteboardItem*)item
44 provideDataForType:(NSString*)type;
45 40
46 // NSDraggingSource: 41 // NSDraggingSource:
47 - (void)draggingSession:(NSDraggingSession*)session 42 - (void)draggingSession:(NSDraggingSession*)session
48 endedAtPoint:(NSPoint)aPoint 43 endedAtPoint:(NSPoint)aPoint
49 operation:(NSDragOperation)operation; 44 operation:(NSDragOperation)operation;
50 - (NSDragOperation)draggingSession:(NSDraggingSession*)session 45 - (NSDragOperation)draggingSession:(NSDraggingSession*)session
51 sourceOperationMaskForDraggingContext:(NSDraggingContext)context; 46 sourceOperationMaskForDraggingContext:(NSDraggingContext)context;
52 47
53 // Make a drag image for the button. 48 // Make a drag image for the button.
54 - (NSImage*)dragImage; 49 - (NSImage*)dragImage;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if ([[self delegate] dragShouldLockBarVisibility]) { 189 if ([[self delegate] dragShouldLockBarVisibility]) {
195 DCHECK(!visibilityDelegate_); 190 DCHECK(!visibilityDelegate_);
196 NSWindow* window = [[self delegate] browserWindow]; 191 NSWindow* window = [[self delegate] browserWindow];
197 visibilityDelegate_ = 192 visibilityDelegate_ =
198 [BrowserWindowController browserWindowControllerForWindow:window]; 193 [BrowserWindowController browserWindowControllerForWindow:window];
199 [visibilityDelegate_ lockBarVisibilityForOwner:self 194 [visibilityDelegate_ lockBarVisibilityForOwner:self
200 withAnimation:NO 195 withAnimation:NO
201 delay:NO]; 196 delay:NO];
202 } 197 }
203 const BookmarkNode* node = [self bookmarkNode]; 198 const BookmarkNode* node = [self bookmarkNode];
204 const BookmarkNode* parent = node ? node->parent() : NULL; 199 const BookmarkNode* parent = node->parent();
205 if (parent && parent->type() == BookmarkNode::FOLDER) { 200 if (parent && parent->type() == BookmarkNode::FOLDER) {
206 content::RecordAction(UserMetricsAction("BookmarkBarFolder_DragStart")); 201 content::RecordAction(UserMetricsAction("BookmarkBarFolder_DragStart"));
207 } else { 202 } else {
208 content::RecordAction(UserMetricsAction("BookmarkBar_DragStart")); 203 content::RecordAction(UserMetricsAction("BookmarkBar_DragStart"));
209 } 204 }
210 205
211 dragMouseOffset_ = [self convertPoint:[event locationInWindow] fromView:nil]; 206 dragMouseOffset_ = [self convertPoint:[event locationInWindow] fromView:nil];
212 dragPending_ = YES; 207 dragPending_ = YES;
213 gDraggedButton = self; 208 gDraggedButton = self;
214 209
215 NSImage* image = [self dragImage]; 210 NSImage* image = [self dragImage];
216 [self setHidden:YES]; 211 [self setHidden:YES];
217 212
218 NSPasteboardItem* pbItem = [NSPasteboardItem new]; 213 NSPasteboardItem* item = [[self delegate] pasteboardItemForDragOfButton:self];
219 [pbItem setDataProvider:self 214 if ([[self delegate] respondsToSelector:@selector(willBeginPasteboardDrag)])
220 forTypes:@[ ui::ClipboardUtil::UTIForPasteboardType( 215 [[self delegate] willBeginPasteboardDrag];
221 kBookmarkButtonDragType) ]];
222 216
223 base::scoped_nsobject<NSDraggingItem> dragItem( 217 base::scoped_nsobject<NSDraggingItem> dragItem(
224 [[NSDraggingItem alloc] initWithPasteboardWriter:pbItem]); 218 [[NSDraggingItem alloc] initWithPasteboardWriter:item]);
225 [dragItem setDraggingFrame:[self bounds] contents:image]; 219 [dragItem setDraggingFrame:[self bounds] contents:image];
226 220
227 [self beginDraggingSessionWithItems:@[ dragItem.get() ] 221 [self beginDraggingSessionWithItems:@[ dragItem.get() ]
228 event:event 222 event:event
229 source:self]; 223 source:self];
230 while (gDraggedButton != nil) { 224 while (gDraggedButton != nil) {
231 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 225 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
232 beforeDate:[NSDate distantFuture]]; 226 beforeDate:[NSDate distantFuture]];
233 } 227 }
234 [self setHidden:NO]; 228 [self setHidden:NO];
235 229
236 // And we're done. 230 // And we're done.
237 dragPending_ = NO; 231 dragPending_ = NO;
238 gDraggedButton = nil; 232 gDraggedButton = nil;
239 233
240 [self autorelease]; 234 [self autorelease];
241 } 235 }
242 236
243 - (void)pasteboard:(NSPasteboard*)sender
244 item:(NSPasteboardItem*)item
245 provideDataForType:(NSString*)type {
246 [sender
247 setData:[NSData dataWithBytes:&gDraggedButton
248 length:sizeof(gDraggedButton)]
249 forType:ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType)];
250 }
251
252 - (NSDragOperation)draggingSession:(NSDraggingSession*)session 237 - (NSDragOperation)draggingSession:(NSDraggingSession*)session
253 sourceOperationMaskForDraggingContext:(NSDraggingContext)context { 238 sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
254 NSDragOperation operation = NSDragOperationCopy; 239 NSDragOperation operation = NSDragOperationCopy;
255 240
256 if (context == NSDraggingContextWithinApplication) 241 if (context == NSDraggingContextWithinApplication)
257 operation |= NSDragOperationMove; 242 operation |= NSDragOperationMove;
258 243
259 if ([delegate_ canDragBookmarkButtonToTrash:self]) 244 if ([delegate_ canDragBookmarkButtonToTrash:self])
260 operation |= NSDragOperationDelete; 245 operation |= NSDragOperationDelete;
261 246
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 [[cell clipPathForFrame:bounds inView:self] setClip]; 479 [[cell clipPathForFrame:bounds inView:self] setClip];
495 [cell drawWithFrame:bounds inView:self]; 480 [cell drawWithFrame:bounds inView:self];
496 481
497 CGContextEndTransparencyLayer(cgContext); 482 CGContextEndTransparencyLayer(cgContext);
498 [image unlockFocus]; 483 [image unlockFocus];
499 484
500 return image.autorelease(); 485 return image.autorelease();
501 } 486 }
502 487
503 @end 488 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_button.h ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_button_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698