Changeset 190084 in webkit


Ignore:
Timestamp:
Sep 21, 2015 3:27:28 PM (9 years ago)
Author:
Antti Koivisto
Message:

HTMLSlotElement should render its assigned nodes
https://bugs.webkit.org/show_bug.cgi?id=149242

Reviewed by Ryosuke Niwa.

Source/WebCore:

Support rendering the assigned nodes under HTMLSlotElement.

  • dom/SlotAssignment.cpp:

(WebCore::SlotAssignment::assignSlots):

Move the empty slot finding to the loop as the hash table may mutate.

  • html/HTMLSlotElement.cpp:

(WebCore::HTMLSlotElement::attributeChanged):
(WebCore::HTMLSlotElement::assignedNodes):
(WebCore::HTMLSlotElement::getDistributedNodes):

  • html/HTMLSlotElement.h:
  • style/StyleResolveTree.cpp:

(WebCore::Style::attachBeforeOrAfterPseudoElementIfNeeded):
(WebCore::Style::attachSlot):
(WebCore::Style::attachRenderTree):
(WebCore::Style::detachChildren):
(WebCore::Style::detachShadowRoot):
(WebCore::Style::detachSlot):
(WebCore::Style::detachRenderTree):
(WebCore::Style::resolveChildren):
(WebCore::Style::resolveSlot):
(WebCore::Style::resolveTree):

LayoutTests:

