Index: dom/public/idl/Makefile.in =================================================================== RCS file: /cvsroot/mozilla/dom/public/idl/Makefile.in,v retrieving revision 1.15 diff -p -u -8 -r1.15 Makefile.in --- dom/public/idl/Makefile.in 19 May 2006 05:57:35 -0000 1.15 +++ dom/public/idl/Makefile.in 24 Jul 2006 04:48:44 -0000 @@ -41,16 +41,17 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk DIRS = \ base \ canvas \ core \ html \ + web-forms \ events \ stylesheets \ views \ sidebar \ css \ traversal \ range \ xbl \ Index: dom/public/idl/web-forms/Makefile.in =================================================================== RCS file: dom/public/idl/web-forms/Makefile.in diff -N dom/public/idl/web-forms/Makefile.in --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/public/idl/web-forms/Makefile.in 24 Jul 2006 04:48:45 -0000 @@ -0,0 +1,54 @@ +# ***** 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 Web Forms 2.0. +# +# The Initial Developer of the Original Code is +# Alexander J. Vincent . +# Portions created by the Initial Developer are Copyright (C) 2006 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = dom +XPIDL_MODULE = dom_web_forms +GRE_MODULE = 1 + +SDK_XPIDLSRCS = \ + nsIDOMWF2ValidityState.idl \ + nsIDOMWF2FormControl.idl \ + nsIDOMWF2FormElement.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk Index: dom/public/idl/web-forms/nsIDOMWF2FormControl.idl =================================================================== RCS file: dom/public/idl/web-forms/nsIDOMWF2FormControl.idl diff -N dom/public/idl/web-forms/nsIDOMWF2FormControl.idl --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/public/idl/web-forms/nsIDOMWF2FormControl.idl 24 Jul 2006 04:48:45 -0000 @@ -0,0 +1,61 @@ +/* ***** 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 Web Forms 2.0. + * + * The Initial Developer of the Original Code is + * Alexander J. Vincent + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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" +#include "nsIDOMWF2ValidityState.idl" + +/* Because these properties and method are reused very frequently, they have + * been extracted into these common interfaces. + */ + +[scriptable, uuid(29360af0-f012-45d3-a339-d7fce8a2634c)] +interface nsIDOMWF2FormControl : nsISupports +{ + /** + * Indicates if this control will be validated. + */ + readonly attribute boolean willValidate; + + /** + * The validity state of this control. + */ + readonly attribute nsIDOMWF2ValidityState validity; + + /** + * Check the validity of this control. + */ + boolean checkValidity(); +}; Index: dom/public/idl/web-forms/nsIDOMWF2FormElement.idl =================================================================== RCS file: dom/public/idl/web-forms/nsIDOMWF2FormElement.idl diff -N dom/public/idl/web-forms/nsIDOMWF2FormElement.idl --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/public/idl/web-forms/nsIDOMWF2FormElement.idl 24 Jul 2006 04:48:45 -0000 @@ -0,0 +1,51 @@ +/* ***** 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 Web Forms 2.0. + * + * The Initial Developer of the Original Code is + * Alexander J. Vincent + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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" +#include "nsIDOMHTMLFormElement.idl" + +/* Because these properties and method are reused very frequently, they have + * been extracted into these common interfaces. + */ + +[scriptable, uuid(c6fa8507-6f41-4ce0-9350-2b1c3431f828)] +interface nsIDOMWF2FormElement : nsISupports +{ + /** + * Check the validity of all active elements in this form. + */ + PRBool checkValidity(); +}; Index: dom/public/idl/web-forms/nsIDOMWF2ValidityState.idl =================================================================== RCS file: dom/public/idl/web-forms/nsIDOMWF2ValidityState.idl diff -N dom/public/idl/web-forms/nsIDOMWF2ValidityState.idl --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/public/idl/web-forms/nsIDOMWF2ValidityState.idl 24 Jul 2006 04:48:45 -0000 @@ -0,0 +1,45 @@ +/* ***** 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 Web Forms 2.0. + * + * The Initial Developer of the Original Code is + * Alexander J. Vincent + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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" + +[scriptable, uuid(5a2e9790-3b72-4512-b3bf-203cec7b3379)] +interface nsIDOMWF2ValidityState : nsISupports { + /** + * True if this control meets all constraints on it. + */ + readonly attribute boolean valid; +}; Index: content/html/content/public/Makefile.in =================================================================== RCS file: /cvsroot/mozilla/content/html/content/public/Makefile.in,v retrieving revision 1.36 diff -p -u -8 -r1.36 Makefile.in --- content/html/content/public/Makefile.in 25 Apr 2006 09:18:29 -0000 1.36 +++ content/html/content/public/Makefile.in 24 Jul 2006 04:48:46 -0000 @@ -59,12 +59,13 @@ EXPORTS = \ nsIOptionElement.h \ nsIRadioControlElement.h \ nsIRadioVisitor.h \ nsIRadioGroupContainer.h \ nsITextControlElement.h \ nsIFileControlElement.h \ nsIFormSubmission.h \ nsIFrameSetElement.h \ + nsDOMWF2ValidityState.h \ $(NULL) include $(topsrcdir)/config/rules.mk Index: content/html/content/public/nsDOMWF2ValidityState.h =================================================================== RCS file: content/html/content/public/nsDOMWF2ValidityState.h diff -N content/html/content/public/nsDOMWF2ValidityState.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ content/html/content/public/nsDOMWF2ValidityState.h 24 Jul 2006 04:48:46 -0000 @@ -0,0 +1,52 @@ +/* ***** 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 Web Forms 2.0. + * + * The Initial Developer of the Original Code is + * Alexander J. Vincent + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 "nsIContent.h" + +class nsDOMWF2ValidityState : public nsIDOMWF2ValidityState +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMWF2VALIDITYSTATE + + nsDOMWF2ValidityState(); + +private: + ~nsDOMWF2ValidityState(); + +protected: + /* additional members */ +}; Index: content/html/content/src/nsDOMWF2ValidityState.cpp =================================================================== RCS file: content/html/content/src/nsDOMWF2ValidityState.cpp diff -N content/html/content/src/nsDOMWF2ValidityState.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ content/html/content/src/nsDOMWF2ValidityState.cpp 24 Jul 2006 04:48:46 -0000 @@ -0,0 +1,68 @@ +/* ***** 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 Web Forms 2.0. + * + * The Initial Developer of the Original Code is + * Alexander J. Vincent + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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.h" +#include "nsDOMWF2ValidityState.h" + +NS_IMPL_ISUPPORTS1(nsDOMWF2ValidityState, + nsIDOMWF2ValidityState) + +nsDOMWF2ValidityState::nsDOMWF2ValidityState() +{ + /* member initializers and constructor code */ +} + +nsDOMWF2ValidityState::~nsDOMWF2ValidityState() +{ + /* destructor code */ +} + +// QueryInterface implementation for nsDOMWF2ValidityState +NS_INTERFACE_MAP_BEGIN(nsDOMWF2ValidityState) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY(nsIDOMWF2ValidityState) + NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(DOMWF2ValidityState) +NS_INTERFACE_MAP_END + +NS_IMPL_ADDREF(nsDOMWF2ValidityState) +NS_IMPL_RELEASE(nsDOMWF2ValidityState) + +/* readonly attribute boolean valid; */ +NS_IMETHODIMP nsDOMWF2ValidityState::GetValid(PRBool *aValid) +{ + *aValid = PR_TRUE; + return NS_OK; +} Index: content/html/content/src/nsHTMLFormElement.cpp =================================================================== RCS file: /cvsroot/mozilla/content/html/content/src/nsHTMLFormElement.cpp,v retrieving revision 1.206 diff -p -u -8 -r1.206 nsHTMLFormElement.cpp --- content/html/content/src/nsHTMLFormElement.cpp 22 Jul 2006 11:07:29 -0000 +++ content/html/content/src/nsHTMLFormElement.cpp 24 Jul 2006 04:48:47 -0000 @@ -35,16 +35,18 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsCOMPtr.h" #include "nsIForm.h" #include "nsIFormControl.h" #include "nsIFormSubmission.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMNSHTMLFormElement.h" +#include "nsIDOMWF2FormElement.h" +#include "nsIDOMWF2FormControl.h" #include "nsIHTMLDocument.h" #include "nsIDOMNSHTMLFormControlList.h" #include "nsIDOMEventReceiver.h" #include "nsGenericHTMLElement.h" #include "nsEventStateManager.h" #include "nsHTMLAtoms.h" #include "nsStyleConsts.h" #include "nsPresContext.h" @@ -127,16 +129,17 @@ private: // nsHTMLFormElement class nsHTMLFormElement : public nsGenericHTMLElement, public nsSupportsWeakReference, public nsIDOMHTMLFormElement, public nsIDOMNSHTMLFormElement, + public nsIDOMWF2FormElement, public nsIWebProgressListener, public nsIForm, public nsIRadioGroupContainer { public: nsHTMLFormElement(nsINodeInfo *aNodeInfo); virtual ~nsHTMLFormElement(); @@ -155,16 +158,19 @@ public: NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::) // nsIDOMHTMLFormElement NS_DECL_NSIDOMHTMLFORMELEMENT // nsIDOMNSHTMLFormElement NS_DECL_NSIDOMNSHTMLFORMELEMENT + // nsIDOMWF2FormElement + NS_DECL_NSIDOMWF2FORMELEMENT + // nsIWebProgressListener NS_DECL_NSIWEBPROGRESSLISTENER // nsIForm NS_IMETHOD AddElement(nsIFormControl* aElement); NS_IMETHOD AddElementToTable(nsIFormControl* aChild, const nsAString& aName); NS_IMETHOD GetElementAt(PRInt32 aIndex, nsIFormControl** aElement) const; @@ -534,16 +540,17 @@ NS_IMPL_ADDREF_INHERITED(nsHTMLFormEleme NS_IMPL_RELEASE_INHERITED(nsHTMLFormElement, nsGenericElement) // QueryInterface implementation for nsHTMLFormElement NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFormElement, nsGenericHTMLElement) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMWF2FormElement) NS_INTERFACE_MAP_ENTRY(nsIForm) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsIRadioGroupContainer) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFormElement) NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMHTMLFormElement @@ -1781,16 +1788,61 @@ nsHTMLFormElement::RemoveFromRadioGroup( } PRUint32 nsHTMLFormElement::ElementCount() const { return mControls->mElements.Count(); } +// nsIDOMWF2FormElement +NS_IMETHODIMP +nsHTMLFormElement::CheckValidity(PRBool *_retval) +{ + *_retval = PR_TRUE; + + nsCOMPtr formControls; + nsresult rv = GetControlEnumerator(getter_AddRefs(formControls)); + NS_ENSURE_SUCCESS(rv, rv); + + // + // Walk the list of nodes and call SubmitNamesValues() on the controls + // + PRBool hasMoreElements; + nsCOMPtr controlSupports; + nsCOMPtr control; + while (NS_SUCCEEDED(formControls->HasMoreElements(&hasMoreElements)) && + hasMoreElements) { + rv = formControls->GetNext(getter_AddRefs(controlSupports)); + NS_ENSURE_SUCCESS(rv, rv); + control = do_QueryInterface(controlSupports); + + if (control) + { + PRBool willValidate; + rv = control->GetWillValidate(&willValidate); + NS_ENSURE_SUCCESS(rv, rv); + + if (willValidate) + { + // Every form control that can be checked for validity gets checked. + PRBool validity; + rv = control->CheckValidity(&validity); + NS_ENSURE_SUCCESS(rv, rv); + if (*_retval && !validity) + { + *_retval = PR_FALSE; + } + } + } + } + + return NS_OK; +} + //---------------------------------------------------------------------- // nsFormControlList implementation, this could go away if there were // a lightweight collection implementation somewhere nsFormControlList::nsFormControlList(nsHTMLFormElement* aForm) : mForm(aForm) { } Index: content/html/content/src/nsHTMLInputElement.cpp =================================================================== RCS file: /cvsroot/mozilla/content/html/content/src/nsHTMLInputElement.cpp,v retrieving revision 1.435 diff -p -u -8 -r1.435 nsHTMLInputElement.cpp --- content/html/content/src/nsHTMLInputElement.cpp 18 Jul 2006 19:32:00 -0000 +++ content/html/content/src/nsHTMLInputElement.cpp 24 Jul 2006 04:48:50 -0000 @@ -55,16 +55,19 @@ #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsStyleConsts.h" #include "nsPresContext.h" #include "nsMappedAttributes.h" #include "nsIFormControl.h" #include "nsIForm.h" #include "nsIFormSubmission.h" +#include "nsIDOMWF2FormControl.h" +#include "nsIDOMWF2ValidityState.h" +#include "nsDOMWF2ValidityState.h" #include "nsITextControlFrame.h" #include "nsIRadioControlFrame.h" #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIFormControlFrame.h" #include "nsIFrame.h" #include "nsIEventStateManager.h" #include "nsIServiceManager.h" @@ -142,16 +145,17 @@ static NS_DEFINE_CID(kXULControllersCID, NS_OUTER_ACTIVATE_EVENT | NS_ORIGINAL_CHECKED_VALUE | NS_NO_CONTENT_DISPATCH)) static const char kWhitespace[] = "\n\r\t\b"; class nsHTMLInputElement : public nsGenericHTMLFormElement, public nsImageLoadingContent, public nsIDOMHTMLInputElement, public nsIDOMNSHTMLInputElement, + public nsIDOMWF2FormControl, public nsITextControlElement, public nsIRadioControlElement, public nsIPhonetic, public nsIDOMNSEditableElement, public nsIFileControlElement { public: nsHTMLInputElement(nsINodeInfo *aNodeInfo, PRBool aFromParser); @@ -170,16 +174,19 @@ public: NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::) // nsIDOMHTMLInputElement NS_DECL_NSIDOMHTMLINPUTELEMENT // nsIDOMNSHTMLInputElement NS_DECL_NSIDOMNSHTMLINPUTELEMENT + // nsIDOMWF2FormControl + NS_DECL_NSIDOMWF2FORMCONTROL + // nsIPhonetic NS_DECL_NSIPHONETIC // nsIDOMNSEditableElement NS_FORWARD_NSIDOMNSEDITABLEELEMENT(nsGenericHTMLElement::) // Overriden nsIFormControl methods NS_IMETHOD_(PRInt32) GetType() const { return mType; } @@ -329,16 +336,21 @@ protected: * so that it won't be possible to 'leak' the value from a text-input to a * file-input. Additionally, the logic for this value is kept as simple as * possible to avoid accidental errors where the wrong filename is used. * Therefor the filename is always owned by this member, never by the frame. * Whenever the frame wants to change the filename it has to call * SetFileName to update this member. */ nsAutoPtr mFileName; + + /** + * Validity state object for this control. + */ + nsCOMPtr mValidity; }; #ifdef ACCESSIBILITY //Helper method static nsresult FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget, nsPresContext* aPresContext, const nsAString& aEventType); #endif @@ -352,16 +364,18 @@ NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER nsHTMLInputElement::nsHTMLInputElement(nsINodeInfo *aNodeInfo, PRBool aFromParser) : nsGenericHTMLFormElement(aNodeInfo), mType(NS_FORM_INPUT_TEXT), // default value mBitField(0), mValue(nsnull) { SET_BOOLBIT(mBitField, BF_PARSER_CREATING, aFromParser); + + mValidity = new nsDOMWF2ValidityState(); } nsHTMLInputElement::~nsHTMLInputElement() { DestroyImageLoadingContent(); if (mValue) { nsMemory::Free(mValue); } @@ -374,16 +388,17 @@ NS_IMPL_ADDREF_INHERITED(nsHTMLInputElem NS_IMPL_RELEASE_INHERITED(nsHTMLInputElement, nsGenericElement) // QueryInterface implementation for nsHTMLInputElement NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLInputElement, nsGenericHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLInputElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLInputElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMWF2FormControl) NS_INTERFACE_MAP_ENTRY(nsITextControlElement) NS_INTERFACE_MAP_ENTRY(nsIFileControlElement) NS_INTERFACE_MAP_ENTRY(nsIRadioControlElement) NS_INTERFACE_MAP_ENTRY(nsIPhonetic) NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver) NS_INTERFACE_MAP_ENTRY(nsIImageLoadingContent) NS_INTERFACE_MAP_ENTRY(nsIDOMNSEditableElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLInputElement) @@ -2166,16 +2181,71 @@ FireEventForAccessibility(nsIDOMHTMLInpu nsEventDispatcher::DispatchDOMEvent(aTarget, nsnull, event, aPresContext, nsnull); } return NS_OK; } #endif +// nsIDOMWF2FormControl + +NS_IMETHODIMP +nsHTMLInputElement::GetWillValidate(PRBool *aWillValidate) +{ + *aWillValidate = PR_FALSE; + + if (!mForm) + return NS_OK; + + /* XXX ajvincent No ancestor of this node may be a repetition element or + a datalist element, but those haven't been implemented yet. + */ + + if (!HasAttr(kNameSpaceID_None, nsHTMLAtoms::name)) + return NS_OK; + + if (HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) + return NS_OK; + + if (mType == NS_FORM_INPUT_RESET || mType == NS_FORM_INPUT_BUTTON) + return NS_OK; + + *aWillValidate = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLInputElement::GetValidity(nsIDOMWF2ValidityState * *aValidity) +{ + *aValidity = mValidity; + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLInputElement::CheckValidity(PRBool *_retval) +{ + nsresult rv = mValidity->GetValid(_retval); + if (!_retval) + { + // Dispatch invalid event. +/* + kXMLEventsNameSpaceURI = namespace + kNameSpaceID_XMLEvents + */ + + nsGUIEvent event(PR_TRUE, NS_FORM_INVALID, nsnull); + nsCOMPtr presContext = GetPresContext(); + nsEventStatus status = nsEventStatus_eIgnore; + nsEventDispatcher::Dispatch(NS_STATIC_CAST(nsIContent*, this), presContext, + &event, nsnull, &status); + } + return NS_OK; +} + nsresult nsHTMLInputElement::Reset() { nsresult rv = NS_OK; nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE); switch (mType) { Index: widget/public/nsGUIEvent.h =================================================================== RCS file: /cvsroot/mozilla/widget/public/nsGUIEvent.h,v retrieving revision 3.136 diff -p -u -8 -r3.136 nsGUIEvent.h --- widget/public/nsGUIEvent.h 20 Jul 2006 15:37:23 -0000 3.136 +++ widget/public/nsGUIEvent.h 24 Jul 2006 04:48:52 -0000 @@ -241,16 +241,17 @@ class nsIDOMEvent; #define NS_PAGE_RESTORE (NS_STREAM_EVENT_START + 7) #define NS_FORM_EVENT_START 1200 #define NS_FORM_SUBMIT (NS_FORM_EVENT_START) #define NS_FORM_RESET (NS_FORM_EVENT_START + 1) #define NS_FORM_CHANGE (NS_FORM_EVENT_START + 2) #define NS_FORM_SELECTED (NS_FORM_EVENT_START + 3) #define NS_FORM_INPUT (NS_FORM_EVENT_START + 4) +#define NS_FORM_INVALID (NS_FORM_EVENT_START + 5) //Need separate focus/blur notifications for non-native widgets #define NS_FOCUS_EVENT_START 1300 #define NS_FOCUS_CONTENT (NS_FOCUS_EVENT_START) #define NS_BLUR_CONTENT (NS_FOCUS_EVENT_START + 1) #define NS_DRAGDROP_EVENT_START 1400