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

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 1964283002: MacViews: Implemented Drag & Drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for dcheng Created 4 years, 6 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: ui/views/cocoa/bridged_content_view.mm
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
index a59d4f0788461572994df001532e34bd5fbccace..5b5924f7cea1dccfc1bea1a4f454fc909e6798dd 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -10,6 +10,8 @@
#include "base/strings/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
+#include "ui/base/dragdrop/drag_drop_types.h"
+#include "ui/base/dragdrop/os_exchange_data_provider_mac.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/compositor/canvas_painter.h"
@@ -23,9 +25,12 @@
#import "ui/gfx/path_mac.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
#include "ui/strings/grit/ui_strings.h"
+#import "ui/views/cocoa/bridged_native_widget.h"
+#import "ui/views/cocoa/drag_drop_client_mac.h"
#include "ui/views/controls/menu/menu_config.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/view.h"
+#include "ui/views/widget/native_widget_mac.h"
#include "ui/views/widget/widget.h"
using views::MenuController;
@@ -225,6 +230,9 @@ base::string16 AttributedSubstringForRangeHelper(
// Notification handler invoked when the Full Keyboard Access mode is changed.
- (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification;
+// Returns the native Widget's drag drop client. Possibly null.
+- (views::DragDropClientMac*)dragDropClient;
+
// Menu action handlers.
- (void)undo:(id)sender;
- (void)redo:(id)sender;
@@ -272,6 +280,8 @@ base::string16 AttributedSubstringForRangeHelper(
// Initialize the focus manager with the correct keyboard accessibility
// setting.
[self updateFullKeyboardAccess];
+ [self registerForDraggedTypes:ui::OSExchangeDataProviderMac::
+ SupportedPasteboardTypes()];
}
return self;
}
@@ -396,6 +406,12 @@ base::string16 AttributedSubstringForRangeHelper(
[self updateFullKeyboardAccess];
}
+- (views::DragDropClientMac*)dragDropClient {
+ views::BridgedNativeWidget* bridge =
+ views::NativeWidgetMac::GetBridgeForNativeWindow([self window]);
+ return bridge ? bridge->drag_drop_client() : nullptr;
+}
+
- (void)undo:(id)sender {
// This DCHECK is more strict than a similar check in handleAction:. It can be
// done here because the actors sending these actions should be calling
@@ -585,6 +601,22 @@ base::string16 AttributedSubstringForRangeHelper(
return YES;
}
+// NSDraggingDestination protocol overrides.
+
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
+ return [self draggingUpdated:sender];
+}
+
+- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
+ views::DragDropClientMac* client = [self dragDropClient];
+ return client ? client->DragUpdate(sender) : ui::DragDropTypes::DRAG_NONE;
+}
+
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
+ views::DragDropClientMac* client = [self dragDropClient];
+ return client && client->Drop(sender) != NSDragOperationNone;
+}
+
- (NSTextInputContext*)inputContext {
// If the textInputClient_ does not exist, return nil since this view does not
// conform to NSTextInputClient protocol.
@@ -1177,6 +1209,21 @@ base::string16 AttributedSubstringForRangeHelper(
return NO;
}
+// NSDraggingSource protocol implementation.
+
+- (NSDragOperation)draggingSession:(NSDraggingSession*)session
+ sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
+ return NSDragOperationEvery;
+}
+
+- (void)draggingSession:(NSDraggingSession*)session
+ endedAtPoint:(NSPoint)screenPoint
+ operation:(NSDragOperation)operation {
+ views::DragDropClientMac* client = [self dragDropClient];
+ if (client)
+ client->EndDrag();
+}
+
// NSAccessibility informal protocol implementation.
- (id)accessibilityAttributeValue:(NSString*)attribute {

Powered by Google App Engine
This is Rietveld 408576698