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_
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/gfx/native_widget_types.h"
31 class WindowTreeHostDelegate;
32 class RootWindowTransformer;
34 // WindowTreeHost bridges between a native window and the embedded RootWindow.
35 // It provides the accelerated widget and maps events from the native os to
37 class AURA_EXPORT WindowTreeHost {
39 virtual ~WindowTreeHost();
41 // Creates a new WindowTreeHost. The caller owns the returned value.
42 static WindowTreeHost* Create(const gfx::Rect& bounds);
46 void InitCompositor();
48 // TODO(beng): these will become trivial accessors in a future CL.
49 aura::Window* window();
50 const aura::Window* window() const;
52 ui::Compositor* compositor() { return compositor_.get(); }
54 void SetRootWindowTransformer(scoped_ptr<RootWindowTransformer> transformer);
55 gfx::Transform GetRootTransform() const;
57 void SetTransform(const gfx::Transform& transform);
59 gfx::Transform GetInverseRootTransform() const;
61 // Updates the root window's size using |host_size|, current
62 // transform and insets.
63 void UpdateRootWindowSize(const gfx::Size& host_size);
65 // Returns the actual size of the screen.
66 // (gfx::Screen only reports on the virtual desktop exposed by Aura.)
67 static gfx::Size GetNativeScreenSize();
69 void set_delegate(WindowTreeHostDelegate* delegate) {
73 // Converts |point| from the root window's coordinate system to native
75 void ConvertPointToNativeScreen(gfx::Point* point) const;
77 // Converts |point| from native screen coordinate system to the root window's.
78 void ConvertPointFromNativeScreen(gfx::Point* point) const;
80 // Converts |point| from the root window's coordinate system to the
82 void ConvertPointToHost(gfx::Point* point) const;
84 // Converts |point| from the host window's coordinate system to the
86 void ConvertPointFromHost(gfx::Point* point) const;
89 // Sets the currently-displayed cursor. If the cursor was previously hidden
90 // via ShowCursor(false), it will remain hidden until ShowCursor(true) is
91 // called, at which point the cursor that was last set via SetCursor() will be
93 void SetCursor(gfx::NativeCursor cursor);
95 // Invoked when the cursor's visibility has changed.
96 void OnCursorVisibilityChanged(bool visible);
98 // Moves the cursor to the specified location relative to the root window.
99 void MoveCursorTo(const gfx::Point& location);
101 // Moves the cursor to the |host_location| given in host coordinates.
102 void MoveCursorToHostLocation(const gfx::Point& host_location);
104 gfx::NativeCursor last_cursor() const { return last_cursor_; }
106 virtual RootWindow* GetRootWindow() = 0;
108 // Returns the accelerated widget.
109 virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
111 // Shows the WindowTreeHost.
112 virtual void Show() = 0;
114 // Hides the WindowTreeHost.
115 virtual void Hide() = 0;
117 // Toggles the host's full screen state.
118 virtual void ToggleFullScreen() = 0;
120 // Gets/Sets the size of the WindowTreeHost.
121 virtual gfx::Rect GetBounds() const = 0;
122 virtual void SetBounds(const gfx::Rect& bounds) = 0;
124 // Sets/Gets the insets that specifies the effective root window area
125 // in the host window.
126 virtual gfx::Insets GetInsets() const = 0;
127 virtual void SetInsets(const gfx::Insets& insets) = 0;
129 // Sets the OS capture to the root window.
130 virtual void SetCapture() = 0;
132 // Releases OS capture of the root window.
133 virtual void ReleaseCapture() = 0;
135 // Queries the mouse's current position relative to the host window and sets
136 // it in |location_return|. Returns true if the cursor is within the host
137 // window. The position set to |location_return| is constrained within the
138 // host window. If the cursor is disabled, returns false and (0, 0) is set to
139 // |location_return|.
140 // This method is expensive, instead use gfx::Screen::GetCursorScreenPoint().
141 virtual bool QueryMouseLocation(gfx::Point* location_return) = 0;
143 // Clips the cursor to the bounds of the root window until UnConfineCursor().
144 // We would like to be able to confine the cursor to that window. However,
145 // currently, we do not have such functionality in X. So we just confine
146 // to the root window. This is ok because this option is currently only
147 // being used in fullscreen mode, so root_window bounds = window bounds.
148 virtual bool ConfineCursorToRootWindow() = 0;
149 virtual void UnConfineCursor() = 0;
151 // Posts |native_event| to the platform's event queue.
152 virtual void PostNativeEvent(const base::NativeEvent& native_event) = 0;
154 // Called when the device scale factor of the root window has chagned.
155 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) = 0;
157 // Stop listening events in preparation for shutdown.
158 virtual void PrepareForShutdown() = 0;
161 friend class TestScreen; // TODO(beng): see if we can remove/consolidate.
164 void DestroyCompositor();
166 void CreateCompositor(gfx::AcceleratedWidget accelerated_widget);
168 // Returns the location of the RootWindow on native screen.
169 virtual gfx::Point GetLocationOnNativeScreen() const = 0;
171 void NotifyHostResized(const gfx::Size& new_size);
173 // Sets the currently displayed cursor.
174 virtual void SetCursorNative(gfx::NativeCursor cursor) = 0;
176 // Moves the cursor to the specified location relative to the root window.
177 virtual void MoveCursorToNative(const gfx::Point& location) = 0;
179 // kCalled when the cursor visibility has changed.
180 virtual void OnCursorVisibilityChangedNative(bool show) = 0;
182 WindowTreeHostDelegate* delegate_;
185 // Moves the cursor to the specified location. This method is internally used
186 // by MoveCursorTo() and MoveCursorToHostLocation().
187 void MoveCursorToInternal(const gfx::Point& root_location,
188 const gfx::Point& host_location);
190 scoped_ptr<ui::Compositor> compositor_;
192 scoped_ptr<RootWindowTransformer> transformer_;
194 // Last cursor set. Used for testing.
195 gfx::NativeCursor last_cursor_;
197 DISALLOW_COPY_AND_ASSIGN(WindowTreeHost);
202 #endif // UI_AURA_WINDOW_TREE_HOST_H_