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_ROOT_WINDOW_HOST_H_
6#define UI_AURA_ROOT_WINDOW_HOST_H_
7
8#include <vector>
9
10#include "base/message_loop/message_loop.h"
11#include "ui/aura/aura_export.h"
12#include "ui/base/cursor/cursor.h"
13#include "ui/gfx/native_widget_types.h"
14
15namespace gfx {
16class Insets;
17class Point;
18class Rect;
19class Size;
20}
21
22namespace aura {
23
24class RootWindow;
25class RootWindowHostDelegate;
26
27// RootWindowHost bridges between a native window and the embedded RootWindow.
28// It provides the accelerated widget and maps events from the native os to
29// aura.
30class AURA_EXPORT RootWindowHost {
31 public:
32  virtual ~RootWindowHost();
33
34  // Creates a new RootWindowHost. The caller owns the returned value.
35  static RootWindowHost* Create(const gfx::Rect& bounds);
36
37  // Returns the actual size of the screen.
38  // (gfx::Screen only reports on the virtual desktop exposed by Aura.)
39  static gfx::Size GetNativeScreenSize();
40
41  void set_delegate(RootWindowHostDelegate* delegate) {
42    delegate_ = delegate;
43  }
44
45  virtual RootWindow* GetRootWindow() = 0;
46
47  // Returns the accelerated widget.
48  virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
49
50  // Shows the RootWindowHost.
51  virtual void Show() = 0;
52
53  // Hides the RootWindowHost.
54  virtual void Hide() = 0;
55
56  // Toggles the host's full screen state.
57  virtual void ToggleFullScreen() = 0;
58
59  // Gets/Sets the size of the RootWindowHost.
60  virtual gfx::Rect GetBounds() const = 0;
61  virtual void SetBounds(const gfx::Rect& bounds) = 0;
62
63  // Sets/Gets the insets that specifies the effective root window area
64  // in the host window.
65  virtual gfx::Insets GetInsets() const = 0;
66  virtual void SetInsets(const gfx::Insets& insets) = 0;
67
68  // Converts |point| from the root window's coordinate system to native
69  // screen's.
70  void ConvertPointToNativeScreen(gfx::Point* point) const;
71
72  // Converts |point| from native screen coordinate system to the root window's.
73  void ConvertPointFromNativeScreen(gfx::Point* point) const;
74
75  // Sets the OS capture to the root window.
76  virtual void SetCapture() = 0;
77
78  // Releases OS capture of the root window.
79  virtual void ReleaseCapture() = 0;
80
81  // Sets the currently displayed cursor.
82  virtual void SetCursor(gfx::NativeCursor cursor) = 0;
83
84  // Queries the mouse's current position relative to the host window and sets
85  // it in |location_return|. Returns true if the cursor is within the host
86  // window. The position set to |location_return| is constrained within the
87  // host window. If the cursor is disabled, returns false and (0, 0) is set to
88  // |location_return|.
89  // This method is expensive, instead use gfx::Screen::GetCursorScreenPoint().
90  virtual bool QueryMouseLocation(gfx::Point* location_return) = 0;
91
92  // Clips the cursor to the bounds of the root window until UnConfineCursor().
93  // We would like to be able to confine the cursor to that window. However,
94  // currently, we do not have such functionality in X. So we just confine
95  // to the root window. This is ok because this option is currently only
96  // being used in fullscreen mode, so root_window bounds = window bounds.
97  virtual bool ConfineCursorToRootWindow() = 0;
98  virtual void UnConfineCursor() = 0;
99
100  // Called when the cursor visibility has changed.
101  virtual void OnCursorVisibilityChanged(bool show) = 0;
102
103  // Moves the cursor to the specified location relative to the root window.
104  virtual void MoveCursorTo(const gfx::Point& location) = 0;
105
106  // Posts |native_event| to the platform's event queue.
107  virtual void PostNativeEvent(const base::NativeEvent& native_event) = 0;
108
109  // Called when the device scale factor of the root window has chagned.
110  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) = 0;
111
112  // Stop listening events in preparation for shutdown.
113  virtual void PrepareForShutdown() = 0;
114
115 protected:
116  RootWindowHost();
117
118  // Returns the location of the RootWindow on native screen.
119  virtual gfx::Point GetLocationOnNativeScreen() const = 0;
120
121  RootWindowHostDelegate* delegate_;
122
123 private:
124  DISALLOW_COPY_AND_ASSIGN(RootWindowHost);
125};
126
127}  // namespace aura
128
129#endif  // UI_AURA_ROOT_WINDOW_HOST_H_
130