Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Side by Side Diff: ash/drag_drop/drag_drop_controller.cc

Issue 9222018: reland -- Disable animations during aura tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer comments. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
32 class DragDropAnimationObserver : public ui::ImplicitAnimationObserver {
33 public:
34 DragDropAnimationObserver(DragDropAnimationObserverClient* client)
35 : client_(client) {}
36 virtual ~DragDropAnimationObserver() {}
37
38 private:
39 // Implementation of ImplicitAnimationObserver
40 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
41 client_->OnDragDropAnimationsCompleted(this);
42 }
43
44 DragDropAnimationObserverClient* client_;
45
46 DISALLOW_COPY_AND_ASSIGN(DragDropAnimationObserver);
47 };
48
49 } // namespace
32 50
33 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
34 // DragDropController, public: 52 // DragDropController, public:
35 53
36 DragDropController::DragDropController() 54 DragDropController::DragDropController()
37 : aura::EventFilter(RootWindow::GetInstance()), 55 : aura::EventFilter(RootWindow::GetInstance()),
38 drag_image_(NULL), 56 drag_image_(NULL),
39 drag_data_(NULL), 57 drag_data_(NULL),
40 drag_operation_(0), 58 drag_operation_(0),
41 dragged_window_(NULL), 59 dragged_window_(NULL),
42 drag_drop_in_progress_(false), 60 drag_drop_in_progress_(false),
43 should_block_during_drag_drop_(true) { 61 should_block_during_drag_drop_(true) {
44 Shell::GetInstance()->AddRootWindowEventFilter(this); 62 Shell::GetInstance()->AddRootWindowEventFilter(this);
45 aura::client::SetDragDropClient(this); 63 aura::client::SetDragDropClient(this);
46 } 64 }
47 65
48 DragDropController::~DragDropController() { 66 DragDropController::~DragDropController() {
67 if (drag_image_.get() && active_observer_.get()) {
sky 2012/01/27 17:54:10 Why do you need to explicitly remove the animation
68 aura::Window* window = drag_image_->GetWidget()->GetNativeView();
69 ui::LayerAnimator* animator = window->layer()->GetAnimator();
70 animator->RemoveObserver(active_observer_.get());
71 }
72
49 Shell::GetInstance()->RemoveRootWindowEventFilter(this); 73 Shell::GetInstance()->RemoveRootWindowEventFilter(this);
50 Cleanup(); 74 Cleanup();
51 if (drag_image_.get()) { 75 if (drag_image_.get())
52 aura::Window* window = drag_image_->GetWidget()->GetNativeView();
53 window->layer()->GetAnimator()->RemoveObserver(this);
54 drag_image_.reset(); 76 drag_image_.reset();
55 }
56 } 77 }
57 78
58 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, 79 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
59 int operation) { 80 int operation) {
60 DCHECK(!drag_drop_in_progress_); 81 DCHECK(!drag_drop_in_progress_);
61 aura::Window* capture_window = RootWindow::GetInstance()->capture_window(); 82 aura::Window* capture_window = RootWindow::GetInstance()->capture_window();
62 if (capture_window) 83 if (capture_window)
63 RootWindow::GetInstance()->ReleaseCapture(capture_window); 84 RootWindow::GetInstance()->ReleaseCapture(capture_window);
64 drag_drop_in_progress_ = true; 85 drag_drop_in_progress_ = true;
65 86
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 217
197 ui::GestureStatus DragDropController::PreHandleGestureEvent( 218 ui::GestureStatus DragDropController::PreHandleGestureEvent(
198 aura::Window* target, 219 aura::Window* target,
199 aura::GestureEvent* event) { 220 aura::GestureEvent* event) {
200 return ui::GESTURE_STATUS_UNKNOWN; 221 return ui::GESTURE_STATUS_UNKNOWN;
201 } 222 }
202 223
203 //////////////////////////////////////////////////////////////////////////////// 224 ////////////////////////////////////////////////////////////////////////////////
204 // DragDropController, private: 225 // DragDropController, private:
205 226
206 void DragDropController::OnLayerAnimationEnded( 227 void DragDropController::OnDragDropAnimationsCompleted(
207 const ui::LayerAnimationSequence* sequence) { 228 ui::ImplicitAnimationObserver* observer) {
229 DCHECK_EQ(active_observer_.get(), observer);
230 active_observer_.reset(NULL);
208 DCHECK(drag_image_.get()); 231 DCHECK(drag_image_.get());
209 drag_image_.reset(); 232 drag_image_.reset();
210 } 233 }
211
212 void DragDropController::OnLayerAnimationAborted(
213 const ui::LayerAnimationSequence* sequence) {
214 DCHECK(drag_image_.get());
215 drag_image_.reset();
216 }
217 234
218 void DragDropController::StartCanceledAnimation() { 235 void DragDropController::StartCanceledAnimation() {
219 aura::Window* window = drag_image_->GetWidget()->GetNativeView(); 236 aura::Window* window = drag_image_->GetWidget()->GetNativeView();
220 ui::LayerAnimator* animator = window->layer()->GetAnimator(); 237 ui::LayerAnimator* animator = window->layer()->GetAnimator();
221 animator->set_preemption_strategy( 238 animator->set_preemption_strategy(
222 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 239 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
223 animator->AddObserver(this);
224 ui::ScopedLayerAnimationSettings animation_setter(animator); 240 ui::ScopedLayerAnimationSettings animation_setter(animator);
225 animation_setter.SetTransitionDuration(kDragDropAnimationDuration); 241 animation_setter.SetTransitionDuration(kDragDropAnimationDuration);
242 active_observer_.reset(new DragDropAnimationObserver(this));
243 animation_setter.AddObserver(active_observer_.get());
226 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size())); 244 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size()));
227 } 245 }
228 246
229 void DragDropController::Cleanup() { 247 void DragDropController::Cleanup() {
230 drag_data_ = NULL; 248 drag_data_ = NULL;
231 drag_drop_in_progress_ = false; 249 drag_drop_in_progress_ = false;
232 } 250 }
233 251
234 } // namespace internal 252 } // namespace internal
235 } // namespace ash 253 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698