From 103e8cb40806cd4f5917f446e0c9256de15d1f62 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Wed, 1 Jun 2005 19:19:33 +0000 Subject: [PATCH] Bug 291026, Allow XBL to bind to XTF elements, r=alex, sr=bryner, a=mkaply git-svn-id: svn://10.0.0.236/trunk@173962 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/xtf/public/Makefile.in | 3 + .../xtf/public/nsIXTFBindableElement.idl | 65 +++++ .../public/nsIXTFBindableElementWrapper.idl | 45 ++++ mozilla/content/xtf/public/nsIXTFElement.idl | 6 +- .../xtf/public/nsIXTFElementWrapper.idl | 9 +- .../xtf/public/nsIXTFSVGVisualWrapper.idl | 8 +- .../xtf/public/nsIXTFStyledElementWrapper.idl | 51 ++++ mozilla/content/xtf/public/nsIXTFVisual.idl | 8 +- .../xtf/public/nsIXTFXMLVisualWrapper.idl | 8 +- .../xtf/public/nsIXTFXULVisualWrapper.idl | 8 +- mozilla/content/xtf/src/Makefile.in | 1 + .../xtf/src/nsXTFBindableElementWrapper.cpp | 227 ++++++++++++++++++ .../xtf/src/nsXTFBindableElementWrapper.h | 51 ++++ .../content/xtf/src/nsXTFElementWrapper.cpp | 59 +++++ mozilla/content/xtf/src/nsXTFElementWrapper.h | 16 ++ .../content/xtf/src/nsXTFSVGVisualWrapper.cpp | 8 +- mozilla/content/xtf/src/nsXTFService.cpp | 12 +- .../content/xtf/src/nsXTFVisualWrapper.cpp | 53 +--- mozilla/content/xtf/src/nsXTFVisualWrapper.h | 8 +- .../content/xtf/src/nsXTFXMLVisualWrapper.cpp | 4 + .../content/xtf/src/nsXTFXULVisualWrapper.cpp | 6 +- mozilla/extensions/xforms/nsXFormsAtoms.h | 5 + .../extensions/xforms/nsXFormsControlStub.cpp | 104 ++++---- .../extensions/xforms/nsXFormsControlStub.h | 163 +++++++++++-- .../extensions/xforms/nsXFormsStubElement.cpp | 164 ++++++++++++- .../extensions/xforms/nsXFormsStubElement.h | 25 ++ mozilla/layout/base/nsCSSFrameConstructor.cpp | 2 +- 27 files changed, 952 insertions(+), 167 deletions(-) create mode 100644 mozilla/content/xtf/public/nsIXTFBindableElement.idl create mode 100644 mozilla/content/xtf/public/nsIXTFBindableElementWrapper.idl create mode 100644 mozilla/content/xtf/public/nsIXTFStyledElementWrapper.idl create mode 100644 mozilla/content/xtf/src/nsXTFBindableElementWrapper.cpp create mode 100644 mozilla/content/xtf/src/nsXTFBindableElementWrapper.h diff --git a/mozilla/content/xtf/public/Makefile.in b/mozilla/content/xtf/public/Makefile.in index 505990d9850..82022d30c96 100644 --- a/mozilla/content/xtf/public/Makefile.in +++ b/mozilla/content/xtf/public/Makefile.in @@ -59,6 +59,9 @@ XPIDLSRCS = \ nsIXTFXMLVisualWrapper.idl \ nsIXTFXULVisual.idl \ nsIXTFXULVisualWrapper.idl \ + nsIXTFBindableElement.idl \ + nsIXTFBindableElementWrapper.idl \ + nsIXTFStyledElementWrapper.idl \ $(NULL) ifdef MOZ_SVG diff --git a/mozilla/content/xtf/public/nsIXTFBindableElement.idl b/mozilla/content/xtf/public/nsIXTFBindableElement.idl new file mode 100644 index 00000000000..d20f2e3ad04 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFBindableElement.idl @@ -0,0 +1,65 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Olli Pettay. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Olli Pettay (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIXTFElement.idl" + +interface nsIXTFBindableElementWrapper; + +/** + * nsIXTFBindableElement can be used to add support for new interfaces to + * normal XML elements. XBL bindings do work with this kind of XTF elements. + * + * @note getScriptingInterfaces don't work at the moment with + * nsIXTFBindableElements. The problem is that XBL does not play nicely + * with that kind of interfaces. + * However, if nsIXTFBindableElement implements scriptable interfaces, those + * can be used by explicitly QIing to them. + */ + +[scriptable, uuid(8dcc630c-9adc-4c60-9954-a004cb45e4a7)] +interface nsIXTFBindableElement : nsIXTFElement +{ + /** + * onCreated will be called before any notifications are sent to + * the xtf element. + * + * @param wrapper is a weak proxy to the wrapping element + * (i.e. holding a reference to this will not create a cycle). + */ + void onCreated(in nsIXTFBindableElementWrapper wrapper); +}; diff --git a/mozilla/content/xtf/public/nsIXTFBindableElementWrapper.idl b/mozilla/content/xtf/public/nsIXTFBindableElementWrapper.idl new file mode 100644 index 00000000000..cb61a0b67c1 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFBindableElementWrapper.idl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Olli Pettay. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Olli Pettay (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIXTFStyledElementWrapper.idl" + +[scriptable, uuid(7914d5f2-14b4-47d0-88f8-70715cfbdfb7)] +interface nsIXTFBindableElementWrapper : nsIXTFStyledElementWrapper +{ +}; + diff --git a/mozilla/content/xtf/public/nsIXTFElement.idl b/mozilla/content/xtf/public/nsIXTFElement.idl index 3c8a451674a..89cc6c460e1 100644 --- a/mozilla/content/xtf/public/nsIXTFElement.idl +++ b/mozilla/content/xtf/public/nsIXTFElement.idl @@ -43,7 +43,7 @@ interface nsIDOMElement; interface nsIDOMNode; interface nsIDOMEvent; -[scriptable, uuid(61077434-18c8-4d2d-956c-7c389a7e9bba)] +[scriptable, uuid(a8b607fd-24b6-4a8c-9a89-d9b24f8e2592)] interface nsIXTFElement : nsISupports { // called when the wrapper object is being destroyed. @@ -67,6 +67,10 @@ interface nsIXTFElement : nsISupports // nsIXTFXULVisual interface in addition to nsIXTFElement: const unsigned long ELEMENT_TYPE_XUL_VISUAL = 3; + // Elements of type BINDABLE are required to implement the + // nsIXTFBindableElement interface in addition to nsIXTFElement: + const unsigned long ELEMENT_TYPE_BINDABLE = 4; + // elementType identifies the type of wrapper that will be built for // a given xtf element. It must remain constant for the entire // lifetime of the xtf element (i.e. before any onCreated()-calls diff --git a/mozilla/content/xtf/public/nsIXTFElementWrapper.idl b/mozilla/content/xtf/public/nsIXTFElementWrapper.idl index 06e8f542592..9a40004684e 100644 --- a/mozilla/content/xtf/public/nsIXTFElementWrapper.idl +++ b/mozilla/content/xtf/public/nsIXTFElementWrapper.idl @@ -38,17 +38,20 @@ #include "nsISupports.idl" +interface nsIAtom; interface nsIDOMElement; interface nsIDOMDocument; -[scriptable, uuid(94c05b72-997a-4bb0-a23d-63e40c55b02c)] +[scriptable, uuid(e71b0b11-45e3-422b-b589-9ea4629e36ec)] interface nsIXTFElementWrapper : nsISupports { readonly attribute nsIDOMElement elementNode; readonly attribute nsIDOMElement documentFrameElement; - // Events can be unmasked by setting the corresponding bit as given - // by the NOTIFY_* constants in nsIXTFElement and nsIXTFVisual: + /** + * Events can be unmasked by setting the corresponding bit as given + * by the NOTIFY_* constants in nsIXTFElement and nsIXTFVisual: + */ attribute unsigned long notificationMask; }; diff --git a/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl b/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl index f6198fba8c9..8a97a110cb5 100644 --- a/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl +++ b/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl @@ -36,10 +36,10 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsIXTFElementWrapper.idl" +#include "nsIXTFStyledElementWrapper.idl" -[scriptable, uuid(056d0708-6112-44ff-b3ca-ecf14936d599)] -interface nsIXTFSVGVisualWrapper : nsIXTFElementWrapper -{ +[scriptable, uuid(78582ad3-db1e-4aa6-a15b-b055a7846352)] +interface nsIXTFSVGVisualWrapper : nsIXTFStyledElementWrapper +{ }; diff --git a/mozilla/content/xtf/public/nsIXTFStyledElementWrapper.idl b/mozilla/content/xtf/public/nsIXTFStyledElementWrapper.idl new file mode 100644 index 00000000000..aac9d5ab372 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFStyledElementWrapper.idl @@ -0,0 +1,51 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Olli Pettay. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Olli Pettay (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIXTFElementWrapper.idl" + +[scriptable, uuid(814dbfdd-32ff-4734-9aea-b84c925bc9c0)] +interface nsIXTFStyledElementWrapper : nsIXTFElementWrapper +{ + /** + * This sets the name of the class attribute. + * Should be called only during ::onCreated. + * Note! nsIXTFAttributeHandler can't be used to handle class attribute. + */ + void setClassAttributeName(in nsIAtom name); +}; + diff --git a/mozilla/content/xtf/public/nsIXTFVisual.idl b/mozilla/content/xtf/public/nsIXTFVisual.idl index b08697f9eb4..b8a1f172025 100644 --- a/mozilla/content/xtf/public/nsIXTFVisual.idl +++ b/mozilla/content/xtf/public/nsIXTFVisual.idl @@ -40,7 +40,7 @@ interface nsIDOMElement; -[scriptable, uuid(59de39e3-56ff-47c0-a580-f15dbde45ed3)] +[scriptable, uuid(2ee5520b-6593-43c1-b660-4885939a6b68)] interface nsIXTFVisual : nsIXTFElement { // The content tree rooted in 'visualContent' will be rendered where @@ -72,10 +72,4 @@ interface nsIXTFVisual : nsIXTFElement // Event notifications: void didLayout(); - - // Returns an atom holding the name of the "class" attribute. - // This is called once during XTFVisual creation. - // The xtf element doesn't have to keep a strong ref to the atom. - // Note! nsIXTFAttributeHandler can't be used to handle class attribute. - nsIAtom getClassAttributeName(); }; diff --git a/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl b/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl index e645314d95c..93c75579248 100644 --- a/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl +++ b/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl @@ -36,10 +36,10 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsIXTFElementWrapper.idl" +#include "nsIXTFStyledElementWrapper.idl" -[scriptable, uuid(a260bc18-c639-41e5-b28a-a6b5c8e99993)] -interface nsIXTFXMLVisualWrapper : nsIXTFElementWrapper -{ +[scriptable, uuid(656c9417-744e-4fa3-8e2b-8218185efe21)] +interface nsIXTFXMLVisualWrapper : nsIXTFStyledElementWrapper +{ }; diff --git a/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl b/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl index 01d23d9f047..4a06f2a4455 100644 --- a/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl +++ b/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl @@ -36,10 +36,10 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsIXTFElementWrapper.idl" +#include "nsIXTFStyledElementWrapper.idl" -[scriptable, uuid(b8bb0585-5b59-4e6f-9e0e-13569da1ad33)] -interface nsIXTFXULVisualWrapper : nsIXTFElementWrapper -{ +[scriptable, uuid(1ab4b724-fd7e-41af-bc19-80bb7299f3c0)] +interface nsIXTFXULVisualWrapper : nsIXTFStyledElementWrapper +{ }; diff --git a/mozilla/content/xtf/src/Makefile.in b/mozilla/content/xtf/src/Makefile.in index 0e541804caa..8fba17de816 100644 --- a/mozilla/content/xtf/src/Makefile.in +++ b/mozilla/content/xtf/src/Makefile.in @@ -69,6 +69,7 @@ CPPSRCS = \ nsXTFWeakTearoff.cpp \ nsXTFXMLVisualWrapper.cpp \ nsXTFXULVisualWrapper.cpp \ + nsXTFBindableElementWrapper.cpp \ $(NULL) ifdef MOZ_SVG diff --git a/mozilla/content/xtf/src/nsXTFBindableElementWrapper.cpp b/mozilla/content/xtf/src/nsXTFBindableElementWrapper.cpp new file mode 100644 index 00000000000..cd10a85c1a3 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFBindableElementWrapper.cpp @@ -0,0 +1,227 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * Olli Pettay + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsCOMPtr.h" +#include "nsXTFElementWrapper.h" +#include "nsIXTFBindableElement.h" +#include "nsXTFWeakTearoff.h" +#include "nsIXTFBindableElementWrapper.h" +#include "nsXTFInterfaceAggregator.h" + +typedef nsXTFStyledElementWrapper nsXTFBindableElementWrapperBase; + +//////////////////////////////////////////////////////////////////////// +// nsXTFBindableElementWrapper class +class nsXTFBindableElementWrapper : public nsXTFBindableElementWrapperBase, + public nsIXTFBindableElementWrapper +{ +protected: + friend nsresult NS_NewXTFBindableElementWrapper(nsIXTFBindableElement* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + + nsXTFBindableElementWrapper(nsINodeInfo* aNodeInfo, nsIXTFBindableElement* xtfElement); + virtual ~nsXTFBindableElementWrapper(); + nsresult Init(); +public: + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFElementWrapperPrivate interface + virtual PRUint32 GetElementType() { return nsIXTFElement::ELEMENT_TYPE_BINDABLE; } + + // nsIXTFBindableElementWrapper interface + NS_DECL_NSIXTFBINDABLEELEMENTWRAPPER + + // nsIXTFStyledElementWrapper + NS_FORWARD_NSIXTFSTYLEDELEMENTWRAPPER(nsXTFStyledElementWrapper::) + + // nsIXTFElementWrapper interface + NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFBindableElementWrapperBase::) + + NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array); +private: + virtual nsIXTFElement *GetXTFElement() const { return mXTFElement; } + + nsCOMPtr mXTFElement; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFBindableElementWrapper::nsXTFBindableElementWrapper(nsINodeInfo* aNodeInfo, + nsIXTFBindableElement* xtfElement) +: nsXTFBindableElementWrapperBase(aNodeInfo), mXTFElement(xtfElement) +{ +#ifdef DEBUG +// printf("nsXTFBindableElementWrapper CTOR\n"); +#endif + NS_ASSERTION(mXTFElement, "xtfElement is null"); +} + +nsresult +nsXTFBindableElementWrapper::Init() +{ + nsXTFBindableElementWrapperBase::Init(); + + // pass a weak wrapper (non base object ref-counted), so that + // our mXTFElement can safely addref/release. + nsISupports *weakWrapper = nsnull; + nsresult rv = NS_NewXTFWeakTearoff(NS_GET_IID(nsIXTFBindableElementWrapper), + (nsIXTFBindableElementWrapper*)this, + &weakWrapper); + if (!weakWrapper) { + NS_ERROR("could not construct weak wrapper"); + return rv; + } + + mXTFElement->OnCreated((nsIXTFBindableElementWrapper*)weakWrapper); + NS_RELEASE(weakWrapper); + + return NS_OK; +} + +NS_IMETHODIMP +nsXTFBindableElementWrapper::GetInterfaces(PRUint32 *count, nsIID * **array) +{ + *count = 0; + *array = nsnull; + return NS_OK; +} + +nsXTFBindableElementWrapper::~nsXTFBindableElementWrapper() +{ + mXTFElement->OnDestroyed(); + mXTFElement = nsnull; + +#ifdef DEBUG +// printf("nsXTFBindableElementWrapper DTOR\n"); +#endif +} + +nsresult +NS_NewXTFBindableElementWrapper(nsIXTFBindableElement* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult) +{ + *aResult = nsnull; + + if (!xtfElement) { + NS_ERROR("can't construct an xtf wrapper without an xtf element"); + return NS_ERROR_INVALID_ARG; + } + + nsXTFBindableElementWrapper* result = new nsXTFBindableElementWrapper(ni, xtfElement); + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + + nsresult rv = result->Init(); + + if (NS_FAILED(rv)) { + NS_RELEASE(result); + return rv; + } + + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + +NS_IMPL_ADDREF_INHERITED(nsXTFBindableElementWrapper, nsXTFBindableElementWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFBindableElementWrapper, nsXTFBindableElementWrapperBase) + +NS_IMETHODIMP +nsXTFBindableElementWrapper::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + nsresult rv; + + if (aIID.Equals(NS_GET_IID(nsIXTFElementWrapperPrivate))) { + *aInstancePtr = NS_STATIC_CAST(nsIXTFElementWrapperPrivate*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + + if(aIID.Equals(NS_GET_IID(nsIXTFElementWrapper))) { + *aInstancePtr = + NS_STATIC_CAST(nsIXTFElementWrapper*, + NS_STATIC_CAST(nsXTFBindableElementWrapperBase*, this)); + + NS_ADDREF_THIS(); + return NS_OK; + } + + if (aIID.Equals(NS_GET_IID(nsIXTFBindableElementWrapper))) { + *aInstancePtr = NS_STATIC_CAST(nsIXTFBindableElementWrapper*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + + if (aIID.Equals(NS_GET_IID(nsIXTFStyledElementWrapper))) { + *aInstancePtr = NS_STATIC_CAST(nsIXTFStyledElementWrapper*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + + // Note, using the nsIClassInfo from nsXMLElement. + if (NS_SUCCEEDED(rv = nsXTFElementWrapperBase::QueryInterface(aIID, aInstancePtr))) { + return rv; + } + + // try to get get the interface from our wrapped element: + void *innerPtr = nsnull; + QueryInterfaceInner(aIID, &innerPtr); + + if (innerPtr) + return NS_NewXTFInterfaceAggregator(aIID, + NS_STATIC_CAST(nsISupports*, innerPtr), + NS_STATIC_CAST(nsIContent*, this), + aInstancePtr); + + return NS_ERROR_NO_INTERFACE; +} + +//---------------------------------------------------------------------- +// nsIXTFBindableElementWrapper implementation: + +// XXX nothing yet + diff --git a/mozilla/content/xtf/src/nsXTFBindableElementWrapper.h b/mozilla/content/xtf/src/nsXTFBindableElementWrapper.h new file mode 100644 index 00000000000..80ab20adf55 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFBindableElementWrapper.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Olli Pettay. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Olli Pettay (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __NS_XTFBINDABLEELEMENTWRAPPER_H__ +#define __NS_XTFBINDABLEELEMENTWRAPPER_H__ + +class nsIXTFBindableElement; +class nsIContent; +class nsINodeInfo; + +nsresult +NS_NewXTFBindableElementWrapper(nsIXTFBindableElement* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + +#endif // __NS_XTFBINDABLEELEMENTWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFElementWrapper.cpp b/mozilla/content/xtf/src/nsXTFElementWrapper.cpp index 8cfae84f867..83e1535e0bd 100644 --- a/mozilla/content/xtf/src/nsXTFElementWrapper.cpp +++ b/mozilla/content/xtf/src/nsXTFElementWrapper.cpp @@ -704,3 +704,62 @@ nsXTFElementWrapper::HandleDOMEvent(nsPresContext* aPresContext, return rv; } +// nsXTFStyleableElementWrapper + +nsXTFStyledElementWrapper::nsXTFStyledElementWrapper(nsINodeInfo* aNodeInfo) +: nsXTFElementWrapper(aNodeInfo) +{ +} + +nsIAtom * +nsXTFStyledElementWrapper::GetClassAttributeName() const +{ + return mClassAttributeName; +} + +const nsAttrValue* +nsXTFStyledElementWrapper::GetClasses() const +{ + const nsAttrValue* val = nsnull; + nsIAtom* clazzAttr = GetClassAttributeName(); + if (clazzAttr) { + val = mAttrsAndChildren.GetAttr(clazzAttr); + // This is possibly the first time we need any classes. + if (val && val->Type() == nsAttrValue::eString) { + nsAutoString value; + val->ToString(value); + nsAttrValue newValue; + newValue.ParseAtomArray(value); + NS_CONST_CAST(nsAttrAndChildArray*, &mAttrsAndChildren)-> + SetAndTakeAttr(clazzAttr, newValue); + } + } + return val; +} + +PRBool +nsXTFStyledElementWrapper::HasClass(nsIAtom* aClass, PRBool /*aCaseSensitive*/) const +{ + const nsAttrValue* val = GetClasses(); + if (val) { + if (val->Type() == nsAttrValue::eAtom) { + return aClass == val->GetAtomValue(); + } + + if (val->Type() == nsAttrValue::eAtomArray) { + return val->GetAtomArrayValue()->IndexOf(aClass) >= 0; + } + } + return PR_FALSE; +} + +nsresult +nsXTFStyledElementWrapper::SetClassAttributeName(nsIAtom* aName) +{ + // The class attribute name can be set only once + if (mClassAttributeName || !aName) + return NS_ERROR_FAILURE; + + mClassAttributeName = aName; + return NS_OK; +} diff --git a/mozilla/content/xtf/src/nsXTFElementWrapper.h b/mozilla/content/xtf/src/nsXTFElementWrapper.h index ae78511f35e..630d48f66bf 100644 --- a/mozilla/content/xtf/src/nsXTFElementWrapper.h +++ b/mozilla/content/xtf/src/nsXTFElementWrapper.h @@ -44,6 +44,7 @@ #include "nsXMLElement.h" #include "nsIXTFAttributeHandler.h" #include "nsIXTFElement.h" +#include "nsIXTFStyledElementWrapper.h" typedef nsXMLElement nsXTFElementWrapperBase; @@ -137,4 +138,19 @@ protected: nsCOMPtr mAttributeHandler; }; +class nsXTFStyledElementWrapper : public nsXTFElementWrapper +{ +public: + nsXTFStyledElementWrapper(nsINodeInfo* aNodeInfo); + + // for nsIStyledContent + virtual nsIAtom *GetClassAttributeName() const; + virtual const nsAttrValue* GetClasses() const; + NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const; + + nsresult SetClassAttributeName(nsIAtom* aName); +protected: + nsCOMPtr mClassAttributeName; +}; + #endif // __NS_XTFELEMENTWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp index 41b0d27b55a..785caa38889 100644 --- a/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp +++ b/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp @@ -65,10 +65,13 @@ public: // nsIXTFElementWrapperPrivate interface virtual PRUint32 GetElementType() { return nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL; } - + // nsIXTFSVGVisualWrapper interface NS_DECL_NSIXTFSVGVISUALWRAPPER - + + // nsIXTFStyledElementWrapper + NS_FORWARD_NSIXTFSTYLEDELEMENTWRAPPER(nsXTFStyledElementWrapper::) + // nsIXTFElementWrapper interface NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFSVGVisualWrapperBase::) @@ -162,6 +165,7 @@ NS_IMPL_RELEASE_INHERITED(nsXTFSVGVisualWrapper, nsXTFSVGVisualWrapperBase) NS_INTERFACE_MAP_BEGIN(nsXTFSVGVisualWrapper) NS_INTERFACE_MAP_ENTRY(nsIXTFSVGVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFStyledElementWrapper) NS_INTERFACE_MAP_END_INHERITING(nsXTFSVGVisualWrapperBase) //---------------------------------------------------------------------- diff --git a/mozilla/content/xtf/src/nsXTFService.cpp b/mozilla/content/xtf/src/nsXTFService.cpp index de597074782..550b1ef4e59 100644 --- a/mozilla/content/xtf/src/nsXTFService.cpp +++ b/mozilla/content/xtf/src/nsXTFService.cpp @@ -50,6 +50,8 @@ #include "nsXTFGenericElementWrapper.h" #include "nsXTFXMLVisualWrapper.h" #include "nsXTFXULVisualWrapper.h" +#include "nsIXTFBindableElement.h" +#include "nsXTFBindableElementWrapper.h" #ifdef MOZ_SVG #include "nsXTFSVGVisualWrapper.h" @@ -149,7 +151,11 @@ nsXTFService::CreateElement(nsIContent** aResult, nsINodeInfo* aNodeInfo) { nsCOMPtr elem2 = do_QueryInterface(elem); return NS_NewXTFGenericElementWrapper(elem2, aNodeInfo, aResult); - break; + } + case nsIXTFElement::ELEMENT_TYPE_BINDABLE: + { + nsCOMPtr elem2 = do_QueryInterface(elem); + return NS_NewXTFBindableElementWrapper(elem2, aNodeInfo, aResult); } case nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL: { @@ -158,20 +164,18 @@ nsXTFService::CreateElement(nsIContent** aResult, nsINodeInfo* aNodeInfo) return NS_NewXTFSVGVisualWrapper(elem2, aNodeInfo, aResult); #else NS_ERROR("xtf svg visuals are only supported in mozilla builds with native svg support"); -#endif break; +#endif } case nsIXTFElement::ELEMENT_TYPE_XML_VISUAL: { nsCOMPtr elem2 = do_QueryInterface(elem); return NS_NewXTFXMLVisualWrapper(elem2, aNodeInfo, aResult); - break; } case nsIXTFElement::ELEMENT_TYPE_XUL_VISUAL: { nsCOMPtr elem2 = do_QueryInterface(elem); return NS_NewXTFXULVisualWrapper(elem2, aNodeInfo, aResult); - break; } default: NS_ERROR("unknown xtf element type"); diff --git a/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp index ff952e429aa..f46e327938f 100644 --- a/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp +++ b/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp @@ -120,56 +120,5 @@ nsXTFVisualWrapper::ApplyDocumentStyleSheets() nsresult nsXTFVisualWrapper::Init() { - nsresult rv = nsXTFVisualWrapperBase::Init(); - NS_ENSURE_SUCCESS(rv, rv); - return GetXTFVisual()->GetClassAttributeName(getter_AddRefs(mClassAttributeName)); + return nsXTFVisualWrapperBase::Init(); } - -nsIAtom * -nsXTFVisualWrapper::GetClassAttributeName() const -{ -#ifdef DEBUG - nsCOMPtr classAttr; - GetXTFVisual()->GetClassAttributeName(getter_AddRefs(classAttr)); - NS_WARN_IF_FALSE(classAttr == mClassAttributeName, - "The name of the class attribute has changed."); -#endif - return mClassAttributeName; -} - -const nsAttrValue* -nsXTFVisualWrapper::GetClasses() const -{ - const nsAttrValue* val = nsnull; - nsIAtom* clazzAttr = GetClassAttributeName(); - if (clazzAttr) { - val = mAttrsAndChildren.GetAttr(clazzAttr); - // This is possibly the first time we need any classes. - if (val && val->Type() == nsAttrValue::eString) { - nsAutoString value; - val->ToString(value); - nsAttrValue newValue; - newValue.ParseAtomArray(value); - NS_CONST_CAST(nsAttrAndChildArray*, &mAttrsAndChildren)-> - SetAndTakeAttr(clazzAttr, newValue); - } - } - return val; -} - -NS_IMETHODIMP_(PRBool) -nsXTFVisualWrapper::HasClass(nsIAtom* aClass, PRBool /*aCaseSensitive*/) const -{ - const nsAttrValue* val = GetClasses(); - if (val) { - if (val->Type() == nsAttrValue::eAtom) { - return aClass == val->GetAtomValue(); - } - - if (val->Type() == nsAttrValue::eAtomArray) { - return val->GetAtomArrayValue()->IndexOf(aClass) >= 0; - } - } - return PR_FALSE; -} - diff --git a/mozilla/content/xtf/src/nsXTFVisualWrapper.h b/mozilla/content/xtf/src/nsXTFVisualWrapper.h index 9789eb01566..df7efe67822 100644 --- a/mozilla/content/xtf/src/nsXTFVisualWrapper.h +++ b/mozilla/content/xtf/src/nsXTFVisualWrapper.h @@ -44,7 +44,7 @@ #include "nsIXTFVisualWrapperPrivate.h" #include "nsIXTFVisual.h" -typedef nsXTFElementWrapper nsXTFVisualWrapperBase; +typedef nsXTFStyledElementWrapper nsXTFVisualWrapperBase; class nsXTFVisualWrapper : public nsXTFVisualWrapperBase, public nsIXTFVisualWrapperPrivate @@ -64,18 +64,12 @@ public: virtual PRBool ApplyDocumentStyleSheets(); nsresult Init(); - - // nsIStyledContent - virtual nsIAtom *GetClassAttributeName() const; - virtual const nsAttrValue* GetClasses() const; - NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const; protected: // to be implemented by subclasses: virtual nsIXTFVisual *GetXTFVisual() const = 0; nsCOMPtr mVisualContent; - nsCOMPtr mClassAttributeName; }; #endif // __NS_XTFVISUALWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp index 9767e9a8aae..88ae010f15e 100644 --- a/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp +++ b/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp @@ -69,6 +69,9 @@ public: // nsIXTFXMLVisualWrapper interface NS_DECL_NSIXTFXMLVISUALWRAPPER + // nsIXTFStyledElementWrapper + NS_FORWARD_NSIXTFSTYLEDELEMENTWRAPPER(nsXTFStyledElementWrapper::) + // nsIXTFElementWrapper interface NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFXMLVisualWrapperBase::) @@ -162,6 +165,7 @@ NS_IMPL_RELEASE_INHERITED(nsXTFXMLVisualWrapper,nsXTFXMLVisualWrapperBase) NS_INTERFACE_MAP_BEGIN(nsXTFXMLVisualWrapper) NS_INTERFACE_MAP_ENTRY(nsIXTFXMLVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFStyledElementWrapper) NS_INTERFACE_MAP_END_INHERITING(nsXTFXMLVisualWrapperBase) //---------------------------------------------------------------------- diff --git a/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp index f0eb7b09372..5f5f8405025 100644 --- a/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp +++ b/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp @@ -68,7 +68,10 @@ public: // nsIXTFXULVisualWrapper interface NS_DECL_NSIXTFXULVISUALWRAPPER - + + // nsIXTFStyledElementWrapper + NS_FORWARD_NSIXTFSTYLEDELEMENTWRAPPER(nsXTFStyledElementWrapper::) + // nsIXTFElementWrapper interface NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFXULVisualWrapperBase::) @@ -162,6 +165,7 @@ NS_IMPL_RELEASE_INHERITED(nsXTFXULVisualWrapper,nsXTFXULVisualWrapperBase) NS_INTERFACE_MAP_BEGIN(nsXTFXULVisualWrapper) NS_INTERFACE_MAP_ENTRY(nsIXTFXULVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFStyledElementWrapper) NS_INTERFACE_MAP_END_INHERITING(nsXTFXULVisualWrapperBase) //---------------------------------------------------------------------- diff --git a/mozilla/extensions/xforms/nsXFormsAtoms.h b/mozilla/extensions/xforms/nsXFormsAtoms.h index 731b951fe3c..e5b31483055 100644 --- a/mozilla/extensions/xforms/nsXFormsAtoms.h +++ b/mozilla/extensions/xforms/nsXFormsAtoms.h @@ -36,6 +36,9 @@ * * ***** END LICENSE BLOCK ***** */ +#ifndef nsXFormsAtoms_h_ +#define nsXFormsAtoms_h_ + #include "nsStaticAtom.h" /** @@ -72,3 +75,5 @@ class nsXFormsAtoms private: static NS_HIDDEN_(const nsStaticAtom) Atoms_info[]; }; + +#endif diff --git a/mozilla/extensions/xforms/nsXFormsControlStub.cpp b/mozilla/extensions/xforms/nsXFormsControlStub.cpp index 87e44db8e26..5398173d6db 100644 --- a/mozilla/extensions/xforms/nsXFormsControlStub.cpp +++ b/mozilla/extensions/xforms/nsXFormsControlStub.cpp @@ -37,7 +37,6 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIModelElementPrivate.h" -#include "nsXFormsAtoms.h" #include "nsXFormsControlStub.h" #include "nsXFormsMDGEngine.h" @@ -83,20 +82,15 @@ nsXFormsHintHelpListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsControlStub, - nsXFormsXMLVisualStub, - nsIXFormsContextControl, - nsIXFormsControl) - NS_IMETHODIMP -nsXFormsControlStub::GetBoundNode(nsIDOMNode **aBoundNode) +nsXFormsControlStubBase::GetBoundNode(nsIDOMNode **aBoundNode) { NS_IF_ADDREF(*aBoundNode = mBoundNode); return NS_OK; } NS_IMETHODIMP -nsXFormsControlStub::GetDependencies(nsCOMArray **aDependencies) +nsXFormsControlStubBase::GetDependencies(nsCOMArray **aDependencies) { if (aDependencies) *aDependencies = &mDependencies; @@ -104,14 +98,14 @@ nsXFormsControlStub::GetDependencies(nsCOMArray **aDependencies) } NS_IMETHODIMP -nsXFormsControlStub::GetElement(nsIDOMElement **aElement) +nsXFormsControlStubBase::GetElement(nsIDOMElement **aElement) { NS_IF_ADDREF(*aElement = mElement); return NS_OK; } void -nsXFormsControlStub::RemoveIndexListeners() +nsXFormsControlStubBase::RemoveIndexListeners() { if (!mIndexesUsed.Count()) return; @@ -125,9 +119,9 @@ nsXFormsControlStub::RemoveIndexListeners() } NS_IMETHODIMP -nsXFormsControlStub::ResetBoundNode(const nsString &aBindAttribute, - PRUint16 aResultType, - nsIDOMXPathResult **aResult) +nsXFormsControlStubBase::ResetBoundNode(const nsString &aBindAttribute, + PRUint16 aResultType, + nsIDOMXPathResult **aResult) { // Clear existing bound node, etc. mBoundNode = nsnull; @@ -167,21 +161,21 @@ nsXFormsControlStub::ResetBoundNode(const nsString &aBindAttribute, } NS_IMETHODIMP -nsXFormsControlStub::Bind() +nsXFormsControlStubBase::Bind() { return ResetBoundNode(NS_LITERAL_STRING("ref"), nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE); } NS_IMETHODIMP -nsXFormsControlStub::TryFocus(PRBool* aOK) +nsXFormsControlStubBase::TryFocus(PRBool* aOK) { *aOK = PR_FALSE; return NS_OK; } NS_IMETHODIMP -nsXFormsControlStub::IsEventTarget(PRBool *aOK) +nsXFormsControlStubBase::IsEventTarget(PRBool *aOK) { *aOK = PR_TRUE; return NS_OK; @@ -189,7 +183,7 @@ nsXFormsControlStub::IsEventTarget(PRBool *aOK) nsresult -nsXFormsControlStub::ProcessNodeBinding(const nsString &aBindingAttr, +nsXFormsControlStubBase::ProcessNodeBinding(const nsString &aBindingAttr, PRUint16 aResultType, nsIDOMXPathResult **aResult, nsIModelElementPrivate **aModel) @@ -255,7 +249,7 @@ nsXFormsControlStub::ProcessNodeBinding(const nsString &aBindingAttr, } void -nsXFormsControlStub::ResetHelpAndHint(PRBool aInitialize) +nsXFormsControlStubBase::ResetHelpAndHint(PRBool aInitialize) { nsCOMPtr targ(do_QueryInterface(mElement)); if (!targ) @@ -284,7 +278,7 @@ nsXFormsControlStub::ResetHelpAndHint(PRBool aInitialize) } PRBool -nsXFormsControlStub::GetReadOnlyState() +nsXFormsControlStubBase::GetReadOnlyState() { PRBool res = PR_FALSE; if (mElement) { @@ -294,7 +288,7 @@ nsXFormsControlStub::GetReadOnlyState() } PRBool -nsXFormsControlStub::GetRelevantState() +nsXFormsControlStubBase::GetRelevantState() { PRBool res = PR_FALSE; if (mElement) { @@ -303,9 +297,9 @@ nsXFormsControlStub::GetRelevantState() return res; } -NS_IMETHODIMP -nsXFormsControlStub::HandleDefault(nsIDOMEvent *aEvent, - PRBool *aHandled) +nsresult +nsXFormsControlStubBase::HandleDefault(nsIDOMEvent *aEvent, + PRBool *aHandled) { NS_ENSURE_ARG(aHandled); *aHandled = PR_FALSE; @@ -332,8 +326,8 @@ nsXFormsControlStub::HandleDefault(nsIDOMEvent *aEvent, return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::OnCreated(nsIXTFXMLVisualWrapper *aWrapper) +nsresult +nsXFormsControlStubBase::Create(nsIXTFElementWrapper *aWrapper) { aWrapper->SetNotificationMask(kStandardNotificationMask); @@ -345,8 +339,8 @@ nsXFormsControlStub::OnCreated(nsIXTFXMLVisualWrapper *aWrapper) return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::OnDestroyed() +nsresult +nsXFormsControlStubBase::OnDestroyed() { ResetHelpAndHint(PR_FALSE); RemoveIndexListeners(); @@ -360,8 +354,8 @@ nsXFormsControlStub::OnDestroyed() return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::DocumentChanged(nsIDOMDocument *aNewDocument) +nsresult +nsXFormsControlStubBase::DocumentChanged(nsIDOMDocument *aNewDocument) { // We need to re-evaluate our instance data binding when our document // changes, since our context can change @@ -373,8 +367,8 @@ nsXFormsControlStub::DocumentChanged(nsIDOMDocument *aNewDocument) return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::ParentChanged(nsIDOMElement *aNewParent) +nsresult +nsXFormsControlStubBase::ParentChanged(nsIDOMElement *aNewParent) { mHasParent = aNewParent != nsnull; // We need to re-evaluate our instance data binding when our parent changes, @@ -387,29 +381,29 @@ nsXFormsControlStub::ParentChanged(nsIDOMElement *aNewParent) return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::WillSetAttribute(nsIAtom *aName, const nsAString &aValue) +nsresult +nsXFormsControlStubBase::WillSetAttribute(nsIAtom *aName, const nsAString &aValue) { MaybeRemoveFromModel(aName, aValue); return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::AttributeSet(nsIAtom *aName, const nsAString &aValue) +nsresult +nsXFormsControlStubBase::AttributeSet(nsIAtom *aName, const nsAString &aValue) { MaybeBindAndRefresh(aName); return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::WillRemoveAttribute(nsIAtom *aName) +nsresult +nsXFormsControlStubBase::WillRemoveAttribute(nsIAtom *aName) { MaybeRemoveFromModel(aName, EmptyString()); return NS_OK; } -NS_IMETHODIMP -nsXFormsControlStub::AttributeRemoved(nsIAtom *aName) +nsresult +nsXFormsControlStubBase::AttributeRemoved(nsIAtom *aName) { MaybeBindAndRefresh(aName); return NS_OK; @@ -418,16 +412,16 @@ nsXFormsControlStub::AttributeRemoved(nsIAtom *aName) // nsIXFormsContextControl NS_IMETHODIMP -nsXFormsControlStub::SetContextNode(nsIDOMNode *aContextNode) +nsXFormsControlStubBase::SetContextNode(nsIDOMNode *aContextNode) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -nsXFormsControlStub::GetContext(nsAString &aModelID, - nsIDOMNode **aContextNode, - PRInt32 *aContextPosition, - PRInt32 *aContextSize) +nsXFormsControlStubBase::GetContext(nsAString &aModelID, + nsIDOMNode **aContextNode, + PRInt32 *aContextPosition, + PRInt32 *aContextSize) { NS_ENSURE_ARG(aContextSize); NS_ENSURE_ARG(aContextPosition); @@ -451,7 +445,7 @@ nsXFormsControlStub::GetContext(nsAString &aModelID, } void -nsXFormsControlStub::ResetProperties() +nsXFormsControlStubBase::ResetProperties() { if (!mElement) { return; @@ -465,7 +459,7 @@ nsXFormsControlStub::ResetProperties() } void -nsXFormsControlStub::AddRemoveSNBAttr(nsIAtom *aName, const nsAString &aValue) +nsXFormsControlStubBase::AddRemoveSNBAttr(nsIAtom *aName, const nsAString &aValue) { nsAutoString attrStr, attrValue; aName->ToString(attrStr); @@ -487,7 +481,7 @@ nsXFormsControlStub::AddRemoveSNBAttr(nsIAtom *aName, const nsAString &aValue) } void -nsXFormsControlStub::MaybeBindAndRefresh(nsIAtom *aName) +nsXFormsControlStubBase::MaybeBindAndRefresh(nsIAtom *aName) { if (aName == nsXFormsAtoms::bind || aName == nsXFormsAtoms::ref || @@ -500,8 +494,8 @@ nsXFormsControlStub::MaybeBindAndRefresh(nsIAtom *aName) } void -nsXFormsControlStub::MaybeRemoveFromModel(nsIAtom *aName, - const nsAString &aValue) +nsXFormsControlStubBase::MaybeRemoveFromModel(nsIAtom *aName, + const nsAString &aValue) { if (aName == nsXFormsAtoms::model || aName == nsXFormsAtoms::bind || @@ -514,3 +508,15 @@ nsXFormsControlStub::MaybeRemoveFromModel(nsIAtom *aName, } } } + +NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsControlStub, + nsXFormsXMLVisualStub, + nsIXFormsContextControl, + nsIXFormsControl) + + +NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsBindableControlStub, + nsXFormsBindableStub, + nsIXFormsContextControl, + nsIXFormsControl) + diff --git a/mozilla/extensions/xforms/nsXFormsControlStub.h b/mozilla/extensions/xforms/nsXFormsControlStub.h index 4504b157e1c..f1b97382bd0 100644 --- a/mozilla/extensions/xforms/nsXFormsControlStub.h +++ b/mozilla/extensions/xforms/nsXFormsControlStub.h @@ -21,6 +21,7 @@ * * Contributor(s): * Allan Beaufour + * Olli Pettay * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -45,6 +46,7 @@ #include "nsIDOMElement.h" #include "nsIDOMNode.h" #include "nsIXTFElement.h" +#include "nsXFormsAtoms.h" #include "nsIDOMEventListener.h" #include "nsIModelElementPrivate.h" @@ -52,6 +54,8 @@ #include "nsIXFormsRepeatElement.h" #include "nsXFormsStubElement.h" #include "nsXFormsUtils.h" +#include "nsIXTFXMLVisualWrapper.h" +#include "nsIXTFBindableElementWrapper.h" class nsIDOMEvent; class nsIDOMXPathResult; @@ -61,19 +65,14 @@ class nsIXTFXMLVisualWrapper; * Common stub for all XForms controls that inherit from nsIXFormsControl and * is bound to an instance node. * - * It also inherits from nsXFormsXMLVisualStub, and overrides a couple of its - * functions. - * * @bug If a control has a model attribute, but no binding attributes we fail * to set this as the context for children. We need to return the contextnode * from EvaluateNodeBinding in that case, and return that in GetContext(). (XXX) * @see http://bugzilla.mozilla.org/show_bug.cgi?id=280366 */ -class nsXFormsControlStub : public nsIXFormsControl, - public nsXFormsXMLVisualStub +class nsXFormsControlStubBase : public nsIXFormsControl { public: - NS_DECL_ISUPPORTS_INHERITED /** The standard notification flags set on nsIXTFElement */ const PRUint32 kStandardNotificationMask; @@ -95,20 +94,17 @@ public: NS_IMETHOD TryFocus(PRBool* aOK); NS_IMETHOD IsEventTarget(PRBool *aOK); - // nsIXTFXMLVisual overrides - /** This sets the notification mask and initializes mElement */ - NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper); - - // nsIXTFElement overrides - NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent, - PRBool *aHandled); - NS_IMETHOD OnDestroyed(); - NS_IMETHOD DocumentChanged(nsIDOMDocument *aNewDocument); - NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent); - NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue); - NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue); - NS_IMETHOD WillRemoveAttribute(nsIAtom *aName); - NS_IMETHOD AttributeRemoved(nsIAtom *aName); + nsresult Create(nsIXTFElementWrapper *aWrapper); + // for nsIXTFElement + nsresult HandleDefault(nsIDOMEvent *aEvent, + PRBool *aHandled); + nsresult OnDestroyed(); + nsresult DocumentChanged(nsIDOMDocument *aNewDocument); + nsresult ParentChanged(nsIDOMElement *aNewParent); + nsresult WillSetAttribute(nsIAtom *aName, const nsAString &aValue); + nsresult AttributeSet(nsIAtom *aName, const nsAString &aValue); + nsresult WillRemoveAttribute(nsIAtom *aName); + nsresult AttributeRemoved(nsIAtom *aName); /** * This function manages the mBindAttrsCount value. mBindAttrsCount will @@ -132,7 +128,7 @@ public: NS_DECL_NSIXFORMSCONTEXTCONTROL /** Constructor */ - nsXFormsControlStub() : + nsXFormsControlStubBase() : kStandardNotificationMask(nsIXTFElement::NOTIFY_WILL_SET_ATTRIBUTE | nsIXTFElement::NOTIFY_ATTRIBUTE_SET | nsIXTFElement::NOTIFY_WILL_REMOVE_ATTRIBUTE | @@ -224,4 +220,129 @@ protected: void RemoveIndexListeners(); }; + +/** + * nsXFormsControlStub inherits from nsXFormsXMLVisualStub + */ +class nsXFormsControlStub : public nsXFormsControlStubBase, + public nsXFormsXMLVisualStub +{ +public: + NS_DECL_ISUPPORTS_INHERITED + // nsIXTFXMLVisual overrides + /** This sets the notification mask and initializes mElement */ + NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper) + { + NS_ENSURE_ARG(aWrapper); + aWrapper->SetClassAttributeName(nsXFormsAtoms::clazz); + return nsXFormsControlStubBase::Create(aWrapper); + } + + // nsIXTFElement overrides + NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent, + PRBool *aHandled) + { + return nsXFormsControlStubBase::HandleDefault(aEvent, aHandled); + } + + NS_IMETHOD OnDestroyed() { + return nsXFormsControlStubBase::OnDestroyed(); + } + + NS_IMETHOD DocumentChanged(nsIDOMDocument *aNewDocument) + { + return nsXFormsControlStubBase::DocumentChanged(aNewDocument); + } + + NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent) + { + return nsXFormsControlStubBase::ParentChanged(aNewParent); + } + + NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue) + { + return nsXFormsControlStubBase::WillSetAttribute(aName, aValue); + } + + NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue) + { + return nsXFormsControlStubBase::AttributeSet(aName, aValue); + } + + NS_IMETHOD WillRemoveAttribute(nsIAtom *aName) + { + return nsXFormsControlStubBase::WillRemoveAttribute(aName); + } + + NS_IMETHOD AttributeRemoved(nsIAtom *aName) + { + return nsXFormsControlStubBase::AttributeRemoved(aName); + } + + /** Constructor */ + nsXFormsControlStub() : nsXFormsControlStubBase() {}; +}; + + +/** + * nsXFormsBindableControlStub inherits from nsXFormsBindableStub + */ +class nsXFormsBindableControlStub : public nsXFormsControlStubBase, + public nsXFormsBindableStub +{ +public: + NS_DECL_ISUPPORTS_INHERITED + // nsIXTFBindableElement overrides + /** This sets the notification mask and initializes mElement */ + NS_IMETHOD OnCreated(nsIXTFBindableElementWrapper *aWrapper) + { + NS_ENSURE_ARG(aWrapper); + aWrapper->SetClassAttributeName(nsXFormsAtoms::clazz); + return nsXFormsControlStubBase::Create(aWrapper); + } + + // nsIXTFElement overrides + NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent, + PRBool *aHandled) + { + return nsXFormsControlStubBase::HandleDefault(aEvent, aHandled); + } + + NS_IMETHOD OnDestroyed() { + return nsXFormsControlStubBase::OnDestroyed(); + } + + NS_IMETHOD DocumentChanged(nsIDOMDocument *aNewDocument) + { + return nsXFormsControlStubBase::DocumentChanged(aNewDocument); + } + + NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent) + { + return nsXFormsControlStubBase::ParentChanged(aNewParent); + } + + NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue) + { + return nsXFormsControlStubBase::WillSetAttribute(aName, aValue); + } + + NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue) + { + return nsXFormsControlStubBase::AttributeSet(aName, aValue); + } + + NS_IMETHOD WillRemoveAttribute(nsIAtom *aName) + { + return nsXFormsControlStubBase::WillRemoveAttribute(aName); + } + + NS_IMETHOD AttributeRemoved(nsIAtom *aName) + { + return nsXFormsControlStubBase::AttributeRemoved(aName); + } + + /** Constructor */ + nsXFormsBindableControlStub() : nsXFormsControlStubBase() {}; +}; #endif diff --git a/mozilla/extensions/xforms/nsXFormsStubElement.cpp b/mozilla/extensions/xforms/nsXFormsStubElement.cpp index 14c3af1fe53..21ddb5a4ee0 100644 --- a/mozilla/extensions/xforms/nsXFormsStubElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsStubElement.cpp @@ -374,13 +374,6 @@ nsXFormsXMLVisualStub::DidLayout() return NS_OK; } -NS_IMETHODIMP -nsXFormsXMLVisualStub::GetClassAttributeName(nsIAtom** aName) -{ - NS_ADDREF(*aName = nsXFormsAtoms::clazz); - return NS_OK; -} - NS_IMETHODIMP nsXFormsXMLVisualStub::OnCreated(nsIXTFXMLVisualWrapper *aWrapper) { @@ -403,3 +396,160 @@ NS_NewXFormsXMLVisualStub(nsIXTFElement **aResult) NS_ADDREF(*aResult); return NS_OK; } + +// nsXFormsBindableStub implementation + +NS_IMPL_ISUPPORTS2(nsXFormsBindableStub, nsIXTFElement, nsIXTFBindableElement) + +NS_IMETHODIMP +nsXFormsBindableStub::OnDestroyed() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::GetElementType(PRUint32 *aElementType) +{ + *aElementType = nsIXTFElement::ELEMENT_TYPE_BINDABLE; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::GetIsAttributeHandler(PRBool *aIsAttributeHandler) +{ + *aIsAttributeHandler = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::GetScriptingInterfaces(PRUint32 *aCount, nsIID ***aArray) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillChangeDocument(nsIDOMDocument *aNewDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::DocumentChanged(nsIDOMDocument *aNewDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillChangeParent(nsIDOMElement *aNewParent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::ParentChanged(nsIDOMElement *aNewParent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillInsertChild(nsIDOMNode *aChild, PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillAppendChild(nsIDOMNode *aChild) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::ChildAppended(nsIDOMNode *aChild) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillRemoveChild(PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::ChildRemoved(PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillSetAttribute(nsIAtom *aName, + const nsAString &aNewValue) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::AttributeSet(nsIAtom *aName, const nsAString &aNewValue) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::WillRemoveAttribute(nsIAtom *aName) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::AttributeRemoved(nsIAtom *aName) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::BeginAddingChildren() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::DoneAddingChildren() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled) +{ + *aHandled = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::OnCreated(nsIXTFBindableElementWrapper *aWrapper) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsBindableStub::CloneState(nsIDOMElement *aElement) +{ + return NS_OK; +} + +nsresult +NS_NewXFormsBindableStub(nsIXTFElement **aResult) +{ + *aResult = new nsXFormsBindableStub(); + 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 a9b6d2ac336..1cf76c32bec 100644 --- a/mozilla/extensions/xforms/nsXFormsStubElement.h +++ b/mozilla/extensions/xforms/nsXFormsStubElement.h @@ -41,6 +41,7 @@ #include "nsIXTFGenericElement.h" #include "nsIXTFXMLVisual.h" +#include "nsIXTFBindableElement.h" /** * An implementation of a generic non-UI XForms element. @@ -86,6 +87,28 @@ public: NS_DECL_NSIXTFXMLVISUAL }; +/** + * An implementation of an XForms bindable control. + * + * This is a base class for UI controls that use nsIXTFBindableElement. + * 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 nsXFormsBindableStub : public nsIXTFBindableElement +{ +protected: + // We need a virtual destructor so that when a subclass does + // NS_IMPL_ISUPPORTS_INHERITED, our Release() implementation calls the + // derived class destructor. + virtual ~nsXFormsBindableStub() {} + +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIXTFELEMENT + NS_DECL_NSIXTFBINDABLEELEMENT +}; + /* Factory methods */ NS_HIDDEN_(nsresult) NS_NewXFormsStubElement(nsIXTFElement **aResult); @@ -93,4 +116,6 @@ NS_NewXFormsStubElement(nsIXTFElement **aResult); NS_HIDDEN_(nsresult) NS_NewXFormsXMLVisualStub(nsIXTFElement **aResult); +NS_HIDDEN_(nsresult) +NS_NewXFormsBindableStub(nsIXTFElement **aResult); #endif diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 9e558a686df..facc0d58cb5 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -7644,7 +7644,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsFrameConstructorState& aState, // display:none, so they don't mess with pseudo-state! aState.mFrameManager->SetUndisplayedContent(aContent, styleContext); return NS_OK; - } else + } else if (xtfElem->GetElementType() != nsIXTFElement::ELEMENT_TYPE_BINDABLE) rv = ConstructXTFFrame(aState, aContent, adjParentFrame, aTag, aNameSpaceID, styleContext, *frameItems, pseudoParent);