Chromium Code Reviews| Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
| diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
| index 86303014acea83a5152c4932743979a40ed20563..8e6cd4a646d3800f4bdc8a0c25b57e5b0679fd86 100644 |
| --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
| +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm |
| @@ -18,8 +18,20 @@ |
| #include "ui/base/l10n/l10n_util_mac.h" |
| #include "ui/base/material_design/material_design_controller.h" |
| +@interface NSView (MountainLionSDK) |
| +- (NSDraggingSession*)beginDraggingSessionWithItems:(NSArray*)items |
| + event:(NSEvent*)event |
| + source: |
| + (id<NSDraggingSource>)source; |
| +@end |
|
Avi (use Gerrit)
2016/04/01 22:31:25
base/mac/sdk_forward_declarations.h ?
erikchen
2016/04/01 22:41:08
Done.
|
| + |
| namespace { |
| +// Set to true when an instance of this class is running a nested run loop. |
| +// Since this must always be run on the UI thread, there should never be two |
| +// simultaneous drags. |
| +bool gInDrag = false; |
| + |
| // When too much data is put into a single-line text field, things get |
| // janky due to the cost of computing the blink rect. Sometimes users |
| // accidentally paste large amounts, so place a limit on what will be |
| @@ -45,6 +57,9 @@ BOOL ThePasteboardIsTooDamnBig() { |
| } // namespace |
| +@interface AutocompleteTextFieldEditor ()<NSDraggingSource> |
| +@end |
| + |
| @implementation AutocompleteTextFieldEditor |
| - (BOOL)shouldDrawInsertionPoint { |
| @@ -104,19 +119,24 @@ BOOL ThePasteboardIsTooDamnBig() { |
| AutocompleteTextFieldObserver* observer = [self observer]; |
| DCHECK(observer); |
| if (observer && observer->CanCopy()) { |
| - NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; |
| - observer->CopyToPasteboard(pboard); |
| - |
| NSPoint p; |
| NSImage* image = [self dragImageForSelectionWithEvent:event origin:&p]; |
| - [self dragImage:image |
| - at:p |
| - offset:mouseOffset |
| - event:event |
| - pasteboard:pboard |
| - source:self |
| - slideBack:slideBack]; |
| + base::scoped_nsobject<NSPasteboardItem> item( |
| + observer->CreatePasteboardItem()); |
| + base::scoped_nsobject<NSDraggingItem> dragItem( |
| + [[NSDraggingItem alloc] initWithPasteboardWriter:item]); |
| + [dragItem setDraggingFrame:[self bounds] contents:image]; |
| + [self beginDraggingSessionWithItems:@[ dragItem.get() ] |
| + event:event |
| + source:self]; |
| + DCHECK(!gInDrag); |
| + gInDrag = true; |
| + while (gInDrag) { |
| + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode |
| + beforeDate:[NSDate distantFuture]]; |
| + } |
| + |
| return YES; |
| } |
| return [super dragSelectionWithEvent:event |
| @@ -124,6 +144,12 @@ BOOL ThePasteboardIsTooDamnBig() { |
| slideBack:slideBack]; |
| } |
| +- (void)draggingSession:(NSDraggingSession*)session |
| + endedAtPoint:(NSPoint)aPoint |
| + operation:(NSDragOperation)operation { |
| + gInDrag = false; |
| +} |
| + |
| - (void)copy:(id)sender { |
| AutocompleteTextFieldObserver* observer = [self observer]; |
| DCHECK(observer); |