| 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_image_view.h" | 7 #include "ash/drag_drop/drag_image_view.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "ui/aura/client/drag_drop_delegate.h" | 10 #include "ui/aura/client/drag_drop_delegate.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 delegate->OnDragExited(); | 97 delegate->OnDragExited(); |
| 98 drag_window_->RemoveObserver(this); | 98 drag_window_->RemoveObserver(this); |
| 99 } | 99 } |
| 100 drag_window_ = target; | 100 drag_window_ = target; |
| 101 drag_window_->AddObserver(this); | 101 drag_window_->AddObserver(this); |
| 102 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { | 102 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { |
| 103 aura::DropTargetEvent e(*drag_data_, | 103 aura::DropTargetEvent e(*drag_data_, |
| 104 event.location(), | 104 event.location(), |
| 105 event.root_location(), | 105 event.root_location(), |
| 106 drag_operation_); | 106 drag_operation_); |
| 107 e.set_flags(event.flags()); |
| 107 delegate->OnDragEntered(e); | 108 delegate->OnDragEntered(e); |
| 108 } | 109 } |
| 109 } else { | 110 } else { |
| 110 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { | 111 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { |
| 111 aura::DropTargetEvent e(*drag_data_, | 112 aura::DropTargetEvent e(*drag_data_, |
| 112 event.location(), | 113 event.location(), |
| 113 event.root_location(), | 114 event.root_location(), |
| 114 drag_operation_); | 115 drag_operation_); |
| 116 e.set_flags(event.flags()); |
| 115 int op = delegate->OnDragUpdated(e); | 117 int op = delegate->OnDragUpdated(e); |
| 116 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? | 118 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? |
| 117 ui::kCursorNoDrop : ui::kCursorCopy; | 119 ui::kCursorNoDrop : ui::kCursorCopy; |
| 118 Shell::GetRootWindow()->SetCursor(cursor); | 120 Shell::GetRootWindow()->SetCursor(cursor); |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 122 DCHECK(drag_image_.get()); | 124 DCHECK(drag_image_.get()); |
| 123 if (drag_image_->visible()) { | 125 if (drag_image_->visible()) { |
| 124 drag_image_->SetScreenPosition( | 126 drag_image_->SetScreenPosition( |
| 125 event.root_location().Subtract(drag_image_offset_)); | 127 event.root_location().Subtract(drag_image_offset_)); |
| 126 } | 128 } |
| 127 } | 129 } |
| 128 | 130 |
| 129 void DragDropController::Drop(aura::Window* target, | 131 void DragDropController::Drop(aura::Window* target, |
| 130 const aura::LocatedEvent& event) { | 132 const aura::LocatedEvent& event) { |
| 131 Shell::GetRootWindow()->SetCursor(ui::kCursorPointer); | 133 Shell::GetRootWindow()->SetCursor(ui::kCursorPointer); |
| 132 aura::client::DragDropDelegate* delegate = NULL; | 134 aura::client::DragDropDelegate* delegate = NULL; |
| 133 | 135 |
| 134 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit | 136 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit |
| 135 // depends on not getting a Drop without DragEnter. This behavior is | 137 // depends on not getting a Drop without DragEnter. This behavior is |
| 136 // consistent with drag/drop on other platforms. | 138 // consistent with drag/drop on other platforms. |
| 137 if (target != drag_window_) | 139 if (target != drag_window_) |
| 138 DragUpdate(target, event); | 140 DragUpdate(target, event); |
| 139 DCHECK(target == drag_window_); | 141 DCHECK(target == drag_window_); |
| 140 | 142 |
| 141 if ((delegate = aura::client::GetDragDropDelegate(target))) { | 143 if ((delegate = aura::client::GetDragDropDelegate(target))) { |
| 142 aura::DropTargetEvent e( | 144 aura::DropTargetEvent e( |
| 143 *drag_data_, event.location(), event.root_location(), drag_operation_); | 145 *drag_data_, event.location(), event.root_location(), drag_operation_); |
| 146 e.set_flags(event.flags()); |
| 144 drag_operation_ = delegate->OnPerformDrop(e); | 147 drag_operation_ = delegate->OnPerformDrop(e); |
| 145 if (drag_operation_ == 0) | 148 if (drag_operation_ == 0) |
| 146 StartCanceledAnimation(); | 149 StartCanceledAnimation(); |
| 147 else | 150 else |
| 148 drag_image_.reset(); | 151 drag_image_.reset(); |
| 149 } else { | 152 } else { |
| 150 drag_image_.reset(); | 153 drag_image_.reset(); |
| 151 } | 154 } |
| 152 | 155 |
| 153 Cleanup(); | 156 Cleanup(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 void DragDropController::Cleanup() { | 270 void DragDropController::Cleanup() { |
| 268 if (drag_window_) | 271 if (drag_window_) |
| 269 drag_window_->RemoveObserver(this); | 272 drag_window_->RemoveObserver(this); |
| 270 drag_window_ = NULL; | 273 drag_window_ = NULL; |
| 271 drag_data_ = NULL; | 274 drag_data_ = NULL; |
| 272 drag_drop_in_progress_ = false; | 275 drag_drop_in_progress_ = false; |
| 273 } | 276 } |
| 274 | 277 |
| 275 } // namespace internal | 278 } // namespace internal |
| 276 } // namespace ash | 279 } // namespace ash |
| OLD | NEW |