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

Unified Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm

Issue 1841813002: Update AutocompleteTextFieldEditor to use non-deprecated dragging APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/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);

Powered by Google App Engine
This is Rietveld 408576698