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_image_view.h" | 7 #include "ash/drag_drop/drag_image_view.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/cursor_manager.h" | 9 #include "ash/wm/cursor_manager.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "ui/views/widget/native_widget_aura.h" | 25 #include "ui/views/widget/native_widget_aura.h" |
26 | 26 |
27 namespace ash { | 27 namespace ash { |
28 namespace internal { | 28 namespace internal { |
29 | 29 |
30 using aura::RootWindow; | 30 using aura::RootWindow; |
31 | 31 |
32 namespace { | 32 namespace { |
33 const base::TimeDelta kDragDropAnimationDuration = | 33 const base::TimeDelta kDragDropAnimationDuration = |
34 base::TimeDelta::FromMilliseconds(250); | 34 base::TimeDelta::FromMilliseconds(250); |
35 | |
36 void UnlockAndSwitchCursor(gfx::NativeCursor new_cursor) { | |
37 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); | |
sky
2012/08/02 16:26:42
Unlock/Lock decrement/increment a count. So, it's
varunjain
2012/08/02 17:29:52
I have moved the cursor locking to the RootWindow.
| |
38 ash::Shell::GetInstance()->cursor_manager()->SetCursor(new_cursor); | |
39 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); | |
40 } | |
35 } // namespace | 41 } // namespace |
36 | 42 |
37 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
38 // DragDropController, public: | 44 // DragDropController, public: |
39 | 45 |
40 DragDropController::DragDropController() | 46 DragDropController::DragDropController() |
41 : drag_image_(NULL), | 47 : drag_image_(NULL), |
42 drag_data_(NULL), | 48 drag_data_(NULL), |
43 drag_operation_(0), | 49 drag_operation_(0), |
44 drag_window_(NULL), | 50 drag_window_(NULL), |
(...skipping 12 matching lines...) Expand all Loading... | |
57 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 63 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
58 const gfx::Point& root_location, | 64 const gfx::Point& root_location, |
59 int operation) { | 65 int operation) { |
60 DCHECK(!drag_drop_in_progress_); | 66 DCHECK(!drag_drop_in_progress_); |
61 // TODO(oshima): Add CaptureClient client API. | 67 // TODO(oshima): Add CaptureClient client API. |
62 aura::Window* capture_window = | 68 aura::Window* capture_window = |
63 aura::client::GetCaptureWindow(Shell::GetPrimaryRootWindow()); | 69 aura::client::GetCaptureWindow(Shell::GetPrimaryRootWindow()); |
64 if (capture_window) | 70 if (capture_window) |
65 capture_window->ReleaseCapture(); | 71 capture_window->ReleaseCapture(); |
66 drag_drop_in_progress_ = true; | 72 drag_drop_in_progress_ = true; |
73 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); | |
67 | 74 |
68 drag_data_ = &data; | 75 drag_data_ = &data; |
69 drag_operation_ = operation; | 76 drag_operation_ = operation; |
70 const ui::OSExchangeDataProviderAura& provider = | 77 const ui::OSExchangeDataProviderAura& provider = |
71 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); | 78 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); |
72 | 79 |
73 drag_image_.reset(new DragImageView); | 80 drag_image_.reset(new DragImageView); |
74 drag_image_->SetImage(provider.drag_image()); | 81 drag_image_->SetImage(provider.drag_image()); |
75 drag_image_offset_ = provider.drag_image_offset(); | 82 drag_image_offset_ = provider.drag_image_offset(); |
76 drag_image_->SetBoundsInScreen(gfx::Rect( | 83 drag_image_->SetBoundsInScreen(gfx::Rect( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 drag_operation_); | 128 drag_operation_); |
122 e.set_flags(event.flags()); | 129 e.set_flags(event.flags()); |
123 int op = delegate->OnDragUpdated(e); | 130 int op = delegate->OnDragUpdated(e); |
124 gfx::NativeCursor cursor = ui::kCursorNoDrop; | 131 gfx::NativeCursor cursor = ui::kCursorNoDrop; |
125 if (op & ui::DragDropTypes::DRAG_COPY) | 132 if (op & ui::DragDropTypes::DRAG_COPY) |
126 cursor = ui::kCursorCopy; | 133 cursor = ui::kCursorCopy; |
127 else if (op & ui::DragDropTypes::DRAG_LINK) | 134 else if (op & ui::DragDropTypes::DRAG_LINK) |
128 cursor = ui::kCursorAlias; | 135 cursor = ui::kCursorAlias; |
129 else if (op & ui::DragDropTypes::DRAG_MOVE) | 136 else if (op & ui::DragDropTypes::DRAG_MOVE) |
130 cursor = ui::kCursorMove; | 137 cursor = ui::kCursorMove; |
131 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); | 138 UnlockAndSwitchCursor(cursor); |
132 } | 139 } |
133 } | 140 } |
134 | 141 |
135 DCHECK(drag_image_.get()); | 142 DCHECK(drag_image_.get()); |
136 if (drag_image_->visible()) { | 143 if (drag_image_->visible()) { |
137 drag_image_->SetScreenPosition( | 144 drag_image_->SetScreenPosition( |
138 event.root_location().Subtract(drag_image_offset_)); | 145 event.root_location().Subtract(drag_image_offset_)); |
139 } | 146 } |
140 } | 147 } |
141 | 148 |
142 void DragDropController::Drop(aura::Window* target, | 149 void DragDropController::Drop(aura::Window* target, |
143 const aura::LocatedEvent& event) { | 150 const aura::LocatedEvent& event) { |
144 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); | 151 UnlockAndSwitchCursor(ui::kCursorPointer); |
145 aura::client::DragDropDelegate* delegate = NULL; | 152 aura::client::DragDropDelegate* delegate = NULL; |
146 | 153 |
147 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit | 154 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit |
148 // depends on not getting a Drop without DragEnter. This behavior is | 155 // depends on not getting a Drop without DragEnter. This behavior is |
149 // consistent with drag/drop on other platforms. | 156 // consistent with drag/drop on other platforms. |
150 if (target != drag_window_) | 157 if (target != drag_window_) |
151 DragUpdate(target, event); | 158 DragUpdate(target, event); |
152 DCHECK(target == drag_window_); | 159 DCHECK(target == drag_window_); |
153 | 160 |
154 if ((delegate = aura::client::GetDragDropDelegate(target))) { | 161 if ((delegate = aura::client::GetDragDropDelegate(target))) { |
155 aura::DropTargetEvent e( | 162 aura::DropTargetEvent e( |
156 *drag_data_, event.location(), event.root_location(), drag_operation_); | 163 *drag_data_, event.location(), event.root_location(), drag_operation_); |
157 e.set_flags(event.flags()); | 164 e.set_flags(event.flags()); |
158 drag_operation_ = delegate->OnPerformDrop(e); | 165 drag_operation_ = delegate->OnPerformDrop(e); |
159 if (drag_operation_ == 0) | 166 if (drag_operation_ == 0) |
160 StartCanceledAnimation(); | 167 StartCanceledAnimation(); |
161 else | 168 else |
162 drag_image_.reset(); | 169 drag_image_.reset(); |
163 } else { | 170 } else { |
164 drag_image_.reset(); | 171 drag_image_.reset(); |
165 } | 172 } |
166 | 173 |
167 Cleanup(); | 174 Cleanup(); |
168 if (should_block_during_drag_drop_) | 175 if (should_block_during_drag_drop_) |
169 quit_closure_.Run(); | 176 quit_closure_.Run(); |
170 } | 177 } |
171 | 178 |
172 void DragDropController::DragCancel() { | 179 void DragDropController::DragCancel() { |
173 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); | 180 UnlockAndSwitchCursor(ui::kCursorPointer); |
174 | 181 |
175 // |drag_window_| can be NULL if we have just started the drag and have not | 182 // |drag_window_| can be NULL if we have just started the drag and have not |
176 // received any DragUpdates, or, if the |drag_window_| gets destroyed during | 183 // received any DragUpdates, or, if the |drag_window_| gets destroyed during |
177 // a drag/drop. | 184 // a drag/drop. |
178 aura::client::DragDropDelegate* delegate = drag_window_? | 185 aura::client::DragDropDelegate* delegate = drag_window_? |
179 aura::client::GetDragDropDelegate(drag_window_) : NULL; | 186 aura::client::GetDragDropDelegate(drag_window_) : NULL; |
180 if (delegate) | 187 if (delegate) |
181 delegate->OnDragExited(); | 188 delegate->OnDragExited(); |
182 | 189 |
183 Cleanup(); | 190 Cleanup(); |
(...skipping 20 matching lines...) Expand all Loading... | |
204 aura::MouseEvent* event) { | 211 aura::MouseEvent* event) { |
205 if (!drag_drop_in_progress_) | 212 if (!drag_drop_in_progress_) |
206 return false; | 213 return false; |
207 switch (event->type()) { | 214 switch (event->type()) { |
208 case ui::ET_MOUSE_DRAGGED: | 215 case ui::ET_MOUSE_DRAGGED: |
209 DragUpdate(target, *event); | 216 DragUpdate(target, *event); |
210 break; | 217 break; |
211 case ui::ET_MOUSE_RELEASED: | 218 case ui::ET_MOUSE_RELEASED: |
212 Drop(target, *event); | 219 Drop(target, *event); |
213 break; | 220 break; |
214 case ui::ET_MOUSE_EXITED: | |
215 DragCancel(); | |
216 break; | |
217 default: | 221 default: |
218 // We could reach here if the user drops outside the root window. | 222 // We could reach here if the user drops outside the root window. |
219 // We could also reach here because RootWindow may sometimes generate a | 223 // We could also reach here because RootWindow may sometimes generate a |
220 // bunch of fake mouse events | 224 // bunch of fake mouse events |
221 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange). | 225 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange). |
222 break; | 226 break; |
223 } | 227 } |
224 return true; | 228 return true; |
225 } | 229 } |
226 | 230 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 animation_setter.AddObserver(this); | 289 animation_setter.AddObserver(this); |
286 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size())); | 290 window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size())); |
287 } | 291 } |
288 | 292 |
289 void DragDropController::Cleanup() { | 293 void DragDropController::Cleanup() { |
290 if (drag_window_) | 294 if (drag_window_) |
291 drag_window_->RemoveObserver(this); | 295 drag_window_->RemoveObserver(this); |
292 drag_window_ = NULL; | 296 drag_window_ = NULL; |
293 drag_data_ = NULL; | 297 drag_data_ = NULL; |
294 drag_drop_in_progress_ = false; | 298 drag_drop_in_progress_ = false; |
299 if (ash::Shell::GetInstance()->cursor_manager()->is_cursor_locked()) | |
300 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); | |
295 } | 301 } |
296 | 302 |
297 } // namespace internal | 303 } // namespace internal |
298 } // namespace ash | 304 } // namespace ash |
OLD | NEW |