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

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

Issue 703473003: Fix bug where form/fieldset :valid/:invalid won't be recalculated upon control's willValidate change (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update a css layout test now that number of SubtreeStyleChange went down Created 6 years, 1 month 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/HTMLFormControlElement.h ('k') | Source/core/html/HTMLFormElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLFormControlElement.cpp
diff --git a/Source/core/html/HTMLFormControlElement.cpp b/Source/core/html/HTMLFormControlElement.cpp
index 02555ac588f08734e86d00d63823419f11815e9e..4b3b2b9dc830c90fffd6c0fe3e6ce3103aa14358 100644
--- a/Source/core/html/HTMLFormControlElement.cpp
+++ b/Source/core/html/HTMLFormControlElement.cpp
@@ -263,27 +263,28 @@ void HTMLFormControlElement::removedFrom(ContainerNode* insertionPoint)
m_hasValidationMessage = false;
m_ancestorDisabledState = AncestorDisabledStateUnknown;
m_dataListAncestorState = Unknown;
+ setNeedsWillValidateCheck();
HTMLElement::removedFrom(insertionPoint);
FormAssociatedElement::removedFrom(insertionPoint);
}
void HTMLFormControlElement::willChangeForm()
{
- formOwnerSetNeedsValidityCheck();
FormAssociatedElement::willChangeForm();
+ formOwnerSetNeedsValidityCheck(ElementRemoval, isValidElement());
}
void HTMLFormControlElement::didChangeForm()
{
- formOwnerSetNeedsValidityCheck();
FormAssociatedElement::didChangeForm();
+ formOwnerSetNeedsValidityCheck(ElementAddition, isValidElement());
}
-void HTMLFormControlElement::formOwnerSetNeedsValidityCheck()
+void HTMLFormControlElement::formOwnerSetNeedsValidityCheck(ValidityRecalcReason reason, bool isValid)
{
HTMLFormElement* form = formOwner();
if (form)
- form->setNeedsValidityCheck();
+ form->setNeedsValidityCheck(reason, isValid);
}
void HTMLFormControlElement::fieldSetAncestorsSetNeedsValidityCheck(Node* node)
@@ -406,12 +407,7 @@ bool HTMLFormControlElement::recalcWillValidate() const
bool HTMLFormControlElement::willValidate() const
{
if (!m_willValidateInitialized || m_dataListAncestorState == Unknown) {
- m_willValidateInitialized = true;
- bool newWillValidate = recalcWillValidate();
- if (m_willValidate != newWillValidate) {
- m_willValidate = newWillValidate;
- const_cast<HTMLFormControlElement*>(this)->setNeedsValidityCheck();
- }
+ const_cast<HTMLFormControlElement*>(this)->setNeedsWillValidateCheck();
} else {
// If the following assertion fails, setNeedsWillValidateCheck() is not
// called correctly when something which changes recalcWillValidate() result
@@ -430,7 +426,10 @@ void HTMLFormControlElement::setNeedsWillValidateCheck()
m_willValidateInitialized = true;
m_willValidate = newWillValidate;
setNeedsValidityCheck();
- setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::Validate));
+ // No need to trigger style recalculation here because
+ // setNeedsValidityCheck() does it in the right away. This relies on
+ // the assumption that valid() is always true if willValidate() is false.
+
if (!m_willValidate)
hideVisibleValidationMessage();
}
@@ -557,14 +556,15 @@ bool HTMLFormControlElement::isValidElement()
void HTMLFormControlElement::setNeedsValidityCheck()
{
bool newIsValid = valid();
- if (willValidate() && newIsValid != m_isValid) {
- formOwnerSetNeedsValidityCheck();
+ bool changed = newIsValid != m_isValid;
+ m_isValid = newIsValid;
+ if (changed) {
+ formOwnerSetNeedsValidityCheck(ElementModification, newIsValid);
fieldSetAncestorsSetNeedsValidityCheck(parentNode());
// Update style for pseudo classes such as :valid :invalid.
pseudoStateChanged(CSSSelector::PseudoValid);
pseudoStateChanged(CSSSelector::PseudoInvalid);
}
- m_isValid = newIsValid;
// Updates only if this control already has a validation message.
if (isValidationMessageVisible()) {
« no previous file with comments | « Source/core/html/HTMLFormControlElement.h ('k') | Source/core/html/HTMLFormElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698