• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_X11_H_
6 #define UI_AURA_ROOT_WINDOW_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_loop.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 RootWindowHostX11 : public RootWindowHost,
37                                       public base::MessageLoop::Dispatcher,
38                                       public ui::EventSource,
39                                       public EnvObserver {
40  public:
41   explicit RootWindowHostX11(const gfx::Rect& bounds);
42   virtual ~RootWindowHostX11();
43 
44   // Overridden from Dispatcher overrides:
45   virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
46 
47   // RootWindowHost 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 void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE;
61   virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
62   virtual bool ConfineCursorToRootWindow() OVERRIDE;
63   virtual void UnConfineCursor() OVERRIDE;
64   virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
65   virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
66   virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE;
67   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
68   virtual void PrepareForShutdown() 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   bool DispatchEventForRootWindow(const base::NativeEvent& event);
81 
82   // Dispatches XI2 events. Note that some events targetted for the X root
83   // window are dispatched to the aura root window (e.g. touch events after
84   // calibration).
85   void DispatchXI2Event(const base::NativeEvent& event);
86 
87   // Returns true if there's an X window manager present... in most cases.  Some
88   // window managers (notably, ion3) don't implement enough of ICCCM for us to
89   // detect that they're there.
90   bool IsWindowManagerPresent();
91 
92   // Sets the cursor on |xwindow_| to |cursor|.  Does not check or update
93   // |current_cursor_|.
94   void SetCursorInternal(gfx::NativeCursor cursor);
95 
96   // Translates the native mouse location into screen coordinates and and
97   // dispatches the event to RootWindowHostDelegate.
98   void TranslateAndDispatchMouseEvent(ui::MouseEvent* event);
99 
100   // Update is_internal_display_ based on delegate_ state
101   void UpdateIsInternalDisplay();
102 
103   // Set the CrOS touchpad "tap paused" property. It is used to temporarily
104   // turn off the Tap-to-click feature when the mouse pointer is invisible.
105   void SetCrOSTapPaused(bool state);
106 
107   // The display and the native X window hosting the root window.
108   XDisplay* xdisplay_;
109   ::Window xwindow_;
110 
111   // The native root window.
112   ::Window x_root_window_;
113 
114   // Current Aura cursor.
115   gfx::NativeCursor current_cursor_;
116 
117   // Is the window mapped to the screen?
118   bool window_mapped_;
119 
120   // The bounds of |xwindow_|.
121   gfx::Rect bounds_;
122 
123   // The insets that specifies the effective area within the |window_|.
124   gfx::Insets insets_;
125 
126   // True if the root host resides on the internal display
127   bool is_internal_display_;
128 
129   scoped_ptr<XID[]> pointer_barriers_;
130 
131   scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_;
132 
133   scoped_ptr<MouseMoveFilter> mouse_move_filter_;
134 
135   ui::X11AtomCache atom_cache_;
136 
137   // Touch ids of which the touch press happens at side bezel region.
138   uint32 bezel_tracking_ids_;
139 
140   DISALLOW_COPY_AND_ASSIGN(RootWindowHostX11);
141 };
142 
143 namespace test {
144 
145 // Set the default value of the override redirect flag used to
146 // create a X window for RootWindowHostX11.
147 AURA_EXPORT void SetUseOverrideRedirectWindowByDefault(bool override_redirect);
148 
149 }  // namespace test
150 }  // namespace aura
151 
152 #endif  // UI_AURA_ROOT_WINDOW_HOST_X11_H_
153