Add ICU message format support
[chromium-blink-merge.git] / ui / aura / window_tree_host.h
blob2587c014b4e81e752c0d826d416a7a9437d9cfe1
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.
5 #ifndef UI_AURA_WINDOW_TREE_HOST_H_
6 #define UI_AURA_WINDOW_TREE_HOST_H_
8 #include <vector>
10 #include "base/event_types.h"
11 #include "base/message_loop/message_loop.h"
12 #include "ui/aura/aura_export.h"
13 #include "ui/base/cursor/cursor.h"
14 #include "ui/base/ime/input_method_delegate.h"
15 #include "ui/events/event_source.h"
16 #include "ui/gfx/native_widget_types.h"
18 namespace gfx {
19 class Insets;
20 class Point;
21 class Rect;
22 class Size;
23 class Transform;
26 namespace ui {
27 class Compositor;
28 class EventProcessor;
29 class InputMethod;
30 class ViewProp;
33 namespace aura {
34 namespace test {
35 class WindowTreeHostTestApi;
38 class WindowEventDispatcher;
39 class WindowTreeHostObserver;
41 // WindowTreeHost bridges between a native window and the embedded RootWindow.
42 // It provides the accelerated widget and maps events from the native os to
43 // aura.
44 class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
45 public ui::EventSource {
46 public:
47 ~WindowTreeHost() override;
49 // Creates a new WindowTreeHost. The caller owns the returned value.
50 static WindowTreeHost* Create(const gfx::Rect& bounds);
52 // Returns the WindowTreeHost for the specified accelerated widget, or NULL
53 // if there is none associated.
54 static WindowTreeHost* GetForAcceleratedWidget(gfx::AcceleratedWidget widget);
56 void InitHost();
58 void InitCompositor();
60 void AddObserver(WindowTreeHostObserver* observer);
61 void RemoveObserver(WindowTreeHostObserver* observer);
63 Window* window() { return window_; }
64 const Window* window() const { return window_; }
66 ui::EventProcessor* event_processor();
68 WindowEventDispatcher* dispatcher() {
69 return const_cast<WindowEventDispatcher*>(
70 const_cast<const WindowTreeHost*>(this)->dispatcher());
72 const WindowEventDispatcher* dispatcher() const { return dispatcher_.get(); }
74 ui::Compositor* compositor() { return compositor_.get(); }
76 // Gets/Sets the root window's transform.
77 virtual gfx::Transform GetRootTransform() const;
78 virtual void SetRootTransform(const gfx::Transform& transform);
79 virtual gfx::Transform GetInverseRootTransform() const;
81 // Updates the root window's size using |host_size|, current
82 // transform and insets.
83 virtual void UpdateRootWindowSize(const gfx::Size& host_size);
85 // Returns the actual size of the screen.
86 // (gfx::Screen only reports on the virtual desktop exposed by Aura.)
87 static gfx::Size GetNativeScreenSize();
89 // Converts |point| from the root window's coordinate system to native
90 // screen's.
91 void ConvertPointToNativeScreen(gfx::Point* point) const;
93 // Converts |point| from native screen coordinate system to the root window's.
94 void ConvertPointFromNativeScreen(gfx::Point* point) const;
96 // Converts |point| from the root window's coordinate system to the
97 // host window's.
98 void ConvertPointToHost(gfx::Point* point) const;
100 // Converts |point| from the host window's coordinate system to the
101 // root window's.
102 void ConvertPointFromHost(gfx::Point* point) const;
104 // Cursor.
105 // Sets the currently-displayed cursor. If the cursor was previously hidden
106 // via ShowCursor(false), it will remain hidden until ShowCursor(true) is
107 // called, at which point the cursor that was last set via SetCursor() will be
108 // used.
109 void SetCursor(gfx::NativeCursor cursor);
111 // Invoked when the cursor's visibility has changed.
112 void OnCursorVisibilityChanged(bool visible);
114 // Moves the cursor to the specified location relative to the root window.
115 void MoveCursorTo(const gfx::Point& location);
117 // Moves the cursor to the |host_location| given in host coordinates.
118 void MoveCursorToHostLocation(const gfx::Point& host_location);
120 gfx::NativeCursor last_cursor() const { return last_cursor_; }
122 // Gets the InputMethod instance, if NULL, creates & owns it.
123 ui::InputMethod* GetInputMethod();
125 // Sets a shared unowned InputMethod. This is used when there is a singleton
126 // InputMethod shared between multiple WindowTreeHost instances.
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.
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 SetSharedInputMethod(ui::InputMethod* input_method);
146 // Overridden from ui::internal::InputMethodDelegate:
147 ui::EventDispatchDetails DispatchKeyEventPostIME(
148 ui::KeyEvent* event) override;
150 // Returns the EventSource responsible for dispatching events to the window
151 // tree.
152 virtual ui::EventSource* GetEventSource() = 0;
154 // Returns the accelerated widget.
155 virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
157 // Shows the WindowTreeHost.
158 void Show();
160 // Hides the WindowTreeHost.
161 void Hide();
163 // Gets/Sets the size of the WindowTreeHost (in pixels).
164 virtual gfx::Rect GetBounds() const = 0;
165 virtual void SetBounds(const gfx::Rect& bounds_in_pixels) = 0;
167 // Sets the OS capture to the root window.
168 virtual void SetCapture() = 0;
170 // Releases OS capture of the root window.
171 virtual void ReleaseCapture() = 0;
173 protected:
174 friend class TestScreen; // TODO(beng): see if we can remove/consolidate.
176 WindowTreeHost();
177 void DestroyCompositor();
178 void DestroyDispatcher();
180 void CreateCompositor(gfx::AcceleratedWidget accelerated_widget);
182 // Returns the location of the RootWindow on native screen.
183 virtual gfx::Point GetLocationOnNativeScreen() const = 0;
185 void OnHostMoved(const gfx::Point& new_location);
186 void OnHostResized(const gfx::Size& new_size);
187 void OnHostCloseRequested();
188 void OnHostActivated();
189 void OnHostLostWindowCapture();
191 // Sets the currently displayed cursor.
192 virtual void SetCursorNative(gfx::NativeCursor cursor) = 0;
194 // Moves the cursor to the specified location relative to the root window.
195 virtual void MoveCursorToNative(const gfx::Point& location) = 0;
197 // kCalled when the cursor visibility has changed.
198 virtual void OnCursorVisibilityChangedNative(bool show) = 0;
200 // Shows the WindowTreeHost.
201 virtual void ShowImpl() = 0;
203 // Hides the WindowTreeHost.
204 virtual void HideImpl() = 0;
206 // Overridden from ui::EventSource:
207 ui::EventProcessor* GetEventProcessor() override;
209 private:
210 friend class test::WindowTreeHostTestApi;
212 // Moves the cursor to the specified location. This method is internally used
213 // by MoveCursorTo() and MoveCursorToHostLocation().
214 void MoveCursorToInternal(const gfx::Point& root_location,
215 const gfx::Point& host_location);
217 // We don't use a scoped_ptr for |window_| since we need this ptr to be valid
218 // during its deletion. (Window's dtor notifies observers that may attempt to
219 // reach back up to access this object which will be valid until the end of
220 // the dtor).
221 Window* window_; // Owning.
223 base::ObserverList<WindowTreeHostObserver> observers_;
225 scoped_ptr<WindowEventDispatcher> dispatcher_;
227 scoped_ptr<ui::Compositor> compositor_;
229 // Last cursor set. Used for testing.
230 gfx::NativeCursor last_cursor_;
231 gfx::Point last_cursor_request_position_in_host_;
233 scoped_ptr<ui::ViewProp> prop_;
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 SetSharedInputMethod() method.
238 ui::InputMethod* input_method_;
240 // Whether the InputMethod instance is owned by this WindowTreeHost.
241 bool owned_input_method_;
243 DISALLOW_COPY_AND_ASSIGN(WindowTreeHost);
246 } // namespace aura
248 #endif // UI_AURA_WINDOW_TREE_HOST_H_