| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 static const int kTouchDragImageVerticalOffset = -25; | 44 static const int kTouchDragImageVerticalOffset = -25; |
| 45 | 45 |
| 46 // Adjusts the drag image bounds such that the new bounds are scaled by |scale| | 46 // Adjusts the drag image bounds such that the new bounds are scaled by |scale| |
| 47 // and translated by the |drag_image_offset| and and additional | 47 // and translated by the |drag_image_offset| and and additional |
| 48 // |vertical_offset|. | 48 // |vertical_offset|. |
| 49 gfx::Rect AdjustDragImageBoundsForScaleAndOffset( | 49 gfx::Rect AdjustDragImageBoundsForScaleAndOffset( |
| 50 const gfx::Rect& drag_image_bounds, | 50 const gfx::Rect& drag_image_bounds, |
| 51 int vertical_offset, | 51 int vertical_offset, |
| 52 float scale, | 52 float scale, |
| 53 gfx::Vector2d* drag_image_offset) { | 53 gfx::Vector2d* drag_image_offset) { |
| 54 gfx::PointF final_origin = drag_image_bounds.origin(); | 54 gfx::Point final_origin = drag_image_bounds.origin(); |
| 55 gfx::SizeF final_size = gfx::SizeF(drag_image_bounds.size()); | 55 gfx::SizeF final_size = gfx::SizeF(drag_image_bounds.size()); |
| 56 final_size.Scale(scale); | 56 final_size.Scale(scale); |
| 57 drag_image_offset->set_x(drag_image_offset->x() * scale); | 57 drag_image_offset->set_x(drag_image_offset->x() * scale); |
| 58 drag_image_offset->set_y(drag_image_offset->y() * scale); | 58 drag_image_offset->set_y(drag_image_offset->y() * scale); |
| 59 float total_x_offset = drag_image_offset->x(); | 59 int total_x_offset = drag_image_offset->x(); |
| 60 float total_y_offset = drag_image_offset->y() - vertical_offset; | 60 int total_y_offset = drag_image_offset->y() - vertical_offset; |
| 61 final_origin.Offset(-total_x_offset, -total_y_offset); | 61 final_origin.Offset(-total_x_offset, -total_y_offset); |
| 62 return gfx::ToEnclosingRect(gfx::RectF(final_origin, final_size)); | 62 return gfx::ToEnclosingRect( |
| 63 gfx::RectF(gfx::PointF(final_origin), final_size)); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void DispatchGestureEndToWindow(aura::Window* window) { | 66 void DispatchGestureEndToWindow(aura::Window* window) { |
| 66 if (window && window->delegate()) { | 67 if (window && window->delegate()) { |
| 67 ui::GestureEvent gesture_end(0, | 68 ui::GestureEvent gesture_end(0, |
| 68 0, | 69 0, |
| 69 0, | 70 0, |
| 70 ui::EventTimeForNow(), | 71 ui::EventTimeForNow(), |
| 71 ui::GestureEventDetails(ui::ET_GESTURE_END)); | 72 ui::GestureEventDetails(ui::ET_GESTURE_END)); |
| 72 window->delegate()->OnGestureEvent(&gesture_end); | 73 window->delegate()->OnGestureEvent(&gesture_end); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 if (drag_window_ != drag_source_window_) | 257 if (drag_window_ != drag_source_window_) |
| 257 drag_window_->RemoveObserver(this); | 258 drag_window_->RemoveObserver(this); |
| 258 } | 259 } |
| 259 drag_window_ = target; | 260 drag_window_ = target; |
| 260 // We are already an observer of |drag_source_window_| so no need to add. | 261 // We are already an observer of |drag_source_window_| so no need to add. |
| 261 if (drag_window_ != drag_source_window_) | 262 if (drag_window_ != drag_source_window_) |
| 262 drag_window_->AddObserver(this); | 263 drag_window_->AddObserver(this); |
| 263 aura::client::DragDropDelegate* delegate = | 264 aura::client::DragDropDelegate* delegate = |
| 264 aura::client::GetDragDropDelegate(drag_window_); | 265 aura::client::GetDragDropDelegate(drag_window_); |
| 265 if (delegate) { | 266 if (delegate) { |
| 266 ui::DropTargetEvent e(*drag_data_, event.location_f(), | 267 ui::DropTargetEvent e(*drag_data_, gfx::Point(), gfx::Point(), |
| 267 event.root_location_f(), drag_operation_); | 268 drag_operation_); |
| 269 e.set_location_f(event.location_f()); |
| 270 e.set_root_location_f(event.root_location_f()); |
| 268 e.set_flags(event.flags()); | 271 e.set_flags(event.flags()); |
| 269 delegate->OnDragEntered(e); | 272 delegate->OnDragEntered(e); |
| 270 } | 273 } |
| 271 } else { | 274 } else { |
| 272 aura::client::DragDropDelegate* delegate = | 275 aura::client::DragDropDelegate* delegate = |
| 273 aura::client::GetDragDropDelegate(drag_window_); | 276 aura::client::GetDragDropDelegate(drag_window_); |
| 274 if (delegate) { | 277 if (delegate) { |
| 275 ui::DropTargetEvent e(*drag_data_, event.location_f(), | 278 ui::DropTargetEvent e(*drag_data_, gfx::Point(), gfx::Point(), |
| 276 event.root_location_f(), drag_operation_); | 279 drag_operation_); |
| 280 e.set_location_f(event.location_f()); |
| 281 e.set_root_location_f(event.root_location_f()); |
| 277 e.set_flags(event.flags()); | 282 e.set_flags(event.flags()); |
| 278 op = delegate->OnDragUpdated(e); | 283 op = delegate->OnDragUpdated(e); |
| 279 gfx::NativeCursor cursor = ui::kCursorNoDrop; | 284 gfx::NativeCursor cursor = ui::kCursorNoDrop; |
| 280 if (op & ui::DragDropTypes::DRAG_COPY) | 285 if (op & ui::DragDropTypes::DRAG_COPY) |
| 281 cursor = ui::kCursorCopy; | 286 cursor = ui::kCursorCopy; |
| 282 else if (op & ui::DragDropTypes::DRAG_LINK) | 287 else if (op & ui::DragDropTypes::DRAG_LINK) |
| 283 cursor = ui::kCursorAlias; | 288 cursor = ui::kCursorAlias; |
| 284 else if (op & ui::DragDropTypes::DRAG_MOVE) | 289 else if (op & ui::DragDropTypes::DRAG_MOVE) |
| 285 cursor = ui::kCursorGrabbing; | 290 cursor = ui::kCursorGrabbing; |
| 286 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); | 291 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 305 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit | 310 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit |
| 306 // depends on not getting a Drop without DragEnter. This behavior is | 311 // depends on not getting a Drop without DragEnter. This behavior is |
| 307 // consistent with drag/drop on other platforms. | 312 // consistent with drag/drop on other platforms. |
| 308 if (target != drag_window_) | 313 if (target != drag_window_) |
| 309 DragUpdate(target, event); | 314 DragUpdate(target, event); |
| 310 DCHECK(target == drag_window_); | 315 DCHECK(target == drag_window_); |
| 311 | 316 |
| 312 aura::client::DragDropDelegate* delegate = | 317 aura::client::DragDropDelegate* delegate = |
| 313 aura::client::GetDragDropDelegate(target); | 318 aura::client::GetDragDropDelegate(target); |
| 314 if (delegate) { | 319 if (delegate) { |
| 315 ui::DropTargetEvent e(*drag_data_, event.location_f(), | 320 ui::DropTargetEvent e(*drag_data_, gfx::Point(), gfx::Point(), |
| 316 event.root_location_f(), drag_operation_); | 321 drag_operation_); |
| 322 e.set_location_f(event.location_f()); |
| 323 e.set_root_location_f(event.root_location_f()); |
| 317 e.set_flags(event.flags()); | 324 e.set_flags(event.flags()); |
| 318 drag_operation_ = delegate->OnPerformDrop(e); | 325 drag_operation_ = delegate->OnPerformDrop(e); |
| 319 if (drag_operation_ == 0) | 326 if (drag_operation_ == 0) |
| 320 StartCanceledAnimation(kCancelAnimationDuration); | 327 StartCanceledAnimation(kCancelAnimationDuration); |
| 321 else | 328 else |
| 322 drag_image_.reset(); | 329 drag_image_.reset(); |
| 323 } else { | 330 } else { |
| 324 drag_image_.reset(); | 331 drag_image_.reset(); |
| 325 } | 332 } |
| 326 | 333 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 return; | 420 return; |
| 414 | 421 |
| 415 // Apply kTouchDragImageVerticalOffset to the location. | 422 // Apply kTouchDragImageVerticalOffset to the location. |
| 416 ui::GestureEvent touch_offset_event(*event, | 423 ui::GestureEvent touch_offset_event(*event, |
| 417 static_cast<aura::Window*>(NULL), | 424 static_cast<aura::Window*>(NULL), |
| 418 static_cast<aura::Window*>(NULL)); | 425 static_cast<aura::Window*>(NULL)); |
| 419 gfx::PointF touch_offset_location = touch_offset_event.location_f(); | 426 gfx::PointF touch_offset_location = touch_offset_event.location_f(); |
| 420 gfx::PointF touch_offset_root_location = touch_offset_event.root_location_f(); | 427 gfx::PointF touch_offset_root_location = touch_offset_event.root_location_f(); |
| 421 touch_offset_location.Offset(0, kTouchDragImageVerticalOffset); | 428 touch_offset_location.Offset(0, kTouchDragImageVerticalOffset); |
| 422 touch_offset_root_location.Offset(0, kTouchDragImageVerticalOffset); | 429 touch_offset_root_location.Offset(0, kTouchDragImageVerticalOffset); |
| 423 touch_offset_event.set_location(touch_offset_location); | 430 touch_offset_event.set_location_f(touch_offset_location); |
| 424 touch_offset_event.set_root_location(touch_offset_root_location); | 431 touch_offset_event.set_root_location_f(touch_offset_root_location); |
| 425 | 432 |
| 426 aura::Window* translated_target = | 433 aura::Window* translated_target = |
| 427 drag_drop_tracker_->GetTarget(touch_offset_event); | 434 drag_drop_tracker_->GetTarget(touch_offset_event); |
| 428 if (!translated_target) { | 435 if (!translated_target) { |
| 429 DragCancel(); | 436 DragCancel(); |
| 430 event->SetHandled(); | 437 event->SetHandled(); |
| 431 return; | 438 return; |
| 432 } | 439 } |
| 433 scoped_ptr<ui::LocatedEvent> translated_event( | 440 scoped_ptr<ui::LocatedEvent> translated_event( |
| 434 drag_drop_tracker_->ConvertEvent(translated_target, touch_offset_event)); | 441 drag_drop_tracker_->ConvertEvent(translated_target, touch_offset_event)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 if (drag_window_) | 562 if (drag_window_) |
| 556 drag_window_->RemoveObserver(this); | 563 drag_window_->RemoveObserver(this); |
| 557 drag_window_ = NULL; | 564 drag_window_ = NULL; |
| 558 drag_data_ = NULL; | 565 drag_data_ = NULL; |
| 559 // Cleanup can be called again while deleting DragDropTracker, so delete | 566 // Cleanup can be called again while deleting DragDropTracker, so delete |
| 560 // the pointer with a local variable to avoid double free. | 567 // the pointer with a local variable to avoid double free. |
| 561 scoped_ptr<ash::DragDropTracker> holder = drag_drop_tracker_.Pass(); | 568 scoped_ptr<ash::DragDropTracker> holder = drag_drop_tracker_.Pass(); |
| 562 } | 569 } |
| 563 | 570 |
| 564 } // namespace ash | 571 } // namespace ash |
| OLD | NEW |