Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: ui/gfx/gtk_native_view_id_manager.cc

Issue 9167002: Revert 116956 - GTK: Seal up GSEALs, focusing on GtkSelectionData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/x/x11_util.cc ('k') | ui/gfx/gtk_preserve_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return i->second; 62 return i->second;
63 63
64 gfx::NativeViewId new_id = 64 gfx::NativeViewId new_id =
65 static_cast<gfx::NativeViewId>(base::RandUint64()); 65 static_cast<gfx::NativeViewId>(base::RandUint64());
66 while (id_to_info_.find(new_id) != id_to_info_.end()) 66 while (id_to_info_.find(new_id) != id_to_info_.end())
67 new_id = static_cast<gfx::NativeViewId>(base::RandUint64()); 67 new_id = static_cast<gfx::NativeViewId>(base::RandUint64());
68 68
69 NativeViewInfo info; 69 NativeViewInfo info;
70 info.widget = widget; 70 info.widget = widget;
71 if (gtk_widget_get_realized(widget)) { 71 if (gtk_widget_get_realized(widget)) {
72 GdkWindow *gdk_window = gtk_widget_get_window(widget); 72 GdkWindow *gdk_window = widget->window;
73 DCHECK(gdk_window); 73 DCHECK(gdk_window);
74 info.x_window_id = GDK_WINDOW_XID(gdk_window); 74 info.x_window_id = GDK_WINDOW_XID(gdk_window);
75 } 75 }
76 76
77 native_view_to_id_[widget] = new_id; 77 native_view_to_id_[widget] = new_id;
78 id_to_info_[new_id] = info; 78 id_to_info_[new_id] = info;
79 79
80 g_signal_connect(widget, "realize", G_CALLBACK(::OnRealize), this); 80 g_signal_connect(widget, "realize", G_CALLBACK(::OnRealize), this);
81 g_signal_connect(widget, "unrealize", G_CALLBACK(::OnUnrealize), this); 81 g_signal_connect(widget, "unrealize", G_CALLBACK(::OnUnrealize), this);
82 g_signal_connect(widget, "destroy", G_CALLBACK(::OnDestroy), this); 82 g_signal_connect(widget, "destroy", G_CALLBACK(::OnDestroy), this);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (i == id_to_info_.end()) 121 if (i == id_to_info_.end())
122 return false; 122 return false;
123 123
124 // We only return permanent XIDs for widgets that allow us to guarantee that 124 // We only return permanent XIDs for widgets that allow us to guarantee that
125 // the XID will not change. 125 // the XID will not change.
126 DCHECK(GTK_IS_PRESERVE_WINDOW(i->second.widget)); 126 DCHECK(GTK_IS_PRESERVE_WINDOW(i->second.widget));
127 GtkPreserveWindow* widget = 127 GtkPreserveWindow* widget =
128 reinterpret_cast<GtkPreserveWindow*>(i->second.widget); 128 reinterpret_cast<GtkPreserveWindow*>(i->second.widget);
129 gtk_preserve_window_set_preserve(widget, TRUE); 129 gtk_preserve_window_set_preserve(widget, TRUE);
130 130
131 *output = GDK_WINDOW_XID(gtk_widget_get_window(i->second.widget)); 131 *output = GDK_WINDOW_XID(i->second.widget->window);
132 132
133 // Update the reference count on the permanent XID. 133 // Update the reference count on the permanent XID.
134 PermanentXIDInfo info; 134 PermanentXIDInfo info;
135 info.widget = widget; 135 info.widget = widget;
136 info.ref_count = 1; 136 info.ref_count = 1;
137 std::pair<std::map<XID, PermanentXIDInfo>::iterator, bool> ret = 137 std::pair<std::map<XID, PermanentXIDInfo>::iterator, bool> ret =
138 perm_xid_to_info_.insert(std::make_pair(*output, info)); 138 perm_xid_to_info_.insert(std::make_pair(*output, info));
139 139
140 if (!ret.second) { 140 if (!ret.second) {
141 DCHECK(ret.first->second.widget == widget); 141 DCHECK(ret.first->second.widget == widget);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 void GtkNativeViewManager::OnRealize(gfx::NativeView widget) { 202 void GtkNativeViewManager::OnRealize(gfx::NativeView widget) {
203 base::AutoLock locked(lock_); 203 base::AutoLock locked(lock_);
204 204
205 const gfx::NativeViewId id = GetWidgetId(widget); 205 const gfx::NativeViewId id = GetWidgetId(widget);
206 std::map<gfx::NativeViewId, NativeViewInfo>::iterator i = 206 std::map<gfx::NativeViewId, NativeViewInfo>::iterator i =
207 id_to_info_.find(id); 207 id_to_info_.find(id);
208 208
209 CHECK(i != id_to_info_.end()); 209 CHECK(i != id_to_info_.end());
210 CHECK(widget->window);
210 211
211 GdkWindow* gdk_window = gtk_widget_get_window(widget); 212 i->second.x_window_id = GDK_WINDOW_XID(widget->window);
212 CHECK(gdk_window);
213 i->second.x_window_id = GDK_WINDOW_XID(gdk_window);
214 } 213 }
215 214
216 void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) { 215 void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) {
217 base::AutoLock locked(lock_); 216 base::AutoLock locked(lock_);
218 217
219 const gfx::NativeViewId id = GetWidgetId(widget); 218 const gfx::NativeViewId id = GetWidgetId(widget);
220 std::map<gfx::NativeViewId, NativeViewInfo>::iterator i = 219 std::map<gfx::NativeViewId, NativeViewInfo>::iterator i =
221 id_to_info_.find(id); 220 id_to_info_.find(id);
222 221
223 CHECK(i != id_to_info_.end()); 222 CHECK(i != id_to_info_.end());
224 } 223 }
225 224
226 void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) { 225 void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) {
227 base::AutoLock locked(lock_); 226 base::AutoLock locked(lock_);
228 227
229 std::map<gfx::NativeView, gfx::NativeViewId>::iterator i = 228 std::map<gfx::NativeView, gfx::NativeViewId>::iterator i =
230 native_view_to_id_.find(widget); 229 native_view_to_id_.find(widget);
231 CHECK(i != native_view_to_id_.end()); 230 CHECK(i != native_view_to_id_.end());
232 231
233 std::map<gfx::NativeViewId, NativeViewInfo>::iterator j = 232 std::map<gfx::NativeViewId, NativeViewInfo>::iterator j =
234 id_to_info_.find(i->second); 233 id_to_info_.find(i->second);
235 CHECK(j != id_to_info_.end()); 234 CHECK(j != id_to_info_.end());
236 235
237 // If the XID is supposed to outlive the widget, mark it 236 // If the XID is supposed to outlive the widget, mark it
238 // in the lookup table. 237 // in the lookup table.
239 if (GTK_IS_PRESERVE_WINDOW(widget) && 238 if (GTK_IS_PRESERVE_WINDOW(widget) &&
240 gtk_preserve_window_get_preserve( 239 gtk_preserve_window_get_preserve(
241 reinterpret_cast<GtkPreserveWindow*>(widget))) { 240 reinterpret_cast<GtkPreserveWindow*>(widget))) {
242 std::map<XID, PermanentXIDInfo>::iterator k = 241 std::map<XID, PermanentXIDInfo>::iterator k =
243 perm_xid_to_info_.find(GDK_WINDOW_XID(gtk_widget_get_window(widget))); 242 perm_xid_to_info_.find(GDK_WINDOW_XID(widget->window));
244 243
245 if (k != perm_xid_to_info_.end()) 244 if (k != perm_xid_to_info_.end())
246 k->second.widget = NULL; 245 k->second.widget = NULL;
247 } 246 }
248 247
249 native_view_to_id_.erase(i); 248 native_view_to_id_.erase(i);
250 id_to_info_.erase(j); 249 id_to_info_.erase(j);
251 } 250 }
252 251
253 // ----------------------------------------------------------------------------- 252 // -----------------------------------------------------------------------------
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.cc ('k') | ui/gfx/gtk_preserve_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698