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

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

Issue 10825143: aura: Fix a couple of drag drop issues: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch 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
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ui/aura/client/drag_drop_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, 57 int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
58 const gfx::Point& root_location, 58 const gfx::Point& root_location,
59 int operation) { 59 int operation) {
60 DCHECK(!drag_drop_in_progress_); 60 DCHECK(!drag_drop_in_progress_);
61 // TODO(oshima): Add CaptureClient client API. 61 // TODO(oshima): Add CaptureClient client API.
62 aura::Window* capture_window = 62 aura::Window* capture_window =
63 aura::client::GetCaptureWindow(Shell::GetPrimaryRootWindow()); 63 aura::client::GetCaptureWindow(Shell::GetPrimaryRootWindow());
64 if (capture_window) 64 if (capture_window)
65 capture_window->ReleaseCapture(); 65 capture_window->ReleaseCapture();
66 drag_drop_in_progress_ = true; 66 drag_drop_in_progress_ = true;
67 drag_cursor_ = ui::kCursorPointer;
67 68
68 drag_data_ = &data; 69 drag_data_ = &data;
69 drag_operation_ = operation; 70 drag_operation_ = operation;
70 const ui::OSExchangeDataProviderAura& provider = 71 const ui::OSExchangeDataProviderAura& provider =
71 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); 72 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider());
72 73
73 drag_image_.reset(new DragImageView); 74 drag_image_.reset(new DragImageView);
74 drag_image_->SetImage(provider.drag_image()); 75 drag_image_->SetImage(provider.drag_image());
75 drag_image_offset_ = provider.drag_image_offset(); 76 drag_image_offset_ = provider.drag_image_offset();
76 drag_image_->SetBoundsInScreen(gfx::Rect( 77 drag_image_->SetBoundsInScreen(gfx::Rect(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 drag_operation_); 122 drag_operation_);
122 e.set_flags(event.flags()); 123 e.set_flags(event.flags());
123 int op = delegate->OnDragUpdated(e); 124 int op = delegate->OnDragUpdated(e);
124 gfx::NativeCursor cursor = ui::kCursorNoDrop; 125 gfx::NativeCursor cursor = ui::kCursorNoDrop;
125 if (op & ui::DragDropTypes::DRAG_COPY) 126 if (op & ui::DragDropTypes::DRAG_COPY)
126 cursor = ui::kCursorCopy; 127 cursor = ui::kCursorCopy;
127 else if (op & ui::DragDropTypes::DRAG_LINK) 128 else if (op & ui::DragDropTypes::DRAG_LINK)
128 cursor = ui::kCursorAlias; 129 cursor = ui::kCursorAlias;
129 else if (op & ui::DragDropTypes::DRAG_MOVE) 130 else if (op & ui::DragDropTypes::DRAG_MOVE)
130 cursor = ui::kCursorMove; 131 cursor = ui::kCursorMove;
132 drag_cursor_ = cursor;
131 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); 133 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor);
132 } 134 }
133 } 135 }
134 136
135 DCHECK(drag_image_.get()); 137 DCHECK(drag_image_.get());
136 if (drag_image_->visible()) { 138 if (drag_image_->visible()) {
137 drag_image_->SetScreenPosition( 139 drag_image_->SetScreenPosition(
138 event.root_location().Subtract(drag_image_offset_)); 140 event.root_location().Subtract(drag_image_offset_));
139 } 141 }
140 } 142 }
141 143
142 void DragDropController::Drop(aura::Window* target, 144 void DragDropController::Drop(aura::Window* target,
143 const aura::LocatedEvent& event) { 145 const aura::LocatedEvent& event) {
146 drag_cursor_ = ui::kCursorPointer;
144 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); 147 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
145 aura::client::DragDropDelegate* delegate = NULL; 148 aura::client::DragDropDelegate* delegate = NULL;
146 149
147 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit 150 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit
148 // depends on not getting a Drop without DragEnter. This behavior is 151 // depends on not getting a Drop without DragEnter. This behavior is
149 // consistent with drag/drop on other platforms. 152 // consistent with drag/drop on other platforms.
150 if (target != drag_window_) 153 if (target != drag_window_)
151 DragUpdate(target, event); 154 DragUpdate(target, event);
152 DCHECK(target == drag_window_); 155 DCHECK(target == drag_window_);
153 156
154 if ((delegate = aura::client::GetDragDropDelegate(target))) { 157 if ((delegate = aura::client::GetDragDropDelegate(target))) {
155 aura::DropTargetEvent e( 158 aura::DropTargetEvent e(
156 *drag_data_, event.location(), event.root_location(), drag_operation_); 159 *drag_data_, event.location(), event.root_location(), drag_operation_);
157 e.set_flags(event.flags()); 160 e.set_flags(event.flags());
158 drag_operation_ = delegate->OnPerformDrop(e); 161 drag_operation_ = delegate->OnPerformDrop(e);
159 if (drag_operation_ == 0) 162 if (drag_operation_ == 0)
160 StartCanceledAnimation(); 163 StartCanceledAnimation();
161 else 164 else
162 drag_image_.reset(); 165 drag_image_.reset();
163 } else { 166 } else {
164 drag_image_.reset(); 167 drag_image_.reset();
165 } 168 }
166 169
167 Cleanup(); 170 Cleanup();
168 if (should_block_during_drag_drop_) 171 if (should_block_during_drag_drop_)
169 quit_closure_.Run(); 172 quit_closure_.Run();
170 } 173 }
171 174
172 void DragDropController::DragCancel() { 175 void DragDropController::DragCancel() {
176 drag_cursor_ = ui::kCursorPointer;
173 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); 177 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
174 178
175 // |drag_window_| can be NULL if we have just started the drag and have not 179 // |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 180 // received any DragUpdates, or, if the |drag_window_| gets destroyed during
177 // a drag/drop. 181 // a drag/drop.
178 aura::client::DragDropDelegate* delegate = drag_window_? 182 aura::client::DragDropDelegate* delegate = drag_window_?
179 aura::client::GetDragDropDelegate(drag_window_) : NULL; 183 aura::client::GetDragDropDelegate(drag_window_) : NULL;
180 if (delegate) 184 if (delegate)
181 delegate->OnDragExited(); 185 delegate->OnDragExited();
182 186
183 Cleanup(); 187 Cleanup();
184 drag_operation_ = 0; 188 drag_operation_ = 0;
185 StartCanceledAnimation(); 189 StartCanceledAnimation();
186 if (should_block_during_drag_drop_) 190 if (should_block_during_drag_drop_)
187 quit_closure_.Run(); 191 quit_closure_.Run();
188 } 192 }
189 193
190 bool DragDropController::IsDragDropInProgress() { 194 bool DragDropController::IsDragDropInProgress() {
191 return drag_drop_in_progress_; 195 return drag_drop_in_progress_;
192 } 196 }
193 197
198 gfx::NativeCursor DragDropController::GetDragCursor() {
199 return drag_cursor_;
200 }
201
194 bool DragDropController::PreHandleKeyEvent(aura::Window* target, 202 bool DragDropController::PreHandleKeyEvent(aura::Window* target,
195 aura::KeyEvent* event) { 203 aura::KeyEvent* event) {
196 if (drag_drop_in_progress_ && event->key_code() == ui::VKEY_ESCAPE) { 204 if (drag_drop_in_progress_ && event->key_code() == ui::VKEY_ESCAPE) {
197 DragCancel(); 205 DragCancel();
198 return true; 206 return true;
199 } 207 }
200 return false; 208 return false;
201 } 209 }
202 210
203 bool DragDropController::PreHandleMouseEvent(aura::Window* target, 211 bool DragDropController::PreHandleMouseEvent(aura::Window* target,
204 aura::MouseEvent* event) { 212 aura::MouseEvent* event) {
205 if (!drag_drop_in_progress_) 213 if (!drag_drop_in_progress_)
206 return false; 214 return false;
207 switch (event->type()) { 215 switch (event->type()) {
208 case ui::ET_MOUSE_DRAGGED: 216 case ui::ET_MOUSE_DRAGGED:
209 DragUpdate(target, *event); 217 DragUpdate(target, *event);
210 break; 218 break;
211 case ui::ET_MOUSE_RELEASED: 219 case ui::ET_MOUSE_RELEASED:
212 Drop(target, *event); 220 Drop(target, *event);
213 break; 221 break;
214 case ui::ET_MOUSE_EXITED:
215 DragCancel();
216 break;
217 default: 222 default:
218 // We could reach here if the user drops outside the root window. 223 // We could reach here if the user drops outside the root window.
219 // We could also reach here because RootWindow may sometimes generate a 224 // We could also reach here because RootWindow may sometimes generate a
220 // bunch of fake mouse events 225 // bunch of fake mouse events
221 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange). 226 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange).
222 break; 227 break;
223 } 228 }
224 return true; 229 return true;
225 } 230 }
226 231
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 void DragDropController::Cleanup() { 294 void DragDropController::Cleanup() {
290 if (drag_window_) 295 if (drag_window_)
291 drag_window_->RemoveObserver(this); 296 drag_window_->RemoveObserver(this);
292 drag_window_ = NULL; 297 drag_window_ = NULL;
293 drag_data_ = NULL; 298 drag_data_ = NULL;
294 drag_drop_in_progress_ = false; 299 drag_drop_in_progress_ = false;
295 } 300 }
296 301
297 } // namespace internal 302 } // namespace internal
298 } // namespace ash 303 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ui/aura/client/drag_drop_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698