First go at adding events support to Browser

master
Marco Pesenti Gritti 18 years ago
parent ac8805246d
commit e05313c152

@ -1,5 +1,14 @@
;; -*- scheme -*-
; object definitions ...
(define-boxed SugarBrowserEvent
(in-module "Sugar")
(c-name "SugarBrowserEvent")
(gtype-id "SUGAR_TYPE_BROWSER_EVENT")
(copy-func "sugar_browser_event_copy")
(release-func "sugar_browser_event_free")
)
(define-object AddressEntry
(in-module "Sugar")
(parent "GtkEntry")

@ -19,7 +19,7 @@ headers
extern Pycairo_CAPI_t *Pycairo_CAPI;
%%
modulename gecko
modulename _sugar
%%
import gobject.GObject as PyGObject_Type
import gtk.Entry as PyGtkEntry_Type
@ -179,3 +179,17 @@ _wrap_sugar_cairo_surface_from_gdk_pixbuf(PyGObject *self, PyObject *args, PyObj
return PycairoSurface_FromSurface(surface, NULL);
}
%%
override-slot SugarBrowserEvent.tp_getattr
static PyObject *
_wrap_sugar_browser_event_tp_getattr(PyObject *self, char *attr)
{
SugarBrowserEvent *event = pyg_boxed_get(self, SugarBrowserEvent);
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[s]", "image_uri");
if (!strcmp(attr, "image_uri"))
return PyString_FromString(event->image_uri);
return NULL;
}
%%

@ -8,8 +8,6 @@ headers
#include <gtkmozembed.h>
%%
modulename gtkmozembed
%%
import gobject.GObject as PyGObject_Type
import gtk.Object as PyGtkObject_Type

@ -20,6 +20,7 @@
#include <config.h>
#include "sugar-browser.h"
#include "sugar-marshal.h"
#include "GeckoContentHandler.h"
#include "GeckoDownload.h"
@ -32,6 +33,7 @@
#include <nsIWebBrowser.h>
#include <nsIWebBrowserFocus.h>
#include <nsIDOMWindow.h>
#include <nsIDOMMouseEvent.h>
#include <nsIGenericFactory.h>
#include <nsIHelperAppLauncherDialog.h>
#include <nsIComponentRegistrar.h>
@ -46,6 +48,13 @@ enum {
PROP_LOADING
};
enum {
MOUSE_CLICK,
N_SIGNALS
};
static guint signals[N_SIGNALS];
static const nsModuleComponentInfo sSugarComponents[] = {
{
"Gecko Content Handler",
@ -190,6 +199,16 @@ sugar_browser_class_init(SugarBrowserClass *browser_class)
gobject_class->get_property = sugar_browser_get_property;
signals[MOUSE_CLICK] = g_signal_new ("mouse_click",
SUGAR_TYPE_BROWSER,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(SugarBrowser, mouse_click),
g_signal_accumulator_true_handled, NULL,
sugar_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN,
1,
SUGAR_TYPE_BROWSER_EVENT);
g_object_class_install_property(gobject_class, PROP_PROGRESS,
g_param_spec_double ("progress",
"Progress",
@ -350,6 +369,21 @@ location_cb(GtkMozEmbed *embed)
update_navigation_properties(browser);
}
static gboolean
dom_mouse_click_cb(GtkMozEmbed *embed, nsIDOMMouseEvent *dom_event)
{
SugarBrowser *browser = SUGAR_BROWSER(embed);
SugarBrowserEvent *event;
gint return_value = FALSE;
event = sugar_browser_event_new();
event->image_uri = g_strdup("testimage");
g_signal_emit(browser, signals[MOUSE_CLICK], 0, event, &return_value);
return return_value;
}
static void
sugar_browser_init(SugarBrowser *browser)
{
@ -365,6 +399,8 @@ sugar_browser_init(SugarBrowser *browser)
G_CALLBACK(title_cb), NULL);
g_signal_connect(G_OBJECT(browser), "location",
G_CALLBACK(location_cb), NULL);
g_signal_connect(G_OBJECT(browser), "dom-mouse-click",
G_CALLBACK(dom_mouse_click_cb), NULL);
}
void
@ -406,3 +442,47 @@ sugar_browser_grab_focus(SugarBrowser *browser)
g_warning ("Need to realize the embed before grabbing focus!\n");
}
}
GType
sugar_browser_event_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY(type == 0)) {
type = g_boxed_type_register_static("SugarBrowserEvent",
(GBoxedCopyFunc)sugar_browser_event_copy,
(GBoxedFreeFunc)sugar_browser_event_free);
}
return type;
}
SugarBrowserEvent *
sugar_browser_event_new(void)
{
SugarBrowserEvent *event;
event = g_new0(SugarBrowserEvent, 1);
return event;
}
SugarBrowserEvent *
sugar_browser_event_copy(SugarBrowserEvent *event)
{
g_return_val_if_fail(event != NULL, NULL);
return (SugarBrowserEvent *)g_memdup(event, sizeof(SugarBrowserEvent));
}
void
sugar_browser_event_free(SugarBrowserEvent *event)
{
g_return_if_fail(event != NULL);
if (event->image_uri) {
g_free(event->image_uri);
}
g_free(event);
}

@ -24,8 +24,9 @@
G_BEGIN_DECLS
typedef struct _SugarBrowser SugarBrowser;
typedef struct _SugarBrowser SugarBrowser;
typedef struct _SugarBrowserClass SugarBrowserClass;
typedef struct _SugarBrowserEvent SugarBrowserEvent;
#define SUGAR_TYPE_BROWSER (sugar_browser_get_type())
#define SUGAR_BROWSER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_BROWSER, SugarBrowser))
@ -45,6 +46,9 @@ struct _SugarBrowser {
gboolean can_go_back;
gboolean can_go_forward;
gboolean loading;
gboolean (* mouse_click) (SugarBrowser *browser,
SugarBrowserEvent *event);
};
struct _SugarBrowserClass {
@ -64,6 +68,16 @@ gboolean sugar_browser_startup (const char *profile_path,
const char *profile_name);
void sugar_browser_shutdown (void);
#define SUGAR_TYPE_BROWSER_EVENT (sugar_browser_event_get_type())
struct _SugarBrowserEvent {
char *image_uri;
};
GType sugar_browser_event_get_type (void);
SugarBrowserEvent *sugar_browser_event_new (void);
SugarBrowserEvent *sugar_browser_event_copy (SugarBrowserEvent *event);
void sugar_browser_event_free (SugarBrowserEvent *event);
G_END_DECLS

@ -1,3 +1,4 @@
VOID:OBJECT,STRING,LONG,LONG
VOID:OBJECT,LONG
VOID:OBJECT
BOOLEAN:BOXED

Loading…
Cancel
Save