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

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

Issue 1855783002: mac: More pasteboard fixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp23_dnd
Patch Set: 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"
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #include "base/mac/sdk_forward_declarations.h" 12 #include "base/mac/sdk_forward_declarations.h"
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h"
14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h"
16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
17 #import "chrome/browser/ui/cocoa/view_id_util.h" 17 #import "chrome/browser/ui/cocoa/view_id_util.h"
18 #include "components/bookmarks/browser/bookmark_model.h" 18 #include "components/bookmarks/browser/bookmark_model.h"
19 #include "content/public/browser/user_metrics.h" 19 #include "content/public/browser/user_metrics.h"
20 #include "ui/base/clipboard/clipboard_util_mac.h"
20 #include "ui/base/cocoa/cocoa_base_utils.h" 21 #include "ui/base/cocoa/cocoa_base_utils.h"
21 #import "ui/base/cocoa/nsview_additions.h" 22 #import "ui/base/cocoa/nsview_additions.h"
22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 23 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
23 24
24 using base::UserMetricsAction; 25 using base::UserMetricsAction;
25 using bookmarks::BookmarkNode; 26 using bookmarks::BookmarkNode;
26 27
27 // The opacity of the bookmark button drag image. 28 // The opacity of the bookmark button drag image.
28 static const CGFloat kDragImageOpacity = 0.7; 29 static const CGFloat kDragImageOpacity = 0.7;
29 30
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 209 }
209 210
210 dragMouseOffset_ = [self convertPoint:[event locationInWindow] fromView:nil]; 211 dragMouseOffset_ = [self convertPoint:[event locationInWindow] fromView:nil];
211 dragPending_ = YES; 212 dragPending_ = YES;
212 gDraggedButton = self; 213 gDraggedButton = self;
213 214
214 NSImage* image = [self dragImage]; 215 NSImage* image = [self dragImage];
215 [self setHidden:YES]; 216 [self setHidden:YES];
216 217
217 NSPasteboardItem* pbItem = [NSPasteboardItem new]; 218 NSPasteboardItem* pbItem = [NSPasteboardItem new];
218 [pbItem setDataProvider:self forTypes:@[ kBookmarkButtonDragType ]]; 219 [pbItem setDataProvider:self
220 forTypes:@[ ui::ClipboardUtil::UTIForPasteboardType(
221 kBookmarkButtonDragType) ]];
219 222
220 base::scoped_nsobject<NSDraggingItem> dragItem( 223 base::scoped_nsobject<NSDraggingItem> dragItem(
221 [[NSDraggingItem alloc] initWithPasteboardWriter:pbItem]); 224 [[NSDraggingItem alloc] initWithPasteboardWriter:pbItem]);
222 [dragItem setDraggingFrame:[self bounds] contents:image]; 225 [dragItem setDraggingFrame:[self bounds] contents:image];
223 226
224 [self beginDraggingSessionWithItems:@[ dragItem.get() ] 227 [self beginDraggingSessionWithItems:@[ dragItem.get() ]
225 event:event 228 event:event
226 source:self]; 229 source:self];
227 while (gDraggedButton != nil) { 230 while (gDraggedButton != nil) {
228 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 231 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
229 beforeDate:[NSDate distantFuture]]; 232 beforeDate:[NSDate distantFuture]];
230 } 233 }
231 [self setHidden:NO]; 234 [self setHidden:NO];
232 235
233 // And we're done. 236 // And we're done.
234 dragPending_ = NO; 237 dragPending_ = NO;
235 gDraggedButton = nil; 238 gDraggedButton = nil;
236 239
237 [self autorelease]; 240 [self autorelease];
238 } 241 }
239 242
240 - (void)pasteboard:(NSPasteboard*)sender 243 - (void)pasteboard:(NSPasteboard*)sender
241 item:(NSPasteboardItem*)item 244 item:(NSPasteboardItem*)item
242 provideDataForType:(NSString*)type { 245 provideDataForType:(NSString*)type {
243 [sender setData:[NSData dataWithBytes:&gDraggedButton 246 [sender
244 length:sizeof(gDraggedButton)] 247 setData:[NSData dataWithBytes:&gDraggedButton
245 forType:kBookmarkButtonDragType]; 248 length:sizeof(gDraggedButton)]
249 forType:ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType)];
246 } 250 }
247 251
248 - (NSDragOperation)draggingSession:(NSDraggingSession*)session 252 - (NSDragOperation)draggingSession:(NSDraggingSession*)session
249 sourceOperationMaskForDraggingContext:(NSDraggingContext)context { 253 sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
250 NSDragOperation operation = NSDragOperationCopy; 254 NSDragOperation operation = NSDragOperationCopy;
251 255
252 if (context == NSDraggingContextWithinApplication) 256 if (context == NSDraggingContextWithinApplication)
253 operation |= NSDragOperationMove; 257 operation |= NSDragOperationMove;
254 258
255 if ([delegate_ canDragBookmarkButtonToTrash:self]) 259 if ([delegate_ canDragBookmarkButtonToTrash:self])
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 [[cell clipPathForFrame:bounds inView:self] setClip]; 494 [[cell clipPathForFrame:bounds inView:self] setClip];
491 [cell drawWithFrame:bounds inView:self]; 495 [cell drawWithFrame:bounds inView:self];
492 496
493 CGContextEndTransparencyLayer(cgContext); 497 CGContextEndTransparencyLayer(cgContext);
494 [image unlockFocus]; 498 [image unlockFocus];
495 499
496 return image.autorelease(); 500 return image.autorelease();
497 } 501 }
498 502
499 @end 503 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698