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

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

Issue 9151007: GTK: Seal up GSEALs, focusing on GtkSelectionData. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add gtk_widget_style_attach to make minimal version 2.18 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
« 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 = widget->window; 72 GdkWindow *gdk_window = gtk_widget_get_window(widget);
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(i->second.widget->window); 131 *output = GDK_WINDOW_XID(gtk_widget_get_window(i->second.widget));
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);
211 210
212 i->second.x_window_id = GDK_WINDOW_XID(widget->window); 211 GdkWindow* gdk_window = gtk_widget_get_window(widget);
212 CHECK(gdk_window);
213 i->second.x_window_id = GDK_WINDOW_XID(gdk_window);
213 } 214 }
214 215
215 void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) { 216 void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) {
216 base::AutoLock locked(lock_); 217 base::AutoLock locked(lock_);
217 218
218 const gfx::NativeViewId id = GetWidgetId(widget); 219 const gfx::NativeViewId id = GetWidgetId(widget);
219 std::map<gfx::NativeViewId, NativeViewInfo>::iterator i = 220 std::map<gfx::NativeViewId, NativeViewInfo>::iterator i =
220 id_to_info_.find(id); 221 id_to_info_.find(id);
221 222
222 CHECK(i != id_to_info_.end()); 223 CHECK(i != id_to_info_.end());
223 } 224 }
224 225
225 void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) { 226 void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) {
226 base::AutoLock locked(lock_); 227 base::AutoLock locked(lock_);
227 228
228 std::map<gfx::NativeView, gfx::NativeViewId>::iterator i = 229 std::map<gfx::NativeView, gfx::NativeViewId>::iterator i =
229 native_view_to_id_.find(widget); 230 native_view_to_id_.find(widget);
230 CHECK(i != native_view_to_id_.end()); 231 CHECK(i != native_view_to_id_.end());
231 232
232 std::map<gfx::NativeViewId, NativeViewInfo>::iterator j = 233 std::map<gfx::NativeViewId, NativeViewInfo>::iterator j =
233 id_to_info_.find(i->second); 234 id_to_info_.find(i->second);
234 CHECK(j != id_to_info_.end()); 235 CHECK(j != id_to_info_.end());
235 236
236 // If the XID is supposed to outlive the widget, mark it 237 // If the XID is supposed to outlive the widget, mark it
237 // in the lookup table. 238 // in the lookup table.
238 if (GTK_IS_PRESERVE_WINDOW(widget) && 239 if (GTK_IS_PRESERVE_WINDOW(widget) &&
239 gtk_preserve_window_get_preserve( 240 gtk_preserve_window_get_preserve(
240 reinterpret_cast<GtkPreserveWindow*>(widget))) { 241 reinterpret_cast<GtkPreserveWindow*>(widget))) {
241 std::map<XID, PermanentXIDInfo>::iterator k = 242 std::map<XID, PermanentXIDInfo>::iterator k =
242 perm_xid_to_info_.find(GDK_WINDOW_XID(widget->window)); 243 perm_xid_to_info_.find(GDK_WINDOW_XID(gtk_widget_get_window(widget)));
243 244
244 if (k != perm_xid_to_info_.end()) 245 if (k != perm_xid_to_info_.end())
245 k->second.widget = NULL; 246 k->second.widget = NULL;
246 } 247 }
247 248
248 native_view_to_id_.erase(i); 249 native_view_to_id_.erase(i);
249 id_to_info_.erase(j); 250 id_to_info_.erase(j);
250 } 251 }
251 252
252 // ----------------------------------------------------------------------------- 253 // -----------------------------------------------------------------------------
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