OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef StyleResolverParentScope_h | 5 #ifndef StyleResolverParentScope_h |
6 #define StyleResolverParentScope_h | 6 #define StyleResolverParentScope_h |
7 | 7 |
8 #include "core/css/resolver/StyleResolver.h" | 8 #include "core/css/resolver/StyleResolver.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 10 #include "core/dom/shadow/ShadowRoot.h" |
10 | 11 |
11 namespace WebCore { | 12 namespace WebCore { |
12 | 13 |
13 // Maintains the parent element stack (and bloom filter) inside recalcStyle. | 14 // Maintains the parent element stack (and bloom filter) inside recalcStyle. |
14 class StyleResolverParentScope FINAL { | 15 class StyleResolverParentScope FINAL { |
15 public: | 16 public: |
16 explicit StyleResolverParentScope(Element& parent); | 17 explicit StyleResolverParentScope(Node& parent); |
17 ~StyleResolverParentScope(); | 18 ~StyleResolverParentScope(); |
18 | 19 |
19 static void ensureParentStackIsPushed(); | 20 static void ensureParentStackIsPushed(); |
20 | 21 |
21 private: | 22 private: |
22 void pushParentIfNeeded(); | 23 void pushParentIfNeeded(); |
23 | 24 |
24 Element& m_parent; | 25 Node& m_parent; |
25 bool m_pushed; | 26 bool m_pushed; |
26 StyleResolverParentScope* m_previous; | 27 StyleResolverParentScope* m_previous; |
| 28 StyleResolver& m_resolver; |
27 | 29 |
28 static StyleResolverParentScope* s_currentScope; | 30 static StyleResolverParentScope* s_currentScope; |
29 }; | 31 }; |
30 | 32 |
31 inline StyleResolverParentScope::StyleResolverParentScope(Element& parent) | 33 inline StyleResolverParentScope::StyleResolverParentScope(Node& parent) |
32 : m_parent(parent) | 34 : m_parent(parent) |
33 , m_pushed(false) | 35 , m_pushed(false) |
34 , m_previous(s_currentScope) | 36 , m_previous(s_currentScope) |
| 37 , m_resolver(*m_parent.document().styleResolver()) |
35 { | 38 { |
36 ASSERT(m_parent.document().inStyleRecalc()); | 39 ASSERT(m_parent.document().inStyleRecalc()); |
| 40 ASSERT(parent.isElementNode() || parent.isShadowRoot()); |
37 s_currentScope = this; | 41 s_currentScope = this; |
38 } | 42 } |
39 | 43 |
40 inline StyleResolverParentScope::~StyleResolverParentScope() | 44 inline StyleResolverParentScope::~StyleResolverParentScope() |
41 { | 45 { |
42 if (m_pushed) | |
43 m_parent.document().styleResolver()->popParentElement(m_parent); | |
44 s_currentScope = m_previous; | 46 s_currentScope = m_previous; |
| 47 if (!m_pushed) |
| 48 return; |
| 49 if (m_parent.isElementNode()) |
| 50 m_resolver.popParentElement(toElement(m_parent)); |
| 51 else |
| 52 m_resolver.popParentShadowRoot(toShadowRoot(m_parent)); |
45 } | 53 } |
46 | 54 |
47 inline void StyleResolverParentScope::ensureParentStackIsPushed() | 55 inline void StyleResolverParentScope::ensureParentStackIsPushed() |
48 { | 56 { |
49 if (s_currentScope) | 57 if (s_currentScope) |
50 s_currentScope->pushParentIfNeeded(); | 58 s_currentScope->pushParentIfNeeded(); |
51 } | 59 } |
52 | 60 |
53 inline void StyleResolverParentScope::pushParentIfNeeded() | 61 inline void StyleResolverParentScope::pushParentIfNeeded() |
54 { | 62 { |
55 if (m_pushed) | 63 if (m_pushed) |
56 return; | 64 return; |
57 if (m_previous) | 65 if (m_previous) |
58 m_previous->pushParentIfNeeded(); | 66 m_previous->pushParentIfNeeded(); |
59 m_parent.document().styleResolver()->pushParentElement(m_parent); | 67 if (m_parent.isElementNode()) |
| 68 m_resolver.pushParentElement(toElement(m_parent)); |
| 69 else |
| 70 m_resolver.pushParentShadowRoot(toShadowRoot(m_parent)); |
60 m_pushed = true; | 71 m_pushed = true; |
61 } | 72 } |
62 | 73 |
63 } // namespace WebCore | 74 } // namespace WebCore |
64 | 75 |
65 #endif // StyleResolverParentScope_h | 76 #endif // StyleResolverParentScope_h |
OLD | NEW |