Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / ash / drag_drop / drag_drop_controller.h
blob35b1d9af15a9df1e1c1ccaa42ed5d93c8353b11d
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/geometry/rect.h"
17 #include "ui/wm/public/drag_drop_client.h"
19 namespace gfx {
20 class LinearAnimation;
23 namespace ash {
24 class DragDropTracker;
25 class DragDropTrackerDelegate;
26 class DragImageView;
28 namespace test {
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 {
37 public:
38 DragDropController();
39 ~DragDropController() override;
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 int StartDragAndDrop(const ui::OSExchangeData& data,
47 aura::Window* root_window,
48 aura::Window* source_window,
49 const gfx::Point& screen_location,
50 int operation,
51 ui::DragDropTypes::DragEventSource source) override;
52 void DragUpdate(aura::Window* target, const ui::LocatedEvent& event) override;
53 void Drop(aura::Window* target, const ui::LocatedEvent& event) override;
54 void DragCancel() override;
55 bool IsDragDropInProgress() override;
57 // Overridden from ui::EventHandler:
58 void OnKeyEvent(ui::KeyEvent* event) override;
59 void OnMouseEvent(ui::MouseEvent* event) override;
60 void OnTouchEvent(ui::TouchEvent* event) override;
61 void OnGestureEvent(ui::GestureEvent* event) override;
63 // Overridden from aura::WindowObserver.
64 void OnWindowDestroyed(aura::Window* window) override;
66 protected:
67 // Helper method to create a LinearAnimation object that will run the drag
68 // cancel animation. Caller take ownership of the returned object. Protected
69 // for testing.
70 virtual gfx::LinearAnimation* CreateCancelAnimation(
71 int duration,
72 int frame_rate,
73 gfx::AnimationDelegate* delegate);
75 // Actual implementation of |DragCancel()|. protected for testing.
76 virtual void DoDragCancel(int drag_cancel_animation_duration_ms);
78 private:
79 friend class ash::test::DragDropControllerTest;
81 // Overridden from gfx::AnimationDelegate:
82 void AnimationEnded(const gfx::Animation* animation) override;
83 void AnimationProgressed(const gfx::Animation* animation) override;
84 void AnimationCanceled(const gfx::Animation* animation) override;
86 // Helper method to start drag widget flying back animation.
87 void StartCanceledAnimation(int animation_duration_ms);
89 // Helper method to forward |pending_log_tap_| event to |drag_source_window_|.
90 void ForwardPendingLongTap();
92 // Helper method to reset everything.
93 void Cleanup();
95 scoped_ptr<DragImageView> drag_image_;
96 gfx::Vector2d drag_image_offset_;
97 const ui::OSExchangeData* drag_data_;
98 int drag_operation_;
100 // Window that is currently under the drag cursor.
101 aura::Window* drag_window_;
103 // Starting and final bounds for the drag image for the drag cancel animation.
104 gfx::Rect drag_image_initial_bounds_for_cancel_animation_;
105 gfx::Rect drag_image_final_bounds_for_cancel_animation_;
107 scoped_ptr<gfx::LinearAnimation> cancel_animation_;
109 // Window that started the drag.
110 aura::Window* drag_source_window_;
112 // Indicates whether the caller should be blocked on a drag/drop session.
113 // Only be used for tests.
114 bool should_block_during_drag_drop_;
116 // Closure for quitting nested message loop.
117 base::Closure quit_closure_;
119 scoped_ptr<ash::DragDropTracker> drag_drop_tracker_;
120 scoped_ptr<DragDropTrackerDelegate> drag_drop_window_delegate_;
122 ui::DragDropTypes::DragEventSource current_drag_event_source_;
124 // Holds a synthetic long tap event to be sent to the |drag_source_window_|.
125 // See comment in OnGestureEvent() on why we need this.
126 scoped_ptr<ui::GestureEvent> pending_long_tap_;
128 base::WeakPtrFactory<DragDropController> weak_factory_;
130 DISALLOW_COPY_AND_ASSIGN(DragDropController);
133 } // namespace ash
135 #endif // ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_