OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ | 5 #ifndef GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ |
6 #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ | 6 #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // | 56 // |
57 // If the widget referenced by |id| does not current have an X window id, | 57 // If the widget referenced by |id| does not current have an X window id, |
58 // |*xid| is set to 0. | 58 // |*xid| is set to 0. |
59 bool GetXIDForId(XID* xid, gfx::NativeViewId id); | 59 bool GetXIDForId(XID* xid, gfx::NativeViewId id); |
60 | 60 |
61 // These are actually private functions, but need to be called from statics. | 61 // These are actually private functions, but need to be called from statics. |
62 void OnRealize(gfx::NativeView widget); | 62 void OnRealize(gfx::NativeView widget); |
63 void OnUnrealize(gfx::NativeView widget); | 63 void OnUnrealize(gfx::NativeView widget); |
64 void OnDestroy(gfx::NativeView widget); | 64 void OnDestroy(gfx::NativeView widget); |
65 | 65 |
| 66 Lock& unrealize_lock() { return unrealize_lock_; } |
| 67 |
66 private: | 68 private: |
67 // This object is a singleton: | 69 // This object is a singleton: |
68 GtkNativeViewManager(); | 70 GtkNativeViewManager(); |
69 friend struct DefaultSingletonTraits<GtkNativeViewManager>; | 71 friend struct DefaultSingletonTraits<GtkNativeViewManager>; |
70 | 72 |
71 struct NativeViewInfo { | 73 struct NativeViewInfo { |
72 NativeViewInfo() | 74 NativeViewInfo() |
73 : x_window_id(0) { | 75 : x_window_id(0) { |
74 } | 76 } |
75 | 77 |
76 XID x_window_id; | 78 XID x_window_id; |
77 }; | 79 }; |
78 | 80 |
79 gfx::NativeViewId GetWidgetId(gfx::NativeView id); | 81 gfx::NativeViewId GetWidgetId(gfx::NativeView id); |
80 | 82 |
| 83 // This lock can be used to block GTK from unrealizing windows. This is needed |
| 84 // when the BACKGROUND_X11 thread is using a window obtained via GetXIDForId, |
| 85 // and can't allow the X11 resource to be deleted. |
| 86 Lock unrealize_lock_; |
| 87 |
81 // protects native_view_to_id_ and id_to_info_ | 88 // protects native_view_to_id_ and id_to_info_ |
82 Lock lock_; | 89 Lock lock_; |
83 // If asked for an id for the same widget twice, we want to return the same | 90 |
84 // id. So this records the current mapping. | 91 // If asked for an id for the same widget twice, we want to return the same |
85 std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; | 92 // id. So this records the current mapping. |
86 std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; | 93 std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; |
| 94 std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; |
87 | 95 |
88 DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); | 96 DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); |
89 }; | 97 }; |
90 | 98 |
91 #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ | 99 #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ |
OLD | NEW |