| 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 "ash/wm/cursor_manager.h" | 11 #include "ash/wm/cursor_manager.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "ui/aura/client/capture_client.h" | 15 #include "ui/aura/client/capture_client.h" |
| 16 #include "ui/aura/client/drag_drop_delegate.h" | 16 #include "ui/aura/client/drag_drop_delegate.h" |
| 17 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
| 18 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/base/animation/linear_animation.h" | 20 #include "ui/base/animation/linear_animation.h" |
| 21 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
| 22 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 22 #include "ui/base/dragdrop/os_exchange_data.h" |
| 23 #include "ui/base/events/event.h" | 23 #include "ui/base/events/event.h" |
| 24 #include "ui/base/events/event_utils.h" | 24 #include "ui/base/events/event_utils.h" |
| 25 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
| 26 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
| 27 #include "ui/gfx/rect_conversions.h" | 27 #include "ui/gfx/rect_conversions.h" |
| 28 #include "ui/views/views_delegate.h" | 28 #include "ui/views/views_delegate.h" |
| 29 #include "ui/views/widget/native_widget_aura.h" | 29 #include "ui/views/widget/native_widget_aura.h" |
| 30 | 30 |
| 31 namespace ash { | 31 namespace ash { |
| 32 namespace internal { | 32 namespace internal { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 int DragDropController::StartDragAndDrop( | 105 int DragDropController::StartDragAndDrop( |
| 106 const ui::OSExchangeData& data, | 106 const ui::OSExchangeData& data, |
| 107 aura::RootWindow* root_window, | 107 aura::RootWindow* root_window, |
| 108 aura::Window* source_window, | 108 aura::Window* source_window, |
| 109 const gfx::Point& root_location, | 109 const gfx::Point& root_location, |
| 110 int operation, | 110 int operation, |
| 111 ui::DragDropTypes::DragEventSource source) { | 111 ui::DragDropTypes::DragEventSource source) { |
| 112 if (IsDragDropInProgress()) | 112 if (IsDragDropInProgress()) |
| 113 return 0; | 113 return 0; |
| 114 | 114 |
| 115 #if defined(OS_WIN) | 115 const ui::OSExchangeData::Provider* provider = &data.provider(); |
| 116 // TODO(win_ash): need to figure out how this will work in Metro, since | |
| 117 // OSExchangeDataProviderAura isn't used in Windows builds. Two alternatives: | |
| 118 // 1) Use OSExchangeDataProviderAura in Ash and OSExchangeDataProviderWin | |
| 119 // elsewhere. This will complicate creating an ui::OSExchangeData to pass | |
| 120 // in more context. | |
| 121 // 2) Add methods to get the image and offset in the base interface of these | |
| 122 // implementations to get to this data here. | |
| 123 NOTIMPLEMENTED(); | |
| 124 return 0; | |
| 125 #else | |
| 126 const ui::OSExchangeDataProviderAura& provider = | |
| 127 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); | |
| 128 // We do not support touch drag/drop without a drag image. | 116 // We do not support touch drag/drop without a drag image. |
| 129 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && | 117 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && |
| 130 provider.drag_image().size().IsEmpty()) | 118 provider->GetDragImage().size().IsEmpty()) |
| 131 return 0; | 119 return 0; |
| 132 | 120 |
| 133 current_drag_event_source_ = source; | 121 current_drag_event_source_ = source; |
| 134 DragDropTracker* tracker = new DragDropTracker(root_window); | 122 DragDropTracker* tracker = new DragDropTracker(root_window); |
| 135 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | 123 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
| 136 // We need to transfer the current gesture sequence and the GR's touch event | 124 // We need to transfer the current gesture sequence and the GR's touch event |
| 137 // queue to the |drag_drop_tracker_|'s capture window so that when it takes | 125 // queue to the |drag_drop_tracker_|'s capture window so that when it takes |
| 138 // capture, it still gets a valid gesture state. | 126 // capture, it still gets a valid gesture state. |
| 139 root_window->gesture_recognizer()->TransferEventsTo(source_window, | 127 root_window->gesture_recognizer()->TransferEventsTo(source_window, |
| 140 tracker->capture_window()); | 128 tracker->capture_window()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 155 | 143 |
| 156 float drag_image_scale = 1; | 144 float drag_image_scale = 1; |
| 157 int drag_image_vertical_offset = 0; | 145 int drag_image_vertical_offset = 0; |
| 158 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { | 146 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { |
| 159 drag_image_scale = kTouchDragImageScale; | 147 drag_image_scale = kTouchDragImageScale; |
| 160 drag_image_vertical_offset = kTouchDragImageVerticalOffset; | 148 drag_image_vertical_offset = kTouchDragImageVerticalOffset; |
| 161 } | 149 } |
| 162 gfx::Point start_location = root_location; | 150 gfx::Point start_location = root_location; |
| 163 ash::wm::ConvertPointToScreen(root_window, &start_location); | 151 ash::wm::ConvertPointToScreen(root_window, &start_location); |
| 164 drag_image_final_bounds_for_cancel_animation_ = gfx::Rect( | 152 drag_image_final_bounds_for_cancel_animation_ = gfx::Rect( |
| 165 start_location - provider.drag_image_offset(), | 153 start_location - provider->GetDragImageOffset(), |
| 166 provider.drag_image().size()); | 154 provider->GetDragImage().size()); |
| 167 drag_image_.reset(new DragImageView); | 155 drag_image_.reset(new DragImageView); |
| 168 drag_image_->SetImage(provider.drag_image()); | 156 drag_image_->SetImage(provider->GetDragImage()); |
| 169 drag_image_offset_ = provider.drag_image_offset(); | 157 drag_image_offset_ = provider->GetDragImageOffset(); |
| 170 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); | 158 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); |
| 171 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(drag_image_bounds, | 159 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(drag_image_bounds, |
| 172 drag_image_vertical_offset, drag_image_scale, &drag_image_offset_); | 160 drag_image_vertical_offset, drag_image_scale, &drag_image_offset_); |
| 173 drag_image_->SetBoundsInScreen(drag_image_bounds); | 161 drag_image_->SetBoundsInScreen(drag_image_bounds); |
| 174 drag_image_->SetWidgetVisible(true); | 162 drag_image_->SetWidgetVisible(true); |
| 175 | 163 |
| 176 drag_window_ = NULL; | 164 drag_window_ = NULL; |
| 177 | 165 |
| 178 // Ends cancel animation if it's in progress. | 166 // Ends cancel animation if it's in progress. |
| 179 if (cancel_animation_.get()) | 167 if (cancel_animation_.get()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 190 #endif // !defined(OS_MACOSX) | 178 #endif // !defined(OS_MACOSX) |
| 191 | 179 |
| 192 if (!cancel_animation_.get() || !cancel_animation_->is_animating() || | 180 if (!cancel_animation_.get() || !cancel_animation_->is_animating() || |
| 193 !pending_long_tap_.get()) { | 181 !pending_long_tap_.get()) { |
| 194 // If drag cancel animation is running, this cleanup is done when the | 182 // If drag cancel animation is running, this cleanup is done when the |
| 195 // animation completes. | 183 // animation completes. |
| 196 if (drag_source_window_) | 184 if (drag_source_window_) |
| 197 drag_source_window_->RemoveObserver(this); | 185 drag_source_window_->RemoveObserver(this); |
| 198 drag_source_window_ = NULL; | 186 drag_source_window_ = NULL; |
| 199 } | 187 } |
| 200 #endif | |
| 201 | 188 |
| 202 return drag_operation_; | 189 return drag_operation_; |
| 203 } | 190 } |
| 204 | 191 |
| 205 void DragDropController::DragUpdate(aura::Window* target, | 192 void DragDropController::DragUpdate(aura::Window* target, |
| 206 const ui::LocatedEvent& event) { | 193 const ui::LocatedEvent& event) { |
| 207 aura::client::DragDropDelegate* delegate = NULL; | 194 aura::client::DragDropDelegate* delegate = NULL; |
| 208 if (target != drag_window_) { | 195 if (target != drag_window_) { |
| 209 if (drag_window_) { | 196 if (drag_window_) { |
| 210 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) | 197 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 drag_window_->RemoveObserver(this); | 495 drag_window_->RemoveObserver(this); |
| 509 drag_window_ = NULL; | 496 drag_window_ = NULL; |
| 510 drag_data_ = NULL; | 497 drag_data_ = NULL; |
| 511 // Cleanup can be called again while deleting DragDropTracker, so use Pass | 498 // Cleanup can be called again while deleting DragDropTracker, so use Pass |
| 512 // instead of reset to avoid double free. | 499 // instead of reset to avoid double free. |
| 513 drag_drop_tracker_.Pass(); | 500 drag_drop_tracker_.Pass(); |
| 514 } | 501 } |
| 515 | 502 |
| 516 } // namespace internal | 503 } // namespace internal |
| 517 } // namespace ash | 504 } // namespace ash |
| OLD | NEW |