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/shell.h" | 5 #include "ash/shell.h" |
6 #include "ash/shell_factory.h" | 6 #include "ash/shell_factory.h" |
7 #include "ash/wm/coordinate_conversion.h" | 7 #include "ash/wm/coordinate_conversion.h" |
8 #include "ash/wm/window_properties.h" | 8 #include "ash/wm/window_properties.h" |
9 #include "ui/aura/client/capture_client.h" | 9 #include "ui/aura/client/capture_client.h" |
10 #include "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/aura/ui_controls_aura.h" | 12 #include "ui/aura/ui_controls_aura.h" |
| 13 #include "ui/aura/window_property.h" |
13 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
14 #include "ui/ui_controls/ui_controls_aura.h" | 15 #include "ui/ui_controls/ui_controls_aura.h" |
15 | 16 |
16 namespace ash { | 17 namespace ui_controls { |
17 namespace internal { | |
18 namespace { | 18 namespace { |
19 | 19 |
| 20 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ui_controls::UIControlsAura, |
| 21 kUIControlsKey, |
| 22 NULL); |
| 23 |
20 // Returns the UIControls object for RootWindow. | 24 // Returns the UIControls object for RootWindow. |
21 // kUIControlsKey is owned property and UIControls object | 25 // kUIControlsKey is owned property and UIControls object |
22 // will be deleted when the root window is deleted. | 26 // will be deleted when the root window is deleted. |
23 ui_controls::UIControlsAura* GetUIControlsForRootWindow( | 27 ui_controls::UIControlsAura* GetUIControlsForRootWindow( |
24 aura::RootWindow* root_window) { | 28 aura::RootWindow* root_window) { |
25 ui_controls::UIControlsAura* native_ui_control = | 29 ui_controls::UIControlsAura* native_ui_control = |
26 root_window->GetProperty(kUIControlsKey); | 30 root_window->GetProperty(kUIControlsKey); |
27 if (!native_ui_control) { | 31 if (!native_ui_control) { |
28 native_ui_control = aura::CreateUIControlsAura(root_window); | 32 native_ui_control = aura::CreateUIControlsAura(root_window); |
29 // Pass the ownership to the |root_window|. | 33 // Pass the ownership to the |root_window|. |
30 root_window->SetProperty(kUIControlsKey, native_ui_control); | 34 root_window->SetProperty(kUIControlsKey, native_ui_control); |
31 } | 35 } |
32 return native_ui_control; | 36 return native_ui_control; |
33 } | 37 } |
34 | 38 |
35 // Returns the UIControls object for the RootWindow at the |point_in_screen| | 39 // Returns the UIControls object for the RootWindow at the |point_in_screen| |
36 // in virtual screen coordinates, and updates the |point| relative to the | 40 // in virtual screen coordinates, and updates the |point| relative to the |
37 // UIControlsAura's root window. NULL if there is no RootWindow under | 41 // UIControlsAura's root window. NULL if there is no RootWindow under |
38 // the |point_in_screen|. | 42 // the |point_in_screen|. |
39 ui_controls::UIControlsAura* GetUIControlsAt(gfx::Point* point_in_screen) { | 43 ui_controls::UIControlsAura* GetUIControlsAt(gfx::Point* point_in_screen) { |
40 // TODO(mazda): Support the case passive grab is taken. | 44 // TODO(mazda): Support the case passive grab is taken. |
41 aura::RootWindow* root = wm::GetRootWindowAt(*point_in_screen); | 45 aura::RootWindow* root = ash::wm::GetRootWindowAt(*point_in_screen); |
42 | 46 |
43 aura::client::ScreenPositionClient* screen_position_client = | 47 aura::client::ScreenPositionClient* screen_position_client = |
44 aura::client::GetScreenPositionClient(root); | 48 aura::client::GetScreenPositionClient(root); |
45 if (screen_position_client) | 49 if (screen_position_client) |
46 screen_position_client->ConvertPointFromScreen(root, point_in_screen); | 50 screen_position_client->ConvertPointFromScreen(root, point_in_screen); |
47 | 51 |
48 return GetUIControlsForRootWindow(root); | 52 return GetUIControlsForRootWindow(root); |
49 } | 53 } |
50 | 54 |
51 } // namespace | 55 } // namespace |
(...skipping 18 matching lines...) Expand all Loading... |
70 | 74 |
71 virtual bool SendKeyPressNotifyWhenDone( | 75 virtual bool SendKeyPressNotifyWhenDone( |
72 gfx::NativeWindow window, | 76 gfx::NativeWindow window, |
73 ui::KeyboardCode key, | 77 ui::KeyboardCode key, |
74 bool control, | 78 bool control, |
75 bool shift, | 79 bool shift, |
76 bool alt, | 80 bool alt, |
77 bool command, | 81 bool command, |
78 const base::Closure& closure) OVERRIDE { | 82 const base::Closure& closure) OVERRIDE { |
79 aura::RootWindow* root = | 83 aura::RootWindow* root = |
80 window ? window->GetRootWindow() : Shell::GetActiveRootWindow(); | 84 window ? window->GetRootWindow() : ash::Shell::GetActiveRootWindow(); |
81 ui_controls::UIControlsAura* ui_controls = GetUIControlsForRootWindow(root); | 85 ui_controls::UIControlsAura* ui_controls = GetUIControlsForRootWindow(root); |
82 return ui_controls && ui_controls->SendKeyPressNotifyWhenDone( | 86 return ui_controls && ui_controls->SendKeyPressNotifyWhenDone( |
83 window, key, control, shift, alt, command, closure); | 87 window, key, control, shift, alt, command, closure); |
84 } | 88 } |
85 | 89 |
86 virtual bool SendMouseMove(long x, long y) OVERRIDE { | 90 virtual bool SendMouseMove(long x, long y) OVERRIDE { |
87 gfx::Point p(x, y); | 91 gfx::Point p(x, y); |
88 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); | 92 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); |
89 return ui_controls && ui_controls->SendMouseMove(p.x(), p.y()); | 93 return ui_controls && ui_controls->SendMouseMove(p.x(), p.y()); |
90 } | 94 } |
91 | 95 |
92 virtual bool SendMouseMoveNotifyWhenDone( | 96 virtual bool SendMouseMoveNotifyWhenDone( |
93 long x, | 97 long x, |
94 long y, | 98 long y, |
95 const base::Closure& closure) OVERRIDE { | 99 const base::Closure& closure) OVERRIDE { |
96 gfx::Point p(x, y); | 100 gfx::Point p(x, y); |
97 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); | 101 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); |
98 return ui_controls && | 102 return ui_controls && |
99 ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure); | 103 ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure); |
100 } | 104 } |
101 | 105 |
102 virtual bool SendMouseEvents(ui_controls::MouseButton type, | 106 virtual bool SendMouseEvents(ui_controls::MouseButton type, |
103 int state) OVERRIDE { | 107 int state) OVERRIDE { |
104 gfx::Point p(Shell::GetScreen()->GetCursorScreenPoint()); | 108 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint()); |
105 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); | 109 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); |
106 return ui_controls && ui_controls->SendMouseEvents(type, state); | 110 return ui_controls && ui_controls->SendMouseEvents(type, state); |
107 } | 111 } |
108 | 112 |
109 virtual bool SendMouseEventsNotifyWhenDone( | 113 virtual bool SendMouseEventsNotifyWhenDone( |
110 ui_controls::MouseButton type, | 114 ui_controls::MouseButton type, |
111 int state, | 115 int state, |
112 const base::Closure& closure) OVERRIDE { | 116 const base::Closure& closure) OVERRIDE { |
113 gfx::Point p(Shell::GetScreen()->GetCursorScreenPoint()); | 117 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint()); |
114 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); | 118 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); |
115 return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone( | 119 return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone( |
116 type, state, closure); | 120 type, state, closure); |
117 } | 121 } |
118 | 122 |
119 virtual bool SendMouseClick(ui_controls::MouseButton type) OVERRIDE { | 123 virtual bool SendMouseClick(ui_controls::MouseButton type) OVERRIDE { |
120 gfx::Point p(Shell::GetScreen()->GetCursorScreenPoint()); | 124 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint()); |
121 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); | 125 ui_controls::UIControlsAura* ui_controls = GetUIControlsAt(&p); |
122 return ui_controls && ui_controls->SendMouseClick(type); | 126 return ui_controls && ui_controls->SendMouseClick(type); |
123 } | 127 } |
124 | 128 |
125 virtual void RunClosureAfterAllPendingUIEvents( | 129 virtual void RunClosureAfterAllPendingUIEvents( |
126 const base::Closure& closure) OVERRIDE { | 130 const base::Closure& closure) OVERRIDE { |
127 ui_controls::UIControlsAura* ui_controls = GetUIControlsForRootWindow( | 131 ui_controls::UIControlsAura* ui_controls = GetUIControlsForRootWindow( |
128 Shell::GetActiveRootWindow()); | 132 ash::Shell::GetActiveRootWindow()); |
129 if (ui_controls) | 133 if (ui_controls) |
130 ui_controls->RunClosureAfterAllPendingUIEvents(closure); | 134 ui_controls->RunClosureAfterAllPendingUIEvents(closure); |
131 } | 135 } |
132 | 136 |
133 private: | 137 private: |
134 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh); | 138 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh); |
135 }; | 139 }; |
136 | 140 |
137 ui_controls::UIControlsAura* CreateUIControls() { | 141 ui_controls::UIControlsAura* CreateAshUIControls() { |
138 return new UIControlsAsh(); | 142 return new UIControlsAsh(); |
139 } | 143 } |
140 | 144 |
141 } // namespace internal | 145 } // namespace ui_controls |
142 } // namespace ash | |
OLD | NEW |