Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_tracker.h" | 5 #include "ash/drag_drop/drag_drop_tracker.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/coordinate_conversion.h" | 9 #include "ash/wm/coordinate_conversion.h" |
| 10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
| 11 #include "ui/base/events/event.h" | 11 #include "ui/base/events/event.h" |
| 12 #include "ui/gfx/screen.h" | 12 #include "ui/gfx/screen.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Creates a window for capturing drag events. | 16 // Creates a window for capturing drag events. |
| 17 aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) { | 17 aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) { |
| 18 aura::Window* window = new aura::Window(NULL); | 18 aura::Window* window = new aura::Window(NULL); |
| 19 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 19 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
| 20 window->Init(ui::LAYER_NOT_DRAWN); | 20 window->Init(ui::LAYER_NOT_DRAWN); |
| 21 window->SetParent(NULL); | 21 window->SetParent(NULL); |
| 22 window->SetBoundsInScreen(root_window->GetBoundsInScreen(), | 22 window->SetBoundsInScreen(root_window->GetBoundsInScreen(), |
| 23 gfx::Screen::GetDisplayNearestWindow(root_window)); | 23 gfx::Screen::GetDisplayNearestWindow(root_window)); |
| 24 window->Show(); | 24 window->Show(); |
| 25 return window; | 25 return window; |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Returns the root window at |location| in |window|'s coordinate. | |
| 29 aura::RootWindow* GetRootWindowAt(aura::Window* window, | |
| 30 const gfx::Point& location) { | |
| 31 gfx::Point location_in_screen = location; | |
| 32 ash::wm::ConvertPointToScreen(window, &location_in_screen); | |
| 33 return ash::wm::GetRootWindowAt(location_in_screen); | |
|
oshima
2012/09/18 23:10:15
I'd prefer this to be different name than GetRootW
mazda
2012/09/18 23:44:57
Removed the function.
| |
| 34 } | |
| 35 | |
| 28 } // namespace | 36 } // namespace |
| 29 | 37 |
| 30 namespace ash { | 38 namespace ash { |
| 31 namespace internal { | 39 namespace internal { |
| 32 | 40 |
| 33 DragDropTracker::DragDropTracker(aura::RootWindow* root_window) | 41 DragDropTracker::DragDropTracker(aura::RootWindow* root_window) |
| 34 : capture_window_(CreateCaptureWindow(root_window)) { | 42 : capture_window_(CreateCaptureWindow(root_window)) { |
| 35 capture_window_->SetCapture(); | 43 capture_window_->SetCapture(); |
| 36 } | 44 } |
| 37 | 45 |
| 38 DragDropTracker::~DragDropTracker() { | 46 DragDropTracker::~DragDropTracker() { |
| 39 capture_window_->ReleaseCapture(); | 47 capture_window_->ReleaseCapture(); |
| 40 } | 48 } |
| 41 | 49 |
| 42 aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { | 50 aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { |
| 43 std::pair<aura::RootWindow*, gfx::Point> pair = | 51 DCHECK(capture_window_.get()); |
| 44 ash::wm::GetRootWindowRelativeToWindow(capture_window_.get(), | 52 gfx::Point location_in_screen = event.location(); |
| 45 event.location()); | 53 wm::ConvertPointToScreen(capture_window_.get(), |
| 46 return pair.first->GetEventHandlerForPoint(pair.second); | 54 &location_in_screen); |
| 55 aura::RootWindow* root_window_at_point = | |
| 56 wm::GetRootWindowAt(location_in_screen); | |
| 57 gfx::Point location_in_root = location_in_screen; | |
| 58 wm::ConvertPointFromScreen(root_window_at_point, &location_in_root); | |
| 59 return root_window_at_point->GetEventHandlerForPoint(location_in_root); | |
| 47 } | 60 } |
| 48 | 61 |
| 49 ui::MouseEvent* DragDropTracker::ConvertMouseEvent( | 62 ui::MouseEvent* DragDropTracker::ConvertMouseEvent( |
| 50 aura::Window* target, | 63 aura::Window* target, |
| 51 const ui::MouseEvent& event) { | 64 const ui::MouseEvent& event) { |
| 52 DCHECK(capture_window_.get()); | 65 DCHECK(capture_window_.get()); |
| 53 std::pair<aura::RootWindow*, gfx::Point> location_pair = | 66 gfx::Point target_location = event.location(); |
| 54 ash::wm::GetRootWindowRelativeToWindow(capture_window_.get(), | 67 aura::Window::ConvertPointToTarget(capture_window_.get(), target, |
| 55 event.location()); | 68 &target_location); |
| 56 aura::Window::ConvertPointToTarget(location_pair.first, target, | 69 gfx::Point target_root_location = event.root_location(); |
| 57 &location_pair.second); | 70 aura::Window::ConvertPointToTarget(capture_window_->GetRootWindow(), |
| 58 std::pair<aura::RootWindow*, gfx::Point> root_location_pair = | 71 GetRootWindowAt(capture_window_.get(), |
| 59 ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), | 72 event.location()), |
| 60 event.root_location()); | 73 &target_root_location); |
| 61 return new ui::MouseEvent(event.type(), | 74 return new ui::MouseEvent(event.type(), |
| 62 location_pair.second, | 75 target_location, |
| 63 root_location_pair.second, | 76 target_root_location, |
| 64 event.flags()); | 77 event.flags()); |
| 65 } | 78 } |
| 66 | 79 |
| 67 } // namespace internal | 80 } // namespace internal |
| 68 } // namespace ash | 81 } // namespace ash |
| OLD | NEW |