Commit d25fff2a authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

Remove "mini-DSR" and replace with declarative Shadow DOM

Change-Id: Idf58c176a453d6fc64b35fe284ac7a1cd2145dfd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485697
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818829}
parent 364124bb
......@@ -23,16 +23,6 @@ namespace blink {
namespace {
// Copy elements in HTMLCollection into a vector because HTMLCollection is a
// live list and would be invalid if a mutation occurs.
HeapVector<Member<Element>> CollectFromHTMLCollection(
HTMLCollection& collection) {
HeapVector<Member<Element>> elements;
for (Element* element : collection)
elements.push_back(element);
return elements;
}
template <class T>
HeapVector<Member<Node>> CollectFromIterable(T iterable) {
HeapVector<Member<Node>> nodes;
......@@ -41,31 +31,6 @@ HeapVector<Member<Node>> CollectFromIterable(T iterable) {
return nodes;
}
// Process Mini-DSL for Declarative Shadow DOM.
// In Mini-DSL, <shadowroot> elements would behaves as if it were "Declarative
// Shadow DOM". This is usuful for constructing a composed tree in testing.
// Declarative Shadow DOM is under the dicussion. See
// https://github.com/whatwg/dom/issues/510. Once Declarative Shadow DOM is
// standardized and implemented, this DSL is no longer required.
void ConvertDeclarativeShadowDOMToShadowRoot(Element& element) {
HTMLCollection* shadow_root_collection =
element.getElementsByTagName("shadowroot");
if (!shadow_root_collection)
return;
for (Element* shadow_root :
CollectFromHTMLCollection(*shadow_root_collection)) {
Element* parent = shadow_root->parentElement();
DCHECK(parent);
parent->removeChild(shadow_root);
ShadowRoot& attached_shadow_root =
parent->AttachShadowRootInternal(ShadowRootType::kOpen);
for (Node* child :
CollectFromIterable(NodeTraversal::ChildrenOf(*shadow_root)))
attached_shadow_root.AppendChild(child);
}
}
void RemoveWhiteSpaceOnlyTextNode(ContainerNode& container) {
for (Node* descendant :
CollectFromIterable(NodeTraversal::InclusiveDescendantsOf(container))) {
......@@ -105,14 +70,13 @@ void SlotAssignmentTest::SetUp() {
void SlotAssignmentTest::SetBody(const char* html) {
Element* body = GetDocument().body();
body->setInnerHTML(String::FromUTF8(html));
ConvertDeclarativeShadowDOMToShadowRoot(*body);
RemoveWhiteSpaceOnlyTextNode(*body);
}
TEST_F(SlotAssignmentTest, DeclarativeShadowDOM) {
SetBody(R"HTML(
<div id=host>
<shadowroot></shadowroot>
<template shadowroot=open></template>
</div>
)HTML");
......@@ -124,11 +88,11 @@ TEST_F(SlotAssignmentTest, DeclarativeShadowDOM) {
TEST_F(SlotAssignmentTest, NestedDeclarativeShadowDOM) {
SetBody(R"HTML(
<div id=host1>
<shadowroot>
<template shadowroot=open>
<div id=host2>
<shadowroot></shadowroot>
<template shadowroot=open></template>
</div>
</shadowroot>
</template>
</div>
)HTML");
......@@ -146,9 +110,9 @@ TEST_F(SlotAssignmentTest, NestedDeclarativeShadowDOM) {
TEST_F(SlotAssignmentTest, AssignedNodesAreSet) {
SetBody(R"HTML(
<div id=host>
<shadowroot>
<template shadowroot=open>
<slot></slot>
</shadowroot>
</template>
<div id='host-child'></div>
</div>
)HTML");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment