Get the image uri from the DOM
This commit is contained in:
parent
e05313c152
commit
6b14d9e883
@ -19,7 +19,7 @@ headers
|
|||||||
extern Pycairo_CAPI_t *Pycairo_CAPI;
|
extern Pycairo_CAPI_t *Pycairo_CAPI;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
modulename _sugar
|
modulename gecko
|
||||||
%%
|
%%
|
||||||
import gobject.GObject as PyGObject_Type
|
import gobject.GObject as PyGObject_Type
|
||||||
import gtk.Entry as PyGtkEntry_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__"))
|
if (!strcmp(attr, "__members__"))
|
||||||
return Py_BuildValue("[s]", "image_uri");
|
return Py_BuildValue("[s]", "image_uri");
|
||||||
if (!strcmp(attr, "image_uri"))
|
if (!strcmp(attr, "image_uri")) {
|
||||||
return PyString_FromString(event->image_uri);
|
if (event->image_uri) {
|
||||||
|
return PyString_FromString(event->image_uri);
|
||||||
|
} else {
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
#include <nsIGenericFactory.h>
|
#include <nsIGenericFactory.h>
|
||||||
#include <nsIHelperAppLauncherDialog.h>
|
#include <nsIHelperAppLauncherDialog.h>
|
||||||
#include <nsIComponentRegistrar.h>
|
#include <nsIComponentRegistrar.h>
|
||||||
|
#include <nsIDOMNode.h>
|
||||||
|
#include <nsIDOMEventTarget.h>
|
||||||
|
#include <nsIDOMHTMLImageElement.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
@ -370,15 +373,53 @@ location_cb(GtkMozEmbed *embed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
dom_mouse_click_cb(GtkMozEmbed *embed, nsIDOMMouseEvent *dom_event)
|
dom_mouse_click_cb(GtkMozEmbed *embed, nsIDOMMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
SugarBrowser *browser = SUGAR_BROWSER(embed);
|
SugarBrowser *browser = SUGAR_BROWSER(embed);
|
||||||
SugarBrowserEvent *event;
|
SugarBrowserEvent *event;
|
||||||
gint return_value = FALSE;
|
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 = 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);
|
g_signal_emit(browser, signals[MOUSE_CLICK], 0, event, &return_value);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
@ -421,7 +462,7 @@ sugar_browser_scroll_pixels(SugarBrowser *browser,
|
|||||||
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
||||||
webBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow));
|
webBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow));
|
||||||
if (!DOMWindow) {
|
if (!DOMWindow) {
|
||||||
webBrowser->GetContentDOMWindow (getter_AddRefs (DOMWindow));
|
webBrowser->GetContentDOMWindow (getter_AddRefs(DOMWindow));
|
||||||
}
|
}
|
||||||
NS_ENSURE_TRUE (DOMWindow, );
|
NS_ENSURE_TRUE (DOMWindow, );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user