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

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

Issue 10855159: Support Drag and Drop across displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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_image_view.h" 8 #include "ash/drag_drop/drag_image_view.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/wm/cursor_manager.h" 10 #include "ash/wm/cursor_manager.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "ui/aura/client/capture_client.h" 13 #include "ui/aura/client/capture_client.h"
13 #include "ui/aura/client/drag_drop_delegate.h" 14 #include "ui/aura/client/drag_drop_delegate.h"
14 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
15 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
16 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
(...skipping 20 matching lines...) Expand all
37 38
38 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
39 // DragDropController, public: 40 // DragDropController, public:
40 41
41 DragDropController::DragDropController() 42 DragDropController::DragDropController()
42 : drag_image_(NULL), 43 : drag_image_(NULL),
43 drag_data_(NULL), 44 drag_data_(NULL),
44 drag_operation_(0), 45 drag_operation_(0),
45 drag_window_(NULL), 46 drag_window_(NULL),
46 drag_drop_in_progress_(false), 47 drag_drop_in_progress_(false),
47 should_block_during_drag_drop_(true) { 48 should_block_during_drag_drop_(true),
49 drag_drop_tracker_(new DragDropTracker) {
48 Shell::GetInstance()->AddEnvEventFilter(this); 50 Shell::GetInstance()->AddEnvEventFilter(this);
49 } 51 }
50 52
51 DragDropController::~DragDropController() { 53 DragDropController::~DragDropController() {
52 Shell::GetInstance()->RemoveEnvEventFilter(this); 54 Shell::GetInstance()->RemoveEnvEventFilter(this);
53 Cleanup(); 55 Cleanup();
54 if (drag_image_.get()) 56 if (drag_image_.get())
55 drag_image_.reset(); 57 drag_image_.reset();
56 } 58 }
57 59
58 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, 60 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
61 aura::RootWindow* root_window,
59 const gfx::Point& root_location, 62 const gfx::Point& root_location,
60 int operation) { 63 int operation) {
61 DCHECK(!drag_drop_in_progress_); 64 DCHECK(!drag_drop_in_progress_);
62 // TODO(oshima): Add CaptureClient client API. 65
63 aura::Window* capture_window =
64 aura::client::GetCaptureWindow(Shell::GetPrimaryRootWindow());
65 if (capture_window)
66 capture_window->ReleaseCapture();
67 drag_drop_in_progress_ = true; 66 drag_drop_in_progress_ = true;
68 drag_cursor_ = ui::kCursorPointer; 67 drag_cursor_ = ui::kCursorPointer;
68 drag_drop_tracker_->StartTracking(root_window);
69 69
70 drag_data_ = &data; 70 drag_data_ = &data;
71 drag_operation_ = operation; 71 drag_operation_ = operation;
72 const ui::OSExchangeDataProviderAura& provider = 72 const ui::OSExchangeDataProviderAura& provider =
73 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); 73 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider());
74 74
75 drag_image_.reset(new DragImageView); 75 drag_image_.reset(new DragImageView);
76 drag_image_->SetImage(provider.drag_image()); 76 drag_image_->SetImage(provider.drag_image());
77 drag_image_offset_ = provider.drag_image_offset(); 77 drag_image_offset_ = provider.drag_image_offset();
78 drag_image_->SetBoundsInScreen(gfx::Rect( 78 drag_image_->SetBoundsInScreen(gfx::Rect(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 DragCancel(); 206 DragCancel();
207 return true; 207 return true;
208 } 208 }
209 return false; 209 return false;
210 } 210 }
211 211
212 bool DragDropController::PreHandleMouseEvent(aura::Window* target, 212 bool DragDropController::PreHandleMouseEvent(aura::Window* target,
213 ui::MouseEvent* event) { 213 ui::MouseEvent* event) {
214 if (!drag_drop_in_progress_) 214 if (!drag_drop_in_progress_)
215 return false; 215 return false;
216 switch (event->type()) { 216 aura::Window* translated_target = drag_drop_tracker_->GetTarget(*event);
217 if (!translated_target)
218 return false;
varunjain 2012/08/20 16:21:22 when can this happen? Drag drop is in progress, so
mazda 2012/08/21 02:10:59 This happens when the cursor goes out of root wind
varunjain 2012/08/21 04:37:25 How about calling DragCancel() instead. It will do
mazda 2012/08/24 08:29:01 Done.
219 scoped_ptr<ui::MouseEvent> translated_event(
220 drag_drop_tracker_->ConvertMouseEvent(translated_target, *event));
221 switch (translated_event->type()) {
217 case ui::ET_MOUSE_DRAGGED: 222 case ui::ET_MOUSE_DRAGGED:
218 DragUpdate(target, *event); 223 DragUpdate(translated_target, *translated_event.get());
varunjain 2012/08/20 16:21:22 would you also require re-parenting the drag_image
mazda 2012/08/21 02:10:59 DragImageView::SetScreenPosition does it internall
varunjain 2012/08/21 04:37:25 cool! thanks for fixing!
219 break; 224 break;
220 case ui::ET_MOUSE_RELEASED: 225 case ui::ET_MOUSE_RELEASED:
221 Drop(target, *event); 226 Drop(translated_target, *translated_event.get());
222 break; 227 break;
223 default: 228 default:
224 // We could reach here if the user drops outside the root window.
225 // We could also reach here because RootWindow may sometimes generate a 229 // We could also reach here because RootWindow may sometimes generate a
226 // bunch of fake mouse events 230 // bunch of fake mouse events
227 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange). 231 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange).
228 break; 232 break;
229 } 233 }
230 return true; 234 return true;
231 } 235 }
232 236
233 ui::TouchStatus DragDropController::PreHandleTouchEvent( 237 ui::TouchStatus DragDropController::PreHandleTouchEvent(
sky 2012/08/20 15:35:18 Do you need to update touch similarly?
varunjain 2012/08/20 15:53:20 Touch dnd does not currently work. I have a bug fo
mazda 2012/08/21 02:10:59 Could you tell me the issue ID? I'll add TODO comm
varunjain 2012/08/21 04:37:25 crbug.com/114755
mazda 2012/08/24 08:29:01 Thanks. I added a TODO comment.
234 aura::Window* target, 238 aura::Window* target,
235 ui::TouchEvent* event) { 239 ui::TouchEvent* event) {
236 // TODO(sad): Also check for the touch-id. 240 // TODO(sad): Also check for the touch-id.
237 if (!drag_drop_in_progress_) 241 if (!drag_drop_in_progress_)
238 return ui::TOUCH_STATUS_UNKNOWN; 242 return ui::TOUCH_STATUS_UNKNOWN;
239 switch (event->type()) { 243 switch (event->type()) {
240 case ui::ET_TOUCH_MOVED: 244 case ui::ET_TOUCH_MOVED:
241 DragUpdate(target, *event); 245 DragUpdate(target, *event);
242 break; 246 break;
243 case ui::ET_TOUCH_RELEASED: 247 case ui::ET_TOUCH_RELEASED:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 animation_setter.AddObserver(this); 295 animation_setter.AddObserver(this);
292 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size())); 296 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size()));
293 } 297 }
294 298
295 void DragDropController::Cleanup() { 299 void DragDropController::Cleanup() {
296 if (drag_window_) 300 if (drag_window_)
297 drag_window_->RemoveObserver(this); 301 drag_window_->RemoveObserver(this);
298 drag_window_ = NULL; 302 drag_window_ = NULL;
299 drag_data_ = NULL; 303 drag_data_ = NULL;
300 drag_drop_in_progress_ = false; 304 drag_drop_in_progress_ = false;
305 drag_drop_tracker_->StopTracking();
301 } 306 }
302 307
303 } // namespace internal 308 } // namespace internal
304 } // namespace ash 309 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698