[email protected] | bb612db | 2012-01-09 17:31:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 5 | #ifndef ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_ |
| 6 | #define ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_ |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 7 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 10 | #include "ash/ash_export.h" |
Scott Violet | 9838c93 | 2017-06-19 20:54:51 | [diff] [blame] | 11 | #include "ash/display/window_tree_host_manager.h" |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 12 | #include "base/callback.h" |
avi | db567a8a | 2015-12-20 17:07:24 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 14 | #include "base/memory/weak_ptr.h" |
Daichi Hirono | e66b415 | 2017-08-01 06:20:33 | [diff] [blame] | 15 | #include "base/observer_list.h" |
Evan Stade | 55a443f | 2017-07-20 19:41:02 | [diff] [blame] | 16 | #include "base/time/time.h" |
sky | 92d41b24 | 2016-10-27 20:10:16 | [diff] [blame] | 17 | #include "ui/aura/client/drag_drop_client.h" |
[email protected] | 341ad58 | 2012-02-03 18:31:09 | [diff] [blame] | 18 | #include "ui/aura/window_observer.h" |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 19 | #include "ui/base/dragdrop/os_exchange_data.h" |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 20 | #include "ui/events/event_constants.h" |
| 21 | #include "ui/events/event_handler.h" |
[email protected] | ffb15d1 | 2013-09-15 17:29:30 | [diff] [blame] | 22 | #include "ui/gfx/animation/animation_delegate.h" |
Avi Drissman | fefc2f8 | 2014-12-22 19:25:29 | [diff] [blame] | 23 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 24 | |
[email protected] | ffb15d1 | 2013-09-15 17:29:30 | [diff] [blame] | 25 | namespace gfx { |
[email protected] | 96fe25bf | 2012-11-27 20:30:25 | [diff] [blame] | 26 | class LinearAnimation; |
[email protected] | bb612db | 2012-01-09 17:31:13 | [diff] [blame] | 27 | } |
| 28 | |
sky | 4f4d259 | 2016-10-28 17:14:47 | [diff] [blame] | 29 | namespace ui { |
| 30 | class LocatedEvent; |
| 31 | } |
| 32 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 33 | namespace ash { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 34 | class DragDropTracker; |
| 35 | class DragDropTrackerDelegate; |
| 36 | class DragImageView; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 37 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 38 | class ASH_EXPORT DragDropController : public aura::client::DragDropClient, |
| 39 | public ui::EventHandler, |
| 40 | public gfx::AnimationDelegate, |
jamescook | 035dc06 | 2016-08-05 21:13:52 | [diff] [blame] | 41 | public aura::WindowObserver, |
Scott Violet | 9838c93 | 2017-06-19 20:54:51 | [diff] [blame] | 42 | public WindowTreeHostManager::Observer { |
[email protected] | 828a6dfa | 2012-05-10 20:03:02 | [diff] [blame] | 43 | public: |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 44 | DragDropController(); |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 45 | ~DragDropController() override; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 46 | |
| 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 Cook | eb426b5 | 2018-09-17 16:45:12 | [diff] [blame] | 51 | void set_enabled(bool enabled) { enabled_ = enabled; } |
| 52 | |
[email protected] | 458b365c | 2011-12-15 05:04:09 | [diff] [blame] | 53 | // Overridden from aura::client::DragDropClient: |
Navid Zolghadr | 0beb829 | 2019-07-08 18:54:04 | [diff] [blame] | 54 | int StartDragAndDrop(std::unique_ptr<ui::OSExchangeData> data, |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 55 | aura::Window* root_window, |
| 56 | aura::Window* source_window, |
pkotwicz | deb3f724 | 2015-02-24 21:16:05 | [diff] [blame] | 57 | const gfx::Point& screen_location, |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 58 | int operation, |
| 59 | ui::DragDropTypes::DragEventSource source) override; |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 60 | void DragCancel() override; |
| 61 | bool IsDragDropInProgress() override; |
Daichi Hirono | e66b415 | 2017-08-01 06:20:33 | [diff] [blame] | 62 | void AddObserver(aura::client::DragDropClientObserver* observer) override; |
| 63 | void RemoveObserver(aura::client::DragDropClientObserver* observer) override; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 64 | |
[email protected] | 304594c | 2012-11-13 16:35:27 | [diff] [blame] | 65 | // Overridden from ui::EventHandler: |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 66 | 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] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 70 | |
[email protected] | 341ad58 | 2012-02-03 18:31:09 | [diff] [blame] | 71 | // Overridden from aura::WindowObserver. |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 72 | void OnWindowDestroyed(aura::Window* window) override; |
[email protected] | 341ad58 | 2012-02-03 18:31:09 | [diff] [blame] | 73 | |
Fergus Dall | a429385 | 2019-07-26 07:13:47 | [diff] [blame^] | 74 | void SetDragImage(const gfx::ImageSkia& image, |
| 75 | const gfx::Vector2d& image_offset); |
| 76 | |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 77 | protected: |
[email protected] | c0861045 | 2012-11-28 21:48:36 | [diff] [blame] | 78 | // 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] | ffb15d1 | 2013-09-15 17:29:30 | [diff] [blame] | 81 | virtual gfx::LinearAnimation* CreateCancelAnimation( |
Evan Stade | 55a443f | 2017-07-20 19:41:02 | [diff] [blame] | 82 | base::TimeDelta duration, |
[email protected] | c0861045 | 2012-11-28 21:48:36 | [diff] [blame] | 83 | int frame_rate, |
[email protected] | ffb15d1 | 2013-09-15 17:29:30 | [diff] [blame] | 84 | gfx::AnimationDelegate* delegate); |
[email protected] | c0861045 | 2012-11-28 21:48:36 | [diff] [blame] | 85 | |
sky | 4f4d259 | 2016-10-28 17:14:47 | [diff] [blame] | 86 | // 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] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 90 | // Actual implementation of |DragCancel()|. protected for testing. |
Evan Stade | 55a443f | 2017-07-20 19:41:02 | [diff] [blame] | 91 | virtual void DoDragCancel(base::TimeDelta drag_cancel_animation_duration); |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 92 | |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 93 | private: |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 94 | friend class DragDropControllerTest; |
James Cook | eb426b5 | 2018-09-17 16:45:12 | [diff] [blame] | 95 | friend class DragDropControllerTestApi; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 96 | |
[email protected] | ffb15d1 | 2013-09-15 17:29:30 | [diff] [blame] | 97 | // Overridden from gfx::AnimationDelegate: |
dcheng | 34dfcbe | 2014-10-29 18:58:19 | [diff] [blame] | 98 | 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] | bb612db | 2012-01-09 17:31:13 | [diff] [blame] | 101 | |
Scott Violet | 9838c93 | 2017-06-19 20:54:51 | [diff] [blame] | 102 | // WindowTreeHostManager::Observer: |
jamescook | 035dc06 | 2016-08-05 21:13:52 | [diff] [blame] | 103 | void OnDisplayConfigurationChanging() override; |
| 104 | |
[email protected] | bb612db | 2012-01-09 17:31:13 | [diff] [blame] | 105 | // Helper method to start drag widget flying back animation. |
Evan Stade | 55a443f | 2017-07-20 19:41:02 | [diff] [blame] | 106 | void StartCanceledAnimation(base::TimeDelta animation_duration); |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 107 | |
| 108 | // Helper method to forward |pending_log_tap_| event to |drag_source_window_|. |
| 109 | void ForwardPendingLongTap(); |
[email protected] | bb612db | 2012-01-09 17:31:13 | [diff] [blame] | 110 | |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 111 | // Helper method to reset everything. |
| 112 | void Cleanup(); |
| 113 | |
James Cook | eb426b5 | 2018-09-17 16:45:12 | [diff] [blame] | 114 | bool enabled_ = false; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 115 | std::unique_ptr<DragImageView> drag_image_; |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 116 | gfx::Vector2d drag_image_offset_; |
Navid Zolghadr | 0beb829 | 2019-07-08 18:54:04 | [diff] [blame] | 117 | std::unique_ptr<ui::OSExchangeData> drag_data_; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 118 | int drag_operation_; |
[email protected] | 6a5fc42 | 2012-03-06 04:43:26 | [diff] [blame] | 119 | |
| 120 | // Window that is currently under the drag cursor. |
| 121 | aura::Window* drag_window_; |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 122 | |
| 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] | 96fe25bf | 2012-11-27 20:30:25 | [diff] [blame] | 126 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 127 | std::unique_ptr<gfx::LinearAnimation> cancel_animation_; |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 128 | |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 129 | // Window that started the drag. |
| 130 | aura::Window* drag_source_window_; |
| 131 | |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 132 | // 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 | |
gab | 2998ee7 | 2017-05-05 16:23:50 | [diff] [blame] | 136 | // Closure for quitting nested run loop. |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 137 | base::Closure quit_closure_; |
| 138 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 139 | std::unique_ptr<ash::DragDropTracker> drag_drop_tracker_; |
| 140 | std::unique_ptr<DragDropTrackerDelegate> drag_drop_window_delegate_; |
[email protected] | 0518d0d | 2012-08-26 11:59:04 | [diff] [blame] | 141 | |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 142 | 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. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 146 | std::unique_ptr<ui::GestureEvent> pending_long_tap_; |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 147 | |
Fergus Dall | a429385 | 2019-07-26 07:13:47 | [diff] [blame^] | 148 | gfx::Point start_location_; |
| 149 | gfx::Point current_location_; |
| 150 | |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 151 | base::ObserverList<aura::client::DragDropClientObserver>::Unchecked |
| 152 | observers_; |
Daichi Hirono | e66b415 | 2017-08-01 06:20:33 | [diff] [blame] | 153 | |
[email protected] | ffa4e448 | 2012-11-28 12:11:49 | [diff] [blame] | 154 | base::WeakPtrFactory<DragDropController> weak_factory_; |
| 155 | |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 156 | DISALLOW_COPY_AND_ASSIGN(DragDropController); |
| 157 | }; |
| 158 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 159 | } // namespace ash |
[email protected] | 084b6bb | 2011-11-17 05:18:16 | [diff] [blame] | 160 | |
[email protected] | 2f74428 | 2011-12-23 22:40:52 | [diff] [blame] | 161 | #endif // ASH_DRAG_DROP_DRAG_DROP_CONTROLLER_H_ |