Cross Package Overlays

クロスパッケージオーバーレイ

This section describes how to apply overlays to files that don't import them.

このセクションでは、オーバーレイをインポートしないファイルにオーバーレイを 適用する方法について述べます。

Applying Overlays to other Packages

他のパッケージにオーバーレイを適用する

Overlays have another very useful feature. In the examples in the previous section, the overlays were imported by the window. You can also go the other way and have the overlays specify which windows that they apply to. You specify this by modifying the contents.rdf file for your package. This is useful because the overlay can modify the user interface of another package without changing the other package. For example, you could add menu items or toolbars to the Mozilla browser window.

オーバーレイは、また別の非常に役立つ機能です。前のセクションの例では、 オーバーレイがウィンドウにインポートされていました。他の方法で行うことも できますし、適用するウィンドウを指定するオーバーレイを持つこともできます。 パッケージの contents.rdf ファイルを修正すれば、この指定ができます。 他のパッケージを変更しないで、オーバーレイでまた別のパッケージのユーザ インターフェイスを修正することができるので便利です。例えば、Mozilla ブラウザ ウィンドウにメニュー項目やツールバーを追加することができます。

We'll use this feature to add a toolbar to the Mozilla browser window. The Mozilla Mail application uses overlays to add content to the browser window. For example, if Mail is not installed, there will be no New Message command. However, if Mail is installed, an overlay will be applied to the menu to add the New Message command. Below, we'll add a find files toolbar to the browser. It probably wouldn't be useful to have this feature, but we'll do it anyway.

Mozilla ブラウザウィンドウにツールバーを加えるのに、この機能を使っています。 Mozilla Mail アプリケーションは、ブラウザウィンドウにコンテンツを追加するのに オーバーレイを使っています。例えば、もし Mail がインストールされないのなら、 New Message コマンドは無いでしょう。でも Mail がインストールされれば、 オーバーレイがメニューに適用されて New Message コマンドが加えられます。 この後で、ブラウザにファイル検索ツールバー (find files toolbar) を追加します。 多分この機能の追加は役に立たないでしょうが、とにかくやってみます。

Mozilla allows you to add a list of overlays to the contents.rdf file that you use to list chrome packages, skins and locales. Once you have created an overlay, you can add it to the contents.rdf file. Then add items, one for each window that you want the overlay to apply to.

contents.rdf ファイルは、クロムパッケージ、スキン、ロケールをリスト化するのに 使われており、このファイルにオーバーレイのリストを追加することができます。 一旦オーバーレイを作成したなら、contents.rdf ファイルに追加できます。それから、 オーバーレイを適用したいウィンドウごとにアイテムを追加します。

First, let's create a simple overlay. It will just have a few fields for entering a filename and directory to search. Call the file foverlay.xul and add it to the findfile directory along with findfile.xul.

最初に簡単なオーバーレイを作ってみましょう。これは検索するファイル名と ディレクトリ名を入力するフィールドを 2、3 個持っています。ファイルを foverlay.xul として findfile.xul と同じ findfile ディレクトリに入れます。

Example 12.7.1: Source
<?xml version="1.0"?>

<overlay
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<toolbox id="navigator-toolbox">
  <toolbar id="findfile_toolbar">
    <label control="findfile_filename" value="Search for files named:"/>
    <textbox id="findfile_filename"/>
    <label control="findfile_dir" value="Directory:"/>
    <textbox id="findfile_dir"/>
    <button label="Browse..."/>
  </toolbar>
</toolbox>

</overlay>

You can view this by changing the overlay to a window. The only thing that is special here is the id used on the toolbox. This value (navigator-toolbox) is the same as the identifier of the toolbox in the browser window (navigator.xul). This means that the overlay will apply to the toolbox in the browser window and the content will be added as an extra toolbar.

オーバーレイをウィンドウに変更すると、この内容を見ることができます。ここで特別と 考えられる唯一のことは、toolbox に使われている id です。この値 (navigator-toolbox) は、ブラウザウィンドウ (navigator.xul) の toolbox の識別子と同じです。このことは、オーバーレイはブラウザウィンドウの toolbox に適用され、その中身は外部からの toolbar として加えられる、ということを 意味しています。

To add this overlay to the manifest file, we need to add two resources. First, we add one for each window that we are applying an overlay to. The code below should be added into content.rdf just before the closing RDF tag.

このオーバーレイをマニフェストファイルに追加するためには、2 つのリソースを 加える必要があります。まず、オーバーレイを適用しているウィンドウごとに 1 つ 加えます。下のコードが、RDF タグを閉じる直前に content.rdf に加えられるべき ものです。

<RDF:Seq about="urn:mozilla:overlays">
  <RDF:li resource="chrome://navigator/content/navigator.xul"/>
</RDF:Seq>

This declares that we are adding a overlay window, a child of the root overlay node (urn:mozilla:overlays). You can add additional nodes for any other windows that you want to apply overlays to by adding additional li nodes.

これはオーバーレイウィンドウを、ルートオーバーレイノード (urn:mozilla:overlays) の 子として追加している、という宣言です。li ノードを 更に追加すると、オーバーレイを適用したい他の任意のウィンドウ用にノードを追加 することができます。

Next, we add a node for each overlay to apply to the window. In this case, we only have one, but we could apply others also. Add these lines just after the previous lines.

次に、各オーバーレイをウィンドウに適用するノードを追加します。この例では 1 つだけ ですが、他へも適用できます。前の行のすぐ後に次の行を追加します。

<RDF:Seq about="chrome://navigator/content/navigator.xul">
  <RDF:li>chrome://findfile/content/foverlay.xul</RDF:li>
</RDF:Seq>

Mozilla reads this information and builds a list of overlays that are applied to other windows. It stores this information in the chrome/overlayinfo directory. You do not need to manually modify the files in this directory. It is automatically generated and modified when Mozilla is first run or when new packages are installed. However, you can force the data to be rebuilt by deleting this directory and the chrome.rdf file.

Mozilla はこの情報を読み込んで、他のウィンドウに適用されるオーバーレイのリストを 作成します。この情報は chrome/overlayinfo ディレクトリに蓄積されます。 手動でこのディレクトリのファイルを修正する必要はありません。Mozilla が最初に起動 されるとき、または新しいパッケージがインストールされるときに、自動的に生成、 修正がなされます。そして、このディレクトリと chrome.rdf ファイルを削除すれば、 データを強制的に再構築することができます。

As a side note, you can use a similar technique to apply extra style sheets. The following example shows how:

副メモとして、同様のテクニックを使って外部スタイルシートを適用することが できます。次の例がその方法を示しています:

<RDF:Seq about="urn:mozilla:stylesheets">
  <RDF:li resource="chrome://messenger/content/messenger.xul"/>
</RDF:Seq>

<RDF:Seq about="chrome://messenger/content/messenger.xul">
  <RDF:li>chrome://blueswayedshoes/skin/myskinfile.css</RDF:li>
</RDF:Seq>

(Next) Next, we'll see how to create an installer for a XUL application.

(進む) 次では、XUL アプリケーション用のインストーラの作り方を見ていきます。

Examples: 12.7.1


Copyright (C) 1999 - 2004 XulPlanet.com
訳者: kmine
このドキュメントのオリジナルは XULPlanet において英語で公布されています。
またドキュメントの管理の言語は現在も英語です。この日本語訳は、
利用者の利便のために Mozilla Japan 翻訳部門によって提供されたものです。
フィードバックは英語で、元の著者に送って下さい。
翻訳された文書の一覧は、現在以下のURLで見ることが出来ます。
http://www.mozilla.gr.jp/jt/xul/progress.html