Title: [279054] trunk
Revision
279054
Author
[email protected]
Date
2021-06-20 03:53:42 -0700 (Sun, 20 Jun 2021)

Log Message

Skip shadow-root creation for input element if it is not necessary
https://bugs.webkit.org/show_bug.cgi?id=227189

Reviewed by Maciej Stachowiak.

Source/WebCore:

Test: fast/forms/checkbox-child-hidden.html

Cherry-pick Chromium optimizations[1,2] for input element and extend the coverage for more types.

Some of input element (e.g. checkbox) do not need to create a shadow-root since they do not have shadow-subtree.
This patch optimizes input element creation by skipping creation of shadow-root for these input types.

Since HTMLTextFormControlElement::childShouldCreateRenderer creates renderer only for children under shadow-root,
we do not need to consider about the case appending an element to checkbox etc. They will not get renderers.

We also replace HTMLInputElement related class' override with final if they are final to make class-hierarchy more explicit
and not to miss the change that needs to be done in the derived classes.

On M1 MBP, this patch improves Speedometer2 by 0.8%.

[1]: https://chromium-review.googlesource.com/c/chromium/src/+/773180
[2]: https://chromium-review.googlesource.com/c/chromium/src/+/826426 (but this is not necessary in WebKit since HTMLTextFormControlElement::childShouldCreateRenderer does the right thing elegantly)

