OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/drag_drop_controller.h" | 5 #include "ui/aura_shell/drag_drop_controller.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
9 #include "ui/aura/client/window_drag_drop_delegate.h" | 9 #include "ui/aura/client/window_drag_drop_delegate.h" |
10 #include "ui/aura/desktop.h" | 10 #include "ui/aura/root_window.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/aura_shell/drag_image_view.h" | 12 #include "ui/aura_shell/drag_image_view.h" |
13 #include "ui/aura_shell/shell.h" | 13 #include "ui/aura_shell/shell.h" |
14 #include "ui/base/dragdrop/drag_drop_types.h" | 14 #include "ui/base/dragdrop/drag_drop_types.h" |
15 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 15 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
16 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 #include "ui/views/widget/native_widget_aura.h" | 18 #include "ui/views/widget/native_widget_aura.h" |
19 | 19 |
20 namespace aura_shell { | 20 namespace aura_shell { |
21 namespace internal { | 21 namespace internal { |
22 | 22 |
23 using aura::Desktop; | 23 using aura::RootWindow; |
24 | 24 |
25 namespace { | 25 namespace { |
26 aura::WindowDragDropDelegate* GetDragDropDelegate(aura::Window* window) { | 26 aura::WindowDragDropDelegate* GetDragDropDelegate(aura::Window* window) { |
27 if (!window) | 27 if (!window) |
28 return NULL; | 28 return NULL; |
29 void* prop = window->GetProperty(aura::kDragDropDelegateKey); | 29 void* prop = window->GetProperty(aura::kDragDropDelegateKey); |
30 if (!prop) | 30 if (!prop) |
31 return NULL; | 31 return NULL; |
32 return static_cast<aura::WindowDragDropDelegate*>(prop); | 32 return static_cast<aura::WindowDragDropDelegate*>(prop); |
33 } | 33 } |
34 | 34 |
35 const gfx::Point kDragDropWidgetOffset(0, 0); | 35 const gfx::Point kDragDropWidgetOffset(0, 0); |
36 | 36 |
37 } | 37 } |
38 | 38 |
39 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
40 // DragDropController, public: | 40 // DragDropController, public: |
41 | 41 |
42 DragDropController::DragDropController() | 42 DragDropController::DragDropController() |
43 : aura::EventFilter(Desktop::GetInstance()), | 43 : aura::EventFilter(RootWindow::GetInstance()), |
44 drag_image_(NULL), | 44 drag_image_(NULL), |
45 drag_data_(NULL), | 45 drag_data_(NULL), |
46 drag_operation_(0), | 46 drag_operation_(0), |
47 dragged_window_(NULL), | 47 dragged_window_(NULL), |
48 drag_drop_in_progress_(false), | 48 drag_drop_in_progress_(false), |
49 should_block_during_drag_drop_(true) { | 49 should_block_during_drag_drop_(true) { |
50 Shell::GetInstance()->AddDesktopEventFilter(this); | 50 Shell::GetInstance()->AddRootWindowEventFilter(this); |
51 } | 51 } |
52 | 52 |
53 DragDropController::~DragDropController() { | 53 DragDropController::~DragDropController() { |
54 Shell::GetInstance()->RemoveDesktopEventFilter(this); | 54 Shell::GetInstance()->RemoveRootWindowEventFilter(this); |
55 Cleanup(); | 55 Cleanup(); |
56 } | 56 } |
57 | 57 |
58 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 58 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
59 int operation) { | 59 int operation) { |
60 DCHECK(!drag_drop_in_progress_); | 60 DCHECK(!drag_drop_in_progress_); |
61 aura::Window* capture_window = Desktop::GetInstance()->capture_window(); | 61 aura::Window* capture_window = RootWindow::GetInstance()->capture_window(); |
62 if (capture_window) | 62 if (capture_window) |
63 Desktop::GetInstance()->ReleaseCapture(capture_window); | 63 RootWindow::GetInstance()->ReleaseCapture(capture_window); |
64 drag_drop_in_progress_ = true; | 64 drag_drop_in_progress_ = true; |
65 | 65 |
66 drag_data_ = &data; | 66 drag_data_ = &data; |
67 drag_operation_ = operation; | 67 drag_operation_ = operation; |
68 gfx::Point location = Desktop::GetInstance()->last_mouse_location(); | 68 gfx::Point location = RootWindow::GetInstance()->last_mouse_location(); |
69 const ui::OSExchangeDataProviderAura& provider = | 69 const ui::OSExchangeDataProviderAura& provider = |
70 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); | 70 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); |
71 | 71 |
72 drag_image_.reset(new DragImageView); | 72 drag_image_.reset(new DragImageView); |
73 drag_image_->SetImage(provider.drag_image()); | 73 drag_image_->SetImage(provider.drag_image()); |
74 drag_image_->SetScreenBounds(gfx::Rect(location.Add(kDragDropWidgetOffset), | 74 drag_image_->SetScreenBounds(gfx::Rect(location.Add(kDragDropWidgetOffset), |
75 drag_image_->GetPreferredSize())); | 75 drag_image_->GetPreferredSize())); |
76 drag_image_->SetWidgetVisible(true); | 76 drag_image_->SetWidgetVisible(true); |
77 | 77 |
78 dragged_window_ = NULL; | 78 dragged_window_ = NULL; |
79 | 79 |
80 if (should_block_during_drag_drop_) { | 80 if (should_block_during_drag_drop_) { |
81 MessageLoopForUI::current()->RunWithDispatcher( | 81 MessageLoopForUI::current()->RunWithDispatcher( |
82 Desktop::GetInstance()->GetDispatcher()); | 82 RootWindow::GetInstance()->GetDispatcher()); |
83 } | 83 } |
84 return drag_operation_; | 84 return drag_operation_; |
85 } | 85 } |
86 | 86 |
87 void DragDropController::DragUpdate(aura::Window* target, | 87 void DragDropController::DragUpdate(aura::Window* target, |
88 const aura::MouseEvent& event) { | 88 const aura::MouseEvent& event) { |
89 aura::WindowDragDropDelegate* delegate = NULL; | 89 aura::WindowDragDropDelegate* delegate = NULL; |
90 if (target != dragged_window_) { | 90 if (target != dragged_window_) { |
91 if ((delegate = GetDragDropDelegate(dragged_window_))) | 91 if ((delegate = GetDragDropDelegate(dragged_window_))) |
92 delegate->OnDragExited(); | 92 delegate->OnDragExited(); |
93 dragged_window_ = target; | 93 dragged_window_ = target; |
94 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 94 if ((delegate = GetDragDropDelegate(dragged_window_))) { |
95 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 95 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
96 delegate->OnDragEntered(e); | 96 delegate->OnDragEntered(e); |
97 } | 97 } |
98 } else { | 98 } else { |
99 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 99 if ((delegate = GetDragDropDelegate(dragged_window_))) { |
100 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 100 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
101 int op = delegate->OnDragUpdated(e); | 101 int op = delegate->OnDragUpdated(e); |
102 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? | 102 gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? |
103 aura::kCursorMove : aura::kCursorHand; | 103 aura::kCursorMove : aura::kCursorHand; |
104 Desktop::GetInstance()->SetCursor(cursor); | 104 RootWindow::GetInstance()->SetCursor(cursor); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 DCHECK(drag_image_.get()); | 108 DCHECK(drag_image_.get()); |
109 if (drag_image_->IsVisible()) { | 109 if (drag_image_->IsVisible()) { |
110 drag_image_->SetScreenPosition(Desktop::GetInstance()-> | 110 drag_image_->SetScreenPosition(RootWindow::GetInstance()-> |
111 last_mouse_location().Add(kDragDropWidgetOffset)); | 111 last_mouse_location().Add(kDragDropWidgetOffset)); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 void DragDropController::Drop(aura::Window* target, | 115 void DragDropController::Drop(aura::Window* target, |
116 const aura::MouseEvent& event) { | 116 const aura::MouseEvent& event) { |
117 aura::WindowDragDropDelegate* delegate = NULL; | 117 aura::WindowDragDropDelegate* delegate = NULL; |
118 DCHECK(target == dragged_window_); | 118 DCHECK(target == dragged_window_); |
119 if ((delegate = GetDragDropDelegate(dragged_window_))) { | 119 if ((delegate = GetDragDropDelegate(dragged_window_))) { |
120 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); | 120 aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // DragDropController, private: | 175 // DragDropController, private: |
176 | 176 |
177 void DragDropController::Cleanup() { | 177 void DragDropController::Cleanup() { |
178 drag_image_.reset(); | 178 drag_image_.reset(); |
179 drag_data_ = NULL; | 179 drag_data_ = NULL; |
180 drag_drop_in_progress_ = false; | 180 drag_drop_in_progress_ = false; |
181 } | 181 } |
182 | 182 |
183 } // namespace internal | 183 } // namespace internal |
184 } // namespace aura_shell | 184 } // namespace aura_shell |
OLD | NEW |