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

Unified Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm

Issue 1815053002: Update BookmarkBarController to use non-deprecated dragging APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp20_107_bluetooth
Patch Set: Comments from avi. Created 4 years, 9 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: chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm
index 6eea93677469813272e9aef36cacb8949859f8bf..43664314dfd8e4a2caf767cbfe49d682188aa875 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm
@@ -9,8 +9,10 @@
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#import "base/mac/scoped_nsobject.h"
+#include "base/mac/sdk_forward_declarations.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
+#import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "components/bookmarks/browser/bookmark_model.h"
@@ -33,7 +35,19 @@ namespace {
BookmarkButton* gDraggedButton = nil; // Weak
};
-@interface BookmarkButton(Private)
+@interface BookmarkButton() <NSPasteboardItemDataProvider>
+
+// NSPasteboardItemDataProvider:
+- (void)pasteboard:(NSPasteboard*)sender
+ item:(NSPasteboardItem*)item
+ provideDataForType:(NSString*)type;
+
+// NSDraggingSource:
+- (void)draggingSession:(NSDraggingSession*)session
+ endedAtPoint:(NSPoint)aPoint
+ operation:(NSDragOperation)operation;
+- (NSDragOperation)draggingSession:(NSDraggingSession*)session
+ sourceOperationMaskForDraggingContext:(NSDraggingContext)context;
// Make a drag image for the button.
- (NSImage*)dragImage;
@@ -42,7 +56,6 @@ BookmarkButton* gDraggedButton = nil; // Weak
@end // @interface BookmarkButton(Private)
-
@implementation BookmarkButton
@synthesize delegate = delegate_;
@@ -175,10 +188,6 @@ BookmarkButton* gDraggedButton = nil; // Weak
// the stack.
[self retain];
- // Ask our delegate to fill the pasteboard for us.
- NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
- [[self delegate] fillPasteboard:pboard forDragOfButton:self];
-
// Lock bar visibility, forcing the overlay to stay visible if we are in
// fullscreen mode.
if ([[self delegate] dragShouldLockBarVisibility]) {
@@ -202,12 +211,23 @@ BookmarkButton* gDraggedButton = nil; // Weak
dragPending_ = YES;
gDraggedButton = self;
- CGFloat yAt = [self bounds].size.height;
- NSSize dragOffset = NSMakeSize(0.0, 0.0);
NSImage* image = [self dragImage];
[self setHidden:YES];
- [self dragImage:image at:NSMakePoint(0, yAt) offset:dragOffset
- event:event pasteboard:pboard source:self slideBack:YES];
+
+ NSPasteboardItem* pbItem = [NSPasteboardItem new];
+ [pbItem setDataProvider:self forTypes:@[ kBookmarkButtonDragType ]];
+
+ base::scoped_nsobject<NSDraggingItem> dragItem(
+ [[NSDraggingItem alloc] initWithPasteboardWriter:pbItem]);
+ [dragItem setDraggingFrame:[self bounds] contents:image];
+
+ [self beginDraggingSessionWithItems:@[ dragItem.get() ]
+ event:event
+ source:self];
+ while (gDraggedButton != nil) {
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
+ beforeDate:[NSDate distantFuture]];
+ }
[self setHidden:NO];
// And we're done.
@@ -217,6 +237,27 @@ BookmarkButton* gDraggedButton = nil; // Weak
[self autorelease];
}
+- (void)pasteboard:(NSPasteboard*)sender
+ item:(NSPasteboardItem*)item
+ provideDataForType:(NSString*)type {
+ [sender setData:[NSData dataWithBytes:&gDraggedButton
+ length:sizeof(gDraggedButton)]
+ forType:kBookmarkButtonDragType];
+}
+
+- (NSDragOperation)draggingSession:(NSDraggingSession*)session
+ sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
+ NSDragOperation operation = NSDragOperationCopy;
+
+ if (context == NSDraggingContextWithinApplication)
+ operation |= NSDragOperationMove;
+
+ if ([delegate_ canDragBookmarkButtonToTrash:self])
+ operation |= NSDragOperationDelete;
+
+ return operation;
+}
+
// Overridden to release bar visibility.
- (DraggableButtonResult)endDrag {
gDraggedButton = nil;
@@ -230,20 +271,9 @@ BookmarkButton* gDraggedButton = nil; // Weak
return kDraggableButtonImplUseBase;
}
-- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
- NSDragOperation operation = NSDragOperationCopy;
- if (isLocal) {
- operation |= NSDragOperationMove;
- }
- if ([delegate_ canDragBookmarkButtonToTrash:self]) {
- operation |= NSDragOperationDelete;
- }
- return operation;
-}
-
-- (void)draggedImage:(NSImage *)anImage
- endedAt:(NSPoint)aPoint
- operation:(NSDragOperation)operation {
+- (void)draggingSession:(NSDraggingSession*)session
+ endedAtPoint:(NSPoint)aPoint
+ operation:(NSDragOperation)operation {
gDraggedButton = nil;
// Inform delegate of drag source that we're finished dragging,
// so it can close auto-opened bookmark folders etc.
@@ -325,8 +355,6 @@ BookmarkButton* gDraggedButton = nil; // Weak
return kDraggableButtonMixinDidWork;
}
-
-
// mouseEntered: and mouseExited: are called from our
// BookmarkButtonCell. We redirect this information to our delegate.
// The controller can then perform menu-like actions (e.g. "hover over
@@ -428,11 +456,6 @@ BookmarkButton* gDraggedButton = nil; // Weak
[self setNeedsDisplay:YES];
}
-@end
-
-@implementation BookmarkButton(Private)
-
-
- (void)installCustomTrackingArea {
const NSTrackingAreaOptions options =
NSTrackingActiveAlways |
@@ -451,7 +474,6 @@ BookmarkButton* gDraggedButton = nil; // Weak
[self addTrackingArea:area_];
}
-
- (NSImage*)dragImage {
NSRect bounds = [self bounds];
base::scoped_nsobject<NSImage> image(
@@ -474,4 +496,4 @@ BookmarkButton* gDraggedButton = nil; // Weak
return image.autorelease();
}
-@end // @implementation BookmarkButton(Private)
+@end
« 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