Enable the relevant tests.

  • platform/mac/TestExpectations:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190081 r190084  
     12015-09-21  Antti Koivisto  <antti@apple.com>
     2
     3        HTMLSlotElement should render its assigned nodes
     4        https://bugs.webkit.org/show_bug.cgi?id=149242
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Enable the relevant tests.
     9
     10        * platform/mac/TestExpectations:
     11
    1122015-09-21  Alex Christensen  <achristensen@webkit.org>
    213
  • trunk/LayoutTests/platform/mac/TestExpectations

    r190074 r190084  
    13041304
    13051305webkit.org/b/148695 fast/shadow-dom [ Pass ]
    1306 webkit.org/b/149242 fast/shadow-dom/css-scoping-shadow-slot.html [ ImageOnlyFailure ]
    1307 webkit.org/b/149242 fast/shadow-dom/css-scoping-shadow-invisible-slot.html [ ImageOnlyFailure ]
    13081306webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-with-rules.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r190079 r190084  
     12015-09-21  Antti Koivisto  <antti@apple.com>
     2
     3        HTMLSlotElement should render its assigned nodes
     4        https://bugs.webkit.org/show_bug.cgi?id=149242
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Support rendering the assigned nodes under HTMLSlotElement.
     9
     10        * dom/SlotAssignment.cpp:
     11        (WebCore::SlotAssignment::assignSlots):
     12
     13            Move the empty slot finding to the loop as the hash table may mutate.
     14
     15        * html/HTMLSlotElement.cpp:
     16        (WebCore::HTMLSlotElement::attributeChanged):
     17        (WebCore::HTMLSlotElement::assignedNodes):
     18        (WebCore::HTMLSlotElement::getDistributedNodes):
     19        * html/HTMLSlotElement.h:
     20        * style/StyleResolveTree.cpp:
     21        (WebCore::Style::attachBeforeOrAfterPseudoElementIfNeeded):
     22        (WebCore::Style::attachSlot):
     23        (WebCore::Style::attachRenderTree):
     24        (WebCore::Style::detachChildren):
     25        (WebCore::Style::detachShadowRoot):
     26        (WebCore::Style::detachSlot):
     27        (WebCore::Style::detachRenderTree):
     28        (WebCore::Style::resolveChildren):
     29        (WebCore::Style::resolveSlot):
     30        (WebCore::Style::resolveTree):
     31
    1322015-09-21  Tim Horton  <timothy_horton@apple.com>
    233
  • trunk/Source/WebCore/dom/SlotAssignment.cpp

    r189950 r190084  
    176176        entry.value->assignedNodes.shrink(0);
    177177
    178     auto defaultSlotEntry = m_slots.find(emptyAtom);
    179 
    180178    for (Node* child = host->firstChild(); child; child = child->nextSibling()) {
    181179        if (is<Element>(child)) {
     
    187185            }
    188186        }
     187        auto defaultSlotEntry = m_slots.find(emptyAtom);
    189188        if (defaultSlotEntry != m_slots.end())
    190189            defaultSlotEntry->value->assignedNodes.append(child);
  • trunk/Source/WebCore/html/HTMLSlotElement.cpp

    r190008 r190084  
    8686}
    8787
     88const Vector<Node*>* HTMLSlotElement::assignedNodes() const
     89{
     90    auto* shadowRoot = containingShadowRoot();
     91    if (!shadowRoot)
     92        return nullptr;
     93
     94    return shadowRoot->assignedNodesForSlot(*this);
     95}
     96
    8897Vector<RefPtr<Node>> HTMLSlotElement::getDistributedNodes() const
    8998{
    9099    Vector<RefPtr<Node>> distributedNodes;
    91100
    92     if (auto shadowRoot = containingShadowRoot()) {
    93         if (auto assignedNodes = shadowRoot->assignedNodesForSlot(*this)) {
    94             for (auto* node : *assignedNodes)
    95                 distributedNodes.append(node);
    96         }
     101    if (auto* assignedNodes = this->assignedNodes()) {
     102        for (auto* node : *assignedNodes)
     103            distributedNodes.append(node);
    97104    }
    98105
  • trunk/Source/WebCore/html/HTMLSlotElement.h

    r189950 r190084  
    3737    static Ref<HTMLSlotElement> create(const QualifiedName&, Document&);
    3838
     39    const Vector<Node*>* assignedNodes() const;
     40
    3941    Vector<RefPtr<Node>> getDistributedNodes() const;
    4042
  • trunk/Source/WebCore/style/StyleResolveTree.cpp

    r190006 r190084  
    3333#include "ElementRareData.h"
    3434#include "FlowThreadController.h"
     35#include "HTMLSlotElement.h"
    3536#include "InsertionPoint.h"
    3637#include "InspectorInstrumentation.h"
     
    469470}
    470471
     472#if ENABLE(SHADOW_DOM)
     473static void attachSlotAssignees(HTMLSlotElement& slot, RenderStyle& inheritedStyle, RenderTreePosition& renderTreePosition)
     474{
     475    if (auto* assignedNodes = slot.assignedNodes()) {
     476        for (auto* child : *assignedNodes) {
     477            if (is<Text>(*child))
     478                attachTextRenderer(downcast<Text>(*child), renderTreePosition);
     479            else if (is<Element>(*child))
     480                attachRenderTree(downcast<Element>(*child), inheritedStyle, renderTreePosition, nullptr);
     481        }
     482    }
     483    slot.clearNeedsStyleRecalc();
     484    slot.clearChildNeedsStyleRecalc();
     485}
     486#endif
     487
    471488static void attachRenderTree(Element& current, RenderStyle& inheritedStyle, RenderTreePosition& renderTreePosition, PassRefPtr<RenderStyle> resolvedStyle)
    472489{
     
    474491    WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
    475492
     493#if ENABLE(SHADOW_DOM)
     494    if (is<HTMLSlotElement>(current)) {
     495        attachSlotAssignees(downcast<HTMLSlotElement>(current), inheritedStyle, renderTreePosition);
     496        return;
     497    }
     498#endif
    476499    if (is<InsertionPoint>(current)) {
    477500        attachDistributedChildren(downcast<InsertionPoint>(current), inheritedStyle, renderTreePosition);
     
    533556static void detachChildren(ContainerNode& current, DetachType detachType)
    534557{
    535     if (is<InsertionPoint>(current))
    536         detachDistributedChildren(downcast<InsertionPoint>(current));
    537 
    538558    for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
    539         if (is<Text>(*child)) {
    540             Style::detachTextRenderer(downcast<Text>(*child));
    541             continue;
    542         }
    543         if (is<Element>(*child))
     559        if (is<Text>(*child))
     560            detachTextRenderer(downcast<Text>(*child));
     561        else if (is<Element>(*child))
    544562            detachRenderTree(downcast<Element>(*child), detachType);
    545563    }
     
    551569    detachChildren(shadowRoot, detachType);
    552570}
     571
     572#if ENABLE(SHADOW_DOM)
     573static void detachSlotAssignees(HTMLSlotElement& slot, DetachType detachType)
     574{
     575    ASSERT(!slot.renderer());
     576    if (auto* assignedNodes = slot.assignedNodes()) {
     577        for (auto* child : *assignedNodes) {
     578            if (is<Text>(*child))
     579                detachTextRenderer(downcast<Text>(*child));
     580            else if (is<Element>(*child))
     581                detachRenderTree(downcast<Element>(*child), detachType);
     582        }
     583    }
     584    slot.clearNeedsStyleRecalc();
     585    slot.clearChildNeedsStyleRecalc();
     586}
     587#endif
    553588
    554589static void detachRenderTree(Element& current, DetachType detachType)
     
    566601        current.clearHoverAndActiveStatusBeforeDetachingRenderer();
    567602
    568     if (ShadowRoot* shadowRoot = current.shadowRoot())
     603    if (is<InsertionPoint>(current))
     604        detachDistributedChildren(downcast<InsertionPoint>(current));
     605#if ENABLE(SHADOW_DOM)
     606    else if (is<HTMLSlotElement>(current))
     607        detachSlotAssignees(downcast<HTMLSlotElement>(current), detachType);
     608#endif
     609    else if (ShadowRoot* shadowRoot = current.shadowRoot())
    569610        detachShadowRoot(*shadowRoot, detachType);
    570611
     
    799840}
    800841
     842#if ENABLE(SHADOW_DOM)
     843static void resolveSlotAssignees(HTMLSlotElement& slot, RenderStyle& inheritedStyle, RenderTreePosition& renderTreePosition, Change change)
     844{
     845    if (auto* assignedNodes = slot.assignedNodes()) {
     846        for (auto* child : *assignedNodes) {
     847            if (is<Text>(*child))
     848                resolveTextNode(downcast<Text>(*child), renderTreePosition);
     849            else if (is<Element>(*child))
     850                resolveTree(downcast<Element>(*child), inheritedStyle, renderTreePosition, change);
     851        }
     852    }
     853    slot.clearNeedsStyleRecalc();
     854    slot.clearChildNeedsStyleRecalc();
     855}
     856#endif
     857
    801858void resolveTree(Element& current, RenderStyle& inheritedStyle, RenderTreePosition& renderTreePosition, Change change)
    802859{
    803860    ASSERT(change != Detach);
    804861
     862#if ENABLE(SHADOW_DOM)
     863    if (is<HTMLSlotElement>(current)) {
     864        resolveSlotAssignees(downcast<HTMLSlotElement>(current), inheritedStyle, renderTreePosition, change);
     865        return;
     866    }
     867#endif
    805868    if (is<InsertionPoint>(current)) {
    806869        current.clearNeedsStyleRecalc();
Note: See TracChangeset for help on using the changeset viewer.