IT翻訳 Nobuyuki の仕事部屋

ボランティアでソフトウエアーローカライズのために翻訳をしている。

Mozilla DOM Hacking Guide: Introduction to XPCOM17

2006-01-26 23:53:44 | InDraft
昨日の続き!

原文:  青色表示
訳文:  黒色表示
注記/訂正: 赤色表示

nstead of having to type the three methods and forward them to nsBar, we can use the "Interface forwarding macro", NS_FORWARD_NSIFOO.

#define NS_FORWARD_NSIFOO(_to) \
NS_IMETHOD GetProp() { return _to GetProp(); } \
NS_IMETHOD SetProp() { return _to SetProp(); } \
NS_IMETHOD Meth() { return _to Meth(); }


この時 3 つのメソッドをタイプして nsBar へ送らなくても、代わりに”インターフェイス転送マクロ”の NS_FORWARD_NSIFOO を使用できます。

#define NS_FORWARD_NSIFOO(_to) \
NS_IMETHOD GetProp() { return _to GetProp(); } \
NS_IMETHOD SetProp() { return _to SetProp(); } \
NS_IMETHOD Meth() { return _to Meth(); }


The meaning of this macro is easy to grasp. It will forward all the methods on the nsIFoo interface to the implementation on the _to class.

このマクロの意味を理解するのは簡単です。 _to クラスの実装に対して nsIFoo インターフェイスのすべてのメソッドを転送します

Application to nsIDOMFabian: we could code our two functions in nsDocument, then forward nsIDOMFabian to nsDocument from nsHTMLDocument. This would allow us to be able to re-use the nsDocument code in nsXMLDocument, for example. This technique is already used for most of the document methods.

nsIDOMFabian のアプリケーション: nsDocument で 2 つの関数をコード化し nsHTMLDocument から nsDocument へ nsIDOMFabian を転送できます。こうする事で例えば、 nsXMLDocument で nsDocument のコードを再利用することもできます。この技術はすでに大抵の document 関数で使われています。

// File nsDocument.h:
class nsDocument : public ...
{
// ...
NS_IMETHOD Fabian(void);
NS_IMETHOD GetNeat(PRBool *aNeat);
// ...
}

// File nsDocument.cpp:
nsDocument::Fabian()
{
// ...
}
nsDocument::GetNeat(PRBool *aNeat)
{
// ...
}

// File nsHTMLDocument.h:
class nsHTMLDocument : public ... ,
public nsIDOMFabian
{
// ...
NS_FORWARD_NSIDOMFABIAN(nsDocument::)
// ...
}

//nsHTMLDocument.cpp では何も必要でない

This was an easy example of "Interface forwarding". These two ways are the most common to implement an interface in the DOM. There are other ways that are a little more complicated, not worth detailing here.

これは "インターフェイス転送" の簡単な例です。これらの2つの方法は DOM でインターフェイスを実装する最も一般的方法です。もう少し複雑な他の方法がありますが、ここでは扱いません

Important note: the nsISupports interface, implemented by all the DOM classes, CANNOT be implemented with forwarding or declaration macros. Special macros are provided to implement nsISupports

重要な注記: すべての DOM クラスによって実装される nsISupports インターフェイスは転送マクロや宣言マクロを使って実装されません。nsISupports の実装には特別なマクロが提供されます

This closes this tutorial about how to add a new interface. Simply make a full rebuild. I recommend building distclean. Your methods will not be available from JavaScript, however, because nsIDOMFabian is not in the Class Info. Please see the User's guide of Class Info to learn how to add it.

新しいインターフェイスの追加方法についてのチュートリアルはここで終わりです。ただ全面的に作り直してください。distclean をビルドするといいでしょう。しかし、JavaScript からはあたたのメソッドは有効になりません。というのは、nsIDOMFabian は Class Info. にないからです。その追加方法に関してはClass Info の使い方を参照してください。

Snoopy
Sleepy