| 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 "base/run_loop.h" |
| 10 #include "ui/aura/client/capture_client.h" | 11 #include "ui/aura/client/capture_client.h" |
| 11 #include "ui/aura/client/drag_drop_delegate.h" | 12 #include "ui/aura/client/drag_drop_delegate.h" |
| 12 #include "ui/aura/cursor_manager.h" | 13 #include "ui/aura/cursor_manager.h" |
| 13 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 14 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 16 #include "ui/base/dragdrop/drag_drop_types.h" | 17 #include "ui/base/dragdrop/drag_drop_types.h" |
| 17 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 18 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
| 18 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
| 19 #include "ui/compositor/layer_animator.h" | 20 #include "ui/compositor/layer_animator.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 drag_image_->SetScreenBounds(gfx::Rect( | 76 drag_image_->SetScreenBounds(gfx::Rect( |
| 76 root_location.Subtract(drag_image_offset_), | 77 root_location.Subtract(drag_image_offset_), |
| 77 drag_image_->GetPreferredSize())); | 78 drag_image_->GetPreferredSize())); |
| 78 drag_image_->SetWidgetVisible(true); | 79 drag_image_->SetWidgetVisible(true); |
| 79 | 80 |
| 80 drag_window_ = NULL; | 81 drag_window_ = NULL; |
| 81 drag_start_location_ = root_location.Subtract(drag_image_offset_); | 82 drag_start_location_ = root_location.Subtract(drag_image_offset_); |
| 82 | 83 |
| 83 #if !defined(OS_MACOSX) | 84 #if !defined(OS_MACOSX) |
| 84 if (should_block_during_drag_drop_) { | 85 if (should_block_during_drag_drop_) { |
| 86 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); |
| 87 quit_closure_ = run_loop.QuitClosure(); |
| 85 MessageLoopForUI* loop = MessageLoopForUI::current(); | 88 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 86 MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | 89 MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| 87 loop->RunWithDispatcher(aura::Env::GetInstance()->GetDispatcher()); | 90 run_loop.Run(); |
| 88 } | 91 } |
| 89 #endif // !defined(OS_MACOSX) | 92 #endif // !defined(OS_MACOSX) |
| 90 | 93 |
| 91 return drag_operation_; | 94 return drag_operation_; |
| 92 } | 95 } |
| 93 | 96 |
| 94 void DragDropController::DragUpdate(aura::Window* target, | 97 void DragDropController::DragUpdate(aura::Window* target, |
| 95 const aura::LocatedEvent& event) { | 98 const aura::LocatedEvent& event) { |
| 96 aura::client::DragDropDelegate* delegate = NULL; | 99 aura::client::DragDropDelegate* delegate = NULL; |
| 97 if (target != drag_window_) { | 100 if (target != drag_window_) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (drag_operation_ == 0) | 159 if (drag_operation_ == 0) |
| 157 StartCanceledAnimation(); | 160 StartCanceledAnimation(); |
| 158 else | 161 else |
| 159 drag_image_.reset(); | 162 drag_image_.reset(); |
| 160 } else { | 163 } else { |
| 161 drag_image_.reset(); | 164 drag_image_.reset(); |
| 162 } | 165 } |
| 163 | 166 |
| 164 Cleanup(); | 167 Cleanup(); |
| 165 if (should_block_during_drag_drop_) | 168 if (should_block_during_drag_drop_) |
| 166 MessageLoop::current()->QuitNow(); | 169 quit_closure_.Run(); |
| 167 } | 170 } |
| 168 | 171 |
| 169 void DragDropController::DragCancel() { | 172 void DragDropController::DragCancel() { |
| 170 aura::Env::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); | 173 aura::Env::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); |
| 171 | 174 |
| 172 // |drag_window_| can be NULL if we have just started the drag and have not | 175 // |drag_window_| can be NULL if we have just started the drag and have not |
| 173 // received any DragUpdates, or, if the |drag_window_| gets destroyed during | 176 // received any DragUpdates, or, if the |drag_window_| gets destroyed during |
| 174 // a drag/drop. | 177 // a drag/drop. |
| 175 aura::client::DragDropDelegate* delegate = drag_window_? | 178 aura::client::DragDropDelegate* delegate = drag_window_? |
| 176 aura::client::GetDragDropDelegate(drag_window_) : NULL; | 179 aura::client::GetDragDropDelegate(drag_window_) : NULL; |
| 177 if (delegate) | 180 if (delegate) |
| 178 delegate->OnDragExited(); | 181 delegate->OnDragExited(); |
| 179 | 182 |
| 180 Cleanup(); | 183 Cleanup(); |
| 181 drag_operation_ = 0; | 184 drag_operation_ = 0; |
| 182 StartCanceledAnimation(); | 185 StartCanceledAnimation(); |
| 183 if (should_block_during_drag_drop_) | 186 if (should_block_during_drag_drop_) |
| 184 MessageLoop::current()->QuitNow(); | 187 quit_closure_.Run(); |
| 185 } | 188 } |
| 186 | 189 |
| 187 bool DragDropController::IsDragDropInProgress() { | 190 bool DragDropController::IsDragDropInProgress() { |
| 188 return drag_drop_in_progress_; | 191 return drag_drop_in_progress_; |
| 189 } | 192 } |
| 190 | 193 |
| 191 bool DragDropController::PreHandleKeyEvent(aura::Window* target, | 194 bool DragDropController::PreHandleKeyEvent(aura::Window* target, |
| 192 aura::KeyEvent* event) { | 195 aura::KeyEvent* event) { |
| 193 return false; | 196 return false; |
| 194 } | 197 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 void DragDropController::Cleanup() { | 281 void DragDropController::Cleanup() { |
| 279 if (drag_window_) | 282 if (drag_window_) |
| 280 drag_window_->RemoveObserver(this); | 283 drag_window_->RemoveObserver(this); |
| 281 drag_window_ = NULL; | 284 drag_window_ = NULL; |
| 282 drag_data_ = NULL; | 285 drag_data_ = NULL; |
| 283 drag_drop_in_progress_ = false; | 286 drag_drop_in_progress_ = false; |
| 284 } | 287 } |
| 285 | 288 |
| 286 } // namespace internal | 289 } // namespace internal |
| 287 } // namespace ash | 290 } // namespace ash |
| OLD | NEW |