Skip to content
Permalink
Browse files
[Shadow DOM] Distribution related code on ShadowRoot should be minimi…
…zed.

https://bugs.webkit.org/show_bug.cgi?id=106282

Reviewed by Dimitri Glazkov.

.:

* Source/autotools/symbols.filter:

Source/WebCore:

ShadowRoot had a certain amount of logic which is dedicated for
node distribution computation.  These code is going to be compiled
out (Bug 103339) and better be part of the node distribution
algorithm, which is ScopeContentDistribution class.

This change

- Renames ShadowRootContentDistributionData to
  ScopeContentDistribution.  New name is concise and a bit more
  meaningful: It owns per TreeScope distribution state.
- Moves distribution related code from ShadowRoot to ScopeContentDistribution

No new tests. Refactoring.

* WebCore.exp.in:
* css/StyleScopeResolver.cpp:
(WebCore::StyleScopeResolver::styleSharingCandidateMatchesHostRules):
(WebCore::StyleScopeResolver::matchHostRules):
* dom/ComposedShadowTreeWalker.cpp:
(WebCore::nodeCanBeDistributed):
(WebCore::ComposedShadowTreeWalker::traverseBackToYoungerShadowRoot):
(WebCore::ComposedShadowTreeWalker::traverseParentBackToYoungerShadowRootOrHost):
(WebCore::AncestorChainWalker::parent):
* dom/ElementShadow.cpp:
(WebCore::ElementShadow::collectSelectFeatureSetFrom):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::insertedInto):
(WebCore::ShadowRoot::removedFrom):
(WebCore::ShadowRoot::ensureScopeDistribution):
(WebCore::ShadowRoot::reportMemoryUsage):
* dom/ShadowRoot.h:
(WebCore):
(ShadowRoot):
(WebCore::ShadowRoot::scopeDistribution):
* html/shadow/ContentDistributor.cpp:
(WebCore::ScopeContentDistribution::ScopeContentDistribution):
(WebCore::ScopeContentDistribution::invalidateInsertionPointList):
(WebCore::ScopeContentDistribution::ensureInsertionPointList):
(WebCore::ScopeContentDistribution::registerInsertionPoint):
(WebCore::ScopeContentDistribution::unregisterInsertionPoint):
(WebCore::ScopeContentDistribution::hasShadowElement):
(WebCore):
(WebCore::ScopeContentDistribution::hasContentElement):
(WebCore::ScopeContentDistribution::countElementShadow):
(WebCore::ScopeContentDistribution::hasInsertionPoint):
(WebCore::ScopeContentDistribution::assignedTo):
(WebCore::ContentDistributor::distribute):
(WebCore::ContentDistributor::invalidate):
* html/shadow/ContentDistributor.h:
(ScopeContentDistribution):
(WebCore::ScopeContentDistribution::registerElementShadow):
(WebCore::ScopeContentDistribution::unregisterElementShadow):
(WebCore::ScopeContentDistribution::hasElementShadow):
* html/shadow/HTMLShadowElement.cpp:
(WebCore::HTMLShadowElement::olderShadowRoot):
* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::insertedInto):
(WebCore::InsertionPoint::removedFrom):
(WebCore::InsertionPoint::contains):
(WebCore):
(WebCore::resolveReprojection):
* html/shadow/InsertionPoint.h:
(InsertionPoint):
(WebCore):
* testing/Internals.cpp:
(WebCore::Internals::hasShadowInsertionPoint):
(WebCore::Internals::hasContentElement):
(WebCore::Internals::countElementShadow):

Source/WebKit/win:

* WebKit.vcproj/WebKit.def.in:


Canonical link: https://commits.webkit.org/124579@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
omo committed Jan 9, 2013
1 parent a7b9f29 commit aa010e847130e92f79acd0370c01c5894608a2e1
Showing 17 changed files with 250 additions and 211 deletions.
@@ -1,3 +1,12 @@
2013-01-08 Hajime Morrita <morrita@google.com>

[Shadow DOM] Distribution related code on ShadowRoot should be minimized.
https://bugs.webkit.org/show_bug.cgi?id=106282

Reviewed by Dimitri Glazkov.

* Source/autotools/symbols.filter:

2013-01-03 Sergio Villar Senin <svillar@igalia.com>

[GTK] Add WebP image support
@@ -1,3 +1,79 @@
2013-01-08 Hajime Morrita <morrita@google.com>

[Shadow DOM] Distribution related code on ShadowRoot should be minimized.
https://bugs.webkit.org/show_bug.cgi?id=106282

Reviewed by Dimitri Glazkov.

