Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / aura / window_tree_host.h
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.
4
5 #ifndef UI_AURA_WINDOW_TREE_HOST_H_
6 #define UI_AURA_WINDOW_TREE_HOST_H_
7
8 #include <vector>
9
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"
15
16 namespace gfx {
17 class Insets;
18 class Point;
19 class Rect;
20 class Size;
21 class Transform;
22 }
23
24 namespace ui {
25 class Compositor;
26 }
27
28 namespace aura {
29
30 class RootWindow;
31 class WindowTreeHostDelegate;
32 class RootWindowTransformer;
33
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
36 // aura.
37 class AURA_EXPORT WindowTreeHost {
38  public:
39   virtual ~WindowTreeHost();
40
41   // Creates a new WindowTreeHost. The caller owns the returned value.
42   static WindowTreeHost* Create(const gfx::Rect& bounds);
43
44   void InitHost();
45
46   void InitCompositor();
47
48   // TODO(beng): these will become trivial accessors in a future CL.
49   aura::Window* window();
50   const aura::Window* window() const;
51
52   ui::Compositor* compositor() { return compositor_.get(); }
53
54   void SetRootWindowTransformer(scoped_ptr<RootWindowTransformer> transformer);
55   gfx::Transform GetRootTransform() const;
56
57   void SetTransform(const gfx::Transform& transform);
58
59   gfx::Transform GetInverseRootTransform() const;
60
61   // Updates the root window's size using |host_size|, current
62   // transform and insets.
63   void UpdateRootWindowSize(const gfx::Size& host_size);
64
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();
68
69   void set_delegate(WindowTreeHostDelegate* delegate) {
70     delegate_ = delegate;
71   }
72
73   // Converts |point| from the root window's coordinate system to native
74   // screen's.
75   void ConvertPointToNativeScreen(gfx::Point* point) const;
76
77   // Converts |point| from native screen coordinate system to the root window's.
78   void ConvertPointFromNativeScreen(gfx::Point* point) const;
79
80   // Converts |point| from the root window's coordinate system to the
81   // host window's.
82   void ConvertPointToHost(gfx::Point* point) const;
83
84   // Converts |point| from the host window's coordinate system to the
85   // root window's.
86   void ConvertPointFromHost(gfx::Point* point) const;
87
88   // Cursor.
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
92   // used.
93   void SetCursor(gfx::NativeCursor cursor);
94
95   // Invoked when the cursor's visibility has changed.
96   void OnCursorVisibilityChanged(bool visible);
97
98   // Moves the cursor to the specified location relative to the root window.
99   void MoveCursorTo(const gfx::Point& location);
100
101   // Moves the cursor to the |host_location| given in host coordinates.
102   void MoveCursorToHostLocation(const gfx::Point& host_location);
103
104   gfx::NativeCursor last_cursor() const { return last_cursor_; }
105
106   virtual RootWindow* GetRootWindow() = 0;
107
108   // Returns the accelerated widget.
109   virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
110
111   // Shows the WindowTreeHost.
112   virtual void Show() = 0;
113
114   // Hides the WindowTreeHost.
115   virtual void Hide() = 0;
116
117   // Toggles the host's full screen state.
118   virtual void ToggleFullScreen() = 0;
119
120   // Gets/Sets the size of the WindowTreeHost.
121   virtual gfx::Rect GetBounds() const = 0;
122   virtual void SetBounds(const gfx::Rect& bounds) = 0;
123
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;
128
129   // Sets the OS capture to the root window.
130   virtual void SetCapture() = 0;
131
132   // Releases OS capture of the root window.
133   virtual void ReleaseCapture() = 0;
134
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;
142
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;
150
151   // Posts |native_event| to the platform's event queue.
152   virtual void PostNativeEvent(const base::NativeEvent& native_event) = 0;
153
154   // Called when the device scale factor of the root window has chagned.
155   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) = 0;
156
157   // Stop listening events in preparation for shutdown.
158   virtual void PrepareForShutdown() = 0;
159
160  protected:
161   friend class TestScreen;  // TODO(beng): see if we can remove/consolidate.
162
163   WindowTreeHost();
164   void DestroyCompositor();
165
166   void CreateCompositor(gfx::AcceleratedWidget accelerated_widget);
167
168   // Returns the location of the RootWindow on native screen.
169   virtual gfx::Point GetLocationOnNativeScreen() const = 0;
170
171   void NotifyHostResized(const gfx::Size& new_size);
172
173   // Sets the currently displayed cursor.
174   virtual void SetCursorNative(gfx::NativeCursor cursor) = 0;
175
176   // Moves the cursor to the specified location relative to the root window.
177   virtual void MoveCursorToNative(const gfx::Point& location) = 0;
178
179   // kCalled when the cursor visibility has changed.
180   virtual void OnCursorVisibilityChangedNative(bool show) = 0;
181
182   WindowTreeHostDelegate* delegate_;
183
184  private:
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);
189
190   scoped_ptr<ui::Compositor> compositor_;
191
192   scoped_ptr<RootWindowTransformer> transformer_;
193
194   // Last cursor set.  Used for testing.
195   gfx::NativeCursor last_cursor_;
196
197   DISALLOW_COPY_AND_ASSIGN(WindowTreeHost);
198 };
199
200 }  // namespace aura
201
202 #endif  // UI_AURA_WINDOW_TREE_HOST_H_