OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PLATFORM_WINDOW_X11_X11_WINDOW_H_ | 5 #ifndef UI_PLATFORM_WINDOW_X11_X11_WINDOW_H_ |
6 #define UI_PLATFORM_WINDOW_X11_X11_WINDOW_H_ | 6 #define UI_PLATFORM_WINDOW_X11_X11_WINDOW_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" |
8 #include "ui/events/platform/platform_event_dispatcher.h" | 12 #include "ui/events/platform/platform_event_dispatcher.h" |
9 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
10 #include "ui/gfx/x/x11_atom_cache.h" | 14 #include "ui/gfx/x/x11_atom_cache.h" |
11 #include "ui/platform_window/platform_window.h" | 15 #include "ui/platform_window/platform_window.h" |
12 #include "ui/platform_window/platform_window_delegate.h" | 16 #include "ui/platform_window/platform_window_delegate.h" |
13 #include "ui/platform_window/x11/x11_window_export.h" | 17 #include "ui/platform_window/x11/x11_window_export.h" |
14 | 18 |
15 typedef struct _XDisplay XDisplay; | 19 typedef struct _XDisplay XDisplay; |
| 20 typedef union _XEvent XEvent; |
16 typedef unsigned long XID; | 21 typedef unsigned long XID; |
17 | 22 |
18 namespace ui { | 23 namespace ui { |
| 24 class X11Window; |
| 25 typedef base::Callback<void(XID, X11Window*)> WindowStatusCallback; |
| 26 |
| 27 class X11_WINDOW_EXPORT X11WindowManager |
| 28 : public base::RefCounted<X11WindowManager> { |
| 29 public: |
| 30 X11WindowManager(); |
| 31 |
| 32 scoped_ptr<X11Window> CreatePlatformWindow(PlatformWindowDelegate* delegate); |
| 33 X11Window* FindWindow(XID id); |
| 34 |
| 35 private: |
| 36 friend class base::RefCounted<X11WindowManager>; |
| 37 |
| 38 virtual ~X11WindowManager(); |
| 39 |
| 40 void OnWindowCreate(XID id, X11Window* window); |
| 41 void OnWindowDestroy(XID id, X11Window* window); |
| 42 |
| 43 std::map<XID, X11Window*> window_map_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(X11WindowManager); |
| 46 }; |
19 | 47 |
20 class X11_WINDOW_EXPORT X11Window : public PlatformWindow, | 48 class X11_WINDOW_EXPORT X11Window : public PlatformWindow, |
21 public PlatformEventDispatcher { | 49 public PlatformEventDispatcher { |
22 public: | 50 public: |
23 explicit X11Window(PlatformWindowDelegate* delegate); | 51 explicit X11Window(PlatformWindowDelegate* delegate, |
| 52 WindowStatusCallback on_create_callback, |
| 53 WindowStatusCallback on_destroy_callback); |
24 ~X11Window() override; | 54 ~X11Window() override; |
25 | 55 |
26 private: | 56 void Create(); |
27 void Destroy(); | |
28 | 57 |
29 void ProcessXInput2Event(XEvent* xevent); | 58 void ProcessWindowEvent(XEvent* xev); |
30 | 59 |
31 // PlatformWindow: | 60 // PlatformWindow: |
32 void Show() override; | 61 void Show() override; |
33 void Hide() override; | 62 void Hide() override; |
34 void Close() override; | 63 void Close() override; |
35 void SetBounds(const gfx::Rect& bounds) override; | 64 void SetBounds(const gfx::Rect& bounds) override; |
36 gfx::Rect GetBounds() override; | 65 gfx::Rect GetBounds() override; |
37 void SetCapture() override; | 66 void SetCapture() override; |
38 void ReleaseCapture() override; | 67 void ReleaseCapture() override; |
39 void ToggleFullscreen() override; | 68 void ToggleFullscreen() override; |
40 void Maximize() override; | 69 void Maximize() override; |
41 void Minimize() override; | 70 void Minimize() override; |
42 void Restore() override; | 71 void Restore() override; |
43 void SetCursor(PlatformCursor cursor) override; | 72 void SetCursor(PlatformCursor cursor) override; |
44 void MoveCursorTo(const gfx::Point& location) override; | 73 void MoveCursorTo(const gfx::Point& location) override; |
45 | 74 |
| 75 private: |
| 76 void Destroy(); |
| 77 |
46 // PlatformEventDispatcher: | 78 // PlatformEventDispatcher: |
47 bool CanDispatchEvent(const PlatformEvent& event) override; | 79 bool CanDispatchEvent(const PlatformEvent& event) override; |
48 uint32_t DispatchEvent(const PlatformEvent& event) override; | 80 uint32_t DispatchEvent(const PlatformEvent& event) override; |
49 | 81 |
50 PlatformWindowDelegate* delegate_; | 82 PlatformWindowDelegate* delegate_; |
51 | 83 |
| 84 WindowStatusCallback on_create_callback_; |
| 85 WindowStatusCallback on_destroy_callback_; |
| 86 |
52 XDisplay* xdisplay_; | 87 XDisplay* xdisplay_; |
53 XID xwindow_; | 88 XID xwindow_; |
54 XID xroot_window_; | 89 XID xroot_window_; |
55 X11AtomCache atom_cache_; | 90 X11AtomCache atom_cache_; |
56 | 91 |
57 // Setting the bounds is an asynchronous operation in X11. |requested_bounds_| | 92 // Setting the bounds is an asynchronous operation in X11. |requested_bounds_| |
58 // is the bounds requested using XConfigureWindow, and |confirmed_bounds_| is | 93 // is the bounds requested using XConfigureWindow, and |confirmed_bounds_| is |
59 // the bounds the X11 server has set on the window. | 94 // the bounds the X11 server has set on the window. |
60 gfx::Rect requested_bounds_; | 95 gfx::Rect requested_bounds_; |
61 gfx::Rect confirmed_bounds_; | 96 gfx::Rect confirmed_bounds_; |
62 | 97 |
63 bool window_mapped_; | 98 bool window_mapped_; |
64 | 99 |
65 DISALLOW_COPY_AND_ASSIGN(X11Window); | 100 DISALLOW_COPY_AND_ASSIGN(X11Window); |
66 }; | 101 }; |
67 | 102 |
68 } // namespace ui | 103 } // namespace ui |
69 | 104 |
70 #endif // UI_PLATFORM_WINDOW_X11_X11_WINDOW_H_ | 105 #endif // UI_PLATFORM_WINDOW_X11_X11_WINDOW_H_ |
OLD | NEW |