mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Disables submit button until submit is done. Bug 280312, r=aaronr+me, patch by smaug@welho.com
This commit is contained in:
parent
529e7b08db
commit
8fed129e53
@ -85,6 +85,8 @@ XPIDLSRCS = \
|
||||
nsIXFormsValueElement.idl \
|
||||
nsIXFormsRepeatElement.idl \
|
||||
nsIXFormsRepeatItemElement.idl \
|
||||
nsIXFormsSubmitElement.idl \
|
||||
nsIXFormsSubmissionElement.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
48
extensions/xforms/nsIXFormsSubmissionElement.idl
Normal file
48
extensions/xforms/nsIXFormsSubmissionElement.idl
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- 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) 2005
|
||||
* 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 "nsIXFormsSubmitElement.idl"
|
||||
|
||||
/**
|
||||
* Interface implemented by the submission element.
|
||||
*/
|
||||
[uuid(d132ff87-f6ce-4b7d-909e-323188966694)]
|
||||
interface nsIXFormsSubmissionElement : nsISupports
|
||||
{
|
||||
void setActivator(in nsIXFormsSubmitElement aActivator);
|
||||
};
|
48
extensions/xforms/nsIXFormsSubmitElement.idl
Normal file
48
extensions/xforms/nsIXFormsSubmitElement.idl
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- 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) 2005
|
||||
* 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 implemented by the submit element.
|
||||
*/
|
||||
[uuid(83427654-2cdd-48f6-bfef-285cb521554a)]
|
||||
interface nsIXFormsSubmitElement : nsISupports
|
||||
{
|
||||
void setDisabled(in boolean aDisable);
|
||||
};
|
@ -261,9 +261,10 @@ public:
|
||||
|
||||
// nsISupports
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsSubmissionElement,
|
||||
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsSubmissionElement,
|
||||
nsXFormsStubElement,
|
||||
nsIRequestObserver)
|
||||
nsIRequestObserver,
|
||||
nsIXFormsSubmissionElement)
|
||||
|
||||
// nsIXTFElement
|
||||
|
||||
@ -280,9 +281,16 @@ nsXFormsSubmissionElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled)
|
||||
nsAutoString type;
|
||||
aEvent->GetType(type);
|
||||
if (type.EqualsLiteral("xforms-submit")) {
|
||||
nsresult rv = Submit();
|
||||
if (NS_FAILED(rv))
|
||||
SubmitEnd(PR_FALSE);
|
||||
// If the submission is already active, do nothing.
|
||||
if (!mSubmissionActive && NS_FAILED(Submit())) {
|
||||
mSubmissionActive = PR_FALSE;
|
||||
if (mActivator) {
|
||||
mActivator->SetDisabled(PR_FALSE);
|
||||
mActivator = nsnull;
|
||||
}
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_SubmitError);
|
||||
}
|
||||
|
||||
*aHandled = PR_TRUE;
|
||||
} else {
|
||||
*aHandled = PR_FALSE;
|
||||
@ -291,6 +299,16 @@ nsXFormsSubmissionElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIXFormsSubmissionElement
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsSubmissionElement::SetActivator(nsIXFormsSubmitElement* aActivator)
|
||||
{
|
||||
if (!mActivator && !mSubmissionActive)
|
||||
mActivator = aActivator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIXTFGenericElement
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -348,7 +366,13 @@ nsXFormsSubmissionElement::OnStopRequest(nsIRequest *request, nsISupports *ctx,
|
||||
|
||||
mPipeIn = 0;
|
||||
|
||||
SubmitEnd(succeeded);
|
||||
mSubmissionActive = PR_FALSE;
|
||||
if (mActivator) {
|
||||
mActivator->SetDisabled(PR_FALSE);
|
||||
mActivator = nsnull;
|
||||
}
|
||||
nsXFormsUtils::DispatchEvent(mElement, succeeded ?
|
||||
eEvent_SubmitDone : eEvent_SubmitError);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -467,6 +491,9 @@ nsXFormsSubmissionElement::Submit()
|
||||
NS_ENSURE_STATE(!mSubmissionActive);
|
||||
mSubmissionActive = PR_TRUE;
|
||||
|
||||
if (mActivator)
|
||||
mActivator->SetDisabled(PR_TRUE);
|
||||
|
||||
// XXX seems to be required by
|
||||
// http://www.w3.org/TR/2003/REC-xforms-20031014/slice4.html#evt-revalidate
|
||||
// but is it really needed for us?
|
||||
@ -510,36 +537,6 @@ nsXFormsSubmissionElement::Submit()
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXFormsSubmissionElement::SubmitEnd(PRBool succeeded)
|
||||
{
|
||||
LOG(("xforms submission complete [%s]\n", succeeded ? "success" : "failure"));
|
||||
|
||||
// XForms 1.0 errata (E37) limits a <submission> element to performing
|
||||
// only one submission at a time, contrary to the spec which places the
|
||||
// limitation on the <model> element.
|
||||
mSubmissionActive = PR_FALSE;
|
||||
|
||||
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);
|
||||
|
||||
event->InitEvent(succeeded ? NS_LITERAL_STRING("xforms-submit-done")
|
||||
: NS_LITERAL_STRING("xforms-submit-error"),
|
||||
PR_TRUE, PR_FALSE);
|
||||
|
||||
// XForms 1.0 errata (E10) states that the target of the xforms-submit-error
|
||||
// event is the <submission> element instead of the <model> element.
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mElement);
|
||||
|
||||
PRBool cancelled;
|
||||
return target->DispatchEvent(event, &cancelled);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXFormsSubmissionElement::GetSelectedInstanceData(nsIDOMNode **result)
|
||||
{
|
||||
|
@ -44,6 +44,8 @@
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIModelElementPrivate.h"
|
||||
#include "nsIXFormsSubmitElement.h"
|
||||
#include "nsIXFormsSubmissionElement.h"
|
||||
|
||||
class nsIMultiplexInputStream;
|
||||
class nsIDOMElement;
|
||||
@ -60,11 +62,13 @@ class SubmissionAttachmentArray;
|
||||
* @see http://www.w3.org/TR/xforms/slice3.html#structure-model-submission
|
||||
*/
|
||||
class nsXFormsSubmissionElement : public nsXFormsStubElement,
|
||||
public nsIRequestObserver
|
||||
public nsIRequestObserver,
|
||||
public nsIXFormsSubmissionElement
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSIXFORMSSUBMISSIONELEMENT
|
||||
|
||||
nsXFormsSubmissionElement()
|
||||
: mElement(nsnull)
|
||||
@ -81,7 +85,6 @@ public:
|
||||
NS_HIDDEN_(nsresult) LoadReplaceInstance(nsIChannel *);
|
||||
NS_HIDDEN_(nsresult) LoadReplaceAll(nsIChannel *);
|
||||
NS_HIDDEN_(nsresult) Submit();
|
||||
NS_HIDDEN_(nsresult) SubmitEnd(PRBool succeeded);
|
||||
NS_HIDDEN_(PRBool) GetBooleanAttr(const nsAString &attrName, PRBool defaultVal = PR_FALSE);
|
||||
NS_HIDDEN_(void) GetDefaultInstanceData(nsIDOMNode **result);
|
||||
NS_HIDDEN_(nsresult) GetSelectedInstanceData(nsIDOMNode **result);
|
||||
@ -102,6 +105,7 @@ public:
|
||||
private:
|
||||
nsIDOMElement *mElement;
|
||||
PRBool mSubmissionActive;
|
||||
nsCOMPtr<nsIXFormsSubmitElement> mActivator;
|
||||
|
||||
// input end of pipe, which contains response data.
|
||||
nsCOMPtr<nsIInputStream> mPipeIn;
|
||||
|
@ -48,6 +48,8 @@
|
||||
#include "nsIXTFXMLVisualWrapper.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
#include "nsXFormsControlStub.h"
|
||||
#include "nsIXFormsSubmitElement.h"
|
||||
#include "nsIXFormsSubmissionElement.h"
|
||||
|
||||
class nsXFormsTriggerElement : public nsXFormsControlStub
|
||||
{
|
||||
@ -128,13 +130,21 @@ nsXFormsTriggerElement::TryFocus(PRBool* aOK)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class nsXFormsSubmitElement : public nsXFormsTriggerElement
|
||||
class nsXFormsSubmitElement : public nsXFormsTriggerElement,
|
||||
public nsIXFormsSubmitElement
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIXFORMSSUBMITELEMENT
|
||||
|
||||
// nsIXTFElement overrides
|
||||
NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled);
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsSubmitElement,
|
||||
nsXFormsTriggerElement,
|
||||
nsIXFormsSubmitElement)
|
||||
|
||||
// nsIXTFElement
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -163,33 +173,27 @@ nsXFormsSubmitElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled)
|
||||
|
||||
nsCOMPtr<nsIDOMElement> submissionElement;
|
||||
ownerDoc->GetElementById(submissionID, getter_AddRefs(submissionElement));
|
||||
nsCOMPtr<nsIXFormsSubmissionElement> xfSubmission(do_QueryInterface(submissionElement));
|
||||
|
||||
if (!submissionElement ||
|
||||
!nsXFormsUtils::IsXFormsElement(submissionElement, submission)) {
|
||||
if (!xfSubmission) {
|
||||
return nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(submissionElement);
|
||||
NS_ASSERTION(targ, "All elements should support nsIDOMEventTarget");
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(ownerDoc);
|
||||
NS_ASSERTION(targ, "All documents should support nsIDOMDocumentEvent");
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
||||
NS_ENSURE_STATE(event);
|
||||
|
||||
rv = event->InitEvent(NS_LITERAL_STRING("xforms-submit"), PR_TRUE, PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
|
||||
|
||||
PRBool unused;
|
||||
rv = targ->DispatchEvent(event, &unused);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
|
||||
xfSubmission->SetActivator(this);
|
||||
nsXFormsUtils::DispatchEvent(submissionElement, eEvent_Submit);
|
||||
|
||||
*aHandled = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsSubmitElement::SetDisabled(PRBool aDisable)
|
||||
{
|
||||
if (mButton)
|
||||
mButton->SetDisabled(aDisable);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
|
Loading…
Reference in New Issue
Block a user