* dom/Element.cpp:
(WebCore::Element::ensureUserAgentShadowRoot):
(WebCore::Element::createUserAgentShadowRoot):
* dom/Element.h:
* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
* html/BaseDateAndTimeInputType.h:
(WebCore::BaseDateAndTimeInputType::BaseDateAndTimeInputType):
* html/ColorInputType.cpp:
(WebCore::ColorInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
* html/ColorInputType.h:
* html/FileInputType.cpp:
(WebCore::FileInputType::FileInputType):
(WebCore::FileInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::create):
(WebCore::HTMLInputElement::createShadowSubtreeAndUpdateInnerTextElementEditability):
(WebCore::HTMLInputElement::updateType): It is possible that shadow root is already created for the previous InputType.
So we should use ensureUserAgentShadowRoot.
(WebCore::HTMLInputElement::initializeInputType): Since this is called at initialization time, we can use createUserAgentShadowRoot
instead of ensureUserAgentShadowRoot.
(WebCore::HTMLInputElement::didAddUserAgentShadowRoot): Deleted. Clean up the logic instead of relying on this callback.
Since HTMLInputElement can replace InputType, while we need to create shadow-subtree when InputType is replaced,
this callback could not be called since shadow-root is already created for the previous InputType. Not relying on this
callback makes the logic much simpler: explicitly create shadow-root and shadow-subtree.
* html/HTMLInputElement.h:
* html/InputType.h:
(WebCore::InputType::needsShadowSubtree const): Since this is in the critical path, we need this super optimized implementation.
Button, checkbox, hidden, image, radio, reset, and submit do not require shadow root.
* html/RangeInputType.cpp:
(WebCore::RangeInputType::RangeInputType):
(WebCore::RangeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
* html/SearchInputType.cpp:
(WebCore::SearchInputType::SearchInputType):
(WebCore::SearchInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::TextFieldInputType):
(WebCore::TextFieldInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):

LayoutTests:

* fast/forms/checkbox-and-pseudo-expected.txt: Added.
* fast/forms/checkbox-and-pseudo.html: Added.
* fast/forms/checkbox-child-hidden-expected.html: Added.
* fast/forms/checkbox-child-hidden.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279053 => 279054)


--- trunk/LayoutTests/ChangeLog	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/LayoutTests/ChangeLog	2021-06-20 10:53:42 UTC (rev 279054)
@@ -1,3 +1,15 @@
+2021-06-20  Yusuke Suzuki  <[email protected]>
+
+        Skip shadow-root creation for input element if it is not necessary
+        https://bugs.webkit.org/show_bug.cgi?id=227189
+
+        Reviewed by Maciej Stachowiak.
+
+        * fast/forms/checkbox-and-pseudo-expected.txt: Added.
+        * fast/forms/checkbox-and-pseudo.html: Added.
+        * fast/forms/checkbox-child-hidden-expected.html: Added.
+        * fast/forms/checkbox-child-hidden.html: Added.
+
 2021-06-19  Darin Adler  <[email protected]>
 
         Fix CSS serialization issues affecting css-counter-styles tests

Added: trunk/LayoutTests/fast/forms/checkbox-and-pseudo.html (0 => 279054)


--- trunk/LayoutTests/fast/forms/checkbox-and-pseudo.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/checkbox-and-pseudo.html	2021-06-20 10:53:42 UTC (rev 279054)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<style>
+input:before {
+  display: block;
+  content: "VISIBLE";
+}
+</style>
+
+<label>
+<input type="checkbox" id="cb">
+</label>
+<script>
+  var checkbox = document.getElementById("cb");
+  checkbox.appendChild(document.createTextNode("Checkbox"));
+</script>

Added: trunk/LayoutTests/fast/forms/checkbox-child-hidden-expected.html (0 => 279054)


--- trunk/LayoutTests/fast/forms/checkbox-child-hidden-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/checkbox-child-hidden-expected.html	2021-06-20 10:53:42 UTC (rev 279054)
@@ -0,0 +1,7 @@
+<!doctype html>
+<!-- Copyright (C) 2021 Google Inc. All rights reserved. -->
+<!-- Copyright (C) 2021 Apple Inc. All rights reserved. -->
+<label>
+<input type="checkbox" id="cb">
+Checkbox
+</label>

Added: trunk/LayoutTests/fast/forms/checkbox-child-hidden.html (0 => 279054)


--- trunk/LayoutTests/fast/forms/checkbox-child-hidden.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/checkbox-child-hidden.html	2021-06-20 10:53:42 UTC (rev 279054)
@@ -0,0 +1,11 @@
+<!doctype html>
+<!-- Copyright (C) 2021 Google Inc. All rights reserved. -->
+<!-- Copyright (C) 2021 Apple Inc. All rights reserved. -->
+<label>
+<input type="checkbox" id="cb">
+Checkbox
+</label>
+<script>
+  var checkbox = document.getElementById("cb");
+  checkbox.appendChild(document.createTextNode("Checkbox"));
+</script>

Modified: trunk/LayoutTests/platform/glib/TestExpectations (279053 => 279054)


--- trunk/LayoutTests/platform/glib/TestExpectations	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/LayoutTests/platform/glib/TestExpectations	2021-06-20 10:53:42 UTC (rev 279054)
@@ -2319,6 +2319,9 @@
 webkit.org/b/227053 fast/canvas/canvas-imageSmoothingEnabled.html [ Failure ]
 webkit.org/b/227053 fast/canvas/canvas-imageSmoothingQuality.html [ Failure ]
 
+# Require expect file for dumped render tree.
+webkit.org/b/227189 fast/forms/checkbox-and-pseudo.html [ Skip ]
+
 # End: Common failures between GTK and WPE.
 
 #////////////////////////////////////////////////////////////////////////////////////////

Added: trunk/LayoutTests/platform/ios/fast/forms/checkbox-and-pseudo-expected.txt (0 => 279054)


--- trunk/LayoutTests/platform/ios/fast/forms/checkbox-and-pseudo-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios/fast/forms/checkbox-and-pseudo-expected.txt	2021-06-20 10:53:42 UTC (rev 279054)
@@ -0,0 +1,14 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x38
+  RenderBlock {HTML} at (0,0) size 800x38
+    RenderBody {BODY} at (8,8) size 784x22
+      RenderInline {LABEL} at (0,0) size 20x19
+        RenderText {#text} at (0,0) size 0x0
+        RenderBlock {INPUT} at (2,3) size 16x16 [bgcolor=#FFFFFF03]
+          RenderBlock (generated) at (0,0) size 16x14
+            RenderText at (0,0) size 41x14
+              text run at (0,0) width 41: "VISIBLE"
+        RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0

Added: trunk/LayoutTests/platform/mac/fast/forms/checkbox-and-pseudo-expected.txt (0 => 279054)


--- trunk/LayoutTests/platform/mac/fast/forms/checkbox-and-pseudo-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/forms/checkbox-and-pseudo-expected.txt	2021-06-20 10:53:42 UTC (rev 279054)
@@ -0,0 +1,14 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x35
+  RenderBlock {HTML} at (0,0) size 800x35
+    RenderBody {BODY} at (8,8) size 784x19
+      RenderInline {LABEL} at (0,0) size 16x18
+        RenderText {#text} at (0,0) size 0x0
+        RenderBlock {INPUT} at (2,4) size 12x12
+          RenderBlock (generated) at (0,0) size 12x13
+            RenderText at (0,0) size 41x13
+              text run at (0,0) width 41: "VISIBLE"
+        RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0

Added: trunk/LayoutTests/platform/win/fast/forms/checkbox-and-pseudo-expected.txt (0 => 279054)


--- trunk/LayoutTests/platform/win/fast/forms/checkbox-and-pseudo-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/win/fast/forms/checkbox-and-pseudo-expected.txt	2021-06-20 10:53:42 UTC (rev 279054)
@@ -0,0 +1,14 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x35
+  RenderBlock {HTML} at (0,0) size 800x35
+    RenderBody {BODY} at (8,8) size 784x19
+      RenderInline {LABEL} at (0,0) size 16x18
+        RenderText {#text} at (0,0) size 0x0
+        RenderBlock {INPUT} at (2,4) size 12x12
+          RenderBlock (generated) at (0,0) size 12x13
+            RenderText at (0,0) size 41x13
+              text run at (0,0) width 41: "VISIBLE"
+        RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (279053 => 279054)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2021-06-20 10:53:42 UTC (rev 279054)
@@ -2164,3 +2164,5 @@
 webgl/2.0.0/conformance2/textures/misc/tex-image-with-bad-args-from-dom-elements.html [ Skip ] # Timeout
 webgl/2.0.0/conformance2/transform_feedback/transform_feedback.html [ Skip ] # Timeout and flaky
 workers/bomb.html [ Skip ] # Timeout
+
+webkit.org/b/227189 fast/forms/checkbox-and-pseudo.html [ Skip ] # Require expect file for dumped render tree.

Modified: trunk/Source/WebCore/ChangeLog (279053 => 279054)


--- trunk/Source/WebCore/ChangeLog	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/ChangeLog	2021-06-20 10:53:42 UTC (rev 279054)
@@ -1,3 +1,67 @@
+2021-06-20  Yusuke Suzuki  <[email protected]>
+
+        Skip shadow-root creation for input element if it is not necessary
+        https://bugs.webkit.org/show_bug.cgi?id=227189
+
+        Reviewed by Maciej Stachowiak.
+
+        Test: fast/forms/checkbox-child-hidden.html
+
+        Cherry-pick Chromium optimizations[1,2] for input element and extend the coverage for more types.
+
+        Some of input element (e.g. checkbox) do not need to create a shadow-root since they do not have shadow-subtree.
+        This patch optimizes input element creation by skipping creation of shadow-root for these input types.
+
+        Since HTMLTextFormControlElement::childShouldCreateRenderer creates renderer only for children under shadow-root,
+        we do not need to consider about the case appending an element to checkbox etc. They will not get renderers.
+
+        We also replace HTMLInputElement related class' override with final if they are final to make class-hierarchy more explicit
+        and not to miss the change that needs to be done in the derived classes.
+
+        On M1 MBP, this patch improves Speedometer2 by 0.8%.
+
+        [1]: https://chromium-review.googlesource.com/c/chromium/src/+/773180
+        [2]: https://chromium-review.googlesource.com/c/chromium/src/+/826426 (but this is not necessary in WebKit since HTMLTextFormControlElement::childShouldCreateRenderer does the right thing elegantly)
+
+        * dom/Element.cpp:
+        (WebCore::Element::ensureUserAgentShadowRoot):
+        (WebCore::Element::createUserAgentShadowRoot):
+        * dom/Element.h:
+        * html/BaseDateAndTimeInputType.cpp:
+        (WebCore::BaseDateAndTimeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
+        * html/BaseDateAndTimeInputType.h:
+        (WebCore::BaseDateAndTimeInputType::BaseDateAndTimeInputType):
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
+        * html/ColorInputType.h:
+        * html/FileInputType.cpp:
+        (WebCore::FileInputType::FileInputType):
+        (WebCore::FileInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::create):
+        (WebCore::HTMLInputElement::createShadowSubtreeAndUpdateInnerTextElementEditability):
+        (WebCore::HTMLInputElement::updateType): It is possible that shadow root is already created for the previous InputType.
+        So we should use ensureUserAgentShadowRoot.
+        (WebCore::HTMLInputElement::initializeInputType): Since this is called at initialization time, we can use createUserAgentShadowRoot
+        instead of ensureUserAgentShadowRoot.
+        (WebCore::HTMLInputElement::didAddUserAgentShadowRoot): Deleted. Clean up the logic instead of relying on this callback.
+        Since HTMLInputElement can replace InputType, while we need to create shadow-subtree when InputType is replaced,
+        this callback could not be called since shadow-root is already created for the previous InputType. Not relying on this
+        callback makes the logic much simpler: explicitly create shadow-root and shadow-subtree.
+        * html/HTMLInputElement.h:
+        * html/InputType.h:
+        (WebCore::InputType::needsShadowSubtree const): Since this is in the critical path, we need this super optimized implementation.
+        Button, checkbox, hidden, image, radio, reset, and submit do not require shadow root.
+        * html/RangeInputType.cpp:
+        (WebCore::RangeInputType::RangeInputType):
+        (WebCore::RangeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
+        * html/SearchInputType.cpp:
+        (WebCore::SearchInputType::SearchInputType):
+        (WebCore::SearchInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::TextFieldInputType):
+        (WebCore::TextFieldInputType::createShadowSubtreeAndUpdateInnerTextElementEditability):
+
 2021-06-19  Darin Adler  <[email protected]>
 
         Fix CSS serialization issues affecting css-counter-styles tests

Modified: trunk/Source/WebCore/dom/Element.cpp (279053 => 279054)


--- trunk/Source/WebCore/dom/Element.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/dom/Element.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -2462,6 +2462,12 @@
 {
     if (auto shadow = userAgentShadowRoot())
         return *shadow;
+    return createUserAgentShadowRoot();
+}
+
+ShadowRoot& Element::createUserAgentShadowRoot()
+{
+    ASSERT(!userAgentShadowRoot());
     auto newShadow = ShadowRoot::create(document(), ShadowRootMode::UserAgent);
     ShadowRoot& shadow = newShadow;
     addShadowRoot(WTFMove(newShadow));

Modified: trunk/Source/WebCore/dom/Element.h (279053 => 279054)


--- trunk/Source/WebCore/dom/Element.h	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/dom/Element.h	2021-06-20 10:53:42 UTC (rev 279054)
@@ -306,6 +306,7 @@
 
     RefPtr<ShadowRoot> userAgentShadowRoot() const;
     WEBCORE_EXPORT ShadowRoot& ensureUserAgentShadowRoot();
+    WEBCORE_EXPORT ShadowRoot& createUserAgentShadowRoot();
 
     void setIsDefinedCustomElement(JSCustomElementInterface&);
     void setIsFailedCustomElement();

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -306,6 +306,7 @@
 
 void BaseDateAndTimeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(ContainerNode::ChildChange::Source source, bool)
 {
+    ASSERT(needsShadowSubtree());
     ASSERT(element());
 
     auto& element = *this->element();

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.h (279053 => 279054)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2021-06-20 10:53:42 UTC (rev 279054)
@@ -60,7 +60,12 @@
         HasMeridiem = 1 << 7,
     };
 
-    BaseDateAndTimeInputType(Type type, HTMLInputElement& element) : InputType(type, element) { }
+    BaseDateAndTimeInputType(Type type, HTMLInputElement& element)
+        : InputType(type, element)
+    {
+        ASSERT(needsShadowSubtree());
+    }
+
     ~BaseDateAndTimeInputType();
 
     Decimal parseToNumber(const String&, const Decimal&) const override;

Modified: trunk/Source/WebCore/html/ColorInputType.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/ColorInputType.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/ColorInputType.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -136,6 +136,7 @@
 
 void ColorInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(ContainerNode::ChildChange::Source source, bool)
 {
+    ASSERT(needsShadowSubtree());
     ASSERT(element());
     ASSERT(element()->shadowRoot());
 

Modified: trunk/Source/WebCore/html/ColorInputType.h (279053 => 279054)


--- trunk/Source/WebCore/html/ColorInputType.h	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/ColorInputType.h	2021-06-20 10:53:42 UTC (rev 279054)
@@ -42,7 +42,12 @@
 class ColorInputType final : public BaseClickableWithKeyInputType, private ColorChooserClient {
     template<typename DowncastedType> friend bool isInvalidInputType(const InputType&, const String&);
 public:
-    explicit ColorInputType(HTMLInputElement& element) : BaseClickableWithKeyInputType(Type::Color, element) { }
+    explicit ColorInputType(HTMLInputElement& element)
+        : BaseClickableWithKeyInputType(Type::Color, element)
+    {
+        ASSERT(needsShadowSubtree());
+    }
+
     virtual ~ColorInputType();
 
 private:

Modified: trunk/Source/WebCore/html/FileInputType.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/FileInputType.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/FileInputType.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -109,6 +109,7 @@
     : BaseClickableWithKeyInputType(Type::File, element)
     , m_fileList(FileList::create())
 {
+    ASSERT(needsShadowSubtree());
 }
 
 FileInputType::~FileInputType()
@@ -275,6 +276,7 @@
 
 void FileInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(ContainerNode::ChildChange::Source source, bool)
 {
+    ASSERT(needsShadowSubtree());
     ASSERT(element());
     ASSERT(element()->shadowRoot());
     element()->userAgentShadowRoot()->appendChild(source, element()->multiple() ? UploadButtonElement::createForMultiple(element()->document()): UploadButtonElement::create(element()->document()));

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -2,10 +2,10 @@
  * Copyright (C) 1999 Lars Knoll ([email protected])
  *           (C) 1999 Antti Koivisto ([email protected])
  *           (C) 2001 Dirk Mueller ([email protected])
- * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
  *           (C) 2006 Alexey Proskuryakov ([email protected])
  * Copyright (C) 2007 Samuel Weinig ([email protected])
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Google Inc. All rights reserved.
  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
  *
@@ -84,7 +84,7 @@
 using namespace HTMLNames;
 
 #if ENABLE(DATALIST_ELEMENT)
-class ListAttributeTargetObserver : IdTargetObserver {
+class ListAttributeTargetObserver final : public IdTargetObserver {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     ListAttributeTargetObserver(const AtomString& id, HTMLInputElement*);
@@ -144,8 +144,11 @@
 {
     bool shouldCreateShadowRootLazily = createdByParser;
     Ref<HTMLInputElement> inputElement = adoptRef(*new HTMLInputElement(tagName, document, form, createdByParser));
-    if (!shouldCreateShadowRootLazily)
-        inputElement->ensureUserAgentShadowRoot();
+    if (!shouldCreateShadowRootLazily) {
+        ASSERT(inputElement->m_inputType->needsShadowSubtree());
+        inputElement->createUserAgentShadowRoot();
+        inputElement->createShadowSubtreeAndUpdateInnerTextElementEditability();
+    }
     return inputElement;
 }
 
@@ -156,7 +159,7 @@
     return *m_imageLoader;
 }
 
-void HTMLInputElement::didAddUserAgentShadowRoot(ShadowRoot&)
+void HTMLInputElement::createShadowSubtreeAndUpdateInnerTextElementEditability()
 {
     Ref<InputType> protectedInputType(*m_inputType);
     protectedInputType->createShadowSubtreeAndUpdateInnerTextElementEditability(m_parsingInProgress ? ChildChange::Source::Parser : ChildChange::Source::API, isInnerTextElementEditable());
@@ -575,7 +578,10 @@
     m_inputType->detachFromElement();
 
     m_inputType = WTFMove(newType);
-    m_inputType->createShadowSubtreeAndUpdateInnerTextElementEditability(m_parsingInProgress ? ChildChange::Source::Parser : ChildChange::Source::API, isInnerTextElementEditable());
+    if (m_inputType->needsShadowSubtree()) {
+        ensureUserAgentShadowRoot();
+        createShadowSubtreeAndUpdateInnerTextElementEditability();
+    }
 
     updateWillValidateAndValidity();
 
@@ -728,7 +734,9 @@
     const AtomString& type = attributeWithoutSynchronization(typeAttr);
     if (type.isNull()) {
         m_inputType = InputType::createText(*this);
-        ensureUserAgentShadowRoot();
+        ASSERT(m_inputType->needsShadowSubtree());
+        createUserAgentShadowRoot();
+        createShadowSubtreeAndUpdateInnerTextElementEditability();
         updateWillValidateAndValidity();
         return;
     }
@@ -735,7 +743,10 @@
 
     m_hasType = true;
     m_inputType = InputType::create(*this, type);
-    ensureUserAgentShadowRoot();
+    if (m_inputType->needsShadowSubtree()) {
+        createUserAgentShadowRoot();
+        createShadowSubtreeAndUpdateInnerTextElementEditability();
+    }
     updateWillValidateAndValidity();
     registerForSuspensionCallbackIfNeeded();
     runPostTypeUpdateTasks();

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (279053 => 279054)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2021-06-20 10:53:42 UTC (rev 279054)
@@ -136,7 +136,7 @@
     HTMLElement* containerElement() const;
     
     RefPtr<TextControlInnerTextElement> innerTextElement() const final;
-    RenderStyle createInnerTextStyle(const RenderStyle&) override;
+    RenderStyle createInnerTextStyle(const RenderStyle&) final;
 
     HTMLElement* innerBlockElement() const;
     HTMLElement* innerSpinButtonElement() const;
@@ -269,7 +269,7 @@
     void addSearchResult();
     void onSearch();
 
-    bool willRespondToMouseClickEvents() override;
+    bool willRespondToMouseClickEvents() final;
 
 #if ENABLE(DATALIST_ELEMENT)
     WEBCORE_EXPORT RefPtr<HTMLElement> list() const;
@@ -348,13 +348,11 @@
 protected:
     HTMLInputElement(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser);
 
-    void defaultEventHandler(Event&) override;
+    void defaultEventHandler(Event&) final;
 
 private:
     enum AutoCompleteSetting { Uninitialized, On, Off };
 
-    void didAddUserAgentShadowRoot(ShadowRoot&) final;
-
     void willChangeForm() final;
     void didChangeForm() final;
     InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) final;
@@ -362,6 +360,8 @@
     void removedFromAncestor(RemovalType, ContainerNode&) final;
     void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
+    void createShadowSubtreeAndUpdateInnerTextElementEditability();
+
     int defaultTabIndex() const final;
     bool hasCustomFocusLogic() const final;
     bool isKeyboardFocusable(KeyboardEvent*) const final;

Modified: trunk/Source/WebCore/html/InputType.h (279053 => 279054)


--- trunk/Source/WebCore/html/InputType.h	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/InputType.h	2021-06-20 10:53:42 UTC (rev 279054)
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Google Inc. All rights reserved.
+ * Copyright (C) 2011-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -144,6 +144,16 @@
         Type::Reset,
     };
 
+    static constexpr OptionSet<Type> nonShadowRootTypes = {
+        Type::Button,
+        Type::Checkbox,
+        Type::Hidden,
+        Type::Image,
+        Type::Radio,
+        Type::Reset,
+        Type::Submit,
+    };
+
     static Ref<InputType> create(HTMLInputElement&, const AtomString&);
     static Ref<InputType> createText(HTMLInputElement&);
     virtual ~InputType();
@@ -195,6 +205,7 @@
     bool isInteractiveContent() const;
     bool supportLabels() const;
     bool isEnumeratable() const;
+    bool needsShadowSubtree() const { return !nonShadowRootTypes.contains(m_type); }
 
     // Form value functions.
 

Modified: trunk/Source/WebCore/html/RangeInputType.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/RangeInputType.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/RangeInputType.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -82,6 +82,7 @@
 RangeInputType::RangeInputType(HTMLInputElement& element)
     : InputType(Type::Range, element)
 {
+    ASSERT(needsShadowSubtree());
 }
 
 const AtomString& RangeInputType::formControlType() const
@@ -244,6 +245,7 @@
 
 void RangeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(ContainerNode::ChildChange::Source source, bool)
 {
+    ASSERT(needsShadowSubtree());
     ASSERT(element());
     ASSERT(element()->userAgentShadowRoot());
 

Modified: trunk/Source/WebCore/html/SearchInputType.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/SearchInputType.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/SearchInputType.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -48,6 +48,7 @@
     : BaseTextInputType(Type::Search, element)
     , m_searchEventTimer(*this, &SearchInputType::searchEventTimerFired)
 {
+    ASSERT(needsShadowSubtree());
 }
 
 void SearchInputType::addSearchResult()
@@ -104,6 +105,7 @@
 
 void SearchInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(ContainerNode::ChildChange::Source source, bool isInnerTextElementEditable)
 {
+    ASSERT(needsShadowSubtree());
     ASSERT(!m_resultsButton);
     ASSERT(!m_cancelButton);
 

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (279053 => 279054)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2021-06-20 09:48:03 UTC (rev 279053)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2021-06-20 10:53:42 UTC (rev 279054)
@@ -75,6 +75,7 @@
 TextFieldInputType::TextFieldInputType(Type type, HTMLInputElement& element)
     : InputType(type, element)
 {
+    ASSERT(needsShadowSubtree());
 }
 
 TextFieldInputType::~TextFieldInputType()
@@ -316,6 +317,7 @@
 
 void TextFieldInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(ContainerNode::ChildChange::Source source, bool isInnerTextElementEditable)
 {
+    ASSERT(needsShadowSubtree());
     ASSERT(element());
     ASSERT(element()->shadowRoot());
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to