Index: extensions/xforms/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/Makefile.in,v
retrieving revision 1.1.2.4
diff -u -8 -r1.1.2.4 Makefile.in
--- extensions/xforms/Makefile.in	5 Oct 2004 22:56:51 -0000	1.1.2.4
+++ extensions/xforms/Makefile.in	6 Oct 2004 20:24:51 -0000
@@ -52,26 +52,51 @@
 REQUIRES	= \
 		xpcom \
 		string \
 		content \
 		dom \
 		widget \
 		necko \
 		websrvcs \
+		webshell \
+		js \
+		xpconnect \
+		pref \
+		layout \
+		gfx \
+		caps \
 		docshell \
 		$(NULL)
 
+XPIDLSRCS 	= \
+		nsIXFormsActionModuleElement.idl \
+		nsIXFormsActionElement.idl \
+		$(NULL)
+
 CPPSRCS		= \
 		nsXFormsElementFactory.cpp \
 		nsXFormsElement.cpp \
 		nsXFormsControl.cpp \
 		nsXFormsModelElement.cpp \
 		nsXFormsInputElement.cpp \
 		nsXFormsSubmissionElement.cpp \
 		nsXFormsStubElement.cpp \
 		nsXFormsAtoms.cpp \
 		nsXFormsModule.cpp \
+		nsXFormsActionModuleBase.cpp \
+		nsXFormsDispatchElement.cpp \
+		nsXFormsSendElement.cpp \
+		nsXFormsSetFocusElement.cpp \
+		nsXFormsResetElement.cpp \
+		nsXFormsRebuildElement.cpp \
+		nsXFormsRecalculateElement.cpp \
+		nsXFormsRevalidateElement.cpp \
+		nsXFormsRefreshElement.cpp \
+		nsXFormsActionElement.cpp \
+		nsXFormsLoadElement.cpp \
+		nsXFormsMessageElement.cpp \
+		nsXFormsSetValueElement.cpp \
 		$(NULL)
 
 EXTRA_DSO_LDOPTS = $(MOZ_COMPONENT_LIBS)
 
 include $(topsrcdir)/config/rules.mk
Index: extensions/xforms/nsXFormsAtoms.h
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsAtoms.h,v
retrieving revision 1.1.2.7
diff -u -8 -r1.1.2.7 nsXFormsAtoms.h
--- extensions/xforms/nsXFormsAtoms.h	5 Oct 2004 22:56:51 -0000	1.1.2.7
+++ extensions/xforms/nsXFormsAtoms.h	6 Oct 2004 20:24:51 -0000
@@ -55,14 +55,23 @@
   static NS_HIDDEN_(nsIAtom *) p3ptype;
   static NS_HIDDEN_(nsIAtom *) model;
   static NS_HIDDEN_(nsIAtom *) modelListProperty;
   static NS_HIDDEN_(nsIAtom *) ref;
   static NS_HIDDEN_(nsIAtom *) action;
   static NS_HIDDEN_(nsIAtom *) method;
   static NS_HIDDEN_(nsIAtom *) replace;
   static NS_HIDDEN_(nsIAtom *) separator;
+  static NS_HIDDEN_(nsIAtom *) name;
+  static NS_HIDDEN_(nsIAtom *) target;
+  static NS_HIDDEN_(nsIAtom *) bubbles;
+  static NS_HIDDEN_(nsIAtom *) cancelable;
+  static NS_HIDDEN_(nsIAtom *) submission;
+  static NS_HIDDEN_(nsIAtom *) control;
+  static NS_HIDDEN_(nsIAtom *) resource;
+  static NS_HIDDEN_(nsIAtom *) show;
+  static NS_HIDDEN_(nsIAtom *) level;
 
   static NS_HIDDEN_(void) InitAtoms();
 
  private:
   static NS_HIDDEN_(const nsStaticAtom) Atoms_info[];
 };
Index: extensions/xforms/nsXFormsStubElement.h
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsStubElement.h,v
retrieving revision 1.1.2.1
diff -u -8 -r1.1.2.1 nsXFormsStubElement.h
--- extensions/xforms/nsXFormsStubElement.h	1 Oct 2004 01:21:25 -0000	1.1.2.1
+++ extensions/xforms/nsXFormsStubElement.h	6 Oct 2004 20:24:52 -0000
@@ -33,19 +33,30 @@
  * 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 "nsXFormsElement.h"
+#include "nsIContent.h"
+#include "nsIDOMXPathResult.h"
+#include "nsXFormsModelElement.h"
 
 class nsXFormsStubElement : public nsXFormsElement,
                             public nsIXTFGenericElement
 {
+public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIXTFELEMENT
   NS_DECL_NSIXTFGENERICELEMENT
+//helpers
+  static PRBool GetSingleNodeBindingValue(nsIContent* aContent, nsAString& aValue);
+  static nsXFormsModelElement* GetModelAndBind(nsIContent* aContent, nsIDOMElement **aBindElement);
+  static already_AddRefed<nsIDOMXPathResult> EvaluateBinding(nsIContent* aContent,
+                                                      PRUint16 aResultType,
+                                                      nsXFormsModelElement **aModel,
+                                                      nsIDOMElement **aBind);
 };
 
 NS_HIDDEN_(nsresult)
 NS_NewXFormsStubElement(nsIXTFElement **aResult);
Index: extensions/xforms/nsXFormsAtoms.cpp
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsAtoms.cpp,v
retrieving revision 1.1.2.6
diff -u -8 -r1.1.2.6 nsXFormsAtoms.cpp
--- extensions/xforms/nsXFormsAtoms.cpp	5 Oct 2004 22:56:51 -0000	1.1.2.6
+++ extensions/xforms/nsXFormsAtoms.cpp	6 Oct 2004 20:24:52 -0000
@@ -53,16 +53,25 @@
 nsIAtom* nsXFormsAtoms::p3ptype;
 nsIAtom* nsXFormsAtoms::model;
 nsIAtom* nsXFormsAtoms::modelListProperty;
 nsIAtom *nsXFormsAtoms::ref;
 nsIAtom *nsXFormsAtoms::action;
 nsIAtom *nsXFormsAtoms::method;
 nsIAtom *nsXFormsAtoms::replace;
 nsIAtom *nsXFormsAtoms::separator;
+nsIAtom* nsXFormsAtoms::name;
+nsIAtom* nsXFormsAtoms::target;
+nsIAtom* nsXFormsAtoms::bubbles;
+nsIAtom* nsXFormsAtoms::cancelable;
+nsIAtom* nsXFormsAtoms::submission;
+nsIAtom* nsXFormsAtoms::control;
+nsIAtom* nsXFormsAtoms::resource;
+nsIAtom* nsXFormsAtoms::show;
+nsIAtom* nsXFormsAtoms::level;
 
 const nsStaticAtom nsXFormsAtoms::Atoms_info[] = {
   { "schema",            &nsXFormsAtoms::schema },
   { "instance",          &nsXFormsAtoms::instance },
   { "src",               &nsXFormsAtoms::src },
   { "bind",              &nsXFormsAtoms::bind },
   { "nodeset",           &nsXFormsAtoms::nodeset },
   { "type",              &nsXFormsAtoms::type },
@@ -73,16 +82,25 @@
   { "constraint",        &nsXFormsAtoms::constraint },
   { "p3ptype",           &nsXFormsAtoms::p3ptype },
   { "model",             &nsXFormsAtoms::model },
   { "ModelListProperty", &nsXFormsAtoms::modelListProperty },
   { "ref",               &nsXFormsAtoms::ref },
   { "action",            &nsXFormsAtoms::action },
   { "method",            &nsXFormsAtoms::method },
   { "replace",           &nsXFormsAtoms::replace },
-  { "separator",         &nsXFormsAtoms::separator }
+  { "separator",         &nsXFormsAtoms::separator },
+  { "name",              &nsXFormsAtoms::name },
+  { "target",            &nsXFormsAtoms::target },
+  { "bubbles",           &nsXFormsAtoms::bubbles },
+  { "cancelable",        &nsXFormsAtoms::cancelable },
+  { "submission",        &nsXFormsAtoms::submission },
+  { "control",           &nsXFormsAtoms::control },
+  { "resource",          &nsXFormsAtoms::resource },
+  { "show",              &nsXFormsAtoms::show },
+  { "level",             &nsXFormsAtoms::level }
 };
 
 void
 nsXFormsAtoms::InitAtoms()
 {
   NS_RegisterStaticAtoms(Atoms_info, NS_ARRAY_LENGTH(Atoms_info));
 }
Index: extensions/xforms/nsXFormsControl.cpp
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsControl.cpp,v
retrieving revision 1.1.2.8
diff -u -8 -r1.1.2.8 nsXFormsControl.cpp
--- extensions/xforms/nsXFormsControl.cpp	4 Oct 2004 22:24:40 -0000	1.1.2.8
+++ extensions/xforms/nsXFormsControl.cpp	6 Oct 2004 20:24:52 -0000
@@ -44,140 +44,38 @@
 #include "nsIDOMElement.h"
 #include "nsIDocument.h"
 #include "nsINameSpaceManager.h"
 #include "nsINodeInfo.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXPathEvaluator.h"
 #include "nsIDOMXPathResult.h"
 #include "nsIDOMXPathNSResolver.h"
