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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if (drag_image_.get()) | 55 if (drag_image_.get()) |
56 drag_image_.reset(); | 56 drag_image_.reset(); |
57 } | 57 } |
58 | 58 |
59 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, | 59 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, |
60 aura::RootWindow* root_window, | 60 aura::RootWindow* root_window, |
61 const gfx::Point& root_location, | 61 const gfx::Point& root_location, |
62 int operation) { | 62 int operation) { |
63 DCHECK(!IsDragDropInProgress()); | 63 DCHECK(!IsDragDropInProgress()); |
64 | 64 |
65 drag_cursor_ = ui::kCursorPointer; | |
66 drag_drop_tracker_.reset(new DragDropTracker(root_window)); | 65 drag_drop_tracker_.reset(new DragDropTracker(root_window)); |
67 | 66 |
68 drag_data_ = &data; | 67 drag_data_ = &data; |
69 drag_operation_ = operation; | 68 drag_operation_ = operation; |
70 const ui::OSExchangeDataProviderAura& provider = | 69 const ui::OSExchangeDataProviderAura& provider = |
71 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); | 70 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); |
72 | 71 |
73 drag_image_.reset(new DragImageView); | 72 drag_image_.reset(new DragImageView); |
74 drag_image_->SetImage(provider.drag_image()); | 73 drag_image_->SetImage(provider.drag_image()); |
75 drag_image_offset_ = provider.drag_image_offset(); | 74 drag_image_offset_ = provider.drag_image_offset(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 drag_operation_); | 120 drag_operation_); |
122 e.set_flags(event.flags()); | 121 e.set_flags(event.flags()); |
123 int op = delegate->OnDragUpdated(e); | 122 int op = delegate->OnDragUpdated(e); |
124 gfx::NativeCursor cursor = ui::kCursorNoDrop; | 123 gfx::NativeCursor cursor = ui::kCursorNoDrop; |
125 if (op & ui::DragDropTypes::DRAG_COPY) | 124 if (op & ui::DragDropTypes::DRAG_COPY) |
126 cursor = ui::kCursorCopy; | 125 cursor = ui::kCursorCopy; |
127 else if (op & ui::DragDropTypes::DRAG_LINK) | 126 else if (op & ui::DragDropTypes::DRAG_LINK) |
128 cursor = ui::kCursorAlias; | 127 cursor = ui::kCursorAlias; |
129 else if (op & ui::DragDropTypes::DRAG_MOVE) | 128 else if (op & ui::DragDropTypes::DRAG_MOVE) |
130 cursor = ui::kCursorMove; | 129 cursor = ui::kCursorMove; |
131 drag_cursor_ = cursor; | |
132 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); | 130 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); |
133 } | 131 } |
134 } | 132 } |
135 | 133 |
136 DCHECK(drag_image_.get()); | 134 DCHECK(drag_image_.get()); |
137 if (drag_image_->visible()) { | 135 if (drag_image_->visible()) { |
138 gfx::Point root_location_in_screen = event.root_location(); | 136 gfx::Point root_location_in_screen = event.root_location(); |
139 ash::wm::ConvertPointToScreen(target->GetRootWindow(), | 137 ash::wm::ConvertPointToScreen(target->GetRootWindow(), |
140 &root_location_in_screen); | 138 &root_location_in_screen); |
141 drag_image_->SetScreenPosition( | 139 drag_image_->SetScreenPosition( |
142 root_location_in_screen.Subtract(drag_image_offset_)); | 140 root_location_in_screen.Subtract(drag_image_offset_)); |
143 } | 141 } |
144 } | 142 } |
145 | 143 |
146 void DragDropController::Drop(aura::Window* target, | 144 void DragDropController::Drop(aura::Window* target, |
147 const ui::LocatedEvent& event) { | 145 const ui::LocatedEvent& event) { |
148 drag_cursor_ = ui::kCursorPointer; | |
149 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); | 146 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); |
150 aura::client::DragDropDelegate* delegate = NULL; | 147 aura::client::DragDropDelegate* delegate = NULL; |
151 | 148 |
152 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit | 149 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit |
153 // depends on not getting a Drop without DragEnter. This behavior is | 150 // depends on not getting a Drop without DragEnter. This behavior is |
154 // consistent with drag/drop on other platforms. | 151 // consistent with drag/drop on other platforms. |
155 if (target != drag_window_) | 152 if (target != drag_window_) |
156 DragUpdate(target, event); | 153 DragUpdate(target, event); |
157 DCHECK(target == drag_window_); | 154 DCHECK(target == drag_window_); |
158 | 155 |
159 if ((delegate = aura::client::GetDragDropDelegate(target))) { | 156 if ((delegate = aura::client::GetDragDropDelegate(target))) { |
160 ui::DropTargetEvent e( | 157 ui::DropTargetEvent e( |
161 *drag_data_, event.location(), event.root_location(), drag_operation_); | 158 *drag_data_, event.location(), event.root_location(), drag_operation_); |
162 e.set_flags(event.flags()); | 159 e.set_flags(event.flags()); |
163 drag_operation_ = delegate->OnPerformDrop(e); | 160 drag_operation_ = delegate->OnPerformDrop(e); |
164 if (drag_operation_ == 0) | 161 if (drag_operation_ == 0) |
165 StartCanceledAnimation(); | 162 StartCanceledAnimation(); |
166 else | 163 else |
167 drag_image_.reset(); | 164 drag_image_.reset(); |
168 } else { | 165 } else { |
169 drag_image_.reset(); | 166 drag_image_.reset(); |
170 } | 167 } |
171 | 168 |
172 Cleanup(); | 169 Cleanup(); |
173 if (should_block_during_drag_drop_) | 170 if (should_block_during_drag_drop_) |
174 quit_closure_.Run(); | 171 quit_closure_.Run(); |
175 } | 172 } |
176 | 173 |
177 void DragDropController::DragCancel() { | 174 void DragDropController::DragCancel() { |
178 drag_cursor_ = ui::kCursorPointer; | |
179 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); | 175 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); |
180 | 176 |
181 // |drag_window_| can be NULL if we have just started the drag and have not | 177 // |drag_window_| can be NULL if we have just started the drag and have not |
182 // received any DragUpdates, or, if the |drag_window_| gets destroyed during | 178 // received any DragUpdates, or, if the |drag_window_| gets destroyed during |
183 // a drag/drop. | 179 // a drag/drop. |
184 aura::client::DragDropDelegate* delegate = drag_window_? | 180 aura::client::DragDropDelegate* delegate = drag_window_? |
185 aura::client::GetDragDropDelegate(drag_window_) : NULL; | 181 aura::client::GetDragDropDelegate(drag_window_) : NULL; |
186 if (delegate) | 182 if (delegate) |
187 delegate->OnDragExited(); | 183 delegate->OnDragExited(); |
188 | 184 |
189 Cleanup(); | 185 Cleanup(); |
190 drag_operation_ = 0; | 186 drag_operation_ = 0; |
191 StartCanceledAnimation(); | 187 StartCanceledAnimation(); |
192 if (should_block_during_drag_drop_) | 188 if (should_block_during_drag_drop_) |
193 quit_closure_.Run(); | 189 quit_closure_.Run(); |
194 } | 190 } |
195 | 191 |
196 bool DragDropController::IsDragDropInProgress() { | 192 bool DragDropController::IsDragDropInProgress() { |
197 return !!drag_drop_tracker_.get(); | 193 return !!drag_drop_tracker_.get(); |
198 } | 194 } |
199 | 195 |
200 gfx::NativeCursor DragDropController::GetDragCursor() { | |
201 return drag_cursor_; | |
202 } | |
203 | |
204 bool DragDropController::PreHandleKeyEvent(aura::Window* target, | 196 bool DragDropController::PreHandleKeyEvent(aura::Window* target, |
205 ui::KeyEvent* event) { | 197 ui::KeyEvent* event) { |
206 if (IsDragDropInProgress() && event->key_code() == ui::VKEY_ESCAPE) { | 198 if (IsDragDropInProgress() && event->key_code() == ui::VKEY_ESCAPE) { |
207 DragCancel(); | 199 DragCancel(); |
208 return true; | 200 return true; |
209 } | 201 } |
210 return false; | 202 return false; |
211 } | 203 } |
212 | 204 |
213 bool DragDropController::PreHandleMouseEvent(aura::Window* target, | 205 bool DragDropController::PreHandleMouseEvent(aura::Window* target, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 drag_window_->RemoveObserver(this); | 298 drag_window_->RemoveObserver(this); |
307 drag_window_ = NULL; | 299 drag_window_ = NULL; |
308 drag_data_ = NULL; | 300 drag_data_ = NULL; |
309 // Cleanup can be called again while deleting DragDropTracker, so use Pass | 301 // Cleanup can be called again while deleting DragDropTracker, so use Pass |
310 // instead of reset to avoid double free. | 302 // instead of reset to avoid double free. |
311 drag_drop_tracker_.Pass(); | 303 drag_drop_tracker_.Pass(); |
312 } | 304 } |
313 | 305 |
314 } // namespace internal | 306 } // namespace internal |
315 } // namespace ash | 307 } // namespace ash |
OLD | NEW |