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
3 // found in the LICENSE file.
5 #ifndef ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_
6 #define ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "ui/aura/window_observer.h"
12 #include "ui/base/dragdrop/os_exchange_data.h"
13 #include "ui/events/event_constants.h"
14 #include "ui/events/event_handler.h"
15 #include "ui/gfx/animation/animation_delegate.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/wm/public/drag_drop_client.h"
20 class LinearAnimation
;
24 class DragDropTracker
;
25 class DragDropTrackerDelegate
;
29 class DragDropControllerTest
;
32 class ASH_EXPORT DragDropController
33 : public aura::client::DragDropClient
,
34 public ui::EventHandler
,
35 public gfx::AnimationDelegate
,
36 public aura::WindowObserver
{
39 virtual ~DragDropController();
41 void set_should_block_during_drag_drop(bool should_block_during_drag_drop
) {
42 should_block_during_drag_drop_
= should_block_during_drag_drop
;
45 // Overridden from aura::client::DragDropClient:
46 virtual int StartDragAndDrop(
47 const ui::OSExchangeData
& data
,
48 aura::Window
* root_window
,
49 aura::Window
* source_window
,
50 const gfx::Point
& root_location
,
52 ui::DragDropTypes::DragEventSource source
) OVERRIDE
;
53 virtual void DragUpdate(aura::Window
* target
,
54 const ui::LocatedEvent
& event
) OVERRIDE
;
55 virtual void Drop(aura::Window
* target
,
56 const ui::LocatedEvent
& event
) OVERRIDE
;
57 virtual void DragCancel() OVERRIDE
;
58 virtual bool IsDragDropInProgress() OVERRIDE
;
60 // Overridden from ui::EventHandler:
61 virtual void OnKeyEvent(ui::KeyEvent
* event
) OVERRIDE
;
62 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
63 virtual void OnTouchEvent(ui::TouchEvent
* event
) OVERRIDE
;
64 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
66 // Overridden from aura::WindowObserver.
67 virtual void OnWindowDestroyed(aura::Window
* window
) OVERRIDE
;
70 // Helper method to create a LinearAnimation object that will run the drag
71 // cancel animation. Caller take ownership of the returned object. Protected
73 virtual gfx::LinearAnimation
* CreateCancelAnimation(
76 gfx::AnimationDelegate
* delegate
);
78 // Actual implementation of |DragCancel()|. protected for testing.
79 virtual void DoDragCancel(int drag_cancel_animation_duration_ms
);
82 friend class ash::test::DragDropControllerTest
;
84 // Overridden from gfx::AnimationDelegate:
85 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
86 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
87 virtual void AnimationCanceled(const gfx::Animation
* animation
) OVERRIDE
;
89 // Helper method to start drag widget flying back animation.
90 void StartCanceledAnimation(int animation_duration_ms
);
92 // Helper method to forward |pending_log_tap_| event to |drag_source_window_|.
93 void ForwardPendingLongTap();
95 // Helper method to reset everything.
98 scoped_ptr
<DragImageView
> drag_image_
;
99 gfx::Vector2d drag_image_offset_
;
100 const ui::OSExchangeData
* drag_data_
;
103 // Window that is currently under the drag cursor.
104 aura::Window
* drag_window_
;
106 // Starting and final bounds for the drag image for the drag cancel animation.
107 gfx::Rect drag_image_initial_bounds_for_cancel_animation_
;
108 gfx::Rect drag_image_final_bounds_for_cancel_animation_
;
110 scoped_ptr
<gfx::LinearAnimation
> cancel_animation_
;
112 // Window that started the drag.
113 aura::Window
* drag_source_window_
;
115 // Indicates whether the caller should be blocked on a drag/drop session.
116 // Only be used for tests.
117 bool should_block_during_drag_drop_
;
119 // Closure for quitting nested message loop.
120 base::Closure quit_closure_
;
122 scoped_ptr
<ash::DragDropTracker
> drag_drop_tracker_
;
123 scoped_ptr
<DragDropTrackerDelegate
> drag_drop_window_delegate_
;
125 ui::DragDropTypes::DragEventSource current_drag_event_source_
;
127 // Holds a synthetic long tap event to be sent to the |drag_source_window_|.
128 // See comment in OnGestureEvent() on why we need this.
129 scoped_ptr
<ui::GestureEvent
> pending_long_tap_
;
131 base::WeakPtrFactory
<DragDropController
> weak_factory_
;
133 DISALLOW_COPY_AND_ASSIGN(DragDropController
);
138 #endif // ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_