ShadowRoot had a certain amount of logic which is dedicated for
node distribution computation. These code is going to be compiled
out (Bug 103339) and better be part of the node distribution
algorithm, which is ScopeContentDistribution class.

This change

- Renames ShadowRootContentDistributionData to
ScopeContentDistribution. New name is concise and a bit more
meaningful: It owns per TreeScope distribution state.
- Moves distribution related code from ShadowRoot to ScopeContentDistribution

No new tests. Refactoring.

* WebCore.exp.in:
* css/StyleScopeResolver.cpp:
(WebCore::StyleScopeResolver::styleSharingCandidateMatchesHostRules):
(WebCore::StyleScopeResolver::matchHostRules):
* dom/ComposedShadowTreeWalker.cpp:
(WebCore::nodeCanBeDistributed):
(WebCore::ComposedShadowTreeWalker::traverseBackToYoungerShadowRoot):
(WebCore::ComposedShadowTreeWalker::traverseParentBackToYoungerShadowRootOrHost):
(WebCore::AncestorChainWalker::parent):
* dom/ElementShadow.cpp:
(WebCore::ElementShadow::collectSelectFeatureSetFrom):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::insertedInto):
(WebCore::ShadowRoot::removedFrom):
(WebCore::ShadowRoot::ensureScopeDistribution):
(WebCore::ShadowRoot::reportMemoryUsage):
* dom/ShadowRoot.h:
(WebCore):
(ShadowRoot):
(WebCore::ShadowRoot::scopeDistribution):
* html/shadow/ContentDistributor.cpp:
(WebCore::ScopeContentDistribution::ScopeContentDistribution):
(WebCore::ScopeContentDistribution::invalidateInsertionPointList):
(WebCore::ScopeContentDistribution::ensureInsertionPointList):
(WebCore::ScopeContentDistribution::registerInsertionPoint):
(WebCore::ScopeContentDistribution::unregisterInsertionPoint):
(WebCore::ScopeContentDistribution::hasShadowElement):
(WebCore):
(WebCore::ScopeContentDistribution::hasContentElement):
(WebCore::ScopeContentDistribution::countElementShadow):
(WebCore::ScopeContentDistribution::hasInsertionPoint):
(WebCore::ScopeContentDistribution::assignedTo):
(WebCore::ContentDistributor::distribute):
(WebCore::ContentDistributor::invalidate):
* html/shadow/ContentDistributor.h:
(ScopeContentDistribution):
(WebCore::ScopeContentDistribution::registerElementShadow):
(WebCore::ScopeContentDistribution::unregisterElementShadow):
(WebCore::ScopeContentDistribution::hasElementShadow):
* html/shadow/HTMLShadowElement.cpp:
(WebCore::HTMLShadowElement::olderShadowRoot):
* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::insertedInto):
(WebCore::InsertionPoint::removedFrom):
(WebCore::InsertionPoint::contains):
(WebCore):
(WebCore::resolveReprojection):
* html/shadow/InsertionPoint.h:
(InsertionPoint):
(WebCore):
* testing/Internals.cpp:
(WebCore::Internals::hasShadowInsertionPoint):
(WebCore::Internals::hasContentElement):
(WebCore::Internals::countElementShadow):

2013-01-08 Tom Sepez <tsepez@chromium.org>

Copy-paste preserves <embed> tags containing active content.
@@ -82,9 +82,6 @@ __ZN7WebCore10ScrollView21setDelegatesScrollingEb
__ZN7WebCore10ScrollView23setScrollbarsSuppressedEbb
__ZN7WebCore10ScrollView24windowResizerRectChangedEv
__ZN7WebCore10ScrollView8addChildEN3WTF10PassRefPtrINS_6WidgetEEE
__ZNK7WebCore10ShadowRoot17hasContentElementEv
__ZNK7WebCore10ShadowRoot18countElementShadowEv
__ZNK7WebCore10ShadowRoot23hasShadowInsertionPointEv
__ZNK7WebCore14ScrollableArea17reportMemoryUsageEPN3WTF16MemoryObjectInfoE
__ZN7WebCore10ShadowRoot6createEPNS_7ElementERi
__ZN7WebCore10deleteFileERKN3WTF6StringE
@@ -672,6 +669,9 @@ __ZN7WebCore24FrameDestructionObserver14frameDestroyedEv
__ZN7WebCore24FrameDestructionObserver14willDetachPageEv
__ZN7WebCore24FrameDestructionObserverC2EPNS_5FrameE
__ZN7WebCore24FrameDestructionObserverD2Ev
__ZN7WebCore24ScopeContentDistribution16hasShadowElementEPKNS_10ShadowRootE
__ZN7WebCore24ScopeContentDistribution18countElementShadowEPKNS_10ShadowRootE
__ZN7WebCore24ScopeContentDistribution17hasContentElementEPKNS_10ShadowRootE
__ZN7WebCore24createFragmentFromMarkupEPNS_8DocumentERKN3WTF6StringES5_NS_27FragmentScriptingPermissionE
__ZN7WebCore24decodeURLEscapeSequencesERKN3WTF6StringE
__ZN7WebCore24deleteCookiesForHostnameERKNS_21NetworkStorageSessionERKN3WTF6StringE
@@ -31,6 +31,7 @@

