Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / aura / window_tree_host_x11.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_X11_H_
6 #define UI_AURA_WINDOW_TREE_HOST_X11_H_
7
8 #include <X11/Xlib.h>
9
10 #include <vector>
11
12 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
13 #undef RootWindow
14
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_pump_dispatcher.h"
17 #include "ui/aura/aura_export.h"
18 #include "ui/aura/env_observer.h"
19 #include "ui/aura/window_tree_host.h"
20 #include "ui/base/x/x11_util.h"
21 #include "ui/events/event_source.h"
22 #include "ui/gfx/insets.h"
23 #include "ui/gfx/rect.h"
24 #include "ui/gfx/x/x11_atom_cache.h"
25
26 namespace ui {
27 class MouseEvent;
28 }
29
30 namespace aura {
31
32 namespace internal {
33 class TouchEventCalibrate;
34 }
35
36 class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost,
37                                       public base::MessagePumpDispatcher,
38                                       public ui::EventSource,
39                                       public EnvObserver {
40  public:
41   explicit WindowTreeHostX11(const gfx::Rect& bounds);
42   virtual ~WindowTreeHostX11();
43
44   // Overridden from Dispatcher overrides:
45   virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE;
46
47   // WindowTreeHost Overrides.
48   virtual RootWindow* GetRootWindow() OVERRIDE;
49   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
50   virtual void Show() OVERRIDE;
51   virtual void Hide() OVERRIDE;
52   virtual void ToggleFullScreen() OVERRIDE;
53   virtual gfx::Rect GetBounds() const OVERRIDE;
54   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
55   virtual gfx::Insets GetInsets() const OVERRIDE;
56   virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
57   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
58   virtual void SetCapture() OVERRIDE;
59   virtual void ReleaseCapture() OVERRIDE;
60   virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
61   virtual bool ConfineCursorToRootWindow() OVERRIDE;
62   virtual void UnConfineCursor() OVERRIDE;
63   virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE;
64   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
65   virtual void PrepareForShutdown() OVERRIDE;
66   virtual void SetCursorNative(gfx::NativeCursor cursor_type) OVERRIDE;
67   virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE;
68   virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE;
69
70   // EnvObserver overrides.
71   virtual void OnWindowInitialized(Window* window) OVERRIDE;
72   virtual void OnRootWindowInitialized(RootWindow* root_window) OVERRIDE;
73
74   // ui::EventSource overrides.
75   virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
76
77  private:
78   class MouseMoveFilter;
79
80   // Dispatches XI2 events. Note that some events targetted for the X root
81   // window are dispatched to the aura root window (e.g. touch events after
82   // calibration).
83   void DispatchXI2Event(const base::NativeEvent& event);
84
85   // Returns true if there's an X window manager present... in most cases.  Some
86   // window managers (notably, ion3) don't implement enough of ICCCM for us to
87   // detect that they're there.
88   bool IsWindowManagerPresent();
89
90   // Sets the cursor on |xwindow_| to |cursor|.  Does not check or update
91   // |current_cursor_|.
92   void SetCursorInternal(gfx::NativeCursor cursor);
93
94   // Translates the native mouse location into screen coordinates and and
95   // dispatches the event to WindowTreeHostDelegate.
96   void TranslateAndDispatchMouseEvent(ui::MouseEvent* event);
97
98   // Update is_internal_display_ based on delegate_ state
99   void UpdateIsInternalDisplay();
100
101   // Set the CrOS touchpad "tap paused" property. It is used to temporarily
102   // turn off the Tap-to-click feature when the mouse pointer is invisible.
103   void SetCrOSTapPaused(bool state);
104
105   // The display and the native X window hosting the root window.
106   XDisplay* xdisplay_;
107   ::Window xwindow_;
108
109   // The native root window.
110   ::Window x_root_window_;
111
112   // Current Aura cursor.
113   gfx::NativeCursor current_cursor_;
114
115   // Is the window mapped to the screen?
116   bool window_mapped_;
117
118   // The bounds of |xwindow_|.
119   gfx::Rect bounds_;
120
121   // The insets that specifies the effective area within the |window_|.
122   gfx::Insets insets_;
123
124   // True if the root host resides on the internal display
125   bool is_internal_display_;
126
127   scoped_ptr<XID[]> pointer_barriers_;
128
129   scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_;
130
131   scoped_ptr<MouseMoveFilter> mouse_move_filter_;
132
133   ui::X11AtomCache atom_cache_;
134
135   // Touch ids of which the touch press happens at side bezel region.
136   uint32 bezel_tracking_ids_;
137
138   DISALLOW_COPY_AND_ASSIGN(WindowTreeHostX11);
139 };
140
141 namespace test {
142
143 // Set the default value of the override redirect flag used to
144 // create a X window for WindowTreeHostX11.
145 AURA_EXPORT void SetUseOverrideRedirectWindowByDefault(bool override_redirect);
146
147 }  // namespace test
148 }  // namespace aura
149
150 #endif  // UI_AURA_WINDOW_TREE_HOST_X11_H_