Bug 363450, implement nsIScriptEventHandlerOwner as a tearoff, r+sr=sicking

This commit is contained in:
Olli.Pettay%helsinki.fi 2006-12-18 17:52:04 +00:00
Родитель a9b39b699c
Коммит 466828ae73
2 изменённых файлов: 50 добавлений и 27 удалений

Просмотреть файл

@ -436,7 +436,9 @@ nsXULElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
} else if (aIID.Equals(NS_GET_IID(nsIXMLContent))) { } else if (aIID.Equals(NS_GET_IID(nsIXMLContent))) {
inst = NS_STATIC_CAST(nsIXMLContent *, this); inst = NS_STATIC_CAST(nsIXMLContent *, this);
} else if (aIID.Equals(NS_GET_IID(nsIScriptEventHandlerOwner))) { } else if (aIID.Equals(NS_GET_IID(nsIScriptEventHandlerOwner))) {
inst = NS_STATIC_CAST(nsIScriptEventHandlerOwner *, this); inst = NS_STATIC_CAST(nsIScriptEventHandlerOwner*,
new nsXULElement::nsScriptEventHandlerOwnerTearoff(this));
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
} else if (aIID.Equals(NS_GET_IID(nsIChromeEventHandler))) { } else if (aIID.Equals(NS_GET_IID(nsIChromeEventHandler))) {
inst = NS_STATIC_CAST(nsIChromeEventHandler *, this); inst = NS_STATIC_CAST(nsIChromeEventHandler *, this);
} else if (aIID.Equals(NS_GET_IID(nsIDOMElementCSSInlineStyle))) { } else if (aIID.Equals(NS_GET_IID(nsIDOMElementCSSInlineStyle))) {
@ -635,15 +637,23 @@ nsXULElement::IsFocusable(PRInt32 *aTabIndex)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// nsIScriptEventHandlerOwner interface // nsIScriptEventHandlerOwner interface
NS_INTERFACE_MAP_BEGIN(nsXULElement::nsScriptEventHandlerOwnerTearoff)
NS_INTERFACE_MAP_ENTRY(nsIScriptEventHandlerOwner)
NS_INTERFACE_MAP_END_AGGREGATED(mElement)
NS_IMPL_ADDREF(nsXULElement::nsScriptEventHandlerOwnerTearoff)
NS_IMPL_RELEASE(nsXULElement::nsScriptEventHandlerOwnerTearoff)
nsresult nsresult
nsXULElement::GetCompiledEventHandler(nsIAtom *aName, nsXULElement::nsScriptEventHandlerOwnerTearoff::GetCompiledEventHandler(
nsScriptObjectHolder &aHandler) nsIAtom *aName,
nsScriptObjectHolder &aHandler)
{ {
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheTests); XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheTests);
aHandler.drop(); aHandler.drop();
nsXULPrototypeAttribute *attr = nsXULPrototypeAttribute *attr =
FindPrototypeAttribute(kNameSpaceID_None, aName); mElement->FindPrototypeAttribute(kNameSpaceID_None, aName);
if (attr) { if (attr) {
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheHits); XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheHits);
aHandler.set(attr->mEventHandler); aHandler.set(attr->mEventHandler);
@ -653,23 +663,24 @@ nsXULElement::GetCompiledEventHandler(nsIAtom *aName,
} }
nsresult nsresult
nsXULElement::CompileEventHandler(nsIScriptContext* aContext, nsXULElement::nsScriptEventHandlerOwnerTearoff::CompileEventHandler(
nsISupports* aTarget, nsIScriptContext* aContext,
nsIAtom *aName, nsISupports* aTarget,
const nsAString& aBody, nsIAtom *aName,
const char* aURL, const nsAString& aBody,
PRUint32 aLineNo, const char* aURL,
nsScriptObjectHolder &aHandler) PRUint32 aLineNo,
nsScriptObjectHolder &aHandler)
{ {
nsresult rv; nsresult rv;
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheSets); XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheSets);
// XXX sXBL/XBL2 issue! Owner or current document? // XXX sXBL/XBL2 issue! Owner or current document?
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(GetOwnerDoc()); nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(mElement->GetOwnerDoc());
nsIScriptContext *context; nsIScriptContext *context;
if (mPrototype && xuldoc) { if (mElement->mPrototype && xuldoc) {
// It'll be shared among the instances of the prototype. // It'll be shared among the instances of the prototype.
// Use the prototype document's special context. Because // Use the prototype document's special context. Because
@ -719,7 +730,7 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsXULPrototypeAttribute *attr = nsXULPrototypeAttribute *attr =
FindPrototypeAttribute(kNameSpaceID_None, aName); mElement->FindPrototypeAttribute(kNameSpaceID_None, aName);
if (attr) { if (attr) {
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheFills); XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheFills);
// take a copy of the event handler, and tell the language about it. // take a copy of the event handler, and tell the language about it.

Просмотреть файл

@ -443,7 +443,6 @@ public:
class nsXULElement : public nsGenericElement, class nsXULElement : public nsGenericElement,
public nsIDOMXULElement, public nsIDOMXULElement,
public nsIScriptEventHandlerOwner,
public nsIChromeEventHandler public nsIChromeEventHandler
{ {
public: public:
@ -582,17 +581,6 @@ public:
// nsIDOMXULElement // nsIDOMXULElement
NS_DECL_NSIDOMXULELEMENT NS_DECL_NSIDOMXULELEMENT
// nsIScriptEventHandlerOwner
nsresult CompileEventHandler(nsIScriptContext* aContext,
nsISupports* aTarget,
nsIAtom *aName,
const nsAString& aBody,
const char* aURL,
PRUint32 aLineNo,
nsScriptObjectHolder &aHandler);
nsresult GetCompiledEventHandler(nsIAtom *aName,
nsScriptObjectHolder &aHandler);
// nsIChromeEventHandler // nsIChromeEventHandler
NS_DECL_NSICHROMEEVENTHANDLER NS_DECL_NSICHROMEEVENTHANDLER
@ -707,7 +695,31 @@ protected:
static already_AddRefed<nsXULElement> static already_AddRefed<nsXULElement>
Create(nsXULPrototypeElement* aPrototype, nsINodeInfo *aNodeInfo, Create(nsXULPrototypeElement* aPrototype, nsINodeInfo *aNodeInfo,
PRBool aIsScriptable); PRBool aIsScriptable);
/**
* A tearoff class for nsXULElement to implement nsIScriptEventHandlerOwner.
*/
class nsScriptEventHandlerOwnerTearoff : public nsIScriptEventHandlerOwner
{
public:
nsScriptEventHandlerOwnerTearoff(nsXULElement* aElement)
: mElement(aElement) {}
NS_DECL_ISUPPORTS
// nsIScriptEventHandlerOwner
virtual nsresult CompileEventHandler(nsIScriptContext* aContext,
nsISupports* aTarget,
nsIAtom *aName,
const nsAString& aBody,
const char* aURL,
PRUint32 aLineNo,
nsScriptObjectHolder &aHandler);
virtual nsresult GetCompiledEventHandler(nsIAtom *aName,
nsScriptObjectHolder &aHandler);
private:
nsRefPtr<nsXULElement> mElement;
};
}; };
#endif // nsXULElement_h__ #endif // nsXULElement_h__