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 #ifndef UI_AURA_WINDOW_TREE_HOST_H_ | 5 #ifndef UI_AURA_WINDOW_TREE_HOST_H_ |
6 #define UI_AURA_WINDOW_TREE_HOST_H_ | 6 #define UI_AURA_WINDOW_TREE_HOST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/event_types.h" | 10 #include "base/event_types.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "ui/aura/aura_export.h" | 12 #include "ui/aura/aura_export.h" |
13 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
14 #include "ui/base/ime/input_method_delegate.h" | |
14 #include "ui/events/event_source.h" | 15 #include "ui/events/event_source.h" |
15 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
16 | 17 |
17 namespace gfx { | 18 namespace gfx { |
18 class Insets; | 19 class Insets; |
19 class Point; | 20 class Point; |
20 class Rect; | 21 class Rect; |
21 class Size; | 22 class Size; |
22 class Transform; | 23 class Transform; |
23 } | 24 } |
24 | 25 |
25 namespace ui { | 26 namespace ui { |
26 class Compositor; | 27 class Compositor; |
27 class EventProcessor; | 28 class EventProcessor; |
29 class InputMethod; | |
28 class ViewProp; | 30 class ViewProp; |
29 } | 31 } |
30 | 32 |
31 namespace aura { | 33 namespace aura { |
32 namespace test { | 34 namespace test { |
33 class WindowTreeHostTestApi; | 35 class WindowTreeHostTestApi; |
34 } | 36 } |
35 | 37 |
36 class WindowEventDispatcher; | 38 class WindowEventDispatcher; |
37 class WindowTreeHostObserver; | 39 class WindowTreeHostObserver; |
38 | 40 |
39 // WindowTreeHost bridges between a native window and the embedded RootWindow. | 41 // WindowTreeHost bridges between a native window and the embedded RootWindow. |
40 // It provides the accelerated widget and maps events from the native os to | 42 // It provides the accelerated widget and maps events from the native os to |
41 // aura. | 43 // aura. |
42 class AURA_EXPORT WindowTreeHost { | 44 class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate, |
45 public ui::EventSource { | |
43 public: | 46 public: |
44 virtual ~WindowTreeHost(); | 47 ~WindowTreeHost() override; |
45 | 48 |
46 // Creates a new WindowTreeHost. The caller owns the returned value. | 49 // Creates a new WindowTreeHost. The caller owns the returned value. |
47 static WindowTreeHost* Create(const gfx::Rect& bounds); | 50 static WindowTreeHost* Create(const gfx::Rect& bounds); |
48 | 51 |
49 // Returns the WindowTreeHost for the specified accelerated widget, or NULL | 52 // Returns the WindowTreeHost for the specified accelerated widget, or NULL |
50 // if there is none associated. | 53 // if there is none associated. |
51 static WindowTreeHost* GetForAcceleratedWidget(gfx::AcceleratedWidget widget); | 54 static WindowTreeHost* GetForAcceleratedWidget(gfx::AcceleratedWidget widget); |
52 | 55 |
53 void InitHost(); | 56 void InitHost(); |
54 | 57 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 void OnCursorVisibilityChanged(bool visible); | 112 void OnCursorVisibilityChanged(bool visible); |
110 | 113 |
111 // Moves the cursor to the specified location relative to the root window. | 114 // Moves the cursor to the specified location relative to the root window. |
112 void MoveCursorTo(const gfx::Point& location); | 115 void MoveCursorTo(const gfx::Point& location); |
113 | 116 |
114 // Moves the cursor to the |host_location| given in host coordinates. | 117 // Moves the cursor to the |host_location| given in host coordinates. |
115 void MoveCursorToHostLocation(const gfx::Point& host_location); | 118 void MoveCursorToHostLocation(const gfx::Point& host_location); |
116 | 119 |
117 gfx::NativeCursor last_cursor() const { return last_cursor_; } | 120 gfx::NativeCursor last_cursor() const { return last_cursor_; } |
118 | 121 |
122 // Gets the InputMethod instance, if NULL, creates & owns it. | |
123 ui::InputMethod* GetInputMethod(); | |
124 | |
125 // Sets a shared unowned InputMethod. This is used when there is a singleton | |
126 // InputMethod shared between multiple WindowTreeHost instances. | |
127 // | |
128 // This is used for Ash only. There are 2 reasons: | |
129 // 1) ChromeOS virtual keyboard needs to receive ShowImeIfNeeded notification | |
130 // from InputMethod. Multiple InputMethod instances makes it hard to | |
131 // register/unregister the observer for that notification. | |
132 // 2) For Ozone, there is no native focus state for the root window and | |
133 // WindowTreeHost. See DrmWindowHost::CanDispatchEvent, the key events always | |
134 // goes to the primary WindowTreeHost. And after InputMethod processed the key | |
135 // event and continue dispatching it, WindowTargeter::FindTargetForEvent may | |
136 // re-dispatch it to a different WindowTreeHost. So the singleton InputMethod | |
137 // can make sure the correct InputMethod instance processes the key event no | |
138 // matter which WindowTreeHost is the target for event. Please refer to the | |
139 // test: ExtendedDesktopTest.KeyEventsOnLockScreen. | |
140 // | |
141 // TODO(shuchen): remove this method after above reasons become invalid. | |
142 // A possible solution is to make sure DrmWindowHost can find the correct | |
143 // WindowTreeHost to dispatch events. | |
144 void SetInputMethod(ui::InputMethod* input_method); | |
sadrul
2015/06/09 15:29:33
Call this SetSharedInputMethod()?
Shu Chen
2015/06/10 03:01:35
Done.
| |
145 | |
146 // Overridden from ui::internal::InputMethodDelegate: | |
147 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override; | |
sadrul
2015/06/09 15:29:33
Can this go in the protected/private section?
Shu Chen
2015/06/10 03:01:35
This should remain public because DisplayControlle
| |
148 | |
119 // Returns the EventSource responsible for dispatching events to the window | 149 // Returns the EventSource responsible for dispatching events to the window |
120 // tree. | 150 // tree. |
121 virtual ui::EventSource* GetEventSource() = 0; | 151 virtual ui::EventSource* GetEventSource() = 0; |
122 | 152 |
123 // Returns the accelerated widget. | 153 // Returns the accelerated widget. |
124 virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; | 154 virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; |
125 | 155 |
126 // Shows the WindowTreeHost. | 156 // Shows the WindowTreeHost. |
127 void Show(); | 157 void Show(); |
128 | 158 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 | 195 |
166 // kCalled when the cursor visibility has changed. | 196 // kCalled when the cursor visibility has changed. |
167 virtual void OnCursorVisibilityChangedNative(bool show) = 0; | 197 virtual void OnCursorVisibilityChangedNative(bool show) = 0; |
168 | 198 |
169 // Shows the WindowTreeHost. | 199 // Shows the WindowTreeHost. |
170 virtual void ShowImpl() = 0; | 200 virtual void ShowImpl() = 0; |
171 | 201 |
172 // Hides the WindowTreeHost. | 202 // Hides the WindowTreeHost. |
173 virtual void HideImpl() = 0; | 203 virtual void HideImpl() = 0; |
174 | 204 |
205 // Overridden from ui::EventSource: | |
206 ui::EventProcessor* GetEventProcessor() override; | |
207 ui::EventDispatchDetails DeliverEventToProcessor(ui::Event* event) override; | |
208 | |
175 private: | 209 private: |
176 friend class test::WindowTreeHostTestApi; | 210 friend class test::WindowTreeHostTestApi; |
177 | 211 |
178 // Moves the cursor to the specified location. This method is internally used | 212 // Moves the cursor to the specified location. This method is internally used |
179 // by MoveCursorTo() and MoveCursorToHostLocation(). | 213 // by MoveCursorTo() and MoveCursorToHostLocation(). |
180 void MoveCursorToInternal(const gfx::Point& root_location, | 214 void MoveCursorToInternal(const gfx::Point& root_location, |
181 const gfx::Point& host_location); | 215 const gfx::Point& host_location); |
182 | 216 |
183 // We don't use a scoped_ptr for |window_| since we need this ptr to be valid | 217 // We don't use a scoped_ptr for |window_| since we need this ptr to be valid |
184 // during its deletion. (Window's dtor notifies observers that may attempt to | 218 // during its deletion. (Window's dtor notifies observers that may attempt to |
185 // reach back up to access this object which will be valid until the end of | 219 // reach back up to access this object which will be valid until the end of |
186 // the dtor). | 220 // the dtor). |
187 Window* window_; // Owning. | 221 Window* window_; // Owning. |
188 | 222 |
189 base::ObserverList<WindowTreeHostObserver> observers_; | 223 base::ObserverList<WindowTreeHostObserver> observers_; |
190 | 224 |
191 scoped_ptr<WindowEventDispatcher> dispatcher_; | 225 scoped_ptr<WindowEventDispatcher> dispatcher_; |
192 | 226 |
193 scoped_ptr<ui::Compositor> compositor_; | 227 scoped_ptr<ui::Compositor> compositor_; |
194 | 228 |
195 // Last cursor set. Used for testing. | 229 // Last cursor set. Used for testing. |
196 gfx::NativeCursor last_cursor_; | 230 gfx::NativeCursor last_cursor_; |
197 gfx::Point last_cursor_request_position_in_host_; | 231 gfx::Point last_cursor_request_position_in_host_; |
198 | 232 |
199 scoped_ptr<ui::ViewProp> prop_; | 233 scoped_ptr<ui::ViewProp> prop_; |
200 | 234 |
235 // The InputMethod instance used to process key events. | |
236 // If owned it, it is created in GetInputMethod() method; | |
237 // If not owned it, it is passed in through SetInputMethod() method. | |
238 ui::InputMethod* input_method_; | |
239 | |
240 // Whether the InputMethod instance is owned by this WindowTreeHost. | |
241 bool owned_input_method_; | |
242 | |
201 DISALLOW_COPY_AND_ASSIGN(WindowTreeHost); | 243 DISALLOW_COPY_AND_ASSIGN(WindowTreeHost); |
202 }; | 244 }; |
203 | 245 |
204 } // namespace aura | 246 } // namespace aura |
205 | 247 |
206 #endif // UI_AURA_WINDOW_TREE_HOST_H_ | 248 #endif // UI_AURA_WINDOW_TREE_HOST_H_ |
OLD | NEW |