summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 21:28:04 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 21:28:04 +0000
commit284f766950396abce8f0672c2ccde6b45de25578 (patch)
treea711fe12c1c3ac2aa83e1392f667cdff8b07221f /app
parentb3f2f32e4cdf73df0073930cef7b4d3531df8e5d (diff)
downloadchromium_src-284f766950396abce8f0672c2ccde6b45de25578.zip
chromium_src-284f766950396abce8f0672c2ccde6b45de25578.tar.gz
chromium_src-284f766950396abce8f0672c2ccde6b45de25578.tar.bz2
GTK: Minimize usage of gtk headers.
BUG=none TEST=none Review URL: http://codereview.chromium.org/2891006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/app_base.gypi6
-rw-r--r--app/gtk_integers.h27
-rw-r--r--app/gtk_signal.h55
-rw-r--r--app/gtk_signal_registrar.cc (renamed from app/gtk_signal.cc)4
-rw-r--r--app/gtk_signal_registrar.h66
5 files changed, 102 insertions, 56 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi
index 966bf15..9c23cd2 100644
--- a/app/app_base.gypi
+++ b/app/app_base.gypi
@@ -41,8 +41,9 @@
'sources!': [
'gtk_dnd_util.cc',
'gtk_dnd_util.h',
- 'gtk_signal.cc',
'gtk_signal.h',
+ 'gtk_signal_registrar.cc',
+ 'gtk_signal_registrar.h',
'gtk_util.cc',
'gtk_util.h',
'x11_util.cc',
@@ -137,8 +138,9 @@
'gfx/gl/gl_mock.h',
'gtk_dnd_util.cc',
'gtk_dnd_util.h',
- 'gtk_signal.cc',
'gtk_signal.h',
+ 'gtk_signal_registrar.cc',
+ 'gtk_signal_registrar.h',
'gtk_util.cc',
'gtk_util.h',
'l10n_util.cc',
diff --git a/app/gtk_integers.h b/app/gtk_integers.h
new file mode 100644
index 0000000..7a95847
--- /dev/null
+++ b/app/gtk_integers.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APP_GTK_INTEGERS_H_
+#define APP_GTK_INTEGERS_H_
+
+// GLib/Gobject/Gtk all use their own integer typedefs. They are copied here
+// for forward declaration reasons so we don't pull in all of gtk.h when we
+// just need a gpointer.
+typedef char gchar;
+typedef short gshort;
+typedef long glong;
+typedef int gint;
+typedef gint gboolean;
+typedef unsigned char guchar;
+typedef unsigned short gushort;
+typedef unsigned long gulong;
+typedef unsigned int guint;
+
+typedef unsigned short guint16;
+typedef unsigned int guint32;
+
+typedef void* gpointer;
+typedef const void *gconstpointer;
+
+#endif // APP_GTK_INTEGERS_H_
diff --git a/app/gtk_signal.h b/app/gtk_signal.h
index ffa487b..a3d5f7a 100644
--- a/app/gtk_signal.h
+++ b/app/gtk_signal.h
@@ -5,11 +5,8 @@
#ifndef APP_GTK_SIGNAL_H_
#define APP_GTK_SIGNAL_H_
-#include <gtk/gtk.h>
-#include <map>
-#include <vector>
-
-#include "base/basictypes.h"
+typedef void* gpointer;
+typedef struct _GtkWidget GtkWidget;
// At the time of writing this, there were two common ways of binding our C++
// code to the gobject C system. We either defined a whole bunch of "static
@@ -116,52 +113,4 @@
CHROMEG_CALLBACK_6(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, \
ARG4, ARG5, ARG6);
-// A class that ensures that callbacks don't run on stale owner objects. Similar
-// in spirit to NotificationRegistrar. Use as follows:
-//
-// class ChromeObject {
-// public:
-// ChromeObject() {
-// ...
-//
-// signals_.Connect(widget, "event", CallbackThunk, this);
-// }
-//
-// ...
-//
-// private:
-// GtkSignalRegistrar signals_;
-// };
-//
-// When |signals_| goes down, it will disconnect the handlers connected via
-// Connect.
-class GtkSignalRegistrar {
- public:
- GtkSignalRegistrar();
- ~GtkSignalRegistrar();
-
- // Connect before the default handler. Returns the handler id.
- glong Connect(gpointer instance, const gchar* detailed_signal,
- GCallback signal_handler, gpointer data);
- // Connect after the default handler. Returns the handler id.
- glong ConnectAfter(gpointer instance, const gchar* detailed_signal,
- GCallback signal_handler, gpointer data);
-
- private:
- static void WeakNotifyThunk(gpointer data, GObject* where_the_object_was) {
- reinterpret_cast<GtkSignalRegistrar*>(data)->WeakNotify(
- where_the_object_was);
- }
- void WeakNotify(GObject* where_the_object_was);
-
- glong ConnectInternal(gpointer instance, const gchar* detailed_signal,
- GCallback signal_handler, gpointer data, bool after);
-
- typedef std::vector<glong> HandlerList;
- typedef std::map<GObject*, HandlerList> HandlerMap;
- HandlerMap handler_lists_;
-
- DISALLOW_COPY_AND_ASSIGN(GtkSignalRegistrar);
-};
-
#endif // APP_GTK_SIGNAL_H_
diff --git a/app/gtk_signal.cc b/app/gtk_signal_registrar.cc
index 4db611d..5530405 100644
--- a/app/gtk_signal.cc
+++ b/app/gtk_signal_registrar.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "app/gtk_signal.h"
+#include "app/gtk_signal_registrar.h"
+
+#include <glib-object.h>
#include "base/logging.h"
diff --git a/app/gtk_signal_registrar.h b/app/gtk_signal_registrar.h
new file mode 100644
index 0000000..3f14dbe
--- /dev/null
+++ b/app/gtk_signal_registrar.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APP_GTK_SIGNAL_REGISTRAR_H_
+#define APP_GTK_SIGNAL_REGISTRAR_H_
+
+#include <glib.h>
+#include <map>
+#include <vector>
+
+#include "base/basictypes.h"
+
+typedef void (*GCallback) (void);
+typedef struct _GObject GObject;
+typedef struct _GtkWidget GtkWidget;
+
+// A class that ensures that callbacks don't run on stale owner objects. Similar
+// in spirit to NotificationRegistrar. Use as follows:
+//
+// class ChromeObject {
+// public:
+// ChromeObject() {
+// ...
+//
+// signals_.Connect(widget, "event", CallbackThunk, this);
+// }
+//
+// ...
+//
+// private:
+// GtkSignalRegistrar signals_;
+// };
+//
+// When |signals_| goes down, it will disconnect the handlers connected via
+// Connect.
+class GtkSignalRegistrar {
+ public:
+ GtkSignalRegistrar();
+ ~GtkSignalRegistrar();
+
+ // Connect before the default handler. Returns the handler id.
+ glong Connect(gpointer instance, const gchar* detailed_signal,
+ GCallback signal_handler, gpointer data);
+ // Connect after the default handler. Returns the handler id.
+ glong ConnectAfter(gpointer instance, const gchar* detailed_signal,
+ GCallback signal_handler, gpointer data);
+
+ private:
+ static void WeakNotifyThunk(gpointer data, GObject* where_the_object_was) {
+ reinterpret_cast<GtkSignalRegistrar*>(data)->WeakNotify(
+ where_the_object_was);
+ }
+ void WeakNotify(GObject* where_the_object_was);
+
+ glong ConnectInternal(gpointer instance, const gchar* detailed_signal,
+ GCallback signal_handler, gpointer data, bool after);
+
+ typedef std::vector<glong> HandlerList;
+ typedef std::map<GObject*, HandlerList> HandlerMap;
+ HandlerMap handler_lists_;
+
+ DISALLOW_COPY_AND_ASSIGN(GtkSignalRegistrar);
+};
+
+#endif // APP_GTK_SIGNAL_REGISTRAR_H_