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..bc0c379790b428249a9b4815eeb6df7beb30a9a9 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,17 @@ |
| #include "ui/base/l10n/l10n_util_mac.h" |
| #include "ui/base/material_design/material_design_controller.h" |
| +@interface NSView (MountainLionSDK) |
| +- (BOOL)dragSelectionWithEvent:(NSEvent*)event |
| + offset:(NSSize)mouseOffset |
| + slideBack:(BOOL)slideBack; |
| +@end |
| + |
| namespace { |
| +// Set to true when an instance of this class is running a nested run loop. |
|
Mark Mentovai
2016/03/30 19:59:08
Add a few words on why it’s desirable for this to
erikchen
2016/03/30 20:05:29
Done:
"""
30 // Since this must always be run on
|
| +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 +54,9 @@ BOOL ThePasteboardIsTooDamnBig() { |
| } // namespace |
| +@interface AutocompleteTextFieldEditor ()<NSDraggingSource> |
| +@end |
| + |
| @implementation AutocompleteTextFieldEditor |
| - (BOOL)shouldDrawInsertionPoint { |
| @@ -104,19 +116,23 @@ 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]; |
| + gInDrag = true; |
|
Mark Mentovai
2016/03/30 19:59:08
DCHECK(!gInDrag);
erikchen
2016/03/30 20:05:29
Done.
|
| + while (gInDrag) { |
| + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode |
| + beforeDate:[NSDate distantFuture]]; |
| + } |
| + |
| return YES; |
| } |
| return [super dragSelectionWithEvent:event |
| @@ -124,6 +140,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); |