- Revision
- 235535
- Author
- [email protected]
- Date
- 2018-08-30 19:26:26 -0700 (Thu, 30 Aug 2018)
Log Message
Add assignedElements to HTMLSlotElement
https://bugs.webkit.org/show_bug.cgi?id=189146
Reviewed by Darin Adler.
LayoutTests/imported/w3c:
Rebaselined the tests now that we're passing all test cases.
* web-platform-tests/shadow-dom/slots-expected.txt:
* web-platform-tests/shadow-dom/slots-fallback-expected.txt:
Source/WebCore:
Added assignedElements to HTMLSlotElement. For now, we simply filter the results returned by assignedNodes.
Also fixed a bug that assignedNodes was returning the fallback content when the slot is not in a shadow tree,
which is specified in step 2 of the concept to find flattened slotables for a slot.
Spec: https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignedelements
https://dom.spec.whatwg.org/#find-flattened-slotables
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): Updated to take Vector<Ref<Node>> for consistency.
(WebCore::HTMLSlotElement::assignedNodes const): Ditto.
(WebCore::HTMLSlotElement::assignedElements const):
* html/HTMLSlotElement.h:
* html/HTMLSlotElement.idl:
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (235534 => 235535)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2018-08-31 02:26:26 UTC (rev 235535)
@@ -1,3 +1,15 @@
+2018-08-30 Ryosuke Niwa <[email protected]>
+
+ Add assignedElements to HTMLSlotElement
+ https://bugs.webkit.org/show_bug.cgi?id=189146
+
+ Reviewed by Darin Adler.
+
+ Rebaselined the tests now that we're passing all test cases.
+
+ * web-platform-tests/shadow-dom/slots-expected.txt:
+ * web-platform-tests/shadow-dom/slots-fallback-expected.txt:
+
2018-08-30 Andy Estes <[email protected]>
[Payment Request] Implement the PaymentMethodChangeEvent and PaymentMethodChangeEventInit interfaces
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-expected.txt (235534 => 235535)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-expected.txt 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-expected.txt 2018-08-31 02:26:26 UTC (rev 235535)
@@ -1,11 +1,11 @@
PASS Slots: Basic.
-FAIL Slots: Basic, elements only. n.s1.assignedElements is not a function. (In 'n.s1.assignedElements()', 'n.s1.assignedElements' is undefined)
+PASS Slots: Basic, elements only.
PASS Slots: Slots in closed.
-FAIL Slots: Slots in closed, elements only. n.s1.assignedElements is not a function. (In 'n.s1.assignedElements()', 'n.s1.assignedElements' is undefined)
+PASS Slots: Slots in closed, elements only.
PASS Slots: Slots not in a shadow tree.
-FAIL Slots: Slots not in a shadow tree, elements only. n.s1.assignedElements is not a function. (In 'n.s1.assignedElements()', 'n.s1.assignedElements' is undefined)
-FAIL Slots: Distributed nodes for Slots not in a shadow tree. assert_array_equals: lengths differ, expected 0 got 1
+PASS Slots: Slots not in a shadow tree, elements only.
+PASS Slots: Distributed nodes for Slots not in a shadow tree.
PASS Slots: Name matching
PASS Slots: No direct host child.
PASS Slots: Default Slot.
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-fallback-expected.txt (235534 => 235535)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-fallback-expected.txt 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-fallback-expected.txt 2018-08-31 02:26:26 UTC (rev 235535)
@@ -1,15 +1,15 @@
PASS Slots fallback: Basic.
-FAIL Slots fallback: Basic, elements only. n.s1.assignedElements is not a function. (In 'n.s1.assignedElements()', 'n.s1.assignedElements' is undefined)
+PASS Slots fallback: Basic, elements only.
PASS Slots fallback: Slots in Slots.
-FAIL Slots fallback: Slots in Slots, elements only. n.s1.assignedElements is not a function. (In 'n.s1.assignedElements()', 'n.s1.assignedElements' is undefined)
+PASS Slots fallback: Slots in Slots, elements only.
PASS Slots fallback: Fallback contents should not be used if a node is assigned.
PASS Slots fallback: Slots in Slots: Assigned nodes should be used as fallback contents of another slot
PASS Slots fallback: Complex case.
-FAIL Slots fallback: Complex case, elements only. n.s1.assignedElements is not a function. (In 'n.s1.assignedElements()', 'n.s1.assignedElements' is undefined)
+PASS Slots fallback: Complex case, elements only.
PASS Slots fallback: Mutation. Append fallback contents.
PASS Slots fallback: Mutation. Remove fallback contents.
PASS Slots fallback: Mutation. Assign a node to a slot so that fallback contens are no longer used.
PASS Slots fallback: Mutation. Remove an assigned node from a slot so that fallback contens will be used.
-FAIL Slots fallback: Mutation. Remove a slot which is a fallback content of another slot. assert_array_equals: fall back contents should be empty because s1 is not in a shadow tree. lengths differ, expected 0 got 1
+PASS Slots fallback: Mutation. Remove a slot which is a fallback content of another slot.
Modified: trunk/Source/WebCore/ChangeLog (235534 => 235535)
--- trunk/Source/WebCore/ChangeLog 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/Source/WebCore/ChangeLog 2018-08-31 02:26:26 UTC (rev 235535)
@@ -1,3 +1,28 @@
+2018-08-30 Ryosuke Niwa <[email protected]>
+
+ Add assignedElements to HTMLSlotElement
+ https://bugs.webkit.org/show_bug.cgi?id=189146
+
+ Reviewed by Darin Adler.
+
+ Added assignedElements to HTMLSlotElement. For now, we simply filter the results returned by assignedNodes.
+
+ Also fixed a bug that assignedNodes was returning the fallback content when the slot is not in a shadow tree,
+ which is specified in step 2 of the concept to find flattened slotables for a slot.
+
+ Spec: https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignedelements
+ https://dom.spec.whatwg.org/#find-flattened-slotables
+
+ 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): Updated to take Vector<Ref<Node>> for consistency.
+ (WebCore::HTMLSlotElement::assignedNodes const): Ditto.
+ (WebCore::HTMLSlotElement::assignedElements const):
+ * html/HTMLSlotElement.h:
+ * html/HTMLSlotElement.idl:
+
2018-08-30 Don Olmstead <[email protected]>
[CMake] Replace AVFoundationSupport.py using CMake
Modified: trunk/Source/WebCore/html/HTMLSlotElement.cpp (235534 => 235535)
--- trunk/Source/WebCore/html/HTMLSlotElement.cpp 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/Source/WebCore/html/HTMLSlotElement.cpp 2018-08-31 02:26:26 UTC (rev 235535)
@@ -106,7 +106,7 @@
return shadowRoot->assignedNodesForSlot(*this);
}
-static void flattenAssignedNodes(Vector<Node*>& nodes, const HTMLSlotElement& slot)
+static void flattenAssignedNodes(Vector<Ref<Node>>& nodes, const HTMLSlotElement& slot)
{
auto* assignedNodes = slot.assignedNodes();
if (!assignedNodes) {
@@ -114,7 +114,7 @@
if (is<HTMLSlotElement>(*child))
flattenAssignedNodes(nodes, downcast<HTMLSlotElement>(*child));
else if (is<Text>(*child) || is<Element>(*child))
- nodes.append(child.get());
+ nodes.append(*child);
}
return;
}
@@ -122,14 +122,16 @@
if (is<HTMLSlotElement>(*node))
flattenAssignedNodes(nodes, downcast<HTMLSlotElement>(*node));
else
- nodes.append(node.get());
+ nodes.append(*node);
}
}
-Vector<Node*> HTMLSlotElement::assignedNodes(const AssignedNodesOptions& options) const
+Vector<Ref<Node>> HTMLSlotElement::assignedNodes(const AssignedNodesOptions& options) const
{
if (options.flatten) {
- Vector<Node*> nodes;
+ if (!isInShadowTree())
+ return { };
+ Vector<Ref<Node>> nodes;
flattenAssignedNodes(nodes, *this);
return nodes;
}
@@ -136,9 +138,23 @@
auto* assignedNodes = this->assignedNodes();
if (!assignedNodes)
return { };
- return *assignedNodes;
+ return assignedNodes->map([] (Node* node) { return makeRef(*node); });
}
+Vector<Ref<Element>> HTMLSlotElement::assignedElements(const AssignedNodesOptions& options) const
+{
+ auto nodes = assignedNodes(options);
+
+ Vector<Ref<Element>> elements;
+ elements.reserveCapacity(nodes.size());
+ for (auto& node : nodes) {
+ if (is<Element>(node))
+ elements.uncheckedAppend(static_reference_cast<Element>(WTFMove(node)));
+ }
+
+ return elements;
+}
+
void HTMLSlotElement::enqueueSlotChangeEvent()
{
// https://dom.spec.whatwg.org/#signal-a-slot-change
Modified: trunk/Source/WebCore/html/HTMLSlotElement.h (235534 => 235535)
--- trunk/Source/WebCore/html/HTMLSlotElement.h 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/Source/WebCore/html/HTMLSlotElement.h 2018-08-31 02:26:26 UTC (rev 235535)
@@ -39,7 +39,8 @@
struct AssignedNodesOptions {
bool flatten;
};
- Vector<Node*> assignedNodes(const AssignedNodesOptions&) const;
+ Vector<Ref<Node>> assignedNodes(const AssignedNodesOptions&) const;
+ Vector<Ref<Element>> assignedElements(const AssignedNodesOptions&) const;
void enqueueSlotChangeEvent();
void didRemoveFromSignalSlotList() { m_inSignalSlotList = false; }
Modified: trunk/Source/WebCore/html/HTMLSlotElement.idl (235534 => 235535)
--- trunk/Source/WebCore/html/HTMLSlotElement.idl 2018-08-31 01:03:35 UTC (rev 235534)
+++ trunk/Source/WebCore/html/HTMLSlotElement.idl 2018-08-31 02:26:26 UTC (rev 235535)
@@ -29,6 +29,7 @@
] interface HTMLSlotElement : HTMLElement {
[Reflect] attribute DOMString name;
sequence<Node> assignedNodes(optional AssignedNodesOptions options);
+ sequence<Element> assignedElements(optional AssignedNodesOptions options);
};
dictionary AssignedNodesOptions {