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 "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/metrics/histogram_macros.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
14 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
16 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
17 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
18 #include "ui/base/dragdrop/drag_drop_types.h" | 19 #include "ui/base/dragdrop/drag_drop_types.h" |
19 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
20 #include "ui/base/hit_test.h" | 21 #include "ui/base/hit_test.h" |
21 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 ui::DragDropTypes::DragEventSource source) { | 153 ui::DragDropTypes::DragEventSource source) { |
153 if (IsDragDropInProgress()) | 154 if (IsDragDropInProgress()) |
154 return 0; | 155 return 0; |
155 | 156 |
156 const ui::OSExchangeData::Provider* provider = &data.provider(); | 157 const ui::OSExchangeData::Provider* provider = &data.provider(); |
157 // We do not support touch drag/drop without a drag image. | 158 // We do not support touch drag/drop without a drag image. |
158 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && | 159 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && |
159 provider->GetDragImage().size().IsEmpty()) | 160 provider->GetDragImage().size().IsEmpty()) |
160 return 0; | 161 return 0; |
161 | 162 |
| 163 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Start", source, |
| 164 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); |
| 165 |
162 current_drag_event_source_ = source; | 166 current_drag_event_source_ = source; |
163 DragDropTracker* tracker = | 167 DragDropTracker* tracker = |
164 new DragDropTracker(root_window, drag_drop_window_delegate_.get()); | 168 new DragDropTracker(root_window, drag_drop_window_delegate_.get()); |
165 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | 169 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
166 // We need to transfer the current gesture sequence and the GR's touch event | 170 // We need to transfer the current gesture sequence and the GR's touch event |
167 // queue to the |drag_drop_tracker_|'s capture window so that when it takes | 171 // queue to the |drag_drop_tracker_|'s capture window so that when it takes |
168 // capture, it still gets a valid gesture state. | 172 // capture, it still gets a valid gesture state. |
169 ui::GestureRecognizer::Get()->TransferEventsTo(source_window, | 173 ui::GestureRecognizer::Get()->TransferEventsTo(source_window, |
170 tracker->capture_window()); | 174 tracker->capture_window()); |
171 // We also send a gesture end to the source window so it can clear state. | 175 // We also send a gesture end to the source window so it can clear state. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 cancel_animation_->End(); | 219 cancel_animation_->End(); |
216 | 220 |
217 if (should_block_during_drag_drop_) { | 221 if (should_block_during_drag_drop_) { |
218 base::RunLoop run_loop; | 222 base::RunLoop run_loop; |
219 quit_closure_ = run_loop.QuitClosure(); | 223 quit_closure_ = run_loop.QuitClosure(); |
220 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 224 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
221 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | 225 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
222 run_loop.Run(); | 226 run_loop.Run(); |
223 } | 227 } |
224 | 228 |
| 229 if (drag_operation_ == 0) { |
| 230 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Cancel", source, |
| 231 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); |
| 232 } else { |
| 233 UMA_HISTOGRAM_ENUMERATION("Event.DragDrop.Drop", source, |
| 234 ui::DragDropTypes::DRAG_EVENT_SOURCE_COUNT); |
| 235 } |
| 236 |
225 if (!cancel_animation_.get() || !cancel_animation_->is_animating() || | 237 if (!cancel_animation_.get() || !cancel_animation_->is_animating() || |
226 !pending_long_tap_.get()) { | 238 !pending_long_tap_.get()) { |
227 // If drag cancel animation is running, this cleanup is done when the | 239 // If drag cancel animation is running, this cleanup is done when the |
228 // animation completes. | 240 // animation completes. |
229 if (drag_source_window_) | 241 if (drag_source_window_) |
230 drag_source_window_->RemoveObserver(this); | 242 drag_source_window_->RemoveObserver(this); |
231 drag_source_window_ = NULL; | 243 drag_source_window_ = NULL; |
232 } | 244 } |
233 | 245 |
234 return drag_operation_; | 246 return drag_operation_; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 | 487 |
476 void DragDropController::AnimationEnded(const gfx::Animation* animation) { | 488 void DragDropController::AnimationEnded(const gfx::Animation* animation) { |
477 cancel_animation_.reset(); | 489 cancel_animation_.reset(); |
478 | 490 |
479 // By the time we finish animation, another drag/drop session may have | 491 // By the time we finish animation, another drag/drop session may have |
480 // started. We do not want to destroy the drag image in that case. | 492 // started. We do not want to destroy the drag image in that case. |
481 if (!IsDragDropInProgress()) | 493 if (!IsDragDropInProgress()) |
482 drag_image_.reset(); | 494 drag_image_.reset(); |
483 if (pending_long_tap_) { | 495 if (pending_long_tap_) { |
484 // If not in a nested message loop, we can forward the long tap right now. | 496 // If not in a nested message loop, we can forward the long tap right now. |
485 if (!should_block_during_drag_drop_) | 497 if (!should_block_during_drag_drop_) { |
486 ForwardPendingLongTap(); | 498 ForwardPendingLongTap(); |
487 else { | 499 } else { |
488 // See comment about this in OnGestureEvent(). | 500 // See comment about this in OnGestureEvent(). |
489 base::MessageLoopForUI::current()->PostTask( | 501 base::MessageLoopForUI::current()->PostTask( |
490 FROM_HERE, | 502 FROM_HERE, |
491 base::Bind(&DragDropController::ForwardPendingLongTap, | 503 base::Bind(&DragDropController::ForwardPendingLongTap, |
492 weak_factory_.GetWeakPtr())); | 504 weak_factory_.GetWeakPtr())); |
493 } | 505 } |
494 } | 506 } |
495 } | 507 } |
496 | 508 |
497 void DragDropController::DoDragCancel(int drag_cancel_animation_duration_ms) { | 509 void DragDropController::DoDragCancel(int drag_cancel_animation_duration_ms) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (drag_window_) | 561 if (drag_window_) |
550 drag_window_->RemoveObserver(this); | 562 drag_window_->RemoveObserver(this); |
551 drag_window_ = NULL; | 563 drag_window_ = NULL; |
552 drag_data_ = NULL; | 564 drag_data_ = NULL; |
553 // Cleanup can be called again while deleting DragDropTracker, so delete | 565 // Cleanup can be called again while deleting DragDropTracker, so delete |
554 // the pointer with a local variable to avoid double free. | 566 // the pointer with a local variable to avoid double free. |
555 scoped_ptr<ash::DragDropTracker> holder = drag_drop_tracker_.Pass(); | 567 scoped_ptr<ash::DragDropTracker> holder = drag_drop_tracker_.Pass(); |
556 } | 568 } |
557 | 569 |
558 } // namespace ash | 570 } // namespace ash |
OLD | NEW |