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

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

Issue 10827145: Convert Aura to use ui::Event. (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
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "ui/aura/client/capture_client.h" 12 #include "ui/aura/client/capture_client.h"
13 #include "ui/aura/client/drag_drop_delegate.h" 13 #include "ui/aura/client/drag_drop_delegate.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/base/event.h"
17 #include "ui/base/dragdrop/drag_drop_types.h" 18 #include "ui/base/dragdrop/drag_drop_types.h"
18 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" 19 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h"
19 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
20 #include "ui/compositor/layer_animator.h" 21 #include "ui/compositor/layer_animator.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h" 22 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/gfx/point.h" 23 #include "ui/gfx/point.h"
23 #include "ui/gfx/rect.h" 24 #include "ui/gfx/rect.h"
24 #include "ui/views/views_delegate.h" 25 #include "ui/views/views_delegate.h"
25 #include "ui/views/widget/native_widget_aura.h" 26 #include "ui/views/widget/native_widget_aura.h"
26 27
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 MessageLoopForUI* loop = MessageLoopForUI::current(); 90 MessageLoopForUI* loop = MessageLoopForUI::current();
90 MessageLoop::ScopedNestableTaskAllower allow_nested(loop); 91 MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
91 run_loop.Run(); 92 run_loop.Run();
92 } 93 }
93 #endif // !defined(OS_MACOSX) 94 #endif // !defined(OS_MACOSX)
94 95
95 return drag_operation_; 96 return drag_operation_;
96 } 97 }
97 98
98 void DragDropController::DragUpdate(aura::Window* target, 99 void DragDropController::DragUpdate(aura::Window* target,
99 const aura::LocatedEvent& event) { 100 const ui::LocatedEvent& event) {
100 aura::client::DragDropDelegate* delegate = NULL; 101 aura::client::DragDropDelegate* delegate = NULL;
101 if (target != drag_window_) { 102 if (target != drag_window_) {
102 if (drag_window_) { 103 if (drag_window_) {
103 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) 104 if ((delegate = aura::client::GetDragDropDelegate(drag_window_)))
104 delegate->OnDragExited(); 105 delegate->OnDragExited();
105 drag_window_->RemoveObserver(this); 106 drag_window_->RemoveObserver(this);
106 } 107 }
107 drag_window_ = target; 108 drag_window_ = target;
108 drag_window_->AddObserver(this); 109 drag_window_->AddObserver(this);
109 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { 110 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
110 aura::DropTargetEvent e(*drag_data_, 111 ui::DropTargetEvent e(*drag_data_,
111 event.location(), 112 event.location(),
112 event.root_location(), 113 event.root_location(),
113 drag_operation_); 114 drag_operation_);
114 e.set_flags(event.flags()); 115 e.set_flags(event.flags());
115 delegate->OnDragEntered(e); 116 delegate->OnDragEntered(e);
116 } 117 }
117 } else { 118 } else {
118 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) { 119 if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
119 aura::DropTargetEvent e(*drag_data_, 120 ui::DropTargetEvent e(*drag_data_,
120 event.location(), 121 event.location(),
121 event.root_location(), 122 event.root_location(),
122 drag_operation_); 123 drag_operation_);
123 e.set_flags(event.flags()); 124 e.set_flags(event.flags());
124 int op = delegate->OnDragUpdated(e); 125 int op = delegate->OnDragUpdated(e);
125 gfx::NativeCursor cursor = ui::kCursorNoDrop; 126 gfx::NativeCursor cursor = ui::kCursorNoDrop;
126 if (op & ui::DragDropTypes::DRAG_COPY) 127 if (op & ui::DragDropTypes::DRAG_COPY)
127 cursor = ui::kCursorCopy; 128 cursor = ui::kCursorCopy;
128 else if (op & ui::DragDropTypes::DRAG_LINK) 129 else if (op & ui::DragDropTypes::DRAG_LINK)
129 cursor = ui::kCursorAlias; 130 cursor = ui::kCursorAlias;
130 else if (op & ui::DragDropTypes::DRAG_MOVE) 131 else if (op & ui::DragDropTypes::DRAG_MOVE)
131 cursor = ui::kCursorMove; 132 cursor = ui::kCursorMove;
132 drag_cursor_ = cursor; 133 drag_cursor_ = cursor;
133 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); 134 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor);
134 } 135 }
135 } 136 }
136 137
137 DCHECK(drag_image_.get()); 138 DCHECK(drag_image_.get());
138 if (drag_image_->visible()) { 139 if (drag_image_->visible()) {
139 drag_image_->SetScreenPosition( 140 drag_image_->SetScreenPosition(
140 event.root_location().Subtract(drag_image_offset_)); 141 event.root_location().Subtract(drag_image_offset_));
141 } 142 }
142 } 143 }
143 144
144 void DragDropController::Drop(aura::Window* target, 145 void DragDropController::Drop(aura::Window* target,
145 const aura::LocatedEvent& event) { 146 const ui::LocatedEvent& event) {
146 drag_cursor_ = ui::kCursorPointer; 147 drag_cursor_ = ui::kCursorPointer;
147 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); 148 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
148 aura::client::DragDropDelegate* delegate = NULL; 149 aura::client::DragDropDelegate* delegate = NULL;
149 150
150 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit 151 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit
151 // depends on not getting a Drop without DragEnter. This behavior is 152 // depends on not getting a Drop without DragEnter. This behavior is
152 // consistent with drag/drop on other platforms. 153 // consistent with drag/drop on other platforms.
153 if (target != drag_window_) 154 if (target != drag_window_)
154 DragUpdate(target, event); 155 DragUpdate(target, event);
155 DCHECK(target == drag_window_); 156 DCHECK(target == drag_window_);
156 157
157 if ((delegate = aura::client::GetDragDropDelegate(target))) { 158 if ((delegate = aura::client::GetDragDropDelegate(target))) {
158 aura::DropTargetEvent e( 159 ui::DropTargetEvent e(
159 *drag_data_, event.location(), event.root_location(), drag_operation_); 160 *drag_data_, event.location(), event.root_location(), drag_operation_);
160 e.set_flags(event.flags()); 161 e.set_flags(event.flags());
161 drag_operation_ = delegate->OnPerformDrop(e); 162 drag_operation_ = delegate->OnPerformDrop(e);
162 if (drag_operation_ == 0) 163 if (drag_operation_ == 0)
163 StartCanceledAnimation(); 164 StartCanceledAnimation();
164 else 165 else
165 drag_image_.reset(); 166 drag_image_.reset();
166 } else { 167 } else {
167 drag_image_.reset(); 168 drag_image_.reset();
168 } 169 }
(...skipping 24 matching lines...) Expand all
193 194
194 bool DragDropController::IsDragDropInProgress() { 195 bool DragDropController::IsDragDropInProgress() {
195 return drag_drop_in_progress_; 196 return drag_drop_in_progress_;
196 } 197 }
197 198
198 gfx::NativeCursor DragDropController::GetDragCursor() { 199 gfx::NativeCursor DragDropController::GetDragCursor() {
199 return drag_cursor_; 200 return drag_cursor_;
200 } 201 }
201 202
202 bool DragDropController::PreHandleKeyEvent(aura::Window* target, 203 bool DragDropController::PreHandleKeyEvent(aura::Window* target,
203 aura::KeyEvent* event) { 204 ui::KeyEvent* event) {
204 if (drag_drop_in_progress_ && event->key_code() == ui::VKEY_ESCAPE) { 205 if (drag_drop_in_progress_ && event->key_code() == ui::VKEY_ESCAPE) {
205 DragCancel(); 206 DragCancel();
206 return true; 207 return true;
207 } 208 }
208 return false; 209 return false;
209 } 210 }
210 211
211 bool DragDropController::PreHandleMouseEvent(aura::Window* target, 212 bool DragDropController::PreHandleMouseEvent(aura::Window* target,
212 aura::MouseEvent* event) { 213 ui::MouseEvent* event) {
213 if (!drag_drop_in_progress_) 214 if (!drag_drop_in_progress_)
214 return false; 215 return false;
215 switch (event->type()) { 216 switch (event->type()) {
216 case ui::ET_MOUSE_DRAGGED: 217 case ui::ET_MOUSE_DRAGGED:
217 DragUpdate(target, *event); 218 DragUpdate(target, *event);
218 break; 219 break;
219 case ui::ET_MOUSE_RELEASED: 220 case ui::ET_MOUSE_RELEASED:
220 Drop(target, *event); 221 Drop(target, *event);
221 break; 222 break;
222 default: 223 default:
223 // We could reach here if the user drops outside the root window. 224 // We could reach here if the user drops outside the root window.
224 // We could also reach here because RootWindow may sometimes generate a 225 // We could also reach here because RootWindow may sometimes generate a
225 // bunch of fake mouse events 226 // bunch of fake mouse events
226 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange). 227 // (aura::RootWindow::PostMouseMoveEventAfterWindowChange).
227 break; 228 break;
228 } 229 }
229 return true; 230 return true;
230 } 231 }
231 232
232 ui::TouchStatus DragDropController::PreHandleTouchEvent( 233 ui::TouchStatus DragDropController::PreHandleTouchEvent(
233 aura::Window* target, 234 aura::Window* target,
234 aura::TouchEvent* event) { 235 ui::TouchEventImpl* event) {
235 // TODO(sad): Also check for the touch-id. 236 // TODO(sad): Also check for the touch-id.
236 if (!drag_drop_in_progress_) 237 if (!drag_drop_in_progress_)
237 return ui::TOUCH_STATUS_UNKNOWN; 238 return ui::TOUCH_STATUS_UNKNOWN;
238 switch (event->type()) { 239 switch (event->type()) {
239 case ui::ET_TOUCH_MOVED: 240 case ui::ET_TOUCH_MOVED:
240 DragUpdate(target, *event); 241 DragUpdate(target, *event);
241 break; 242 break;
242 case ui::ET_TOUCH_RELEASED: 243 case ui::ET_TOUCH_RELEASED:
243 Drop(target, *event); 244 Drop(target, *event);
244 break; 245 break;
245 case ui::ET_TOUCH_CANCELLED: 246 case ui::ET_TOUCH_CANCELLED:
246 DragCancel(); 247 DragCancel();
247 break; 248 break;
248 default: 249 default:
249 return ui::TOUCH_STATUS_UNKNOWN; 250 return ui::TOUCH_STATUS_UNKNOWN;
250 } 251 }
251 return ui::TOUCH_STATUS_CONTINUE; 252 return ui::TOUCH_STATUS_CONTINUE;
252 } 253 }
253 254
254 ui::GestureStatus DragDropController::PreHandleGestureEvent( 255 ui::GestureStatus DragDropController::PreHandleGestureEvent(
255 aura::Window* target, 256 aura::Window* target,
256 aura::GestureEvent* event) { 257 ui::GestureEventImpl* event) {
257 return ui::GESTURE_STATUS_UNKNOWN; 258 return ui::GESTURE_STATUS_UNKNOWN;
258 } 259 }
259 260
260 void DragDropController::OnWindowDestroyed(aura::Window* window) { 261 void DragDropController::OnWindowDestroyed(aura::Window* window) {
261 if (drag_window_ == window) { 262 if (drag_window_ == window) {
262 drag_window_->RemoveObserver(this); 263 drag_window_->RemoveObserver(this);
263 drag_window_ = NULL; 264 drag_window_ = NULL;
264 } 265 }
265 } 266 }
266 267
(...skipping 27 matching lines...) Expand all
294 void DragDropController::Cleanup() { 295 void DragDropController::Cleanup() {
295 if (drag_window_) 296 if (drag_window_)
296 drag_window_->RemoveObserver(this); 297 drag_window_->RemoveObserver(this);
297 drag_window_ = NULL; 298 drag_window_ = NULL;
298 drag_data_ = NULL; 299 drag_data_ = NULL;
299 drag_drop_in_progress_ = false; 300 drag_drop_in_progress_ = false;
300 } 301 }
301 302
302 } // namespace internal 303 } // namespace internal
303 } // namespace ash 304 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698