| 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/window_drag_drop_delegate.h" |
| 10 #include "ui/aura/desktop.h" | 10 #include "ui/aura/desktop.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 drag_drop_in_progress_(false), | 48 drag_drop_in_progress_(false), |
| 49 should_block_during_drag_drop_(true) { | 49 should_block_during_drag_drop_(true) { |
| 50 Shell::GetInstance()->AddDesktopEventFilter(this); | 50 Shell::GetInstance()->AddDesktopEventFilter(this); |
| 51 } | 51 } |
| 52 | 52 |
| 53 DragDropController::~DragDropController() { | 53 DragDropController::~DragDropController() { |
| 54 Shell::GetInstance()->RemoveDesktopEventFilter(this); | 54 Shell::GetInstance()->RemoveDesktopEventFilter(this); |
| 55 Cleanup(); | 55 Cleanup(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 58 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
| 59 int operation) { | 59 int operation) { |
| 60 DCHECK(!drag_drop_in_progress_); | 60 DCHECK(!drag_drop_in_progress_); |
| 61 aura::Window* capture_window = Desktop::GetInstance()->capture_window(); | 61 aura::Window* capture_window = Desktop::GetInstance()->capture_window(); |
| 62 if (capture_window) | 62 if (capture_window) |
| 63 Desktop::GetInstance()->ReleaseCapture(capture_window); | 63 Desktop::GetInstance()->ReleaseCapture(capture_window); |
| 64 drag_drop_in_progress_ = true; | 64 drag_drop_in_progress_ = true; |
| 65 | 65 |
| 66 drag_data_ = &data; | 66 drag_data_ = &data; |
| 67 drag_operation_ = operation; | 67 drag_operation_ = operation; |
| 68 gfx::Point location = Desktop::GetInstance()->last_mouse_location(); | 68 gfx::Point location = Desktop::GetInstance()->last_mouse_location(); |
| 69 const ui::OSExchangeDataProviderAura& provider = | 69 const ui::OSExchangeDataProviderAura& provider = |
| 70 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); | 70 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); |
| 71 | 71 |
| 72 drag_image_.reset(new DragImageView); | 72 drag_image_.reset(new DragImageView); |
| 73 drag_image_->SetImage(provider.drag_image()); | 73 drag_image_->SetImage(provider.drag_image()); |
| 74 drag_image_->SetScreenBounds(gfx::Rect(location.Add(kDragDropWidgetOffset), | 74 drag_image_->SetScreenBounds(gfx::Rect(location.Add(kDragDropWidgetOffset), |
| 75 drag_image_->GetPreferredSize())); | 75 drag_image_->GetPreferredSize())); |
| 76 drag_image_->SetWidgetVisible(true); | 76 drag_image_->SetWidgetVisible(true); |
| 77 | 77 |
| 78 dragged_window_ = Desktop::GetInstance()->GetEventHandlerForPoint(location); | 78 dragged_window_ = NULL; |
| 79 | 79 |
| 80 if (should_block_during_drag_drop_) { | 80 if (should_block_during_drag_drop_) { |
| 81 MessageLoopForUI::current()->RunWithDispatcher( | 81 MessageLoopForUI::current()->RunWithDispatcher( |
| 82 Desktop::GetInstance()->GetDispatcher()); | 82 Desktop::GetInstance()->GetDispatcher()); |
| 83 } | 83 } |
| 84 return drag_operation_; |
| 84 } | 85 } |
| 85 | 86 |
| 86 void DragDropController::DragUpdate(aura::Window* target, | 87 void DragDropController::DragUpdate(aura::Window* target, |
| 87 const aura::MouseEvent& event) { | 88 const aura::MouseEvent& event) { |
| 88 aura::WindowDragDropDelegate* delegate = NULL; | 89 aura::WindowDragDropDelegate* delegate = NULL; |
| 89 if (target != dragged_window_) { | 90 if (target != dragged_window_) { |
| 90 if ((delegate = GetDragDropDelegate(dragged_window_))) | 91 if ((delegate = GetDragDropDelegate(dragged_window_))) |
| 91 delegate->OnDragExited(); | 92 delegate->OnDragExited(); |
| 92 dragged_window_ = target; | 93 dragged_window_ = target; |
| 93 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 94 if ((delegate = GetDragDropDelegate(dragged_window_))) { |
| 94 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 95 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
| 95 if (delegate->CanDrop(e)) | 96 delegate->OnDragEntered(e); |
| 96 delegate->OnDragEntered(e); | |
| 97 } | 97 } |
| 98 } else { | 98 } else { |
| 99 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 99 if ((delegate = GetDragDropDelegate(dragged_window_))) { |
| 100 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 100 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
| 101 delegate->OnDragUpdated(e); | 101 int op = delegate->OnDragUpdated(e); |
| 102 // TODO(varunjain): uncomment the following lines when cursor issue with | 102 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? |
| 103 // X for tests is fixed. | 103 aura::kCursorMove : aura::kCursorHand; |
| 104 // gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? | 104 Desktop::GetInstance()->SetCursor(cursor); |
| 105 // aura::kCursorMove : aura::kCursorHand; | |
| 106 // Desktop::GetInstance()->SetCursor(cursor); | |
| 107 } | 105 } |
| 108 } | 106 } |
| 109 | 107 |
| 110 DCHECK(drag_image_.get()); | 108 DCHECK(drag_image_.get()); |
| 111 if (drag_image_->IsVisible()) { | 109 if (drag_image_->IsVisible()) { |
| 112 drag_image_->SetScreenPosition(Desktop::GetInstance()-> | 110 drag_image_->SetScreenPosition(Desktop::GetInstance()-> |
| 113 last_mouse_location().Add(kDragDropWidgetOffset)); | 111 last_mouse_location().Add(kDragDropWidgetOffset)); |
| 114 } | 112 } |
| 115 } | 113 } |
| 116 | 114 |
| 117 void DragDropController::Drop(aura::Window* target, | 115 void DragDropController::Drop(aura::Window* target, |
| 118 const aura::MouseEvent& event) { | 116 const aura::MouseEvent& event) { |
| 119 aura::WindowDragDropDelegate* delegate = NULL; | 117 aura::WindowDragDropDelegate* delegate = NULL; |
| 120 DCHECK(target == dragged_window_); | 118 DCHECK(target == dragged_window_); |
| 121 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 119 if ((delegate = GetDragDropDelegate(dragged_window_))) { |
| 122 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 120 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
| 123 if (delegate->CanDrop(e)) | 121 drag_operation_ = delegate->OnPerformDrop(e); |
| 124 delegate->OnPerformDrop(e); | 122 // TODO(varunjain): if drag_op is 0, do drag widget flying back animation |
| 125 // TODO(varunjain): else Do drag widget flying back animation | |
| 126 } | 123 } |
| 127 | 124 |
| 128 Cleanup(); | 125 Cleanup(); |
| 129 if (should_block_during_drag_drop_) | 126 if (should_block_during_drag_drop_) |
| 130 MessageLoop::current()->Quit(); | 127 MessageLoop::current()->Quit(); |
| 131 } | 128 } |
| 132 | 129 |
| 133 void DragDropController::DragCancel() { | 130 void DragDropController::DragCancel() { |
| 134 // TODO(varunjain): Do drag widget flying back animation | 131 // TODO(varunjain): Do drag widget flying back animation |
| 135 Cleanup(); | 132 Cleanup(); |
| 133 drag_operation_ = 0; |
| 136 if (should_block_during_drag_drop_) | 134 if (should_block_during_drag_drop_) |
| 137 MessageLoop::current()->Quit(); | 135 MessageLoop::current()->Quit(); |
| 138 } | 136 } |
| 139 | 137 |
| 138 bool DragDropController::IsDragDropInProgress() { |
| 139 return drag_drop_in_progress_; |
| 140 } |
| 141 |
| 140 bool DragDropController::PreHandleKeyEvent(aura::Window* target, | 142 bool DragDropController::PreHandleKeyEvent(aura::Window* target, |
| 141 aura::KeyEvent* event) { | 143 aura::KeyEvent* event) { |
| 142 return false; | 144 return false; |
| 143 } | 145 } |
| 144 | 146 |
| 145 bool DragDropController::PreHandleMouseEvent(aura::Window* target, | 147 bool DragDropController::PreHandleMouseEvent(aura::Window* target, |
| 146 aura::MouseEvent* event) { | 148 aura::MouseEvent* event) { |
| 147 if (!drag_drop_in_progress_) | 149 if (!drag_drop_in_progress_) |
| 148 return false; | 150 return false; |
| 149 switch (event->type()) { | 151 switch (event->type()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 168 aura::TouchEvent* event) { | 170 aura::TouchEvent* event) { |
| 169 return ui::TOUCH_STATUS_UNKNOWN; | 171 return ui::TOUCH_STATUS_UNKNOWN; |
| 170 } | 172 } |
| 171 | 173 |
| 172 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
| 173 // DragDropController, private: | 175 // DragDropController, private: |
| 174 | 176 |
| 175 void DragDropController::Cleanup() { | 177 void DragDropController::Cleanup() { |
| 176 drag_image_.reset(); | 178 drag_image_.reset(); |
| 177 drag_data_ = NULL; | 179 drag_data_ = NULL; |
| 178 drag_operation_ = 0; | |
| 179 drag_drop_in_progress_ = false; | 180 drag_drop_in_progress_ = false; |
| 180 } | 181 } |
| 181 | 182 |
| 182 } // namespace internal | 183 } // namespace internal |
| 183 } // namespace aura_shell | 184 } // namespace aura_shell |
| OLD | NEW |