diff options
Diffstat (limited to 'Source/WebCore/html/shadow/ContentDistributor.cpp')
-rw-r--r-- | Source/WebCore/html/shadow/ContentDistributor.cpp | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/Source/WebCore/html/shadow/ContentDistributor.cpp b/Source/WebCore/html/shadow/ContentDistributor.cpp index e3216839f..0c095e437 100644 --- a/Source/WebCore/html/shadow/ContentDistributor.cpp +++ b/Source/WebCore/html/shadow/ContentDistributor.cpp @@ -58,6 +58,40 @@ size_t ContentDistribution::find(const Node* node) const return it.get()->value; } +ShadowRootContentDistributionData::ShadowRootContentDistributionData() + : m_insertionPointAssignedTo(0) + , m_numberOfShadowElementChildren(0) + , m_numberOfContentElementChildren(0) + , m_numberOfElementShadowChildren(0) + , m_insertionPointListIsValid(false) +{ +} + +void ShadowRootContentDistributionData::invalidateInsertionPointList() +{ + m_insertionPointListIsValid = false; + m_insertionPointList.clear(); +} + +const Vector<InsertionPoint*>& ShadowRootContentDistributionData::ensureInsertionPointList(ShadowRoot* shadowRoot) +{ + if (m_insertionPointListIsValid) + return m_insertionPointList; + + m_insertionPointListIsValid = true; + ASSERT(m_insertionPointList.isEmpty()); + + if (!shadowRoot->hasInsertionPoint()) + return m_insertionPointList; + + for (Node* node = shadowRoot; node; node = node->traverseNextNode(shadowRoot)) { + if (node->isInsertionPoint()) + m_insertionPointList.append(toInsertionPoint(node)); + } + + return m_insertionPointList; +} + ContentDistributor::ContentDistributor() : m_validity(Undetermined) { @@ -107,17 +141,18 @@ void ContentDistributor::distribute(Element* host) for (ShadowRoot* root = host->youngestShadowRoot(); root; root = root->olderShadowRoot()) { HTMLShadowElement* firstActiveShadowInsertionPoint = 0; - for (Node* node = root; node; node = node->traverseNextNode(root)) { - if (!isActiveInsertionPoint(node)) + const Vector<InsertionPoint*>& insertionPoints = root->insertionPointList(); + for (size_t i = 0; i < insertionPoints.size(); ++i) { + InsertionPoint* point = insertionPoints[i]; + if (!point->isActive()) continue; - InsertionPoint* point = toInsertionPoint(node); - if (isHTMLShadowElement(node)) { + if (isHTMLShadowElement(point)) { if (!firstActiveShadowInsertionPoint) - firstActiveShadowInsertionPoint = toHTMLShadowElement(node); + firstActiveShadowInsertionPoint = toHTMLShadowElement(point); } else { distributeSelectionsTo(point, pool, distributed); - if (ElementShadow* shadow = node->parentNode()->isElementNode() ? toElement(node->parentNode())->shadow() : 0) + if (ElementShadow* shadow = point->parentNode()->isElementNode() ? toElement(point->parentNode())->shadow() : 0) shadow->invalidateDistribution(); } } @@ -148,13 +183,10 @@ bool ContentDistributor::invalidate(Element* host) for (ShadowRoot* root = host->youngestShadowRoot(); root; root = root->olderShadowRoot()) { root->setAssignedTo(0); - - for (Node* node = root; node; node = node->traverseNextNode(root)) { - if (!node->isInsertionPoint()) - continue; + const Vector<InsertionPoint*>& insertionPoints = root->insertionPointList(); + for (size_t i = 0; i < insertionPoints.size(); ++i) { needsReattach = needsReattach || true; - InsertionPoint* point = toInsertionPoint(node); - point->clearDistribution(); + insertionPoints[i]->clearDistribution(); } } |