Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Unified Diff: Source/core/dom/shadow/ElementShadow.cpp

Issue 59903015: [Shadow DOM]: Empty shadow insertion points should behave like <shadow><content *leftover*></conten… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/shadow/ElementShadow.cpp
diff --git a/Source/core/dom/shadow/ElementShadow.cpp b/Source/core/dom/shadow/ElementShadow.cpp
index 158addd3d0da4180463f8863a020789d291d6a10..249110600fd6d22051ae404d51fa5f4bd6845ab2 100644
--- a/Source/core/dom/shadow/ElementShadow.cpp
+++ b/Source/core/dom/shadow/ElementShadow.cpp
@@ -40,26 +40,34 @@ namespace WebCore {
class DistributionPool {
public:
- explicit DistributionPool(const ContainerNode*);
+ explicit DistributionPool(const ContainerNode&);
+ void clear();
~DistributionPool();
void distributeTo(InsertionPoint*, ElementShadow*);
+ void populateChildren(const ContainerNode&);
private:
- void populateChildren(const ContainerNode*);
void detachNonDistributedNodes();
Vector<Node*, 32> m_nodes;
Vector<bool, 32> m_distributed;
};
-inline DistributionPool::DistributionPool(const ContainerNode* parent)
+inline DistributionPool::DistributionPool(const ContainerNode& parent)
{
- if (parent)
- populateChildren(parent);
+ populateChildren(parent);
}
-inline void DistributionPool::populateChildren(const ContainerNode* parent)
+inline void DistributionPool::clear()
{
- for (Node* child = parent->firstChild(); child; child = child->nextSibling()) {
+ detachNonDistributedNodes();
+ m_nodes.clear();
+ m_distributed.clear();
+}
+
+inline void DistributionPool::populateChildren(const ContainerNode& parent)
+{
+ clear();
+ for (Node* child = parent.firstChild(); child; child = child->nextSibling()) {
if (isActiveInsertionPoint(*child)) {
InsertionPoint* insertionPoint = toInsertionPoint(child);
for (size_t i = 0; i < insertionPoint->size(); ++i)
@@ -255,13 +263,10 @@ const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c
void ElementShadow::distribute()
{
host()->setNeedsStyleRecalc();
-
- const ContainerNode* poolContainer = host();
-
Vector<HTMLShadowElement*, 32> shadowInsertionPoints;
- for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
- DistributionPool pool(poolContainer);
+ DistributionPool pool(*host());
+ for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
HTMLShadowElement* shadowInsertionPoint = 0;
const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendantInsertionPoints();
for (size_t i = 0; i < insertionPoints.size(); ++i) {
@@ -277,9 +282,13 @@ void ElementShadow::distribute()
shadow->setNeedsDistributionRecalc();
}
}
- if (shadowInsertionPoint)
+ if (shadowInsertionPoint) {
shadowInsertionPoints.append(shadowInsertionPoint);
- poolContainer = shadowInsertionPoint;
+ if (shadowInsertionPoint->hasChildNodes())
+ pool.populateChildren(*shadowInsertionPoint);
+ } else if (!root->isOldest()) {
+ pool.clear();
+ }
}
for (size_t i = shadowInsertionPoints.size(); i > 0; --i) {
@@ -292,7 +301,8 @@ void ElementShadow::distribute()
distributeNodeChildrenTo(shadowInsertionPoint, root->olderShadowRoot());
root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot(shadowInsertionPoint);
} else if (root->isOldest()) {
- DistributionPool pool(shadowInsertionPoint);
+ if (shadowInsertionPoint->hasChildNodes())
+ pool.populateChildren(*shadowInsertionPoint);
pool.distributeTo(shadowInsertionPoint, this);
}
if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInsertionPoint))
@@ -308,7 +318,7 @@ void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio
void ElementShadow::distributeNodeChildrenTo(InsertionPoint* insertionPoint, ContainerNode* containerNode)
{
- DistributionPool pool(containerNode);
+ DistributionPool pool(*containerNode);
pool.distributeTo(insertionPoint, this);
}

Powered by Google App Engine
This is Rietveld 408576698