Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: Source/core/html/HTMLFormElement.cpp

Issue 658063002: Fix the issue where checking a form for :valid/:invalid would trigger invalid events for its elemen… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Pull + small style fixes Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 HTMLElement::trace(visitor); 109 HTMLElement::trace(visitor);
110 } 110 }
111 111
112 bool HTMLFormElement::matchesValidityPseudoClasses() const 112 bool HTMLFormElement::matchesValidityPseudoClasses() const
113 { 113 {
114 return true; 114 return true;
115 } 115 }
116 116
117 bool HTMLFormElement::isValidElement() 117 bool HTMLFormElement::isValidElement()
118 { 118 {
119 return checkValidity(); 119 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchNoEv ent);
120 } 120 }
121 121
122 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style) 122 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style)
123 { 123 {
124 if (!m_wasDemoted) 124 if (!m_wasDemoted)
125 return HTMLElement::rendererIsNeeded(style); 125 return HTMLElement::rendererIsNeeded(style);
126 126
127 ContainerNode* node = parentNode(); 127 ContainerNode* node = parentNode();
128 if (!node || !node->renderer()) 128 if (!node || !node->renderer())
129 return HTMLElement::rendererIsNeeded(style); 129 return HTMLElement::rendererIsNeeded(style);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (submitElement && submitElement->formNoValidate()) 283 if (submitElement && submitElement->formNoValidate())
284 return true; 284 return true;
285 285
286 const FormAssociatedElement::List& elements = associatedElements(); 286 const FormAssociatedElement::List& elements = associatedElements();
287 for (unsigned i = 0; i < elements.size(); ++i) { 287 for (unsigned i = 0; i < elements.size(); ++i) {
288 if (elements[i]->isFormControlElement()) 288 if (elements[i]->isFormControlElement())
289 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage( ); 289 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage( );
290 } 290 }
291 291
292 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvali dControls; 292 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > unhandledInvali dControls;
293 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls)) 293 if (!checkInvalidControlsAndCollectUnhandled(&unhandledInvalidControls, Chec kValidityDispatchInvalidEvent))
294 return true; 294 return true;
295 // Because the form has invalid controls, we abort the form submission and 295 // Because the form has invalid controls, we abort the form submission and
296 // show a validation message on a focusable form control. 296 // show a validation message on a focusable form control.
297 297
298 // Needs to update layout now because we'd like to call isFocusable(), which 298 // Needs to update layout now because we'd like to call isFocusable(), which
299 // has !renderer()->needsLayout() assertion. 299 // has !renderer()->needsLayout() assertion.
300 document().updateLayoutIgnorePendingStylesheets(); 300 document().updateLayoutIgnorePendingStylesheets();
301 301
302 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); 302 RefPtrWillBeRawPtr<HTMLFormElement> protector(this);
303 // Focus on the first focusable control and show a validation message. 303 // Focus on the first focusable control and show a validation message.
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 void HTMLFormElement::setNeedsValidityCheck() 726 void HTMLFormElement::setNeedsValidityCheck()
727 { 727 {
728 // For now unconditionally order style recalculation, which triggers 728 // For now unconditionally order style recalculation, which triggers
729 // validity recalculation. In the near future, implement validity cache and 729 // validity recalculation. In the near future, implement validity cache and
730 // recalculate style only if it changed. 730 // recalculate style only if it changed.
731 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createW ithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Invalid)); 731 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createW ithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Invalid));
732 } 732 }
733 733
734 bool HTMLFormElement::checkValidity() 734 bool HTMLFormElement::checkValidity()
735 { 735 {
736 return !checkInvalidControlsAndCollectUnhandled(0); 736 return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInva lidEvent);
737 } 737 }
738 738
739 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R efPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls) 739 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<R efPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls, CheckValid ityEventBehavior eventBehavior)
740 { 740 {
741 RefPtrWillBeRawPtr<HTMLFormElement> protector(this); 741 RefPtrWillBeRawPtr<HTMLFormElement> protector(this);
742 // Copy associatedElements because event handlers called from 742 // Copy associatedElements because event handlers called from
743 // HTMLFormControlElement::checkValidity() might change associatedElements. 743 // HTMLFormControlElement::checkValidity() might change associatedElements.
744 const FormAssociatedElement::List& associatedElements = this->associatedElem ents(); 744 const FormAssociatedElement::List& associatedElements = this->associatedElem ents();
745 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements; 745 WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> > elements;
746 elements.reserveCapacity(associatedElements.size()); 746 elements.reserveCapacity(associatedElements.size());
747 for (unsigned i = 0; i < associatedElements.size(); ++i) 747 for (unsigned i = 0; i < associatedElements.size(); ++i)
748 elements.append(associatedElements[i]); 748 elements.append(associatedElements[i]);
749 bool hasInvalidControls = false; 749 bool hasInvalidControls = false;
750 for (unsigned i = 0; i < elements.size(); ++i) { 750 for (unsigned i = 0; i < elements.size(); ++i) {
751 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { 751 if (elements[i]->form() == this && elements[i]->isFormControlElement()) {
752 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get()); 752 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get());
753 if (!control->checkValidity(unhandledInvalidControls) && control->fo rmOwner() == this) 753 if (!control->checkValidity(unhandledInvalidControls, eventBehavior) && control->formOwner() == this)
754 hasInvalidControls = true; 754 hasInvalidControls = true;
755 } 755 }
756 } 756 }
757 return hasInvalidControls; 757 return hasInvalidControls;
758 } 758 }
759 759
760 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) 760 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName)
761 { 761 {
762 if (pastName.isEmpty() || !m_pastNamesMap) 762 if (pastName.isEmpty() || !m_pastNamesMap)
763 return 0; 763 return 0;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 } 859 }
860 860
861 void HTMLFormElement::setDemoted(bool demoted) 861 void HTMLFormElement::setDemoted(bool demoted)
862 { 862 {
863 if (demoted) 863 if (demoted)
864 UseCounter::count(document(), UseCounter::DemotedFormElement); 864 UseCounter::count(document(), UseCounter::DemotedFormElement);
865 m_wasDemoted = demoted; 865 m_wasDemoted = demoted;
866 } 866 }
867 867
868 } // namespace 868 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698