| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_AURA_ROOT_WINDOW_HOST_LINUX_H_ | 5 #ifndef WM_HOST_ROOT_WINDOW_HOST_LINUX_H_ |
| 6 #define UI_AURA_ROOT_WINDOW_HOST_LINUX_H_ | 6 #define WM_HOST_ROOT_WINDOW_HOST_LINUX_H_ |
| 7 | 7 |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 12 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| 13 #undef RootWindow | 13 #undef RootWindow |
| 14 | 14 |
| 15 #include "base/hash_tables.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 17 #include "ui/aura/root_window_host.h" | 18 #include "ui/aura/root_window_host.h" |
| 19 #include "ui/aura/window_observer.h" |
| 18 #include "ui/base/x/x11_atom_cache.h" | 20 #include "ui/base/x/x11_atom_cache.h" |
| 19 #include "ui/base/x/x11_util.h" | 21 #include "ui/base/x/x11_util.h" |
| 20 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 21 | 23 |
| 22 namespace ui { | 24 namespace ui { |
| 23 class MouseEvent; | 25 class MouseEvent; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace aura { | 28 namespace wm { |
| 29 class ForeignWindow; |
| 27 | 30 |
| 28 namespace internal { | 31 namespace internal { |
| 29 class TouchEventCalibrate; | 32 class TouchEventCalibrate; |
| 30 } | 33 } |
| 31 | 34 |
| 32 class RootWindowHostLinux : public RootWindowHost, | 35 class RootWindowHostLinux : public aura::RootWindowHost, |
| 33 public MessageLoop::Dispatcher { | 36 public MessageLoop::Dispatcher, |
| 37 public aura::WindowObserver, |
| 38 public base::SupportsWeakPtr<RootWindowHostLinux> { |
| 34 public: | 39 public: |
| 35 explicit RootWindowHostLinux(const gfx::Rect& bounds); | 40 explicit RootWindowHostLinux(const gfx::Rect& bounds); |
| 36 virtual ~RootWindowHostLinux(); | 41 virtual ~RootWindowHostLinux(); |
| 37 | 42 |
| 38 // Overridden from Dispatcher overrides: | 43 // Overridden from Dispatcher overrides: |
| 39 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | 44 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
| 40 | 45 |
| 41 // RootWindowHost Overrides. | 46 private: |
| 42 virtual void SetDelegate(RootWindowHostDelegate* delegate) OVERRIDE; | 47 class MouseMoveFilter; |
| 43 virtual RootWindow* GetRootWindow() OVERRIDE; | 48 |
| 49 typedef base::hash_map< ::Window, scoped_refptr<ForeignWindow> > |
| 50 ForeignWindowMap; |
| 51 |
| 52 bool DispatchEventForRootWindow(const base::NativeEvent& event); |
| 53 |
| 54 // Dispatches XI2 events. Note that some events targetted for the X root |
| 55 // window are dispatched to the aura root window (e.g. touch events after |
| 56 // calibration). |
| 57 void DispatchXI2Event(const base::NativeEvent& event); |
| 58 |
| 59 // Overridden from aura::RootWindowHost: |
| 60 virtual void SetDelegate(aura::RootWindowHostDelegate* delegate) OVERRIDE; |
| 61 virtual aura::RootWindow* GetRootWindow() OVERRIDE; |
| 44 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | 62 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; |
| 45 virtual void Show() OVERRIDE; | 63 virtual void Show() OVERRIDE; |
| 46 virtual void Hide() OVERRIDE; | 64 virtual void Hide() OVERRIDE; |
| 47 virtual void ToggleFullScreen() OVERRIDE; | 65 virtual void ToggleFullScreen() OVERRIDE; |
| 48 virtual gfx::Rect GetBounds() const OVERRIDE; | 66 virtual gfx::Rect GetBounds() const OVERRIDE; |
| 49 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | 67 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
| 50 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; | 68 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; |
| 51 virtual void SetCapture() OVERRIDE; | 69 virtual void SetCapture() OVERRIDE; |
| 52 virtual void ReleaseCapture() OVERRIDE; | 70 virtual void ReleaseCapture() OVERRIDE; |
| 53 virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; | 71 virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; |
| 54 virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; | 72 virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; |
| 55 virtual bool ConfineCursorToRootWindow() OVERRIDE; | 73 virtual bool ConfineCursorToRootWindow() OVERRIDE; |
| 56 virtual void UnConfineCursor() OVERRIDE; | 74 virtual void UnConfineCursor() OVERRIDE; |
| 57 virtual void OnCursorVisibilityChanged(bool show) OVERRIDE; | 75 virtual void OnCursorVisibilityChanged(bool show) OVERRIDE; |
| 58 virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE; | 76 virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE; |
| 59 virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE; | 77 virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE; |
| 60 virtual bool CopyAreaToSkCanvas(const gfx::Rect& source_bounds, | 78 virtual bool CopyAreaToSkCanvas(const gfx::Rect& source_bounds, |
| 61 const gfx::Point& dest_offset, | 79 const gfx::Point& dest_offset, |
| 62 SkCanvas* canvas) OVERRIDE; | 80 SkCanvas* canvas) OVERRIDE; |
| 63 virtual bool GrabSnapshot( | 81 virtual bool GrabSnapshot( |
| 64 const gfx::Rect& snapshot_bounds, | 82 const gfx::Rect& snapshot_bounds, |
| 65 std::vector<unsigned char>* png_representation) OVERRIDE; | 83 std::vector<unsigned char>* png_representation) OVERRIDE; |
| 66 virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; | 84 virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; |
| 67 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; | 85 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; |
| 68 virtual void PrepareForShutdown() OVERRIDE; | 86 virtual void PrepareForShutdown() OVERRIDE; |
| 69 | 87 |
| 70 private: | |
| 71 class MouseMoveFilter; | |
| 72 | |
| 73 bool DispatchEventForRootWindow(const base::NativeEvent& event); | |
| 74 | |
| 75 // Dispatches XI2 events. Note that some events targetted for the X root | |
| 76 // window are dispatched to the aura root window (e.g. touch events after | |
| 77 // calibration). | |
| 78 void DispatchXI2Event(const base::NativeEvent& event); | |
| 79 | |
| 80 // Returns true if there's an X window manager present... in most cases. Some | 88 // Returns true if there's an X window manager present... in most cases. Some |
| 81 // window managers (notably, ion3) don't implement enough of ICCCM for us to | 89 // window managers (notably, ion3) don't implement enough of ICCCM for us to |
| 82 // detect that they're there. | 90 // detect that they're there. |
| 83 bool IsWindowManagerPresent(); | 91 bool IsWindowManagerPresent(); |
| 84 | 92 |
| 85 // Sets the cursor on |xwindow_| to |cursor|. Does not check or update | 93 // Sets the cursor on |xwindow_| to |cursor|. Does not check or update |
| 86 // |current_cursor_|. | 94 // |current_cursor_|. |
| 87 void SetCursorInternal(gfx::NativeCursor cursor); | 95 void SetCursorInternal(gfx::NativeCursor cursor); |
| 88 | 96 |
| 89 // Translates the native mouse location into screen coordinates and and | 97 // Translates the native mouse location into screen coordinates and and |
| 90 // dispatches the event to RootWindowHostDelegate. | 98 // dispatches the event to RootWindowHostDelegate. |
| 91 void TranslateAndDispatchMouseEvent(ui::MouseEvent* event); | 99 void TranslateAndDispatchMouseEvent(ui::MouseEvent* event); |
| 92 | 100 |
| 93 // Copies and returns |snapshot_bounds| from |xwindow_|. Helper method for | 101 // Copies and returns |snapshot_bounds| from |xwindow_|. Helper method for |
| 94 // CopyAreaToSkCanvas() and GrabSnapshot(). | 102 // CopyAreaToSkCanvas() and GrabSnapshot(). |
| 95 scoped_ptr<ui::XScopedImage> GetXImage(const gfx::Rect& snapshot_bounds); | 103 scoped_ptr<ui::XScopedImage> GetXImage(const gfx::Rect& snapshot_bounds); |
| 96 | 104 |
| 97 RootWindowHostDelegate* delegate_; | 105 // Overridden from aura::WindowObserver: |
| 106 virtual void OnWindowAdded(aura::Window* window) OVERRIDE; |
| 107 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE; |
| 108 virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE; |
| 109 virtual void OnWindowVisibilityChanged( |
| 110 aura::Window* window, bool visible) OVERRIDE; |
| 111 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 112 const gfx::Rect& old_bounds, |
| 113 const gfx::Rect& new_bounds) OVERRIDE; |
| 114 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 115 |
| 116 ::Window GetTopForeignWindow(const aura::Window* window); |
| 117 ::Window FindForeignWindowToStackAbove(const aura::Window* window); |
| 118 void MapWindowIfNeeded(ForeignWindow* window); |
| 119 void UnmapWindowIfNeeded(ForeignWindow* window); |
| 120 |
| 121 void RecursiveConfigure( |
| 122 aura::Window* window, |
| 123 gfx::Vector2d offset, |
| 124 ::Window* sibling_to_stack_above, |
| 125 SkRegion* input_region); |
| 126 |
| 127 // Configure of native windows. |
| 128 void Configure(); |
| 129 |
| 130 // Schedule deferred configure of native windows. |
| 131 void ScheduleConfigure(aura::Window* window); |
| 132 |
| 133 aura::RootWindowHostDelegate* delegate_; |
| 98 | 134 |
| 99 // The display and the native X window hosting the root window. | 135 // The display and the native X window hosting the root window. |
| 100 Display* xdisplay_; | 136 Display* xdisplay_; |
| 101 ::Window xwindow_; | 137 ::Window xwindow_; |
| 102 | 138 |
| 103 // The native root window. | 139 // The native root window. |
| 104 ::Window x_root_window_; | 140 ::Window x_root_window_; |
| 105 | 141 |
| 106 // Current Aura cursor. | 142 // Current Aura cursor. |
| 107 gfx::NativeCursor current_cursor_; | 143 gfx::NativeCursor current_cursor_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 bool focus_when_shown_; | 155 bool focus_when_shown_; |
| 120 | 156 |
| 121 scoped_ptr<XID[]> pointer_barriers_; | 157 scoped_ptr<XID[]> pointer_barriers_; |
| 122 | 158 |
| 123 scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_; | 159 scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_; |
| 124 | 160 |
| 125 scoped_ptr<MouseMoveFilter> mouse_move_filter_; | 161 scoped_ptr<MouseMoveFilter> mouse_move_filter_; |
| 126 | 162 |
| 127 ui::X11AtomCache atom_cache_; | 163 ui::X11AtomCache atom_cache_; |
| 128 | 164 |
| 165 ForeignWindowMap foreign_windows_; |
| 166 aura::Window* configure_window_; |
| 167 |
| 168 // The native input window. |
| 169 ::Window x_input_window_; |
| 170 |
| 171 // To ensure we set the default cursor for native windows. |
| 172 bool need_to_set_default_cursor_; |
| 173 |
| 129 DISALLOW_COPY_AND_ASSIGN(RootWindowHostLinux); | 174 DISALLOW_COPY_AND_ASSIGN(RootWindowHostLinux); |
| 130 }; | 175 }; |
| 131 | 176 |
| 132 } // namespace aura | 177 } // namespace wm |
| 133 | 178 |
| 134 #endif // UI_AURA_ROOT_WINDOW_HOST_LINUX_H_ | 179 #endif // WM_HOST_ROOT_WINDOW_HOST_LINUX_H_ |
| OLD | NEW |