OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 86 |
87 // Since StyleResolver creates RuleSets according to styles' document | 87 // Since StyleResolver creates RuleSets according to styles' document |
88 // order, a parent of the given ScopedRuleData has been already | 88 // order, a parent of the given ScopedRuleData has been already |
89 // prepared. | 89 // prepared. |
90 const ContainerNode* e = target->scope()->parentOrShadowHostNode(); | 90 const ContainerNode* e = target->scope()->parentOrShadowHostNode(); |
91 for (; e; e = e->parentOrShadowHostNode()) { | 91 for (; e; e = e->parentOrShadowHostNode()) { |
92 if (ScopedStyleResolver* scopeResolver = scopedStyleResolverFor(e)) { | 92 if (ScopedStyleResolver* scopeResolver = scopedStyleResolverFor(e)) { |
93 target->setParent(scopeResolver); | 93 target->setParent(scopeResolver); |
94 break; | 94 break; |
95 } | 95 } |
96 if (e->isShadowRoot() || e->isDocumentNode()) { | 96 if (e->isDocumentNode()) { |
97 bool dummy; | 97 bool dummy; |
98 ScopedStyleResolver* scopeResolver = addScopedStyleResolver(e, dummy ); | 98 ScopedStyleResolver* scopeResolver = addScopedStyleResolver(e, dummy ); |
99 target->setParent(scopeResolver); | 99 target->setParent(scopeResolver); |
100 setupScopeStylesTree(scopeResolver); | 100 setupScopeStylesTree(scopeResolver); |
101 break; | 101 break; |
102 } | 102 } |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 void ScopedStyleTree::clear() | 106 void ScopedStyleTree::clear() |
107 { | 107 { |
108 m_authorStyles.clear(); | 108 m_authorStyles.clear(); |
109 m_scopeResolverForDocument = 0; | 109 m_scopeResolverForDocument = 0; |
110 m_cache.clear(); | 110 m_cache.clear(); |
111 } | 111 } |
112 | 112 |
113 void ScopedStyleTree::resolveScopeStyles(const Element* element, Vector<std::pai r<ScopedStyleResolver*, bool>, 8>& resolvers) | 113 void ScopedStyleTree::resolveScopeStyles(const Element* element, Vector<ScopedSt yleResolver*, 8>& resolvers) |
114 { | 114 { |
115 ScopedStyleResolver* scopeResolver = scopedResolverFor(element); | 115 ScopedStyleResolver* scopeResolver = scopedResolverFor(element); |
116 if (!scopeResolver) | 116 if (!scopeResolver) |
117 return; | 117 return; |
118 | 118 |
119 bool applyAuthorStylesOfElementTreeScope = element->treeScope()->applyAuthor Styles(); | 119 for ( ; scopeResolver; scopeResolver = scopeResolver->parent()) |
hayato
2013/05/29 11:16:27
Now we can remove L115-L117, that can be merged to
tasak
2013/05/31 10:06:58
Done.
| |
120 bool applyAuthorStyles = m_cache.authorStyleBoundsIndex == m_cache.scopeReso lverBoundsIndex ? applyAuthorStylesOfElementTreeScope : false; | 120 resolvers.append(scopeResolver); |
121 | |
122 for ( ; scopeResolver; scopeResolver = scopeResolver->parent()) { | |
123 resolvers.append(std::pair<ScopedStyleResolver*, bool>(scopeResolver, ap plyAuthorStyles)); | |
124 if (scopeResolver->scope()->isShadowRoot()) { | |
125 if (scopeResolver->parent()->scope()->isInShadowTree()) | |
126 applyAuthorStyles = applyAuthorStyles && toShadowRoot(scopeResol ver->scope())->applyAuthorStyles(); | |
127 else | |
128 applyAuthorStyles = applyAuthorStylesOfElementTreeScope; | |
129 } | |
130 } | |
131 } | 121 } |
132 | 122 |
133 inline ScopedStyleResolver* ScopedStyleTree::enclosingScopedStyleResolverFor(con st ContainerNode* scope, int& authorStyleBoundsIndex) | 123 inline ScopedStyleResolver* ScopedStyleTree::enclosingScopedStyleResolverFor(con st ContainerNode* scope) |
134 { | 124 { |
135 for (; scope; scope = scope->parentOrShadowHostNode()) { | 125 for (; scope; scope = scope->parentOrShadowHostNode()) |
136 if (ScopedStyleResolver* scopeStyleResolver = scopedStyleResolverFor(sco pe)) | 126 if (ScopedStyleResolver* scopeStyleResolver = scopedStyleResolverFor(sco pe)) |
137 return scopeStyleResolver; | 127 return scopeStyleResolver; |
138 if (scope->isShadowRoot() && !toShadowRoot(scope)->applyAuthorStyles()) | |
139 --authorStyleBoundsIndex; | |
140 } | |
141 return 0; | 128 return 0; |
142 } | 129 } |
143 | 130 |
144 void ScopedStyleTree::resolveStyleCache(const ContainerNode* scope) | 131 void ScopedStyleTree::resolveStyleCache(const ContainerNode* scope) |
145 { | 132 { |
146 int authorStyleBoundsIndex = 0; | 133 m_cache.scopeResolver = enclosingScopedStyleResolverFor(scope); |
147 m_cache.scopeResolver = enclosingScopedStyleResolverFor(scope, authorStyleBo undsIndex); | |
148 m_cache.scopeResolverBoundsIndex = authorStyleBoundsIndex; | |
149 m_cache.nodeForScopeStyles = scope; | 134 m_cache.nodeForScopeStyles = scope; |
150 m_cache.authorStyleBoundsIndex = 0; | |
151 } | 135 } |
152 | 136 |
153 void ScopedStyleTree::pushStyleCache(const ContainerNode* scope, const Container Node* parent) | 137 void ScopedStyleTree::pushStyleCache(const ContainerNode* scope, const Container Node* parent) |
154 { | 138 { |
155 if (m_authorStyles.isEmpty()) | 139 if (m_authorStyles.isEmpty()) |
156 return; | 140 return; |
157 | 141 |
158 if (!cacheIsValid(parent)) { | 142 if (!cacheIsValid(parent)) { |
159 resolveStyleCache(scope); | 143 resolveStyleCache(scope); |
160 return; | 144 return; |
161 } | 145 } |
162 | 146 |
163 if (scope->isShadowRoot() && !toShadowRoot(scope)->applyAuthorStyles()) | |
164 ++m_cache.authorStyleBoundsIndex; | |
165 | |
166 ScopedStyleResolver* scopeResolver = scopedStyleResolverFor(scope); | 147 ScopedStyleResolver* scopeResolver = scopedStyleResolverFor(scope); |
167 if (scopeResolver) { | 148 if (scopeResolver) |
168 m_cache.scopeResolver = scopeResolver; | 149 m_cache.scopeResolver = scopeResolver; |
169 m_cache.scopeResolverBoundsIndex = m_cache.authorStyleBoundsIndex; | |
170 } | |
171 m_cache.nodeForScopeStyles = scope; | 150 m_cache.nodeForScopeStyles = scope; |
172 } | 151 } |
173 | 152 |
174 void ScopedStyleTree::popStyleCache(const ContainerNode* scope) | 153 void ScopedStyleTree::popStyleCache(const ContainerNode* scope) |
175 { | 154 { |
176 if (cacheIsValid(scope)) { | 155 if (!cacheIsValid(scope)) |
177 bool needUpdateBoundsIndex = scope->isShadowRoot() && !toShadowRoot(scop e)->applyAuthorStyles(); | 156 return; |
178 | 157 |
179 if (m_cache.scopeResolver && m_cache.scopeResolver->scope() == scope) { | 158 if (m_cache.scopeResolver && m_cache.scopeResolver->scope() == scope) |
180 m_cache.scopeResolver = m_cache.scopeResolver->parent(); | 159 m_cache.scopeResolver = m_cache.scopeResolver->parent(); |
181 if (needUpdateBoundsIndex) | 160 m_cache.nodeForScopeStyles = scope->parentOrShadowHostNode(); |
182 --m_cache.scopeResolverBoundsIndex; | |
183 } | |
184 if (needUpdateBoundsIndex) | |
185 --m_cache.authorStyleBoundsIndex; | |
186 m_cache.nodeForScopeStyles = scope->parentOrShadowHostNode(); | |
187 } | |
188 } | 161 } |
189 | 162 |
190 void ScopedStyleTree::collectFeaturesTo(RuleFeatureSet& features) | 163 void ScopedStyleTree::collectFeaturesTo(RuleFeatureSet& features) |
191 { | 164 { |
192 for (HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator i t = m_authorStyles.begin(); it != m_authorStyles.end(); ++it) | 165 for (HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator i t = m_authorStyles.begin(); it != m_authorStyles.end(); ++it) |
193 it->value->collectFeaturesTo(features); | 166 it->value->collectFeaturesTo(features); |
194 } | 167 } |
195 | 168 |
196 void ScopedStyleTree::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) cons t | 169 void ScopedStyleTree::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) cons t |
197 { | 170 { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 } | 326 } |
354 | 327 |
355 void ScopedStyleResolver::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 328 void ScopedStyleResolver::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
356 { | 329 { |
357 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 330 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
358 info.addMember(m_authorStyle, "authorStyle"); | 331 info.addMember(m_authorStyle, "authorStyle"); |
359 info.addMember(m_atHostRules, "atHostRules"); | 332 info.addMember(m_atHostRules, "atHostRules"); |
360 } | 333 } |
361 | 334 |
362 } // namespace WebCore | 335 } // namespace WebCore |
OLD | NEW |