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

Side by Side Diff: ui/aura/desktop.cc

Issue 8450018: First shot at implementing drag&drop for Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor changes Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/aura/desktop.h" 5 #include "ui/aura/desktop.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "ui/aura/aura_switches.h" 16 #include "ui/aura/aura_switches.h"
17 #include "ui/aura/desktop_delegate.h" 17 #include "ui/aura/desktop_delegate.h"
18 #include "ui/aura/desktop_host.h" 18 #include "ui/aura/desktop_host.h"
19 #include "ui/aura/desktop_observer.h" 19 #include "ui/aura/desktop_observer.h"
20 #include "ui/aura/drag_drop_controller.h"
20 #include "ui/aura/event.h" 21 #include "ui/aura/event.h"
21 #include "ui/aura/event_filter.h" 22 #include "ui/aura/event_filter.h"
22 #include "ui/aura/focus_manager.h" 23 #include "ui/aura/focus_manager.h"
23 #include "ui/aura/screen_aura.h" 24 #include "ui/aura/screen_aura.h"
24 #include "ui/aura/screen_rotation.h" 25 #include "ui/aura/screen_rotation.h"
25 #include "ui/aura/toplevel_window_container.h" 26 #include "ui/aura/toplevel_window_container.h"
26 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
27 #include "ui/aura/window_delegate.h" 28 #include "ui/aura/window_delegate.h"
28 #include "ui/gfx/compositor/compositor.h" 29 #include "ui/gfx/compositor/compositor.h"
29 #include "ui/gfx/compositor/layer.h" 30 #include "ui/gfx/compositor/layer.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 for (i = desktop_->children().rbegin(); 76 for (i = desktop_->children().rbegin();
76 i != desktop_->children().rend(); 77 i != desktop_->children().rend();
77 ++i) { 78 ++i) {
78 if (*i == ignore) 79 if (*i == ignore)
79 continue; 80 continue;
80 return *i; 81 return *i;
81 } 82 }
82 return NULL; 83 return NULL;
83 } 84 }
84 85
86 virtual DragDropController* GetDragDropController() const OVERRIDE {
87 return NULL;
88 }
89
85 Desktop* desktop_; 90 Desktop* desktop_;
86 91
87 DISALLOW_COPY_AND_ASSIGN(DefaultDesktopDelegate); 92 DISALLOW_COPY_AND_ASSIGN(DefaultDesktopDelegate);
88 }; 93 };
89 94
90 class DesktopEventFilter : public EventFilter { 95 class DesktopEventFilter : public EventFilter {
91 public: 96 public:
92 explicit DesktopEventFilter(Window* owner) : EventFilter(owner) {} 97 explicit DesktopEventFilter(Window* owner) : EventFilter(owner) {}
93 virtual ~DesktopEventFilter() {} 98 virtual ~DesktopEventFilter() {}
94 99
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 ALLOW_THIS_IN_INITIALIZER_LIST( 219 ALLOW_THIS_IN_INITIALIZER_LIST(
215 delegate_(new DefaultDesktopDelegate(this))), 220 delegate_(new DefaultDesktopDelegate(this))),
216 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), 221 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)),
217 active_window_(NULL), 222 active_window_(NULL),
218 in_destructor_(false), 223 in_destructor_(false),
219 screen_(new ScreenAura), 224 screen_(new ScreenAura),
220 capture_window_(NULL), 225 capture_window_(NULL),
221 mouse_pressed_handler_(NULL), 226 mouse_pressed_handler_(NULL),
222 mouse_moved_handler_(NULL), 227 mouse_moved_handler_(NULL),
223 focused_window_(NULL), 228 focused_window_(NULL),
224 touch_event_handler_(NULL) { 229 touch_event_handler_(NULL),
230 drag_drop_in_progress_(false) {
225 set_name("RootWindow"); 231 set_name("RootWindow");
226 gfx::Screen::SetInstance(screen_); 232 gfx::Screen::SetInstance(screen_);
227 host_->SetDesktop(this); 233 host_->SetDesktop(this);
228 last_mouse_location_ = host_->QueryMouseLocation(); 234 last_mouse_location_ = host_->QueryMouseLocation();
229 SetEventFilter(new DesktopEventFilter(this)); 235 SetEventFilter(new DesktopEventFilter(this));
230 236
231 if (ui::Compositor::compositor_factory()) { 237 if (ui::Compositor::compositor_factory()) {
232 compositor_ = (*ui::Compositor::compositor_factory())(this); 238 compositor_ = (*ui::Compositor::compositor_factory())(this);
233 } else { 239 } else {
234 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), 240 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 295
290 void Desktop::Draw() { 296 void Desktop::Draw() {
291 compositor_->Draw(false); 297 compositor_->Draw(false);
292 } 298 }
293 299
294 bool Desktop::DispatchMouseEvent(MouseEvent* event) { 300 bool Desktop::DispatchMouseEvent(MouseEvent* event) {
295 event->UpdateForTransform(layer()->transform()); 301 event->UpdateForTransform(layer()->transform());
296 302
297 last_mouse_location_ = event->location(); 303 last_mouse_location_ = event->location();
298 304
305 if (drag_drop_in_progress_) {
306 DCHECK(delegate_->GetDragDropController());
307 switch (event->type()) {
308 case ui::ET_MOUSE_DRAGGED:
309 delegate_->GetDragDropController()->DragUpdate(*event);
310 break;
311 case ui::ET_MOUSE_RELEASED:
312 delegate_->GetDragDropController()->Drop(*event);
313 case ui::ET_MOUSE_EXITED:
314 drag_drop_in_progress_ = false;
315 MessageLoop::current()->Quit();
316 break;
317 default:
318 NOTREACHED();
319 break;
320 }
321 return true;
322 }
323
299 Window* target = 324 Window* target =
300 mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_; 325 mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_;
301 if (!target) 326 if (!target)
302 target = GetEventHandlerForPoint(event->location()); 327 target = GetEventHandlerForPoint(event->location());
303 switch (event->type()) { 328 switch (event->type()) {
304 case ui::ET_MOUSE_MOVED: 329 case ui::ET_MOUSE_MOVED:
305 HandleMouseMoved(*event, target); 330 HandleMouseMoved(*event, target);
306 break; 331 break;
307 case ui::ET_MOUSE_PRESSED: 332 case ui::ET_MOUSE_PRESSED:
308 if (!mouse_pressed_handler_) 333 if (!mouse_pressed_handler_)
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 511
487 void Desktop::SetTransform(const ui::Transform& transform) { 512 void Desktop::SetTransform(const ui::Transform& transform) {
488 Window::SetTransform(transform); 513 Window::SetTransform(transform);
489 514
490 // If the layer is not animating, then we need to update the host size 515 // If the layer is not animating, then we need to update the host size
491 // immediately. 516 // immediately.
492 if (!layer()->GetAnimator()->is_animating()) 517 if (!layer()->GetAnimator()->is_animating())
493 OnHostResized(host_->GetSize()); 518 OnHostResized(host_->GetSize());
494 } 519 }
495 520
521 void Desktop::StartDragAndDrop(const ui::OSExchangeData& data, int operation) {
522 if (delegate_->GetDragDropController() && !drag_drop_in_progress_) {
523 if (capture_window_)
524 ReleaseCapture(capture_window_);
525 delegate_->GetDragDropController()->StartDragAndDrop(data, operation,
526 last_mouse_location_);
527 drag_drop_in_progress_ = true;
528 MessageLoopForUI::current()->RunWithDispatcher(host_.get());
529 }
530 }
531
496 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { 532 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) {
497 if (target == mouse_moved_handler_) 533 if (target == mouse_moved_handler_)
498 return; 534 return;
499 535
500 // Send an exited event. 536 // Send an exited event.
501 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { 537 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) {
502 MouseEvent translated_event(event, this, mouse_moved_handler_, 538 MouseEvent translated_event(event, this, mouse_moved_handler_,
503 ui::ET_MOUSE_EXITED); 539 ui::ET_MOUSE_EXITED);
504 ProcessMouseEvent(mouse_moved_handler_, &translated_event); 540 ProcessMouseEvent(mouse_moved_handler_, &translated_event);
505 } 541 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { 668 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) {
633 bounds.set_size(gfx::Size(parsed_width, parsed_height)); 669 bounds.set_size(gfx::Size(parsed_width, parsed_height));
634 } else if (use_fullscreen_host_window_) { 670 } else if (use_fullscreen_host_window_) {
635 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); 671 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize());
636 } 672 }
637 673
638 return bounds; 674 return bounds;
639 } 675 }
640 676
641 } // namespace aura 677 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698