Home | History | Annotate | Download | only in aura
      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/root_window_host.h"
     20 #include "ui/base/x/x11_atom_cache.h"
     21 #include "ui/base/x/x11_util.h"
     22 #include "ui/gfx/insets.h"
     23 #include "ui/gfx/rect.h"
     24 
     25 namespace ui {
     26 class MouseEvent;
     27 }
     28 
     29 namespace aura {
     30 
     31 namespace internal {
     32 class TouchEventCalibrate;
     33 }
     34 
     35 class RootWindowHostX11 : public RootWindowHost,
     36                           public base::MessageLoop::Dispatcher,
     37                           public EnvObserver {
     38  public:
     39   explicit RootWindowHostX11(const gfx::Rect& bounds);
     40   virtual ~RootWindowHostX11();
     41 
     42   // Overridden from Dispatcher overrides:
     43   virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
     44 
     45   // RootWindowHost Overrides.
     46   virtual void SetDelegate(RootWindowHostDelegate* delegate) OVERRIDE;
     47   virtual RootWindow* GetRootWindow() OVERRIDE;
     48   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
     49   virtual void Show() OVERRIDE;
     50   virtual void Hide() OVERRIDE;
     51   virtual void ToggleFullScreen() OVERRIDE;
     52   virtual gfx::Rect GetBounds() const OVERRIDE;
     53   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
     54   virtual gfx::Insets GetInsets() const OVERRIDE;
     55   virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
     56   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
     57   virtual void SetCapture() OVERRIDE;
     58   virtual void ReleaseCapture() OVERRIDE;
     59   virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE;
     60   virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
     61   virtual bool ConfineCursorToRootWindow() OVERRIDE;
     62   virtual void UnConfineCursor() OVERRIDE;
     63   virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
     64   virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
     65   virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE;
     66   virtual bool CopyAreaToSkCanvas(const gfx::Rect& source_bounds,
     67                                   const gfx::Point& dest_offset,
     68                                   SkCanvas* canvas) OVERRIDE;
     69   virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE;
     70   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
     71   virtual void PrepareForShutdown() OVERRIDE;
     72 
     73   // EnvObserver overrides.
     74   virtual void OnWindowInitialized(Window* window) OVERRIDE;
     75   virtual void OnRootWindowInitialized(RootWindow* root_window) OVERRIDE;
     76  private:
     77   class MouseMoveFilter;
     78 
     79   bool DispatchEventForRootWindow(const base::NativeEvent& event);
     80 
     81   // Dispatches XI2 events. Note that some events targetted for the X root
     82   // window are dispatched to the aura root window (e.g. touch events after
     83   // calibration).
     84   void DispatchXI2Event(const base::NativeEvent& event);
     85 
     86   // Returns true if there's an X window manager present... in most cases.  Some
     87   // window managers (notably, ion3) don't implement enough of ICCCM for us to
     88   // detect that they're there.
     89   bool IsWindowManagerPresent();
     90 
     91   // Sets the cursor on |xwindow_| to |cursor|.  Does not check or update
     92   // |current_cursor_|.
     93   void SetCursorInternal(gfx::NativeCursor cursor);
     94 
     95   // Translates the native mouse location into screen coordinates and and
     96   // dispatches the event to RootWindowHostDelegate.
     97   void TranslateAndDispatchMouseEvent(ui::MouseEvent* event);
     98 
     99   // Update is_internal_display_ based on delegate_ state
    100   void UpdateIsInternalDisplay();
    101 
    102   // Set the CrOS touchpad "tap paused" property. It is used to temporarily
    103   // turn off the Tap-to-click feature when the mouse pointer is invisible.
    104   void SetCrOSTapPaused(bool state);
    105 
    106   RootWindowHostDelegate* delegate_;
    107 
    108   // The display and the native X window hosting the root window.
    109   Display* xdisplay_;
    110   ::Window xwindow_;
    111 
    112   // The native root window.
    113   ::Window x_root_window_;
    114 
    115   // Current Aura cursor.
    116   gfx::NativeCursor current_cursor_;
    117 
    118   // Is the window mapped to the screen?
    119   bool window_mapped_;
    120 
    121   // The bounds of |xwindow_|.
    122   gfx::Rect bounds_;
    123 
    124   // The insets that specifies the effective area within the |window_|.
    125   gfx::Insets insets_;
    126 
    127   // The bounds of |x_root_window_|.
    128   gfx::Rect x_root_bounds_;
    129 
    130   // True if the root host resides on the internal display
    131   bool is_internal_display_;
    132 
    133   // True if the window should be focused when the window is shown.
    134   bool focus_when_shown_;
    135 
    136   scoped_ptr<XID[]> pointer_barriers_;
    137 
    138   scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_;
    139 
    140   scoped_ptr<MouseMoveFilter> mouse_move_filter_;
    141 
    142   ui::X11AtomCache atom_cache_;
    143 
    144   DISALLOW_COPY_AND_ASSIGN(RootWindowHostX11);
    145 };
    146 
    147 namespace test {
    148 
    149 // Set the default value of the override redirect flag used to
    150 // create a X window for RootWindowHostX11.
    151 AURA_EXPORT void SetUseOverrideRedirectWindowByDefault(bool override_redirect);
    152 
    153 }  // namespace test
    154 }  // namespace aura
    155 
    156 #endif  // UI_AURA_ROOT_WINDOW_HOST_X11_H_
    157