Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/drag_drop/drag_drop_tracker.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_window_ids.h" | |
| 9 #include "ash/wm/coordinate_conversion.h" | |
| 10 #include "ui/aura/root_window.h" | |
| 11 #include "ui/base/event.h" | |
| 12 #include "ui/gfx/screen.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Creates a window for capturing drag events. | |
| 17 aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) { | |
| 18 aura::Window* window = new aura::Window(NULL); | |
| 19 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
| 20 window->Init(ui::LAYER_NOT_DRAWN); | |
| 21 window->SetParent(NULL); | |
| 22 window->SetBoundsInScreen(root_window->GetBoundsInScreen(), | |
| 23 gfx::Screen::GetDisplayNearestWindow(root_window)); | |
| 24 window->Show(); | |
| 25 return window; | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 namespace ash { | |
| 31 namespace internal { | |
| 32 | |
| 33 DragDropTracker::DragDropTracker(aura::RootWindow* root_window) | |
| 34 : capture_window_(CreateCaptureWindow(root_window)) { | |
| 35 capture_window_->SetCapture(); | |
|
varunjain
2012/08/21 04:37:26
Do you also need to listen to OnWindowDestroying o
mazda
2012/08/24 08:29:01
I don't think it's necessary to listen to OnWindow
| |
| 36 } | |
| 37 | |
| 38 DragDropTracker::~DragDropTracker() { | |
| 39 capture_window_->ReleaseCapture(); | |
| 40 } | |
| 41 | |
| 42 aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { | |
| 43 std::pair<aura::RootWindow*, gfx::Point> pair = | |
| 44 ash::wm::GetRootWindowRelativeToWindow(capture_window_.get(), | |
| 45 event.location()); | |
| 46 return pair.first->GetEventHandlerForPoint(pair.second); | |
| 47 } | |
| 48 | |
| 49 ui::MouseEvent* DragDropTracker::ConvertMouseEvent( | |
| 50 aura::Window* target, | |
| 51 const ui::MouseEvent& event) { | |
| 52 DCHECK(capture_window_.get()); | |
| 53 std::pair<aura::RootWindow*, gfx::Point> location_pair = | |
| 54 ash::wm::GetRootWindowRelativeToWindow(capture_window_.get(), | |
| 55 event.location()); | |
| 56 aura::Window::ConvertPointToTarget(location_pair.first, target, | |
| 57 &location_pair.second); | |
| 58 std::pair<aura::RootWindow*, gfx::Point> root_location_pair = | |
| 59 ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), | |
| 60 event.root_location()); | |
| 61 return new ui::MouseEvent(event.type(), | |
| 62 location_pair.second, | |
| 63 root_location_pair.second, | |
| 64 event.flags()); | |
| 65 } | |
| 66 | |
| 67 } // namespace internal | |
| 68 } // namespace ash | |
| OLD | NEW |