+#include "nsXFormsStubElement.h"
 
 NS_IMPL_ISUPPORTS1(nsXFormsControl, nsXFormsControl)
 
 nsXFormsModelElement*
 nsXFormsControl::GetModelAndBind(nsIDOMElement **aBindElement)
 {
   *aBindElement = nsnull;
   NS_ENSURE_TRUE(mWrapper, nsnull);
 
   nsCOMPtr<nsIDOMElement> node;
   mWrapper->GetElementNode(getter_AddRefs(node));
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(node));
-  NS_ASSERTION(content, "wrapper must implement nsIContent");
-
-  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(content->GetDocument());
-  if (!domDoc)
-    return nsnull;
-
-  nsAutoString bindId;
-  content->GetAttr(kNameSpaceID_None, nsXFormsAtoms::bind, bindId);
-
-  nsCOMPtr<nsIDOMNode> modelWrapper;
-
-  if (!bindId.IsEmpty()) {
-    // Get the bind element with the given id.
-    domDoc->GetElementById(bindId, aBindElement);
-
-    nsCOMPtr<nsIContent> bindContent = do_QueryInterface(*aBindElement);
-    nsIContent *modelContent = bindContent;
-
-    if (modelContent) {
-      while ((modelContent = modelContent->GetParent())) {
-        nsINodeInfo *nodeInfo = modelContent->GetNodeInfo();
-        if (nodeInfo &&
-            nodeInfo->NamespaceEquals(NS_LITERAL_STRING("http://www.w3.org/2002/xforms")) &&
-            nodeInfo->NameAtom() == nsXFormsAtoms::model)
-          break;
-      }
-    }
-
-    modelWrapper = do_QueryInterface(modelContent);
-  } else {
-    // If no bind was given, we use model.
-    nsAutoString modelId;
-    content->GetAttr(kNameSpaceID_None, nsXFormsAtoms::model, modelId);
-
-    if (modelId.IsEmpty()) {
-      // No model given, so use the first one in the document.
-      nsCOMPtr<nsIDOMNodeList> nodes;
-      domDoc->GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/2002/xforms"),
-                                     NS_LITERAL_STRING("model"),
-                                     getter_AddRefs(nodes));
-
-      if (!nodes)
-        return nsnull;
-
-      nodes->Item(0, getter_AddRefs(modelWrapper));
-    } else {
-      nsCOMPtr<nsIDOMElement> wrapperElement;
-      domDoc->GetElementById(modelId, getter_AddRefs(wrapperElement));
-      modelWrapper = wrapperElement;
-    }
-  }
-
-  nsCOMPtr<nsIXTFPrivate> modelPrivate = do_QueryInterface(modelWrapper);
-  nsCOMPtr<nsISupports> modelElement;
-  if (modelPrivate)
-    modelPrivate->GetInner(getter_AddRefs(modelElement));
-
-  nsISupports *modelRaw = NS_STATIC_CAST(nsISupports*, modelElement.get());
-  return NS_STATIC_CAST(nsXFormsModelElement*,
-                        NS_STATIC_CAST(nsIXFormsModelElement*, modelRaw));
+  return nsXFormsStubElement::GetModelAndBind(content, aBindElement);
 }
 
 already_AddRefed<nsIDOMXPathResult>
 nsXFormsControl::EvaluateBinding(PRUint16               aResultType,
                                  nsXFormsModelElement **aModel,
                                  nsIDOMElement        **aBind)
 {
-  // A control may be attached to a model by either using the 'bind'
-  // attribute to give the id of a bind element, or using the 'model'
-  // attribute to give the id of a model.  If neither of these are given,
-  // the control belongs to the first model in the document.
-
-  *aBind = nsnull;
-
-  NS_IF_ADDREF(*aModel = GetModelAndBind(aBind));
-  if (!*aModel)
-    return nsnull;
-
-  nsCOMPtr<nsIDOMElement> resolverNode;
-  nsAutoString expr;
-
-  if (*aBind) {
-    resolverNode = *aBind;
-    resolverNode->GetAttribute(NS_LITERAL_STRING("nodeset"), expr);
-  } else {
-    mWrapper->GetElementNode(getter_AddRefs(resolverNode));
-    resolverNode->GetAttribute(NS_LITERAL_STRING("ref"), expr);
-  }
-
-  if (expr.IsEmpty())
-    return nsnull;
-
-  // Get the instance data and evaluate the xpath expression.
-  // XXXfixme when xpath extensions are implemented (instance())
-  nsCOMPtr<nsIDOMDocument> instanceDoc;
-  (*aModel)->GetInstanceDocument(NS_LITERAL_STRING(""),
-                                 getter_AddRefs(instanceDoc));
-
-  if (!instanceDoc)
-    return nsnull;
-
-  nsCOMPtr<nsIDOMXPathEvaluator> eval = do_QueryInterface(instanceDoc);
-  nsCOMPtr<nsIDOMXPathNSResolver> resolver;
-  eval->CreateNSResolver(resolverNode, getter_AddRefs(resolver));
-  NS_ENSURE_TRUE(resolver, nsnull);
-
-  nsCOMPtr<nsIDOMElement> docElement;
-  instanceDoc->GetDocumentElement(getter_AddRefs(docElement));
-
-  nsCOMPtr<nsISupports> result;
-  eval->Evaluate(expr, docElement, resolver, aResultType, nsnull,
-                 getter_AddRefs(result));
-
-  nsIDOMXPathResult *xpResult = nsnull;
-  if (result)
-    CallQueryInterface(result, &xpResult); // addrefs
+  NS_ENSURE_TRUE(mWrapper, nsnull);
+
+  nsCOMPtr<nsIDOMElement> node;
+  mWrapper->GetElementNode(getter_AddRefs(node));
 
-  return xpResult;
+  nsCOMPtr<nsIContent> content(do_QueryInterface(node));
+  return nsXFormsStubElement::EvaluateBinding(content, aResultType, aModel, aBind);
 }
Index: extensions/xforms/nsXFormsElementFactory.cpp
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsElementFactory.cpp,v
retrieving revision 1.1.2.5
diff -u -8 -r1.1.2.5 nsXFormsElementFactory.cpp
--- extensions/xforms/nsXFormsElementFactory.cpp	5 Oct 2004 22:56:51 -0000	1.1.2.5
+++ extensions/xforms/nsXFormsElementFactory.cpp	6 Oct 2004 20:24:53 -0000
@@ -37,28 +37,67 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsXFormsElementFactory.h"
 #include "nsXFormsModelElement.h"
 #include "nsXFormsSubmissionElement.h"
 #include "nsXFormsStubElement.h"
 #include "nsString.h"
 
+//Form Control Module Elements
 NS_HIDDEN_(nsresult) NS_NewXFormsInputElement(nsIXTFElement **aElement);
 
+//Action Module Elements
+NS_HIDDEN_(nsresult) NS_NewXFormsDispatchElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsSendElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsSetFocusElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsResetElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsRebuildElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsRecalculateElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsRevalidateElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsRefreshElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsActionElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsLoadElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsMessageElement(nsIXTFElement **aResult);
+NS_HIDDEN_(nsresult) NS_NewXFormsSetValueElement(nsIXTFElement **aResult);
+
 NS_IMPL_ISUPPORTS1(nsXFormsElementFactory, nsIXTFElementFactory)
 
 NS_IMETHODIMP
 nsXFormsElementFactory::CreateElement(const nsAString& aTagName,
                                       nsIXTFElement **aElement)
 {
   if (aTagName.EqualsLiteral("model"))
     return NS_NewXFormsModelElement(aElement);
   if (aTagName.EqualsLiteral("bind"))
     return NS_NewXFormsStubElement(aElement);
   if (aTagName.EqualsLiteral("input"))
     return NS_NewXFormsInputElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("dispatch")))
+    return NS_NewXFormsDispatchElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("send")))
+    return NS_NewXFormsSendElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("setfocus")))
+    return NS_NewXFormsSetFocusElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("reset")))
+    return NS_NewXFormsResetElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("rebuild")))
+    return NS_NewXFormsRebuildElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("recalculate")))
+    return NS_NewXFormsRecalculateElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("revalidate")))
+    return NS_NewXFormsRevalidateElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("refresh")))
+    return NS_NewXFormsRefreshElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("action")))
+    return NS_NewXFormsActionElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("load")))
+    return NS_NewXFormsLoadElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("message")))
+    return NS_NewXFormsMessageElement(aElement);
+  if (aTagName.Equals(NS_LITERAL_STRING("setvalue")))
+    return NS_NewXFormsSetValueElement(aElement);
   if (aTagName.EqualsLiteral("submission"))
     return NS_NewXFormsSubmissionElement(aElement);
 
   *aElement = nsnull;
   return NS_ERROR_FAILURE;
 }
