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" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 switch (event->type()) { | 325 switch (event->type()) { |
326 case ui::ET_TOUCH_CANCELLED: | 326 case ui::ET_TOUCH_CANCELLED: |
327 DragCancel(); | 327 DragCancel(); |
328 break; | 328 break; |
329 default: | 329 default: |
330 break; | 330 break; |
331 } | 331 } |
332 return ui::ER_UNHANDLED; | 332 return ui::ER_UNHANDLED; |
333 } | 333 } |
334 | 334 |
335 ui::EventResult DragDropController::OnGestureEvent(ui::GestureEvent* event) { | 335 void DragDropController::OnGestureEvent(ui::GestureEvent* event) { |
336 if (!IsDragDropInProgress()) | 336 if (!IsDragDropInProgress()) |
337 return ui::ER_UNHANDLED; | 337 return; |
338 | 338 |
339 // If current drag session was not started by touch, dont process this touch | 339 // If current drag session was not started by touch, dont process this touch |
340 // event, but consume it so it does not interfere with current drag session. | 340 // event, but consume it so it does not interfere with current drag session. |
341 if (current_drag_event_source_ != ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) | 341 if (current_drag_event_source_ != |
342 return ui::ER_CONSUMED; | 342 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
| 343 event->StopPropagation(); |
| 344 return; |
| 345 } |
343 | 346 |
344 // Apply kTouchDragImageVerticalOffset to the location. | 347 // Apply kTouchDragImageVerticalOffset to the location. |
345 ui::GestureEvent touch_offset_event(*event, | 348 ui::GestureEvent touch_offset_event(*event, |
346 static_cast<aura::Window*>(NULL), | 349 static_cast<aura::Window*>(NULL), |
347 static_cast<aura::Window*>(NULL)); | 350 static_cast<aura::Window*>(NULL)); |
348 gfx::Point touch_offset_location = touch_offset_event.location(); | 351 gfx::Point touch_offset_location = touch_offset_event.location(); |
349 gfx::Point touch_offset_root_location = touch_offset_event.root_location(); | 352 gfx::Point touch_offset_root_location = touch_offset_event.root_location(); |
350 touch_offset_location.Offset(0, kTouchDragImageVerticalOffset); | 353 touch_offset_location.Offset(0, kTouchDragImageVerticalOffset); |
351 touch_offset_root_location.Offset(0, kTouchDragImageVerticalOffset); | 354 touch_offset_root_location.Offset(0, kTouchDragImageVerticalOffset); |
352 touch_offset_event.set_location(touch_offset_location); | 355 touch_offset_event.set_location(touch_offset_location); |
353 touch_offset_event.set_root_location(touch_offset_root_location); | 356 touch_offset_event.set_root_location(touch_offset_root_location); |
354 | 357 |
355 aura::Window* translated_target = | 358 aura::Window* translated_target = |
356 drag_drop_tracker_->GetTarget(touch_offset_event); | 359 drag_drop_tracker_->GetTarget(touch_offset_event); |
357 if (!translated_target) { | 360 if (!translated_target) { |
358 DragCancel(); | 361 DragCancel(); |
359 return ui::ER_HANDLED; | 362 event->SetHandled(); |
| 363 return; |
360 } | 364 } |
361 scoped_ptr<ui::LocatedEvent> translated_event( | 365 scoped_ptr<ui::LocatedEvent> translated_event( |
362 drag_drop_tracker_->ConvertEvent(translated_target, touch_offset_event)); | 366 drag_drop_tracker_->ConvertEvent(translated_target, touch_offset_event)); |
363 | 367 |
364 switch (event->type()) { | 368 switch (event->type()) { |
365 case ui::ET_GESTURE_SCROLL_UPDATE: | 369 case ui::ET_GESTURE_SCROLL_UPDATE: |
366 DragUpdate(translated_target, *translated_event.get()); | 370 DragUpdate(translated_target, *translated_event.get()); |
367 break; | 371 break; |
368 case ui::ET_GESTURE_SCROLL_END: | 372 case ui::ET_GESTURE_SCROLL_END: |
369 Drop(translated_target, *translated_event.get()); | 373 Drop(translated_target, *translated_event.get()); |
370 break; | 374 break; |
371 case ui::ET_SCROLL_FLING_START: | 375 case ui::ET_SCROLL_FLING_START: |
372 case ui::ET_GESTURE_LONG_TAP: | 376 case ui::ET_GESTURE_LONG_TAP: |
373 // Ideally we would want to just forward this long tap event to the | 377 // Ideally we would want to just forward this long tap event to the |
374 // |drag_source_window_|. However, webkit does not accept events while a | 378 // |drag_source_window_|. However, webkit does not accept events while a |
375 // drag drop is still in progress. The drag drop ends only when the nested | 379 // drag drop is still in progress. The drag drop ends only when the nested |
376 // message loop ends. Due to this stupidity, we have to defer forwarding | 380 // message loop ends. Due to this stupidity, we have to defer forwarding |
377 // the long tap. | 381 // the long tap. |
378 pending_long_tap_.reset( | 382 pending_long_tap_.reset( |
379 new ui::GestureEvent(*event, | 383 new ui::GestureEvent(*event, |
380 static_cast<aura::Window*>(drag_drop_tracker_->capture_window()), | 384 static_cast<aura::Window*>(drag_drop_tracker_->capture_window()), |
381 static_cast<aura::Window*>(drag_source_window_))); | 385 static_cast<aura::Window*>(drag_source_window_))); |
382 DoDragCancel(kTouchCancelAnimationDuration); | 386 DoDragCancel(kTouchCancelAnimationDuration); |
383 break; | 387 break; |
384 default: | 388 default: |
385 break; | 389 break; |
386 } | 390 } |
387 return ui::ER_HANDLED; | 391 event->SetHandled(); |
388 } | 392 } |
389 | 393 |
390 void DragDropController::OnWindowDestroyed(aura::Window* window) { | 394 void DragDropController::OnWindowDestroyed(aura::Window* window) { |
391 if (drag_window_ == window) { | 395 if (drag_window_ == window) { |
392 drag_window_->RemoveObserver(this); | 396 drag_window_->RemoveObserver(this); |
393 drag_window_ = NULL; | 397 drag_window_ = NULL; |
394 } | 398 } |
395 if (drag_source_window_ == window) { | 399 if (drag_source_window_ == window) { |
396 drag_source_window_->RemoveObserver(this); | 400 drag_source_window_->RemoveObserver(this); |
397 drag_source_window_ = NULL; | 401 drag_source_window_ = NULL; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 drag_window_->RemoveObserver(this); | 490 drag_window_->RemoveObserver(this); |
487 drag_window_ = NULL; | 491 drag_window_ = NULL; |
488 drag_data_ = NULL; | 492 drag_data_ = NULL; |
489 // Cleanup can be called again while deleting DragDropTracker, so use Pass | 493 // Cleanup can be called again while deleting DragDropTracker, so use Pass |
490 // instead of reset to avoid double free. | 494 // instead of reset to avoid double free. |
491 drag_drop_tracker_.Pass(); | 495 drag_drop_tracker_.Pass(); |
492 } | 496 } |
493 | 497 |
494 } // namespace internal | 498 } // namespace internal |
495 } // namespace ash | 499 } // namespace ash |
OLD | NEW |