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 #ifndef UI_BASE_GTK_GTK_SIGNAL_REGISTRAR_H_ | 5 #ifndef UI_BASE_GTK_GTK_SIGNAL_REGISTRAR_H_ |
6 #define UI_BASE_GTK_GTK_SIGNAL_REGISTRAR_H_ | 6 #define UI_BASE_GTK_GTK_SIGNAL_REGISTRAR_H_ |
7 | 7 |
8 #include <glib.h> | 8 #include <glib.h> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "ui/base/ui_export.h" | 13 #include "ui/base/ui_base_export.h" |
14 | 14 |
15 typedef void (*GCallback) (void); | 15 typedef void (*GCallback) (void); |
16 typedef struct _GObject GObject; | 16 typedef struct _GObject GObject; |
17 typedef struct _GtkWidget GtkWidget; | 17 typedef struct _GtkWidget GtkWidget; |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 // A class that ensures that callbacks don't run on stale owner objects. Similar | 21 // A class that ensures that callbacks don't run on stale owner objects. Similar |
22 // in spirit to NotificationRegistrar. Use as follows: | 22 // in spirit to NotificationRegistrar. Use as follows: |
23 // | 23 // |
24 // class ChromeObject { | 24 // class ChromeObject { |
25 // public: | 25 // public: |
26 // ChromeObject() { | 26 // ChromeObject() { |
27 // ... | 27 // ... |
28 // | 28 // |
29 // signals_.Connect(widget, "event", CallbackThunk, this); | 29 // signals_.Connect(widget, "event", CallbackThunk, this); |
30 // } | 30 // } |
31 // | 31 // |
32 // ... | 32 // ... |
33 // | 33 // |
34 // private: | 34 // private: |
35 // GtkSignalRegistrar signals_; | 35 // GtkSignalRegistrar signals_; |
36 // }; | 36 // }; |
37 // | 37 // |
38 // When |signals_| goes down, it will disconnect the handlers connected via | 38 // When |signals_| goes down, it will disconnect the handlers connected via |
39 // Connect. | 39 // Connect. |
40 class UI_EXPORT GtkSignalRegistrar { | 40 class UI_BASE_EXPORT GtkSignalRegistrar { |
41 public: | 41 public: |
42 GtkSignalRegistrar(); | 42 GtkSignalRegistrar(); |
43 ~GtkSignalRegistrar(); | 43 ~GtkSignalRegistrar(); |
44 | 44 |
45 // Connect before the default handler. Returns the handler id. | 45 // Connect before the default handler. Returns the handler id. |
46 glong Connect(gpointer instance, const gchar* detailed_signal, | 46 glong Connect(gpointer instance, const gchar* detailed_signal, |
47 GCallback signal_handler, gpointer data); | 47 GCallback signal_handler, gpointer data); |
48 // Connect after the default handler. Returns the handler id. | 48 // Connect after the default handler. Returns the handler id. |
49 glong ConnectAfter(gpointer instance, const gchar* detailed_signal, | 49 glong ConnectAfter(gpointer instance, const gchar* detailed_signal, |
50 GCallback signal_handler, gpointer data); | 50 GCallback signal_handler, gpointer data); |
(...skipping 15 matching lines...) Expand all Loading... |
66 GCallback signal_handler, gpointer data, bool after); | 66 GCallback signal_handler, gpointer data, bool after); |
67 | 67 |
68 HandlerMap handler_lists_; | 68 HandlerMap handler_lists_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(GtkSignalRegistrar); | 70 DISALLOW_COPY_AND_ASSIGN(GtkSignalRegistrar); |
71 }; | 71 }; |
72 | 72 |
73 } // namespace ui | 73 } // namespace ui |
74 | 74 |
75 #endif // UI_BASE_GTK_GTK_SIGNAL_REGISTRAR_H_ | 75 #endif // UI_BASE_GTK_GTK_SIGNAL_REGISTRAR_H_ |
OLD | NEW |