Upstream version 8.37.180.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 "base/memory/scoped_ptr.h"
9 #include "ui/aura/aura_export.h"
10 #include "ui/aura/window_tree_host.h"
11 #include "ui/events/event_source.h"
12 #include "ui/events/platform/platform_event_dispatcher.h"
13 #include "ui/gfx/insets.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/x/x11_atom_cache.h"
16
17 // X forward decls to avoid including Xlib.h in a header file.
18 typedef struct _XDisplay XDisplay;
19 typedef unsigned long XID;
20 typedef XID Window;
21
22 namespace ui {
23 class MouseEvent;
24 }
25
26 namespace aura {
27
28 namespace internal {
29 class TouchEventCalibrate;
30 }
31
32 class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost,
33                                       public ui::EventSource,
34                                       public ui::PlatformEventDispatcher {
35
36  public:
37   explicit WindowTreeHostX11(const gfx::Rect& bounds);
38   virtual ~WindowTreeHostX11();
39
40   // ui::PlatformEventDispatcher:
41   virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
42   virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
43
44   // WindowTreeHost:
45   virtual ui::EventSource* GetEventSource() OVERRIDE;
46   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
47   virtual void Show() OVERRIDE;
48   virtual void Hide() OVERRIDE;
49   virtual gfx::Rect GetBounds() const OVERRIDE;
50   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
51   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
52   virtual void SetCapture() OVERRIDE;
53   virtual void ReleaseCapture() OVERRIDE;
54   virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE;
55   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
56   virtual void SetCursorNative(gfx::NativeCursor cursor_type) OVERRIDE;
57   virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE;
58   virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE;
59
60   // ui::EventSource overrides.
61   virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
62
63  protected:
64   // Called when X Configure Notify event is recevied.
65   virtual void OnConfigureNotify();
66
67   // Translates the native mouse location into screen coordinates and
68   // dispatches the event via WindowEventDispatcher.
69   virtual void TranslateAndDispatchLocatedEvent(ui::LocatedEvent* event);
70
71   ::Window x_root_window() { return x_root_window_; }
72   XDisplay* xdisplay() { return xdisplay_; }
73   const gfx::Rect bounds() const { return bounds_; }
74   ui::X11AtomCache* atom_cache() { return &atom_cache_; }
75
76  private:
77   // Dispatches XI2 events. Note that some events targetted for the X root
78   // window are dispatched to the aura root window (e.g. touch events after
79   // calibration).
80   void DispatchXI2Event(const base::NativeEvent& event);
81
82   // Sets the cursor on |xwindow_| to |cursor|.  Does not check or update
83   // |current_cursor_|.
84   void SetCursorInternal(gfx::NativeCursor cursor);
85
86   // The display and the native X window hosting the root window.
87   XDisplay* xdisplay_;
88   ::Window xwindow_;
89
90   // The native root window.
91   ::Window x_root_window_;
92
93   // Current Aura cursor.
94   gfx::NativeCursor current_cursor_;
95
96   // Is the window mapped to the screen?
97   bool window_mapped_;
98
99   // The bounds of |xwindow_|.
100   gfx::Rect bounds_;
101
102   scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_;
103
104   ui::X11AtomCache atom_cache_;
105
106   DISALLOW_COPY_AND_ASSIGN(WindowTreeHostX11);
107 };
108
109 namespace test {
110
111 // Set the default value of the override redirect flag used to
112 // create a X window for WindowTreeHostX11.
113 AURA_EXPORT void SetUseOverrideRedirectWindowByDefault(bool override_redirect);
114
115 }  // namespace test
116 }  // namespace aura
117
118 #endif  // UI_AURA_WINDOW_TREE_HOST_X11_H_