From 6489ead25062142ab0dd9fc7285dc65cb438b284 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Fri, 28 Jan 2005 22:51:20 +0000 Subject: Refactored to elimiate code duplication. 2005-01-28 Christian Persch * embed/mozilla/mozilla-embed.cpp: Refactored to elimiate code duplication. --- embed/mozilla/mozilla-embed.cpp | 87 +++++++++++++---------------------------- 1 file changed, 28 insertions(+), 59 deletions(-) (limited to 'embed') diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index f3e0aac40..54db6067c 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -57,10 +57,10 @@ static void mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, gint state, guint status, MozillaEmbed *membed); -static gint mozilla_embed_dom_mouse_click_cb (GtkMozEmbed *embed, +static gboolean mozilla_embed_dom_mouse_click_cb(GtkMozEmbed *embed, gpointer dom_event, MozillaEmbed *membed); -static gint mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, +static gboolean mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, gpointer dom_event, MozillaEmbed *membed); static void mozilla_embed_new_window_cb (GtkMozEmbed *embed, @@ -871,21 +871,18 @@ mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, const char *aURI, g_signal_emit_by_name (membed, "ge_net_state", aURI, estate); } -static gint -mozilla_embed_dom_mouse_click_cb (GtkMozEmbed *embed, gpointer dom_event, - MozillaEmbed *membed) +static gboolean +mozilla_embed_emit_mouse_signal (MozillaEmbed *embed, + gpointer dom_event, + const char *signal_name) { + MozillaEmbedPrivate *mpriv = embed->priv; MozillaEmbedEvent *info; EventContext event_context; gint return_value = FALSE; nsresult rv; - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - if (dom_event == NULL) - { - g_warning ("mozilla_embed_dom_mouse_click_cb: domevent NULL"); - return FALSE; - } + if (dom_event == NULL) return FALSE; nsCOMPtr ev = static_cast(dom_event); NS_ENSURE_TRUE (ev, FALSE); @@ -896,65 +893,20 @@ mozilla_embed_dom_mouse_click_cb (GtkMozEmbed *embed, gpointer dom_event, event_context.Init (mpriv->browser); rv = event_context.GetMouseEventInfo (ev, MOZILLA_EMBED_EVENT (info)); - - if (NS_SUCCEEDED (rv)) - { - nsCOMPtr domDoc; - rv = event_context.GetTargetDocument (getter_AddRefs(domDoc)); - if (NS_SUCCEEDED (rv)) - { - rv = mpriv->browser->PushTargetDocument (domDoc); - if (NS_SUCCEEDED (rv)) - { - g_signal_emit_by_name (membed, "ge_dom_mouse_click", - info, &return_value); - mpriv->browser->PopTargetDocument (); - } - } - - } - - g_object_unref (info); - - return return_value; -} - -static gint -mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, gpointer dom_event, - MozillaEmbed *membed) -{ - MozillaEmbedEvent *info; - EventContext event_context; - gint return_value = FALSE; - nsresult rv; - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - if (dom_event == NULL) + if (NS_FAILED (rv)) { - g_warning ("mozilla_embed_dom_mouse_down_cb: domevent NULL"); + g_object_unref (info); return FALSE; } - nsCOMPtr ev = static_cast(dom_event); - NS_ENSURE_TRUE (ev, FALSE); - nsCOMPtr dev = do_QueryInterface (ev); - NS_ENSURE_TRUE (dev, FALSE); - - info = mozilla_embed_event_new (NS_STATIC_CAST (gpointer, dev)); - - event_context.Init (mpriv->browser); - rv = event_context.GetMouseEventInfo (ev, MOZILLA_EMBED_EVENT (info)); - if (NS_FAILED (rv)) return FALSE; - nsCOMPtr domDoc; rv = event_context.GetTargetDocument (getter_AddRefs(domDoc)); if (NS_SUCCEEDED (rv)) { mpriv->browser->PushTargetDocument (domDoc); - g_signal_emit_by_name (membed, "ge_dom_mouse_down", + g_signal_emit_by_name (embed, signal_name, info, &return_value); - mpriv->browser->PopTargetDocument (); } @@ -963,6 +915,23 @@ mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, gpointer dom_event, return return_value; } +static gboolean +mozilla_embed_dom_mouse_click_cb (GtkMozEmbed *embed, + gpointer dom_event, + MozillaEmbed *membed) +{ + return mozilla_embed_emit_mouse_signal (membed, dom_event, + "ge_dom_mouse_click"); +} + +static gboolean +mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, gpointer dom_event, + MozillaEmbed *membed) +{ + return mozilla_embed_emit_mouse_signal (membed, dom_event, + "ge_dom_mouse_down"); +} + static void mozilla_embed_new_window_cb (GtkMozEmbed *embed, GtkMozEmbed **newEmbed, -- cgit v1.2.3