Here's a note Adam Lock posted a while ago on how to use chrome in your 
embedding app.

Hope this helps...

Chak

-------------Adam's note on using chrome-------------------
Hi all,

This is a quick note to describe how chrome and embedding work at the 
moment to give some ideas how you might use it.

As you may know from Mozilla the application the chrome dictates the 
entire look and feel of the application. Chrome generally comprises of 
XUL (the layout structure), Javascript (the program logic), CSS (the 
layout style or "skin") and DTD (the language locales). Generally the 
structure/logic, the style/skin and the locale are in separate places.

What I've done is put together some simple generic embedding chrome 
suitable for when Gecko is embedded into someone else's window. It has a 
few popup menus and some simple buttons. This chrome lives in 
mozilla\embedding\browser\chrome. I call it generic because most 
embedders will likely want to modify it in some way - adding extra menu 
options, removing the toolbar or whatever.

The embedding chrome consists of:

     * mini-nav.xul - defines toolbars, buttons, popup menus and the 
content area
     * mini-nav.js - initialisation code and methods for handling menu 
and button clicks
     * embedding.dtd - Locale specific language strings for menu items 
and button labels
     * embedding.css - Style information including bitmaps to place on 
the toolbar buttons.

The embedding chrome is not built by default, so the first thing you 
must do is:

cd mozilla\embedding\browser\chrome
nmake /f makefile.win

This copies the chrome files to Mozilla's chrome folder. The next step 
is run Mozilla so that it updates its list of what skins, packages and 
languages are installed on this system. You can do this and test the 
chrome at the same time by typing:

cd mozilla\dist\win32_d.obj\bin
mozilla -chrome chrome://embedding/browser/content/mini-nav.xul

Mozilla will run, but it will use the embedding chrome. It should have a 
toolbar with back, forward, reload, stop and an address bar and a popup 
menu with back, forward, stop and reload. It will probably get some more 
stuff in time. Testing embedding chrome in Mozilla is a great way to see 
if its working or not because JavaScript errors get printed to the 
console - something you won't get in the embedding app.

So how do you use the chrome in your own embedding application?

First of all, you must tell your webbrowser object that it will be 
hosting chrome as opposed to content. Add this in your webbrowser 
initialisation code but *before* you call nsIBaseWindow::Create():

nsCOMPtr<nsIDocShellTreeItem>
browserAsItem(do_QueryInterface(mWebBrowser));
browserAsItem->SetItemType(nsIDocShellTreeItem::typeChromeWrapper);

This tells the webbrowser object that it should create a root docshell 
for hosting chrome, which has more privileges that normal content. 
Without this line popup menus won't work because DOM events don't 
"bubble" correctly and you may also run into security issues.

Next, you load the chrome like you would any other URL:

mWebBrowserAsNav->LoadURI("chrome://embedding/browser/content/mini-nav.xul");

Your chrome will load and be visible in the window.

To load some content (e.g. when the user clicks on a link in another 
window), you want it to happen in the content area in the middle of the 
chrome and not replace the chrome itself. This means you have to obtain 
the content areas nsIWebNavigation interface and call LoadURI on that. 
This is done like this:

nsCOMPtr<nsIDocShellTreeItem>
browserAsItem(do_QueryInterface(mWebBrowser));
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
browserAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
nsCOMPtr<nsIDocShellTreeItem> contentItem;
treeOwner->GetPrimaryContentShell(getter_AddRefs(contentItem));
nsCOMPtr<nsIWebNavigation> contentItemAsNav(do_QueryInterface(contentItem));
contentItemAsNav->LoadURI("http://www.mozilla.org";);

So that's how to use chrome in embedding. Otherwise it's pretty much the 
same as loading any other URL.

I encourage you to play with the chrome and see if you can change the 
menu options, hide the toolbar and so on. Hopefully, you'll see that 
it's pretty powerful stuff! The www.mozilla.org website and the 
netscape.public.mozilla.ui and netscape.public.mozilla.xpfe newsgroups 
are good places to find answers to general chrome questions.

I'm currently working on some enhancements to the embedding chrome that 
will make it easier for the embedder and the chrome javascript to talk 
back and forth. When this in place it will be simple for Javascript code 
to call into the C++ embedding site to perform native actions when a 
menu option is selected for instance.
-------------Adam's note on using chrome-------------------

Markus Essl wrote:

> Hello!
> 
> I have a couple of questions, I hope you could answer some of them.
> 
> What I'm trying to do: build a program that runs from CD, views an 
> HTML-UI that needs some "native" XPCOM-components.
> 
> I've build my XPCOM-components in a dll and put that in the components 
> folder. This works fine. Additionally I made them a JavaScript-Object in 
> my main application, which is based on MfcEmbed. But as far as i can see 
> is this the only change from MfcEmbed that I need to make, and this is 
> not really necessary.
> 
> If it's possible, I'd like to get rid of that MFC stuff - I'd like to 
> define my menus in XUL, so basically it's the same as the mozilla 
> application with a different chrome and an additional module in the 
> components directory.
> 
> Should I use mozilla directly? If I putted mozilla on the CD, could I 
> give it a "different" name so it doesn't interfere with an existing 
> installation?
> 
> Another related question: there is a example of a chrome that can be 
> used for embedding apps, I think this is 
> mozilla/embedding/browser/chrome - i've read a document that describes 
> how to install and use it, but that was some time ago and now I can't 
> find it anymore. Can you tell me where it is?
> 
> I'm sorry that the questions are at a very low level - there are so many 
> new things so my head is spinning and I don't know on what to focus.
> 
> 
> Thanks,
> Markus
> 


Reply via email to