Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: ash/drag_drop/drag_drop_controller.cc

Issue 11787005: Get drag and drop working on Win Ash. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/gfx/point.h" 24 #include "ui/gfx/point.h"
25 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/rect_conversions.h" 26 #include "ui/gfx/rect_conversions.h"
27 #include "ui/views/views_delegate.h" 27 #include "ui/views/views_delegate.h"
28 #include "ui/views/widget/native_widget_aura.h" 28 #include "ui/views/widget/native_widget_aura.h"
29 29
30 namespace ash { 30 namespace ash {
31 namespace internal { 31 namespace internal {
32 32
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 int DragDropController::StartDragAndDrop( 99 int DragDropController::StartDragAndDrop(
100 const ui::OSExchangeData& data, 100 const ui::OSExchangeData& data,
101 aura::RootWindow* root_window, 101 aura::RootWindow* root_window,
102 aura::Window* source_window, 102 aura::Window* source_window,
103 const gfx::Point& root_location, 103 const gfx::Point& root_location,
104 int operation, 104 int operation,
105 ui::DragDropTypes::DragEventSource source) { 105 ui::DragDropTypes::DragEventSource source) {
106 if (IsDragDropInProgress()) 106 if (IsDragDropInProgress())
107 return 0; 107 return 0;
108 108
109 #if defined(OS_WIN) 109 const ui::OSExchangeData::Provider* provider = &data.provider();
110 // TODO(win_ash): need to figure out how this will work in Metro, since
111 // OSExchangeDataProviderAura isn't used in Windows builds. Two alternatives:
112 // 1) Use OSExchangeDataProviderAura in Ash and OSExchangeDataProviderWin
113 // elsewhere. This will complicate creating an ui::OSExchangeData to pass
114 // in more context.
115 // 2) Add methods to get the image and offset in the base interface of these
116 // implementations to get to this data here.
117 NOTIMPLEMENTED();
118 return 0;
119 #else
120 const ui::OSExchangeDataProviderAura& provider =
121 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider());
122 // We do not support touch drag/drop without a drag image. 110 // We do not support touch drag/drop without a drag image.
123 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && 111 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH &&
124 provider.drag_image().size().IsEmpty()) 112 provider->GetDragImage().size().IsEmpty())
125 return 0; 113 return 0;
126 114
127 current_drag_event_source_ = source; 115 current_drag_event_source_ = source;
128 DragDropTracker* tracker = new DragDropTracker(root_window); 116 DragDropTracker* tracker = new DragDropTracker(root_window);
129 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { 117 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) {
130 // We need to transfer the current gesture sequence and the GR's touch event 118 // We need to transfer the current gesture sequence and the GR's touch event
131 // queue to the |drag_drop_tracker_|'s capture window so that when it takes 119 // queue to the |drag_drop_tracker_|'s capture window so that when it takes
132 // capture, it still gets a valid gesture state. 120 // capture, it still gets a valid gesture state.
133 root_window->gesture_recognizer()->TransferEventsTo(source_window, 121 root_window->gesture_recognizer()->TransferEventsTo(source_window,
134 tracker->capture_window()); 122 tracker->capture_window());
(...skipping 14 matching lines...) Expand all
149 137
150 float drag_image_scale = 1; 138 float drag_image_scale = 1;
151 int drag_image_vertical_offset = 0; 139 int drag_image_vertical_offset = 0;
152 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { 140 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) {
153 drag_image_scale = kTouchDragImageScale; 141 drag_image_scale = kTouchDragImageScale;
154 drag_image_vertical_offset = kTouchDragImageVerticalOffset; 142 drag_image_vertical_offset = kTouchDragImageVerticalOffset;
155 } 143 }
156 gfx::Point start_location = root_location; 144 gfx::Point start_location = root_location;
157 ash::wm::ConvertPointToScreen(root_window, &start_location); 145 ash::wm::ConvertPointToScreen(root_window, &start_location);
158 drag_image_final_bounds_for_cancel_animation_ = gfx::Rect( 146 drag_image_final_bounds_for_cancel_animation_ = gfx::Rect(
159 start_location - provider.drag_image_offset(), 147 start_location - provider->GetDragImageOffset(),
160 provider.drag_image().size()); 148 provider->GetDragImage().size());
161 drag_image_.reset(new DragImageView); 149 drag_image_.reset(new DragImageView);
162 drag_image_->SetImage(provider.drag_image()); 150 drag_image_->SetImage(provider->GetDragImage());
163 drag_image_offset_ = provider.drag_image_offset(); 151 drag_image_offset_ = provider->GetDragImageOffset();
164 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); 152 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize());
165 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(drag_image_bounds, 153 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(drag_image_bounds,
166 drag_image_vertical_offset, drag_image_scale, &drag_image_offset_); 154 drag_image_vertical_offset, drag_image_scale, &drag_image_offset_);
167 drag_image_->SetBoundsInScreen(drag_image_bounds); 155 drag_image_->SetBoundsInScreen(drag_image_bounds);
168 drag_image_->SetWidgetVisible(true); 156 drag_image_->SetWidgetVisible(true);
169 157
170 drag_window_ = NULL; 158 drag_window_ = NULL;
171 159
172 // Ends cancel animation if it's in progress. 160 // Ends cancel animation if it's in progress.
173 if (cancel_animation_.get()) 161 if (cancel_animation_.get())
(...skipping 10 matching lines...) Expand all
184 #endif // !defined(OS_MACOSX) 172 #endif // !defined(OS_MACOSX)
185 173
186 if (!cancel_animation_.get() || !cancel_animation_->is_animating() || 174 if (!cancel_animation_.get() || !cancel_animation_->is_animating() ||
187 !pending_long_tap_.get()) { 175 !pending_long_tap_.get()) {
188 // If drag cancel animation is running, this cleanup is done when the 176 // If drag cancel animation is running, this cleanup is done when the
189 // animation completes. 177 // animation completes.
190 if (drag_source_window_) 178 if (drag_source_window_)
191 drag_source_window_->RemoveObserver(this); 179 drag_source_window_->RemoveObserver(this);
192 drag_source_window_ = NULL; 180 drag_source_window_ = NULL;
193 } 181 }
194 #endif
195 182
196 return drag_operation_; 183 return drag_operation_;
197 } 184 }
198 185
199 void DragDropController::DragUpdate(aura::Window* target, 186 void DragDropController::DragUpdate(aura::Window* target,
200 const ui::LocatedEvent& event) { 187 const ui::LocatedEvent& event) {
201 aura::client::DragDropDelegate* delegate = NULL; 188 aura::client::DragDropDelegate* delegate = NULL;
202 if (target != drag_window_) { 189 if (target != drag_window_) {
203 if (drag_window_) { 190 if (drag_window_) {
204 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) 191 if ((delegate = aura::client::GetDragDropDelegate(drag_window_)))
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 drag_window_->RemoveObserver(this); 489 drag_window_->RemoveObserver(this);
503 drag_window_ = NULL; 490 drag_window_ = NULL;
504 drag_data_ = NULL; 491 drag_data_ = NULL;
505 // Cleanup can be called again while deleting DragDropTracker, so use Pass 492 // Cleanup can be called again while deleting DragDropTracker, so use Pass
506 // instead of reset to avoid double free. 493 // instead of reset to avoid double free.
507 drag_drop_tracker_.Pass(); 494 drag_drop_tracker_.Pass();
508 } 495 }
509 496
510 } // namespace internal 497 } // namespace internal
511 } // namespace ash 498 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698