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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 namespace internal { | 23 namespace internal { |
24 | 24 |
25 using aura::RootWindow; | 25 using aura::RootWindow; |
26 | 26 |
27 namespace { | 27 namespace { |
28 const gfx::Point kDragDropWidgetOffset(0, 0); | 28 const gfx::Point kDragDropWidgetOffset(0, 0); |
29 const base::TimeDelta kDragDropAnimationDuration = | 29 const base::TimeDelta kDragDropAnimationDuration = |
30 base::TimeDelta::FromMilliseconds(250); | 30 base::TimeDelta::FromMilliseconds(250); |
31 } | 31 } // namespace |
32 | 32 |
33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
34 // DragDropController, public: | 34 // DragDropController, public: |
35 | 35 |
36 DragDropController::DragDropController() | 36 DragDropController::DragDropController() |
37 : drag_image_(NULL), | 37 : drag_image_(NULL), |
38 drag_data_(NULL), | 38 drag_data_(NULL), |
39 drag_operation_(0), | 39 drag_operation_(0), |
40 dragged_window_(NULL), | 40 dragged_window_(NULL), |
41 drag_drop_in_progress_(false), | 41 drag_drop_in_progress_(false), |
42 should_block_during_drag_drop_(true) { | 42 should_block_during_drag_drop_(true) { |
43 Shell::GetInstance()->AddRootWindowEventFilter(this); | 43 Shell::GetInstance()->AddRootWindowEventFilter(this); |
44 aura::client::SetDragDropClient(this); | 44 aura::client::SetDragDropClient(this); |
45 } | 45 } |
46 | 46 |
47 DragDropController::~DragDropController() { | 47 DragDropController::~DragDropController() { |
48 Shell::GetInstance()->RemoveRootWindowEventFilter(this); | 48 Shell::GetInstance()->RemoveRootWindowEventFilter(this); |
49 Cleanup(); | 49 Cleanup(); |
50 if (drag_image_.get()) { | 50 if (drag_image_.get()) |
51 aura::Window* window = drag_image_->GetWidget()->GetNativeView(); | |
52 window->layer()->GetAnimator()->RemoveObserver(this); | |
53 drag_image_.reset(); | 51 drag_image_.reset(); |
54 } | |
55 } | 52 } |
56 | 53 |
57 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 54 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
58 int operation) { | 55 int operation) { |
59 DCHECK(!drag_drop_in_progress_); | 56 DCHECK(!drag_drop_in_progress_); |
60 aura::Window* capture_window = RootWindow::GetInstance()->capture_window(); | 57 aura::Window* capture_window = RootWindow::GetInstance()->capture_window(); |
61 if (capture_window) | 58 if (capture_window) |
62 RootWindow::GetInstance()->ReleaseCapture(capture_window); | 59 RootWindow::GetInstance()->ReleaseCapture(capture_window); |
63 drag_drop_in_progress_ = true; | 60 drag_drop_in_progress_ = true; |
64 | 61 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 196 |
200 ui::GestureStatus DragDropController::PreHandleGestureEvent( | 197 ui::GestureStatus DragDropController::PreHandleGestureEvent( |
201 aura::Window* target, | 198 aura::Window* target, |
202 aura::GestureEvent* event) { | 199 aura::GestureEvent* event) { |
203 return ui::GESTURE_STATUS_UNKNOWN; | 200 return ui::GESTURE_STATUS_UNKNOWN; |
204 } | 201 } |
205 | 202 |
206 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
207 // DragDropController, private: | 204 // DragDropController, private: |
208 | 205 |
209 void DragDropController::OnLayerAnimationEnded( | 206 void DragDropController::OnImplicitAnimationsCompleted() { |
210 const ui::LayerAnimationSequence* sequence) { | |
211 DCHECK(drag_image_.get()); | 207 DCHECK(drag_image_.get()); |
212 drag_image_.reset(); | 208 drag_image_.reset(); |
213 } | 209 } |
214 | |
215 void DragDropController::OnLayerAnimationAborted( | |
216 const ui::LayerAnimationSequence* sequence) { | |
217 DCHECK(drag_image_.get()); | |
218 drag_image_.reset(); | |
219 } | |
220 | 210 |
221 void DragDropController::StartCanceledAnimation() { | 211 void DragDropController::StartCanceledAnimation() { |
222 aura::Window* window = drag_image_->GetWidget()->GetNativeView(); | 212 aura::Window* window = drag_image_->GetWidget()->GetNativeView(); |
223 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 213 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
224 animator->set_preemption_strategy( | 214 animator->set_preemption_strategy( |
225 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 215 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
226 animator->AddObserver(this); | 216 |
| 217 // Stop waiting for any as yet unfinished implicit animations. |
| 218 StopObservingImplicitAnimations(); |
| 219 |
227 ui::ScopedLayerAnimationSettings animation_setter(animator); | 220 ui::ScopedLayerAnimationSettings animation_setter(animator); |
228 animation_setter.SetTransitionDuration(kDragDropAnimationDuration); | 221 animation_setter.SetTransitionDuration(kDragDropAnimationDuration); |
| 222 animation_setter.AddObserver(this); |
229 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size())); | 223 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size())); |
230 } | 224 } |
231 | 225 |
232 void DragDropController::Cleanup() { | 226 void DragDropController::Cleanup() { |
233 drag_data_ = NULL; | 227 drag_data_ = NULL; |
234 drag_drop_in_progress_ = false; | 228 drag_drop_in_progress_ = false; |
235 } | 229 } |
236 | 230 |
237 } // namespace internal | 231 } // namespace internal |
238 } // namespace ash | 232 } // namespace ash |
OLD | NEW |