| 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 24 matching lines...) Expand all Loading... |
| 35 // DragDropController, public: | 35 // DragDropController, public: |
| 36 | 36 |
| 37 DragDropController::DragDropController() | 37 DragDropController::DragDropController() |
| 38 : drag_image_(NULL), | 38 : drag_image_(NULL), |
| 39 drag_data_(NULL), | 39 drag_data_(NULL), |
| 40 drag_operation_(0), | 40 drag_operation_(0), |
| 41 drag_window_(NULL), | 41 drag_window_(NULL), |
| 42 drag_drop_in_progress_(false), | 42 drag_drop_in_progress_(false), |
| 43 should_block_during_drag_drop_(true) { | 43 should_block_during_drag_drop_(true) { |
| 44 Shell::GetInstance()->AddRootWindowEventFilter(this); | 44 Shell::GetInstance()->AddRootWindowEventFilter(this); |
| 45 aura::client::SetDragDropClient(Shell::GetRootWindow(), this); | 45 aura::client::SetDragDropClient(Shell::GetPrimaryRootWindow(), this); |
| 46 } | 46 } |
| 47 | 47 |
| 48 DragDropController::~DragDropController() { | 48 DragDropController::~DragDropController() { |
| 49 Shell::GetInstance()->RemoveRootWindowEventFilter(this); | 49 Shell::GetInstance()->RemoveRootWindowEventFilter(this); |
| 50 Cleanup(); | 50 Cleanup(); |
| 51 if (drag_image_.get()) | 51 if (drag_image_.get()) |
| 52 drag_image_.reset(); | 52 drag_image_.reset(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 55 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
| 56 const gfx::Point& root_location, | 56 const gfx::Point& root_location, |
| 57 int operation) { | 57 int operation) { |
| 58 DCHECK(!drag_drop_in_progress_); | 58 DCHECK(!drag_drop_in_progress_); |
| 59 aura::Window* capture_window = Shell::GetRootWindow()->capture_window(); | 59 aura::Window* capture_window = |
| 60 Shell::GetPrimaryRootWindow()->capture_window(); |
| 60 if (capture_window) | 61 if (capture_window) |
| 61 Shell::GetRootWindow()->ReleaseCapture(capture_window); | 62 Shell::GetPrimaryRootWindow()->ReleaseCapture(capture_window); |
| 62 drag_drop_in_progress_ = true; | 63 drag_drop_in_progress_ = true; |
| 63 | 64 |
| 64 drag_data_ = &data; | 65 drag_data_ = &data; |
| 65 drag_operation_ = operation; | 66 drag_operation_ = operation; |
| 66 const ui::OSExchangeDataProviderAura& provider = | 67 const ui::OSExchangeDataProviderAura& provider = |
| 67 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); | 68 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); |
| 68 | 69 |
| 69 drag_image_.reset(new DragImageView); | 70 drag_image_.reset(new DragImageView); |
| 70 drag_image_->SetImage(provider.drag_image()); | 71 drag_image_->SetImage(provider.drag_image()); |
| 71 drag_image_offset_ = provider.drag_image_offset(); | 72 drag_image_offset_ = provider.drag_image_offset(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } else { | 111 } else { |
| 111 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { | 112 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { |
| 112 aura::DropTargetEvent e(*drag_data_, | 113 aura::DropTargetEvent e(*drag_data_, |
| 113 event.location(), | 114 event.location(), |
| 114 event.root_location(), | 115 event.root_location(), |
| 115 drag_operation_); | 116 drag_operation_); |
| 116 e.set_flags(event.flags()); | 117 e.set_flags(event.flags()); |
| 117 int op = delegate->OnDragUpdated(e); | 118 int op = delegate->OnDragUpdated(e); |
| 118 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? | 119 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? |
| 119 ui::kCursorNoDrop : ui::kCursorCopy; | 120 ui::kCursorNoDrop : ui::kCursorCopy; |
| 120 Shell::GetRootWindow()->SetCursor(cursor); | 121 Shell::GetPrimaryRootWindow()->SetCursor(cursor); |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 DCHECK(drag_image_.get()); | 125 DCHECK(drag_image_.get()); |
| 125 if (drag_image_->visible()) { | 126 if (drag_image_->visible()) { |
| 126 drag_image_->SetScreenPosition( | 127 drag_image_->SetScreenPosition( |
| 127 event.root_location().Subtract(drag_image_offset_)); | 128 event.root_location().Subtract(drag_image_offset_)); |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 | 131 |
| 131 void DragDropController::Drop(aura::Window* target, | 132 void DragDropController::Drop(aura::Window* target, |
| 132 const aura::LocatedEvent& event) { | 133 const aura::LocatedEvent& event) { |
| 133 Shell::GetRootWindow()->SetCursor(ui::kCursorPointer); | 134 Shell::GetPrimaryRootWindow()->SetCursor(ui::kCursorPointer); |
| 134 aura::client::DragDropDelegate* delegate = NULL; | 135 aura::client::DragDropDelegate* delegate = NULL; |
| 135 | 136 |
| 136 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit | 137 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit |
| 137 // depends on not getting a Drop without DragEnter. This behavior is | 138 // depends on not getting a Drop without DragEnter. This behavior is |
| 138 // consistent with drag/drop on other platforms. | 139 // consistent with drag/drop on other platforms. |
| 139 if (target != drag_window_) | 140 if (target != drag_window_) |
| 140 DragUpdate(target, event); | 141 DragUpdate(target, event); |
| 141 DCHECK(target == drag_window_); | 142 DCHECK(target == drag_window_); |
| 142 | 143 |
| 143 if ((delegate = aura::client::GetDragDropDelegate(target))) { | 144 if ((delegate = aura::client::GetDragDropDelegate(target))) { |
| 144 aura::DropTargetEvent e( | 145 aura::DropTargetEvent e( |
| 145 *drag_data_, event.location(), event.root_location(), drag_operation_); | 146 *drag_data_, event.location(), event.root_location(), drag_operation_); |
| 146 e.set_flags(event.flags()); | 147 e.set_flags(event.flags()); |
| 147 drag_operation_ = delegate->OnPerformDrop(e); | 148 drag_operation_ = delegate->OnPerformDrop(e); |
| 148 if (drag_operation_ == 0) | 149 if (drag_operation_ == 0) |
| 149 StartCanceledAnimation(); | 150 StartCanceledAnimation(); |
| 150 else | 151 else |
| 151 drag_image_.reset(); | 152 drag_image_.reset(); |
| 152 } else { | 153 } else { |
| 153 drag_image_.reset(); | 154 drag_image_.reset(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 Cleanup(); | 157 Cleanup(); |
| 157 if (should_block_during_drag_drop_) | 158 if (should_block_during_drag_drop_) |
| 158 MessageLoop::current()->QuitNow(); | 159 MessageLoop::current()->QuitNow(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 void DragDropController::DragCancel() { | 162 void DragDropController::DragCancel() { |
| 162 Shell::GetRootWindow()->SetCursor(ui::kCursorPointer); | 163 Shell::GetPrimaryRootWindow()->SetCursor(ui::kCursorPointer); |
| 163 | 164 |
| 164 // |drag_window_| can be NULL if we have just started the drag and have not | 165 // |drag_window_| can be NULL if we have just started the drag and have not |
| 165 // received any DragUpdates, or, if the |drag_window_| gets destroyed during | 166 // received any DragUpdates, or, if the |drag_window_| gets destroyed during |
| 166 // a drag/drop. | 167 // a drag/drop. |
| 167 aura::client::DragDropDelegate* delegate = drag_window_? | 168 aura::client::DragDropDelegate* delegate = drag_window_? |
| 168 aura::client::GetDragDropDelegate(drag_window_) : NULL; | 169 aura::client::GetDragDropDelegate(drag_window_) : NULL; |
| 169 if (delegate) | 170 if (delegate) |
| 170 delegate->OnDragExited(); | 171 delegate->OnDragExited(); |
| 171 | 172 |
| 172 Cleanup(); | 173 Cleanup(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 void DragDropController::Cleanup() { | 271 void DragDropController::Cleanup() { |
| 271 if (drag_window_) | 272 if (drag_window_) |
| 272 drag_window_->RemoveObserver(this); | 273 drag_window_->RemoveObserver(this); |
| 273 drag_window_ = NULL; | 274 drag_window_ = NULL; |
| 274 drag_data_ = NULL; | 275 drag_data_ = NULL; |
| 275 drag_drop_in_progress_ = false; | 276 drag_drop_in_progress_ = false; |
| 276 } | 277 } |
| 277 | 278 |
| 278 } // namespace internal | 279 } // namespace internal |
| 279 } // namespace ash | 280 } // namespace ash |
| OLD | NEW |