| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/drag_drop_controller.h" | 5 #include "ui/aura_shell/drag_drop_controller.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/window_drag_drop_delegate.h" | 9 #include "ui/aura/client/drag_drop_delegate.h" |
| 10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura_shell/drag_image_view.h" | 12 #include "ui/aura_shell/drag_image_view.h" |
| 13 #include "ui/aura_shell/shell.h" | 13 #include "ui/aura_shell/shell.h" |
| 14 #include "ui/base/dragdrop/drag_drop_types.h" | 14 #include "ui/base/dragdrop/drag_drop_types.h" |
| 15 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 15 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
| 16 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
| 17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 18 #include "ui/views/widget/native_widget_aura.h" | 18 #include "ui/views/widget/native_widget_aura.h" |
| 19 | 19 |
| 20 namespace aura_shell { | 20 namespace aura_shell { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 using aura::RootWindow; | 23 using aura::RootWindow; |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 aura::WindowDragDropDelegate* GetDragDropDelegate(aura::Window* window) { | |
| 27 if (!window) | |
| 28 return NULL; | |
| 29 void* prop = window->GetProperty(aura::kDragDropDelegateKey); | |
| 30 if (!prop) | |
| 31 return NULL; | |
| 32 return static_cast<aura::WindowDragDropDelegate*>(prop); | |
| 33 } | |
| 34 | |
| 35 const gfx::Point kDragDropWidgetOffset(0, 0); | 26 const gfx::Point kDragDropWidgetOffset(0, 0); |
| 36 | |
| 37 } | 27 } |
| 38 | 28 |
| 39 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 40 // DragDropController, public: | 30 // DragDropController, public: |
| 41 | 31 |
| 42 DragDropController::DragDropController() | 32 DragDropController::DragDropController() |
| 43 : aura::EventFilter(RootWindow::GetInstance()), | 33 : aura::EventFilter(RootWindow::GetInstance()), |
| 44 drag_image_(NULL), | 34 drag_image_(NULL), |
| 45 drag_data_(NULL), | 35 drag_data_(NULL), |
| 46 drag_operation_(0), | 36 drag_operation_(0), |
| 47 dragged_window_(NULL), | 37 dragged_window_(NULL), |
| 48 drag_drop_in_progress_(false), | 38 drag_drop_in_progress_(false), |
| 49 should_block_during_drag_drop_(true) { | 39 should_block_during_drag_drop_(true) { |
| 50 Shell::GetInstance()->AddRootWindowEventFilter(this); | 40 Shell::GetInstance()->AddRootWindowEventFilter(this); |
| 41 aura::client::SetDragDropClient(this); |
| 51 } | 42 } |
| 52 | 43 |
| 53 DragDropController::~DragDropController() { | 44 DragDropController::~DragDropController() { |
| 54 Shell::GetInstance()->RemoveRootWindowEventFilter(this); | 45 Shell::GetInstance()->RemoveRootWindowEventFilter(this); |
| 55 Cleanup(); | 46 Cleanup(); |
| 56 } | 47 } |
| 57 | 48 |
| 58 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 49 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
| 59 int operation) { | 50 int operation) { |
| 60 DCHECK(!drag_drop_in_progress_); | 51 DCHECK(!drag_drop_in_progress_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 79 | 70 |
| 80 if (should_block_during_drag_drop_) { | 71 if (should_block_during_drag_drop_) { |
| 81 MessageLoopForUI::current()->RunWithDispatcher( | 72 MessageLoopForUI::current()->RunWithDispatcher( |
| 82 RootWindow::GetInstance()->GetDispatcher()); | 73 RootWindow::GetInstance()->GetDispatcher()); |
| 83 } | 74 } |
| 84 return drag_operation_; | 75 return drag_operation_; |
| 85 } | 76 } |
| 86 | 77 |
| 87 void DragDropController::DragUpdate(aura::Window* target, | 78 void DragDropController::DragUpdate(aura::Window* target, |
| 88 const aura::MouseEvent& event) { | 79 const aura::MouseEvent& event) { |
| 89 aura::WindowDragDropDelegate* delegate = NULL; | 80 aura::client::DragDropDelegate* delegate = NULL; |
| 90 if (target != dragged_window_) { | 81 if (target != dragged_window_) { |
| 91 if ((delegate = GetDragDropDelegate(dragged_window_))) | 82 if (dragged_window_ && |
| 83 (delegate = aura::client::GetDragDropDelegate(dragged_window_))) { |
| 92 delegate->OnDragExited(); | 84 delegate->OnDragExited(); |
| 85 } |
| 93 dragged_window_ = target; | 86 dragged_window_ = target; |
| 94 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 87 if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) { |
| 95 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 88 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
| 96 delegate->OnDragEntered(e); | 89 delegate->OnDragEntered(e); |
| 97 } | 90 } |
| 98 } else { | 91 } else { |
| 99 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 92 if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) { |
| 100 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 93 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
| 101 int op = delegate->OnDragUpdated(e); | 94 int op = delegate->OnDragUpdated(e); |
| 102 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? | 95 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? |
| 103 aura::kCursorMove : aura::kCursorHand; | 96 aura::kCursorMove : aura::kCursorHand; |
| 104 RootWindow::GetInstance()->SetCursor(cursor); | 97 RootWindow::GetInstance()->SetCursor(cursor); |
| 105 } | 98 } |
| 106 } | 99 } |
| 107 | 100 |
| 108 DCHECK(drag_image_.get()); | 101 DCHECK(drag_image_.get()); |
| 109 if (drag_image_->visible()) { | 102 if (drag_image_->visible()) { |
| 110 drag_image_->SetScreenPosition(RootWindow::GetInstance()-> | 103 drag_image_->SetScreenPosition(RootWindow::GetInstance()-> |
| 111 last_mouse_location().Add(kDragDropWidgetOffset)); | 104 last_mouse_location().Add(kDragDropWidgetOffset)); |
| 112 } | 105 } |
| 113 } | 106 } |
| 114 | 107 |
| 115 void DragDropController::Drop(aura::Window* target, | 108 void DragDropController::Drop(aura::Window* target, |
| 116 const aura::MouseEvent& event) { | 109 const aura::MouseEvent& event) { |
| 117 aura::WindowDragDropDelegate* delegate = NULL; | 110 aura::client::DragDropDelegate* delegate = NULL; |
| 118 DCHECK(target == dragged_window_); | 111 DCHECK(target == dragged_window_); |
| 119 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 112 if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) { |
| 120 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 113 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
| 121 drag_operation_ = delegate->OnPerformDrop(e); | 114 drag_operation_ = delegate->OnPerformDrop(e); |
| 122 // TODO(varunjain): if drag_op is 0, do drag widget flying back animation | 115 // TODO(varunjain): if drag_op is 0, do drag widget flying back animation |
| 123 } | 116 } |
| 124 | 117 |
| 125 Cleanup(); | 118 Cleanup(); |
| 126 if (should_block_during_drag_drop_) | 119 if (should_block_during_drag_drop_) |
| 127 MessageLoop::current()->Quit(); | 120 MessageLoop::current()->Quit(); |
| 128 } | 121 } |
| 129 | 122 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // DragDropController, private: | 168 // DragDropController, private: |
| 176 | 169 |
| 177 void DragDropController::Cleanup() { | 170 void DragDropController::Cleanup() { |
| 178 drag_image_.reset(); | 171 drag_image_.reset(); |
| 179 drag_data_ = NULL; | 172 drag_data_ = NULL; |
| 180 drag_drop_in_progress_ = false; | 173 drag_drop_in_progress_ = false; |
| 181 } | 174 } |
| 182 | 175 |
| 183 } // namespace internal | 176 } // namespace internal |
| 184 } // namespace aura_shell | 177 } // namespace aura_shell |
| OLD | NEW |