diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index 052a1ca37c6..39dced1be60 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -1376,6 +1376,9 @@ for extension in $MOZ_EXTENSIONS; do extensions/webservices/wsdl/Makefile extensions/webservices/wsdl/src/Makefile " ;; + xforms ) MAKEFILES_extensions="$MAKEFILES_extensions + extensions/xforms/Makefile + " ;; xmlextras ) MAKEFILES_extensions="$MAKEFILES_extensions extensions/xmlextras/Makefile extensions/xmlextras/base/Makefile diff --git a/mozilla/extensions/xforms/Makefile.in b/mozilla/extensions/xforms/Makefile.in new file mode 100644 index 00000000000..1a065d58f29 --- /dev/null +++ b/mozilla/extensions/xforms/Makefile.in @@ -0,0 +1,71 @@ +# +# ***** 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 mozilla.org code. +# +# The Initial Developer of the Original Code is +# IBM Corporation. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Brian Ryner +# +# Alternatively, the contents of this file may be used under the terms of +# either of 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 ***** + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = xforms +LIBRARY_NAME = xforms +IS_COMPONENT = 1 +EXPORT_LIBRARY = 1 +MODULE_NAME = xforms + +REQUIRES = \ + xpcom \ + string \ + content \ + dom \ + widget \ + necko \ + websrvcs \ + $(NULL) + +CPPSRCS = \ + nsXFormsElementFactory.cpp \ + nsXFormsModelElement.cpp \ + nsXFormsAtoms.cpp \ + nsXFormsModule.cpp \ + $(NULL) + +EXTRA_DSO_LDOPTS = $(MOZ_COMPONENT_LIBS) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/extensions/xforms/nsXFormsAtoms.cpp b/mozilla/extensions/xforms/nsXFormsAtoms.cpp new file mode 100644 index 00000000000..a81f046f79e --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsAtoms.cpp @@ -0,0 +1,56 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsXFormsAtoms.h" +#include "nsMemory.h" + +nsIAtom* nsXFormsAtoms::schema; +nsIAtom* nsXFormsAtoms::instance; +nsIAtom* nsXFormsAtoms::src; + +const nsStaticAtom nsXFormsAtoms::Atoms_info[] = { + { "schema", &nsXFormsAtoms::schema }, + { "instance", &nsXFormsAtoms::instance }, + { "src", &nsXFormsAtoms::src } +}; + +void +nsXFormsAtoms::InitAtoms() +{ + NS_RegisterStaticAtoms(Atoms_info, NS_ARRAY_LENGTH(Atoms_info)); +} diff --git a/mozilla/extensions/xforms/nsXFormsAtoms.h b/mozilla/extensions/xforms/nsXFormsAtoms.h new file mode 100644 index 00000000000..99148646751 --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsAtoms.h @@ -0,0 +1,52 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsStaticAtom.h" + +class nsXFormsAtoms +{ + public: + static nsIAtom *schema; + static nsIAtom *instance; + static nsIAtom *src; + + static NS_HIDDEN_(void) InitAtoms(); + + private: + static const nsStaticAtom Atoms_info[]; +}; diff --git a/mozilla/extensions/xforms/nsXFormsElementFactory.cpp b/mozilla/extensions/xforms/nsXFormsElementFactory.cpp new file mode 100644 index 00000000000..ca7bf9581b1 --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsElementFactory.cpp @@ -0,0 +1,54 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsXFormsElementFactory.h" +#include "nsXFormsModelElement.h" +#include "nsString.h" + +NS_IMPL_ISUPPORTS1(nsXFormsElementFactory, nsIXTFElementFactory) + +NS_IMETHODIMP +nsXFormsElementFactory::CreateElement(const nsAString& aTagName, + nsIXTFElement **aElement) +{ + if (aTagName.Equals(NS_LITERAL_STRING("model"))) + return NS_NewXFormsModelElement(aElement); + + *aElement = nsnull; + return NS_ERROR_FAILURE; +} diff --git a/mozilla/extensions/xforms/nsXFormsElementFactory.h b/mozilla/extensions/xforms/nsXFormsElementFactory.h new file mode 100644 index 00000000000..b4229e56c76 --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsElementFactory.h @@ -0,0 +1,49 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsIXTFElementFactory.h" + +#define NS_XFORMSELEMENTFACTORY_CID \ +{0xc068f682, 0x03b5, 0x4e96, {0x81, 0xe1, 0x60, 0x13, 0xf9, 0x12, 0x88, 0xb2}} + +class nsXFormsElementFactory : public nsIXTFElementFactory +{ + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIXTFELEMENTFACTORY +}; diff --git a/mozilla/extensions/xforms/nsXFormsModelElement.cpp b/mozilla/extensions/xforms/nsXFormsModelElement.cpp new file mode 100644 index 00000000000..d06d47b50c7 --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsModelElement.cpp @@ -0,0 +1,492 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsXFormsModelElement.h" +#include "nsIXTFGenericElementWrapper.h" +#include "nsMemory.h" +#include "nsIDOMDocumentEvent.h" +#include "nsIDOMEvent.h" +#include "nsIDOMEventTarget.h" +#include "nsIDOMElement.h" +#include "nsIDOM3Node.h" +#include "nsString.h" +#include "nsIDocument.h" +#include "nsXFormsAtoms.h" +#include "nsINameSpaceManager.h" +#include "nsIServiceManager.h" +#include "nsINodeInfo.h" +#include "nsIDOMDOMImplementation.h" +#include "nsIDOMXMLDocument.h" +#include "nsIDOMEventReceiver.h" + +#include "nsISchemaLoader.h" + +static const nsIID sScriptingIIDs[] = { + NS_IDOMELEMENT_IID, + NS_IDOMEVENTTARGET_IID, + NS_IDOM3NODE_IID, + NS_IXFORMSMODELELEMENT_IID +}; + +// non-cancellable event +#define EVENT_HELPER_NC(name, event, bubble) \ +inline nsresult \ +Dispatch##name##Event(nsXFormsModelElement *elt) \ +{ \ + PRBool defaultPrevented; \ + return elt->DispatchEvent("xforms-" event, bubble, PR_FALSE, &defaultPrevented); \ +} + +// cancellable event +#define EVENT_HELPER(name, event, bubble) \ +inline nsresult \ +Dispatch##name##Event(nsXFormsModelElement *elt, PRBool *aDefaultPrevented) \ +{ return elt->DispatchEvent("xforms-" event, bubble, PR_TRUE, aDefaultPrevented); } + +// Initialization events +EVENT_HELPER_NC(ModelConstruct, "model-construct", PR_TRUE) +EVENT_HELPER_NC(ModelConstructDone, "model-construct-done", PR_TRUE) +EVENT_HELPER_NC(Ready, "ready", PR_TRUE) +EVENT_HELPER_NC(ModelDestruct, "model-destruct", PR_TRUE) + +// Error events +EVENT_HELPER_NC(BindingException, "binding-exception", PR_TRUE) +EVENT_HELPER_NC(LinkException, "link-exception", PR_TRUE) +EVENT_HELPER_NC(LinkError, "link-error", PR_TRUE) +EVENT_HELPER_NC(ComputeException, "compute-exception", PR_TRUE) + +NS_IMPL_ADDREF(nsXFormsModelElement) +NS_IMPL_RELEASE(nsXFormsModelElement) + +NS_INTERFACE_MAP_BEGIN(nsXFormsModelElement) + NS_INTERFACE_MAP_ENTRY(nsIXTFElement) + NS_INTERFACE_MAP_ENTRY(nsIXTFGenericElement) + NS_INTERFACE_MAP_ENTRY(nsIXFormsModelElement) + NS_INTERFACE_MAP_ENTRY(nsISchemaLoadListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMLoadListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXTFElement) +NS_INTERFACE_MAP_END + +NS_IMETHODIMP +nsXFormsModelElement::OnDestroyed() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::GetElementType(PRUint32 *aType) +{ + *aType = ELEMENT_TYPE_GENERIC_ELEMENT; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::GetScriptingInterfaces(PRUint32 *aCount, nsIID ***aArray) +{ + PRUint32 count = NS_ARRAY_LENGTH(sScriptingIIDs); + + nsIID **iids = NS_STATIC_CAST(nsIID**, + nsMemory::Alloc(count * sizeof(nsIID*))); + if (!iids) { + return NS_ERROR_OUT_OF_MEMORY; + } + + for (PRUint32 i = 0; i < count; ++i) { + iids[i] = NS_STATIC_CAST(nsIID*, + nsMemory::Clone(&sScriptingIIDs[i], sizeof(nsIID))); + + if (!iids[i]) { + for (PRUint32 j = 0; j < i; ++j) + nsMemory::Free(iids[j]); + nsMemory::Free(iids); + return NS_ERROR_OUT_OF_MEMORY; + } + } + + *aArray = iids; + *aCount = count; + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::WillChangeDocument(nsISupports* aNewDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::DocumentChanged(nsISupports* aNewDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::WillChangeParent(nsISupports* aNewParent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::ParentChanged(nsISupports* aNewParent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::WillInsertChild(nsISupports* aChild, PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::ChildInserted(nsISupports* aChild, PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::WillAppendChild(nsISupports* aChild) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::ChildAppended(nsISupports* aChild) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::WillRemoveChild(PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::ChildRemoved(PRUint32 aIndex) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::SetAttribute(const nsAString &aName, + const nsAString &aNewValue) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::UnsetAttribute(const nsAString& aName) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::GetAttribute(const nsAString& aName, nsAString& aValue) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::HasAttribute(const nsAString& aName, PRBool* aHasAttr) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::GetAttributeCount(PRUint32* aCount) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::GetAttributeNameAt(PRUint32 aIndex, nsAString& aName) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::DoneAddingChildren() +{ + // We wait until all children are added to dispatch xforms-model-construct, + // since the model may have an action handler for this event. + + nsresult rv = DispatchModelConstructEvent(this); + NS_ENSURE_SUCCESS(rv, rv); + + // xforms-model-construct is not cancellable, so always proceed. + // (XForms 4.2.1) + // 1. load xml schemas + + nsAutoString schemaList; + mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::schema, schemaList); + if (!schemaList.IsEmpty()) { + nsCOMPtr loader = do_GetService(NS_SCHEMALOADER_CONTRACTID); + NS_ENSURE_TRUE(loader, NS_ERROR_FAILURE); + + // Parse the space-separated list. + PRUint32 offset = 0; + while (1) { + PRInt32 index = schemaList.FindChar(PRUnichar(' '), offset); + nsresult rv = loader->LoadAsync(Substring(schemaList, offset, + index - offset), this); + if (NS_FAILED(rv)) { + DispatchLinkExceptionEvent(this); // this is a fatal error + return NS_OK; + } + if (index == -1) + break; + + offset = index + 1; + } + } + + // 2. construct an XPath data model from inline or external initial instance + // data. + + // XXX the spec says there can be any number of nodes, but + // I can't see how it makes sense to have more than one per model. + + PRUint32 childCount = mContent->GetChildCount(); + for (PRUint32 i = 0; i < childCount; ++i) { + nsIContent *child = mContent->GetChildAt(i); + nsINodeInfo *ni = child->GetNodeInfo(); + if (ni && ni->Equals(nsXFormsAtoms::instance, kNameSpaceID_XForms)) { + // Create a document which will hold the live instance data. + nsCOMPtr domDoc = do_QueryInterface(child->GetDocument()); + nsCOMPtr domImpl; + domDoc->GetImplementation(getter_AddRefs(domImpl)); + + nsAutoString src; + child->GetAttr(kNameSpaceID_None, nsXFormsAtoms::src, src); + + rv = domImpl->CreateDocument(EmptyString(), EmptyString(), nsnull, + getter_AddRefs(mInstanceDocument)); + NS_ENSURE_SUCCESS(rv, rv); + + if (src.IsEmpty()) { + // No src means we should use the inline instance data, using the + // first child element of the instance node as the root. + + PRUint32 instanceChildCount = child->GetChildCount(); + nsCOMPtr root; + + for (PRUint32 j = 0; j < instanceChildCount; ++j) { + nsIContent *node = child->GetChildAt(j); + if (node->IsContentOfType(nsIContent::eELEMENT)) { + root = do_QueryInterface(node); + break; + } + } + + if (root) { + nsCOMPtr newNode; + rv = mInstanceDocument->ImportNode(root, PR_TRUE, + getter_AddRefs(newNode)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr nodeReturn; + rv = mInstanceDocument->AppendChild(newNode, + getter_AddRefs(nodeReturn)); + NS_ENSURE_SUCCESS(rv, rv); + } + } else { + // We're using external instance data, so we need to load + // the data into a new document which becomes our live instance data. + + // Hook up load an error listeners so we'll know when the document + // is done loading. + + nsCOMPtr rec = + do_QueryInterface(mInstanceDocument); + rec->AddEventListenerByIID(this, NS_GET_IID(nsIDOMLoadListener)); + + nsCOMPtr xmlDoc = + do_QueryInterface(mInstanceDocument); + + PRBool success; + xmlDoc->Load(src, &success); + if (!success) { + DispatchLinkExceptionEvent(this); + return NS_OK; + } + } + } + } + + // 3. if applicable, initialize P3P + + // 4. construct instance data from initial instance data. apply all + // elements in document order. + + // 5. dispatch xforms-rebuild, xforms-recalculate, xforms-revalidate + + // mark this model as initialized + + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::OnCreated(nsIXTFGenericElementWrapper *aWrapper) +{ + nsCOMPtr node; + aWrapper->GetElementNode(getter_AddRefs(node)); + mContent = do_QueryInterface(node); + + NS_ASSERTION(mContent, "Wrapper is not an nsIContent, we'll crash soon"); + + aWrapper->SetShouldHandleAttributes(PR_TRUE); + + return NS_OK; +} + + +// nsIXFormsModelElement + +NS_IMETHODIMP +nsXFormsModelElement::GetInstanceDocument(const nsAString& aInstanceID, + nsIDOMDocument **aDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Rebuild() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Recalculate() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Revalidate() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Refresh() +{ + return NS_OK; +} + +// nsISchemaLoadListener + +NS_IMETHODIMP +nsXFormsModelElement::OnLoad(nsISchema* aSchema) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::OnError(PRInt32 aStatus, const nsAString &aStatusMessage) +{ + return NS_OK; +} + +// nsIDOMEventListener + +NS_IMETHODIMP +nsXFormsModelElement::HandleEvent(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Load(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::BeforeUnload(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Unload(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Abort(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsModelElement::Error(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +// internal methods + +nsresult +nsXFormsModelElement::DispatchEvent(const char *aEvent, + PRBool aCanBubble, PRBool aCanCancel, + PRBool *aDefaultPrevented) +{ + nsCOMPtr event; + nsCOMPtr doc = do_QueryInterface(mContent->GetDocument()); + doc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); + NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY); + + event->InitEvent(NS_ConvertUTF8toUTF16(aEvent), aCanBubble, aCanCancel); + + nsCOMPtr target = do_QueryInterface(mContent); + return target->DispatchEvent(event, aDefaultPrevented); +} + +nsresult +NS_NewXFormsModelElement(nsIXTFElement **aResult) +{ + *aResult = new nsXFormsModelElement(); + if (!*aResult) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aResult); + return NS_OK; +} diff --git a/mozilla/extensions/xforms/nsXFormsModelElement.h b/mozilla/extensions/xforms/nsXFormsModelElement.h new file mode 100644 index 00000000000..4c3d9c7ab4d --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsModelElement.h @@ -0,0 +1,80 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsIXTFGenericElement.h" +#include "nsIXFormsModelElement.h" +#include "nsIContent.h" +#include "nsISchema.h" +#include "nsCOMArray.h" +#include "nsCOMPtr.h" +#include "nsIDOMLoadListener.h" +#include "nsIDOMDocument.h" + +#include "nsISchemaLoader.h" + +class nsXFormsModelElement : public nsIXTFGenericElement, + public nsIXFormsModelElement, + public nsISchemaLoadListener, + public nsIDOMLoadListener +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIXTFELEMENT + NS_DECL_NSIXTFGENERICELEMENT + NS_DECL_NSIXFORMSMODELELEMENT + NS_DECL_NSISCHEMALOADLISTENER + NS_DECL_NSIDOMEVENTLISTENER + + // nsIDOMLoadListener + NS_IMETHOD Load(nsIDOMEvent* aEvent); + NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent); + NS_IMETHOD Unload(nsIDOMEvent* aEvent); + NS_IMETHOD Abort(nsIDOMEvent* aEvent); + NS_IMETHOD Error(nsIDOMEvent* aEvent); + + NS_HIDDEN_(nsresult) DispatchEvent(const char *aEvent, + PRBool aCanBubble, PRBool aCanCancel, + PRBool *aDefaultPrevented); +private: + + nsCOMPtr mContent; + nsCOMArray mSchemas; + nsCOMPtr mInstanceDocument; +}; + +NS_HIDDEN_(nsresult) NS_NewXFormsModelElement(nsIXTFElement **aResult); diff --git a/mozilla/extensions/xforms/nsXFormsModule.cpp b/mozilla/extensions/xforms/nsXFormsModule.cpp new file mode 100644 index 00000000000..acfaed701db --- /dev/null +++ b/mozilla/extensions/xforms/nsXFormsModule.cpp @@ -0,0 +1,59 @@ +/* -*- 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 Mozilla XForms support. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * 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 "nsIGenericFactory.h" +#include "nsXFormsElementFactory.h" +#include "nsXFormsAtoms.h" + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsElementFactory) + +static const nsModuleComponentInfo components[] = { + { "XForms element factory", + NS_XFORMSELEMENTFACTORY_CID, + NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX "http://www.w3.org/2002/xforms", + nsXFormsElementFactoryConstructor } +}; + +PR_STATIC_CALLBACK(nsresult) +XFormsModuleCtor(nsIModule* aSelf) +{ + nsXFormsAtoms::InitAtoms(); + return NS_OK; +} + +NS_IMPL_NSGETMODULE_WITH_CTOR(xforms, components, XFormsModuleCtor)