How to attach mouse event listeners to embedded nsIWebBrowser

View: New views
3 Messages — Rating Filter:   Alert me  

How to attach mouse event listeners to embedded nsIWebBrowser

by Matthew Talbert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've embedded an nsIWebBrowser in my application. Because I'm just
generating HTML for it on the fly, I'm using OpenStream,
AppendToStream, and CloseStream to add content. What I need is to add
event listeners for mouse movement over the web browser as well as
mouse clicks. I've read documentation and tried lots of different
things, but nothing I have tried has worked. For instance, the code
below would seem to do the right thing, but it does nothing:

   nsCOMPtr<nsIDOMWindow> domWindow;
    mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));

    if (!mEventTarget) {
        mEventTarget = do_QueryInterface(domWindow);

        if (mEventTarget)
                mEventTarget->AddEventListener(NS_LITERAL_STRING
("mouseover"), (nsIDOMEventListener *)mEventListener, PR_FALSE);
}

Perhaps it isn't working because this is run during initialization,
but before any content is actually added. However, if I add it during
AppendStream, or CloseStream, it segfaults.

What am I doing wrong?

Matthew
_______________________________________________
dev-embedding mailing list
dev-embedding@...
https://lists.mozilla.org/listinfo/dev-embedding

Re: How to attach mouse event listeners to embedded nsIWebBrowser

by rappel101170 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Matthew,

here is a code snippet that worked for me. At least for an embedded
gecko 1.8.1.

nsCOMPtr<nsIDOMEventTarget> cpEventTarget;
nsCOMPtr<nsIDOMWindow> cpDomWin;
m_pWebBrowser->GetContentDOMWindow (getter_AddRefs(cpDomWin));
nsCOMPtr<nsIDOMWindow2> cpDomWin2 (do_QueryInterface (cpDomWin));
cpDomWin2->GetWindowRoot(getter_AddRefs(cpEventTarget));

rv = cpEventTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
                m_pBrowserImpl, PR_FALSE);

I did this after initialization and m_pBrowserImpl received the
mousedown events.

regards,
Rainer
_______________________________________________
dev-embedding mailing list
dev-embedding@...
https://lists.mozilla.org/listinfo/dev-embedding

Re: How to attach mouse event listeners to embedded nsIWebBrowser

by Matthew Talbert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Aug 28, 8:15 am, ra <rappel101...@...> wrote:

> Hi Matthew,
>
> here is a code snippet that worked for me. At least for an embedded
> gecko 1.8.1.
>
> nsCOMPtr<nsIDOMEventTarget> cpEventTarget;
> nsCOMPtr<nsIDOMWindow> cpDomWin;
> m_pWebBrowser->GetContentDOMWindow (getter_AddRefs(cpDomWin));
> nsCOMPtr<nsIDOMWindow2> cpDomWin2 (do_QueryInterface (cpDomWin));
> cpDomWin2->GetWindowRoot(getter_AddRefs(cpEventTarget));
>
> rv = cpEventTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
>                 m_pBrowserImpl, PR_FALSE);
>
> I did this after initialization and m_pBrowserImpl received the
> mousedown events.
>
> regards,
> Rainer

Thank you, that works. I had tried before to get a nsIDOMWindow2, and
then GetWindowRoot, but I guess I still don't know when to use stuff
like QueryInterface and AddRefs. Thanks again,

Matthew
_______________________________________________
dev-embedding mailing list
dev-embedding@...
https://lists.mozilla.org/listinfo/dev-embedding