Action module implementation (bug 263008). Patch by smaug@welho.com, r=bryner
git-svn-id: svn://10.0.0.236/trunk@164968 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -70,6 +70,8 @@ XPIDLSRCS = \
|
||||
nsIInstanceElementPrivate.idl \
|
||||
nsIModelElementPrivate.idl \
|
||||
nsIXFormsControl.idl \
|
||||
nsIXFormsActionElement.idl \
|
||||
nsIXFormsActionModuleElement.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
@@ -91,6 +93,18 @@ CPPSRCS = \
|
||||
nsXFormsXPathParser.cpp \
|
||||
nsXFormsXPathScanner.cpp \
|
||||
nsXFormsXPathXMLUtil.cpp \
|
||||
nsXFormsActionElement.cpp \
|
||||
nsXFormsActionModuleBase.cpp \
|
||||
nsXFormsDispatchElement.cpp \
|
||||
nsXFormsRebuildElement.cpp \
|
||||
nsXFormsRecalculateElement.cpp \
|
||||
nsXFormsRefreshElement.cpp \
|
||||
nsXFormsRevalidateElement.cpp \
|
||||
nsXFormsResetElement.cpp \
|
||||
nsXFormsSendElement.cpp \
|
||||
nsXFormsSetFocusElement.cpp \
|
||||
nsXFormsSetValueElement.cpp \
|
||||
nsXFormsLoadElement.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
53
mozilla/extensions/xforms/nsIXFormsActionElement.idl
Normal file
53
mozilla/extensions/xforms/nsIXFormsActionElement.idl
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- 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 nsIDOMNode;
|
||||
|
||||
[uuid(829a9aef-c832-48d7-b0a4-6f13cad2a14c)]
|
||||
interface nsIXFormsActionElement : nsISupports
|
||||
{
|
||||
void setRebuild(in nsIDOMNode aModel, in boolean aEnable);
|
||||
void setRecalculate(in nsIDOMNode aModel, in boolean aEnable);
|
||||
void setRevalidate(in nsIDOMNode aModel, in boolean aEnable);
|
||||
void setRefresh(in nsIDOMNode aModel, in boolean aEnable);
|
||||
};
|
||||
|
||||
|
||||
|
||||
49
mozilla/extensions/xforms/nsIXFormsActionModuleElement.idl
Normal file
49
mozilla/extensions/xforms/nsIXFormsActionModuleElement.idl
Normal file
@@ -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);
|
||||
};
|
||||
|
||||
185
mozilla/extensions/xforms/nsXFormsActionElement.cpp
Normal file
185
mozilla/extensions/xforms/nsXFormsActionElement.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
/* -*- 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"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
#define DEFERRED_REBUILD 0x01
|
||||
#define DEFERRED_RECALCULATE 0x02
|
||||
#define DEFERRED_REVALIDATE 0x04
|
||||
#define DEFERRED_REFRESH 0x08
|
||||
|
||||
nsXFormsActionElement::nsXFormsActionElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsActionElement,
|
||||
nsXFormsActionModuleBase,
|
||||
nsIXTFElement,
|
||||
nsIXTFGenericElement,
|
||||
nsIXFormsActionElement)
|
||||
|
||||
PR_STATIC_CALLBACK(PLDHashOperator) DoDeferredActions(nsISupports * aModel,
|
||||
PRUint32 aDeferred,
|
||||
void * data)
|
||||
{
|
||||
if (aModel && aDeferred) {
|
||||
nsCOMPtr<nsIDOMNode> element = NS_STATIC_CAST(nsIDOMNode *, aModel);
|
||||
if (aDeferred & DEFERRED_REBUILD)
|
||||
nsXFormsUtils::DispatchEvent(element, eEvent_Rebuild);
|
||||
if (aDeferred & DEFERRED_RECALCULATE)
|
||||
nsXFormsUtils::DispatchEvent(element, eEvent_Recalculate);
|
||||
if (aDeferred & DEFERRED_REVALIDATE)
|
||||
nsXFormsUtils::DispatchEvent(element, eEvent_Revalidate);
|
||||
if (aDeferred & DEFERRED_REFRESH)
|
||||
nsXFormsUtils::DispatchEvent(element, eEvent_Refresh);
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsActionElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
if (!mElement)
|
||||
return NS_OK;
|
||||
|
||||
if (!mDeferredUpdates.IsInitialized()) {
|
||||
if (!mDeferredUpdates.Init())
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
mDeferredUpdates.Clear();
|
||||
}
|
||||
|
||||
mParentAction = aParentAction;
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
mElement->GetChildNodes(getter_AddRefs(childNodes));
|
||||
if (!childNodes)
|
||||
return NS_OK;
|
||||
PRUint32 count;
|
||||
childNodes->GetLength(&count);
|
||||
nsCOMPtr<nsIXFormsActionModuleElement> actionChild;
|
||||
nsCOMPtr<nsIDOMEvent> event(aEvent);
|
||||
for (PRUint32 i = 0; i < count; ++i) {
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
childNodes->Item(i, getter_AddRefs(child));
|
||||
actionChild = do_QueryInterface(child);
|
||||
if (actionChild)
|
||||
actionChild->HandleAction(event, this);
|
||||
}
|
||||
if (!aParentAction) //Otherwise parent will handle deferred updates
|
||||
mDeferredUpdates.EnumerateRead(DoDeferredActions, nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsActionElement::SetRebuild(nsIDOMNode* 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(nsIDOMNode* 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(nsIDOMNode* 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(nsIDOMNode* 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;
|
||||
}
|
||||
|
||||
60
mozilla/extensions/xforms/nsXFormsActionElement.h
Normal file
60
mozilla/extensions/xforms/nsXFormsActionElement.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- 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 "nsIXFormsActionElement.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
|
||||
|
||||
85
mozilla/extensions/xforms/nsXFormsActionModuleBase.cpp
Normal file
85
mozilla/extensions/xforms/nsXFormsActionModuleBase.cpp
Normal file
@@ -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"
|
||||
#include "nsIDOM3Node.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsXFormsModelElement.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIXTFGenericElementWrapper.h"
|
||||
#include "nsIDOMDocumentEvent.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
|
||||
nsXFormsActionModuleBase::nsXFormsActionModuleBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsXFormsActionModuleBase::~nsXFormsActionModuleBase()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsActionModuleBase,
|
||||
nsXFormsStubElement,
|
||||
nsIXFormsActionModuleElement,
|
||||
nsIDOMEventListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsActionModuleBase::OnCreated(nsIXTFGenericElementWrapper *aWrapper)
|
||||
{
|
||||
aWrapper->GetElementNode(getter_AddRefs(mElement));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXFormsActionModuleBase::OnDestroyed()
|
||||
{
|
||||
mElement = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsActionModuleBase::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
if (!aEvent)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
return HandleAction(aEvent, nsnull);
|
||||
}
|
||||
|
||||
65
mozilla/extensions/xforms/nsXFormsActionModuleBase.h
Normal file
65
mozilla/extensions/xforms/nsXFormsActionModuleBase.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*- 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 "nsIDOMEventListener.h"
|
||||
#include "nsXFormsStubElement.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIXFormsActionModuleElement.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
|
||||
class nsXFormsActionModuleBase : public nsIDOMEventListener,
|
||||
public nsXFormsStubElement,
|
||||
public nsIXFormsActionModuleElement
|
||||
{
|
||||
public:
|
||||
nsXFormsActionModuleBase();
|
||||
virtual ~nsXFormsActionModuleBase();
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIXTFGENERICELEMENT
|
||||
NS_DECL_NSIDOMEVENTLISTENER
|
||||
NS_IMETHOD OnDestroyed();
|
||||
protected:
|
||||
nsCOMPtr<nsIDOMElement> mElement;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
128
mozilla/extensions/xforms/nsXFormsDispatchElement.cpp
Normal file
128
mozilla/extensions/xforms/nsXFormsDispatchElement.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/* -*- 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 "nsIDOMDocument.h"
|
||||
#include "nsIDOMDocumentEvent.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
|
||||
class nsXFormsDispatchElement : public nsXFormsActionModuleBase
|
||||
{
|
||||
public:
|
||||
nsXFormsDispatchElement();
|
||||
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
|
||||
};
|
||||
|
||||
nsXFormsDispatchElement::nsXFormsDispatchElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsDispatchElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
if (!mElement)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString name;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
||||
if (name.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString target;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("target"), target);
|
||||
if (target.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
PRBool cancelable = PR_TRUE;
|
||||
PRBool bubbles = PR_TRUE;
|
||||
if (!nsXFormsUtils::IsXFormsEvent(name, cancelable, bubbles)) {
|
||||
nsAutoString cancelableStr;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("cancelable"), cancelableStr);
|
||||
cancelable = cancelableStr.EqualsLiteral("true");
|
||||
|
||||
nsAutoString bubbleStr;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("bubbles"), bubbleStr);
|
||||
bubbles = bubbleStr.EqualsLiteral("true");
|
||||
|
||||
PRBool tmp;
|
||||
if (cancelableStr.IsEmpty() && bubbleStr.IsEmpty())
|
||||
nsXFormsUtils::GetEventDefaults(name, cancelable, bubbles);
|
||||
else if (cancelableStr.IsEmpty())
|
||||
nsXFormsUtils::GetEventDefaults(name, cancelable, tmp);
|
||||
else if (bubbleStr.IsEmpty())
|
||||
nsXFormsUtils::GetEventDefaults(name, tmp, bubbles);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
mElement->GetOwnerDocument(getter_AddRefs(doc));
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,19 @@
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsInputElement(nsIXTFElement **aElement);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsOutputElement(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_NewXFormsSetValueElement(nsIXTFElement **aResult);
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsXFormsElementFactory, nsIXTFElementFactory)
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -62,6 +75,28 @@ nsXFormsElementFactory::CreateElement(const nsAString& aTagName,
|
||||
return NS_NewXFormsInputElement(aElement);
|
||||
if (aTagName.EqualsLiteral("output"))
|
||||
return NS_NewXFormsOutputElement(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("setvalue")))
|
||||
return NS_NewXFormsSetValueElement(aElement);
|
||||
if (aTagName.EqualsLiteral("submission"))
|
||||
return NS_NewXFormsSubmissionElement(aElement);
|
||||
|
||||
|
||||
128
mozilla/extensions/xforms/nsXFormsLoadElement.cpp
Normal file
128
mozilla/extensions/xforms/nsXFormsLoadElement.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/* -*- 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 "nsIDOMDocument.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIDOMLocation.h"
|
||||
#include "nsIDOMDocumentView.h"
|
||||
#include "nsIDOMAbstractView.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
|
||||
class nsXFormsLoadElement : public nsXFormsActionModuleBase
|
||||
{
|
||||
public:
|
||||
nsXFormsLoadElement();
|
||||
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
|
||||
};
|
||||
|
||||
nsXFormsLoadElement::nsXFormsLoadElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsLoadElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
if(!mElement)
|
||||
return NS_OK;
|
||||
//If the element has 'resource' and single node binding, the
|
||||
//action has no effect.
|
||||
PRBool hasBind;
|
||||
PRBool hasRef;
|
||||
mElement->HasAttribute(NS_LITERAL_STRING("bind"), &hasBind);
|
||||
mElement->HasAttribute(NS_LITERAL_STRING("ref"), &hasRef);
|
||||
nsAutoString resource;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("resource"), resource);
|
||||
|
||||
if (!resource.IsEmpty() && (hasBind || hasRef))
|
||||
return NS_OK;
|
||||
nsAutoString urlstr;
|
||||
if (!resource.IsEmpty())
|
||||
urlstr = resource;
|
||||
else if (!nsXFormsUtils::GetSingleNodeBindingValue(mElement, urlstr))
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
mElement->GetOwnerDocument(getter_AddRefs(doc));
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentView> dview(do_QueryInterface(doc));
|
||||
if (!dview)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMAbstractView> aview;
|
||||
dview->GetDefaultView(getter_AddRefs(aview));
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> internal(do_QueryInterface(aview));
|
||||
NS_ASSERTION(internal, "No AbstractView or it isn't an nsIDOMWindowInternal");
|
||||
if (!internal)
|
||||
return NS_OK;
|
||||
|
||||
PRBool openNew = PR_FALSE;
|
||||
nsAutoString show;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("show"), show);
|
||||
if (show.EqualsLiteral("new")) {
|
||||
openNew = PR_TRUE;
|
||||
}
|
||||
//Otherwise 'replace'
|
||||
if (openNew) {
|
||||
nsCOMPtr<nsIDOMWindow> messageWindow;
|
||||
internal->Open(urlstr, EmptyString(), EmptyString(),
|
||||
getter_AddRefs(messageWindow));
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMLocation> location;
|
||||
internal->GetLocation(getter_AddRefs(location));
|
||||
if (location)
|
||||
location->Assign(urlstr);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -40,9 +40,6 @@
|
||||
#include "nsXFormsModelElement.h"
|
||||
#include "nsIXTFGenericElementWrapper.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsIDOMDocumentEvent.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOM3Node.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
@@ -83,29 +80,6 @@ static const nsIID sScriptingIIDs[] = {
|
||||
NS_IXFORMSMODELELEMENT_IID
|
||||
};
|
||||
|
||||
struct EventData
|
||||
{
|
||||
const char *name;
|
||||
PRBool canCancel;
|
||||
PRBool canBubble;
|
||||
};
|
||||
|
||||
static const EventData sModelEvents[] = {
|
||||
{ "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-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-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 nsIAtom* sModelPropsList[eModel__count];
|
||||
|
||||
nsXFormsModelElement::nsXFormsModelElement()
|
||||
@@ -226,7 +200,7 @@ nsXFormsModelElement::DoneAddingChildren()
|
||||
// We wait until all children are added to dispatch xforms-model-construct,
|
||||
// since the model may have an action handler for this event.
|
||||
|
||||
nsresult rv = DispatchEvent(eEvent_ModelConstruct);
|
||||
nsresult rv = nsXFormsUtils::DispatchEvent(mElement, eEvent_ModelConstruct);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// xforms-model-construct is not cancellable, so always proceed.
|
||||
@@ -257,7 +231,8 @@ nsXFormsModelElement::DoneAddingChildren()
|
||||
nsnull, baseURI);
|
||||
|
||||
if (!newURI) {
|
||||
DispatchEvent(eEvent_LinkException); // this is a fatal error
|
||||
// this is a fatal error
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -266,7 +241,8 @@ nsXFormsModelElement::DoneAddingChildren()
|
||||
|
||||
rv = loader->LoadAsync(NS_ConvertUTF8toUTF16(uriSpec), this);
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchEvent(eEvent_LinkException); // this is a fatal error
|
||||
// this is a fatal error
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
if (index == -1)
|
||||
@@ -432,7 +408,7 @@ nsXFormsModelElement::OnLoad(nsISchema* aSchema)
|
||||
nsresult rv = FinishConstruction();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
DispatchEvent(eEvent_Refresh);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_Refresh);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@@ -444,7 +420,7 @@ NS_IMETHODIMP
|
||||
nsXFormsModelElement::OnError(nsresult aStatus,
|
||||
const nsAString &aStatusMessage)
|
||||
{
|
||||
DispatchEvent(eEvent_LinkException);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -473,8 +449,9 @@ nsXFormsModelElement::Load(nsIDOMEvent* aEvent)
|
||||
|
||||
NS_ASSERTION(models, "models list is empty!");
|
||||
for (PRInt32 i = 0; i < models->Count(); ++i) {
|
||||
NS_STATIC_CAST(nsXFormsModelElement*, models->ElementAt(i))
|
||||
->DispatchEvent(eEvent_ModelConstructDone);
|
||||
nsXFormsModelElement* model =
|
||||
NS_STATIC_CAST(nsXFormsModelElement*, models->ElementAt(i));
|
||||
nsXFormsUtils::DispatchEvent(model->mElement, eEvent_ModelConstructDone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,14 +473,14 @@ nsXFormsModelElement::Unload(nsIDOMEvent* aEvent)
|
||||
NS_IMETHODIMP
|
||||
nsXFormsModelElement::Abort(nsIDOMEvent* aEvent)
|
||||
{
|
||||
DispatchEvent(eEvent_LinkException);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsModelElement::Error(nsIDOMEvent* aEvent)
|
||||
{
|
||||
DispatchEvent(eEvent_LinkException);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -544,11 +521,11 @@ nsXFormsModelElement::InstanceLoadFinished(PRBool aSuccess)
|
||||
{
|
||||
--mPendingInstanceCount;
|
||||
if (!aSuccess) {
|
||||
DispatchEvent(eEvent_LinkException);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
} else if (IsComplete()) {
|
||||
nsresult rv = FinishConstruction();
|
||||
if (NS_SUCCEEDED(rv))
|
||||
DispatchEvent(eEvent_Refresh);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_Refresh);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@@ -647,7 +624,7 @@ nsXFormsModelElement::FinishConstruction()
|
||||
if (namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
|
||||
if (!ProcessBind(xpath, firstInstanceRoot, nsnull,
|
||||
nsCOMPtr<nsIDOMElement>(do_QueryInterface(child)))) {
|
||||
DispatchEvent(eEvent_BindingException);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
@@ -656,9 +633,9 @@ nsXFormsModelElement::FinishConstruction()
|
||||
|
||||
// 5. dispatch xforms-rebuild, xforms-recalculate, xforms-revalidate
|
||||
|
||||
DispatchEvent(eEvent_Rebuild);
|
||||
DispatchEvent(eEvent_Recalculate);
|
||||
DispatchEvent(eEvent_Revalidate);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_Rebuild);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_Recalculate);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_Revalidate);
|
||||
|
||||
// We're done initializing this model.
|
||||
|
||||
@@ -809,27 +786,6 @@ nsXFormsModelElement::ProcessBind(nsIDOMXPathEvaluator *aEvaluator,
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXFormsModelElement::DispatchEvent(nsXFormsModelEvent aEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentEvent> doc = do_QueryInterface(domDoc);
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
doc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
||||
NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
const EventData *data = &sModelEvents[aEvent];
|
||||
event->InitEvent(NS_ConvertUTF8toUTF16(data->name),
|
||||
data->canBubble, data->canCancel);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mElement);
|
||||
PRBool cancelled;
|
||||
return target->DispatchEvent(event, &cancelled);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsXFormsModelElement::Startup()
|
||||
{
|
||||
|
||||
@@ -57,27 +57,6 @@ class nsIDOMNode;
|
||||
class nsIDOMXPathEvaluator;
|
||||
class nsXFormsControl;
|
||||
|
||||
/**
|
||||
* XForms event types
|
||||
*
|
||||
* @see http://www.w3.org/TR/xforms/slice4.html#rpm-events
|
||||
*/
|
||||
enum nsXFormsModelEvent {
|
||||
eEvent_ModelConstruct,
|
||||
eEvent_ModelConstructDone,
|
||||
eEvent_Ready,
|
||||
eEvent_ModelDestruct,
|
||||
eEvent_Rebuild,
|
||||
eEvent_Refresh,
|
||||
eEvent_Revalidate,
|
||||
eEvent_Recalculate,
|
||||
eEvent_Reset,
|
||||
eEvent_BindingException,
|
||||
eEvent_LinkException,
|
||||
eEvent_LinkError,
|
||||
eEvent_ComputeException
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of the XForms \<model\> element.
|
||||
*
|
||||
@@ -121,7 +100,6 @@ public:
|
||||
static NS_HIDDEN_(void) Startup();
|
||||
|
||||
private:
|
||||
NS_HIDDEN_(nsresult) DispatchEvent(nsXFormsModelEvent aEvent);
|
||||
|
||||
NS_HIDDEN_(already_AddRefed<nsIDOMDocument>)
|
||||
FindInstanceDocument(const nsAString &aID);
|
||||
|
||||
@@ -55,6 +55,7 @@ PR_STATIC_CALLBACK(nsresult)
|
||||
XFormsModuleCtor(nsIModule* aSelf)
|
||||
{
|
||||
nsXFormsAtoms::InitAtoms();
|
||||
nsXFormsUtils::Init();
|
||||
nsXFormsModelElement::Startup();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
80
mozilla/extensions/xforms/nsXFormsRebuildElement.cpp
Normal file
80
mozilla/extensions/xforms/nsXFormsRebuildElement.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsRebuildElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> model =
|
||||
nsXFormsUtils::GetModelAndBind(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
nsnull);
|
||||
if (model) {
|
||||
if (aParentAction) {
|
||||
aParentAction->SetRebuild(model, PR_FALSE);
|
||||
}
|
||||
return nsXFormsUtils::DispatchEvent(model, eEvent_Rebuild);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsRebuildElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsRebuildElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
80
mozilla/extensions/xforms/nsXFormsRecalculateElement.cpp
Normal file
80
mozilla/extensions/xforms/nsXFormsRecalculateElement.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsRecalculateElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> model =
|
||||
nsXFormsUtils::GetModelAndBind(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
nsnull);
|
||||
if (model) {
|
||||
if (aParentAction) {
|
||||
aParentAction->SetRecalculate(model, PR_FALSE);
|
||||
}
|
||||
return nsXFormsUtils::DispatchEvent(model, eEvent_Recalculate);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsRecalculateElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsRecalculateElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
80
mozilla/extensions/xforms/nsXFormsRefreshElement.cpp
Normal file
80
mozilla/extensions/xforms/nsXFormsRefreshElement.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsRefreshElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> model =
|
||||
nsXFormsUtils::GetModelAndBind(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
nsnull);
|
||||
if (model) {
|
||||
if (aParentAction) {
|
||||
aParentAction->SetRefresh(model, PR_FALSE);
|
||||
}
|
||||
return nsXFormsUtils::DispatchEvent(model, eEvent_Refresh);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsRefreshElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsRefreshElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
82
mozilla/extensions/xforms/nsXFormsResetElement.cpp
Normal file
82
mozilla/extensions/xforms/nsXFormsResetElement.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/* -*- 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() {
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsResetElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> model =
|
||||
nsXFormsUtils::GetModelAndBind(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
nsnull);
|
||||
if (model) {
|
||||
if (aParentAction) {
|
||||
aParentAction->SetRebuild(model, PR_FALSE);
|
||||
aParentAction->SetRecalculate(model, PR_FALSE);
|
||||
aParentAction->SetRevalidate(model, PR_FALSE);
|
||||
aParentAction->SetRefresh(model, PR_FALSE);
|
||||
}
|
||||
return nsXFormsUtils::DispatchEvent(model, eEvent_Reset);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsResetElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsResetElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
80
mozilla/extensions/xforms/nsXFormsRevalidateElement.cpp
Normal file
80
mozilla/extensions/xforms/nsXFormsRevalidateElement.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* 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()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsRevalidateElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> model =
|
||||
nsXFormsUtils::GetModelAndBind(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
nsnull);
|
||||
if (model) {
|
||||
if (aParentAction) {
|
||||
aParentAction->SetRevalidate(model, PR_FALSE);
|
||||
}
|
||||
return nsXFormsUtils::DispatchEvent(model, eEvent_Revalidate);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsRevalidateElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsRevalidateElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
91
mozilla/extensions/xforms/nsXFormsSendElement.cpp
Normal file
91
mozilla/extensions/xforms/nsXFormsSendElement.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/* -*- 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 "nsIDOMDocument.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsXFormsSendElement : public nsXFormsActionModuleBase
|
||||
{
|
||||
public:
|
||||
nsXFormsSendElement();
|
||||
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
|
||||
};
|
||||
|
||||
nsXFormsSendElement::nsXFormsSendElement() {
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsSendElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
if (!mElement)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString submission;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("submission"), submission);
|
||||
if (submission.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
mElement->GetOwnerDocument(getter_AddRefs(doc));
|
||||
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
|
||||
|
||||
return nsXFormsUtils::DispatchEvent(el, eEvent_Submit);
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsSendElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsSendElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
92
mozilla/extensions/xforms/nsXFormsSetFocusElement.cpp
Normal file
92
mozilla/extensions/xforms/nsXFormsSetFocusElement.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/* -*- 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 "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsXFormsSetFocusElement : public nsXFormsActionModuleBase
|
||||
{
|
||||
public:
|
||||
nsXFormsSetFocusElement();
|
||||
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
|
||||
};
|
||||
|
||||
nsXFormsSetFocusElement::nsXFormsSetFocusElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsSetFocusElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
if (!mElement)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString control;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("control"), control);
|
||||
if (control.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
mElement->GetOwnerDocument(getter_AddRefs(doc));
|
||||
if (!doc)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> el;
|
||||
doc->GetElementById(control, getter_AddRefs(el));
|
||||
if (!el)
|
||||
return NS_OK;
|
||||
//XXX Should we check the type of the element?
|
||||
|
||||
return nsXFormsUtils::DispatchEvent(el, eEvent_Focus);
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsSetFocusElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsSetFocusElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
164
mozilla/extensions/xforms/nsXFormsSetValueElement.cpp
Normal file
164
mozilla/extensions/xforms/nsXFormsSetValueElement.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/* -*- 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 "nsIDOMXPathResult.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIXFormsModelElement.h"
|
||||
#include "nsXFormsModelElement.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
|
||||
class nsXFormsSetValueElement : public nsXFormsActionModuleBase
|
||||
{
|
||||
public:
|
||||
nsXFormsSetValueElement();
|
||||
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
|
||||
};
|
||||
|
||||
nsXFormsSetValueElement::nsXFormsSetValueElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsSetValueElement::HandleAction(nsIDOMEvent* aEvent,
|
||||
nsIXFormsActionElement *aParentAction)
|
||||
{
|
||||
if (!mElement)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> bind;
|
||||
nsCOMPtr<nsIDOMNode> dommodel =
|
||||
nsXFormsUtils::GetModelAndBind(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
getter_AddRefs(bind));
|
||||
if (!dommodel)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString value;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("value"), value);
|
||||
if (!value.IsEmpty()) {
|
||||
nsCOMPtr<nsIXFormsModelElement> model(do_QueryInterface(dommodel));
|
||||
if (!model)
|
||||
return NS_OK;
|
||||
|
||||
// Get the instance data and evaluate the xpath expression.
|
||||
// XXXfixme when xpath extensions are implemented (instance())
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> instanceDoc;
|
||||
model->GetInstanceDocument(NS_LITERAL_STRING(""),
|
||||
getter_AddRefs(instanceDoc));
|
||||
if (!instanceDoc)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> docElement;
|
||||
instanceDoc->GetDocumentElement(getter_AddRefs(docElement));
|
||||
|
||||
nsCOMPtr<nsIDOMXPathResult> xpResult =
|
||||
nsXFormsUtils::EvaluateXPath(value, docElement, mElement,
|
||||
nsIDOMXPathResult::STRING_TYPE);
|
||||
xpResult->GetStringValue(value);
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOM3Node> n3(do_QueryInterface(mElement));
|
||||
n3->GetTextContent(value);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> model;
|
||||
nsCOMPtr<nsIDOMElement> bindElement;
|
||||
nsCOMPtr<nsIDOMXPathResult> result =
|
||||
nsXFormsUtils:: EvaluateNodeBinding(mElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
NS_LITERAL_STRING("ref"),
|
||||
EmptyString(),
|
||||
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
|
||||
getter_AddRefs(model),
|
||||
getter_AddRefs(bindElement));
|
||||
|
||||
if (!result)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> singleNode;
|
||||
result->GetSingleNodeValue(getter_AddRefs(singleNode));
|
||||
if (!singleNode)
|
||||
return NS_OK;
|
||||
|
||||
PRUint16 nodeType = 0;
|
||||
singleNode->GetNodeType(&nodeType);
|
||||
|
||||
switch (nodeType) {
|
||||
case nsIDOMNode::ATTRIBUTE_NODE:
|
||||
case nsIDOMNode::TEXT_NODE:
|
||||
singleNode->SetNodeValue(value);
|
||||
break;
|
||||
case nsIDOMNode::ELEMENT_NODE:
|
||||
nsCOMPtr<nsIDOM3Node> node = do_QueryInterface(singleNode);
|
||||
NS_ASSERTION(node, "DOM Nodes must support DOM3 interfaces");
|
||||
node->SetTextContent(value);
|
||||
break;
|
||||
}
|
||||
|
||||
//XXX Mark the node changed
|
||||
|
||||
if (aParentAction) {
|
||||
aParentAction->SetRecalculate(dommodel, PR_TRUE);
|
||||
aParentAction->SetRevalidate(dommodel, PR_TRUE);
|
||||
aParentAction->SetRefresh(dommodel, PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsXFormsUtils::DispatchEvent(dommodel, eEvent_Recalculate);
|
||||
nsXFormsUtils::DispatchEvent(dommodel, eEvent_Revalidate);
|
||||
nsXFormsUtils::DispatchEvent(dommodel, eEvent_Refresh);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,133 @@
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIXFormsModelElement.h"
|
||||
|
||||
#include "nsIDOMDocumentEvent.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMEventTarget.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 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> sXFormsEvents;
|
||||
static nsDataHashtable<nsStringHashKey,PRUint32> sEventDefaults;
|
||||
|
||||
/* static */ nsresult
|
||||
nsXFormsUtils::Init()
|
||||
{
|
||||
if (!sXFormsEvents.Init())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sXFormsEventsEntries); ++i) {
|
||||
PRUint32 flag = 0;
|
||||
if (sXFormsEventsEntries[i].canCancel)
|
||||
flag |= CANCELABLE;
|
||||
if (sXFormsEventsEntries[i].canBubble)
|
||||
flag |= BUBBLES;
|
||||
sXFormsEvents.Put(NS_ConvertUTF8toUTF16(sXFormsEventsEntries[i].name),
|
||||
flag);
|
||||
}
|
||||
|
||||
if (!sEventDefaults.Init())
|
||||
return NS_ERROR_FAILURE;
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sEventDefaultsEntries); ++i) {
|
||||
PRUint32 flag = 0;
|
||||
if (sEventDefaultsEntries[i].canCancel)
|
||||
flag |= CANCELABLE;
|
||||
if (sEventDefaultsEntries[i].canBubble)
|
||||
flag |= BUBBLES;
|
||||
sEventDefaults.Put(NS_ConvertUTF8toUTF16(sEventDefaultsEntries[i].name),
|
||||
flag);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */ nsIDOMNode*
|
||||
nsXFormsUtils::GetParentModel(nsIDOMElement *aElement)
|
||||
{
|
||||
@@ -84,23 +211,26 @@ nsXFormsUtils::GetModelAndBind(nsIDOMElement *aElement,
|
||||
PRUint32 aElementFlags,
|
||||
nsIDOMElement **aBindElement)
|
||||
{
|
||||
*aBindElement = nsnull;
|
||||
NS_ENSURE_TRUE(aElement, nsnull);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
aElement->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
if (!domDoc)
|
||||
return nsnull;
|
||||
|
||||
nsAutoString bindId;
|
||||
aElement->GetAttribute(NS_LITERAL_STRING("bind"), bindId);
|
||||
|
||||
if (!bindId.IsEmpty()) {
|
||||
// Get the bind element with the given id.
|
||||
domDoc->GetElementById(bindId, aBindElement);
|
||||
|
||||
if (*aBindElement)
|
||||
return GetParentModel(*aBindElement);
|
||||
|
||||
if (aBindElement) {
|
||||
*aBindElement = nsnull;
|
||||
|
||||
nsAutoString bindId;
|
||||
aElement->GetAttribute(NS_LITERAL_STRING("bind"), bindId);
|
||||
|
||||
if (!bindId.IsEmpty()) {
|
||||
// Get the bind element with the given id.
|
||||
domDoc->GetElementById(bindId, aBindElement);
|
||||
|
||||
if (*aBindElement)
|
||||
return GetParentModel(*aBindElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (aElementFlags & ELEMENT_WITH_MODEL_ATTR) {
|
||||
@@ -460,6 +590,81 @@ nsXFormsUtils::SetNodeValue(nsIDOMNode* aDataNode, const nsString& aNodeValue)
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ PRBool
|
||||
nsXFormsUtils::GetSingleNodeBindingValue(nsIDOMElement* aElement,
|
||||
nsString& aValue)
|
||||
{
|
||||
if (!aElement)
|
||||
return PR_FALSE;
|
||||
nsCOMPtr<nsIDOMNode> model;
|
||||
nsCOMPtr<nsIDOMElement> bindElement;
|
||||
nsCOMPtr<nsIDOMXPathResult> result =
|
||||
EvaluateNodeBinding(aElement,
|
||||
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
|
||||
NS_LITERAL_STRING("ref"),
|
||||
EmptyString(),
|
||||
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
|
||||
getter_AddRefs(model),
|
||||
getter_AddRefs(bindElement));
|
||||
if (!result)
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> singleNode;
|
||||
result->GetSingleNodeValue(getter_AddRefs(singleNode));
|
||||
if (!singleNode)
|
||||
return PR_FALSE;
|
||||
|
||||
nsXFormsUtils::GetNodeValue(singleNode, aValue);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsXFormsUtils::DispatchEvent(nsIDOMNode* aTarget, nsXFormsEvent aEvent)
|
||||
{
|
||||
if (!aTarget)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
aTarget->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentEvent> doc = do_QueryInterface(domDoc);
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
doc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
||||
NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
const EventData *data = &sXFormsEventsEntries[aEvent];
|
||||
event->InitEvent(NS_ConvertUTF8toUTF16(data->name),
|
||||
data->canBubble, data->canCancel);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aTarget);
|
||||
PRBool cancelled;
|
||||
return target->DispatchEvent(event, &cancelled);
|
||||
}
|
||||
|
||||
/* static */ PRBool
|
||||
nsXFormsUtils::IsXFormsEvent(const nsAString& aEvent,
|
||||
PRBool& aCancelable,
|
||||
PRBool& aBubbles)
|
||||
{
|
||||
PRUint32 flag = 0;
|
||||
if (!sXFormsEvents.Get(aEvent, &flag))
|
||||
return PR_FALSE;
|
||||
aCancelable = (flag & CANCELABLE) ? PR_TRUE : PR_FALSE;
|
||||
aBubbles = (flag & BUBBLES) ? PR_TRUE : PR_FALSE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsXFormsUtils::GetEventDefaults(const nsAString& aEvent,
|
||||
PRBool& aCancelable,
|
||||
PRBool& aBubbles)
|
||||
{
|
||||
PRUint32 flag = 0;
|
||||
if (!sEventDefaults.Get(aEvent, &flag))
|
||||
return;
|
||||
aCancelable = (flag & CANCELABLE) ? PR_TRUE : PR_FALSE;
|
||||
aBubbles = (flag & BUBBLES) ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsXFormsUtils::CloneScriptingInterfaces(const nsIID *aIIDList,
|
||||
|
||||
@@ -54,6 +54,56 @@ class nsString;
|
||||
#define NS_NAMESPACE_XML_SCHEMA "http://www.w3.org/2001/XMLSchema"
|
||||
#define NS_NAMESPACE_XML_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance"
|
||||
|
||||
/**
|
||||
* XForms event types
|
||||
*
|
||||
* @see http://www.w3.org/TR/xforms/slice4.html#rpm-events
|
||||
*/
|
||||
|
||||
enum nsXFormsEvent {
|
||||
eEvent_ModelConstruct,
|
||||
eEvent_ModelConstructDone,
|
||||
eEvent_Ready,
|
||||
eEvent_ModelDestruct,
|
||||
eEvent_Previous,
|
||||
eEvent_Next,
|
||||
eEvent_Focus,
|
||||
eEvent_Help,
|
||||
eEvent_Hint,
|
||||
eEvent_Rebuild,
|
||||
eEvent_Refresh,
|
||||
eEvent_Revalidate,
|
||||
eEvent_Recalculate,
|
||||
eEvent_Reset,
|
||||
eEvent_Submit,
|
||||
eEvent_DOMActivate,
|
||||
eEvent_ValueChanged,
|
||||
eEvent_Select,
|
||||
eEvent_Deselect,
|
||||
eEvent_ScrollFirst,
|
||||
eEvent_ScrollLast,
|
||||
eEvent_Insert,
|
||||
eEvent_Delete,
|
||||
eEvent_Valid,
|
||||
eEvent_Invalid,
|
||||
eEvent_DOMFocusIn,
|
||||
eEvent_DOMFocusOut,
|
||||
eEvent_Readonly,
|
||||
eEvent_Readwrite,
|
||||
eEvent_Required,
|
||||
eEvent_Optional,
|
||||
eEvent_Enabled,
|
||||
eEvent_Disabled,
|
||||
eEvent_InRange,
|
||||
eEvent_OutOfRange,
|
||||
eEvent_SubmitDone,
|
||||
eEvent_SubmitError,
|
||||
eEvent_BindingException,
|
||||
eEvent_LinkException,
|
||||
eEvent_LinkError,
|
||||
eEvent_ComputeException
|
||||
};
|
||||
|
||||
/**
|
||||
* This class has static helper methods that don't fit into a specific place
|
||||
* in the class hierarchy.
|
||||
@@ -73,6 +123,12 @@ public:
|
||||
ELEMENT_WITH_MODEL_ATTR = 1 << 0
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize nsXFormsUtils.
|
||||
*/
|
||||
static NS_HIDDEN_(nsresult)
|
||||
Init();
|
||||
|
||||
/**
|
||||
* Locate the model that is a parent of |aElement|. This method walks up the
|
||||
* content tree looking for the containing model.
|
||||
@@ -151,6 +207,38 @@ public:
|
||||
static NS_HIDDEN_(void) SetNodeValue(nsIDOMNode *aDataNode,
|
||||
const nsString &aNodeValue);
|
||||
|
||||
/**
|
||||
* Convenience method for doing XPath evaluations to get string value
|
||||
* for an element.
|
||||
* Returns PR_TRUE if the evaluation succeeds.
|
||||
*/
|
||||
static NS_HIDDEN_(PRBool)
|
||||
GetSingleNodeBindingValue(nsIDOMElement* aElement, nsString& aValue);
|
||||
|
||||
/**
|
||||
* Dispatch an XForms event.
|
||||
*/
|
||||
static NS_HIDDEN_(nsresult)
|
||||
DispatchEvent(nsIDOMNode* aTarget, nsXFormsEvent aEvent);
|
||||
|
||||
/**
|
||||
* Returns PR_TRUE, if aEvent is an XForms event, and sets the values
|
||||
* of aCancelable and aBubbles parameters according to the event type.
|
||||
*/
|
||||
static NS_HIDDEN_(PRBool)
|
||||
IsXFormsEvent(const nsAString& aEvent,
|
||||
PRBool& aCancelable,
|
||||
PRBool& aBubbles);
|
||||
|
||||
/**
|
||||
* Checks if aEvent is a predefined event and sets the values
|
||||
* of aCancelable and aBubbles parameters according to the event type.
|
||||
*/
|
||||
static NS_HIDDEN_(void)
|
||||
GetEventDefaults(const nsAString& aEvent,
|
||||
PRBool& aCancelable,
|
||||
PRBool& aBubbles);
|
||||
|
||||
/**
|
||||
* Clone the set of IIDs in |aIIDList| into |aOutArray|.
|
||||
* |aOutCount| is set to |aIIDCount|.
|
||||
|
||||
Reference in New Issue
Block a user