From df6dd4618bfdf4915229349a6dc967890fbf8470 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 27 Sep 2006 14:45:55 +0200 Subject: [PATCH] Open "requested" popups in a new activity --- activities/browser/BrowserActivity.py | 13 ++++++++- bindings/gecko/Makefile.am | 1 + bindings/gecko/gecko-browser.cpp | 42 ++++++++++++++++++++++++++- bindings/gecko/gecko-browser.h | 28 ++++++++++++++++-- bindings/gecko/gecko.defs | 31 ++++++++++++++++++-- bindings/gecko/gecko.override | 11 +++++++ bindings/gecko/geckomodule.c | 4 +++ configure.ac | 5 +++- 8 files changed, 128 insertions(+), 7 deletions(-) diff --git a/activities/browser/BrowserActivity.py b/activities/browser/BrowserActivity.py index 8a315b43..01075ede 100644 --- a/activities/browser/BrowserActivity.py +++ b/activities/browser/BrowserActivity.py @@ -2,6 +2,7 @@ import os import gtk import gtkmozembed +import gobject from sugar.activity.Activity import Activity from sugar.presence.PresenceService import PresenceService @@ -13,6 +14,16 @@ from NotificationBar import NotificationBar from NavigationToolbar import NavigationToolbar from sugar import env +class Browser(gecko.Browser): + __gtype_name__ = "SugarBrowser" + def __init__(self): + gecko.Browser.__init__(self) + + def do_create_window(self): + activity = BrowserActivity() + activity.set_type('com.redhat.Sugar.BrowserActivity') + return activity.get_embed() + class BrowserActivity(Activity): def __init__(self): Activity.__init__(self) @@ -35,7 +46,7 @@ class BrowserActivity(Activity): vbox.pack_start(self._notif_bar, False) self._notif_bar.connect('action', self.__notif_bar_action_cb) - self._embed = gtkmozembed.MozEmbed() + self._embed = Browser() self._embed.connect("title", self.__title_cb) vbox.pack_start(self._embed) self._embed.show() diff --git a/bindings/gecko/Makefile.am b/bindings/gecko/Makefile.am index 148d8faf..7da2e523 100644 --- a/bindings/gecko/Makefile.am +++ b/bindings/gecko/Makefile.am @@ -26,6 +26,7 @@ EXTRA_DIST = gecko.override gecko.defs .defs.c: (cd $(srcdir)\ && $(PYGTK_CODEGEN) \ + --register $(GNOMEPYTHONEXTRAS_DEFSDIR)/gtkmozembed.defs \ --override $*.override \ --prefix py$* $*.defs) > gen-$*.c \ && cp gen-$*.c $*.c \ diff --git a/bindings/gecko/gecko-browser.cpp b/bindings/gecko/gecko-browser.cpp index d2627740..cab07f84 100644 --- a/bindings/gecko/gecko-browser.cpp +++ b/bindings/gecko/gecko-browser.cpp @@ -23,7 +23,7 @@ #include void -gecko_startup(void) +gecko_browser_startup(void) { nsCOMPtr prefService; @@ -36,3 +36,43 @@ gecko_startup(void) pref->SetBoolPref ("dom.disable_open_during_load", TRUE); } + +G_DEFINE_TYPE(GeckoBrowser, gecko_browser, GTK_TYPE_MOZ_EMBED) + +//static guint signals[N_SIGNALS]; + +GeckoBrowser * +gecko_browser_new(void) +{ + return GECKO_BROWSER(g_object_new(GECKO_TYPE_BROWSER, NULL)); +} + +static void +gecko_browser_class_init(GeckoBrowserClass *browser_class) +{ +} + +GeckoBrowser * +gecko_browser_create_window(GeckoBrowser *browser) +{ + return GECKO_BROWSER_GET_CLASS(browser)->create_window(browser); +} + +static void +gecko_browser_new_window_cb(GtkMozEmbed *embed, + GtkMozEmbed **newEmbed, + guint chromemask) +{ + GeckoBrowser *browser; + + browser = gecko_browser_create_window(GECKO_BROWSER(embed)); + + *newEmbed = GTK_MOZ_EMBED(browser); +} + +static void +gecko_browser_init(GeckoBrowser *browser) +{ + g_signal_connect(G_OBJECT(browser), "new-window", + G_CALLBACK(gecko_browser_new_window_cb), NULL); +} diff --git a/bindings/gecko/gecko-browser.h b/bindings/gecko/gecko-browser.h index d9564bcb..d41d2c5f 100644 --- a/bindings/gecko/gecko-browser.h +++ b/bindings/gecko/gecko-browser.h @@ -19,11 +19,35 @@ #ifndef __GECKO_BROWSER_H__ #define __GECKO_BROWSER_H__ -#include +#include G_BEGIN_DECLS -void gecko_startup (void); +typedef struct _GeckoBrowser GeckoBrowser; +typedef struct _GeckoBrowserClass GeckoBrowserClass; +typedef struct _GeckoBrowserPrivate GeckoBrowserPrivate; + +#define GECKO_TYPE_BROWSER (gecko_browser_get_type()) +#define GECKO_BROWSER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GECKO_TYPE_BROWSER, GeckoBrowser)) +#define GECKO_BROWSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GECKO_TYPE_BROWSER, GeckoBrowserClass)) +#define GECKO_IS_BROWSER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), GECKO_TYPE_BROWSER)) +#define GECKO_IS_BROWSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GECKO_TYPE_BROWSER)) +#define GECKO_BROWSER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), GECKO_TYPE_BROWSER, GeckoBrowserClass)) + +struct _GeckoBrowser { + GtkMozEmbed base_instance; +}; + +struct _GeckoBrowserClass { + GtkMozEmbedClass base_class; + + GeckoBrowser * (* create_window) (GeckoBrowser *browser); +}; + +GType gecko_browser_get_type (void); +void gecko_browser_startup (void); +GeckoBrowser *gecko_browser_new (void); +GeckoBrowser *gecko_browser_create_window (GeckoBrowser *browser); G_END_DECLS diff --git a/bindings/gecko/gecko.defs b/bindings/gecko/gecko.defs index 2351e193..c7f6c1ac 100644 --- a/bindings/gecko/gecko.defs +++ b/bindings/gecko/gecko.defs @@ -1,13 +1,40 @@ ;; -*- scheme -*- ; object definitions ... +(define-object Browser + (in-module "Gecko") + (parent "GtkMozEmbed") + (c-name "GeckoBrowser") + (gtype-id "GECKO_TYPE_BROWSER") +) + ;; Enumerations and flags ... -;; From sugar-browser.h +;; From gecko-browser.h + +(define-function get_type + (c-name "gecko_browser_get_type") + (return-type "GType") +) (define-function startup - (c-name "gecko_startup") + (c-name "gecko_browser_startup") (return-type "none") ) +(define-function new + (c-name "gecko_browser_new") + (is-constructor-of "GeckoBrowser") + (return-type "GeckoBrowser*") +) +(define-method create_window + (of-object "GeckoBrowser") + (c-name "gecko_browser_create_window") + (return-type "GeckoBrowser*") +) + +(define-virtual create_window + (of-object "GeckoBrowser") + (return-type "GeckoBrowser*") +) diff --git a/bindings/gecko/gecko.override b/bindings/gecko/gecko.override index 3ef8f3fd..b32caa60 100644 --- a/bindings/gecko/gecko.override +++ b/bindings/gecko/gecko.override @@ -3,5 +3,16 @@ headers #include +#include "pygobject.h" #include "gecko-browser.h" + +%% +modulename gecko +%% +import gobject.GObject as PyGObject_Type +import gtkmozembed.MozEmbed as PyGtkMozEmbed_Type +%% +ignore-glob + *_get_type + _* %% diff --git a/bindings/gecko/geckomodule.c b/bindings/gecko/geckomodule.c index ba16813d..8455de8a 100644 --- a/bindings/gecko/geckomodule.c +++ b/bindings/gecko/geckomodule.c @@ -5,6 +5,8 @@ /* include this first, before NO_IMPORT_PYGOBJECT is defined */ #include +void pygecko_register_classes (PyObject *d); + extern PyMethodDef pygecko_functions[]; DL_EXPORT(void) @@ -17,6 +19,8 @@ initgecko(void) m = Py_InitModule ("gecko", pygecko_functions); d = PyModule_GetDict (m); + pygecko_register_classes (d); + if (PyErr_Occurred ()) { Py_FatalError ("can't initialise module globalkeys"); } diff --git a/configure.ac b/configure.ac index e307b53e..4d8a2f98 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,10 @@ AC_PATH_PROG(PYGTK_CODEGEN, pygtk-codegen-2.0, no) PKG_CHECK_MODULES(PYGTK, pygtk-2.0) PKG_CHECK_MODULES(GLOBALKEYS, gdk-2.0) -PKG_CHECK_MODULES(GECKO, xulrunner-gtkmozembed) +PKG_CHECK_MODULES(GECKO, gtk+-2.0 xulrunner-gtkmozembed) + +GNOMEPYTHONEXTRAS_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0` +AC_SUBST(GNOMEPYTHONEXTRAS_DEFSDIR) # # Setup GETTEXT