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/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
8 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
9 #include "ash/common/wm/root_window_finder.h" | 9 #include "ash/common/wm/root_window_finder.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 class CaptureWindowActivationDelegate | 23 class CaptureWindowActivationDelegate |
24 : public aura::client::ActivationDelegate { | 24 : public aura::client::ActivationDelegate { |
25 public: | 25 public: |
26 CaptureWindowActivationDelegate() {} | 26 CaptureWindowActivationDelegate() {} |
27 ~CaptureWindowActivationDelegate() override {} | 27 ~CaptureWindowActivationDelegate() override {} |
28 | 28 |
29 // aura::client::ActivationDelegate overrides: | 29 // aura::client::ActivationDelegate overrides: |
30 bool ShouldActivate() const override { return false; } | 30 bool ShouldActivate() const override { return false; } |
31 | 31 |
32 private: | 32 private: |
33 | |
34 DISALLOW_COPY_AND_ASSIGN(CaptureWindowActivationDelegate); | 33 DISALLOW_COPY_AND_ASSIGN(CaptureWindowActivationDelegate); |
35 }; | 34 }; |
36 | 35 |
37 // Creates a window for capturing drag events. | 36 // Creates a window for capturing drag events. |
38 aura::Window* CreateCaptureWindow(aura::Window* context_root, | 37 aura::Window* CreateCaptureWindow(aura::Window* context_root, |
39 aura::WindowDelegate* delegate) { | 38 aura::WindowDelegate* delegate) { |
40 static CaptureWindowActivationDelegate* activation_delegate_instance = NULL; | 39 static CaptureWindowActivationDelegate* activation_delegate_instance = NULL; |
41 if (!activation_delegate_instance) | 40 if (!activation_delegate_instance) |
42 activation_delegate_instance = new CaptureWindowActivationDelegate; | 41 activation_delegate_instance = new CaptureWindowActivationDelegate; |
43 aura::Window* window = new aura::Window(delegate); | 42 aura::Window* window = new aura::Window(delegate); |
44 // Set type of window as popup to prevent different window manager codes | 43 // Set type of window as popup to prevent different window manager codes |
45 // trying to manage this window. | 44 // trying to manage this window. |
46 window->SetType(ui::wm::WINDOW_TYPE_POPUP); | 45 window->SetType(ui::wm::WINDOW_TYPE_POPUP); |
47 window->Init(ui::LAYER_NOT_DRAWN); | 46 window->Init(ui::LAYER_NOT_DRAWN); |
48 aura::client::ParentWindowWithContext(window, context_root, gfx::Rect()); | 47 aura::client::ParentWindowWithContext(window, context_root, gfx::Rect()); |
49 aura::client::SetActivationDelegate(window, activation_delegate_instance); | 48 aura::client::SetActivationDelegate(window, activation_delegate_instance); |
50 window->Show(); | 49 window->Show(); |
51 DCHECK(window->bounds().size().IsEmpty()); | 50 DCHECK(window->bounds().size().IsEmpty()); |
52 return window; | 51 return window; |
53 } | 52 } |
54 | 53 |
55 } // namespace | 54 } // namespace |
56 | 55 |
57 DragDropTracker::DragDropTracker(aura::Window* context_root, | 56 DragDropTracker::DragDropTracker(aura::Window* context_root, |
58 aura::WindowDelegate* delegate) | 57 aura::WindowDelegate* delegate) |
59 : capture_window_(CreateCaptureWindow(context_root, delegate)) { | 58 : capture_window_(CreateCaptureWindow(context_root, delegate)) {} |
60 } | |
61 | 59 |
62 DragDropTracker::~DragDropTracker() { | 60 DragDropTracker::~DragDropTracker() { |
63 capture_window_->ReleaseCapture(); | 61 capture_window_->ReleaseCapture(); |
64 } | 62 } |
65 | 63 |
66 void DragDropTracker::TakeCapture() { | 64 void DragDropTracker::TakeCapture() { |
67 capture_window_->SetCapture(); | 65 capture_window_->SetCapture(); |
68 } | 66 } |
69 | 67 |
70 aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { | 68 aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { |
71 DCHECK(capture_window_.get()); | 69 DCHECK(capture_window_.get()); |
72 gfx::Point location_in_screen = event.location(); | 70 gfx::Point location_in_screen = event.location(); |
73 ::wm::ConvertPointToScreen(capture_window_.get(), &location_in_screen); | 71 ::wm::ConvertPointToScreen(capture_window_.get(), &location_in_screen); |
74 aura::Window* root_window_at_point = | 72 aura::Window* root_window_at_point = |
75 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(location_in_screen)); | 73 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(location_in_screen)); |
76 gfx::Point location_in_root = location_in_screen; | 74 gfx::Point location_in_root = location_in_screen; |
77 ::wm::ConvertPointFromScreen(root_window_at_point, &location_in_root); | 75 ::wm::ConvertPointFromScreen(root_window_at_point, &location_in_root); |
78 return root_window_at_point->GetEventHandlerForPoint(location_in_root); | 76 return root_window_at_point->GetEventHandlerForPoint(location_in_root); |
79 } | 77 } |
80 | 78 |
81 ui::LocatedEvent* DragDropTracker::ConvertEvent( | 79 ui::LocatedEvent* DragDropTracker::ConvertEvent(aura::Window* target, |
82 aura::Window* target, | 80 const ui::LocatedEvent& event) { |
83 const ui::LocatedEvent& event) { | |
84 DCHECK(capture_window_.get()); | 81 DCHECK(capture_window_.get()); |
85 gfx::Point target_location = event.location(); | 82 gfx::Point target_location = event.location(); |
86 aura::Window::ConvertPointToTarget(capture_window_.get(), target, | 83 aura::Window::ConvertPointToTarget(capture_window_.get(), target, |
87 &target_location); | 84 &target_location); |
88 gfx::Point location_in_screen = event.location(); | 85 gfx::Point location_in_screen = event.location(); |
89 ::wm::ConvertPointToScreen(capture_window_.get(), &location_in_screen); | 86 ::wm::ConvertPointToScreen(capture_window_.get(), &location_in_screen); |
90 gfx::Point target_root_location = event.root_location(); | 87 gfx::Point target_root_location = event.root_location(); |
91 aura::Window::ConvertPointToTarget( | 88 aura::Window::ConvertPointToTarget( |
92 capture_window_->GetRootWindow(), | 89 capture_window_->GetRootWindow(), |
93 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(location_in_screen)), | 90 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(location_in_screen)), |
94 &target_root_location); | 91 &target_root_location); |
95 return new ui::MouseEvent( | 92 return new ui::MouseEvent( |
96 event.type(), target_location, target_root_location, | 93 event.type(), target_location, target_root_location, |
97 ui::EventTimeForNow(), event.flags(), | 94 ui::EventTimeForNow(), event.flags(), |
98 static_cast<const ui::MouseEvent&>(event).changed_button_flags()); | 95 static_cast<const ui::MouseEvent&>(event).changed_button_flags()); |
99 } | 96 } |
100 | 97 |
101 } // namespace ash | 98 } // namespace ash |
OLD | NEW |