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

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

Issue 10919135: Move ash specific cursor code to CursorManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
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_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
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; 65 SetDragCursor(ui::kCursorPointer);
66 drag_drop_tracker_.reset(new DragDropTracker(root_window)); 66 drag_drop_tracker_.reset(new DragDropTracker(root_window));
67 67
68 drag_data_ = &data; 68 drag_data_ = &data;
69 drag_operation_ = operation; 69 drag_operation_ = operation;
70 const ui::OSExchangeDataProviderAura& provider = 70 const ui::OSExchangeDataProviderAura& provider =
71 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider()); 71 static_cast<const ui::OSExchangeDataProviderAura&>(data.provider());
72 72
73 drag_image_.reset(new DragImageView); 73 drag_image_.reset(new DragImageView);
74 drag_image_->SetImage(provider.drag_image()); 74 drag_image_->SetImage(provider.drag_image());
75 drag_image_offset_ = provider.drag_image_offset(); 75 drag_image_offset_ = provider.drag_image_offset();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 drag_operation_); 121 drag_operation_);
122 e.set_flags(event.flags()); 122 e.set_flags(event.flags());
123 int op = delegate->OnDragUpdated(e); 123 int op = delegate->OnDragUpdated(e);
124 gfx::NativeCursor cursor = ui::kCursorNoDrop; 124 gfx::NativeCursor cursor = ui::kCursorNoDrop;
125 if (op & ui::DragDropTypes::DRAG_COPY) 125 if (op & ui::DragDropTypes::DRAG_COPY)
126 cursor = ui::kCursorCopy; 126 cursor = ui::kCursorCopy;
127 else if (op & ui::DragDropTypes::DRAG_LINK) 127 else if (op & ui::DragDropTypes::DRAG_LINK)
128 cursor = ui::kCursorAlias; 128 cursor = ui::kCursorAlias;
129 else if (op & ui::DragDropTypes::DRAG_MOVE) 129 else if (op & ui::DragDropTypes::DRAG_MOVE)
130 cursor = ui::kCursorMove; 130 cursor = ui::kCursorMove;
131 drag_cursor_ = cursor; 131 SetDragCursor(cursor);
132 ash::Shell::GetInstance()->cursor_manager()->SetCursor(cursor); 132 ash::Shell::GetInstance()->cursor_manager()->SetCursor(drag_cursor_);
133 } 133 }
134 } 134 }
135 135
136 DCHECK(drag_image_.get()); 136 DCHECK(drag_image_.get());
137 if (drag_image_->visible()) { 137 if (drag_image_->visible()) {
138 gfx::Point root_location_in_screen = event.root_location(); 138 gfx::Point root_location_in_screen = event.root_location();
139 ash::wm::ConvertPointToScreen(target->GetRootWindow(), 139 ash::wm::ConvertPointToScreen(target->GetRootWindow(),
140 &root_location_in_screen); 140 &root_location_in_screen);
141 drag_image_->SetScreenPosition( 141 drag_image_->SetScreenPosition(
142 root_location_in_screen.Subtract(drag_image_offset_)); 142 root_location_in_screen.Subtract(drag_image_offset_));
143 } 143 }
144 } 144 }
145 145
146 void DragDropController::Drop(aura::Window* target, 146 void DragDropController::Drop(aura::Window* target,
147 const ui::LocatedEvent& event) { 147 const ui::LocatedEvent& event) {
148 drag_cursor_ = ui::kCursorPointer; 148 SetDragCursor(ui::kCursorPointer);
149 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); 149 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
150 aura::client::DragDropDelegate* delegate = NULL; 150 aura::client::DragDropDelegate* delegate = NULL;
151 151
152 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit 152 // We must guarantee that a target gets a OnDragEntered before Drop. WebKit
153 // depends on not getting a Drop without DragEnter. This behavior is 153 // depends on not getting a Drop without DragEnter. This behavior is
154 // consistent with drag/drop on other platforms. 154 // consistent with drag/drop on other platforms.
155 if (target != drag_window_) 155 if (target != drag_window_)
156 DragUpdate(target, event); 156 DragUpdate(target, event);
157 DCHECK(target == drag_window_); 157 DCHECK(target == drag_window_);
158 158
159 if ((delegate = aura::client::GetDragDropDelegate(target))) { 159 if ((delegate = aura::client::GetDragDropDelegate(target))) {
160 ui::DropTargetEvent e( 160 ui::DropTargetEvent e(
161 *drag_data_, event.location(), event.root_location(), drag_operation_); 161 *drag_data_, event.location(), event.root_location(), drag_operation_);
162 e.set_flags(event.flags()); 162 e.set_flags(event.flags());
163 drag_operation_ = delegate->OnPerformDrop(e); 163 drag_operation_ = delegate->OnPerformDrop(e);
164 if (drag_operation_ == 0) 164 if (drag_operation_ == 0)
165 StartCanceledAnimation(); 165 StartCanceledAnimation();
166 else 166 else
167 drag_image_.reset(); 167 drag_image_.reset();
168 } else { 168 } else {
169 drag_image_.reset(); 169 drag_image_.reset();
170 } 170 }
171 171
172 Cleanup(); 172 Cleanup();
173 if (should_block_during_drag_drop_) 173 if (should_block_during_drag_drop_)
174 quit_closure_.Run(); 174 quit_closure_.Run();
175 } 175 }
176 176
177 void DragDropController::DragCancel() { 177 void DragDropController::DragCancel() {
178 drag_cursor_ = ui::kCursorPointer; 178 SetDragCursor(ui::kCursorPointer);
Daniel Erat 2012/09/06 23:47:15 Can SetDragCursor() just call ash::Shell::GetInsta
mazda 2012/09/07 02:20:57 It turned out that we don't need to set drag_curso
179 ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer); 179 ash::Shell::GetInstance()->cursor_manager()->SetCursor(drag_cursor_);
180 180
181 // |drag_window_| can be NULL if we have just started the drag and have not 181 // |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 182 // received any DragUpdates, or, if the |drag_window_| gets destroyed during
183 // a drag/drop. 183 // a drag/drop.
184 aura::client::DragDropDelegate* delegate = drag_window_? 184 aura::client::DragDropDelegate* delegate = drag_window_?
185 aura::client::GetDragDropDelegate(drag_window_) : NULL; 185 aura::client::GetDragDropDelegate(drag_window_) : NULL;
186 if (delegate) 186 if (delegate)
187 delegate->OnDragExited(); 187 delegate->OnDragExited();
188 188
189 Cleanup(); 189 Cleanup();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void DragDropController::Cleanup() { 304 void DragDropController::Cleanup() {
305 if (drag_window_) 305 if (drag_window_)
306 drag_window_->RemoveObserver(this); 306 drag_window_->RemoveObserver(this);
307 drag_window_ = NULL; 307 drag_window_ = NULL;
308 drag_data_ = NULL; 308 drag_data_ = NULL;
309 // Cleanup can be called again while deleting DragDropTracker, so use Pass 309 // Cleanup can be called again while deleting DragDropTracker, so use Pass
310 // instead of reset to avoid double free. 310 // instead of reset to avoid double free.
311 drag_drop_tracker_.Pass(); 311 drag_drop_tracker_.Pass();
312 } 312 }
313 313
314 void DragDropController::SetDragCursor(gfx::NativeCursor cursor) {
315 drag_cursor_ = ash::Shell::GetInstance()->cursor_manager()->
316 GetCursorFromNativeType(cursor);
317 }
318
314 } // namespace internal 319 } // namespace internal
315 } // namespace ash 320 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/shell.cc » ('j') | ash/shell.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698