Title: [273388] branches/safari-611-branch/Source/WebCore
Revision
273388
Author
repst...@apple.com
Date
2021-02-24 09:10:03 -0800 (Wed, 24 Feb 2021)

Log Message

Cherry-pick r272354. rdar://problem/74622963

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272354 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-611-branch/Source/WebCore/ChangeLog (273387 => 273388)


--- branches/safari-611-branch/Source/WebCore/ChangeLog	2021-02-24 17:09:38 UTC (rev 273387)
+++ branches/safari-611-branch/Source/WebCore/ChangeLog	2021-02-24 17:10:03 UTC (rev 273388)
@@ -1,3 +1,52 @@
+2021-02-23  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r272354. rdar://problem/74622963
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272354 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-17  Ruben Turcios  <rubent...@apple.com>
 
         Cherry-pick r272626. rdar://problem/74410222

Modified: branches/safari-611-branch/Source/WebCore/html/HTMLFormControlElement.cpp (273387 => 273388)


--- branches/safari-611-branch/Source/WebCore/html/HTMLFormControlElement.cpp	2021-02-24 17:09:38 UTC (rev 273387)
+++ branches/safari-611-branch/Source/WebCore/html/HTMLFormControlElement.cpp	2021-02-24 17:10:03 UTC (rev 273388)
@@ -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: branches/safari-611-branch/Source/WebCore/html/HTMLFormControlElement.h (273387 => 273388)


--- branches/safari-611-branch/Source/WebCore/html/HTMLFormControlElement.h	2021-02-24 17:09:38 UTC (rev 273387)
+++ branches/safari-611-branch/Source/WebCore/html/HTMLFormControlElement.h	2021-02-24 17:10:03 UTC (rev 273388)
@@ -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();
 
@@ -172,6 +173,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; }
@@ -181,6 +185,9 @@
     bool needsMouseFocusableQuirk() const;
 
     std::unique_ptr<ValidationMessage> m_validationMessage;
+    
+    unsigned m_delayedUpdateValidityCount { 0 };
+
     bool m_isFocusingWithValidationMessage { false };
 
     unsigned m_disabled : 1;
@@ -207,6 +214,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: branches/safari-611-branch/Source/WebCore/html/HTMLInputElement.cpp (273387 => 273388)


--- branches/safari-611-branch/Source/WebCore/html/HTMLInputElement.cpp	2021-02-24 17:09:38 UTC (rev 273387)
+++ branches/safari-611-branch/Source/WebCore/html/HTMLInputElement.cpp	2021-02-24 17:10:03 UTC (rev 273388)
@@ -821,6 +821,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