Index: Source/core/html/HTMLFormControlElement.cpp |
diff --git a/Source/core/html/HTMLFormControlElement.cpp b/Source/core/html/HTMLFormControlElement.cpp |
index 6029f3fe1e814339a8d896db5eb0e1bf69de265b..a6a97915f684137cea3bfd027c219301b5628a40 100644 |
--- a/Source/core/html/HTMLFormControlElement.cpp |
+++ b/Source/core/html/HTMLFormControlElement.cpp |
@@ -246,6 +246,13 @@ void HTMLFormControlElement::didMoveToNewDocument(Document& oldDocument) |
HTMLElement::didMoveToNewDocument(oldDocument); |
} |
+void HTMLFormControlElement::setFormOwnerNeedsStyleRecalc() |
keishi
2014/10/03 03:44:13
I think this should be done by the HTMLFormElement
Bartek Nowierski
2014/10/03 06:01:33
Done.
|
+{ |
+ HTMLFormElement* form = formOwner(); |
+ if (form) |
+ form->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Invalid)); |
+} |
+ |
Node::InsertionNotificationRequest HTMLFormControlElement::insertedInto(ContainerNode* insertionPoint) |
{ |
m_ancestorDisabledState = AncestorDisabledStateUnknown; |
@@ -253,11 +260,22 @@ Node::InsertionNotificationRequest HTMLFormControlElement::insertedInto(Containe |
setNeedsWillValidateCheck(); |
HTMLElement::insertedInto(insertionPoint); |
FormAssociatedElement::insertedInto(insertionPoint); |
+ |
+ // Element addition can change validity of the form. |
keishi
2014/10/03 03:44:13
I think you'll find that Blink is light on comment
Bartek Nowierski
2014/10/03 06:01:33
Done.
|
+ // Order form style recalculation (do it at the end to ensure that form |
+ // owner is set). |
+ setFormOwnerNeedsStyleRecalc(); |
+ |
return InsertionDone; |
} |
void HTMLFormControlElement::removedFrom(ContainerNode* insertionPoint) |
{ |
+ // Element removal can definitely change validity of the form. |
+ // Order form style recalculation (do it at the begining to ensure that |
+ // form owner is still set). |
+ setFormOwnerNeedsStyleRecalc(); |
+ |
hideVisibleValidationMessage(); |
m_hasValidationMessage = false; |
m_ancestorDisabledState = AncestorDisabledStateUnknown; |
@@ -469,7 +487,7 @@ ValidationMessageClient* HTMLFormControlElement::validationMessageClient() const |
bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls) |
{ |
- if (!willValidate() || isValidFormControlElement()) |
+ if (!willValidate() || isValidElement()) |
return true; |
// An event handler can deref this object. |
RefPtrWillBeRawPtr<HTMLFormControlElement> protector(this); |
@@ -480,7 +498,7 @@ bool HTMLFormControlElement::checkValidity(WillBeHeapVector<RefPtrWillBeMember<F |
return false; |
} |
-bool HTMLFormControlElement::isValidFormControlElement() |
+bool HTMLFormControlElement::isValidElement() |
{ |
// If the following assertion fails, setNeedsValidityCheck() is not called |
// correctly when something which changes validity is updated. |
@@ -493,6 +511,11 @@ void HTMLFormControlElement::setNeedsValidityCheck() |
bool newIsValid = valid(); |
if (willValidate() && newIsValid != m_isValid) { |
// Update style for pseudo classes such as :valid :invalid. |
+ // A change here could've affected the style of the form itself and |
+ // other form elemetns, so recaluclate the entire form's subtree. |
+ setFormOwnerNeedsStyleRecalc(); |
+ // Then recalculate the element itself (and its subtree), because |
+ // it might not be in the tree of the owner form. |
setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Invalid)); |
} |
m_isValid = newIsValid; |