| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 [sender draggingSourceOperationMask]); | 141 [sender draggingSourceOperationMask]); |
| 142 } | 142 } |
| 143 | 143 |
| 144 drag_operation = drop_helper_.OnDragOver( | 144 drag_operation = drop_helper_.OnDragOver( |
| 145 *[data_source_ data], LocationInView([sender draggingLocation]), | 145 *[data_source_ data], LocationInView([sender draggingLocation]), |
| 146 operation_); | 146 operation_); |
| 147 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); | 147 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); |
| 148 } | 148 } |
| 149 | 149 |
| 150 NSDragOperation DragDropClientMac::Drop(id<NSDraggingInfo> sender) { | 150 NSDragOperation DragDropClientMac::Drop(id<NSDraggingInfo> sender) { |
| 151 int drag_operation = drop_helper_.OnDrop( | 151 // OnDrop can optionally delete |this|, so clear data members first. |
| 152 *[data_source_ data], LocationInView([sender draggingLocation]), | 152 base::scoped_nsobject<CocoaDragDropDataProvider> data_source = data_source_; |
| 153 operation_); | 153 int operation = operation_; |
| 154 data_source_.reset(); | 154 data_source_.reset(); |
| 155 operation_ = 0; | 155 operation_ = 0; |
| 156 |
| 157 int drag_operation = drop_helper_.OnDrop( |
| 158 *[data_source data], LocationInView([sender draggingLocation]), |
| 159 operation); |
| 156 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); | 160 return ui::DragDropTypes::DragOperationToNSDragOperation(drag_operation); |
| 157 } | 161 } |
| 158 | 162 |
| 159 void DragDropClientMac::EndDrag() { | 163 void DragDropClientMac::EndDrag() { |
| 160 data_source_.reset(); | 164 data_source_.reset(); |
| 161 | 165 |
| 162 // Allow a test to invoke EndDrag() without spinning the nested run loop. | 166 // Allow a test to invoke EndDrag() without spinning the nested run loop. |
| 163 if (!quit_closure_.is_null()) { | 167 if (!quit_closure_.is_null()) { |
| 164 quit_closure_.Run(); | 168 quit_closure_.Run(); |
| 165 quit_closure_.Reset(); | 169 quit_closure_.Reset(); |
| 166 } | 170 } |
| 167 } | 171 } |
| 168 | 172 |
| 169 gfx::Point DragDropClientMac::LocationInView(NSPoint point) const { | 173 gfx::Point DragDropClientMac::LocationInView(NSPoint point) const { |
| 170 return gfx::Point(point.x, NSHeight([bridge_->ns_window() frame]) - point.y); | 174 return gfx::Point(point.x, NSHeight([bridge_->ns_window() frame]) - point.y); |
| 171 } | 175 } |
| 172 | 176 |
| 173 } // namespace views | 177 } // namespace views |
| OLD | NEW |