XBL Inheritance

XBL の継承

In this section, we'll look at how to extend existing XBL definitions.

このセクションでは、既にある XBL 定義を拡張する方法を見ることにしましょう。

Inheritance

継承 (Inheritance)

Sometimes you may want to create an XBL widget that is similar to an existing one. For example, let's say you want to create an XBL button with a popup. One way to create this is to duplicate the existing XBL code for buttons. However, it would be better to simply extend the existing button code.

時には、既にあるものに似た XBL ウィジェットを作りたい場合があるかもしれません。 例えば、ポップアップ付きの XBL ボタンを作りたいとしましょう。これを作る一つの 方法は、ボタン用に既にある XBL コードを複製することです。しかし、既にある ボタンのコードを拡張するだけの方が望ましいでしょう。

Any binding can be extended with another. The child binding can add properties, methods and event handlers. The child binding will have all the features it defines in addition to the features from the binding it inherits from (and any that binding inherits from and so on up the tree).

バインディングはどれも、別のものを拡張できます。子供のバインディングには、 プロパティ、メソッド、イベントハンドラを追加できます。子供のバインディングは、 それが継承するバインディングの機能 (と、そのバインディングがツリーの上流から継承する機能) の他に、それが定義するすべての機能をもちます。

To extend an existing binding, add an extends attribute on to the binding tag. For example, the following binding creates a textbox which adds the text 'http://www' to the beginning of its value when the F4 key is pressed.

既にあるバインディングを拡張するには、 binding タグに extends 属性を追加します。例えば、以下の バインディングは、テキストボックスを作ります。これは、F4 キーが押されると、 その値の始めに 'http://www' というテキストを追加します。

Example 11.7.1: Source
<binding id="textboxwithhttp"
         extends="chrome://global/content/bindings/textbox.xml#textbox">
  <handlers>
    <handler event="keypress" keycode="VK_F4">
      this.value="http://www"+value;
    </handler>
  </handlers>
</binding>

The XBL here extends from the XUL textbox element. The URL given in the extends attribute above is the URL of the binding of the textbox binding. This means that we inherit all of the content and behavior provided by the textbox binding. In addition, we add a handler which responds to the keypress event.

ここでは、XBL は XUL の textbox 要素を拡張しています。上の extends 属性にある URL は、textbox binding のバインディング URL です。これは、テキストボックスのバインディングが 提供する内容と振る舞いのすべてを継承するということです。それ以外に、 キー押し下げイベントに応答するハンドラを追加しています。

Autocompleting TextBoxes

テキストボックスを自動補完する

The example above is similar to how the URL autocomplete feature works in Mozilla. A textbox that supports autocomplete is just one with a XBL binding that extends the basic textbox.

上の例は、URL の自動補完機能が Mozilla で動作する仕組みに類似しています。 自動補完をサポートするテキストボックスは、基本となるテキストボックスを拡張する XBL バインディングをもつものにすぎません。

The autocomplete textbox adds extra event handling so that when a URL is typed, a menu will pop up with possible completions. You can use it in your own applications too. Just create a textbox with two extra attributes.

自動補完テキストボックスに特別なイベント処理を追加し、それによって、URL が入力されると、メニューは補完候補からなるポップアップを表示します。 これは、自分自身のアプリケーションでも使用できます。2 つの特別な属性をもつ テキストボックスを作るだけです。

<textbox type="autocomplete" searchSessions="history"/>

Set the type to autocomplete to add the autocomplete feature to an existing textbox. Set the searchSessions to indicate what type of data to look up. In this case, the value history is used, which looks up URLs in the history. (You can also use the value addrbook to look up addresses in the address book.)

既にあるテキストボックスに自動補完機能を追加するには、 typeautocomplete に設定します。どんな種類のデータを探すのか指示するため、 searchSessions を設定します。この場合は、 history を使っています。これは、履歴 (history) にある URL を探します。(アドレスブック内のアドレスを探すために、 addrbook という値も使用できます。)


(Next) In the next section, we'll see an example XBL-defined widget.

(進む) 次のセクションでは、XBL で定義したウィジェットの例を見ることにしましょう。

Examples: 11.7.1


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