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

Unified Diff: third_party/WebKit/Source/core/dom/shadow/ElementShadowV0.cpp

Issue 2322213002: Refactor ElementShadow by separating v0 related features as ElementShadowV0 (Closed)
Patch Set: addressed Created 4 years, 3 months 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: third_party/WebKit/Source/core/dom/shadow/ElementShadowV0.cpp
diff --git a/third_party/WebKit/Source/core/dom/shadow/ElementShadow.cpp b/third_party/WebKit/Source/core/dom/shadow/ElementShadowV0.cpp
similarity index 58%
copy from third_party/WebKit/Source/core/dom/shadow/ElementShadow.cpp
copy to third_party/WebKit/Source/core/dom/shadow/ElementShadowV0.cpp
index 89e06450e1bf245415928e33c79f56e9abc3001b..ffcd1448e56e4aa43bd1c1063880355966f545df 100644
--- a/third_party/WebKit/Source/core/dom/shadow/ElementShadow.cpp
+++ b/third_party/WebKit/Source/core/dom/shadow/ElementShadowV0.cpp
@@ -24,19 +24,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "core/dom/shadow/ElementShadow.h"
+#include "core/dom/shadow/ElementShadowV0.h"
-#include "core/css/StyleSheetList.h"
#include "core/dom/ElementTraversal.h"
-#include "core/dom/NodeTraversal.h"
-#include "core/dom/StyleChangeReason.h"
#include "core/dom/shadow/DistributedNodes.h"
-#include "core/frame/Deprecation.h"
+#include "core/dom/shadow/ElementShadow.h"
#include "core/html/HTMLContentElement.h"
#include "core/html/HTMLShadowElement.h"
#include "core/inspector/InspectorInstrumentation.h"
-#include "platform/EventDispatchForbiddenScope.h"
-#include "platform/ScriptForbiddenScope.h"
namespace blink {
@@ -46,7 +41,7 @@ public:
explicit DistributionPool(const ContainerNode&);
void clear();
~DistributionPool();
- void distributeTo(InsertionPoint*, ElementShadow*);
+ void distributeTo(InsertionPoint*, ElementShadowV0*);
void populateChildren(const ContainerNode&);
private:
@@ -87,7 +82,7 @@ inline void DistributionPool::populateChildren(const ContainerNode& parent)
m_distributed.fill(false);
}
-void DistributionPool::distributeTo(InsertionPoint* insertionPoint, ElementShadow* elementShadow)
+void DistributionPool::distributeTo(InsertionPoint* insertionPoint, ElementShadowV0* elementShadow)
{
DistributedNodes distributedNodes;
@@ -129,160 +124,51 @@ inline void DistributionPool::detachNonDistributedNodes()
}
}
-ElementShadow* ElementShadow::create()
+ElementShadowV0* ElementShadowV0::create(ElementShadow& elementShadow)
{
- return new ElementShadow();
+ return new ElementShadowV0(elementShadow);
}
-ElementShadow::ElementShadow()
- : m_needsDistributionRecalc(false)
+ElementShadowV0::ElementShadowV0(ElementShadow& elementShadow)
+ : m_elementShadow(&elementShadow)
, m_needsSelectFeatureSet(false)
{
}
-ElementShadow::~ElementShadow()
-{
-}
-
-ShadowRoot& ElementShadow::youngestShadowRoot() const
-{
- ShadowRoot* current = m_shadowRoot;
- DCHECK(current);
- while (current->youngerShadowRoot())
- current = current->youngerShadowRoot();
- return *current;
-}
-
-ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType type)
-{
- EventDispatchForbiddenScope assertNoEventDispatch;
- ScriptForbiddenScope forbidScript;
-
- if (type == ShadowRootType::V0 && m_shadowRoot) {
- DCHECK_EQ(m_shadowRoot->type(), ShadowRootType::V0);
- Deprecation::countDeprecation(shadowHost.document(), UseCounter::ElementCreateShadowRootMultiple);
- }
-
- if (m_shadowRoot) {
- // TODO(hayato): Is the order, from the youngest to the oldest, important?
- for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShadowRoot())
- root->lazyReattachIfAttached();
- }
-
- ShadowRoot* shadowRoot = ShadowRoot::create(shadowHost.document(), type);
- shadowRoot->setParentOrShadowHostNode(&shadowHost);
- shadowRoot->setParentTreeScope(shadowHost.treeScope());
- appendShadowRoot(*shadowRoot);
- setNeedsDistributionRecalc();
-
- shadowRoot->insertedInto(&shadowHost);
- shadowHost.setChildNeedsStyleRecalc();
- shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::Shadow));
-
- InspectorInstrumentation::didPushShadowRoot(&shadowHost, shadowRoot);
-
- return *shadowRoot;
-}
-
-void ElementShadow::appendShadowRoot(ShadowRoot& shadowRoot)
-{
- if (!m_shadowRoot) {
- m_shadowRoot = &shadowRoot;
- return;
- }
- ShadowRoot& youngest = youngestShadowRoot();
- DCHECK(shadowRoot.type() == ShadowRootType::V0);
- DCHECK(youngest.type() == ShadowRootType::V0);
- youngest.setYoungerShadowRoot(shadowRoot);
- shadowRoot.setOlderShadowRoot(youngest);
-}
-
-void ElementShadow::attach(const Node::AttachContext& context)
+ElementShadowV0::~ElementShadowV0()
{
- Node::AttachContext childrenContext(context);
- childrenContext.resolvedStyle = 0;
-
- for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShadowRoot()) {
- if (root->needsAttach())
- root->attachLayoutTree(childrenContext);
- }
}
-void ElementShadow::detach(const Node::AttachContext& context)
+ShadowRoot& ElementShadowV0::youngestShadowRoot() const
{
- Node::AttachContext childrenContext(context);
- childrenContext.resolvedStyle = 0;
-
- for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShadowRoot())
- root->detachLayoutTree(childrenContext);
+ return m_elementShadow->youngestShadowRoot();
}
-void ElementShadow::setNeedsDistributionRecalc()
+ShadowRoot& ElementShadowV0::oldestShadowRoot() const
{
- if (m_needsDistributionRecalc)
- return;
- m_needsDistributionRecalc = true;
- host().markAncestorsWithChildNeedsDistributionRecalc();
- if (!isV1())
- clearDistributionV0();
+ return m_elementShadow->oldestShadowRoot();
}
-bool ElementShadow::hasSameStyles(const ElementShadow* other) const
+const InsertionPoint* ElementShadowV0::finalDestinationInsertionPointFor(const Node* key) const
{
- ShadowRoot* root = &youngestShadowRoot();
- ShadowRoot* otherRoot = &other->youngestShadowRoot();
- while (root || otherRoot) {
- if (!root || !otherRoot)
- return false;
-
- StyleSheetList& list = root->styleSheets();
- StyleSheetList& otherList = otherRoot->styleSheets();
-
- if (list.length() != otherList.length())
- return false;
-
- for (size_t i = 0; i < list.length(); i++) {
- if (toCSSStyleSheet(list.item(i))->contents() != toCSSStyleSheet(otherList.item(i))->contents())
- return false;
- }
- root = root->olderShadowRoot();
- otherRoot = otherRoot->olderShadowRoot();
- }
-
- return true;
-}
-
-const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Node* key) const
-{
- DCHECK(!isV1());
DCHECK(key);
DCHECK(!key->needsDistributionRecalc());
NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoints.find(key);
return it == m_nodeToInsertionPoints.end() ? nullptr : it->value->last();
}
-const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(const Node* key) const
+const DestinationInsertionPoints* ElementShadowV0::destinationInsertionPointsFor(const Node* key) const
{
- DCHECK(!isV1());
DCHECK(key);
DCHECK(!key->needsDistributionRecalc());
NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoints.find(key);
return it == m_nodeToInsertionPoints.end() ? nullptr : it->value;
}
-void ElementShadow::distribute()
+void ElementShadowV0::distribute()
{
- if (isV1())
- youngestShadowRoot().distributeV1();
- else
- distributeV0();
-}
-
-void ElementShadow::distributeV0()
-{
- DCHECK(!isV1());
HeapVector<Member<HTMLShadowElement>, 32> shadowInsertionPoints;
- DistributionPool pool(host());
+ DistributionPool pool(m_elementShadow->host());
for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShadowRoot()) {
HTMLShadowElement* shadowInsertionPoint = 0;
@@ -319,40 +205,39 @@ void ElementShadow::distributeV0()
if (ElementShadow* shadow = shadowWhereNodeCanBeDistributedForV0(*shadowInsertionPoint))
shadow->setNeedsDistributionRecalc();
}
- InspectorInstrumentation::didPerformElementShadowDistribution(&host());
+ InspectorInstrumentation::didPerformElementShadowDistribution(const_cast<Element*>(&m_elementShadow->host()));
}
-void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertionPoint)
+void ElementShadowV0::didDistributeNode(const Node* node, InsertionPoint* insertionPoint)
{
- DCHECK(!isV1());
NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints.add(node, nullptr);
if (result.isNewEntry)
result.storedValue->value = new DestinationInsertionPoints;
result.storedValue->value->append(insertionPoint);
}
-const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet()
+const SelectRuleFeatureSet& ElementShadowV0::ensureSelectFeatureSet()
{
- DCHECK(!isV1());
if (!m_needsSelectFeatureSet)
return m_selectFeatures;
m_selectFeatures.clear();
- for (ShadowRoot* root = &oldestShadowRoot(); root; root = root->youngerShadowRoot())
+ for (const ShadowRoot* root = &oldestShadowRoot(); root; root = root->youngerShadowRoot())
collectSelectFeatureSetFrom(*root);
m_needsSelectFeatureSet = false;
return m_selectFeatures;
}
-void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root)
+void ElementShadowV0::collectSelectFeatureSetFrom(const ShadowRoot& root)
{
- DCHECK(!isV1());
if (!root.containsShadowRoots() && !root.containsContentElements())
return;
for (Element& element : ElementTraversal::descendantsOf(root)) {
- if (ElementShadow* shadow = element.shadow())
- m_selectFeatures.add(shadow->ensureSelectFeatureSet());
+ if (ElementShadow* shadow = element.shadow()) {
+ if (!shadow->isV1())
+ m_selectFeatures.add(shadow->v0().ensureSelectFeatureSet());
+ }
if (!isHTMLContentElement(element))
continue;
const CSSSelectorList& list = toHTMLContentElement(element).selectorList();
@@ -360,36 +245,33 @@ void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root)
}
}
-void ElementShadow::willAffectSelector()
+void ElementShadowV0::willAffectSelector()
{
- DCHECK(!isV1());
- for (ElementShadow* shadow = this; shadow; shadow = shadow->containingShadow()) {
- if (shadow->needsSelectFeatureSet())
+ for (ElementShadow* shadow = m_elementShadow; shadow; shadow = shadow->containingShadow()) {
+ if (shadow->isV1() || shadow->v0().needsSelectFeatureSet())
break;
- shadow->setNeedsSelectFeatureSet();
+ shadow->v0().setNeedsSelectFeatureSet();
}
- setNeedsDistributionRecalc();
+ m_elementShadow->setNeedsDistributionRecalc();
}
-void ElementShadow::clearDistributionV0()
+void ElementShadowV0::clearDistribution()
{
- DCHECK(!isV1());
m_nodeToInsertionPoints.clear();
- for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShadowRoot())
+ for (ShadowRoot* root = &m_elementShadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
root->setShadowInsertionPointOfYoungerShadowRoot(nullptr);
}
-DEFINE_TRACE(ElementShadow)
+DEFINE_TRACE(ElementShadowV0)
{
+ visitor->trace(m_elementShadow);
visitor->trace(m_nodeToInsertionPoints);
visitor->trace(m_selectFeatures);
- visitor->trace(m_shadowRoot);
}
-DEFINE_TRACE_WRAPPERS(ElementShadow)
+DEFINE_TRACE_WRAPPERS(ElementShadowV0)
{
- visitor->traceWrappers(m_shadowRoot);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698