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