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/Document.h"
10 #include "core/dom/Element.h"
11 #include "core/dom/shadow/ShadowRoot.h"
15 // Maintains the parent element stack (and bloom filter) inside recalcStyle.
16 class StyleResolverParentScope FINAL {
19 explicit StyleResolverParentScope(Node& parent);
20 ~StyleResolverParentScope();
22 static void ensureParentStackIsPushed();
25 void pushParentIfNeeded();
26 Node& parent() const { return *m_parent; }
28 RawPtrWillBeMember<Node> m_parent;
30 StyleResolverParentScope* m_previous;
31 StyleResolver& m_resolver;
33 static StyleResolverParentScope* s_currentScope;
36 inline StyleResolverParentScope::StyleResolverParentScope(Node& parent)
39 , m_previous(s_currentScope)
40 , m_resolver(*parent.document().styleResolver())
42 ASSERT(parent.document().inStyleRecalc());
43 ASSERT(parent.isElementNode() || parent.isShadowRoot());
44 s_currentScope = this;
45 m_resolver.increaseStyleSharingDepth();
48 inline StyleResolverParentScope::~StyleResolverParentScope()
50 s_currentScope = m_previous;
51 m_resolver.decreaseStyleSharingDepth();
54 if (parent().isElementNode())
55 m_resolver.popParentElement(toElement(parent()));
58 inline void StyleResolverParentScope::ensureParentStackIsPushed()
61 s_currentScope->pushParentIfNeeded();
64 inline void StyleResolverParentScope::pushParentIfNeeded()
69 m_previous->pushParentIfNeeded();
70 if (parent().isElementNode())
71 m_resolver.pushParentElement(toElement(parent()));
77 #endif // StyleResolverParentScope_h