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

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: 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/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..7d8cb9a287dd2eadc1fcc6cd3d5bd4c23225aa93 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
@@ -4,6 +4,7 @@
#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
+#include "base/mac/sdk_forward_declarations.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" // IDC_*
@@ -20,6 +21,11 @@
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 +51,9 @@ BOOL ThePasteboardIsTooDamnBig() {
} // namespace
+@interface AutocompleteTextFieldEditor ()<NSDraggingSource>
+@end
+
@implementation AutocompleteTextFieldEditor
- (BOOL)shouldDrawInsertionPoint {
@@ -104,19 +113,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 +138,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