Changeset 206534 in webkit


Ignore:
Timestamp:
Sep 28, 2016 12:37:14 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

assignedNodes should include fallback contents when flattened option is set
https://bugs.webkit.org/show_bug.cgi?id=162656

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Rebaselined the tests now that all the test cases are passing.

  • web-platform-tests/shadow-dom/slots-expected.txt:
  • web-platform-tests/shadow-dom/slots-fallback-expected.txt:

Source/WebCore:

Fixed the bug by traversing through fallback contents when there are no assigned nodes.

Tests: imported/w3c/web-platform-tests/shadow-dom/slots.html

imported/w3c/web-platform-tests/shadow-dom/slots-fallback.html

  • html/HTMLSlotElement.cpp:

(WebCore::flattenAssignedNodes):
(WebCore::HTMLSlotElement::assignedNodes):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r206463 r206534  
     12016-09-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        assignedNodes should include fallback contents when flattened option is set
     4        https://bugs.webkit.org/show_bug.cgi?id=162656
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Rebaselined the tests now that all the test cases are passing.
     9
     10        * web-platform-tests/shadow-dom/slots-expected.txt:
     11        * web-platform-tests/shadow-dom/slots-fallback-expected.txt:
     12
    1132016-09-27  Ryosuke Niwa  <rniwa@webkit.org>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-expected.txt

    r206463 r206534  
    33PASS Slots: Slots in closed.
    44PASS Slots: Slots not in a shadow tree.
    5 FAIL Slots: Distributed nooes for Slots not in a shadow tree. assert_array_equals: lengths differ, expected 1 got 0
     5PASS Slots: Distributed nooes for Slots not in a shadow tree.
    66PASS Slots: Name matching
    77PASS Slots: No direct host child.
  • trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-fallback-expected.txt

    r206463 r206534  
    11
    2 FAIL Slots fallback: Basic. assert_array_equals: lengths differ, expected 1 got 0
    3 FAIL Slots fallback: Slots in Slots. assert_array_equals: lengths differ, expected 1 got 0
    4 FAIL Slots fallback: Fallback contents should not be used if a node is assigned. assert_array_equals: lengths differ, expected 1 got 0
    5 FAIL Slots fallback: Slots in Slots: Assinged nodes should be used as fallback contents of another slot assert_array_equals: lengths differ, expected 1 got 0
    6 FAIL Slots fallback: Complex case. assert_array_equals: lengths differ, expected 2 got 0
    7 FAIL Slots fallback: Mutation. Append fallback contents. assert_array_equals: lengths differ, expected 3 got 0
    8 FAIL Slots fallback: Mutation. Remove fallback contents. assert_array_equals: lengths differ, expected 1 got 0
    9 FAIL Slots fallback: Mutation. Assign a node to a slot so that fallback contens are no longer used. assert_array_equals: lengths differ, expected 2 got 0
    10 FAIL Slots fallback: Mutation. Remove an assigned node from a slot so that fallback contens will be used. assert_array_equals: lengths differ, expected 1 got 0
    11 FAIL Slots fallback: Mutation.  Remove a slot which is a fallback content of another slot. assert_array_equals: lengths differ, expected 1 got 0
     2PASS Slots fallback: Basic.
     3PASS Slots fallback: Slots in Slots.
     4PASS Slots fallback: Fallback contents should not be used if a node is assigned.
     5PASS Slots fallback: Slots in Slots: Assinged nodes should be used as fallback contents of another slot
     6PASS Slots fallback: Complex case.
     7PASS Slots fallback: Mutation. Append fallback contents.
     8PASS Slots fallback: Mutation. Remove fallback contents.
     9PASS Slots fallback: Mutation. Assign a node to a slot so that fallback contens are no longer used.
     10PASS Slots fallback: Mutation. Remove an assigned node from a slot so that fallback contens will be used.
     11PASS Slots fallback: Mutation.  Remove a slot which is a fallback content of another slot.
    1212
  • trunk/Source/WebCore/ChangeLog

    r206527 r206534  
     12016-09-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        assignedNodes should include fallback contents when flattened option is set
     4        https://bugs.webkit.org/show_bug.cgi?id=162656
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Fixed the bug by traversing through fallback contents when there are no assigned nodes.
     9
     10        Tests: imported/w3c/web-platform-tests/shadow-dom/slots.html
     11               imported/w3c/web-platform-tests/shadow-dom/slots-fallback.html
     12
     13        * html/HTMLSlotElement.cpp:
     14        (WebCore::flattenAssignedNodes):
     15        (WebCore::HTMLSlotElement::assignedNodes):
     16
    1172016-09-27  Wenson Hsieh  <wenson_hsieh@apple.com>
    218
  • trunk/Source/WebCore/html/HTMLSlotElement.cpp

    r203324 r206534  
    2727#include "HTMLSlotElement.h"
    2828
    29 
    3029#include "Event.h"
    3130#include "EventNames.h"
     
    3332#include "MutationObserver.h"
    3433#include "ShadowRoot.h"
     34#include "Text.h"
    3535
    3636namespace WebCore {
     
    9999}
    100100
    101 static void flattenAssignedNodes(Vector<Node*>& nodes, const Vector<Node*>& assignedNodes)
     101static void flattenAssignedNodes(Vector<Node*>& nodes, const HTMLSlotElement& slot)
    102102{
    103     for (Node* node : assignedNodes) {
    104         if (is<HTMLSlotElement>(*node)) {
    105             if (auto* innerAssignedNodes = downcast<HTMLSlotElement>(*node).assignedNodes())
    106                 flattenAssignedNodes(nodes, *innerAssignedNodes);
    107             continue;
     103    auto* assignedNodes = slot.assignedNodes();
     104    if (!assignedNodes) {
     105        for (Node* child = slot.firstChild(); child; child = child->nextSibling()) {
     106            if (is<HTMLSlotElement>(*child))
     107                flattenAssignedNodes(nodes, downcast<HTMLSlotElement>(*child));
     108            else if (is<Text>(*child) || is<Element>(*child))
     109                nodes.append(child);
    108110        }
    109         nodes.append(node);
     111        return;
     112    }
     113    for (Node* node : *assignedNodes) {
     114        if (is<HTMLSlotElement>(*node))
     115            flattenAssignedNodes(nodes, downcast<HTMLSlotElement>(*node));
     116        else
     117            nodes.append(node);
    110118    }
    111119}
     
    113121Vector<Node*> HTMLSlotElement::assignedNodes(const AssignedNodesOptions& options) const
    114122{
     123    if (options.flatten) {
     124        Vector<Node*> nodes;
     125        flattenAssignedNodes(nodes, *this);
     126        return nodes;
     127    }
    115128    auto* assignedNodes = this->assignedNodes();
    116129    if (!assignedNodes)
    117130        return { };
    118 
    119     if (!options.flatten)
    120         return *assignedNodes;
    121 
    122     Vector<Node*> nodes;
    123     flattenAssignedNodes(nodes, *assignedNodes);
    124     return nodes;
     131    return *assignedNodes;
    125132}
    126133
Note: See TracChangeset for help on using the changeset viewer.