OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/drag_drop/drag_drop_controller.h" | 5 #include "ash/drag_drop/drag_drop_controller.h" |
6 | 6 |
7 #include "ash/drag_drop/drag_drop_tracker.h" | 7 #include "ash/drag_drop/drag_drop_tracker.h" |
8 #include "ash/drag_drop/drag_image_view.h" | 8 #include "ash/drag_drop/drag_image_view.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/coordinate_conversion.h" | 10 #include "ash/wm/coordinate_conversion.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
15 #include "ui/aura/client/drag_drop_delegate.h" | 15 #include "ui/aura/client/drag_drop_delegate.h" |
16 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
17 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | |
19 #include "ui/base/animation/linear_animation.h" | 20 #include "ui/base/animation/linear_animation.h" |
20 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
21 #include "ui/base/dragdrop/os_exchange_data.h" | 22 #include "ui/base/dragdrop/os_exchange_data.h" |
22 #include "ui/base/events/event.h" | 23 #include "ui/base/events/event.h" |
23 #include "ui/base/events/event_utils.h" | 24 #include "ui/base/events/event_utils.h" |
25 #include "ui/base/hit_test.h" | |
24 #include "ui/gfx/point.h" | 26 #include "ui/gfx/point.h" |
25 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/rect_conversions.h" | 28 #include "ui/gfx/rect_conversions.h" |
27 #include "ui/views/views_delegate.h" | 29 #include "ui/views/views_delegate.h" |
28 #include "ui/views/widget/native_widget_aura.h" | 30 #include "ui/views/widget/native_widget_aura.h" |
29 | 31 |
30 namespace ash { | 32 namespace ash { |
31 namespace internal { | 33 namespace internal { |
32 | 34 |
33 using aura::RootWindow; | 35 using aura::RootWindow; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 0, | 72 0, |
71 0, | 73 0, |
72 ui::EventTimeForNow(), | 74 ui::EventTimeForNow(), |
73 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), | 75 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), |
74 0); | 76 0); |
75 window->delegate()->OnGestureEvent(&gesture_end); | 77 window->delegate()->OnGestureEvent(&gesture_end); |
76 } | 78 } |
77 } | 79 } |
78 } // namespace | 80 } // namespace |
79 | 81 |
82 class DragDropWindowDelegate : public aura::WindowDelegate { | |
varunjain
2013/03/25 18:04:23
nit: rename to DragDropTrackerDelegate or DragDrop
oshima
2013/03/25 20:41:10
Done.
| |
83 public: | |
84 explicit DragDropWindowDelegate(DragDropController* controller) | |
85 : drag_drop_controller_(controller) {} | |
86 virtual ~DragDropWindowDelegate() {} | |
87 | |
88 // Overridden from WindowDelegate: | |
89 virtual gfx::Size GetMinimumSize() const OVERRIDE { | |
90 return gfx::Size(); | |
91 } | |
92 | |
93 virtual gfx::Size GetMaximumSize() const OVERRIDE { | |
94 return gfx::Size(); | |
95 } | |
96 | |
97 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, | |
98 const gfx::Rect& new_bounds) OVERRIDE {} | |
99 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { | |
100 return gfx::kNullCursor; | |
101 } | |
102 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | |
103 return HTCAPTION; | |
104 } | |
105 virtual bool ShouldDescendIntoChildForEventHandling( | |
106 aura::Window* child, | |
107 const gfx::Point& location) OVERRIDE { | |
108 return true; | |
109 } | |
110 virtual bool CanFocus() OVERRIDE { return true; } | |
111 virtual void OnCaptureLost() OVERRIDE { | |
112 drag_drop_controller_->DragCancel(); | |
113 } | |
114 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
115 } | |
116 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} | |
117 virtual void OnWindowDestroying() OVERRIDE {} | |
118 virtual void OnWindowDestroyed() OVERRIDE {} | |
119 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} | |
120 virtual bool HasHitTestMask() const OVERRIDE { return false; } | |
121 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} | |
122 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE { | |
123 return scoped_refptr<ui::Texture>(); | |
124 } | |
125 | |
126 private: | |
127 DragDropController* drag_drop_controller_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(DragDropWindowDelegate); | |
130 }; | |
131 | |
80 //////////////////////////////////////////////////////////////////////////////// | 132 //////////////////////////////////////////////////////////////////////////////// |
81 // DragDropController, public: | 133 // DragDropController, public: |
82 | 134 |
83 DragDropController::DragDropController() | 135 DragDropController::DragDropController() |
84 : drag_image_(NULL), | 136 : drag_image_(NULL), |
85 drag_data_(NULL), | 137 drag_data_(NULL), |
86 drag_operation_(0), | 138 drag_operation_(0), |
87 drag_window_(NULL), | 139 drag_window_(NULL), |
88 drag_source_window_(NULL), | 140 drag_source_window_(NULL), |
89 should_block_during_drag_drop_(true), | 141 should_block_during_drag_drop_(true), |
142 ALLOW_THIS_IN_INITIALIZER_LIST( | |
143 drag_drop_window_delegate_(new DragDropWindowDelegate(this))), | |
90 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), | 144 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), |
91 weak_factory_(this) { | 145 weak_factory_(this) { |
92 Shell::GetInstance()->AddPreTargetHandler(this); | 146 Shell::GetInstance()->AddPreTargetHandler(this); |
93 } | 147 } |
94 | 148 |
95 DragDropController::~DragDropController() { | 149 DragDropController::~DragDropController() { |
96 Shell::GetInstance()->RemovePreTargetHandler(this); | 150 Shell::GetInstance()->RemovePreTargetHandler(this); |
97 Cleanup(); | 151 Cleanup(); |
98 if (cancel_animation_.get()) | 152 if (cancel_animation_.get()) |
99 cancel_animation_->End(); | 153 cancel_animation_->End(); |
(...skipping 11 matching lines...) Expand all Loading... | |
111 if (IsDragDropInProgress()) | 165 if (IsDragDropInProgress()) |
112 return 0; | 166 return 0; |
113 | 167 |
114 const ui::OSExchangeData::Provider* provider = &data.provider(); | 168 const ui::OSExchangeData::Provider* provider = &data.provider(); |
115 // We do not support touch drag/drop without a drag image. | 169 // We do not support touch drag/drop without a drag image. |
116 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && | 170 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && |
117 provider->GetDragImage().size().IsEmpty()) | 171 provider->GetDragImage().size().IsEmpty()) |
118 return 0; | 172 return 0; |
119 | 173 |
120 current_drag_event_source_ = source; | 174 current_drag_event_source_ = source; |
121 DragDropTracker* tracker = new DragDropTracker(root_window); | 175 DragDropTracker* tracker = |
176 new DragDropTracker(root_window, drag_drop_window_delegate_.get()); | |
122 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | 177 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
123 // We need to transfer the current gesture sequence and the GR's touch event | 178 // We need to transfer the current gesture sequence and the GR's touch event |
124 // queue to the |drag_drop_tracker_|'s capture window so that when it takes | 179 // queue to the |drag_drop_tracker_|'s capture window so that when it takes |
125 // capture, it still gets a valid gesture state. | 180 // capture, it still gets a valid gesture state. |
126 root_window->gesture_recognizer()->TransferEventsTo(source_window, | 181 root_window->gesture_recognizer()->TransferEventsTo(source_window, |
127 tracker->capture_window()); | 182 tracker->capture_window()); |
128 // We also send a gesture end to the source window so it can clear state. | 183 // We also send a gesture end to the source window so it can clear state. |
129 // TODO(varunjain): Remove this whole block when gesture sequence | 184 // TODO(varunjain): Remove this whole block when gesture sequence |
130 // transferring is properly done in the GR (http://crbug.com/160558) | 185 // transferring is properly done in the GR (http://crbug.com/160558) |
131 DispatchGestureEndToWindow(source_window); | 186 DispatchGestureEndToWindow(source_window); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 } else { | 318 } else { |
264 drag_image_.reset(); | 319 drag_image_.reset(); |
265 } | 320 } |
266 | 321 |
267 Cleanup(); | 322 Cleanup(); |
268 if (should_block_during_drag_drop_) | 323 if (should_block_during_drag_drop_) |
269 quit_closure_.Run(); | 324 quit_closure_.Run(); |
270 } | 325 } |
271 | 326 |
272 void DragDropController::DragCancel() { | 327 void DragDropController::DragCancel() { |
328 // Ignore if the drag window is already deleted. This happens when | |
varunjain
2013/03/25 18:04:23
Can we handle this case in DragDropWindowDelegate:
oshima
2013/03/25 20:41:10
Checking if drag&drop is in progress in OnCaptureL
| |
329 // |drag_drop_tracker_| is reset, which invokes OnCaptureLost. | |
330 if (!drag_window_) | |
331 return; | |
273 DoDragCancel(kCancelAnimationDuration); | 332 DoDragCancel(kCancelAnimationDuration); |
274 } | 333 } |
275 | 334 |
276 bool DragDropController::IsDragDropInProgress() { | 335 bool DragDropController::IsDragDropInProgress() { |
277 return !!drag_drop_tracker_.get(); | 336 return !!drag_drop_tracker_.get(); |
278 } | 337 } |
279 | 338 |
280 void DragDropController::OnKeyEvent(ui::KeyEvent* event) { | 339 void DragDropController::OnKeyEvent(ui::KeyEvent* event) { |
281 if (IsDragDropInProgress() && event->key_code() == ui::VKEY_ESCAPE) { | 340 if (IsDragDropInProgress() && event->key_code() == ui::VKEY_ESCAPE) { |
282 DragCancel(); | 341 DragCancel(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 drag_window_->RemoveObserver(this); | 553 drag_window_->RemoveObserver(this); |
495 drag_window_ = NULL; | 554 drag_window_ = NULL; |
496 drag_data_ = NULL; | 555 drag_data_ = NULL; |
497 // Cleanup can be called again while deleting DragDropTracker, so use Pass | 556 // Cleanup can be called again while deleting DragDropTracker, so use Pass |
498 // instead of reset to avoid double free. | 557 // instead of reset to avoid double free. |
499 drag_drop_tracker_.Pass(); | 558 drag_drop_tracker_.Pass(); |
500 } | 559 } |
501 | 560 |
502 } // namespace internal | 561 } // namespace internal |
503 } // namespace ash | 562 } // namespace ash |
OLD | NEW |