4eeda04095fc098b67935c264d533bbfd13d5fce
[platform/framework/web/crosswalk.git] / src / ozone / ui / desktop_aura / desktop_window_tree_host_wayland.h
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.
5
6 #ifndef OZONE_IMPL_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WAYLAND_H_
7 #define OZONE_IMPL_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WAYLAND_H_
8
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "ui/aura/window_tree_host.h"
15 #include "ui/platform_window/platform_window_delegate.h"
16 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
17
18 namespace ui {
19 class PlatformWindow;
20 }
21
22 namespace views {
23
24 namespace corewm {
25 class Tooltip;
26 }
27
28 class DesktopDragDropClientWayland;
29 class WindowTreeHostDelegateWayland;
30
31 class VIEWS_EXPORT DesktopWindowTreeHostWayland
32     : public DesktopWindowTreeHost,
33       public aura::WindowTreeHost,
34       public ui::PlatformWindowDelegate
35 {
36  public:
37   DesktopWindowTreeHostWayland(
38       internal::NativeWidgetDelegate* native_widget_delegate,
39       DesktopNativeWidgetAura* desktop_native_widget_aura);
40   virtual ~DesktopWindowTreeHostWayland();
41
42   // Accepts a opaque handle widget and returns associated
43   // DesktopWindowTreeHostWayland.
44   static DesktopWindowTreeHostWayland* GetHostForAcceleratedWidget(
45       gfx::AcceleratedWidget widget);
46
47   // Get all open top-level windows. This includes windows that may not be
48   // visible. This list is sorted in their stacking order, i.e. the first window
49   // is the topmost window.
50   static const std::vector<aura::Window*>& GetAllOpenWindows();
51
52   // Accepts a opaque handle widget and returns associated aura::Window.
53   static aura::Window* GetContentWindowForAcceleratedWidget(
54       gfx::AcceleratedWidget widget);
55
56   // Returns window bounds. This is used by Screen to determine if a point
57   // belongs to a particular window.
58   gfx::Rect GetBoundsInScreen() const;
59
60  private:
61   enum {
62     Uninitialized = 0x00,
63     Visible = 0x01,  // Window is Visible.
64     FullScreen = 0x02,  // Window is in fullscreen mode.
65     Maximized = 0x04,  // Window is maximized,
66     Minimized = 0x08,  // Window is minimized.
67     Normal = 0x10,  // Window is in Normal Mode.
68     Active = 0x20  // Window is Active.
69   };
70
71   typedef unsigned RootWindowState;
72
73   // Initializes our Ozone surface to draw on. This method performs all
74   // initialization related to talking to the Ozone server.
75   void InitWaylandWindow(const views::Widget::InitParams& params);
76
77   // Called when another DRWHL takes capture, or when capture is released
78   // entirely.
79   void OnCaptureReleased();
80
81   // ui::PlatformWindowDelegate:
82   // TODO(kalyan) Provide appropriate implementations.
83   virtual void OnBoundsChanged(const gfx::Rect&) OVERRIDE {}
84   virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE{}
85   virtual void DispatchEvent(ui::Event* event) OVERRIDE{}
86   virtual void OnCloseRequest() OVERRIDE{}
87   virtual void OnClosed() OVERRIDE{}
88   virtual void OnWindowStateChanged(ui::PlatformWindowState new_state) OVERRIDE{}
89   virtual void OnLostCapture() OVERRIDE{}
90   virtual void OnAcceleratedWidgetAvailable(
91       gfx::AcceleratedWidget widget) OVERRIDE;
92   virtual void OnActivationChanged(bool active) OVERRIDE{}
93
94   // Overridden from DesktopWindowTreeHost:
95   virtual void Init(
96       aura::Window* content_window,
97       const views::Widget::InitParams& params) OVERRIDE;
98   virtual void OnNativeWidgetCreated(
99       const views::Widget::InitParams& params) OVERRIDE;
100   virtual scoped_ptr<views::corewm::Tooltip> CreateTooltip() OVERRIDE;
101   virtual scoped_ptr<aura::client::DragDropClient> CreateDragDropClient(
102       views::DesktopNativeCursorManager* cursor_manager) OVERRIDE;
103   virtual void Close() OVERRIDE;
104   virtual void CloseNow() OVERRIDE;
105   virtual aura::WindowTreeHost* AsWindowTreeHost() OVERRIDE;
106   virtual void ShowWindowWithState(ui::WindowShowState show_state) OVERRIDE;
107   virtual void ShowMaximizedWithBounds(
108       const gfx::Rect& restored_bounds) OVERRIDE;
109   virtual bool IsVisible() const OVERRIDE;
110   virtual void SetSize(const gfx::Size& size) OVERRIDE;
111   virtual void StackAtTop() OVERRIDE;
112   virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
113   virtual void GetWindowPlacement(
114       gfx::Rect* bounds,
115       ui::WindowShowState* show_state) const OVERRIDE;
116   virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
117   virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
118   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
119   virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
120   virtual void SetShape(gfx::NativeRegion native_region) OVERRIDE;
121   virtual void Activate() OVERRIDE;
122   virtual void Deactivate() OVERRIDE;
123   virtual bool IsActive() const OVERRIDE;
124   virtual void Maximize() OVERRIDE;
125   virtual void Minimize() OVERRIDE;
126   virtual void Restore() OVERRIDE;
127   virtual bool IsMaximized() const OVERRIDE;
128   virtual bool IsMinimized() const OVERRIDE;
129   virtual bool HasCapture() const OVERRIDE;
130   virtual bool IsAlwaysOnTop() const OVERRIDE;
131   virtual void SetVisibleOnAllWorkspaces(bool always_visible) OVERRIDE;
132   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
133   virtual bool SetWindowTitle(const base::string16& title) OVERRIDE;
134   virtual void ClearNativeFocus() OVERRIDE;
135   virtual views::Widget::MoveLoopResult RunMoveLoop(
136       const gfx::Vector2d& drag_offset,
137       views::Widget::MoveLoopSource source,
138       views::Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
139   virtual void EndMoveLoop() OVERRIDE;
140   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
141   virtual bool ShouldUseNativeFrame() const OVERRIDE;
142   virtual bool ShouldWindowContentsBeTransparent() const OVERRIDE;
143   virtual void FrameTypeChanged() OVERRIDE;
144   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
145   virtual bool IsFullscreen() const OVERRIDE;
146   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
147   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
148                               const gfx::ImageSkia& app_icon) OVERRIDE;
149   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
150   virtual void FlashFrame(bool flash_frame) OVERRIDE;
151   virtual void OnRootViewLayout() OVERRIDE;
152   virtual void OnNativeWidgetFocus() OVERRIDE;
153   virtual void OnNativeWidgetBlur() OVERRIDE;
154   virtual bool IsAnimatingClosed() const OVERRIDE;
155   virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE;
156
157   // Overridden from aura::WindowTreeHost:
158   virtual ui::EventSource* GetEventSource() OVERRIDE;
159   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
160   virtual void Show() OVERRIDE;
161   virtual void Hide() OVERRIDE;
162   virtual gfx::Rect GetBounds() const OVERRIDE;
163   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
164   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
165   virtual void SetCapture() OVERRIDE;
166   virtual void ReleaseCapture() OVERRIDE;
167   virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE;
168   virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE;
169   virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE;
170   virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
171
172   void HandleNativeWidgetActivationChanged(bool active);
173   void HandleWindowResize(unsigned width, unsigned height);
174   void HandleWindowUnminimized();
175
176   void HandlePreeditChanged(const std::string& text, const std::string& commit);
177   void HandleCommit(const std::string& text);
178
179   RootWindowState state_;
180
181   // Current bounds of DRWH.
182   gfx::Rect bounds_;
183   // Original bounds of DRWH.
184   gfx::Rect previous_bounds_;
185   gfx::Rect previous_maximize_bounds_;
186   gfx::AcceleratedWidget window_;
187   base::string16 title_;
188
189   base::WeakPtrFactory<DesktopWindowTreeHostWayland> close_widget_factory_;
190
191   // Owned by DesktopNativeWidgetAura.
192   DesktopDragDropClientWayland* drag_drop_client_;
193   views::internal::NativeWidgetDelegate* native_widget_delegate_;
194   aura::Window* content_window_;
195
196   views::DesktopNativeWidgetAura* desktop_native_widget_aura_;
197   // We can optionally have a parent which can order us to close, or own
198   // children who we're responsible for closing when we CloseNow().
199   DesktopWindowTreeHostWayland* window_parent_;
200   std::set<DesktopWindowTreeHostWayland*> window_children_;
201
202   // Platform-specific part of this DesktopWindowTreeHost.
203   scoped_ptr<ui::PlatformWindow> platform_window_;
204
205   static WindowTreeHostDelegateWayland* g_delegate_ozone_wayland_;
206   friend class WindowTreeHostDelegateWayland;
207   DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostWayland);
208 };
209
210 }  // namespace views
211
212 #endif  // OZONE_IMPL_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WAYLAND_H_