Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1463)

Side by Side Diff: Source/core/css/resolver/ScopedStyleResolver.cpp

Issue 16194002: Make ScopedStyleResolver use apply-author-styles of a given element's treescope. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rewrite layout test Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 for (ScopedStyleResolver* scopeResolver = scopedResolverFor(element); scopeR esolver; scopeResolver = scopeResolver->parent())
116 if (!scopeResolver) 116 resolvers.append(scopeResolver);
117 return;
118
119 bool applyAuthorStylesOfElementTreeScope = element->treeScope()->applyAuthor Styles();
120 bool applyAuthorStyles = m_cache.authorStyleBoundsIndex == m_cache.scopeReso lverBoundsIndex ? applyAuthorStylesOfElementTreeScope : false;
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 } 117 }
132 118
133 inline ScopedStyleResolver* ScopedStyleTree::enclosingScopedStyleResolverFor(con st ContainerNode* scope, int& authorStyleBoundsIndex) 119 inline ScopedStyleResolver* ScopedStyleTree::enclosingScopedStyleResolverFor(con st ContainerNode* scope)
134 { 120 {
135 for (; scope; scope = scope->parentOrShadowHostNode()) { 121 for (; scope; scope = scope->parentOrShadowHostNode())
136 if (ScopedStyleResolver* scopeStyleResolver = scopedStyleResolverFor(sco pe)) 122 if (ScopedStyleResolver* scopeStyleResolver = scopedStyleResolverFor(sco pe))
137 return scopeStyleResolver; 123 return scopeStyleResolver;
138 if (scope->isShadowRoot() && !toShadowRoot(scope)->applyAuthorStyles())
139 --authorStyleBoundsIndex;
140 }
141 return 0; 124 return 0;
142 } 125 }
143 126
144 void ScopedStyleTree::resolveStyleCache(const ContainerNode* scope) 127 void ScopedStyleTree::resolveStyleCache(const ContainerNode* scope)
145 { 128 {
146 int authorStyleBoundsIndex = 0; 129 m_cache.scopeResolver = enclosingScopedStyleResolverFor(scope);
147 m_cache.scopeResolver = enclosingScopedStyleResolverFor(scope, authorStyleBo undsIndex);
148 m_cache.scopeResolverBoundsIndex = authorStyleBoundsIndex;
149 m_cache.nodeForScopeStyles = scope; 130 m_cache.nodeForScopeStyles = scope;
150 m_cache.authorStyleBoundsIndex = 0;
151 } 131 }
152 132
153 void ScopedStyleTree::pushStyleCache(const ContainerNode* scope, const Container Node* parent) 133 void ScopedStyleTree::pushStyleCache(const ContainerNode* scope, const Container Node* parent)
154 { 134 {
155 if (m_authorStyles.isEmpty()) 135 if (m_authorStyles.isEmpty())
156 return; 136 return;
157 137
158 if (!cacheIsValid(parent)) { 138 if (!cacheIsValid(parent)) {
159 resolveStyleCache(scope); 139 resolveStyleCache(scope);
160 return; 140 return;
161 } 141 }
162 142
163 if (scope->isShadowRoot() && !toShadowRoot(scope)->applyAuthorStyles())
164 ++m_cache.authorStyleBoundsIndex;
165
166 ScopedStyleResolver* scopeResolver = scopedStyleResolverFor(scope); 143 ScopedStyleResolver* scopeResolver = scopedStyleResolverFor(scope);
167 if (scopeResolver) { 144 if (scopeResolver)
168 m_cache.scopeResolver = scopeResolver; 145 m_cache.scopeResolver = scopeResolver;
169 m_cache.scopeResolverBoundsIndex = m_cache.authorStyleBoundsIndex;
170 }
171 m_cache.nodeForScopeStyles = scope; 146 m_cache.nodeForScopeStyles = scope;
172 } 147 }
173 148
174 void ScopedStyleTree::popStyleCache(const ContainerNode* scope) 149 void ScopedStyleTree::popStyleCache(const ContainerNode* scope)
175 { 150 {
176 if (cacheIsValid(scope)) { 151 if (!cacheIsValid(scope))
177 bool needUpdateBoundsIndex = scope->isShadowRoot() && !toShadowRoot(scop e)->applyAuthorStyles(); 152 return;
178 153
179 if (m_cache.scopeResolver && m_cache.scopeResolver->scope() == scope) { 154 if (m_cache.scopeResolver && m_cache.scopeResolver->scope() == scope)
180 m_cache.scopeResolver = m_cache.scopeResolver->parent(); 155 m_cache.scopeResolver = m_cache.scopeResolver->parent();
181 if (needUpdateBoundsIndex) 156 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 } 157 }
189 158
190 void ScopedStyleTree::collectFeaturesTo(RuleFeatureSet& features) 159 void ScopedStyleTree::collectFeaturesTo(RuleFeatureSet& features)
191 { 160 {
192 for (HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator i t = m_authorStyles.begin(); it != m_authorStyles.end(); ++it) 161 for (HashMap<const ContainerNode*, OwnPtr<ScopedStyleResolver> >::iterator i t = m_authorStyles.begin(); it != m_authorStyles.end(); ++it)
193 it->value->collectFeaturesTo(features); 162 it->value->collectFeaturesTo(features);
194 } 163 }
195 164
196 void ScopedStyleTree::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) cons t 165 void ScopedStyleTree::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) cons t
197 { 166 {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 322 }
354 323
355 void ScopedStyleResolver::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 324 void ScopedStyleResolver::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
356 { 325 {
357 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); 326 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
358 info.addMember(m_authorStyle, "authorStyle"); 327 info.addMember(m_authorStyle, "authorStyle");
359 info.addMember(m_atHostRules, "atHostRules"); 328 info.addMember(m_atHostRules, "atHostRules");
360 } 329 }
361 330
362 } // namespace WebCore 331 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/ScopedStyleResolver.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698