From 1ab6c4beb7e3efd49dd6495f6f930b79c822b539 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Sun, 7 Nov 2004 08:54:32 +0000 Subject: [PATCH] Add a shared base class for elements that derive from nsIXTFXMLVisual. r=darin. git-svn-id: svn://10.0.0.236/trunk@165082 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xforms/nsXFormsInputElement.cpp | 168 +++-------------- .../xforms/nsXFormsOutputElement.cpp | 159 +++------------- .../extensions/xforms/nsXFormsStubElement.cpp | 178 ++++++++++++++++++ .../extensions/xforms/nsXFormsStubElement.h | 26 ++- 4 files changed, 247 insertions(+), 284 deletions(-) diff --git a/mozilla/extensions/xforms/nsXFormsInputElement.cpp b/mozilla/extensions/xforms/nsXFormsInputElement.cpp index adfc5b8888b..8f1f80519b4 100644 --- a/mozilla/extensions/xforms/nsXFormsInputElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsInputElement.cpp @@ -36,7 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsIXTFXMLVisual.h" +#include "nsXFormsStubElement.h" #include "nsIDOMEventTarget.h" #include "nsIDOM3Node.h" #include "nsIDOMElement.h" @@ -57,24 +57,29 @@ #include "nsIContent.h" #include "nsIDOMXPathExpression.h" -static const nsIID sScriptingIIDs[] = { - NS_IDOMELEMENT_IID, - NS_IDOMEVENTTARGET_IID, - NS_IDOM3NODE_IID -}; - /** * Implementation of the XForms \ element. */ -class nsXFormsInputElement : public nsIXTFXMLVisual, +class nsXFormsInputElement : public nsXFormsXMLVisualStub, public nsIDOMFocusListener, public nsIXFormsControl { public: - NS_DECL_ISUPPORTS - NS_DECL_NSIXTFXMLVISUAL - NS_DECL_NSIXTFVISUAL - NS_DECL_NSIXTFELEMENT + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFXMLVisual overrides + NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper); + + // nsIXTFVisual overrides + NS_IMETHOD GetVisualContent(nsIDOMElement **aElement); + + // nsIXTFElement overrides + NS_IMETHOD OnDestroyed(); + NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent); + NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue); + NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue); + + // nsIXFormsControl NS_DECL_NSIXFORMSCONTROL // nsIDOMEventListener @@ -91,17 +96,11 @@ private: nsIDOMElement *mElement; }; -NS_IMPL_ADDREF(nsXFormsInputElement) -NS_IMPL_RELEASE(nsXFormsInputElement) - -NS_INTERFACE_MAP_BEGIN(nsXFormsInputElement) - NS_INTERFACE_MAP_ENTRY(nsIXTFXMLVisual) - NS_INTERFACE_MAP_ENTRY(nsIXTFElement) - NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) - NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener) - NS_INTERFACE_MAP_ENTRY(nsIXFormsControl) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXTFXMLVisual) -NS_INTERFACE_MAP_END +NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsInputElement, + nsXFormsXMLVisualStub, + nsIXFormsControl, + nsIDOMFocusListener, + nsIDOMEventListener) // nsIXTFXMLVisual @@ -156,26 +155,6 @@ nsXFormsInputElement::GetVisualContent(nsIDOMElement **aElement) return NS_OK; } -NS_IMETHODIMP -nsXFormsInputElement::GetInsertionPoint(nsIDOMElement **aElement) -{ - *aElement = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::GetApplyDocumentStyleSheets(PRBool *aApply) -{ - *aApply = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::DidLayout() -{ - return NS_OK; -} - // nsIXTFElement NS_IMETHODIMP @@ -189,46 +168,6 @@ nsXFormsInputElement::OnDestroyed() return NS_OK; } -NS_IMETHODIMP -nsXFormsInputElement::GetElementType(PRUint32 *aType) -{ - *aType = ELEMENT_TYPE_XML_VISUAL; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::GetIsAttributeHandler(PRBool *aIsHandler) -{ - *aIsHandler = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::GetScriptingInterfaces(PRUint32 *aCount, nsIID ***aArray) -{ - return nsXFormsUtils::CloneScriptingInterfaces(sScriptingIIDs, - NS_ARRAY_LENGTH(sScriptingIIDs), - aCount, aArray); -} - -NS_IMETHODIMP -nsXFormsInputElement::WillChangeDocument(nsIDOMDocument *aNewDocument) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::DocumentChanged(nsIDOMDocument *aNewDocument) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::WillChangeParent(nsIDOMElement *aNewParent) -{ - return NS_OK; -} - NS_IMETHODIMP nsXFormsInputElement::ParentChanged(nsIDOMElement *aNewParent) { @@ -240,42 +179,6 @@ nsXFormsInputElement::ParentChanged(nsIDOMElement *aNewParent) return NS_OK; } -NS_IMETHODIMP -nsXFormsInputElement::WillInsertChild(nsIDOMNode *aChild, PRUint32 aIndex) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::WillAppendChild(nsIDOMNode *aChild) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::ChildAppended(nsIDOMNode *aChild) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::WillRemoveChild(PRUint32 aIndex) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::ChildRemoved(PRUint32 aIndex) -{ - return NS_OK; -} - NS_IMETHODIMP nsXFormsInputElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue) { @@ -304,31 +207,6 @@ nsXFormsInputElement::AttributeSet(nsIAtom *aName, const nsAString &aValue) return NS_OK; } -NS_IMETHODIMP -nsXFormsInputElement::WillRemoveAttribute(nsIAtom *aName) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::AttributeRemoved(nsIAtom *aName) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::DoneAddingChildren() -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsInputElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled) -{ - *aHandled = PR_FALSE; - return NS_OK; -} - // nsIDOMEventListener NS_IMETHODIMP @@ -383,7 +261,7 @@ nsXFormsInputElement::Blur(nsIDOMEvent *aEvent) return NS_OK; } -// other methods +// nsIXFormsControl NS_IMETHODIMP nsXFormsInputElement::Refresh() diff --git a/mozilla/extensions/xforms/nsXFormsOutputElement.cpp b/mozilla/extensions/xforms/nsXFormsOutputElement.cpp index 5255ead3075..443d5edb602 100755 --- a/mozilla/extensions/xforms/nsXFormsOutputElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsOutputElement.cpp @@ -40,7 +40,7 @@ //#define DEBUG_XF_OUTPUT #endif -#include "nsIXTFXMLVisual.h" +#include "nsXFormsStubElement.h" #include "nsIXTFXMLVisualWrapper.h" #include "nsAutoPtr.h" @@ -61,25 +61,31 @@ #include "nsXFormsAtoms.h" #include "nsXFormsUtils.h" -static const nsIID sScriptingIIDs[] = { - NS_IDOMELEMENT_IID, - NS_IDOM3NODE_IID, - NS_IDOMEVENTTARGET_IID -}; - /** * Implementation of the XForms \ element. * * @see http://www.w3.org/TR/xforms/slice8.html#ui-output */ -class nsXFormsOutputElement : public nsIXTFXMLVisual, +class nsXFormsOutputElement : public nsXFormsXMLVisualStub, public nsIXFormsControl { public: - NS_DECL_ISUPPORTS - NS_DECL_NSIXTFXMLVISUAL - NS_DECL_NSIXTFVISUAL - NS_DECL_NSIXTFELEMENT + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFXMLVisual overrides + NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper); + + // nsIXTFVisual overrides + NS_IMETHOD GetVisualContent(nsIDOMElement **aElement); + NS_IMETHOD GetInsertionPoint(nsIDOMElement **aElement); + + // nsIXTFElement overrides + NS_IMETHOD OnDestroyed(); + NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent); + NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue); + NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue); + + // nsIXFormsControl NS_DECL_NSIXFORMSCONTROL nsXFormsOutputElement() : mElement(nsnull) {} @@ -89,15 +95,9 @@ private: nsIDOMElement *mElement; }; -NS_IMPL_ADDREF(nsXFormsOutputElement) -NS_IMPL_RELEASE(nsXFormsOutputElement) - -NS_INTERFACE_MAP_BEGIN(nsXFormsOutputElement) - NS_INTERFACE_MAP_ENTRY(nsIXTFXMLVisual) - NS_INTERFACE_MAP_ENTRY(nsIXTFElement) - NS_INTERFACE_MAP_ENTRY(nsIXFormsControl) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXTFXMLVisual) -NS_INTERFACE_MAP_END +NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsOutputElement, + nsXFormsXMLVisualStub, + nsIXFormsControl) // nsIXTFXMLVisual @@ -153,19 +153,6 @@ nsXFormsOutputElement::GetInsertionPoint(nsIDOMElement **aElement) return NS_OK; } -NS_IMETHODIMP -nsXFormsOutputElement::GetApplyDocumentStyleSheets(PRBool *aApply) -{ - *aApply = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::DidLayout() -{ - return NS_OK; -} - // nsIXTFElement NS_IMETHODIMP @@ -177,46 +164,6 @@ nsXFormsOutputElement::OnDestroyed() return NS_OK; } -NS_IMETHODIMP -nsXFormsOutputElement::GetElementType(PRUint32 *aType) -{ - *aType = ELEMENT_TYPE_XML_VISUAL; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::GetIsAttributeHandler(PRBool *aIsHandler) -{ - *aIsHandler = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::GetScriptingInterfaces(PRUint32 *aCount, nsIID ***aArray) -{ - return nsXFormsUtils::CloneScriptingInterfaces(sScriptingIIDs, - NS_ARRAY_LENGTH(sScriptingIIDs), - aCount, aArray); -} - -NS_IMETHODIMP -nsXFormsOutputElement::WillChangeDocument(nsIDOMDocument *aNewDocument) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::DocumentChanged(nsIDOMDocument *aNewDocument) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::WillChangeParent(nsIDOMElement *aNewParent) -{ - return NS_OK; -} - NS_IMETHODIMP nsXFormsOutputElement::ParentChanged(nsIDOMElement *aNewParent) { @@ -229,42 +176,6 @@ nsXFormsOutputElement::ParentChanged(nsIDOMElement *aNewParent) return NS_OK; } -NS_IMETHODIMP -nsXFormsOutputElement::WillInsertChild(nsIDOMNode *aChild, PRUint32 aIndex) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::WillAppendChild(nsIDOMNode *aChild) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::ChildAppended(nsIDOMNode *aChild) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::WillRemoveChild(PRUint32 aIndex) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::ChildRemoved(PRUint32 aIndex) -{ - return NS_OK; -} - NS_IMETHODIMP nsXFormsOutputElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue) { @@ -293,33 +204,7 @@ nsXFormsOutputElement::AttributeSet(nsIAtom *aName, const nsAString &aValue) return NS_OK; } -NS_IMETHODIMP -nsXFormsOutputElement::WillRemoveAttribute(nsIAtom *aName) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::AttributeRemoved(nsIAtom *aName) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::DoneAddingChildren() -{ - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsOutputElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled) -{ - *aHandled = PR_FALSE; - return NS_OK; -} - - -// other methods +// nsIXFormsControl NS_IMETHODIMP nsXFormsOutputElement::Refresh() diff --git a/mozilla/extensions/xforms/nsXFormsStubElement.cpp b/mozilla/extensions/xforms/nsXFormsStubElement.cpp index eb13b4c1d52..1ed47e0bb7e 100644 --- a/mozilla/extensions/xforms/nsXFormsStubElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsStubElement.cpp @@ -49,6 +49,8 @@ static const nsIID sScriptingIIDs[] = { NS_IDOM3NODE_IID }; +// nsXFormsStubElement implementation + NS_IMPL_ISUPPORTS2(nsXFormsStubElement, nsIXTFElement, nsIXTFGenericElement) NS_IMETHODIMP @@ -193,3 +195,179 @@ NS_NewXFormsStubElement(nsIXTFElement **aResult) NS_ADDREF(*aResult); return NS_OK; } + + +// nsXFormsXMLVisualStub implementation + +NS_IMPL_ISUPPORTS3(nsXFormsXMLVisualStub, nsIXTFXMLVisual, nsIXTFVisual, + nsIXTFElement) + +NS_IMETHODIMP +nsXFormsXMLVisualStub::OnDestroyed() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::GetElementType(PRUint32 *aElementType) +{ + *aElementType = nsIXTFElement::ELEMENT_TYPE_XML_VISUAL; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::GetIsAttributeHandler(PRBool *aIsAttributeHandler) +{ + *aIsAttributeHandler = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::GetScriptingInterfaces(PRUint32 *aCount, + nsIID ***aArray) +{ + return nsXFormsUtils::CloneScriptingInterfaces(sScriptingIIDs, + NS_ARRAY_LENGTH(sScriptingIIDs), + aCount, aArray); +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillChangeDocument(nsIDOMDocument *aNewDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::DocumentChanged(nsIDOMDocument *aNewDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillChangeParent(nsIDOMElement *aNewParent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::ParentChanged(nsIDOMElement *aNewParent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillInsertChild(nsIDOMNode *aChild, PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillAppendChild(nsIDOMNode *aChild) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::ChildAppended(nsIDOMNode *aChild) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillRemoveChild(PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::ChildRemoved(PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillSetAttribute(nsIAtom *aName, + const nsAString &aNewValue) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::AttributeSet(nsIAtom *aName, const nsAString &aNewValue) { + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::WillRemoveAttribute(nsIAtom *aName) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::AttributeRemoved(nsIAtom *aName) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::DoneAddingChildren() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled) +{ + *aHandled = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::GetVisualContent(nsIDOMElement **aContent) +{ + *aContent = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::GetInsertionPoint(nsIDOMElement **aInsertionPoint) +{ + *aInsertionPoint = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::GetApplyDocumentStyleSheets(PRBool *aApplySheets) +{ + *aApplySheets = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::DidLayout() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsXMLVisualStub::OnCreated(nsIXTFXMLVisualWrapper *aWrapper) +{ + return NS_OK; +} + +nsresult +NS_NewXFormsXMLVisualStub(nsIXTFElement **aResult) +{ + *aResult = new nsXFormsXMLVisualStub(); + if (!*aResult) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aResult); + return NS_OK; +} diff --git a/mozilla/extensions/xforms/nsXFormsStubElement.h b/mozilla/extensions/xforms/nsXFormsStubElement.h index 469b39aeb82..e04c6d366f7 100644 --- a/mozilla/extensions/xforms/nsXFormsStubElement.h +++ b/mozilla/extensions/xforms/nsXFormsStubElement.h @@ -40,12 +40,14 @@ #define nsXFormsStubElement_h_ #include "nsIXTFGenericElement.h" +#include "nsIXTFXMLVisual.h" /** * An implementation of a generic non-UI XForms element. * - * This is used for e.g. bind so that the id attribute works correctly for - * these nodes. + * This is the implementation for e.g. bind so that the id attribute works + * correctly for these nodes. It is also a base class for all XForms + * nsIXTFGenericElement implementations. */ class nsXFormsStubElement : public nsIXTFGenericElement { @@ -54,7 +56,27 @@ class nsXFormsStubElement : public nsIXTFGenericElement NS_DECL_NSIXTFGENERICELEMENT }; +/** + * An implementation of an XForms UI control. + * + * This is a base class for UI controls that use nsIXTFXMLVisual. + * Note: a pointer to the anonymous content root is _not_ provided as part + * of this base class because different implementations want to store + * different types of interface pointers. + */ +class nsXFormsXMLVisualStub : public nsIXTFXMLVisual +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIXTFELEMENT + NS_DECL_NSIXTFVISUAL + NS_DECL_NSIXTFXMLVISUAL +}; + +/* Factory methods */ NS_HIDDEN_(nsresult) NS_NewXFormsStubElement(nsIXTFElement **aResult); +NS_HIDDEN_(nsresult) +NS_NewXFormsXMLVisualStub(nsIXTFElement **aResult); + #endif