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

Side by Side Diff: chrome/browser/gtk/rounded_window.cc

Issue 1783010: GTK: more signal handler foolproofing. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 7 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 | « chrome/browser/gtk/options/content_page_gtk.cc ('k') | no next file » | 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) 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 #include "chrome/browser/gtk/rounded_window.h" 5 #include "chrome/browser/gtk/rounded_window.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include "app/gtk_signal.h"
10 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
11 #include "chrome/browser/gtk/gtk_util.h" 12 #include "chrome/browser/gtk/gtk_util.h"
12 13
13 namespace gtk_util { 14 namespace gtk_util {
14 15
15 namespace { 16 namespace {
16 17
17 const char* kRoundedData = "rounded-window-data"; 18 const char* kRoundedData = "rounded-window-data";
18 19
19 // If the border radius is less than |kMinRoundedBorderSize|, we don't actually 20 // If the border radius is less than |kMinRoundedBorderSize|, we don't actually
20 // round the corners, we just truncate the corner. 21 // round the corners, we just truncate the corner.
21 const int kMinRoundedBorderSize = 8; 22 const int kMinRoundedBorderSize = 8;
22 23
23 struct RoundedWindowData { 24 struct RoundedWindowData {
24 // Expected window size. Used to detect when we need to reshape the window. 25 // Expected window size. Used to detect when we need to reshape the window.
25 int expected_width; 26 int expected_width;
26 int expected_height; 27 int expected_height;
27 28
28 // Color of the border. 29 // Color of the border.
29 GdkColor border_color; 30 GdkColor border_color;
30 31
31 // Radius of the edges in pixels. 32 // Radius of the edges in pixels.
32 int corner_size; 33 int corner_size;
33 34
34 // Which corners should be rounded? 35 // Which corners should be rounded?
35 int rounded_edges; 36 int rounded_edges;
36 37
37 // Which sides of the window should have an internal border? 38 // Which sides of the window should have an internal border?
38 int drawn_borders; 39 int drawn_borders;
40
41 // Keeps track of attached signal handlers.
42 GtkSignalRegistrar signals;
39 }; 43 };
40 44
41 // Callback from GTK to release allocated memory. 45 // Callback from GTK to release allocated memory.
42 void FreeRoundedWindowData(gpointer data) { 46 void FreeRoundedWindowData(gpointer data) {
43 delete static_cast<RoundedWindowData*>(data); 47 delete static_cast<RoundedWindowData*>(data);
44 } 48 }
45 49
46 enum FrameType { 50 enum FrameType {
47 FRAME_MASK, 51 FRAME_MASK,
48 FRAME_STROKE, 52 FRAME_STROKE,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 253
250 } // namespace 254 } // namespace
251 255
252 void ActAsRoundedWindow( 256 void ActAsRoundedWindow(
253 GtkWidget* widget, const GdkColor& color, int corner_size, 257 GtkWidget* widget, const GdkColor& color, int corner_size,
254 int rounded_edges, int drawn_borders) { 258 int rounded_edges, int drawn_borders) {
255 DCHECK(widget); 259 DCHECK(widget);
256 DCHECK(!g_object_get_data(G_OBJECT(widget), kRoundedData)); 260 DCHECK(!g_object_get_data(G_OBJECT(widget), kRoundedData));
257 261
258 gtk_widget_set_app_paintable(widget, TRUE); 262 gtk_widget_set_app_paintable(widget, TRUE);
259 g_signal_connect(widget, "expose-event",
260 G_CALLBACK(OnRoundedWindowExpose), NULL);
261 g_signal_connect(widget, "style-set", G_CALLBACK(OnStyleSet), NULL);
262 263
263 RoundedWindowData* data = new RoundedWindowData; 264 RoundedWindowData* data = new RoundedWindowData;
265 data->signals.Connect(widget, "expose-event",
266 G_CALLBACK(OnRoundedWindowExpose), NULL);
267 data->signals.Connect(widget, "style-set", G_CALLBACK(OnStyleSet), NULL);
268
264 data->expected_width = -1; 269 data->expected_width = -1;
265 data->expected_height = -1; 270 data->expected_height = -1;
266 271
267 data->border_color = color; 272 data->border_color = color;
268 data->corner_size = corner_size; 273 data->corner_size = corner_size;
269 274
270 data->rounded_edges = rounded_edges; 275 data->rounded_edges = rounded_edges;
271 data->drawn_borders = drawn_borders; 276 data->drawn_borders = drawn_borders;
272 277
273 g_object_set_data_full(G_OBJECT(widget), kRoundedData, 278 g_object_set_data_full(G_OBJECT(widget), kRoundedData,
274 data, FreeRoundedWindowData); 279 data, FreeRoundedWindowData);
275 } 280 }
276 281
277 void StopActingAsRoundedWindow(GtkWidget* widget) { 282 void StopActingAsRoundedWindow(GtkWidget* widget) {
278 g_signal_handlers_disconnect_by_func(widget, 283 g_object_set_data(G_OBJECT(widget), kRoundedData, NULL);
279 reinterpret_cast<gpointer>(OnRoundedWindowExpose), NULL);
280 g_signal_handlers_disconnect_by_func(widget,
281 reinterpret_cast<gpointer>(OnStyleSet), NULL);
282
283 delete static_cast<RoundedWindowData*>(
284 g_object_steal_data(G_OBJECT(widget), kRoundedData));
285 284
286 if (GTK_WIDGET_REALIZED(widget)) 285 if (GTK_WIDGET_REALIZED(widget))
287 gdk_window_shape_combine_mask(widget->window, NULL, 0, 0); 286 gdk_window_shape_combine_mask(widget->window, NULL, 0, 0);
288 } 287 }
289 288
290 bool IsActingAsRoundedWindow(GtkWidget* widget) { 289 bool IsActingAsRoundedWindow(GtkWidget* widget) {
291 return g_object_get_data(G_OBJECT(widget), kRoundedData) != NULL; 290 return g_object_get_data(G_OBJECT(widget), kRoundedData) != NULL;
292 } 291 }
293 292
294 void SetRoundedWindowEdgesAndBorders(GtkWidget* widget, 293 void SetRoundedWindowEdgesAndBorders(GtkWidget* widget,
(...skipping 11 matching lines...) Expand all
306 305
307 void SetRoundedWindowBorderColor(GtkWidget* widget, GdkColor color) { 306 void SetRoundedWindowBorderColor(GtkWidget* widget, GdkColor color) {
308 DCHECK(widget); 307 DCHECK(widget);
309 RoundedWindowData* data = static_cast<RoundedWindowData*>( 308 RoundedWindowData* data = static_cast<RoundedWindowData*>(
310 g_object_get_data(G_OBJECT(widget), kRoundedData)); 309 g_object_get_data(G_OBJECT(widget), kRoundedData));
311 DCHECK(data); 310 DCHECK(data);
312 data->border_color = color; 311 data->border_color = color;
313 } 312 }
314 313
315 } // namespace gtk_util 314 } // namespace gtk_util
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/content_page_gtk.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698