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

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

Issue 1224673002: Implement proposed shadow tree cascade order. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added documentation Created 5 years, 4 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
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 static StylePropertySet* rightToLeftDeclaration() 118 static StylePropertySet* rightToLeftDeclaration()
119 { 119 {
120 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(MutableStylePropertySet, rightToLeftDec l, (MutableStylePropertySet::create())); 120 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(MutableStylePropertySet, rightToLeftDec l, (MutableStylePropertySet::create()));
121 if (rightToLeftDecl->isEmpty()) 121 if (rightToLeftDecl->isEmpty())
122 rightToLeftDecl->setProperty(CSSPropertyDirection, CSSValueRtl); 122 rightToLeftDecl->setProperty(CSSPropertyDirection, CSSValueRtl);
123 return rightToLeftDecl; 123 return rightToLeftDecl;
124 } 124 }
125 125
126 static void collectScopedResolversForHostedShadowTrees(const Element* element, W illBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8>& resolvers)
127 {
128 ElementShadow* shadow = element->shadow();
129 if (!shadow)
130 return;
131
132 // Adding scoped resolver for active shadow roots for shadow host styling.
133 for (ShadowRoot* shadowRoot = shadow->youngestShadowRoot(); shadowRoot; shad owRoot = shadowRoot->olderShadowRoot()) {
134 if (shadowRoot->numberOfStyles() > 0) {
135 if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver( ))
136 resolvers.append(resolver);
137 }
138 }
139 }
140
141 StyleResolver::StyleResolver(Document& document) 126 StyleResolver::StyleResolver(Document& document)
142 : m_document(document) 127 : m_document(document)
143 , m_viewportStyleResolver(ViewportStyleResolver::create(&document)) 128 , m_viewportStyleResolver(ViewportStyleResolver::create(&document))
144 , m_needCollectFeatures(false) 129 , m_needCollectFeatures(false)
145 , m_printMediaType(false) 130 , m_printMediaType(false)
146 , m_styleResourceLoader(&document) 131 , m_styleResourceLoader(&document)
147 , m_styleSharingDepth(0) 132 , m_styleSharingDepth(0)
148 , m_accessCount(0) 133 , m_accessCount(0)
149 { 134 {
150 FrameView* view = document.view(); 135 FrameView* view = document.view();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 { 215 {
231 // Need to recreate RuleFeatureSet. 216 // Need to recreate RuleFeatureSet.
232 m_features.clear(); 217 m_features.clear();
233 m_siblingRuleSet.clear(); 218 m_siblingRuleSet.clear();
234 m_uncommonAttributeRuleSet.clear(); 219 m_uncommonAttributeRuleSet.clear();
235 m_needCollectFeatures = true; 220 m_needCollectFeatures = true;
236 } 221 }
237 222
238 void StyleResolver::addTreeBoundaryCrossingScope(ContainerNode& scope) 223 void StyleResolver::addTreeBoundaryCrossingScope(ContainerNode& scope)
239 { 224 {
240 m_treeBoundaryCrossingRules.addScope(scope); 225 m_treeBoundaryCrossingScopes.add(&scope);
241 } 226 }
242 227
243 void StyleResolver::resetAuthorStyle(TreeScope& treeScope) 228 void StyleResolver::resetAuthorStyle(TreeScope& treeScope)
244 { 229 {
245 m_treeBoundaryCrossingRules.removeScope(treeScope.rootNode()); 230 m_treeBoundaryCrossingScopes.remove(&treeScope.rootNode());
246 231
247 ScopedStyleResolver* resolver = treeScope.scopedStyleResolver(); 232 ScopedStyleResolver* resolver = treeScope.scopedStyleResolver();
248 if (!resolver) 233 if (!resolver)
249 return; 234 return;
250 235
251 resetRuleFeatures(); 236 resetRuleFeatures();
252 237
253 if (treeScope.rootNode().isDocumentNode()) { 238 if (treeScope.rootNode().isDocumentNode()) {
254 resolver->resetAuthorStyle(); 239 resolver->resetAuthorStyle();
255 return; 240 return;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 321
337 void StyleResolver::popParentElement(Element& parent) 322 void StyleResolver::popParentElement(Element& parent)
338 { 323 {
339 m_selectorFilter.popParent(parent); 324 m_selectorFilter.popParent(parent);
340 } 325 }
341 326
342 StyleResolver::~StyleResolver() 327 StyleResolver::~StyleResolver()
343 { 328 {
344 } 329 }
345 330
346 static inline ScopedStyleResolver* scopedResolverFor(const Element* element) 331 static inline ScopedStyleResolver* scopedResolverFor(const Element& element)
347 { 332 {
348 // Ideally, returning element->treeScope().scopedStyleResolver() should be 333 // Ideally, returning element->treeScope().scopedStyleResolver() should be
349 // enough, but ::cue and custom pseudo elements like ::-webkit-meter-bar pie rce 334 // enough, but ::cue and custom pseudo elements like ::-webkit-meter-bar pie rce
350 // through a shadow dom boundary, yet they are not part of m_treeBoundaryCro ssingRules. 335 // through a shadow dom boundary, yet they are not part of m_treeBoundaryCro ssingScopes.
351 // The assumption here is that these rules only pierce through one boundary and 336 // The assumption here is that these rules only pierce through one boundary and
352 // that the scope of these elements do not have a style resolver due to the fact 337 // that the scope of these elements do not have a style resolver due to the fact
353 // that VTT scopes and UA shadow trees don't have <style> elements. This is 338 // that VTT scopes and UA shadow trees don't have <style> elements. This is
354 // backed up by the ASSERTs below. 339 // backed up by the ASSERTs below.
355 // 340 //
356 // FIXME: Make ::cue and custom pseudo elements part of boundary crossing ru les 341 // FIXME: Make ::cue and custom pseudo elements part of boundary crossing ru les
357 // when moving those rules to ScopedStyleResolver as part of issue 401359. 342 // when moving those rules to ScopedStyleResolver as part of issue 401359.
358 343
359 TreeScope* treeScope = &element->treeScope(); 344 TreeScope* treeScope = &element.treeScope();
360 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) { 345 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) {
361 ASSERT(element->shadowPseudoId().isEmpty()); 346 ASSERT(element.shadowPseudoId().isEmpty());
362 ASSERT(!element->isVTTElement()); 347 ASSERT(!element.isVTTElement());
363 return resolver; 348 return resolver;
364 } 349 }
365 350
366 treeScope = treeScope->parentTreeScope(); 351 treeScope = treeScope->parentTreeScope();
367 if (!treeScope) 352 if (!treeScope)
368 return nullptr; 353 return nullptr;
369 if (element->shadowPseudoId().isEmpty() && !element->isVTTElement()) 354 if (element.shadowPseudoId().isEmpty() && !element.isVTTElement())
370 return nullptr; 355 return nullptr;
371 return treeScope->scopedStyleResolver(); 356 return treeScope->scopedStyleResolver();
372 } 357 }
373 358
374 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules) 359 void StyleResolver::matchHostRules(const Element& element, ElementRuleCollector& collector, bool includeEmptyRules)
375 { 360 {
376 collector.clearMatchedRules(); 361 ElementShadow* shadow = element.shadow();
362 if (!shadow)
363 return;
377 364
378 CascadeOrder cascadeOrder = 0; 365 // Adding scoped resolvers for active shadow roots for shadow host styling.
379 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree; 366 for (ShadowRoot* shadowRoot = shadow->oldestShadowRoot(); shadowRoot; shadow Root = shadowRoot->youngerShadowRoot()) {
380 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree); 367 if (!shadowRoot->numberOfStyles())
368 continue;
369 if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver()) {
370 collector.clearMatchedRules();
371 resolver->collectMatchingShadowHostRules(collector, includeEmptyRule s);
372 collector.sortAndTransferMatchedRules();
373 collector.closeOriginOrScope();
374 }
375 }
376 }
381 377
382 // Apply :host and :host-context rules from inner scopes. 378 ScopedStyleResolver* StyleResolver::matchElementScopeRules(const Element& elemen t, ElementRuleCollector& collector, bool includeEmptyRules)
kochi 2015/08/10 12:15:03 Can this be a static function, rather than a priva
383 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) 379 {
384 resolversInShadowTree.at(j)->collectMatchingShadowHostRules(collector, i ncludeEmptyRules, ++cascadeOrder); 380 ScopedStyleResolver* resolver = scopedResolverFor(element);
381 if (resolver) {
382 collector.clearMatchedRules();
383 resolver->collectMatchingAuthorRules(collector, includeEmptyRules);
384 resolver->collectMatchingTreeBoundaryCrossingRules(collector, includeEmp tyRules);
385 collector.sortAndTransferMatchedRules();
386 }
387 collector.closeOriginOrScope();
388 return resolver;
389 }
385 390
386 // Apply normal rules from element scope. 391 void StyleResolver::matchScopedRules(const Element& element, ElementRuleCollecto r& collector, bool includeEmptyRules)
387 if (ScopedStyleResolver* resolver = scopedResolverFor(element)) 392 {
388 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, ++cas cadeOrder); 393 bool matchElementScope = true;
389 394
390 // Apply /deep/ and ::shadow rules from outer scopes, and ::content from inn er. 395 for (auto it = m_treeBoundaryCrossingScopes.rbegin(); it != m_treeBoundaryCr ossingScopes.rend(); ++it) {
391 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules); 396 const TreeScope& scope = (*it)->treeScope();
392 collector.sortAndTransferMatchedRules(); 397 ScopedStyleResolver* resolver = scope.scopedStyleResolver();
398 ASSERT(resolver);
399
400 if (matchElementScope && scope.isInclusiveAncestorOf(element.treeScope() )) {
401 matchElementScope = false;
402 if (matchElementScopeRules(element, collector, includeEmptyRules) == resolver)
403 continue;
404 }
405
406 collector.clearMatchedRules();
407 resolver->collectMatchingTreeBoundaryCrossingRules(collector, includeEmp tyRules);
408 collector.sortAndTransferMatchedRules();
409 collector.closeOriginOrScope();
410 }
411
412 if (matchElementScope)
413 matchElementScopeRules(element, collector, includeEmptyRules);
414 }
415
416 void StyleResolver::matchAuthorRules(const Element& element, ElementRuleCollecto r& collector, bool includeEmptyRules)
417 {
418 matchHostRules(element, collector, includeEmptyRules);
419 matchScopedRules(element, collector, includeEmptyRules);
393 } 420 }
394 421
395 void StyleResolver::matchUARules(ElementRuleCollector& collector) 422 void StyleResolver::matchUARules(ElementRuleCollector& collector)
396 { 423 {
397 collector.setMatchingUARules(true); 424 collector.setMatchingUARules(true);
398 425
399 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( ); 426 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( );
400 RuleSet* userAgentStyleSheet = m_printMediaType ? defaultStyleSheets.default PrintStyle() : defaultStyleSheets.defaultStyle(); 427 RuleSet* userAgentStyleSheet = m_printMediaType ? defaultStyleSheets.default PrintStyle() : defaultStyleSheets.defaultStyle();
401 matchRuleSet(collector, userAgentStyleSheet); 428 matchRuleSet(collector, userAgentStyleSheet);
402 429
403 // In quirks mode, we match rules from the quirks user agent sheet. 430 // In quirks mode, we match rules from the quirks user agent sheet.
404 if (document().inQuirksMode()) 431 if (document().inQuirksMode())
405 matchRuleSet(collector, defaultStyleSheets.defaultQuirksStyle()); 432 matchRuleSet(collector, defaultStyleSheets.defaultQuirksStyle());
406 433
407 // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet. 434 // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet.
408 if (document().isViewSource()) 435 if (document().isViewSource())
409 matchRuleSet(collector, defaultStyleSheets.defaultViewSourceStyle()); 436 matchRuleSet(collector, defaultStyleSheets.defaultViewSourceStyle());
410 437
438 collector.closeOriginOrScope();
411 collector.setMatchingUARules(false); 439 collector.setMatchingUARules(false);
412 } 440 }
413 441
414 void StyleResolver::matchRuleSet(ElementRuleCollector& collector, RuleSet* rules ) 442 void StyleResolver::matchRuleSet(ElementRuleCollector& collector, RuleSet* rules )
415 { 443 {
416 collector.clearMatchedRules(); 444 collector.clearMatchedRules();
417 collector.collectMatchingRules(MatchRequest(rules)); 445 collector.collectMatchingRules(MatchRequest(rules));
418 collector.sortAndTransferMatchedRules(); 446 collector.sortAndTransferMatchedRules();
447 collector.closeOriginOrScope();
419 } 448 }
420 449
421 void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto r& collector, bool includeSMILProperties) 450 void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto r& collector, bool includeSMILProperties)
422 { 451 {
423 matchUARules(collector); 452 matchUARules(collector);
424 453
425 // Now check author rules, beginning first with presentational attributes ma pped from HTML. 454 // Now check author rules, beginning first with presentational attributes ma pped from HTML.
426 if (state.element()->isStyledElement()) { 455 if (state.element()->isStyledElement()) {
427 collector.addElementStyleProperties(state.element()->presentationAttribu teStyle()); 456 collector.addElementStyleProperties(state.element()->presentationAttribu teStyle());
428 457
429 // Now we check additional mapped declarations. 458 // Now we check additional mapped declarations.
430 // Tables and table cells share an additional mapped rule that must be a pplied 459 // Tables and table cells share an additional mapped rule that must be a pplied
431 // after all attributes, since their mapped style depends on the values of multiple attributes. 460 // after all attributes, since their mapped style depends on the values of multiple attributes.
432 collector.addElementStyleProperties(state.element()->additionalPresentat ionAttributeStyle()); 461 collector.addElementStyleProperties(state.element()->additionalPresentat ionAttributeStyle());
433 462
434 if (state.element()->isHTMLElement()) { 463 if (state.element()->isHTMLElement()) {
435 bool isAuto; 464 bool isAuto;
436 TextDirection textDirection = toHTMLElement(state.element())->direct ionalityIfhasDirAutoAttribute(isAuto); 465 TextDirection textDirection = toHTMLElement(state.element())->direct ionalityIfhasDirAutoAttribute(isAuto);
437 if (isAuto) { 466 if (isAuto) {
438 state.setHasDirAutoAttribute(true); 467 state.setHasDirAutoAttribute(true);
439 collector.addElementStyleProperties(textDirection == LTR ? leftT oRightDeclaration() : rightToLeftDeclaration()); 468 collector.addElementStyleProperties(textDirection == LTR ? leftT oRightDeclaration() : rightToLeftDeclaration());
440 } 469 }
441 } 470 }
442 } 471 }
443 472
444 matchAuthorRules(state.element(), collector, false); 473 matchAuthorRules(*state.element(), collector, false);
445 474
446 if (state.element()->isStyledElement()) { 475 if (state.element()->isStyledElement()) {
476 // TODO(rune@opera.com): Adding style attribute rules here is probably t oo late
477 // when you have shadow piercing combinators. When we don't have piercin g combinators,
478 // the style attribute always belong to the outermost scope whose rules apply to
479 // the element. Thus, applying inline style here is correct. Fixing this for piercing
480 // combinators means moving the code below into matchElementScopeRules a nd _not_
481 // invoking it for pseudo style requests.
447 if (state.element()->inlineStyle()) { 482 if (state.element()->inlineStyle()) {
448 // Inline style is immutable as long as there is no CSSOM wrapper. 483 // Inline style is immutable as long as there is no CSSOM wrapper.
449 bool isInlineStyleCacheable = !state.element()->inlineStyle()->isMut able(); 484 bool isInlineStyleCacheable = !state.element()->inlineStyle()->isMut able();
450 collector.addElementStyleProperties(state.element()->inlineStyle(), isInlineStyleCacheable); 485 collector.addElementStyleProperties(state.element()->inlineStyle(), isInlineStyleCacheable);
451 } 486 }
452 487
453 // Now check SMIL animation override style. 488 // Now check SMIL animation override style.
454 if (includeSMILProperties && state.element()->isSVGElement()) 489 if (includeSMILProperties && state.element()->isSVGElement())
455 collector.addElementStyleProperties(toSVGElement(state.element())->a nimatedSMILStyleProperties(), false /* isCacheable */); 490 collector.addElementStyleProperties(toSVGElement(state.element())->a nimatedSMILStyleProperties(), false /* isCacheable */);
491
492 collector.closeOriginOrScope();
456 } 493 }
457 } 494 }
458 495
459 PassRefPtr<ComputedStyle> StyleResolver::styleForDocument(Document& document) 496 PassRefPtr<ComputedStyle> StyleResolver::styleForDocument(Document& document)
460 { 497 {
461 const LocalFrame* frame = document.frame(); 498 const LocalFrame* frame = document.frame();
462 499
463 RefPtr<ComputedStyle> documentStyle = ComputedStyle::create(); 500 RefPtr<ComputedStyle> documentStyle = ComputedStyle::create();
464 documentStyle->setRTLOrdering(document.visuallyOrdered() ? VisualOrder : Log icalOrder); 501 documentStyle->setRTLOrdering(document.visuallyOrdered() ? VisualOrder : Log icalOrder);
465 documentStyle->setZoom(frame && !document.printing() ? frame->pageZoomFactor () : 1); 502 documentStyle->setZoom(frame && !document.printing() ? frame->pageZoomFactor () : 1);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 777
741 // Since we don't use pseudo-elements in any of our quirk/print 778 // Since we don't use pseudo-elements in any of our quirk/print
742 // user agent rules, don't waste time walking those rules. 779 // user agent rules, don't waste time walking those rules.
743 780
744 if (!baseComputedStyle) { 781 if (!baseComputedStyle) {
745 // Check UA, user and author rules. 782 // Check UA, user and author rules.
746 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); 783 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style());
747 collector.setPseudoStyleRequest(pseudoStyleRequest); 784 collector.setPseudoStyleRequest(pseudoStyleRequest);
748 785
749 matchUARules(collector); 786 matchUARules(collector);
750 matchAuthorRules(state.element(), collector, false); 787 matchAuthorRules(*state.element(), collector, false);
751 788
752 if (collector.matchedResult().matchedProperties.isEmpty()) 789 if (!collector.matchedResult().hasMatchedProperties())
753 return false; 790 return false;
754 791
755 applyMatchedProperties(state, collector.matchedResult()); 792 applyMatchedProperties(state, collector.matchedResult());
756 applyCallbackSelectors(state); 793 applyCallbackSelectors(state);
757 794
758 // Cache our original display. 795 // Cache our original display.
759 state.style()->setOriginalDisplay(state.style()->display()); 796 state.style()->setOriginalDisplay(state.style()->display());
760 797
761 // FIXME: Passing 0 as the Element* introduces a lot of complexity 798 // FIXME: Passing 0 as the Element* introduces a lot of complexity
762 // in the adjustComputedStyle code. 799 // in the adjustComputedStyle code.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 PageRuleCollector collector(rootElementStyle, pageIndex); 852 PageRuleCollector collector(rootElementStyle, pageIndex);
816 853
817 collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle ()); 854 collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle ());
818 855
819 if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver()) 856 if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver())
820 scopedResolver->matchPageRules(collector); 857 scopedResolver->matchPageRules(collector);
821 858
822 bool inheritedOnly = false; 859 bool inheritedOnly = false;
823 860
824 const MatchResult& result = collector.matchedResult(); 861 const MatchResult& result = collector.matchedResult();
825 applyMatchedProperties<HighPropertyPriority>(state, result, false, result.be gin(), result.end(), inheritedOnly); 862 applyMatchedProperties<HighPropertyPriority>(state, result.allRules(), false , inheritedOnly);
826 863
827 // If our font got dirtied, go ahead and update it now. 864 // If our font got dirtied, go ahead and update it now.
828 updateFont(state); 865 updateFont(state);
829 866
830 applyMatchedProperties<LowPropertyPriority>(state, result, false, result.beg in(), result.end(), inheritedOnly); 867 applyMatchedProperties<LowPropertyPriority>(state, result.allRules(), false, inheritedOnly);
831 868
832 loadPendingResources(state); 869 loadPendingResources(state);
833 870
834 didAccess(); 871 didAccess();
835 872
836 // Now return the style. 873 // Now return the style.
837 return state.takeStyle(); 874 return state.takeStyle();
838 } 875 }
839 876
840 PassRefPtr<ComputedStyle> StyleResolver::initialStyleForElement() 877 PassRefPtr<ComputedStyle> StyleResolver::initialStyleForElement()
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 927
891 void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo llector& collector, PseudoId pseudoId, unsigned rulesToInclude) 928 void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo llector& collector, PseudoId pseudoId, unsigned rulesToInclude)
892 { 929 {
893 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); 930 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
894 931
895 if (rulesToInclude & UAAndUserCSSRules) 932 if (rulesToInclude & UAAndUserCSSRules)
896 matchUARules(collector); 933 matchUARules(collector);
897 934
898 if (rulesToInclude & AuthorCSSRules) { 935 if (rulesToInclude & AuthorCSSRules) {
899 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); 936 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
900 matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules); 937 matchAuthorRules(*element, collector, rulesToInclude & EmptyCSSRules);
901 } 938 }
902 } 939 }
903 940
904 // ----------------------------------------------------------------------------- -------- 941 // ----------------------------------------------------------------------------- --------
905 // this is mostly boring stuff on how to apply a certain rule to the Computedsty le... 942 // this is mostly boring stuff on how to apply a certain rule to the Computedsty le...
906 943
907 bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Ele ment* animatingElement) 944 bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Ele ment* animatingElement)
908 { 945 {
909 Element* element = state.element(); 946 Element* element = state.element();
910 ASSERT(element); 947 ASSERT(element);
(...skipping 22 matching lines...) Expand all
933 applyAnimatedProperties<LowPropertyPriority>(state, activeInterpolationsForT ransitions); 970 applyAnimatedProperties<LowPropertyPriority>(state, activeInterpolationsForT ransitions);
934 971
935 // Start loading resources used by animations. 972 // Start loading resources used by animations.
936 loadPendingResources(state); 973 loadPendingResources(state);
937 974
938 ASSERT(!state.fontBuilder().fontDirty()); 975 ASSERT(!state.fontBuilder().fontDirty());
939 976
940 return true; 977 return true;
941 } 978 }
942 979
980 static void collectScopedResolversForHostedShadowTrees(const Element& element, W illBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8>& resolvers)
981 {
982 ElementShadow* shadow = element.shadow();
983 if (!shadow)
984 return;
985
986 // Adding scoped resolver for active shadow roots for shadow host styling.
987 for (ShadowRoot* shadowRoot = shadow->youngestShadowRoot(); shadowRoot; shad owRoot = shadowRoot->olderShadowRoot()) {
988 if (shadowRoot->numberOfStyles() > 0) {
989 if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver( ))
990 resolvers.append(resolver);
991 }
992 }
993 }
994
943 StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* element, con st AtomicString& animationName) 995 StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* element, con st AtomicString& animationName)
944 { 996 {
945 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers; 997 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers;
946 collectScopedResolversForHostedShadowTrees(element, resolvers); 998 collectScopedResolversForHostedShadowTrees(*element, resolvers);
947 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver()) 999 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver())
948 resolvers.append(scopedResolver); 1000 resolvers.append(scopedResolver);
949 1001
950 for (size_t i = 0; i < resolvers.size(); ++i) { 1002 for (size_t i = 0; i < resolvers.size(); ++i) {
951 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA nimation(animationName.impl())) 1003 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA nimation(animationName.impl()))
952 return keyframesRule; 1004 return keyframesRule;
953 } 1005 }
954 return nullptr; 1006 return nullptr;
955 } 1007 }
956 1008
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } 1270 }
1219 1271
1220 if (!CSSPropertyPriorityData<priority>::propertyHasPriority(property)) 1272 if (!CSSPropertyPriorityData<priority>::propertyHasPriority(property))
1221 continue; 1273 continue;
1222 1274
1223 StyleBuilder::applyProperty(current.id(), state, current.value()); 1275 StyleBuilder::applyProperty(current.id(), state, current.value());
1224 } 1276 }
1225 } 1277 }
1226 1278
1227 template <CSSPropertyPriority priority> 1279 template <CSSPropertyPriority priority>
1228 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, unsigned startIndex, unsigned endIndex, bool inheritedOnly) 1280 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hedPropertiesRange& range, bool isImportant, bool inheritedOnly)
1229 { 1281 {
1230 if (startIndex == endIndex) 1282 if (range.begin() == range.end())
1231 return; 1283 return;
1232 1284
1233 ASSERT_WITH_SECURITY_IMPLICATION(endIndex <= matchResult.matchedProperties.s ize());
1234
1235 if (state.style()->insideLink() != NotInsideLink) { 1285 if (state.style()->insideLink() != NotInsideLink) {
1236 for (unsigned i = startIndex; i < endIndex; ++i) { 1286 for (const auto& matchedProperties : range) {
1237 const MatchedProperties& matchedProperties = matchResult.matchedProp erties[i];
1238 unsigned linkMatchType = matchedProperties.m_types.linkMatchType; 1287 unsigned linkMatchType = matchedProperties.m_types.linkMatchType;
1239 // FIXME: It would be nicer to pass these as arguments but that requ ires changes in many places. 1288 // FIXME: It would be nicer to pass these as arguments but that requ ires changes in many places.
1240 state.setApplyPropertyToRegularStyle(linkMatchType & CSSSelector::Ma tchLink); 1289 state.setApplyPropertyToRegularStyle(linkMatchType & CSSSelector::Ma tchLink);
1241 state.setApplyPropertyToVisitedLinkStyle(linkMatchType & CSSSelector ::MatchVisited); 1290 state.setApplyPropertyToVisitedLinkStyle(linkMatchType & CSSSelector ::MatchVisited);
1242 1291
1243 applyProperties<priority>(state, matchedProperties.properties.get(), isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedPropertie s.m_types.whitelistType)); 1292 applyProperties<priority>(state, matchedProperties.properties.get(), isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedPropertie s.m_types.whitelistType));
1244 } 1293 }
1245 state.setApplyPropertyToRegularStyle(true); 1294 state.setApplyPropertyToRegularStyle(true);
1246 state.setApplyPropertyToVisitedLinkStyle(false); 1295 state.setApplyPropertyToVisitedLinkStyle(false);
1247 return; 1296 return;
1248 } 1297 }
1249 for (unsigned i = startIndex; i < endIndex; ++i) { 1298 for (const auto& matchedProperties : range)
1250 const MatchedProperties& matchedProperties = matchResult.matchedProperti es[i];
1251 applyProperties<priority>(state, matchedProperties.properties.get(), isI mportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.m_ types.whitelistType)); 1299 applyProperties<priority>(state, matchedProperties.properties.get(), isI mportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.m_ types.whitelistType));
1252 }
1253 } 1300 }
1254 1301
1255 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties , unsigned size) 1302 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties , unsigned size)
1256 { 1303 {
1257 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size ); 1304 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size );
1258 } 1305 }
1259 1306
1260 void StyleResolver::invalidateMatchedPropertiesCache() 1307 void StyleResolver::invalidateMatchedPropertiesCache()
1261 { 1308 {
1262 m_matchedPropertiesCache.clear(); 1309 m_matchedPropertiesCache.clear();
1263 } 1310 }
1264 1311
1265 void StyleResolver::notifyResizeForViewportUnits() 1312 void StyleResolver::notifyResizeForViewportUnits()
1266 { 1313 {
1267 m_viewportStyleResolver->collectViewportRules(); 1314 m_viewportStyleResolver->collectViewportRules();
1268 m_matchedPropertiesCache.clearViewportDependent(); 1315 m_matchedPropertiesCache.clearViewportDependent();
1269 } 1316 }
1270 1317
1271 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult) 1318 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult)
1272 { 1319 {
1273 const Element* element = state.element(); 1320 const Element* element = state.element();
1274 ASSERT(element); 1321 ASSERT(element);
1275 1322
1276 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyApply, 1); 1323 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyApply, 1);
1277 1324
1278 unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash( matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0; 1325 unsigned cacheHash = matchResult.isCacheable() ? computeMatchedPropertiesHas h(matchResult.matchedProperties().data(), matchResult.matchedProperties().size() ) : 0;
1279 bool applyInheritedOnly = false; 1326 bool applyInheritedOnly = false;
1280 const CachedMatchedProperties* cachedMatchedProperties = cacheHash ? m_match edPropertiesCache.find(cacheHash, state, matchResult) : 0; 1327 const CachedMatchedProperties* cachedMatchedProperties = cacheHash ? m_match edPropertiesCache.find(cacheHash, state, matchResult.matchedProperties()) : 0;
1281 1328
1282 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(element, *state.style(), *state.parentStyle())) { 1329 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(element, *state.style(), *state.parentStyle())) {
1283 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheHit, 1); 1330 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheHit, 1);
1284 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact 1331 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact
1285 // style declarations. We then only need to apply the inherited properti es, if any, as their values can depend on the 1332 // style declarations. We then only need to apply the inherited properti es, if any, as their values can depend on the
1286 // element context. This is fast and saves memory by reusing the style d ata structures. 1333 // element context. This is fast and saves memory by reusing the style d ata structures.
1287 state.style()->copyNonInheritedFromCached(*cachedMatchedProperties->comp utedStyle); 1334 state.style()->copyNonInheritedFromCached(*cachedMatchedProperties->comp utedStyle);
1288 if (state.parentStyle()->inheritedDataShared(*cachedMatchedProperties->p arentComputedStyle) && !isAtShadowBoundary(element) 1335 if (state.parentStyle()->inheritedDataShared(*cachedMatchedProperties->p arentComputedStyle) && !isAtShadowBoundary(element)
1289 && (!state.distributedToInsertionPoint() || state.style()->userModif y() == READ_ONLY)) { 1336 && (!state.distributedToInsertionPoint() || state.style()->userModif y() == READ_ONLY)) {
1290 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheInheritedHi t, 1); 1337 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheInheritedHi t, 1);
(...skipping 10 matching lines...) Expand all
1301 1348
1302 return; 1349 return;
1303 } 1350 }
1304 applyInheritedOnly = true; 1351 applyInheritedOnly = true;
1305 } 1352 }
1306 1353
1307 // Now we have all of the matched rules in the appropriate order. Walk the r ules and apply 1354 // Now we have all of the matched rules in the appropriate order. Walk the r ules and apply
1308 // high-priority properties first, i.e., those properties that other propert ies depend on. 1355 // high-priority properties first, i.e., those properties that other propert ies depend on.
1309 // The order is (1) high-priority not important, (2) high-priority important , (3) normal not important 1356 // The order is (1) high-priority not important, (2) high-priority important , (3) normal not important
1310 // and (4) normal important. 1357 // and (4) normal important.
1311 applyMatchedProperties<HighPropertyPriority>(state, matchResult, false, matc hResult.begin(), matchResult.end(), applyInheritedOnly); 1358 applyMatchedProperties<HighPropertyPriority>(state, matchResult.allRules(), false, applyInheritedOnly);
1312 applyMatchedProperties<HighPropertyPriority>(state, matchResult, true, match Result.beginAuthor(), matchResult.endAuthor(), applyInheritedOnly); 1359 for (auto range : ImportantAuthorRanges(matchResult))
1313 applyMatchedProperties<HighPropertyPriority>(state, matchResult, true, match Result.beginUA(), matchResult.endUA(), applyInheritedOnly); 1360 applyMatchedProperties<HighPropertyPriority>(state, range, true, applyIn heritedOnly);
1361 applyMatchedProperties<HighPropertyPriority>(state, matchResult.uaRules(), t rue, applyInheritedOnly);
1314 1362
1315 if (UNLIKELY(isSVGForeignObjectElement(element))) { 1363 if (UNLIKELY(isSVGForeignObjectElement(element))) {
1316 // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignOb ject content should not be scaled again. 1364 // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignOb ject content should not be scaled again.
1317 // 1365 //
1318 // FIXME: The following hijacks the zoom property for foreignObject so t hat children of foreignObject get the 1366 // FIXME: The following hijacks the zoom property for foreignObject so t hat children of foreignObject get the
1319 // correct font-size in case of zooming. 'zoom' has HighPropertyPriority , along with other font-related 1367 // correct font-size in case of zooming. 'zoom' has HighPropertyPriority , along with other font-related
1320 // properties used as input to the FontBuilder, so resetting it here may cause the FontBuilder to recompute the 1368 // properties used as input to the FontBuilder, so resetting it here may cause the FontBuilder to recompute the
1321 // font used as inheritable font for foreignObject content. If we want t o support zoom on foreignObject we'll 1369 // font used as inheritable font for foreignObject content. If we want t o support zoom on foreignObject we'll
1322 // need to find another way of handling the SVG zoom model. 1370 // need to find another way of handling the SVG zoom model.
1323 state.setEffectiveZoom(ComputedStyle::initialZoom()); 1371 state.setEffectiveZoom(ComputedStyle::initialZoom());
1324 } 1372 }
1325 1373
1326 if (cachedMatchedProperties && cachedMatchedProperties->computedStyle->effec tiveZoom() != state.style()->effectiveZoom()) { 1374 if (cachedMatchedProperties && cachedMatchedProperties->computedStyle->effec tiveZoom() != state.style()->effectiveZoom()) {
1327 state.fontBuilder().didChangeEffectiveZoom(); 1375 state.fontBuilder().didChangeEffectiveZoom();
1328 applyInheritedOnly = false; 1376 applyInheritedOnly = false;
1329 } 1377 }
1330 1378
1331 // If our font got dirtied, go ahead and update it now. 1379 // If our font got dirtied, go ahead and update it now.
1332 updateFont(state); 1380 updateFont(state);
1333 1381
1334 // Many properties depend on the font. If it changes we just apply all prope rties. 1382 // Many properties depend on the font. If it changes we just apply all prope rties.
1335 if (cachedMatchedProperties && cachedMatchedProperties->computedStyle->fontD escription() != state.style()->fontDescription()) 1383 if (cachedMatchedProperties && cachedMatchedProperties->computedStyle->fontD escription() != state.style()->fontDescription())
1336 applyInheritedOnly = false; 1384 applyInheritedOnly = false;
1337 1385
1338 // Now do the normal priority UA properties. 1386 // Now do the normal priority UA properties.
1339 applyMatchedProperties<LowPropertyPriority>(state, matchResult, false, match Result.beginUA(), matchResult.endUA(), applyInheritedOnly); 1387 applyMatchedProperties<LowPropertyPriority>(state, matchResult.uaRules(), fa lse, applyInheritedOnly);
1340 1388
1341 // Cache the UA properties to pass them to LayoutTheme in adjustComputedStyl e. 1389 // Cache the UA properties to pass them to LayoutTheme in adjustComputedStyl e.
1342 state.cacheUserAgentBorderAndBackground(); 1390 state.cacheUserAgentBorderAndBackground();
1343 1391
1344 // Now do the author and user normal priority properties and all the !import ant properties. 1392 // Now do the author and user normal priority properties and all the !import ant properties.
1345 applyMatchedProperties<LowPropertyPriority>(state, matchResult, false, match Result.beginAuthor(), matchResult.endAuthor(), applyInheritedOnly); 1393 applyMatchedProperties<LowPropertyPriority>(state, matchResult.authorRules() , false, applyInheritedOnly);
1346 applyMatchedProperties<LowPropertyPriority>(state, matchResult, true, matchR esult.beginAuthor(), matchResult.endAuthor(), applyInheritedOnly); 1394 for (auto range : ImportantAuthorRanges(matchResult))
1347 applyMatchedProperties<LowPropertyPriority>(state, matchResult, true, matchR esult.beginUA(), matchResult.endUA(), applyInheritedOnly); 1395 applyMatchedProperties<LowPropertyPriority>(state, range, true, applyInh eritedOnly);
1396 applyMatchedProperties<LowPropertyPriority>(state, matchResult.uaRules(), tr ue, applyInheritedOnly);
1348 1397
1349 loadPendingResources(state); 1398 loadPendingResources(state);
1350 1399
1351 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, *state.style(), *state.parentStyle())) { 1400 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, *state.style(), *state.parentStyle())) {
1352 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded, 1); 1401 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded, 1);
1353 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), cache Hash, matchResult); 1402 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), cache Hash, matchResult.matchedProperties());
1354 } 1403 }
1355 1404
1356 ASSERT(!state.fontBuilder().fontDirty()); 1405 ASSERT(!state.fontBuilder().fontDirty());
1357 } 1406 }
1358 1407
1359 void StyleResolver::applyCallbackSelectors(StyleResolverState& state) 1408 void StyleResolver::applyCallbackSelectors(StyleResolverState& state)
1360 { 1409 {
1361 if (!m_watchedSelectorsRules) 1410 if (!m_watchedSelectorsRules)
1362 return; 1411 return;
1363 1412
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 { 1479 {
1431 #if ENABLE(OILPAN) 1480 #if ENABLE(OILPAN)
1432 visitor->trace(m_matchedPropertiesCache); 1481 visitor->trace(m_matchedPropertiesCache);
1433 visitor->trace(m_viewportDependentMediaQueryResults); 1482 visitor->trace(m_viewportDependentMediaQueryResults);
1434 visitor->trace(m_selectorFilter); 1483 visitor->trace(m_selectorFilter);
1435 visitor->trace(m_viewportStyleResolver); 1484 visitor->trace(m_viewportStyleResolver);
1436 visitor->trace(m_features); 1485 visitor->trace(m_features);
1437 visitor->trace(m_siblingRuleSet); 1486 visitor->trace(m_siblingRuleSet);
1438 visitor->trace(m_uncommonAttributeRuleSet); 1487 visitor->trace(m_uncommonAttributeRuleSet);
1439 visitor->trace(m_watchedSelectorsRules); 1488 visitor->trace(m_watchedSelectorsRules);
1440 visitor->trace(m_treeBoundaryCrossingRules); 1489 visitor->trace(m_treeBoundaryCrossingScopes);
1441 visitor->trace(m_styleResourceLoader); 1490 visitor->trace(m_styleResourceLoader);
1442 visitor->trace(m_styleSharingLists); 1491 visitor->trace(m_styleSharingLists);
1443 visitor->trace(m_pendingStyleSheets); 1492 visitor->trace(m_pendingStyleSheets);
1444 visitor->trace(m_document); 1493 visitor->trace(m_document);
1445 #endif 1494 #endif
1446 } 1495 }
1447 1496
1448 } // namespace blink 1497 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698