Index: extensions/xforms/nsXFormsInputElement.cpp
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsInputElement.cpp,v
retrieving revision 1.1.2.10
diff -u -8 -r1.1.2.10 nsXFormsInputElement.cpp
--- extensions/xforms/nsXFormsInputElement.cpp	5 Oct 2004 22:10:19 -0000	1.1.2.10
+++ extensions/xforms/nsXFormsInputElement.cpp	6 Oct 2004 20:24:53 -0000
@@ -51,16 +51,17 @@
 #include "nsIDOMHTMLInputElement.h"
 #include "nsXFormsAtoms.h"
 #include "nsAutoPtr.h"
 #include "nsIDOMXPathResult.h"
 #include "nsIDOMFocusListener.h"
 #include "nsIDOM3EventTarget.h"
 #include "nsIDOMEventReceiver.h"
 #include "nsIDOMEventGroup.h"
+#include "nsIXTFElementWrapper.h"
 
 static const nsIID sScriptingIIDs[] = {
   NS_IDOMELEMENT_IID,
   NS_IDOMEVENTTARGET_IID,
   NS_IDOM3NODE_IID
 };
 
 class nsXFormsInputElement : public nsXFormsControl,
Index: extensions/xforms/nsXFormsStubElement.cpp
===================================================================
RCS file: /cvsroot/mozilla/extensions/xforms/Attic/nsXFormsStubElement.cpp,v
retrieving revision 1.1.2.1
diff -u -8 -r1.1.2.1 nsXFormsStubElement.cpp
--- extensions/xforms/nsXFormsStubElement.cpp	1 Oct 2004 01:21:25 -0000	1.1.2.1
+++ extensions/xforms/nsXFormsStubElement.cpp	6 Oct 2004 20:24:57 -0000
@@ -36,16 +36,26 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsXFormsStubElement.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOM3Node.h"
 #include "nsMemory.h"
+#include "nsIDOMXPathEvaluator.h"
+#include "nsIDOMXPathResult.h"
+#include "nsIDOMXPathNSResolver.h"
+#include "nsXFormsControl.h"
+#include "nsAutoPtr.h"
+#include "nsIDocument.h"
+#include "nsXFormsAtoms.h"
+#include "nsINameSpaceManager.h"
+#include "nsINodeInfo.h"
+#include "nsIDOMNodeList.h"
 
 static const nsIID sScriptingIIDs[] = {
   NS_IDOMELEMENT_IID,
   NS_IDOMEVENTTARGET_IID,
   NS_IDOM3NODE_IID
 };
 
 NS_IMPL_ISUPPORTS2(nsXFormsStubElement, nsIXTFElement, nsIXTFGenericElement)
@@ -177,16 +187,161 @@
 }
 
 NS_IMETHODIMP
 nsXFormsStubElement::OnCreated(nsIXTFGenericElementWrapper *aWrapper)
 {
   return NS_OK;
 }
 
