| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ui/views/cocoa/drag_drop_client_mac.h" | 5 #import "ui/views/cocoa/drag_drop_client_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "ui/base/dragdrop/os_exchange_data_provider_mac.h" | 10 #import "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 NSDragOperation DragDropClientMac::DragUpdate(id<NSDraggingInfo> sender) { | 127 NSDragOperation DragDropClientMac::DragUpdate(id<NSDraggingInfo> sender) { |
| 128 int drag_operation = ui::DragDropTypes::DRAG_NONE; | 128 int drag_operation = ui::DragDropTypes::DRAG_NONE; |
| 129 | 129 |
| 130 // Since dragging from non MacView sources does not generate OSExchangeData, | 130 // Since dragging from non MacView sources does not generate OSExchangeData, |
| 131 // we need to generate one based on the provided pasteboard. | 131 // we need to generate one based on the provided pasteboard. |
| 132 if (!data_source_.get()) { | 132 if (!data_source_.get()) { |
| 133 data_source_.reset([[CocoaDragDropDataProvider alloc] | 133 data_source_.reset([[CocoaDragDropDataProvider alloc] |
| 134 initWithPasteboard:[sender draggingPasteboard]]); | 134 initWithPasteboard:[sender draggingPasteboard]]); |
| 135 operation_ = ui::DragDropTypes::NSDragOperationToDragOperation( |
| 136 [sender draggingSourceOperationMask]); |
| 135 } | 137 } |
| 136 | 138 |
| 137 drag_operation = drop_helper_.OnDragOver( | 139 drag_operation = drop_helper_.OnDragOver( |
| 138 *[data_source_ data], LocationInView([sender draggingLocation]), | 140 *[data_source_ data], LocationInView([sender draggingLocation]), |
| 139 operation_); | 141 operation_); |
| 140 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); | 142 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); |
| 141 } | 143 } |
| 142 | 144 |
| 143 NSDragOperation DragDropClientMac::Drop(id<NSDraggingInfo> sender) { | 145 NSDragOperation DragDropClientMac::Drop(id<NSDraggingInfo> sender) { |
| 144 int drag_operation = drop_helper_.OnDrop( | 146 int drag_operation = drop_helper_.OnDrop( |
| 145 *[data_source_ data], LocationInView([sender draggingLocation]), | 147 *[data_source_ data], LocationInView([sender draggingLocation]), |
| 146 operation_); | 148 operation_); |
| 149 data_source_.reset(); |
| 150 operation_ = 0; |
| 147 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); | 151 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); |
| 148 } | 152 } |
| 149 | 153 |
| 150 void DragDropClientMac::EndDrag() { | 154 void DragDropClientMac::EndDrag() { |
| 151 data_source_.reset(); | 155 data_source_.reset(); |
| 152 | 156 |
| 153 // Allow a test to invoke EndDrag() without spinning the nested run loop. | 157 // Allow a test to invoke EndDrag() without spinning the nested run loop. |
| 154 if (!quit_closure_.is_null()) { | 158 if (!quit_closure_.is_null()) { |
| 155 quit_closure_.Run(); | 159 quit_closure_.Run(); |
| 156 quit_closure_.Reset(); | 160 quit_closure_.Reset(); |
| 157 } | 161 } |
| 158 } | 162 } |
| 159 | 163 |
| 160 gfx::Point DragDropClientMac::LocationInView(NSPoint point) const { | 164 gfx::Point DragDropClientMac::LocationInView(NSPoint point) const { |
| 161 return gfx::Point(point.x, NSHeight([bridge_->ns_window() frame]) - point.y); | 165 return gfx::Point(point.x, NSHeight([bridge_->ns_window() frame]) - point.y); |
| 162 } | 166 } |
| 163 | 167 |
| 164 } // namespace views | 168 } // namespace views |
| OLD | NEW |