OLD | NEW |
| (Empty) |
1 // Copyright (c) 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. | |
4 | |
5 #include "config.h" | |
6 #include "core/dom/SiblingRuleHelper.h" | |
7 | |
8 #include "core/dom/Document.h" | |
9 #include "core/dom/Element.h" | |
10 #include "core/dom/StyleEngine.h" | |
11 #include "core/dom/shadow/ShadowRoot.h" | |
12 | |
13 namespace WebCore { | |
14 | |
15 bool SiblingRuleHelper::isFinishedParsingChildren() | |
16 { | |
17 if (m_node->isElementNode()) | |
18 return toElement(m_node)->isFinishedParsingChildren(); | |
19 | |
20 return toShadowRoot(m_node)->isFinishedParsingChildren(); | |
21 } | |
22 | |
23 void SiblingRuleHelper::setChildrenAffectedByDirectAdjacentRules() | |
24 { | |
25 if (m_node->isElementNode()) | |
26 toElement(m_node)->setChildrenAffectedByDirectAdjacentRules(); | |
27 else | |
28 toShadowRoot(m_node)->setChildrenAffectedByDirectAdjacentRules(); | |
29 } | |
30 | |
31 void SiblingRuleHelper::setChildrenAffectedByIndirectAdjacentRules() | |
32 { | |
33 if (m_node->isElementNode()) | |
34 toElement(m_node)->setChildrenAffectedByIndirectAdjacentRules(); | |
35 else | |
36 toShadowRoot(m_node)->setChildrenAffectedByIndirectAdjacentRules(); | |
37 } | |
38 | |
39 void SiblingRuleHelper::setChildrenAffectedByForwardPositionalRules() | |
40 { | |
41 if (m_node->isElementNode()) | |
42 toElement(m_node)->setChildrenAffectedByForwardPositionalRules(); | |
43 else | |
44 toShadowRoot(m_node)->setChildrenAffectedByForwardPositionalRules(); | |
45 } | |
46 | |
47 void SiblingRuleHelper::setChildrenAffectedByBackwardPositionalRules() | |
48 { | |
49 if (m_node->isElementNode()) | |
50 toElement(m_node)->setChildrenAffectedByBackwardPositionalRules(); | |
51 else | |
52 toShadowRoot(m_node)->setChildrenAffectedByBackwardPositionalRules(); | |
53 } | |
54 | |
55 void SiblingRuleHelper::setChildrenAffectedByFirstChildRules() | |
56 { | |
57 if (m_node->isElementNode()) | |
58 toElement(m_node)->setChildrenAffectedByFirstChildRules(); | |
59 else | |
60 toShadowRoot(m_node)->setChildrenAffectedByFirstChildRules(); | |
61 } | |
62 | |
63 void SiblingRuleHelper::setChildrenAffectedByLastChildRules() | |
64 { | |
65 if (m_node->isElementNode()) | |
66 toElement(m_node)->setChildrenAffectedByLastChildRules(); | |
67 else | |
68 toShadowRoot(m_node)->setChildrenAffectedByLastChildRules(); | |
69 } | |
70 | |
71 bool SiblingRuleHelper::childrenAffectedByPositionalRules() const | |
72 { | |
73 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByPositi
onalRules() : toShadowRoot(m_node)->childrenAffectedByPositionalRules(); | |
74 } | |
75 | |
76 bool SiblingRuleHelper::childrenAffectedByFirstChildRules() const | |
77 { | |
78 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByFirstC
hildRules() : toShadowRoot(m_node)->childrenAffectedByFirstChildRules(); | |
79 } | |
80 | |
81 bool SiblingRuleHelper::childrenAffectedByLastChildRules() const | |
82 { | |
83 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByLastCh
ildRules() : toShadowRoot(m_node)->childrenAffectedByLastChildRules(); | |
84 } | |
85 | |
86 bool SiblingRuleHelper::childrenAffectedByDirectAdjacentRules() const | |
87 { | |
88 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByDirect
AdjacentRules() : toShadowRoot(m_node)->childrenAffectedByDirectAdjacentRules(); | |
89 } | |
90 | |
91 bool SiblingRuleHelper::childrenAffectedByIndirectAdjacentRules() const | |
92 { | |
93 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByIndire
ctAdjacentRules() : toShadowRoot(m_node)->childrenAffectedByIndirectAdjacentRule
s(); | |
94 } | |
95 | |
96 bool SiblingRuleHelper::childrenAffectedByForwardPositionalRules() const | |
97 { | |
98 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByForwar
dPositionalRules() : toShadowRoot(m_node)->childrenAffectedByForwardPositionalRu
les(); | |
99 } | |
100 | |
101 bool SiblingRuleHelper::childrenAffectedByBackwardPositionalRules() const | |
102 { | |
103 return m_node->isElementNode() ? toElement(m_node)->childrenAffectedByBackwa
rdPositionalRules() : toShadowRoot(m_node)->childrenAffectedByBackwardPositional
Rules(); | |
104 } | |
105 | |
106 void SiblingRuleHelper::checkForChildrenAdjacentRuleChanges() | |
107 { | |
108 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); | |
109 bool hasIndirectAdjacentRules = childrenAffectedByIndirectAdjacentRules(); | |
110 | |
111 if (!hasDirectAdjacentRules && !hasIndirectAdjacentRules) | |
112 return; | |
113 | |
114 unsigned forceCheckOfNextElementCount = 0; | |
115 bool forceCheckOfAnyElementSibling = false; | |
116 Document& document = m_node->document(); | |
117 | |
118 for (Node* child = m_node->firstChild(); child; child = child->nextSibling()
) { | |
119 if (!child->isElementNode()) | |
120 continue; | |
121 Element* element = toElement(child); | |
122 bool childRulesChanged = element->needsStyleRecalc() && element->styleCh
angeType() >= SubtreeStyleChange; | |
123 | |
124 if (forceCheckOfNextElementCount || forceCheckOfAnyElementSibling) | |
125 element->setNeedsStyleRecalc(SubtreeStyleChange); | |
126 | |
127 if (forceCheckOfNextElementCount) | |
128 forceCheckOfNextElementCount--; | |
129 | |
130 if (childRulesChanged && hasDirectAdjacentRules) | |
131 forceCheckOfNextElementCount = document.styleEngine()->maxDirectAdja
centSelectors(); | |
132 | |
133 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childR
ulesChanged && hasIndirectAdjacentRules); | |
134 } | |
135 } | |
136 | |
137 bool SiblingRuleHelper::childrenSupportStyleSharing() | |
138 { | |
139 return m_node->isElementNode() ? toElement(m_node)->childrenSupportStyleShar
ing() : toShadowRoot(m_node)->childrenSupportStyleSharing(); | |
140 } | |
141 | |
142 } // namespace WebCore | |
143 | |
OLD | NEW |