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 | |
13 namespace { | |
14 | |
15 // Creates a window for capturing drag events. | |
16 aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) { | |
17 aura::Window* window = new aura::Window(NULL); | |
18 window->Init(ui::LAYER_NOT_DRAWN); | |
19 aura::Window* default_container = | |
20 ash::Shell::GetContainer(root_window, | |
21 ash::internal::kShellWindowId_DefaultContainer); | |
22 default_container->AddChild(window); | |
sky
2012/08/20 15:35:18
Doesn't SetParent(NULL) do what you want instead o
mazda
2012/08/21 02:10:59
Yes, it does with some setups. I changed the code
| |
23 window->Show(); | |
24 return window; | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 namespace ash { | |
30 namespace internal { | |
31 | |
32 DragDropTracker::DragDropTracker() | |
33 : capture_window_(NULL) { | |
34 } | |
35 | |
36 DragDropTracker::~DragDropTracker() { | |
37 StopTracking(); | |
38 } | |
39 | |
40 void DragDropTracker::StartTracking(aura::RootWindow* root_window) { | |
41 StopTracking(); | |
42 capture_window_ = CreateCaptureWindow(root_window); | |
43 capture_window_->SetCapture(); | |
44 } | |
45 | |
46 void DragDropTracker::StopTracking() { | |
47 if (capture_window_) { | |
48 capture_window_->ReleaseCapture(); | |
49 delete capture_window_; | |
50 } | |
51 capture_window_ = NULL; | |
52 } | |
53 | |
54 aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { | |
55 std::pair<aura::RootWindow*, gfx::Point> pair = | |
56 ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), | |
57 event.location()); | |
58 return pair.first->GetEventHandlerForPoint(pair.second); | |
59 } | |
60 | |
61 ui::MouseEvent* DragDropTracker::ConvertMouseEvent( | |
62 aura::Window* target, | |
63 const ui::MouseEvent& event) { | |
64 DCHECK(capture_window_); | |
65 std::pair<aura::RootWindow*, gfx::Point> location_pair = | |
66 ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), | |
67 event.location()); | |
68 aura::Window::ConvertPointToTarget(location_pair.first, target, | |
69 &location_pair.second); | |
70 std::pair<aura::RootWindow*, gfx::Point> root_location_pair = | |
71 ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), | |
72 event.root_location()); | |
73 return new ui::MouseEvent(event.type(), | |
74 location_pair.second, | |
75 root_location_pair.second, | |
76 event.flags()); | |
77 } | |
78 | |
79 } // namespace internal | |
80 } // namespace ash | |
OLD | NEW |