Title: [272354] trunk/Source/WebCore
Revision
272354
Author
simon.fra...@apple.com
Date
2021-02-03 20:09:26 -0800 (Wed, 03 Feb 2021)

Log Message

Avoid frequent calls to HTMLFormControlElement::updateValidity() when constructing form control elements
https://bugs.webkit.org/show_bug.cgi?id=221320

Reviewed by Geoffrey Garen.

HTMLFormControlElement::updateValidity() can get called multiple times inside
HTMLInputElement::parserDidSetAttributes(), so add a simple delaying scope so that
validity is only updated once at the end.

* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::endDelayingUpdateValidity):
(WebCore::HTMLFormControlElement::computeWillValidate const):
(WebCore::HTMLFormControlElement::updateValidity):
* html/HTMLFormControlElement.h:
(WebCore::HTMLFormControlElement::startDelayingUpdateValidity):
(WebCore::DelayedUpdateValidityScope::DelayedUpdateValidityScope):
(WebCore::DelayedUpdateValidityScope::~DelayedUpdateValidityScope):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parserDidSetAttributes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272353 => 272354)


--- trunk/Source/WebCore/ChangeLog	2021-02-04 04:06:19 UTC (rev 272353)
+++ trunk/Source/WebCore/ChangeLog	2021-02-04 04:09:26 UTC (rev 272354)
@@ -1,3 +1,25 @@
+2021-02-03  Simon Fraser  <simon.fra...@apple.com>
+
+        Avoid frequent calls to HTMLFormControlElement::updateValidity() when constructing form control elements
+        https://bugs.webkit.org/show_bug.cgi?id=221320
+
+        Reviewed by Geoffrey Garen.
+
+        HTMLFormControlElement::updateValidity() can get called multiple times inside
+        HTMLInputElement::parserDidSetAttributes(), so add a simple delaying scope so that
+        validity is only updated once at the end.
+
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::endDelayingUpdateValidity):
+        (WebCore::HTMLFormControlElement::computeWillValidate const):
+        (WebCore::HTMLFormControlElement::updateValidity):
+        * html/HTMLFormControlElement.h:
+        (WebCore::HTMLFormControlElement::startDelayingUpdateValidity):
+        (WebCore::DelayedUpdateValidityScope::DelayedUpdateValidityScope):
+        (WebCore::DelayedUpdateValidityScope::~DelayedUpdateValidityScope):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::parserDidSetAttributes):
+
 2021-02-03  Jer Noble  <jer.no...@apple.com>
 
         [Cocoa] WebM audio goes out-of-sync or stops playing after a seek

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (272353 => 272354)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2021-02-04 04:06:19 UTC (rev 272353)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2021-02-04 04:09:26 UTC (rev 272354)
@@ -410,12 +410,18 @@
     return willValidate() && !isValidFormControlElement();
 }
 
+void HTMLFormControlElement::endDelayingUpdateValidity()
+{
+    ASSERT(m_delayedUpdateValidityCount);
+    if (!--m_delayedUpdateValidityCount)
+        updateValidity();
+}
+
 bool HTMLFormControlElement::computeWillValidate() const
 {
     if (m_dataListAncestorState == Unknown) {
 #if ENABLE(DATALIST_ELEMENT)
-        m_dataListAncestorState = ancestorsOfType<HTMLDataListElement>(*this).first()
-            ? InsideDataList : NotInsideDataList;
+        m_dataListAncestorState = ancestorsOfType<HTMLDataListElement>(*this).first() ? InsideDataList : NotInsideDataList;
 #else
         m_dataListAncestorState = NotInsideDataList;
 #endif
@@ -576,6 +582,9 @@
 
 void HTMLFormControlElement::updateValidity()
 {
+    if (m_delayedUpdateValidityCount)
+        return;
+
     bool willValidate = this->willValidate();
     bool wasValid = m_isValid;
 

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (272353 => 272354)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2021-02-04 04:06:19 UTC (rev 272353)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2021-02-04 04:09:26 UTC (rev 272354)
@@ -44,6 +44,7 @@
 // unless there is a special reason.
 class HTMLFormControlElement : public LabelableElement, public FormAssociatedElement {
     WTF_MAKE_ISO_ALLOCATED(HTMLFormControlElement);
+    friend class DelayedUpdateValidityScope;
 public:
     virtual ~HTMLFormControlElement();
 
@@ -173,6 +174,9 @@
     bool isValidFormControlElement() const;
 
     bool computeIsDisabledByFieldsetAncestor() const;
+    
+    void startDelayingUpdateValidity() { ++m_delayedUpdateValidityCount; }
+    void endDelayingUpdateValidity();
 
     HTMLElement& asHTMLElement() final { return *this; }
     const HTMLFormControlElement& asHTMLElement() const final { return *this; }
@@ -182,6 +186,9 @@
     bool needsMouseFocusableQuirk() const;
 
     std::unique_ptr<ValidationMessage> m_validationMessage;
+    
+    unsigned m_delayedUpdateValidityCount { 0 };
+
     bool m_isFocusingWithValidationMessage { false };
 
     unsigned m_disabled : 1;
@@ -208,6 +215,24 @@
     unsigned m_hasAutofocused : 1;
 };
 
+class DelayedUpdateValidityScope {
+public:
+    DelayedUpdateValidityScope(HTMLFormControlElement& element)
+        : m_element(element)
+    {
+        m_element.startDelayingUpdateValidity();
+    }
+    
+    ~DelayedUpdateValidityScope()
+    {
+        m_element.endDelayingUpdateValidity();
+    }
+
+private:
+    HTMLFormControlElement& m_element;
+};
+
+
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLFormControlElement)

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (272353 => 272354)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-02-04 04:06:19 UTC (rev 272353)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-02-04 04:09:26 UTC (rev 272354)
@@ -822,6 +822,8 @@
 
 void HTMLInputElement::parserDidSetAttributes()
 {
+    DelayedUpdateValidityScope delayedUpdateValidityScope(*this);
+
     ASSERT(m_parsingInProgress);
     initializeInputType();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to