The problem seems to be solved. I used nsIWebBrowserFocus' methods activate() and deactivate() and nsIWebBrowserChrome's focusNextElement() and focusPrevElement() - that was enough for me. The only problem I met was a bug in Mozilla code: browser gets focus back to itself after calling focusNextElement() or focusPrevElement() - thanks to the comment in SWT AbstractMozillaBrowser.java code I was able to resolve it quickly. This is solved by handling these events asynchronously.

The next thing I'm going to implement is printing browser content, will write a separate message later.

Thanks,

Artem

Niky Williams wrote:

Artem Ananiev wrote:

I'm embedding a Firefox browser into my Java application using JavaXPCOM/Xulrunner, Win32 (Linux will be later and I suspect there are a lot of problems there too...)

The next thing I want to make work is key events and focus handling. I have found the following methods and interfaces related:

nsIWebBrowserChromeFocus.focusNextElement() - called by embedded browser when focus is tabbed out from it in forward direction. This interface must be implemented by embedder (by myself)

nsIWebBrowserChromeFocus.focusPrevElement() - the same as above but in backward direction

nsIWebBrowserFocus - this interface can be obtainer from nsIWebBrowser instance via queryInterface

nsIWebBrowserFocus.activate() - according to specification, this method must be called when my top-level window (where the browser is embedded within) is activated and the browser had focus when the window was previously deactivated. However, it seems that this method should be called each time I want the browser to get focus, not only when the top-level window is activated. Is it right?

nsIWebBrowserFocus.deactivate() - opposite to the previous one

nsIWebBrowserFocus.setFocusAtFirstElement() - can be used by embedding application to set focus at the first focusable element in embedded browser. It seems that I need to call activate() before this method

nsIWebBrowserFocus.setFocusAtLastElement() - the same as the previous one but for the last element

nsIDomEventListener.handleEvent() for event type "focus" - I'm not sure but it seems that this event is sent by browser when it wants to get focus. In event handler for this event I call activate() method in nsIWebBrowser and it works, but... This "focus" event is sent, for example, each time I click the browser by mouse, event if the browser has already gained focus. Is it an intended behaviour or I should call something else than activate()?

There are some other methods, I don't know when and why they are called:

nsIEmbeddingSiteWindow.setFocus()
nsIBaseWindow.setFocus()

Also, it would be fine to get some events when the browser is losing focus like WM_FILLFOCUS in Win32.

Thanks in advance,

Artem


Artem,
In my application, when I create the web browser and the chrome, I make it visible, then Activate () the web browser (via nsIWebBrowserFocus)...that's about it. It seems to behave correctly for me. I don't really mess with the other methods. I do have some code in here that I react to the WM_ACTIVATE windows message (I reactivate the web browser)...but I don't know if that is even needed or not. Wish I could be more help :(

Nik Williams
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to