OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "ui/gfx/gtk_native_view_id_manager.h" | 5 #include "ui/gfx/gtk_native_view_id_manager.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "ui/base/gtk/gtk_compat.h" |
12 #include "ui/gfx/gtk_preserve_window.h" | 13 #include "ui/gfx/gtk_preserve_window.h" |
13 | 14 |
14 // ----------------------------------------------------------------------------- | 15 // ----------------------------------------------------------------------------- |
15 // Bounce functions for GTK to callback into a C++ object... | 16 // Bounce functions for GTK to callback into a C++ object... |
16 | 17 |
17 void OnRealize(gfx::NativeView widget, void* arg) { | 18 void OnRealize(gfx::NativeView widget, void* arg) { |
18 GtkNativeViewManager* manager = reinterpret_cast<GtkNativeViewManager*>(arg); | 19 GtkNativeViewManager* manager = reinterpret_cast<GtkNativeViewManager*>(arg); |
19 manager->OnRealize(widget); | 20 manager->OnRealize(widget); |
20 } | 21 } |
21 | 22 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (i != native_view_to_id_.end()) | 60 if (i != native_view_to_id_.end()) |
60 return i->second; | 61 return i->second; |
61 | 62 |
62 gfx::NativeViewId new_id = | 63 gfx::NativeViewId new_id = |
63 static_cast<gfx::NativeViewId>(base::RandUint64()); | 64 static_cast<gfx::NativeViewId>(base::RandUint64()); |
64 while (id_to_info_.find(new_id) != id_to_info_.end()) | 65 while (id_to_info_.find(new_id) != id_to_info_.end()) |
65 new_id = static_cast<gfx::NativeViewId>(base::RandUint64()); | 66 new_id = static_cast<gfx::NativeViewId>(base::RandUint64()); |
66 | 67 |
67 NativeViewInfo info; | 68 NativeViewInfo info; |
68 info.widget = widget; | 69 info.widget = widget; |
69 if (GTK_WIDGET_REALIZED(widget)) { | 70 if (gtk_widget_get_realized(widget)) { |
70 GdkWindow *gdk_window = widget->window; | 71 GdkWindow *gdk_window = widget->window; |
71 DCHECK(gdk_window); | 72 DCHECK(gdk_window); |
72 info.x_window_id = GDK_WINDOW_XID(gdk_window); | 73 info.x_window_id = GDK_WINDOW_XID(gdk_window); |
73 } | 74 } |
74 | 75 |
75 native_view_to_id_[widget] = new_id; | 76 native_view_to_id_[widget] = new_id; |
76 id_to_info_[new_id] = info; | 77 id_to_info_[new_id] = info; |
77 | 78 |
78 g_signal_connect(widget, "realize", G_CALLBACK(::OnRealize), this); | 79 g_signal_connect(widget, "realize", G_CALLBACK(::OnRealize), this); |
79 g_signal_connect(widget, "unrealize", G_CALLBACK(::OnUnrealize), this); | 80 g_signal_connect(widget, "unrealize", G_CALLBACK(::OnUnrealize), this); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 242 |
242 if (k != perm_xid_to_info_.end()) | 243 if (k != perm_xid_to_info_.end()) |
243 k->second.widget = NULL; | 244 k->second.widget = NULL; |
244 } | 245 } |
245 | 246 |
246 native_view_to_id_.erase(i); | 247 native_view_to_id_.erase(i); |
247 id_to_info_.erase(j); | 248 id_to_info_.erase(j); |
248 } | 249 } |
249 | 250 |
250 // ----------------------------------------------------------------------------- | 251 // ----------------------------------------------------------------------------- |
OLD | NEW |