如何将鼠标事件侦听器附加到 C++ 中的嵌入式 nsIWebBrowser
我已在我的应用程序中嵌入了 nsIWebBrowser。因为我只是动态生成 HTML,所以我使用 OpenStream、AppendToStream 和 CloseStream 来添加内容。我需要的是为鼠标在网络浏览器上移动以及鼠标单击添加事件侦听器。我已经阅读了文档并尝试了很多不同的方法,但我所尝试的都不起作用。例如,下面的代码似乎做了正确的事情,但它什么也没做:
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);
}
也许它不起作用,因为它是在初始化期间运行的,但在实际添加任何内容之前运行。但是,如果我在 AppendStream 或 CloseStream 期间添加它,则会出现段错误。
请告诉我一个简单的方法来做到这一点。
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.
Please tell me a straightforward way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,答案如下:
Well, here's the answer: