Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / html / HTMLSummaryElement.cpp
index 8b5c187..13d3cf4 100644 (file)
 #include "DetailsMarkerControl.h"
 #include "HTMLDetailsElement.h"
 #include "HTMLFormControlElement.h"
-#include "InsertionPoint.h"
+#include "HTMLSlotElement.h"
 #include "KeyboardEvent.h"
 #include "MouseEvent.h"
-#include "NodeRenderingTraversal.h"
 #include "PlatformMouseEvent.h"
 #include "RenderBlockFlow.h"
+#include "ShadowRoot.h"
 
 namespace WebCore {
 
 using namespace HTMLNames;
 
-class SummaryContentElement final : public InsertionPoint {
-public:
-    static Ref<SummaryContentElement> create(Document&);
-
-private:
-    SummaryContentElement(Document& document)
-        : InsertionPoint(webkitShadowContentTag, document)
-    {
-    }
-};
-
-Ref<SummaryContentElement> SummaryContentElement::create(Document& document)
-{
-    return adoptRef(*new SummaryContentElement(document));
-}
-
 Ref<HTMLSummaryElement> HTMLSummaryElement::create(const QualifiedName& tagName, Document& document)
 {
     Ref<HTMLSummaryElement> summary = adoptRef(*new HTMLSummaryElement(tagName, document));
-    summary->ensureUserAgentShadowRoot();
+    summary->addShadowRoot(ShadowRoot::create(document, ShadowRoot::Type::UserAgent));
     return summary;
 }
 
@@ -67,37 +51,33 @@ HTMLSummaryElement::HTMLSummaryElement(const QualifiedName& tagName, Document& d
 
 RenderPtr<RenderElement> HTMLSummaryElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
 {
-    return createRenderer<RenderBlockFlow>(*this, WTF::move(style));
-}
-
-bool HTMLSummaryElement::childShouldCreateRenderer(const Node& child) const
-{
-    if (child.isPseudoElement())
-        return HTMLElement::childShouldCreateRenderer(child);
-
-    return hasShadowRootOrActiveInsertionPointParent(child) && HTMLElement::childShouldCreateRenderer(child);
+    return createRenderer<RenderBlockFlow>(*this, WTFMove(style));
 }
 
 void HTMLSummaryElement::didAddUserAgentShadowRoot(ShadowRoot* root)
 {
     root->appendChild(DetailsMarkerControl::create(document()), ASSERT_NO_EXCEPTION);
-    root->appendChild(SummaryContentElement::create(document()), ASSERT_NO_EXCEPTION);
+    root->appendChild(HTMLSlotElement::create(slotTag, document()));
 }
 
 HTMLDetailsElement* HTMLSummaryElement::detailsElement() const
 {
-    Node* mayDetails = NodeRenderingTraversal::parent(this);
-    if (!mayDetails || !mayDetails->hasTagName(detailsTag))
-        return nullptr;
-    return downcast<HTMLDetailsElement>(mayDetails);
+    auto* parent = parentElement();
+    if (parent && is<HTMLDetailsElement>(*parent))
+        return downcast<HTMLDetailsElement>(parent);
+    // Fallback summary element is in the shadow tree.
+    auto* host = shadowHost();
+    if (host && is<HTMLDetailsElement>(*host))
+        return downcast<HTMLDetailsElement>(host);
+    return nullptr;
 }
 
-bool HTMLSummaryElement::isMainSummary() const
+bool HTMLSummaryElement::isActiveSummary() const
 {
-    if (HTMLDetailsElement* details = detailsElement())
-        return details->findMainSummary() == this;
-
-    return false;
+    HTMLDetailsElement* details = detailsElement();
+    if (!details)
+        return false;
+    return details->isActiveSummary(*this);
 }
 
 static bool isClickableControl(Node* node)
@@ -114,12 +94,12 @@ static bool isClickableControl(Node* node)
 
 bool HTMLSummaryElement::supportsFocus() const
 {
-    return isMainSummary();
+    return isActiveSummary();
 }
 
 void HTMLSummaryElement::defaultEventHandler(Event* event)
 {
-    if (isMainSummary() && renderer()) {
+    if (isActiveSummary() && renderer()) {
         if (event->type() == eventNames().DOMActivateEvent && !isClickableControl(event->target()->toNode())) {
             if (HTMLDetailsElement* details = detailsElement())
                 details->toggleOpen();
@@ -160,7 +140,7 @@ void HTMLSummaryElement::defaultEventHandler(Event* event)
 
 bool HTMLSummaryElement::willRespondToMouseClickEvents()
 {
-    if (isMainSummary() && renderer())
+    if (isActiveSummary() && renderer())
         return true;
 
     return HTMLElement::willRespondToMouseClickEvents();