Hello,
I am trying to simulate a mouseup event which should correspond to a
mousedown event that has previously occurred. When I get the mousedown
event, I save the event target to which the event was directed. I create
a mouse event using the event factory interface nsIDOMDocumentEvent,
specifying MouseEvents as the event type. Then I quiery the created
event for nsIDOMMouseEvent, and call InitMouseEvent on it. Then I call
the DispatchEvent method on the saved event target. What happens is that
the event is received only by the element that corresponds to the event
target.It seems there is no bubbling. Further, when I try to send it to
the parent DOM document object of the element, so that the event passes
through the capture phase, the event doesn't reach the element at all,
it seems it doesnt reach anything at all. I also tried to send the event
to the main DOM window, same result. I tried sending both through the
nsIEventTarget and nsIEventRecevier interfaces but the result was the
same. It seems that I can only snd the event directly to the element,
and then no default action occurs. For example, on buttons that have
javascript handlers, the handlers are called. But the "a" tags within
which the buttons are placed do not work, so links do not work. Also
plain links do not work as well. Here is the code:
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
nsCOMPtr<nsIDOMDocument> domDocument;
nsCOMPtr<nsIDOMNode> targetDOMNode;
nsCOMPtr<nsIDOMDocumentView> docView;
nsCOMPtr<nsIDOMAbstractView> docAbstractView;
nsCOMPtr<nsIDOMDocumentEvent> domEventFactory;
nsCOMPtr<nsIDOMEvent> genericEvent;
nsresult rv;
targetDOMNode = do_QueryInterface(mMouseDownEventTarget, &rv);
if (NS_FAILED(rv) || (!targetDOMNode))
throw EmbeddedBrowserException("CreateMouseUpEvent: could not
query DOMNode interface from event target");
rv = targetDOMNode->GetOwnerDocument(getter_AddRefs(domDocument));
if (NS_FAILED(rv) || (!domDocument))
throw EmbeddedBrowserException("CreateMouseUpEvent: could not
get owner DOM document of DOM Node");
domEventFactory = do_QueryInterface(domDocument, &rv);
if (NS_FAILED(rv) || (!domEventFactory))
throw EmbeddedBrowserException("CreateMouseUpEvent: could not
get event factory interface");
rv =
domEventFactory->CreateEvent(NS_LITERAL_STRING("MouseEvents"),getter_AddRefs(genericEvent));
if (NS_FAILED(rv) || (!genericEvent))
throw EmbeddedBrowserException("CreateMouseUpEvent: Could not
create genereic event");
mouseEvent = do_QueryInterface(genericEvent, &rv);
if (NS_FAILED(rv) || (!mouseEvent))
throw EmbeddedBrowserException("CreateMouseUpEvent: could not
obtain nsIDOMMouseEvent interface from generic DOM event");
docView = do_QueryInterface(domDocument, &rv);
if(NS_FAILED(rv) || (!docView))
throw EmbeddedBrowserException("CreateMouseUpEvent: could not
obtain nsIDOMDocumentView interface from DOM document");
rv = docView->GetDefaultView(getter_AddRefs(docAbstractView));
if(NS_FAILED(rv) || (!docAbstractView))
throw EmbeddedBrowserException("CreateMouseUpEvent: could not
get abstract view");
wxPoint mouseUpPos = wxGetMousePosition();
mouseEvent->InitMouseEvent(NS_LITERAL_STRING("mouseup"), PR_TRUE,
PR_TRUE, docAbstractView, 1, mouseUpPos.x, mouseUpPos.y,
ScreenToClient(mouseUpPos).x, ScreenToClient(mouseUpPos).y, PR_FALSE,
PR_FALSE, PR_FALSE, PR_FALSE, 1, mMouseDownEventTarget);
PRBool noPreventDefault = PR_TRUE; //true if default action is to be
taken, false if not, see nsIDOMEventTarget.h for documentation
rv = mMouseDownEventTarget->DispatchEvent(mouseEvent);
if (NS_FAILED(rv))
throw EmbeddedBrowserException("CreateMouseUpEvent: Error
dispatching mouseup event");
I have seen a post with the similar problem somewhere, saying the event
does not bubble. So, anybody has an idea?
Regards
Alex
_______________________________________________
mozilla-embedding mailing list
mozilla-embedding@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-embedding