blob: 684dbbfa517d3c304326721a61edac4f5f54c342 [file] [log] [blame]
[email protected]bb612db2012-01-09 17:31:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]084b6bb2011-11-17 05:18:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]2f744282011-12-23 22:40:525#ifndef ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_
6#define ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_
[email protected]084b6bb2011-11-17 05:18:167
dchenga94547472016-04-08 08:41:118#include <memory>
9
[email protected]b65bdda2011-12-23 23:35:3110#include "ash/ash_export.h"
Scott Violet9838c932017-06-19 20:54:5111#include "ash/display/window_tree_host_manager.h"
[email protected]8e937c1e2012-06-28 22:57:3012#include "base/callback.h"
avidb567a8a2015-12-20 17:07:2413#include "base/macros.h"
[email protected]ffa4e4482012-11-28 12:11:4914#include "base/memory/weak_ptr.h"
Daichi Hironoe66b4152017-08-01 06:20:3315#include "base/observer_list.h"
Evan Stade55a443f2017-07-20 19:41:0216#include "base/time/time.h"
sky92d41b242016-10-27 20:10:1617#include "ui/aura/client/drag_drop_client.h"
[email protected]341ad582012-02-03 18:31:0918#include "ui/aura/window_observer.h"
[email protected]084b6bb2011-11-17 05:18:1619#include "ui/base/dragdrop/os_exchange_data.h"
[email protected]86ccbd42013-09-18 18:11:5420#include "ui/events/event_constants.h"
21#include "ui/events/event_handler.h"
[email protected]ffb15d12013-09-15 17:29:3022#include "ui/gfx/animation/animation_delegate.h"
Avi Drissmanfefc2f82014-12-22 19:25:2923#include "ui/gfx/geometry/rect.h"
[email protected]084b6bb2011-11-17 05:18:1624
[email protected]ffb15d12013-09-15 17:29:3025namespace gfx {
[email protected]96fe25bf2012-11-27 20:30:2526class LinearAnimation;
[email protected]bb612db2012-01-09 17:31:1327}
28
sky4f4d2592016-10-28 17:14:4729namespace ui {
30class LocatedEvent;
31}
32
[email protected]55f593352011-12-24 05:42:4633namespace ash {
[email protected]093b8d642014-04-03 20:59:2834class DragDropTracker;
35class DragDropTrackerDelegate;
36class DragImageView;
[email protected]084b6bb2011-11-17 05:18:1637
jamescookb8dcef522016-06-25 14:42:5538class ASH_EXPORT DragDropController : public aura::client::DragDropClient,
39 public ui::EventHandler,
40 public gfx::AnimationDelegate,
jamescook035dc062016-08-05 21:13:5241 public aura::WindowObserver,
Scott Violet9838c932017-06-19 20:54:5142 public WindowTreeHostManager::Observer {
[email protected]828a6dfa2012-05-10 20:03:0243 public:
[email protected]084b6bb2011-11-17 05:18:1644 DragDropController();
dcheng34dfcbe2014-10-29 18:58:1945 ~DragDropController() override;
[email protected]084b6bb2011-11-17 05:18:1646
47 void set_should_block_during_drag_drop(bool should_block_during_drag_drop) {
48 should_block_during_drag_drop_ = should_block_during_drag_drop;
49 }
50
James Cookeb426b52018-09-17 16:45:1251 void set_enabled(bool enabled) { enabled_ = enabled; }
52
[email protected]458b365c2011-12-15 05:04:0953 // Overridden from aura::client::DragDropClient:
Navid Zolghadr0beb8292019-07-08 18:54:0454 int StartDragAndDrop(std::unique_ptr<ui::OSExchangeData> data,
dcheng34dfcbe2014-10-29 18:58:1955 aura::Window* root_window,
56 aura::Window* source_window,
pkotwiczdeb3f7242015-02-24 21:16:0557 const gfx::Point& screen_location,
dcheng34dfcbe2014-10-29 18:58:1958 int operation,
59 ui::DragDropTypes::DragEventSource source) override;
dcheng34dfcbe2014-10-29 18:58:1960 void DragCancel() override;
61 bool IsDragDropInProgress() override;
Daichi Hironoe66b4152017-08-01 06:20:3362 void AddObserver(aura::client::DragDropClientObserver* observer) override;
63 void RemoveObserver(aura::client::DragDropClientObserver* observer) override;
[email protected]084b6bb2011-11-17 05:18:1664
[email protected]304594c2012-11-13 16:35:2765 // Overridden from ui::EventHandler:
dcheng34dfcbe2014-10-29 18:58:1966 void OnKeyEvent(ui::KeyEvent* event) override;
67 void OnMouseEvent(ui::MouseEvent* event) override;
68 void OnTouchEvent(ui::TouchEvent* event) override;
69 void OnGestureEvent(ui::GestureEvent* event) override;
[email protected]084b6bb2011-11-17 05:18:1670
[email protected]341ad582012-02-03 18:31:0971 // Overridden from aura::WindowObserver.
dcheng34dfcbe2014-10-29 18:58:1972 void OnWindowDestroyed(aura::Window* window) override;
[email protected]341ad582012-02-03 18:31:0973
Fergus Dalla4293852019-07-26 07:13:4774 void SetDragImage(const gfx::ImageSkia& image,
75 const gfx::Vector2d& image_offset);
76
[email protected]ffa4e4482012-11-28 12:11:4977 protected:
[email protected]c08610452012-11-28 21:48:3678 // Helper method to create a LinearAnimation object that will run the drag
79 // cancel animation. Caller take ownership of the returned object. Protected
80 // for testing.
[email protected]ffb15d12013-09-15 17:29:3081 virtual gfx::LinearAnimation* CreateCancelAnimation(
Evan Stade55a443f2017-07-20 19:41:0282 base::TimeDelta duration,
[email protected]c08610452012-11-28 21:48:3683 int frame_rate,
[email protected]ffb15d12013-09-15 17:29:3084 gfx::AnimationDelegate* delegate);
[email protected]c08610452012-11-28 21:48:3685
sky4f4d2592016-10-28 17:14:4786 // Exposed for tests to override.
87 virtual void DragUpdate(aura::Window* target, const ui::LocatedEvent& event);
88 virtual void Drop(aura::Window* target, const ui::LocatedEvent& event);
89
[email protected]ffa4e4482012-11-28 12:11:4990 // Actual implementation of |DragCancel()|. protected for testing.
Evan Stade55a443f2017-07-20 19:41:0291 virtual void DoDragCancel(base::TimeDelta drag_cancel_animation_duration);
[email protected]ffa4e4482012-11-28 12:11:4992
[email protected]084b6bb2011-11-17 05:18:1693 private:
James Cook317781a2017-07-18 02:08:0694 friend class DragDropControllerTest;
James Cookeb426b52018-09-17 16:45:1295 friend class DragDropControllerTestApi;
[email protected]084b6bb2011-11-17 05:18:1696
[email protected]ffb15d12013-09-15 17:29:3097 // Overridden from gfx::AnimationDelegate:
dcheng34dfcbe2014-10-29 18:58:1998 void AnimationEnded(const gfx::Animation* animation) override;
99 void AnimationProgressed(const gfx::Animation* animation) override;
100 void AnimationCanceled(const gfx::Animation* animation) override;
[email protected]bb612db2012-01-09 17:31:13101
Scott Violet9838c932017-06-19 20:54:51102 // WindowTreeHostManager::Observer:
jamescook035dc062016-08-05 21:13:52103 void OnDisplayConfigurationChanging() override;
104
[email protected]bb612db2012-01-09 17:31:13105 // Helper method to start drag widget flying back animation.
Evan Stade55a443f2017-07-20 19:41:02106 void StartCanceledAnimation(base::TimeDelta animation_duration);
[email protected]ffa4e4482012-11-28 12:11:49107
108 // Helper method to forward |pending_log_tap_| event to |drag_source_window_|.
109 void ForwardPendingLongTap();
[email protected]bb612db2012-01-09 17:31:13110
[email protected]084b6bb2011-11-17 05:18:16111 // Helper method to reset everything.
112 void Cleanup();
113
James Cookeb426b52018-09-17 16:45:12114 bool enabled_ = false;
dchenga94547472016-04-08 08:41:11115 std::unique_ptr<DragImageView> drag_image_;
[email protected]ceb36f7d2012-10-31 18:33:24116 gfx::Vector2d drag_image_offset_;
Navid Zolghadr0beb8292019-07-08 18:54:04117 std::unique_ptr<ui::OSExchangeData> drag_data_;
[email protected]084b6bb2011-11-17 05:18:16118 int drag_operation_;
[email protected]6a5fc422012-03-06 04:43:26119
120 // Window that is currently under the drag cursor.
121 aura::Window* drag_window_;
[email protected]ffa4e4482012-11-28 12:11:49122
123 // Starting and final bounds for the drag image for the drag cancel animation.
124 gfx::Rect drag_image_initial_bounds_for_cancel_animation_;
125 gfx::Rect drag_image_final_bounds_for_cancel_animation_;
[email protected]96fe25bf2012-11-27 20:30:25126
dchenga94547472016-04-08 08:41:11127 std::unique_ptr<gfx::LinearAnimation> cancel_animation_;
[email protected]084b6bb2011-11-17 05:18:16128
[email protected]ffa4e4482012-11-28 12:11:49129 // Window that started the drag.
130 aura::Window* drag_source_window_;
131
[email protected]084b6bb2011-11-17 05:18:16132 // Indicates whether the caller should be blocked on a drag/drop session.
133 // Only be used for tests.
134 bool should_block_during_drag_drop_;
135
gab2998ee72017-05-05 16:23:50136 // Closure for quitting nested run loop.
[email protected]8e937c1e2012-06-28 22:57:30137 base::Closure quit_closure_;
138
dchenga94547472016-04-08 08:41:11139 std::unique_ptr<ash::DragDropTracker> drag_drop_tracker_;
140 std::unique_ptr<DragDropTrackerDelegate> drag_drop_window_delegate_;
[email protected]0518d0d2012-08-26 11:59:04141
[email protected]ffa4e4482012-11-28 12:11:49142 ui::DragDropTypes::DragEventSource current_drag_event_source_;
143
144 // Holds a synthetic long tap event to be sent to the |drag_source_window_|.
145 // See comment in OnGestureEvent() on why we need this.
dchenga94547472016-04-08 08:41:11146 std::unique_ptr<ui::GestureEvent> pending_long_tap_;
[email protected]ffa4e4482012-11-28 12:11:49147
Fergus Dalla4293852019-07-26 07:13:47148 gfx::Point start_location_;
149 gfx::Point current_location_;
150
Trent Apteda250ec3ab2018-08-19 08:52:19151 base::ObserverList<aura::client::DragDropClientObserver>::Unchecked
152 observers_;
Daichi Hironoe66b4152017-08-01 06:20:33153
[email protected]ffa4e4482012-11-28 12:11:49154 base::WeakPtrFactory<DragDropController> weak_factory_;
155
[email protected]084b6bb2011-11-17 05:18:16156 DISALLOW_COPY_AND_ASSIGN(DragDropController);
157};
158
[email protected]55f593352011-12-24 05:42:46159} // namespace ash
[email protected]084b6bb2011-11-17 05:18:16160
[email protected]2f744282011-12-23 22:40:52161#endif // ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_