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