Get the image uri from the DOM

This commit is contained in:
Marco Pesenti Gritti 2007-03-13 12:51:15 +01:00
parent e05313c152
commit 6b14d9e883
2 changed files with 54 additions and 7 deletions

View File

@ -19,7 +19,7 @@ headers
extern Pycairo_CAPI_t *Pycairo_CAPI;
%%
modulename _sugar
modulename gecko
%%
import gobject.GObject as PyGObject_Type
import gtk.Entry as PyGtkEntry_Type
@ -187,8 +187,14 @@ _wrap_sugar_browser_event_tp_getattr(PyObject *self, char *attr)
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[s]", "image_uri");
if (!strcmp(attr, "image_uri"))
if (!strcmp(attr, "image_uri")) {
if (event->image_uri) {
return PyString_FromString(event->image_uri);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
return NULL;
}

View File

@ -37,6 +37,9 @@
#include <nsIGenericFactory.h>
#include <nsIHelperAppLauncherDialog.h>
#include <nsIComponentRegistrar.h>
#include <nsIDOMNode.h>
#include <nsIDOMEventTarget.h>
#include <nsIDOMHTMLImageElement.h>
enum {
PROP_0,
@ -370,14 +373,52 @@ location_cb(GtkMozEmbed *embed)
}
static gboolean
dom_mouse_click_cb(GtkMozEmbed *embed, nsIDOMMouseEvent *dom_event)
dom_mouse_click_cb(GtkMozEmbed *embed, nsIDOMMouseEvent *mouseEvent)
{
SugarBrowser *browser = SUGAR_BROWSER(embed);
SugarBrowserEvent *event;
gint return_value = FALSE;
nsCOMPtr<nsIDOMEventTarget> eventTarget;
mouseEvent->GetTarget(getter_AddRefs(eventTarget));
NS_ENSURE_TRUE(mouseEvent, FALSE);
nsCOMPtr<nsIDOMNode> targetNode;
targetNode = do_QueryInterface(eventTarget);
NS_ENSURE_TRUE(targetNode, FALSE);
event = sugar_browser_event_new();
event->image_uri = g_strdup("testimage");
nsresult rv;
PRUint16 type;
rv = targetNode->GetNodeType(&type);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(targetNode);
if ((nsIDOMNode::ELEMENT_NODE == type) && element) {
nsString uTag;
rv = element->GetLocalName(uTag);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCString tag;
NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag);
if (g_ascii_strcasecmp (tag.get(), "img") == 0) {
nsString img;
nsCOMPtr <nsIDOMHTMLImageElement> image;
image = do_QueryInterface(targetNode, &rv);
if (NS_FAILED(rv) || !image) return NS_ERROR_FAILURE;
rv = image->GetSrc(img);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCString cImg;
NS_UTF16ToCString (img, NS_CSTRING_ENCODING_UTF8, cImg);
event->image_uri = g_strdup(cImg.get());
}
}
g_signal_emit(browser, signals[MOUSE_CLICK], 0, event, &return_value);