OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ash/drag_drop/drag_drop_controller.h" | 5 #include "ash/drag_drop/drag_drop_controller.h" |
6 | 6 |
7 #include "ash/drag_drop/drag_drop_tracker.h" | 7 #include "ash/drag_drop/drag_drop_tracker.h" |
8 #include "ash/drag_drop/drag_image_view.h" | 8 #include "ash/drag_drop/drag_image_view.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/coordinate_conversion.h" | 10 #include "ash/wm/coordinate_conversion.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (drag_source_window_) | 237 if (drag_source_window_) |
238 drag_source_window_->RemoveObserver(this); | 238 drag_source_window_->RemoveObserver(this); |
239 drag_source_window_ = NULL; | 239 drag_source_window_ = NULL; |
240 } | 240 } |
241 | 241 |
242 return drag_operation_; | 242 return drag_operation_; |
243 } | 243 } |
244 | 244 |
245 void DragDropController::DragUpdate(aura::Window* target, | 245 void DragDropController::DragUpdate(aura::Window* target, |
246 const ui::LocatedEvent& event) { | 246 const ui::LocatedEvent& event) { |
247 aura::client::DragDropDelegate* delegate = NULL; | |
248 int op = ui::DragDropTypes::DRAG_NONE; | 247 int op = ui::DragDropTypes::DRAG_NONE; |
249 if (target != drag_window_) { | 248 if (target != drag_window_) { |
250 if (drag_window_) { | 249 if (drag_window_) { |
251 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) | 250 aura::client::DragDropDelegate* delegate = |
| 251 aura::client::GetDragDropDelegate(drag_window_); |
| 252 if (delegate) |
252 delegate->OnDragExited(); | 253 delegate->OnDragExited(); |
253 if (drag_window_ != drag_source_window_) | 254 if (drag_window_ != drag_source_window_) |
254 drag_window_->RemoveObserver(this); | 255 drag_window_->RemoveObserver(this); |
255 } | 256 } |
256 drag_window_ = target; | 257 drag_window_ = target; |
257 // We are already an observer of |drag_source_window_| so no need to add. | 258 // We are already an observer of |drag_source_window_| so no need to add. |
258 if (drag_window_ != drag_source_window_) | 259 if (drag_window_ != drag_source_window_) |
259 drag_window_->AddObserver(this); | 260 drag_window_->AddObserver(this); |
260 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { | 261 aura::client::DragDropDelegate* delegate = |
| 262 aura::client::GetDragDropDelegate(drag_window_); |
| 263 if (delegate) { |
261 ui::DropTargetEvent e(*drag_data_, | 264 ui::DropTargetEvent e(*drag_data_, |
262 event.location(), | 265 event.location(), |
263 event.root_location(), | 266 event.root_location(), |
264 drag_operation_); | 267 drag_operation_); |
265 e.set_flags(event.flags()); | 268 e.set_flags(event.flags()); |
266 delegate->OnDragEntered(e); | 269 delegate->OnDragEntered(e); |
267 } | 270 } |
268 } else { | 271 } else { |
269 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { | 272 aura::client::DragDropDelegate* delegate = |
| 273 aura::client::GetDragDropDelegate(drag_window_); |
| 274 if (delegate) { |
270 ui::DropTargetEvent e(*drag_data_, | 275 ui::DropTargetEvent e(*drag_data_, |
271 event.location(), | 276 event.location(), |
272 event.root_location(), | 277 event.root_location(), |
273 drag_operation_); | 278 drag_operation_); |
274 e.set_flags(event.flags()); | 279 e.set_flags(event.flags()); |
275 op = delegate->OnDragUpdated(e); | 280 op = delegate->OnDragUpdated(e); |
276 gfx::NativeCursor cursor = ui::kCursorNoDrop; | 281 gfx::NativeCursor cursor = ui::kCursorNoDrop; |
277 if (op & ui::DragDropTypes::DRAG_COPY) | 282 if (op & ui::DragDropTypes::DRAG_COPY) |
278 cursor = ui::kCursorCopy; | 283 cursor = ui::kCursorCopy; |
279 else if (op & ui::DragDropTypes::DRAG_LINK) | 284 else if (op & ui::DragDropTypes::DRAG_LINK) |
(...skipping 11 matching lines...) Expand all Loading... |
291 &root_location_in_screen); | 296 &root_location_in_screen); |
292 drag_image_->SetScreenPosition( | 297 drag_image_->SetScreenPosition( |
293 root_location_in_screen - drag_image_offset_); | 298 root_location_in_screen - drag_image_offset_); |
294 drag_image_->SetTouchDragOperation(op); | 299 drag_image_->SetTouchDragOperation(op); |
295 } | 300 } |
296 } | 301 } |
297 | 302 |
298 void DragDropController::Drop(aura::Window* target, | 303 void DragDropController::Drop(aura::Window* target, |
299 const ui::LocatedEvent& event) { | 304 const ui::LocatedEvent& event) { |
300 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); | 305 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); |
301 aura::client::DragDropDelegate* delegate = NULL; | |
302 | 306 |
303 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit | 307 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit |
304 // depends on not getting a Drop without DragEnter. This behavior is | 308 // depends on not getting a Drop without DragEnter. This behavior is |
305 // consistent with drag/drop on other platforms. | 309 // consistent with drag/drop on other platforms. |
306 if (target != drag_window_) | 310 if (target != drag_window_) |
307 DragUpdate(target, event); | 311 DragUpdate(target, event); |
308 DCHECK(target == drag_window_); | 312 DCHECK(target == drag_window_); |
309 | 313 |
310 if ((delegate = aura::client::GetDragDropDelegate(target))) { | 314 aura::client::DragDropDelegate* delegate = |
| 315 aura::client::GetDragDropDelegate(target); |
| 316 if (delegate) { |
311 ui::DropTargetEvent e( | 317 ui::DropTargetEvent e( |
312 *drag_data_, event.location(), event.root_location(), drag_operation_); | 318 *drag_data_, event.location(), event.root_location(), drag_operation_); |
313 e.set_flags(event.flags()); | 319 e.set_flags(event.flags()); |
314 drag_operation_ = delegate->OnPerformDrop(e); | 320 drag_operation_ = delegate->OnPerformDrop(e); |
315 if (drag_operation_ == 0) | 321 if (drag_operation_ == 0) |
316 StartCanceledAnimation(kCancelAnimationDuration); | 322 StartCanceledAnimation(kCancelAnimationDuration); |
317 else | 323 else |
318 drag_image_.reset(); | 324 drag_image_.reset(); |
319 } else { | 325 } else { |
320 drag_image_.reset(); | 326 drag_image_.reset(); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 if (drag_window_) | 557 if (drag_window_) |
552 drag_window_->RemoveObserver(this); | 558 drag_window_->RemoveObserver(this); |
553 drag_window_ = NULL; | 559 drag_window_ = NULL; |
554 drag_data_ = NULL; | 560 drag_data_ = NULL; |
555 // Cleanup can be called again while deleting DragDropTracker, so use Pass | 561 // Cleanup can be called again while deleting DragDropTracker, so use Pass |
556 // instead of reset to avoid double free. | 562 // instead of reset to avoid double free. |
557 drag_drop_tracker_.Pass(); | 563 drag_drop_tracker_.Pass(); |
558 } | 564 } |
559 | 565 |
560 } // namespace ash | 566 } // namespace ash |
OLD | NEW |