#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "ContentDistributor.h"
#include "ContextFeatures.h"
#include "ElementShadow.h"
#include "HTMLNames.h"
@@ -210,7 +211,7 @@ bool StyleScopeResolver::styleSharingCandidateMatchesHostRules(const Element* el
if (atHostRuleSetFor(shadowRoot))
return true;

if (!shadowRoot->hasShadowInsertionPoint())
if (!ScopeContentDistribution::hasShadowElement(shadowRoot))
break;
}
return false;
@@ -232,7 +233,7 @@ void StyleScopeResolver::matchHostRules(const Element* element, Vector<RuleSet*>
for (ShadowRoot* shadowRoot = shadow->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) {
if (RuleSet* ruleSet = atHostRuleSetFor(shadowRoot))
matchedRules.append(ruleSet);
if (!shadowRoot->hasShadowInsertionPoint())
if (!ScopeContentDistribution::hasShadowElement(shadowRoot))
break;
}
}
@@ -63,7 +63,7 @@ static inline bool nodeCanBeDistributed(const Node* node)
return false;

if (ShadowRoot* shadowRoot = parent->isShadowRoot() ? toShadowRoot(parent) : 0)
return shadowRoot->assignedTo();
return ScopeContentDistribution::assignedTo(shadowRoot);

if (parent->isElementNode() && toElement(parent)->shadow())
return true;
@@ -198,7 +198,7 @@ Node* ComposedShadowTreeWalker::traverseBackToYoungerShadowRoot(const Node* node
if (node->parentNode() && node->parentNode()->isShadowRoot()) {
ShadowRoot* parentShadowRoot = toShadowRoot(node->parentNode());
if (!parentShadowRoot->isYoungest()) {
InsertionPoint* assignedInsertionPoint = parentShadowRoot->assignedTo();
InsertionPoint* assignedInsertionPoint = ScopeContentDistribution::assignedTo(parentShadowRoot);
ASSERT(assignedInsertionPoint);
return traverseSiblingInCurrentTree(assignedInsertionPoint, direction);
}
@@ -267,7 +267,7 @@ inline Node* ComposedShadowTreeWalker::traverseParentInCurrentTree(const Node* n
Node* ComposedShadowTreeWalker::traverseParentBackToYoungerShadowRootOrHost(const ShadowRoot* shadowRoot, ParentTraversalDetails* details) const
{
ASSERT(shadowRoot);
ASSERT(!shadowRoot->assignedTo());
ASSERT(!ScopeContentDistribution::assignedTo(shadowRoot));

if (shadowRoot->isYoungest()) {
if (canCrossUpperBoundary()) {
@@ -343,14 +343,14 @@ void AncestorChainWalker::parent()
}
if (!m_node->isShadowRoot()) {
m_node = m_node->parentNode();
if (!(m_node && m_node->isShadowRoot() && toShadowRoot(m_node)->assignedTo()))
if (!(m_node && m_node->isShadowRoot() && ScopeContentDistribution::assignedTo(toShadowRoot(m_node))))
m_distributedNode = m_node;
m_isCrossingInsertionPoint = false;
return;
}

const ShadowRoot* shadowRoot = toShadowRoot(m_node);
if (InsertionPoint* insertionPoint = shadowRoot->assignedTo()) {
if (InsertionPoint* insertionPoint = ScopeContentDistribution::assignedTo(shadowRoot)) {
m_node = insertionPoint;
m_isCrossingInsertionPoint = true;
return;
@@ -233,7 +233,7 @@ void ElementShadow::ensureSelectFeatureSetCollected()

void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot* root)
{
if (root->hasElementShadow()) {
if (ScopeContentDistribution::hasElementShadow(root)) {
for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) {
if (ElementShadow* elementShadow = element->shadow()) {
elementShadow->ensureSelectFeatureSetCollected();
@@ -242,7 +242,7 @@ void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot* root)
}
}

if (root->hasContentElement()) {
if (ScopeContentDistribution::hasContentElement(root)) {
for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) {
if (isHTMLContentElement(element)) {
const CSSSelectorList& list = toHTMLContentElement(element)->selectorList();
@@ -226,11 +226,6 @@ ElementShadow* ShadowRoot::owner() const
return 0;
}

bool ShadowRoot::hasInsertionPoint() const
{
return hasShadowInsertionPoint() || hasContentElement();
}

bool ShadowRoot::applyAuthorStyles() const
{
return m_applyAuthorStyles;
@@ -284,7 +279,7 @@ Node::InsertionNotificationRequest ShadowRoot::insertedInto(ContainerNode* inser
return InsertionDone;

if (ShadowRoot* root = host()->containingShadowRoot()) {
root->registerElementShadow();
root->ensureScopeDistribution()->registerElementShadow();
m_registeredWithParentShadowRoot = true;
}

@@ -298,28 +293,14 @@ void ShadowRoot::removedFrom(ContainerNode* insertionPoint)
if (!root)
root = insertionPoint->containingShadowRoot();

if (root)
root->unregisterElementShadow();
if (root && root->scopeDistribution())
root->scopeDistribution()->unregisterElementShadow();
m_registeredWithParentShadowRoot = false;
}

DocumentFragment::removedFrom(insertionPoint);
}

InsertionPoint* ShadowRoot::assignedTo() const
{
if (!distributionData())
return 0;

return distributionData()->insertionPointAssignedTo();
}

void ShadowRoot::setAssignedTo(InsertionPoint* insertionPoint)
{
ASSERT(!assignedTo() || !insertionPoint);
ensureDistributionData()->setInsertionPointAssignedTo(insertionPoint);
}

void ShadowRoot::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
GuardOrphanShadowRoot({ });
@@ -328,14 +309,6 @@ void ShadowRoot::childrenChanged(bool changedByParser, Node* beforeChange, Node*
owner()->invalidateDistribution();
}

const Vector<RefPtr<InsertionPoint> >& ShadowRoot::insertionPointList()
{
typedef Vector<RefPtr<InsertionPoint> > InsertionPointVector;
DEFINE_STATIC_LOCAL(InsertionPointVector, emptyVector, ());

return distributionData() ? distributionData()->ensureInsertionPointList(this) : emptyVector;
}

void ShadowRoot::registerScopedHTMLStyleChild()
{
++m_numberOfStyles;
@@ -349,76 +322,23 @@ void ShadowRoot::unregisterScopedHTMLStyleChild()
setHasScopedHTMLStyleChild(m_numberOfStyles > 0);
}

inline ShadowRootContentDistributionData* ShadowRoot::ensureDistributionData()
ScopeContentDistribution* ShadowRoot::ensureScopeDistribution()
{
if (m_distributionData)
return m_distributionData.get();
if (m_scopeDistribution)
return m_scopeDistribution.get();

m_distributionData = adoptPtr(new ShadowRootContentDistributionData);
return m_distributionData.get();
m_scopeDistribution = adoptPtr(new ScopeContentDistribution);
return m_scopeDistribution.get();
}

void ShadowRoot::registerInsertionPoint(InsertionPoint* point)
{
ensureDistributionData()->regiterInsertionPoint(this, point);
}

void ShadowRoot::unregisterInsertionPoint(InsertionPoint* point)
{
ensureDistributionData()->unregisterInsertionPoint(this, point);
}

bool ShadowRoot::hasShadowInsertionPoint() const
{
if (!distributionData())
return false;

return distributionData()->hasShadowElementChildren();
}

bool ShadowRoot::hasContentElement() const
{
if (!distributionData())
return false;

return distributionData()->hasContentElementChildren();
}

void ShadowRoot::registerElementShadow()
{
ensureDistributionData()->incrementNumberOfElementShadowChildren();
}

void ShadowRoot::unregisterElementShadow()
{
ASSERT(hasElementShadow());
distributionData()->decrementNumberOfElementShadowChildren();
}

bool ShadowRoot::hasElementShadow() const
{
if (!distributionData())
return false;

return distributionData()->hasElementShadowChildren();
}

unsigned ShadowRoot::countElementShadow() const
{
if (!distributionData())
return 0;

return distributionData()->numberOfElementShadowChildren();
}

void ShadowRoot::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
DocumentFragment::reportMemoryUsage(memoryObjectInfo);
TreeScope::reportMemoryUsage(memoryObjectInfo);
info.addMember(m_prev);
info.addMember(m_next);
info.addMember(m_distributionData);
info.addMember(m_scopeDistribution);
}

}

0 comments on commit aa010e8

Please sign in to comment.