+PRBool
+nsXFormsStubElement::GetSingleNodeBindingValue(nsIContent* aContent, nsAString& aValue) {
+  if (!aContent)
+    return PR_FALSE;
+  nsRefPtr<nsXFormsModelElement> model;
+  nsCOMPtr<nsIDOMElement> bindElement;
+  nsCOMPtr<nsIDOMXPathResult> result =
+    EvaluateBinding(aContent, nsIDOMXPathResult::STRING_TYPE,
+                    getter_AddRefs(model), getter_AddRefs(bindElement));
+  if (!result)
+    return PR_FALSE;
+  result->GetStringValue(aValue);
+  if (aValue.IsEmpty())
+    return PR_FALSE;
+  return PR_TRUE;
+}
+
+nsXFormsModelElement*
+nsXFormsStubElement::GetModelAndBind(nsIContent* aContent, 
+                                     nsIDOMElement **aBindElement)
+{
+  *aBindElement = nsnull;
+  NS_ENSURE_TRUE(aContent, nsnull);
+
+  nsCOMPtr<nsIDOMElement> node(do_QueryInterface(aContent));
+
+  nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aContent->GetDocument()));
+  if (!domDoc)
+    return nsnull;
+
+  nsAutoString bindId;
+  aContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::bind, bindId);
+
+  nsCOMPtr<nsIDOMNode> modelWrapper;
+
+  if (!bindId.IsEmpty()) {
+    // Get the bind element with the given id.
+    domDoc->GetElementById(bindId, aBindElement);
+
+    nsCOMPtr<nsIContent> bindContent = do_QueryInterface(*aBindElement);
+    nsIContent *modelContent = bindContent;
+
+    if (modelContent) {
+      while ((modelContent = modelContent->GetParent())) {
+        nsINodeInfo *nodeInfo = modelContent->GetNodeInfo();
+        if (nodeInfo &&
+            nodeInfo->NamespaceEquals(NS_LITERAL_STRING("http://www.w3.org/2002/xforms")) &&
+            nodeInfo->NameAtom() == nsXFormsAtoms::model)
+          break;
+      }
+    }
+
+    modelWrapper = do_QueryInterface(modelContent);
+  } else {
+    // If no bind was given, we use model.
+    nsAutoString modelId;
+    aContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::model, modelId);
+
+    if (modelId.IsEmpty()) {
+      // No model given, so use the first one in the document.
+      nsCOMPtr<nsIDOMNodeList> nodes;
+      domDoc->GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/2002/xforms"),
+                                     NS_LITERAL_STRING("model"),
+                                     getter_AddRefs(nodes));
+
+      if (!nodes)
+        return nsnull;
+
+      nodes->Item(0, getter_AddRefs(modelWrapper));
+    } else {
+      nsCOMPtr<nsIDOMElement> wrapperElement;
+      domDoc->GetElementById(modelId, getter_AddRefs(wrapperElement));
+      modelWrapper = wrapperElement;
+    }
+  }
+
+  nsCOMPtr<nsIXTFPrivate> modelPrivate = do_QueryInterface(modelWrapper);
+  nsCOMPtr<nsISupports> modelElement;
+  if (modelPrivate)
+    modelPrivate->GetInner(getter_AddRefs(modelElement));
+
+  nsISupports *modelRaw = NS_STATIC_CAST(nsISupports*, modelElement.get());
+  return NS_STATIC_CAST(nsXFormsModelElement*,
+                        NS_STATIC_CAST(nsIXFormsModelElement*, modelRaw));
+}
+
+already_AddRefed<nsIDOMXPathResult>
+nsXFormsStubElement::EvaluateBinding(nsIContent* aContent,
+                                     PRUint16 aResultType,
+                                     nsXFormsModelElement **aModel,
+                                     nsIDOMElement **aBind)
+{
+  // A control may be attached to a model by either using the 'bind'
+  // attribute to give the id of a bind element, or using the 'model'
+  // attribute to give the id of a model.  If neither of these are given,
+  // the control belongs to the first model in the document.
+
+  *aBind = nsnull;
+
+  NS_IF_ADDREF(*aModel = GetModelAndBind(aContent, aBind));
+  if (!*aModel)
+    return nsnull;
+
+  nsCOMPtr<nsIDOMElement> resolverNode;
+  nsAutoString expr;
+
+  if (*aBind) {
+    resolverNode = *aBind;
+    resolverNode->GetAttribute(NS_LITERAL_STRING("nodeset"), expr);
+  } else {
+    resolverNode = do_QueryInterface(aContent);
+    resolverNode->GetAttribute(NS_LITERAL_STRING("ref"), expr);
+  }
+
+  if (expr.IsEmpty())
+    return nsnull;
+
+  // Get the instance data and evaluate the xpath expression.
+  // XXXfixme when xpath extensions are implemented (instance())
+  nsCOMPtr<nsIDOMDocument> instanceDoc;
+  (*aModel)->GetInstanceDocument(NS_LITERAL_STRING(""),
+                                 getter_AddRefs(instanceDoc));
+
+  if (!instanceDoc)
+    return nsnull;
+
+  nsCOMPtr<nsIDOMXPathEvaluator> eval = do_QueryInterface(instanceDoc);
+  nsCOMPtr<nsIDOMXPathNSResolver> resolver;
+  eval->CreateNSResolver(resolverNode, getter_AddRefs(resolver));
+  NS_ENSURE_TRUE(resolver, nsnull);
+
+  nsCOMPtr<nsIDOMElement> docElement;
+  instanceDoc->GetDocumentElement(getter_AddRefs(docElement));
+
+  nsCOMPtr<nsISupports> result;
+  eval->Evaluate(expr, docElement, resolver, aResultType, nsnull,
+                 getter_AddRefs(result));
+
+  nsIDOMXPathResult *xpResult = nsnull;
+  if (result)
+    CallQueryInterface(result, &xpResult); // addrefs
+
+  return xpResult;
+}
+
 nsresult
 NS_NewXFormsStubElement(nsIXTFElement **aResult)
 {
   *aResult = new nsXFormsStubElement();
   if (!*aResult)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aResult);
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsIXFormsActionElement.idl	2004-09-22 20:01:20.000000000 +0300
@@ -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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsISupports.idl"
+
+interface nsIDOMElement;
+interface nsIDOMElement;
+
+[uuid(829a9aef-c832-48d7-b0a4-6f13cad2a14c)]
+interface nsIXFormsActionElement : nsISupports
+{
+  void setRebuild(in nsIDOMElement aModel, in boolean aEnable);
+  void setRecalculate(in nsIDOMElement aModel, in boolean aEnable);
+  void setRevalidate(in nsIDOMElement aModel, in boolean aEnable);
+  void setRefresh(in nsIDOMElement aModel, in boolean aEnable);
+};
+
+
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsActionElement.h	2004-10-06 18:25:32.000000000 +0300
@@ -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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#ifndef nsXFormsActionElement_h_
+#define nsXFormsActionElement_h_
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsDataHashtable.h"
+
+class nsXFormsActionElement : public nsXFormsActionModuleBase,
+                              public nsIXFormsActionElement
+{
+public:
+  nsXFormsActionElement();
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_NSIXFORMSACTIONELEMENT
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+private:
+  nsCOMPtr<nsIXFormsActionElement> mParentAction;
+  nsDataHashtable<nsISupportsHashKey,PRUint32> mDeferredUpdates;
+};
+
+#endif
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsActionElement.cpp	2004-10-05 21:44:40.000000000 +0300
@@ -0,0 +1,199 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionElement.h"
+#include "nsIXFormsModelElement.h"
+#include "nsIDOMNodeList.h"
+
+
+#define DEFERRED_REBUILD     0x01
+#define DEFERRED_RECALCULATE 0x02
+#define DEFERRED_REVALIDATE  0x04
+#define DEFERRED_REFRESH     0x08
+
+nsXFormsActionElement::nsXFormsActionElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsActionElement\n");
+#endif
+}
+
+NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsActionElement, nsXFormsActionModuleBase, nsIXTFElement, nsIXTFGenericElement, nsIXFormsActionElement)
+
+PR_STATIC_CALLBACK(PLDHashOperator) DoDeferredActions(nsISupports * aModel, 
+                                                      PRUint32 aDeferred,
+                                                      void * data)
+{
+  if (aModel && aDeferred) {
+    nsCOMPtr<nsIDOMElement> element = NS_STATIC_CAST(nsIDOMElement *, aModel);
+    nsCOMPtr<nsIDOMDocument> doc;
+    element->GetOwnerDocument(getter_AddRefs(doc));
+    if (doc) {
+      nsCOMPtr<nsIDOMEventTarget> targetEl(do_QueryInterface(element));
+      nsCOMPtr<nsIDOMDocumentEvent> docEvent(do_QueryInterface(doc));
+      if (targetEl) {
+        PRBool cancelled;
+        if (aDeferred & DEFERRED_REBUILD) {
+          nsCOMPtr<nsIDOMEvent> event;
+          docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+          event->InitEvent(NS_LITERAL_STRING("xforms-rebuild"), PR_TRUE, PR_TRUE);
+          targetEl->DispatchEvent(event, &cancelled);
+        }
+        if (aDeferred & DEFERRED_RECALCULATE) {
+          nsCOMPtr<nsIDOMEvent> event;
+          docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+          event->InitEvent(NS_LITERAL_STRING("xforms-recalculate"), PR_TRUE, PR_TRUE);
+          targetEl->DispatchEvent(event, &cancelled);
+        }
+        if (aDeferred & DEFERRED_REVALIDATE) {
+          nsCOMPtr<nsIDOMEvent> event;
+          docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+          event->InitEvent(NS_LITERAL_STRING("xforms-revalidate"), PR_TRUE, PR_TRUE);
+          targetEl->DispatchEvent(event, &cancelled);
+        }
+        if (aDeferred & DEFERRED_REFRESH) {
+          nsCOMPtr<nsIDOMEvent> event;
+          docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+          event->InitEvent(NS_LITERAL_STRING("xforms-refresh"), PR_TRUE, PR_TRUE);
+          targetEl->DispatchEvent(event, &cancelled);
+        }
+      }
+    }
+  }
+  return PL_DHASH_NEXT;
+}
+
+NS_IMETHODIMP nsXFormsActionElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                  nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsActionElement::HandleAction\n");
+#endif
+  if (!mContent)
+    return NS_OK;
+
+  if (!mDeferredUpdates.IsInitialized()) {
+    if (!mDeferredUpdates.Init())
+      return NS_ERROR_OUT_OF_MEMORY;
+  }
+  else {
+    mDeferredUpdates.Clear();
+  }
+
+  mParentAction = aParentAction;
+  PRUint32 count = mContent->GetChildCount();
+  nsCOMPtr<nsIXFormsActionModuleElement> actionChild;
+  nsCOMPtr<nsIDOMEvent> event(aEvent);
+  for (PRUint32 i = 0; i < count; ++i) {
+    nsCOMPtr<nsIContent> child = mContent->GetChildAt(i);
+    actionChild = do_QueryInterface(child);
+    if (actionChild)
+      actionChild->HandleAction(event, this);
+  }
+  if (!aParentAction) //Otherwise parent will handle deferred updates
+    mDeferredUpdates.EnumerateRead(DoDeferredActions, mContent);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsXFormsActionElement::SetRebuild(nsIDOMElement* aModel, PRBool aEnable)
+{
+  if (mParentAction)
+    return mParentAction->SetRebuild(aModel, aEnable);
+  PRUint32 deferred = 0;
+  mDeferredUpdates.Get(aModel, &deferred);
+  if (aEnable)
+    deferred |= DEFERRED_REBUILD;
+  else
+    deferred &= ~DEFERRED_REBUILD;
+  mDeferredUpdates.Put(aModel, deferred);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsXFormsActionElement::SetRecalculate(nsIDOMElement* aModel, PRBool aEnable)
+{
+  if (mParentAction)
+    return mParentAction->SetRecalculate(aModel, aEnable);
+  PRUint32 deferred = 0;
+  mDeferredUpdates.Get(aModel, &deferred);
+  if (aEnable)
+    deferred |= DEFERRED_RECALCULATE;
+  else
+    deferred &= ~DEFERRED_RECALCULATE;
+  mDeferredUpdates.Put(aModel, deferred);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsXFormsActionElement::SetRevalidate(nsIDOMElement* aModel, PRBool aEnable)
+{
+  if (mParentAction)
+    return mParentAction->SetRevalidate(aModel, aEnable);
+  PRUint32 deferred = 0;
+  mDeferredUpdates.Get(aModel, &deferred);
+  if (aEnable)
+    deferred |= DEFERRED_REVALIDATE;
+  else
+    deferred &= ~DEFERRED_REVALIDATE;
+  mDeferredUpdates.Put(aModel, deferred);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsXFormsActionElement::SetRefresh(nsIDOMElement* aModel, PRBool aEnable)
+{
+  if (mParentAction)
+    return mParentAction->SetRefresh(aModel, aEnable);
+  PRUint32 deferred = 0;
+  mDeferredUpdates.Get(aModel, &deferred);
+  if (aEnable)
+    deferred |= DEFERRED_REFRESH;
+  else
+    deferred &= ~DEFERRED_REFRESH;
+  mDeferredUpdates.Put(aModel, deferred);
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsActionElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsActionElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsIXFormsActionModuleElement.idl	2004-09-17 00:58:44.000000000 +0300
@@ -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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsISupports.idl"
+
+interface nsIDOMEvent;
+interface nsIXFormsActionElement;
+
+[uuid(b19c47e4-2478-4a73-91a3-d86f91d91ffd)]
+interface nsIXFormsActionModuleElement : nsISupports
+{
+  void handleAction(in nsIDOMEvent aEvent, in nsIXFormsActionElement aParentAction);
+};
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsActionModuleBase.h	2004-10-06 22:48:01.950582624 +0300
@@ -0,0 +1,105 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#ifndef nsXFormsActionModuleBase_h_
+#define nsXFormsActionModuleBase_h_
+
+#include "nsCOMPtr.h"
+#include "nsIXTFGenericElement.h"
+#include "nsIXTFGenericElementWrapper.h"
+#include "nsIDOMEventListener.h"
+#include "nsXFormsElement.h"
+#include "nsString.h"
+#include "nsIDOMElement.h"
+#include "nsIDOMDocument.h"
+#include "nsIDOMDocumentEvent.h"
+#include "nsIDOMEventTarget.h"
+#include "nsIDOMEvent.h"
+#include "nsXFormsAtoms.h"
+#include "nsINameSpaceManager.h"
+#include "nsIDocument.h"
+#include "nsIXFormsActionElement.h"
+#include "nsIXFormsActionModuleElement.h"
+#include "nsIXFormsModelElement.h"
+#include "nsXFormsStubElement.h"
+#include "nsXFormsModelElement.h"
+#include "nsIDOMXPathResult.h"
+
+class nsXFormsActionModuleBase : public nsIDOMEventListener,
+                                 public nsXFormsStubElement,
+                                 public nsIXFormsActionModuleElement
+{
+public:
+  nsXFormsActionModuleBase();
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_NSIXTFGENERICELEMENT
+  NS_DECL_NSIDOMEVENTLISTENER
+  
+  NS_IMETHOD OnDestroyed();
+  
+  NS_IMETHOD GetElementType(PRUint32 *aElementType) { return nsXFormsStubElement::GetElementType(aElementType); }
+  NS_IMETHOD GetIsAttributeHandler(PRBool *aIsAttributeHandler) { return nsXFormsStubElement::GetIsAttributeHandler(aIsAttributeHandler); }
+  NS_IMETHOD GetScriptingInterfaces(PRUint32 *count, nsIID * **array) { return nsXFormsStubElement::GetScriptingInterfaces(count, array); }
+  NS_IMETHOD GetNotificationMask(PRUint32 *aNotificationMask) { return nsXFormsStubElement::GetNotificationMask(aNotificationMask); }
+  NS_IMETHOD WillChangeDocument(nsISupports *newDoc) { return nsXFormsStubElement::WillChangeDocument(newDoc); }
+  NS_IMETHOD DocumentChanged(nsISupports *newDoc) { return nsXFormsStubElement::DocumentChanged(newDoc); }
+  NS_IMETHOD WillChangeParent(nsISupports *newParent) { return nsXFormsStubElement::WillChangeParent(newParent); }
+  NS_IMETHOD ParentChanged(nsISupports *newParent) { return nsXFormsStubElement::ParentChanged(newParent); }
+  NS_IMETHOD WillInsertChild(nsISupports *child, PRUint32 index) { return nsXFormsStubElement::WillInsertChild(child, index); }
+  NS_IMETHOD ChildInserted(nsISupports *child, PRUint32 index) { return nsXFormsStubElement::ChildInserted(child, index); }
+  NS_IMETHOD WillAppendChild(nsISupports *child) { return nsXFormsStubElement::WillAppendChild(child); }
+  NS_IMETHOD ChildAppended(nsISupports *child) { return nsXFormsStubElement::ChildAppended(child); }
+  NS_IMETHOD WillRemoveChild(PRUint32 index) { return nsXFormsStubElement::WillRemoveChild(index); }
+  NS_IMETHOD ChildRemoved(PRUint32 index) { return nsXFormsStubElement::ChildRemoved(index); }
+  NS_IMETHOD WillSetAttribute(nsIAtom *name, const nsAString & newValue) { return nsXFormsStubElement::WillSetAttribute(name, newValue); }
+  NS_IMETHOD AttributeSet(nsIAtom *name, const nsAString & newValue) { return nsXFormsStubElement::AttributeSet(name, newValue); }
+  NS_IMETHOD WillUnsetAttribute(nsIAtom *name) { return nsXFormsStubElement::WillUnsetAttribute(name); }
+  NS_IMETHOD AttributeUnset(nsIAtom *name) { return nsXFormsStubElement::AttributeUnset(name); }
+  NS_IMETHOD DoneAddingChildren() { return nsXFormsStubElement::DoneAddingChildren(); }
+protected:
+  //Helper methods
+  nsresult DispatchEventForModel(const nsAString& aEvent, 
+                                PRBool aBubbles, 
+                                PRBool aCancelable);
+  nsresult GetModelElement(nsIDOMElement** aModelElement);
+
+  nsIContent *mContent;
+};
+
+#endif
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsActionModuleBase.cpp	2004-10-06 22:49:51.222970696 +0300
@@ -0,0 +1,140 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+#include "nsIDOM3Node.h"
+#include "nsMemory.h"
+#include "nsIDOMNodeList.h"
+#include "nsXFormsModelElement.h"
+#include "nsIContent.h"
+#include "nsString.h"
+#include "nsIDOMElement.h"
+#include "nsIDocument.h"
+#include "nsINameSpaceManager.h"
+#include "nsINodeInfo.h"
+#include "nsIDOMNodeList.h"
+
+
+nsXFormsActionModuleBase::nsXFormsActionModuleBase() : mContent(nsnull)
+{
+}
+
+NS_IMPL_ISUPPORTS4(nsXFormsActionModuleBase, nsIXFormsActionModuleElement, nsIDOMEventListener, nsIXTFElement, nsIXTFGenericElement)
+
+NS_IMETHODIMP nsXFormsActionModuleBase::OnCreated(nsIXTFGenericElementWrapper *aWrapper)
+{
+  nsCOMPtr<nsIDOMElement> node;
+  aWrapper->GetElementNode(getter_AddRefs(node));
+  nsCOMPtr<nsIContent> content = do_QueryInterface(node);
+  mContent = content;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsXFormsActionModuleBase::OnDestroyed()
+{
+  mContent = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsXFormsActionModuleBase::HandleEvent(nsIDOMEvent* aEvent)
+{
+#ifdef DEBUG
+  printf("nsXFormsActionModuleBase::HandleEvent\n");
+#endif
+  return HandleAction(aEvent, nsnull);
+}
+
+nsresult nsXFormsActionModuleBase::DispatchEventForModel(const nsAString& aEvent,
+                                                         PRBool aBubbles,
+                                                         PRBool aCancelable)
+{
+  nsCOMPtr<nsIDOMElement> model;
+  GetModelElement(getter_AddRefs(model));
+  if (!model)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mContent->GetDocument());
+  if (!doc)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(doc);
+  nsCOMPtr<nsIDOMEvent> event;
+  docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+  event->InitEvent(aEvent, aBubbles, aCancelable);
+  nsCOMPtr<nsIDOMEventTarget> targetEl = do_QueryInterface(model);
+  if (targetEl) {
+    PRBool cancelled;
+    targetEl->DispatchEvent(event, &cancelled);
+  }
+  return NS_OK;
+}
+
+nsresult nsXFormsActionModuleBase::GetModelElement(nsIDOMElement** aModelElement)
+{
+  *aModelElement = nsnull;
+  if (!mContent)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mContent->GetDocument());
+  if (!doc)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMElement> el;
+  nsAutoString model;
+  nsresult rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::model, model);
+  if (rv != NS_CONTENT_ATTR_HAS_VALUE) {
+      nsCOMPtr<nsIDOMNodeList> nodes;
+      doc->GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.w3.org/2002/xforms"),
+                                  NS_LITERAL_STRING("model"),
+                                  getter_AddRefs(nodes));
+      if (!nodes)
+        return NS_OK;
+      nsCOMPtr<nsIDOMNode> node;
+      nodes->Item(0, getter_AddRefs(node));
+      el = do_QueryInterface(node);
+  }
+  else {
+    doc->GetElementById(model, getter_AddRefs(el));
+  }
+  
+  if (!el)
+    return NS_OK;
+  return CallQueryInterface(el, aModelElement);
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsDispatchElement.cpp	2004-10-06 18:21:24.000000000 +0300
@@ -0,0 +1,275 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsDataHashtable.h"
+
+struct EventData
+{
+  const char *name;
+  PRBool      canCancel;
+  PRBool      canBubble;
+};
+
+#define CANCELABLE 0x01
+#define BUBBLES    0x02
+
+static const EventData sXFormsEventsEntries[] = {
+  { "xforms-model-construct",      PR_FALSE, PR_TRUE  },
+  { "xforms-model-construct-done", PR_FALSE, PR_TRUE  },
+  { "xforms-ready",                PR_FALSE, PR_TRUE  },
+  { "xforms-model-destruct",       PR_FALSE, PR_TRUE  },
+  { "xforms-previous",             PR_TRUE,  PR_FALSE },
+  { "xforms-next",                 PR_TRUE,  PR_FALSE },
+  { "xforms-focus",                PR_TRUE,  PR_FALSE },
+  { "xforms-help",                 PR_TRUE,  PR_TRUE  },
+  { "xforms-hint",                 PR_TRUE,  PR_TRUE  },
+  { "xforms-rebuild",              PR_TRUE,  PR_TRUE  },
+  { "xforms-refresh",              PR_TRUE,  PR_TRUE  },
+  { "xforms-revalidate",           PR_TRUE,  PR_TRUE  },
+  { "xforms-recalculate",          PR_TRUE,  PR_TRUE  },
+  { "xforms-reset",                PR_TRUE,  PR_TRUE  },
+  { "xforms-submit",               PR_TRUE,  PR_TRUE  },
+  { "DOMActivate",                 PR_TRUE,  PR_TRUE  },
+  { "xforms-value-changed",        PR_FALSE, PR_TRUE  },
+  { "xforms-select",               PR_FALSE, PR_TRUE  },
+  { "xforms-deselect",             PR_FALSE, PR_TRUE  },
+  { "xforms-scroll-first",         PR_FALSE, PR_TRUE  },
+  { "xforms-scroll-last",          PR_FALSE, PR_TRUE  },
+  { "xforms-insert",               PR_FALSE, PR_TRUE  },
+  { "xforms-delete",               PR_FALSE, PR_TRUE  },
+  { "xforms-valid",                PR_FALSE, PR_TRUE  },
+  { "xforms-invalid",              PR_FALSE, PR_TRUE  },
+  { "DOMFocusIn",                  PR_FALSE, PR_TRUE  },
+  { "DOMFocusOut",                 PR_FALSE, PR_TRUE  },
+  { "xforms-readonly",             PR_FALSE, PR_TRUE  },
+  { "xforms-readwrite",            PR_FALSE, PR_TRUE  },
+  { "xforms-required",             PR_FALSE, PR_TRUE  },
+  { "xforms-optional",             PR_FALSE, PR_TRUE  },
+  { "xforms-enabled",              PR_FALSE, PR_TRUE  },
+  { "xforms-disabled",             PR_FALSE, PR_TRUE  },
+  { "xforms-in-range",             PR_FALSE, PR_TRUE  },
+  { "xforms-out-of-range",         PR_FALSE, PR_TRUE  },
+  { "xforms-submit-done",          PR_FALSE, PR_TRUE  },
+  { "xforms-submit-error",         PR_FALSE, PR_TRUE  },
+  { "xforms-binding-exception",    PR_FALSE, PR_TRUE  },
+  { "xforms-link-exception",       PR_FALSE, PR_TRUE  },
+  { "xforms-link-error",           PR_FALSE, PR_TRUE  },
+  { "xforms-compute-exception",    PR_FALSE, PR_TRUE  }
+};
+
+static nsDataHashtable<nsStringHashKey,PRUint32> sXFormsEvents;
+
+static const EventData sEventDefaultsEntries[] = {
+  //UIEvents already in sXFormsEvents
+  
+  //MouseEvent
+  { "click",                       PR_TRUE,  PR_TRUE  },
+  { "mousedown",                   PR_TRUE,  PR_TRUE  },
+  { "mouseup",                     PR_TRUE,  PR_TRUE  },
+  { "mouseover",                   PR_TRUE,  PR_TRUE  },
+  { "mousemove",                   PR_FALSE, PR_TRUE  },
+  { "mouseout",                    PR_TRUE,  PR_TRUE  },
+  //MutationEvent
+  { "DOMSubtreeModified",          PR_FALSE, PR_TRUE  },
+  { "DOMNodeInserted",             PR_FALSE, PR_TRUE  },
+  { "DOMNodeRemoved",              PR_FALSE, PR_TRUE  },
+  { "DOMNodeRemovedFromDocument",  PR_FALSE, PR_FALSE },
+  { "DOMNodeInsertedIntoDocument", PR_FALSE, PR_FALSE },
+  { "DOMAttrModified",             PR_FALSE, PR_TRUE  },
+  { "DOMCharacterDataModified",    PR_FALSE, PR_TRUE  },
+  //HTMLEvents
+  { "load",                        PR_FALSE, PR_FALSE },
+  { "unload",                      PR_FALSE, PR_FALSE },
+  { "abort",                       PR_FALSE, PR_TRUE  },
+  { "error",                       PR_FALSE, PR_TRUE  },
+  { "select",                      PR_FALSE, PR_TRUE  },
+  { "change",                      PR_FALSE, PR_TRUE  },
+  { "submit",                      PR_TRUE,  PR_TRUE  },
+  { "reset",                       PR_FALSE, PR_TRUE  },
+  { "focus",                       PR_FALSE, PR_FALSE },
+  { "blur",                        PR_FALSE, PR_FALSE },
+  { "resize",                      PR_FALSE, PR_TRUE  },
+  { "scroll",                      PR_FALSE, PR_TRUE  }
+};
+
+static nsDataHashtable<nsStringHashKey,PRUint32> sEventDefaults;
+
+static PRBool IsXFormsEvent(const nsAString& aEvent, PRBool& aCancelable, PRBool& aBubbles)
+{
+  if (!sXFormsEvents.IsInitialized()) {
+    if (!sXFormsEvents.Init())
+      return PR_FALSE;
+    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(sXFormsEventsEntries); ++i) {
+      PRUint32 flag = 0;
+      if (sXFormsEventsEntries[i].canCancel)
+        flag |= CANCELABLE;
+      if (sXFormsEventsEntries[i].canBubble)
+        flag |= BUBBLES;
+      nsAutoString event;
+      event.Assign(NS_ConvertUTF8toUTF16(sXFormsEventsEntries[i].name));
+      sXFormsEvents.Put(event, flag);
+    }
+  }
+
+  PRUint32 flag = 0;
+  if (!sXFormsEvents.Get(aEvent, &flag))
+    return PR_FALSE;
+  aCancelable = (flag & CANCELABLE);
+  aBubbles = (flag & BUBBLES);
+  return PR_TRUE;
+}
+
+static void GetEventDefaults(const nsAString& aEvent, PRBool& aCancelable, PRBool& aBubbles)
+{
+  if (!sEventDefaults.IsInitialized()) {
+    if (!sEventDefaults.Init())
+      return;
+    for (unsigned int i = 0; i < NS_ARRAY_LENGTH(sEventDefaultsEntries); ++i) {
+      PRUint32 flag = 0;
+      if (sEventDefaultsEntries[i].canCancel)
+        flag |= CANCELABLE;
+      if (sEventDefaultsEntries[i].canBubble)
+        flag |= BUBBLES;
+      nsAutoString event;
+      event.Assign(NS_ConvertUTF8toUTF16(sEventDefaultsEntries[i].name));
+      sEventDefaults.Put(event, flag);
+    }
+  }
+
+  PRUint32 flag = 0;
+  if (!sEventDefaults.Get(aEvent, &flag))
+    return;
+  aCancelable = (flag & CANCELABLE);
+  aBubbles = (flag & BUBBLES);
+}
+
+class nsXFormsDispatchElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsDispatchElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsDispatchElement::nsXFormsDispatchElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsDispatchElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsDispatchElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                    nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsDispatchElement::HandleAction\n");
+#endif
+  if (!aEvent) 
+    return NS_ERROR_INVALID_ARG;
+  if (!mContent)
+    return NS_OK;
+  
+  nsAutoString name;
+  nsresult rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::name, name);
+  if (rv != NS_CONTENT_ATTR_HAS_VALUE)
+    return NS_OK;
+
+  nsAutoString target;
+  rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::target, target);
+  if (rv != NS_CONTENT_ATTR_HAS_VALUE)
+    return NS_OK;
+
+  PRBool cancelable = PR_TRUE;
+  PRBool bubbles = PR_TRUE;
+  if (!IsXFormsEvent(name, cancelable, bubbles)) {
+    PRBool hasCancelableAttr = PR_TRUE;
+    nsAutoString cancelableStr;
+    if (mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::cancelable, cancelableStr) ==
+      NS_CONTENT_ATTR_NOT_THERE)
+      hasCancelableAttr = PR_FALSE;
+    else
+      cancelable = cancelableStr.Equals(NS_LITERAL_STRING("true"));
+
+    PRBool hasBubblesAttr = PR_TRUE;
+    nsAutoString bubbleStr;
+    if (mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::bubbles, bubbleStr) ==
+      NS_CONTENT_ATTR_NOT_THERE)
+      hasBubblesAttr = PR_FALSE;
+    else
+      bubbles = bubbleStr.Equals(NS_LITERAL_STRING("true"));
+
+    PRBool tmp;
+    if (!hasCancelableAttr && !hasBubblesAttr)
+      GetEventDefaults(name, cancelable, bubbles);
+    else if (!hasCancelableAttr)
+      GetEventDefaults(name, cancelable, tmp);
+    else if (!hasBubblesAttr)
+      GetEventDefaults(name, tmp, bubbles);
+  }
+  
+  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mContent->GetDocument());
+  if (!doc)
+    return NS_OK;
+  nsCOMPtr<nsIDOMElement> el;
+  doc->GetElementById(target, getter_AddRefs(el));
+  if (!el)
+    return NS_OK;
+  
+  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(doc);
+  nsCOMPtr<nsIDOMEvent> event;
+  docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+  event->InitEvent(name, bubbles, cancelable);
+  nsCOMPtr<nsIDOMEventTarget> targetEl = do_QueryInterface(el);
+  if (targetEl) {
+    PRBool cancelled;
+    targetEl->DispatchEvent(event, &cancelled);
+  }
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsDispatchElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsDispatchElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsResetElement.cpp	2004-10-06 18:23:20.000000000 +0300
@@ -0,0 +1,86 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+
+class nsXFormsResetElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsResetElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsResetElement::nsXFormsResetElement() {
+#ifdef DEBUG
+  printf("Ctor nsXFormsResetElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsResetElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                 nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsResetElement::HandleAction\n");
+#endif
+  if (aParentAction) {
+    nsCOMPtr<nsIDOMElement> model;
+    GetModelElement(getter_AddRefs(model));
+    if (model) {
+      aParentAction->SetRebuild(model, PR_FALSE);
+      aParentAction->SetRecalculate(model, PR_FALSE);
+      aParentAction->SetRevalidate(model, PR_FALSE);
+      aParentAction->SetRefresh(model, PR_FALSE);
+    }
+  }
+  return nsXFormsActionModuleBase::DispatchEventForModel(NS_LITERAL_STRING("xforms-reset"), 
+                                                         PR_TRUE, 
+                                                         PR_TRUE);
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsResetElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsResetElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsSendElement.cpp	2004-10-06 18:23:44.000000000 +0300
@@ -0,0 +1,100 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+
+class nsXFormsSendElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsSendElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsSendElement::nsXFormsSendElement() {
+#ifdef DEBUG
+  printf("Ctor nsXFormsSendElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsSendElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsSendElement::HandleAction\n");
+#endif
+  if (!mContent)
+    return NS_OK;
+
+  nsAutoString submission;
+  nsresult rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::submission, submission);
+  if (rv != NS_CONTENT_ATTR_HAS_VALUE)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mContent->GetDocument());
+  if (!doc)
+    return NS_OK;
+  nsCOMPtr<nsIDOMElement> el;
+  doc->GetElementById(submission, getter_AddRefs(el));
+  if (!el)
+    return NS_OK;
+  
+  //XXX Check the element type when we have the submission element
+  
+  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(doc);
+  nsCOMPtr<nsIDOMEvent> event;
+  docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+  event->InitEvent(NS_LITERAL_STRING("xforms-submit"), PR_TRUE, PR_TRUE);
+  nsCOMPtr<nsIDOMEventTarget> targetEl = do_QueryInterface(el);
+  if (targetEl) {
+    PRBool cancelled;
+    targetEl->DispatchEvent(event, &cancelled);
+  }
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsSendElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsSendElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsSetFocusElement.cpp	2004-10-06 18:24:02.000000000 +0300
@@ -0,0 +1,100 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+
+class nsXFormsSetFocusElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsSetFocusElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsSetFocusElement::nsXFormsSetFocusElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsSetFocusElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsSetFocusElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                    nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsSetFocusElement::HandleAction\n");
+#endif
+  if (!mContent)
+    return NS_OK;
+
+  nsAutoString control;
+  nsresult rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::control, control);
+  if (rv != NS_CONTENT_ATTR_HAS_VALUE)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mContent->GetDocument());
+  if (!doc)
+    return NS_OK;
+  nsCOMPtr<nsIDOMElement> el;
+  doc->GetElementById(control, getter_AddRefs(el));
+  if (!el)
+    return NS_OK;
+  //Should we check the type of the element?
+  
+  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(doc);
+  nsCOMPtr<nsIDOMEvent> event;
+  docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+  event->InitEvent(NS_LITERAL_STRING("xforms-focus"), PR_FALSE, PR_TRUE);
+  nsCOMPtr<nsIDOMEventTarget> targetEl = do_QueryInterface(el);
+  if (targetEl) {
+    PRBool cancelled;
+    targetEl->DispatchEvent(event, &cancelled);
+  }
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsSetFocusElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsSetFocusElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsRebuildElement.cpp	2004-10-06 18:22:37.000000000 +0300
@@ -0,0 +1,83 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+
+class nsXFormsRebuildElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsRebuildElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsRebuildElement::nsXFormsRebuildElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsRebuildElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsRebuildElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                   nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsRebuildElement::HandleAction\n");
+#endif
+  if (aParentAction) {
+    nsCOMPtr<nsIDOMElement> model;
+    GetModelElement(getter_AddRefs(model));
+    if (model)
+      aParentAction->SetRebuild(model, PR_FALSE);
+  }
+  return nsXFormsActionModuleBase::DispatchEventForModel(NS_LITERAL_STRING("xforms-rebuild"), 
+                                                         PR_TRUE, 
+                                                         PR_TRUE);
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsRebuildElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsRebuildElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsRecalculateElement.cpp	2004-10-06 18:22:54.000000000 +0300
@@ -0,0 +1,83 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+
+class nsXFormsRecalculateElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsRecalculateElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsRecalculateElement::nsXFormsRecalculateElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsRecalculateElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsRecalculateElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                       nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsRecalculateElement::HandleAction\n");
+#endif
+  if (aParentAction) {
+    nsCOMPtr<nsIDOMElement> model;
+    GetModelElement(getter_AddRefs(model));
+    if (model)
+      aParentAction->SetRecalculate(model, PR_FALSE);
+  }
+  return nsXFormsActionModuleBase::DispatchEventForModel(NS_LITERAL_STRING("xforms-recalculate"), 
+                                                         PR_TRUE, 
+                                                         PR_TRUE);
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsRecalculateElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsRecalculateElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsRevalidateElement.cpp	2004-10-06 18:23:50.000000000 +0300
@@ -0,0 +1,83 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+
+class nsXFormsRevalidateElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsRevalidateElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsRevalidateElement::nsXFormsRevalidateElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsRevalidateElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsRevalidateElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                      nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsRevalidateElement::HandleAction\n");
+#endif
+  if (aParentAction) {
+    nsCOMPtr<nsIDOMElement> model;
+    GetModelElement(getter_AddRefs(model));
+    if (model)
+      aParentAction->SetRevalidate(model, PR_FALSE);
+  }
+  return nsXFormsActionModuleBase::DispatchEventForModel(NS_LITERAL_STRING("xforms-revalidate"), 
+                                                         PR_TRUE, 
+                                                         PR_TRUE);
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsRevalidateElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsRevalidateElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsRefreshElement.cpp	2004-10-06 18:23:07.000000000 +0300
@@ -0,0 +1,83 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+
+class nsXFormsRefreshElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsRefreshElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsRefreshElement::nsXFormsRefreshElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsRefreshElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsRefreshElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                   nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsRefreshElement::HandleAction\n");
+#endif
+  if (aParentAction) {
+    nsCOMPtr<nsIDOMElement> model;
+    GetModelElement(getter_AddRefs(model));
+    if (model)
+      aParentAction->SetRefresh(model, PR_FALSE);
+  }
+  return nsXFormsActionModuleBase::DispatchEventForModel(NS_LITERAL_STRING("xforms-refresh"), 
+                                                         PR_TRUE, 
+                                                         PR_TRUE);
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsRefreshElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsRefreshElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsLoadElement.cpp	2004-10-06 23:01:05.290496856 +0300
@@ -0,0 +1,140 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+#include "nsILinkHandler.h"
+#include "nsContentUtils.h"
+#include "nsIPresContext.h"
+#include "nsIPresShell.h"
+#include "nsIScriptSecurityManager.h"
+#include "nsNetUtil.h"
+#include "nsXFormsControl.h"
+
+class nsXFormsLoadElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsLoadElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsLoadElement::nsXFormsLoadElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsLoadElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsLoadElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                 nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsLoadElement::HandleAction\n");
+#endif
+  if(!mContent)
+    return NS_OK;
+  //If the element has 'resource' and single node binding, the
+  //action has no effect.
+  if (mContent->HasAttr(kNameSpaceID_None, nsXFormsAtoms::resource) &&
+      (mContent->HasAttr(kNameSpaceID_None, nsXFormsAtoms::bind) ||
+       mContent->HasAttr(kNameSpaceID_None, nsXFormsAtoms::model) ||
+       mContent->HasAttr(kNameSpaceID_None, nsXFormsAtoms::ref)))
+    return NS_OK;
+
+  nsAutoString resource;
+  nsresult rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::resource, resource);
+  if (rv == NS_CONTENT_ATTR_NOT_THERE && !GetSingleNodeBindingValue(mContent, resource))
+    return NS_OK;
+
+  nsLinkVerb verb = eLinkVerb_Undefined;
+  nsAutoString show;
+  rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::show, show);
+  if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
+    if (show.Equals(NS_LITERAL_STRING("new"))) {
+      verb = eLinkVerb_New;
+      //XXX Check "browser.block.target_new_window" ?
+    }
+    else if (show.Equals(NS_LITERAL_STRING("replace")))
+      verb = eLinkVerb_Replace;
+  }
+  nsIDocument * doc = mContent->GetDocument();
+  if (!doc)
+    return NS_OK;
+  
+  nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
+  nsCOMPtr<nsIURI> uri;
+  nsCAutoString originCharset;
+  originCharset = doc->GetDocumentCharacterSet();
+  rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8(resource), originCharset.get(), baseURI);
+
+  if (NS_SUCCEEDED(rv)) {
+    nsIPresShell *shell = doc->GetShellAt(0);
+    if (!shell)
+      return NS_OK;
+    nsCOMPtr<nsIPresContext> presContext;
+    shell->GetPresContext(getter_AddRefs(presContext));
+    nsILinkHandler *handler = presContext->GetLinkHandler();
+    if (!handler)
+      return NS_OK;
+    nsresult proceed = NS_OK;
+    // Check that this page is allowed to load this URI.
+    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
+             do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+    if (NS_SUCCEEDED(rv))
+      proceed =
+        securityManager->CheckLoadURI(baseURI, uri,
+                                      nsIScriptSecurityManager::STANDARD);
+    if (NS_SUCCEEDED(proceed)) {
+      //Let's use OnLinkClick here, even if the event was something else.
+      handler->OnLinkClick(mContent, verb, uri, EmptyString().get());
+    }
+  }
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsLoadElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsLoadElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsMessageElement.cpp	2004-10-06 23:24:06.585508096 +0300
@@ -0,0 +1,200 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionElement.h"
+#include "nsIDOMDocumentView.h"
+#include "nsIDOMAbstractView.h"
+#include "nsIDOMWindowInternal.h"
+#include "nsIPrompt.h"
+#include "nsIDOM3Node.h"
+#include "nsIDOMHTMLDocument.h"
+#include "nsIDOMXULDocument.h"
+#include "nsIDOMEventTarget.h"
+
+class nsXFormsMessageElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsMessageElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+protected:
+  nsCOMPtr<nsIDOMElement> mMessage;
+};
+
+nsXFormsMessageElement::nsXFormsMessageElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsMessageElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsMessageElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                   nsIXFormsActionElement *aParentAction)
+{
+  //XForms specifies <message> in a very abstract way.
+#ifdef DEBUG
+  printf("nsXFormsMessageElement::HandleAction\n");
+#endif
+  //XXX Add support for single node binding attributes and for xforms-link-error.
+  //XXX How to handle for example the following:
+  //XXX <message level="ephemeral" src="http://mozilla.org"/>
+  //XXX Todo: src for ephemeral and modal, error checks
+
+  if (!mContent)
+    return NS_OK;
+  nsCOMPtr<nsIDOMDocumentView> dview(do_QueryInterface(mContent->GetDocument()));
+  if (!dview)
+    return NS_OK;
+  nsCOMPtr<nsIDOMAbstractView> aview;
+  dview->GetDefaultView(getter_AddRefs(aview));
+  if (!aview)
+    return NS_OK;
+  nsCOMPtr<nsIDOMWindowInternal> internal(do_QueryInterface(aview));
+  if (!internal)
+    return NS_OK;
+  nsAutoString level;
+  nsresult rv = mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::level, level);
+  if (rv != NS_CONTENT_ATTR_HAS_VALUE)
+    return NS_OK;
+  nsAutoString instanceData;
+  PRBool hasSNB = GetSingleNodeBindingValue(mContent, instanceData);
+  if (level.Equals(NS_LITERAL_STRING("ephemeral")) || level.Equals(NS_LITERAL_STRING("modal"))) {
+    nsCOMPtr<nsIDOM3Node> n3(do_QueryInterface(mContent));
+    if (!n3)
+      return NS_OK;
+    nsAutoString value;
+    if (!hasSNB)
+      n3->GetTextContent(value);
+    else
+      value = instanceData;
+    if (level.Equals(NS_LITERAL_STRING("ephemeral"))) {
+      internal->SetStatus(value);
+    }
+    else {
+      nsCOMPtr<nsIPrompt> prompter;
+      internal->GetPrompter(getter_AddRefs(prompter));
+      prompter->Alert(NS_LITERAL_STRING("[XForms]").get(), value.get());
+    }
+  }
+  else {
+    nsAutoString src;
+    mContent->GetAttr(kNameSpaceID_None, nsXFormsAtoms::src, src);
+    if (!src.IsEmpty()) {
+      //Don't reuse windows for external messages, at least not for now
+      level.Assign(NS_LITERAL_STRING(""));
+    }
+    
+    //XXX Add options here. They don't work in XForms branch!
+    nsAutoString options/*(NS_LITERAL_STRING("location=false"))*/;
+    nsCOMPtr<nsIDOMWindow> messageWindow;
+    internal->Open(src, level, options, getter_AddRefs(messageWindow));
+    if (messageWindow && src.IsEmpty()) {
+      //XXX What would be the best way to implement this? And what features
+      //    should be supported?
+      nsCOMPtr<nsIDOMDocument> newDoc;
+      messageWindow->GetDocument(getter_AddRefs(newDoc));
+      nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(newDoc));
+      if (htmlDoc)
+        htmlDoc->SetTitle(NS_LITERAL_STRING("[XForms]"));
+      if (newDoc) {
+        nsCOMPtr<nsIDOMElement> html;
+        newDoc->GetDocumentElement(getter_AddRefs(html));
+        if (html) {
+          nsCOMPtr<nsIDOMNode> body;
+          html->GetLastChild(getter_AddRefs(body));
+          if (body) {
+            if (hasSNB) {
+              nsCOMPtr<nsIDOM3Node> b3(do_QueryInterface(body));
+              b3->SetTextContent(instanceData);
+            }
+            else {
+              //If the window was used before, it contains nodes which should
+              //be removed before adding new ones.
+              nsCOMPtr<nsIDOMNode> tmp;
+              nsCOMPtr<nsIDOMNode> last;
+              PRBool hasChildNodes = PR_FALSE;
+              do {
+                body->HasChildNodes(&hasChildNodes);
+                if (hasChildNodes) {
+                  body->GetLastChild(getter_AddRefs(last));
+                  if (last)
+                    body->RemoveChild(last, getter_AddRefs(tmp));
+                }
+              } while (hasChildNodes);
+              
+              //Now add the new children
+              //XXX Add support for <xf:output> when it is implemented.
+              PRUint32 count = mContent->GetChildCount();
+              for (PRUint32 i = 0; i < count; ++i) {
+                nsCOMPtr<nsIDOMNode> child(do_QueryInterface(mContent->GetChildAt(i)));
+                if (child) {
+                  nsCOMPtr<nsIDOMNode> clone;
+                  child->CloneNode(PR_TRUE, getter_AddRefs(clone));
+                  if (clone) {
+                    //XXX ImportNode does not work properly (not at least in XForms branch).
+                    //nsCOMPtr<nsIDOMNode> imported;
+                    //newDoc->ImportNode(clone, PR_TRUE, getter_AddRefs(imported));
+                    //if (imported) {
+                      //body->AppendChild(imported, getter_AddRefs(tmp));
+                      body->AppendChild(clone, getter_AddRefs(tmp));
+                    //}
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+      nsCOMPtr<nsIDOMWindowInternal> newInternal(do_QueryInterface(messageWindow));
+      if (newInternal)
+        newInternal->Focus();
+    }
+  }
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsMessageElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsMessageElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
--- /dev/null	2004-02-23 23:02:56.000000000 +0200
+++ extensions/xforms/nsXFormsSetValueElement.cpp	2004-10-06 18:24:13.000000000 +0300
@@ -0,0 +1,85 @@
+/* -*- 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
+ * Olli Pettay.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
+ *
+ * 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 ***** */
+
+#include "nsXFormsActionModuleBase.h"
+#include "nsXFormsActionElement.h"
+
+class nsXFormsSetValueElement : public nsXFormsActionModuleBase
+{
+public:
+  nsXFormsSetValueElement();
+  NS_DECL_NSIXFORMSACTIONMODULEELEMENT
+};
+
+nsXFormsSetValueElement::nsXFormsSetValueElement()
+{
+#ifdef DEBUG
+  printf("Ctor nsXFormsSetValueElement\n");
+#endif
+}
+
+NS_IMETHODIMP nsXFormsSetValueElement::HandleAction(nsIDOMEvent* aEvent, 
+                                                   nsIXFormsActionElement *aParentAction)
+{
+#ifdef DEBUG
+  printf("nsXFormsSetValueElement::HandleAction\n");
+#endif
+  //XXX Implement Single Node Binding
+  if (aParentAction) {
+    nsCOMPtr<nsIDOMElement> model;
+    GetModelElement(getter_AddRefs(model));
+    if (model) {
+      aParentAction->SetRecalculate(model, PR_TRUE);
+      aParentAction->SetRevalidate(model, PR_TRUE);
+      aParentAction->SetRefresh(model, PR_TRUE);
+    }
+  }
+  return NS_OK;
+}
+
+NS_HIDDEN_(nsresult)
+NS_NewXFormsSetValueElement(nsIXTFElement **aResult)
+{
+  *aResult = new nsXFormsSetValueElement();
+  if (!*aResult)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aResult);
+  return NS_OK;
+}
+
