1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef StyleResolverParentScope_h
6 #define StyleResolverParentScope_h
8 #include "core/css/resolver/StyleResolver.h"
9 #include "core/dom/Element.h"
10 #include "core/dom/shadow/ShadowRoot.h"
14 // Maintains the parent element stack (and bloom filter) inside recalcStyle.
15 class StyleResolverParentScope FINAL {
17 explicit StyleResolverParentScope(Node& parent);
18 ~StyleResolverParentScope();
20 static void ensureParentStackIsPushed();
23 void pushParentIfNeeded();
27 StyleResolverParentScope* m_previous;
28 StyleResolver& m_resolver;
30 static StyleResolverParentScope* s_currentScope;
33 inline StyleResolverParentScope::StyleResolverParentScope(Node& parent)
36 , m_previous(s_currentScope)
37 , m_resolver(*m_parent.document().styleResolver())
39 ASSERT(m_parent.document().inStyleRecalc());
40 ASSERT(parent.isElementNode() || parent.isShadowRoot());
41 s_currentScope = this;
42 m_resolver.increaseStyleSharingDepth();
45 inline StyleResolverParentScope::~StyleResolverParentScope()
47 s_currentScope = m_previous;
48 m_resolver.decreaseStyleSharingDepth();
51 if (m_parent.isElementNode())
52 m_resolver.popParentElement(toElement(m_parent));
54 m_resolver.popParentShadowRoot(toShadowRoot(m_parent));
57 inline void StyleResolverParentScope::ensureParentStackIsPushed()
60 s_currentScope->pushParentIfNeeded();
63 inline void StyleResolverParentScope::pushParentIfNeeded()
68 m_previous->pushParentIfNeeded();
69 if (m_parent.isElementNode())
70 m_resolver.pushParentElement(toElement(m_parent));
72 m_resolver.pushParentShadowRoot(toShadowRoot(m_parent));
76 } // namespace WebCore
78 #endif // StyleResolverParentScope_h