Re: Tab & click event registration
Jens Sorensen <[email protected]> Fri, 23 Apr 2010 13:01:33 -0700
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
I assume you have implemented at “nsIObserver“ and that the “Observe”
method gets invoked at startup with “xpcom-startup” as the topic. This
would be a good point to get a hold of the “nsIObserverService”
(do_GetService(NS_OBSERVERSERVICE_CONTRACTID)) which allows you to add
an observer which observes when a “domwindowopened” event occours.
Example:
observer = do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
observer->AddObserver(this, NS_LITERAL_STRING("domwindowopened"), PR_FALSE);
observer->AddObserver(this, NS_LITERAL_STRING("domwindowclosed"), PR_FALSE);
This will allow you to get notified when a window is being opened
(browser, help->about, tools->options etc). You can add a onload event
handler to the given window and when the 'onload' event comes in then
get the document and check if its a browser window. The browser window
always has the id of “main-window” (you can verify this by using DOM
Inpector).
Now that you have a reference to the browser window (nsiDOMWindow)
then get the nsIDOMEventTarget interface and add the event TabXXX
event handlers for the given window
nsCOMPtr<nsIDOMEventTarget> domTargetEvent = do_QueryInterface(
browserDOMWindow);
domTargetEvent->AddEventListener(NS_LITERAL_STRIN(“TabOpen”, this, PR_TRUE);
Since I pass in the “this” pointer then your class should implement
then “nsIDOMEventListener” interface.
Thanks,
Jens Sorensen
On Thu, Apr 22, 2010 at 11:32 PM, Vaibhav <[email protected]> wrote:
> Hi,
>
> I am writing Firefox extension using C++.
> I am confused about where do I register Tab & Click events in C++.
> After reading Mozilla's tabbed browser document, I do it in javascript
> file.
>
> It is as follows:
> /////////////////////////////////////////////////////////////////////////// ////
> function Init()
> {
> var container;
> container = gBrowser.tabContainer;
> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
> const cid = '@MyXPCOM/TestComponent';
> var obj =
> Components.classes[cid].getService(Components.interfaces.iTestComponent);
> container.addEventListener("TabOpen", obj, false);
> container.addEventListener("TabMove", obj, false);
> container.addEventListener("TabClose", obj, false);
> container.addEventListener("TabSelect", obj, false);
> window.addEventListener("click", obj, false);
> }
>
> function DeInit()
> {
> // Actually I want to unregister Tab & Click events, but till
> this
> function gets called
> // component instance is no more.
> }
>
> window.addEventListener('load', Init, false);
> window.addEventListener('unload', DeInit, false);
> ///////////////////////////////////////////////////////////////
>
> But I want to do above things in C++.
>
> Vaibhav.
> _______________________________________________
> dev-tech-dom mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-dom
>