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

Side by Side Diff: sky/engine/core/css/resolver/StyleResolver.cpp

Issue 836193003: Combine match methods on StyleResolver. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « sky/engine/core/css/resolver/StyleResolver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 void StyleResolver::clearStyleSharingList() 233 void StyleResolver::clearStyleSharingList()
234 { 234 {
235 m_styleSharingLists.resize(0); 235 m_styleSharingLists.resize(0);
236 } 236 }
237 237
238 StyleResolver::~StyleResolver() 238 StyleResolver::~StyleResolver()
239 { 239 {
240 } 240 }
241 241
242 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC ollector& collector, bool includeEmptyRules, Vector<RawPtr<ScopedStyleResolver>, 8>& resolvers, Vector<RawPtr<ScopedStyleResolver>, 8>& resolversInShadowTree) 242 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector)
243 { 243 {
244 collector.clearMatchedRules(); 244 collector.clearMatchedRules();
245 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1; 245 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1;
246 246
247 // TODO(esprehn): Eliminate CascadeScope and CascadeOrder.
247 CascadeScope cascadeScope = 0; 248 CascadeScope cascadeScope = 0;
248 CascadeOrder cascadeOrder = 0; 249 CascadeOrder cascadeOrder = 0;
249 250
250 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) 251 // TODO(esprehn): Remove this.
251 resolversInShadowTree.at(j)->collectMatchingAuthorRules(collector, inclu deEmptyRules, cascadeScope, cascadeOrder++); 252 bool includeEmptyRules = false;
252 253
253 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc ope()) 254 // TODO(esprehn): This can only match :host rules, we should just store
254 ++cascadeScope; 255 // them in a separate RuleSet.
255 cascadeOrder += resolvers.size(); 256 if (ShadowRoot* shadowRoot = element->shadowRoot())
256 for (unsigned i = 0; i < resolvers.size(); ++i) 257 shadowRoot->scopedStyleResolver().collectMatchingAuthorRules(collector, includeEmptyRules, cascadeScope, cascadeOrder++);
257 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules , cascadeScope++, --cascadeOrder); 258
259 ScopedStyleResolver& resolver = element->treeScope().scopedStyleResolver();
260 resolver.collectMatchingAuthorRules(collector, includeEmptyRules, cascadeSco pe, cascadeOrder);
258 261
259 collector.sortAndTransferMatchedRules(); 262 collector.sortAndTransferMatchedRules();
260 } 263 }
261
262 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules)
263 {
264 collector.clearMatchedRules();
265 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1;
266
267 Vector<RawPtr<ScopedStyleResolver>, 8> resolvers;
268 resolvers.append(&element->treeScope().scopedStyleResolver());
269
270 Vector<RawPtr<ScopedStyleResolver>, 8> resolversInShadowTree;
271 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree);
272 if (!resolversInShadowTree.isEmpty()) {
273 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res olvers, resolversInShadowTree);
274 return;
275 }
276
277 if (resolvers.isEmpty())
278 return;
279
280 CascadeScope cascadeScope = 0;
281 CascadeOrder cascadeOrder = resolvers.size();
282 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) {
283 ScopedStyleResolver* resolver = resolvers.at(i);
284 // FIXME: Need to clarify how to treat style scoped.
285 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, casca deScope++, resolver->treeScope() == element->treeScope() && resolver->treeScope( ).rootNode().isShadowRoot() ? 0 : cascadeOrder);
286 }
287
288 collector.sortAndTransferMatchedRules();
289 }
290 264
291 void StyleResolver::matchUARules(ElementRuleCollector& collector) 265 void StyleResolver::matchUARules(ElementRuleCollector& collector)
292 { 266 {
293 collector.setMatchingUARules(true); 267 collector.setMatchingUARules(true);
294 268
295 matchUARules(collector, &defaultStyles());
296
297 collector.setMatchingUARules(false);
298 }
299
300 void StyleResolver::matchUARules(ElementRuleCollector& collector, RuleSet* rules )
301 {
302 collector.clearMatchedRules(); 269 collector.clearMatchedRules();
303 collector.matchedResult().ranges.lastUARule = collector.matchedResult().matc hedProperties.size() - 1; 270 collector.matchedResult().ranges.lastUARule = collector.matchedResult().matc hedProperties.size() - 1;
304 271
305 RuleRange ruleRange = collector.matchedResult().ranges.UARuleRange(); 272 RuleRange ruleRange = collector.matchedResult().ranges.UARuleRange();
306 collector.collectMatchingRules(MatchRequest(rules), ruleRange); 273 collector.collectMatchingRules(MatchRequest(&defaultStyles()), ruleRange);
307 274
308 collector.sortAndTransferMatchedRules(); 275 collector.sortAndTransferMatchedRules();
276
277 collector.setMatchingUARules(false);
309 } 278 }
310 279
311 void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto r& collector) 280 void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto r& collector)
312 { 281 {
313 matchUARules(collector); 282 matchUARules(collector);
314 matchAuthorRules(state.element(), collector, false); 283 matchAuthorRules(state.element(), collector);
315 284
316 if (state.element()->isStyledElement()) { 285 if (state.element()->isStyledElement()) {
317 if (state.element()->inlineStyle()) { 286 if (state.element()->inlineStyle()) {
318 // Inline style is immutable as long as there is no CSSOM wrapper. 287 // Inline style is immutable as long as there is no CSSOM wrapper.
319 bool isInlineStyleCacheable = !state.element()->inlineStyle()->isMut able(); 288 bool isInlineStyleCacheable = !state.element()->inlineStyle()->isMut able();
320 collector.addElementStyleProperties(state.element()->inlineStyle(), isInlineStyleCacheable); 289 collector.addElementStyleProperties(state.element()->inlineStyle(), isInlineStyleCacheable);
321 } 290 }
322 } 291 }
323 } 292 }
324 293
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions); 505 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions);
537 506
538 // Start loading resources used by animations. 507 // Start loading resources used by animations.
539 loadPendingResources(state); 508 loadPendingResources(state);
540 509
541 ASSERT(!state.fontBuilder().fontDirty()); 510 ASSERT(!state.fontBuilder().fontDirty());
542 511
543 return true; 512 return true;
544 } 513 }
545 514
546 void StyleResolver::collectScopedResolversForHostedShadowTrees(const Element* el ement, Vector<RawPtr<ScopedStyleResolver>, 8>& resolvers)
547 {
548 ElementShadow* shadow = element->shadow();
549 if (!shadow)
550 return;
551
552 // Adding scoped resolver for active shadow roots for shadow host styling.
553 if (ShadowRoot* shadowRoot = shadow->shadowRoot())
554 resolvers.append(&shadowRoot->scopedStyleResolver());
555 }
556
557 void StyleResolver::styleTreeResolveScopedKeyframesRules(const Element* element, Vector<RawPtr<ScopedStyleResolver>, 8>& resolvers) 515 void StyleResolver::styleTreeResolveScopedKeyframesRules(const Element* element, Vector<RawPtr<ScopedStyleResolver>, 8>& resolvers)
558 { 516 {
559 // Add resolvers for shadow roots hosted by the given element. 517 // Add resolvers for shadow roots hosted by the given element.
560 collectScopedResolversForHostedShadowTrees(element, resolvers); 518 if (ShadowRoot* shadowRoot = element->shadowRoot())
519 resolvers.append(&shadowRoot->scopedStyleResolver());
561 resolvers.append(&element->treeScope().scopedStyleResolver()); 520 resolvers.append(&element->treeScope().scopedStyleResolver());
562 } 521 }
563 522
564 template <StyleResolver::StyleApplicationPass pass> 523 template <StyleResolver::StyleApplicationPass pass>
565 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Has hMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolations) 524 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Has hMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolations)
566 { 525 {
567 for (HashMap<CSSPropertyID, RefPtr<Interpolation> >::const_iterator iter = a ctiveInterpolations.begin(); iter != activeInterpolations.end(); ++iter) { 526 for (HashMap<CSSPropertyID, RefPtr<Interpolation> >::const_iterator iter = a ctiveInterpolations.begin(); iter != activeInterpolations.end(); ++iter) {
568 CSSPropertyID property = iter->key; 527 CSSPropertyID property = iter->key;
569 if (!isPropertyForPass<pass>(property)) 528 if (!isPropertyForPass<pass>(property))
570 continue; 529 continue;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 bool StyleResolver::mediaQueryAffectedByViewportChange() const 809 bool StyleResolver::mediaQueryAffectedByViewportChange() const
851 { 810 {
852 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { 811 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) {
853 if (m_medium->eval(m_viewportDependentMediaQueryResults[i]->expression() ) != m_viewportDependentMediaQueryResults[i]->result()) 812 if (m_medium->eval(m_viewportDependentMediaQueryResults[i]->expression() ) != m_viewportDependentMediaQueryResults[i]->result())
854 return true; 813 return true;
855 } 814 }
856 return false; 815 return false;
857 } 816 }
858 817
859 } // namespace blink 818 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/resolver/StyleResolver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698