OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/aura/wm_window_aura.h" | 5 #include "ash/aura/wm_window_aura.h" |
6 #include "ash/common/wm/root_window_finder.h" | 6 #include "ash/common/wm/root_window_finder.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_factory.h" | 8 #include "ash/shell_factory.h" |
9 #include "ash/wm/window_properties.h" | 9 #include "ash/wm/window_properties.h" |
10 #include "ui/aura/client/capture_client.h" | 10 #include "ui/aura/client/capture_client.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 using ui_controls::UIControlsAura; | 26 using ui_controls::UIControlsAura; |
27 using ui_controls::MouseButton; | 27 using ui_controls::MouseButton; |
28 | 28 |
29 DEFINE_OWNED_WINDOW_PROPERTY_KEY(UIControlsAura, kUIControlsKey, NULL); | 29 DEFINE_OWNED_WINDOW_PROPERTY_KEY(UIControlsAura, kUIControlsKey, NULL); |
30 | 30 |
31 // Returns the UIControls object for RootWindow. | 31 // Returns the UIControls object for RootWindow. |
32 // kUIControlsKey is owned property and UIControls object | 32 // kUIControlsKey is owned property and UIControls object |
33 // will be deleted when the root window is deleted. | 33 // will be deleted when the root window is deleted. |
34 UIControlsAura* GetUIControlsForRootWindow(aura::Window* root_window) { | 34 UIControlsAura* GetUIControlsForRootWindow(aura::Window* root_window) { |
35 UIControlsAura* native_ui_control = | 35 UIControlsAura* native_ui_control = root_window->GetProperty(kUIControlsKey); |
36 root_window->GetProperty(kUIControlsKey); | |
37 if (!native_ui_control) { | 36 if (!native_ui_control) { |
38 native_ui_control = | 37 native_ui_control = |
39 aura::test::CreateUIControlsAura(root_window->GetHost()); | 38 aura::test::CreateUIControlsAura(root_window->GetHost()); |
40 // Pass the ownership to the |root_window|. | 39 // Pass the ownership to the |root_window|. |
41 root_window->SetProperty(kUIControlsKey, native_ui_control); | 40 root_window->SetProperty(kUIControlsKey, native_ui_control); |
42 } | 41 } |
43 return native_ui_control; | 42 return native_ui_control; |
44 } | 43 } |
45 | 44 |
46 // Returns the UIControls object for the RootWindow at |point_in_screen|. | 45 // Returns the UIControls object for the RootWindow at |point_in_screen|. |
47 UIControlsAura* GetUIControlsAt(const gfx::Point& point_in_screen) { | 46 UIControlsAura* GetUIControlsAt(const gfx::Point& point_in_screen) { |
48 // TODO(mazda): Support the case passive grab is taken. | 47 // TODO(mazda): Support the case passive grab is taken. |
49 return GetUIControlsForRootWindow( | 48 return GetUIControlsForRootWindow( |
50 WmWindowAura::GetAuraWindow(ash::wm::GetRootWindowAt(point_in_screen))); | 49 WmWindowAura::GetAuraWindow(ash::wm::GetRootWindowAt(point_in_screen))); |
51 } | 50 } |
52 | 51 |
53 } // namespace | 52 } // namespace |
54 | 53 |
55 class UIControlsAsh : public UIControlsAura { | 54 class UIControlsAsh : public UIControlsAura { |
56 public: | 55 public: |
57 UIControlsAsh() { | 56 UIControlsAsh() {} |
58 } | |
59 ~UIControlsAsh() override {} | 57 ~UIControlsAsh() override {} |
60 | 58 |
61 // UIControslAura overrides: | 59 // UIControslAura overrides: |
62 bool SendKeyPress(gfx::NativeWindow window, | 60 bool SendKeyPress(gfx::NativeWindow window, |
63 ui::KeyboardCode key, | 61 ui::KeyboardCode key, |
64 bool control, | 62 bool control, |
65 bool shift, | 63 bool shift, |
66 bool alt, | 64 bool alt, |
67 bool command) override { | 65 bool command) override { |
68 return SendKeyPressNotifyWhenDone( | 66 return SendKeyPressNotifyWhenDone(window, key, control, shift, alt, command, |
69 window, key, control, shift, alt, command, base::Closure()); | 67 base::Closure()); |
70 } | 68 } |
71 | 69 |
72 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | 70 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
73 ui::KeyboardCode key, | 71 ui::KeyboardCode key, |
74 bool control, | 72 bool control, |
75 bool shift, | 73 bool shift, |
76 bool alt, | 74 bool alt, |
77 bool command, | 75 bool command, |
78 const base::Closure& closure) override { | 76 const base::Closure& closure) override { |
79 aura::Window* root = | 77 aura::Window* root = |
80 window ? window->GetRootWindow() : ash::Shell::GetTargetRootWindow(); | 78 window ? window->GetRootWindow() : ash::Shell::GetTargetRootWindow(); |
81 UIControlsAura* ui_controls = GetUIControlsForRootWindow(root); | 79 UIControlsAura* ui_controls = GetUIControlsForRootWindow(root); |
82 return ui_controls && ui_controls->SendKeyPressNotifyWhenDone( | 80 return ui_controls && |
83 window, key, control, shift, alt, command, closure); | 81 ui_controls->SendKeyPressNotifyWhenDone(window, key, control, shift, |
| 82 alt, command, closure); |
84 } | 83 } |
85 | 84 |
86 bool SendMouseMove(long x, long y) override { | 85 bool SendMouseMove(long x, long y) override { |
87 gfx::Point p(x, y); | 86 gfx::Point p(x, y); |
88 UIControlsAura* ui_controls = GetUIControlsAt(p); | 87 UIControlsAura* ui_controls = GetUIControlsAt(p); |
89 return ui_controls && ui_controls->SendMouseMove(p.x(), p.y()); | 88 return ui_controls && ui_controls->SendMouseMove(p.x(), p.y()); |
90 } | 89 } |
91 | 90 |
92 bool SendMouseMoveNotifyWhenDone(long x, | 91 bool SendMouseMoveNotifyWhenDone(long x, |
93 long y, | 92 long y, |
94 const base::Closure& closure) override { | 93 const base::Closure& closure) override { |
95 gfx::Point p(x, y); | 94 gfx::Point p(x, y); |
96 UIControlsAura* ui_controls = GetUIControlsAt(p); | 95 UIControlsAura* ui_controls = GetUIControlsAt(p); |
97 return ui_controls && | 96 return ui_controls && |
98 ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure); | 97 ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure); |
99 } | 98 } |
100 | 99 |
101 bool SendMouseEvents(MouseButton type, int state) override { | 100 bool SendMouseEvents(MouseButton type, int state) override { |
102 gfx::Point p(display::Screen::GetScreen()->GetCursorScreenPoint()); | 101 gfx::Point p(display::Screen::GetScreen()->GetCursorScreenPoint()); |
103 UIControlsAura* ui_controls = GetUIControlsAt(p); | 102 UIControlsAura* ui_controls = GetUIControlsAt(p); |
104 return ui_controls && ui_controls->SendMouseEvents(type, state); | 103 return ui_controls && ui_controls->SendMouseEvents(type, state); |
105 } | 104 } |
106 | 105 |
107 bool SendMouseEventsNotifyWhenDone(MouseButton type, | 106 bool SendMouseEventsNotifyWhenDone(MouseButton type, |
108 int state, | 107 int state, |
109 const base::Closure& closure) override { | 108 const base::Closure& closure) override { |
110 gfx::Point p(aura::Env::GetInstance()->last_mouse_location()); | 109 gfx::Point p(aura::Env::GetInstance()->last_mouse_location()); |
111 UIControlsAura* ui_controls = GetUIControlsAt(p); | 110 UIControlsAura* ui_controls = GetUIControlsAt(p); |
112 return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone( | 111 return ui_controls && |
113 type, state, closure); | 112 ui_controls->SendMouseEventsNotifyWhenDone(type, state, closure); |
114 } | 113 } |
115 | 114 |
116 bool SendMouseClick(MouseButton type) override { | 115 bool SendMouseClick(MouseButton type) override { |
117 gfx::Point p(display::Screen::GetScreen()->GetCursorScreenPoint()); | 116 gfx::Point p(display::Screen::GetScreen()->GetCursorScreenPoint()); |
118 UIControlsAura* ui_controls = GetUIControlsAt(p); | 117 UIControlsAura* ui_controls = GetUIControlsAt(p); |
119 return ui_controls && ui_controls->SendMouseClick(type); | 118 return ui_controls && ui_controls->SendMouseClick(type); |
120 } | 119 } |
121 | 120 |
122 void RunClosureAfterAllPendingUIEvents( | 121 void RunClosureAfterAllPendingUIEvents( |
123 const base::Closure& closure) override { | 122 const base::Closure& closure) override { |
124 UIControlsAura* ui_controls = GetUIControlsForRootWindow( | 123 UIControlsAura* ui_controls = |
125 ash::Shell::GetTargetRootWindow()); | 124 GetUIControlsForRootWindow(ash::Shell::GetTargetRootWindow()); |
126 if (ui_controls) | 125 if (ui_controls) |
127 ui_controls->RunClosureAfterAllPendingUIEvents(closure); | 126 ui_controls->RunClosureAfterAllPendingUIEvents(closure); |
128 } | 127 } |
129 | 128 |
130 private: | 129 private: |
131 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh); | 130 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh); |
132 }; | 131 }; |
133 | 132 |
134 ui_controls::UIControlsAura* CreateAshUIControls() { | 133 ui_controls::UIControlsAura* CreateAshUIControls() { |
135 return new ash::test::UIControlsAsh(); | 134 return new ash::test::UIControlsAsh(); |
136 } | 135 } |
137 | 136 |
138 } // namespace test | 137 } // namespace test |
139 } // namespace ash | 138 } // namespace ash |
OLD | NEW |