| 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 43664314dfd8e4a2caf767cbfe49d682188aa875..6eea93677469813272e9aef36cacb8949859f8bf 100644
|
| --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm
|
| +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm
|
| @@ -9,10 +9,8 @@
|
| #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"
|
| @@ -35,19 +33,7 @@
|
| BookmarkButton* gDraggedButton = nil; // Weak
|
| };
|
|
|
| -@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;
|
| +@interface BookmarkButton(Private)
|
|
|
| // Make a drag image for the button.
|
| - (NSImage*)dragImage;
|
| @@ -55,6 +41,7 @@
|
| - (void)installCustomTrackingArea;
|
|
|
| @end // @interface BookmarkButton(Private)
|
| +
|
|
|
| @implementation BookmarkButton
|
|
|
| @@ -188,6 +175,10 @@
|
| // 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]) {
|
| @@ -211,23 +202,12 @@
|
| dragPending_ = YES;
|
| gDraggedButton = self;
|
|
|
| + CGFloat yAt = [self bounds].size.height;
|
| + NSSize dragOffset = NSMakeSize(0.0, 0.0);
|
| NSImage* image = [self dragImage];
|
| [self setHidden: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 dragImage:image at:NSMakePoint(0, yAt) offset:dragOffset
|
| + event:event pasteboard:pboard source:self slideBack:YES];
|
| [self setHidden:NO];
|
|
|
| // And we're done.
|
| @@ -235,27 +215,6 @@
|
| gDraggedButton = nil;
|
|
|
| [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.
|
| @@ -271,9 +230,20 @@
|
| return kDraggableButtonImplUseBase;
|
| }
|
|
|
| -- (void)draggingSession:(NSDraggingSession*)session
|
| - endedAtPoint:(NSPoint)aPoint
|
| - operation:(NSDragOperation)operation {
|
| +- (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 {
|
| gDraggedButton = nil;
|
| // Inform delegate of drag source that we're finished dragging,
|
| // so it can close auto-opened bookmark folders etc.
|
| @@ -355,6 +325,8 @@
|
| 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
|
| @@ -456,6 +428,11 @@
|
| [self setNeedsDisplay:YES];
|
| }
|
|
|
| +@end
|
| +
|
| +@implementation BookmarkButton(Private)
|
| +
|
| +
|
| - (void)installCustomTrackingArea {
|
| const NSTrackingAreaOptions options =
|
| NSTrackingActiveAlways |
|
| @@ -474,6 +451,7 @@
|
| [self addTrackingArea:area_];
|
| }
|
|
|
| +
|
| - (NSImage*)dragImage {
|
| NSRect bounds = [self bounds];
|
| base::scoped_nsobject<NSImage> image(
|
| @@ -496,4 +474,4 @@
|
| return image.autorelease();
|
| }
|
|
|
| -@end
|
| +@end // @implementation BookmarkButton(Private)
|
|
|