1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Copyright 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #ifndef DESKTOP_ROOT_WINDOW_HOST_WAYLAND_H_
7 #define DESKTOP_ROOT_WINDOW_HOST_WAYLAND_H_
12 #include "base/basictypes.h"
13 #include "ozone/wayland/window_change_observer.h"
14 #include "ui/aura/root_window_host.h"
15 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h"
18 class DesktopDispatcherClient;
19 class OzoneDesktopWindowMoveClient;
20 class OzoneWindowEventFilter;
26 namespace ozonewayland {
27 class DesktopDragDropClientWayland;
29 class VIEWS_EXPORT DesktopRootWindowHostWayland
30 : public views::DesktopRootWindowHost,
31 public aura::RootWindowHost,
32 public WindowChangeObserver,
33 public base::MessageLoop::Dispatcher {
35 DesktopRootWindowHostWayland(
36 views::internal::NativeWidgetDelegate* native_widget_delegate,
37 views::DesktopNativeWidgetAura* desktop_native_widget_aura);
38 virtual ~DesktopRootWindowHostWayland();
40 // Called by OzoneDesktopHandler to notify us that the native windowing system
41 // has changed our activation.
42 void HandleNativeWidgetActivationChanged(bool active);
47 Visible = 0x01, // Window is Visible.
48 FullScreen = 0x02, // Window is in fullscreen mode.
49 Maximized = 0x04, // Window is maximized,
50 Minimized = 0x08, // Window is minimized.
51 Normal = 0x10, // Window is in Normal Mode.
52 Active = 0x20 // Window is Active.
55 typedef unsigned RootWindowState;
57 // Accepts a opaque handle widget and returns associated
58 // DesktopRootWindowHostWayland.
59 static DesktopRootWindowHostWayland* GetHostForAcceleratedWidget(
60 gfx::AcceleratedWidget widget);
62 // Initializes our Ozone surface to draw on. This method performs all
63 // initialization related to talking to the Ozone server.
64 void InitWaylandWindow(const views::Widget::InitParams& params);
66 // Creates an aura::RootWindow to contain the |content_window|, along with
67 // all aura client objects that direct behavior.
68 aura::RootWindow* InitRootWindow(const views::Widget::InitParams& params);
70 // Returns true if there's an X window manager present... in most cases. Some
71 // window managers (notably, ion3) don't implement enough of ICCCM for us to
72 // detect that they're there.
73 bool IsWindowManagerPresent();
75 // Called when another DRWHL takes capture, or when capture is released
77 void OnCaptureReleased();
79 // Dispatches a mouse event, taking mouse capture into account. If a
80 // different host has capture, we translate the event to its coordinate space
81 // and dispatch it to that host instead.
82 void DispatchMouseEvent(ui::MouseEvent* event);
84 // Overridden from DesktopRootWindowHost:
85 virtual void Init(aura::Window* content_window,
86 const views::Widget::InitParams& params,
87 aura::RootWindow::CreateParams* rw_create_params) OVERRIDE;
88 virtual void OnRootWindowCreated(
89 aura::RootWindow* root, const views::Widget::InitParams& params) OVERRIDE;
90 virtual scoped_ptr<views::corewm::Tooltip> CreateTooltip() OVERRIDE;
91 virtual scoped_ptr<aura::client::DragDropClient> CreateDragDropClient(
92 views::DesktopNativeCursorManager* cursor_manager) OVERRIDE;
93 virtual void Close() OVERRIDE;
94 virtual void CloseNow() OVERRIDE;
95 virtual aura::RootWindowHost* AsRootWindowHost() OVERRIDE;
96 virtual void ShowWindowWithState(ui::WindowShowState show_state) OVERRIDE;
97 virtual void ShowMaximizedWithBounds(
98 const gfx::Rect& restored_bounds) OVERRIDE;
99 virtual bool IsVisible() const OVERRIDE;
100 virtual void SetSize(const gfx::Size& size) OVERRIDE;
101 virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
102 virtual void GetWindowPlacement(
104 ui::WindowShowState* show_state) const OVERRIDE;
105 virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
106 virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
107 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
108 virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
109 virtual void SetShape(gfx::NativeRegion native_region) OVERRIDE;
110 virtual void Activate() OVERRIDE;
111 virtual void Deactivate() OVERRIDE;
112 virtual bool IsActive() const OVERRIDE;
113 virtual void Maximize() OVERRIDE;
114 virtual void Minimize() OVERRIDE;
115 virtual void Restore() OVERRIDE;
116 virtual bool IsMaximized() const OVERRIDE;
117 virtual bool IsMinimized() const OVERRIDE;
118 virtual bool HasCapture() const OVERRIDE;
119 virtual bool IsAlwaysOnTop() const OVERRIDE;
120 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
121 virtual void SetWindowTitle(const string16& title) OVERRIDE;
122 virtual void ClearNativeFocus() OVERRIDE;
123 virtual views::Widget::MoveLoopResult RunMoveLoop(
124 const gfx::Vector2d& drag_offset,
125 views::Widget::MoveLoopSource source,
126 views::Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
127 virtual void EndMoveLoop() OVERRIDE;
128 virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
129 virtual bool ShouldUseNativeFrame() OVERRIDE;
130 virtual void FrameTypeChanged() OVERRIDE;
131 virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
132 virtual void SetFullscreen(bool fullscreen) OVERRIDE;
133 virtual bool IsFullscreen() const OVERRIDE;
134 virtual void SetOpacity(unsigned char opacity) OVERRIDE;
135 virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
136 const gfx::ImageSkia& app_icon) OVERRIDE;
137 virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
138 virtual void FlashFrame(bool flash_frame) OVERRIDE;
139 virtual void OnRootViewLayout() const OVERRIDE;
140 virtual void OnNativeWidgetFocus() OVERRIDE;
141 virtual void OnNativeWidgetBlur() OVERRIDE;
142 virtual bool IsAnimatingClosed() const OVERRIDE;
144 // Overridden from aura::RootWindowHost:
145 virtual void SetDelegate(aura::RootWindowHostDelegate* delegate) OVERRIDE;
146 virtual aura::RootWindow* GetRootWindow() OVERRIDE;
147 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
148 virtual void Show() OVERRIDE;
149 virtual void Hide() OVERRIDE;
150 virtual void ToggleFullScreen() OVERRIDE;
151 virtual gfx::Rect GetBounds() const OVERRIDE;
152 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
153 virtual gfx::Insets GetInsets() const OVERRIDE;
154 virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
155 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
156 virtual void SetCapture() OVERRIDE;
157 virtual void ReleaseCapture() OVERRIDE;
158 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
159 virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
160 virtual bool ConfineCursorToRootWindow() OVERRIDE;
161 virtual void UnConfineCursor() OVERRIDE;
162 virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
163 virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
164 virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE;
165 virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
166 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
167 virtual void PrepareForShutdown() OVERRIDE;
169 // Window Change Observer.
170 virtual void OnWindowFocused(unsigned windowhandle) OVERRIDE;
171 virtual void OnWindowEnter(unsigned windowhandle) OVERRIDE;
172 virtual void OnWindowLeave(unsigned windowhandle) OVERRIDE;
174 // Overridden from DesktopSelectionProviderAuraOzone:
175 // virtual void SetDropHandler(
176 // ui::OSExchangeDataProviderAuraOzone* handler) OVERRIDE;
178 // Overridden from Dispatcher:
179 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
181 std::list<gfx::AcceleratedWidget>& open_windows();
185 base::WeakPtrFactory<DesktopRootWindowHostWayland> close_widget_factory_;
187 // We are owned by the RootWindow, but we have to have a back pointer to it.
188 aura::RootWindow* root_window_;
190 // Owned by DesktopNativeWidgetAura.
191 DesktopDragDropClientWayland* drag_drop_client_;
193 scoped_ptr<views::DesktopDispatcherClient> dispatcher_client_;
195 gfx::AcceleratedWidget window_;
196 views::internal::NativeWidgetDelegate* native_widget_delegate_;
198 RootWindowState state_;
200 // Current bounds of DRWH.
202 // Original bounds of DRWH.
203 gfx::Rect previous_bounds_;
205 aura::RootWindowHostDelegate* root_window_host_delegate_;
207 aura::Window* content_window_;
209 views::DesktopNativeWidgetAura* desktop_native_widget_aura_;
210 // We can optionally have a parent which can order us to close, or own
211 // children who we're responsible for closing when we CloseNow().
212 DesktopRootWindowHostWayland* window_parent_;
213 std::set<DesktopRootWindowHostWayland*> window_children_;
217 // The current root window host that has capture. While X11 has something
218 // like Windows SetCapture()/ReleaseCapture(), it is entirely implicit and
219 // there are no notifications when this changes. We need to track this so we
220 // can notify widgets when they have lost capture, which controls a bunch of
221 // things in views like hiding menus.
222 static DesktopRootWindowHostWayland* g_current_capture;
223 // Current dispatcher.
224 static DesktopRootWindowHostWayland* g_current_dispatcher_;
225 // List of all open windows.
226 static std::list<gfx::AcceleratedWidget>* open_windows_;
228 DISALLOW_COPY_AND_ASSIGN(DesktopRootWindowHostWayland);
231 } // namespace ozonewayland
233 #endif // DESKTOP_ROOT_WINDOW_HOST_WAYLAND_H_