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

Unified Diff: Source/core/dom/Element.cpp

Issue 102273004: Defer pushing the parent stack in recalcStyle until StyleResolver::styleForElement() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: no-find-copies Created 7 years 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/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index cca4eab671f19e85afd63d5b385d881983ffa15d..21fadd0eb9d882d1a0049a3b5f5518f0740072ad 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -40,6 +40,7 @@
#include "core/css/PropertySetCSSStyleDeclaration.h"
#include "core/css/StylePropertySet.h"
#include "core/css/resolver/StyleResolver.h"
+#include "core/css/resolver/StyleResolverParentScope.h"
#include "core/dom/Attr.h"
#include "core/dom/CSSSelectorWatch.h"
#include "core/dom/ClientRect.h"
@@ -104,40 +105,6 @@ namespace WebCore {
using namespace HTMLNames;
using namespace XMLNames;
-class StyleResolverParentPusher {
-public:
- explicit StyleResolverParentPusher(Element& parent)
- : m_parent(parent)
- , m_pushedStyleResolver(0)
- {
- }
- void push()
- {
- if (m_pushedStyleResolver)
- return;
- m_pushedStyleResolver = &m_parent.document().ensureStyleResolver();
- m_pushedStyleResolver->pushParentElement(m_parent);
- }
- ~StyleResolverParentPusher()
- {
-
- if (!m_pushedStyleResolver)
- return;
-
- // This tells us that our pushed style selector is in a bad state,
- // so we should just bail out in that scenario.
- ASSERT(m_pushedStyleResolver == m_parent.document().styleResolver());
- if (m_pushedStyleResolver != m_parent.document().styleResolver())
- return;
-
- m_pushedStyleResolver->popParentElement(m_parent);
- }
-
-private:
- Element& m_parent;
- StyleResolver* m_pushedStyleResolver;
-};
-
typedef Vector<RefPtr<Attr> > AttrNodeList;
typedef HashMap<Element*, OwnPtr<AttrNodeList> > AttrNodeListMap;
@@ -1365,8 +1332,6 @@ void Element::attach(const AttachContext& context)
{
ASSERT(document().inStyleRecalc());
- StyleResolverParentPusher parentPusher(*this);
-
// We've already been through detach when doing an attach, but we might
// need to clear any state that's been added since then.
if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) {
@@ -1382,15 +1347,13 @@ void Element::attach(const AttachContext& context)
addCallbackSelectors();
- createPseudoElementIfNeeded(BEFORE);
+ StyleResolverParentScope parentScope(*this);
// When a shadow root exists, it does the work of attaching the children.
- if (ElementShadow* shadow = this->shadow()) {
- parentPusher.push();
+ if (ElementShadow* shadow = this->shadow())
shadow->attach(context);
- } else if (firstChild()) {
- parentPusher.push();
- }
+
+ createPseudoElementIfNeeded(BEFORE);
ContainerNode::attach(context);
@@ -1601,21 +1564,19 @@ void Element::recalcChildStyle(StyleRecalcChange change)
ASSERT(change >= Inherit || childNeedsStyleRecalc());
ASSERT(!needsStyleRecalc());
- StyleResolverParentPusher parentPusher(*this);
+ StyleResolverParentScope parentScope(*this);
for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
- if (shouldRecalcStyle(change, root)) {
- parentPusher.push();
+ if (shouldRecalcStyle(change, root))
root->recalcStyle(change);
- }
}
- if (shouldRecalcStyle(change, this))
- updatePseudoElement(BEFORE, change);
-
if (change < Force && hasRareData() && childNeedsStyleRecalc())
checkForChildrenAdjacentRuleChanges();
+ if (shouldRecalcStyle(change, this))
+ updatePseudoElement(BEFORE, change);
+
// This loop is deliberately backwards because we use insertBefore in the rendering tree, and want to avoid
// a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last
// child and work our way back means in the common case, we'll find the insertion point in O(1) time.
@@ -1628,12 +1589,10 @@ void Element::recalcChildStyle(StyleRecalcChange change)
lastTextNode = toText(child);
} else if (child->isElementNode()) {
Element* element = toElement(child);
- if (shouldRecalcStyle(change, element)) {
- parentPusher.push();
+ if (shouldRecalcStyle(change, element))
element->recalcStyle(change, lastTextNode);
- } else if (element->supportsStyleSharing()) {
+ else if (element->supportsStyleSharing())
styleResolver.addToStyleSharingList(*element);
- }
if (element->renderer())
lastTextNode = 0;
}

Powered by Google App Engine
This is Rietveld 408576698