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

Unified Diff: Source/core/html/HTMLFormElement.cpp

Issue 948373002: Revert of Simplify form validation handling (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLFormElement.cpp
diff --git a/Source/core/html/HTMLFormElement.cpp b/Source/core/html/HTMLFormElement.cpp
index c768e3a45852c1c8356a68f31010e80023e80ef0..bcd39c067668885e6dbdb5253fd757f530fd9ea9 100644
--- a/Source/core/html/HTMLFormElement.cpp
+++ b/Source/core/html/HTMLFormElement.cpp
@@ -78,6 +78,7 @@
, m_shouldSubmit(false)
, m_isInResetFunction(false)
, m_wasDemoted(false)
+ , m_invalidControlsCount(0)
, m_pendingAutocompleteEventsQueue(GenericEventQueue::create(this))
{
}
@@ -713,6 +714,31 @@
return 0;
}
+void HTMLFormElement::setNeedsValidityCheck(ValidityRecalcReason reason, bool isValid)
+{
+ bool formWasInvalid = m_invalidControlsCount > 0;
+ switch (reason) {
+ case ElementRemoval:
+ if (!isValid)
+ --m_invalidControlsCount;
+ break;
+ case ElementAddition:
+ if (!isValid)
+ ++m_invalidControlsCount;
+ break;
+ case ElementModification:
+ if (isValid)
+ --m_invalidControlsCount;
+ else
+ ++m_invalidControlsCount;
+ break;
+ }
+ if (formWasInvalid && !m_invalidControlsCount)
+ pseudoStateChanged(CSSSelector::PseudoValid);
+ if (!formWasInvalid && m_invalidControlsCount)
+ pseudoStateChanged(CSSSelector::PseudoInvalid);
+}
+
bool HTMLFormElement::checkValidity()
{
return !checkInvalidControlsAndCollectUnhandled(0, CheckValidityDispatchInvalidEvent);
@@ -720,6 +746,9 @@
bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement>>* unhandledInvalidControls, CheckValidityEventBehavior eventBehavior)
{
+ if (!unhandledInvalidControls && eventBehavior == CheckValidityDispatchNoEvent)
+ return m_invalidControlsCount;
+
RefPtrWillBeRawPtr<HTMLFormElement> protector(this);
// Copy associatedElements because event handlers called from
// HTMLFormControlElement::checkValidity() might change associatedElements.
@@ -732,13 +761,12 @@
for (unsigned i = 0; i < elements.size(); ++i) {
if (elements[i]->form() == this && elements[i]->isFormControlElement()) {
HTMLFormControlElement* control = toHTMLFormControlElement(elements[i].get());
- if (!control->checkValidity(unhandledInvalidControls, eventBehavior) && control->formOwner() == this) {
+ if (!control->checkValidity(unhandledInvalidControls, eventBehavior) && control->formOwner() == this)
++invalidControlsCount;
- if (!unhandledInvalidControls && eventBehavior == CheckValidityDispatchNoEvent)
- return true;
- }
- }
- }
+ }
+ }
+ if (eventBehavior == CheckValidityDispatchNoEvent)
+ ASSERT(invalidControlsCount == m_invalidControlsCount);
return invalidControlsCount;
}
« 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