Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / drag_drop / drag_drop_controller.h
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.
4
5 #ifndef ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_
6 #define ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_
7
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"
18
19 namespace gfx {
20 class LinearAnimation;
21 }
22
23 namespace ash {
24 class DragDropTracker;
25 class DragDropTrackerDelegate;
26 class DragImageView;
27
28 namespace test {
29 class DragDropControllerTest;
30 }
31
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;
40
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;
43   }
44
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& root_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;
56
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;
62
63   // Overridden from aura::WindowObserver.
64   void OnWindowDestroyed(aura::Window* window) override;
65
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);
74
75   // Actual implementation of |DragCancel()|. protected for testing.
76   virtual void DoDragCancel(int drag_cancel_animation_duration_ms);
77
78  private:
79   friend class ash::test::DragDropControllerTest;
80
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;
85
86   // Helper method to start drag widget flying back animation.
87   void StartCanceledAnimation(int animation_duration_ms);
88
89   // Helper method to forward |pending_log_tap_| event to |drag_source_window_|.
90   void ForwardPendingLongTap();
91
92   // Helper method to reset everything.
93   void Cleanup();
94
95   scoped_ptr<DragImageView> drag_image_;
96   gfx::Vector2d drag_image_offset_;
97   const ui::OSExchangeData* drag_data_;
98   int drag_operation_;
99
100   // Window that is currently under the drag cursor.
101   aura::Window* drag_window_;
102
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_;
106
107   scoped_ptr<gfx::LinearAnimation> cancel_animation_;
108
109   // Window that started the drag.
110   aura::Window* drag_source_window_;
111
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_;
115
116   // Closure for quitting nested message loop.
117   base::Closure quit_closure_;
118
119   scoped_ptr<ash::DragDropTracker> drag_drop_tracker_;
120   scoped_ptr<DragDropTrackerDelegate> drag_drop_window_delegate_;
121
122   ui::DragDropTypes::DragEventSource current_drag_event_source_;
123
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_;
127
128   base::WeakPtrFactory<DragDropController> weak_factory_;
129
130   DISALLOW_COPY_AND_ASSIGN(DragDropController);
131 };
132
133 }  // namespace ash
134
135 #endif  // ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_