Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | |
| 10 #include "ash/common/drag_drop/drag_image_view.h" | |
| 9 #include "ash/drag_drop/drag_drop_tracker.h" | 11 #include "ash/drag_drop/drag_drop_tracker.h" |
| 10 #include "ash/drag_drop/drag_image_view.h" | |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "ui/aura/client/capture_client.h" | 18 #include "ui/aura/client/capture_client.h" |
| 18 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 DragDropController::DragDropController() | 128 DragDropController::DragDropController() |
| 128 : drag_data_(NULL), | 129 : drag_data_(NULL), |
| 129 drag_operation_(0), | 130 drag_operation_(0), |
| 130 drag_window_(NULL), | 131 drag_window_(NULL), |
| 131 drag_source_window_(NULL), | 132 drag_source_window_(NULL), |
| 132 should_block_during_drag_drop_(true), | 133 should_block_during_drag_drop_(true), |
| 133 drag_drop_window_delegate_(new DragDropTrackerDelegate(this)), | 134 drag_drop_window_delegate_(new DragDropTrackerDelegate(this)), |
| 134 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), | 135 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), |
| 135 weak_factory_(this) { | 136 weak_factory_(this) { |
| 136 Shell::GetInstance()->PrependPreTargetHandler(this); | 137 Shell::GetInstance()->PrependPreTargetHandler(this); |
| 138 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | |
| 137 } | 139 } |
| 138 | 140 |
| 139 DragDropController::~DragDropController() { | 141 DragDropController::~DragDropController() { |
| 142 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | |
| 140 Shell::GetInstance()->RemovePreTargetHandler(this); | 143 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 141 Cleanup(); | 144 Cleanup(); |
| 142 if (cancel_animation_) | 145 if (cancel_animation_) |
| 143 cancel_animation_->End(); | 146 cancel_animation_->End(); |
| 144 if (drag_image_) | 147 if (drag_image_) |
| 145 drag_image_.reset(); | 148 drag_image_.reset(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 int DragDropController::StartDragAndDrop( | 151 int DragDropController::StartDragAndDrop( |
| 149 const ui::OSExchangeData& data, | 152 const ui::OSExchangeData& data, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 float drag_image_scale = 1; | 195 float drag_image_scale = 1; |
| 193 int drag_image_vertical_offset = 0; | 196 int drag_image_vertical_offset = 0; |
| 194 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | 197 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
| 195 drag_image_scale = kTouchDragImageScale; | 198 drag_image_scale = kTouchDragImageScale; |
| 196 drag_image_vertical_offset = kTouchDragImageVerticalOffset; | 199 drag_image_vertical_offset = kTouchDragImageVerticalOffset; |
| 197 } | 200 } |
| 198 gfx::Point start_location = screen_location; | 201 gfx::Point start_location = screen_location; |
| 199 drag_image_final_bounds_for_cancel_animation_ = | 202 drag_image_final_bounds_for_cancel_animation_ = |
| 200 gfx::Rect(start_location - provider->GetDragImageOffset(), | 203 gfx::Rect(start_location - provider->GetDragImageOffset(), |
| 201 provider->GetDragImage().size()); | 204 provider->GetDragImage().size()); |
| 202 drag_image_.reset(new DragImageView(source_window->GetRootWindow(), source)); | 205 drag_image_.reset(new DragImageView( |
| 206 WmWindowAura::Get(source_window)->GetRootWindow(), source)); | |
|
msw
2016/08/05 19:32:58
nit: comment here on the reasoning for using WmWin
James Cook
2016/08/05 20:10:11
There's no good reason to change it to WmWindow::G
| |
| 203 drag_image_->SetImage(provider->GetDragImage()); | 207 drag_image_->SetImage(provider->GetDragImage()); |
| 204 drag_image_offset_ = provider->GetDragImageOffset(); | 208 drag_image_offset_ = provider->GetDragImageOffset(); |
| 205 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); | 209 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); |
| 206 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset( | 210 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset( |
| 207 drag_image_bounds, drag_image_vertical_offset, drag_image_scale, | 211 drag_image_bounds, drag_image_vertical_offset, drag_image_scale, |
| 208 &drag_image_offset_); | 212 &drag_image_offset_); |
| 209 drag_image_->SetBoundsInScreen(drag_image_bounds); | 213 drag_image_->SetBoundsInScreen(drag_image_bounds); |
| 210 drag_image_->SetWidgetVisible(true); | 214 drag_image_->SetWidgetVisible(true); |
| 211 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | 215 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
| 212 drag_image_->SetTouchDragOperationHintPosition( | 216 drag_image_->SetTouchDragOperationHintPosition( |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 gfx::Rect current_bounds = animation->CurrentValueBetween( | 534 gfx::Rect current_bounds = animation->CurrentValueBetween( |
| 531 drag_image_initial_bounds_for_cancel_animation_, | 535 drag_image_initial_bounds_for_cancel_animation_, |
| 532 drag_image_final_bounds_for_cancel_animation_); | 536 drag_image_final_bounds_for_cancel_animation_); |
| 533 drag_image_->SetBoundsInScreen(current_bounds); | 537 drag_image_->SetBoundsInScreen(current_bounds); |
| 534 } | 538 } |
| 535 | 539 |
| 536 void DragDropController::AnimationCanceled(const gfx::Animation* animation) { | 540 void DragDropController::AnimationCanceled(const gfx::Animation* animation) { |
| 537 AnimationEnded(animation); | 541 AnimationEnded(animation); |
| 538 } | 542 } |
| 539 | 543 |
| 544 void DragDropController::OnDisplayConfigurationChanging() { | |
| 545 // Abort in-progress drags if a monitor is added or removed because the drag | |
| 546 // image widget's container may be destroyed. | |
| 547 if (IsDragDropInProgress()) | |
| 548 DragCancel(); | |
| 549 } | |
| 550 | |
| 540 void DragDropController::StartCanceledAnimation(int animation_duration_ms) { | 551 void DragDropController::StartCanceledAnimation(int animation_duration_ms) { |
| 541 DCHECK(drag_image_.get()); | 552 DCHECK(drag_image_.get()); |
| 542 drag_image_->SetTouchDragOperationHintOff(); | 553 drag_image_->SetTouchDragOperationHintOff(); |
| 543 drag_image_initial_bounds_for_cancel_animation_ = | 554 drag_image_initial_bounds_for_cancel_animation_ = |
| 544 drag_image_->GetBoundsInScreen(); | 555 drag_image_->GetBoundsInScreen(); |
| 545 cancel_animation_.reset(CreateCancelAnimation( | 556 cancel_animation_.reset(CreateCancelAnimation( |
| 546 animation_duration_ms, kCancelAnimationFrameRate, this)); | 557 animation_duration_ms, kCancelAnimationFrameRate, this)); |
| 547 cancel_animation_->Start(); | 558 cancel_animation_->Start(); |
| 548 } | 559 } |
| 549 | 560 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 562 if (drag_window_) | 573 if (drag_window_) |
| 563 drag_window_->RemoveObserver(this); | 574 drag_window_->RemoveObserver(this); |
| 564 drag_window_ = NULL; | 575 drag_window_ = NULL; |
| 565 drag_data_ = NULL; | 576 drag_data_ = NULL; |
| 566 // Cleanup can be called again while deleting DragDropTracker, so delete | 577 // Cleanup can be called again while deleting DragDropTracker, so delete |
| 567 // the pointer with a local variable to avoid double free. | 578 // the pointer with a local variable to avoid double free. |
| 568 std::unique_ptr<ash::DragDropTracker> holder = std::move(drag_drop_tracker_); | 579 std::unique_ptr<ash::DragDropTracker> holder = std::move(drag_drop_tracker_); |
| 569 } | 580 } |
| 570 | 581 |
| 571 } // namespace ash | 582 } // namespace ash |
| OLD | NEW |