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

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

Issue 2455943003: Backend for css rule tracking (Closed)
Patch Set: Backend for CSS Rule tracking. Created 4 years, 1 month 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. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
10 * (http://www.torchmobile.com/) 10 * (http://www.torchmobile.com/)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "core/css/resolver/AnimatedStyleBuilder.h" 65 #include "core/css/resolver/AnimatedStyleBuilder.h"
66 #include "core/css/resolver/CSSVariableResolver.h" 66 #include "core/css/resolver/CSSVariableResolver.h"
67 #include "core/css/resolver/MatchResult.h" 67 #include "core/css/resolver/MatchResult.h"
68 #include "core/css/resolver/MediaQueryResult.h" 68 #include "core/css/resolver/MediaQueryResult.h"
69 #include "core/css/resolver/ScopedStyleResolver.h" 69 #include "core/css/resolver/ScopedStyleResolver.h"
70 #include "core/css/resolver/SelectorFilterParentScope.h" 70 #include "core/css/resolver/SelectorFilterParentScope.h"
71 #include "core/css/resolver/SharedStyleFinder.h" 71 #include "core/css/resolver/SharedStyleFinder.h"
72 #include "core/css/resolver/StyleAdjuster.h" 72 #include "core/css/resolver/StyleAdjuster.h"
73 #include "core/css/resolver/StyleResolverState.h" 73 #include "core/css/resolver/StyleResolverState.h"
74 #include "core/css/resolver/StyleResolverStats.h" 74 #include "core/css/resolver/StyleResolverStats.h"
75 #include "core/css/resolver/StyleRuleUsageTracker.h"
75 #include "core/dom/CSSSelectorWatch.h" 76 #include "core/dom/CSSSelectorWatch.h"
76 #include "core/dom/FirstLetterPseudoElement.h" 77 #include "core/dom/FirstLetterPseudoElement.h"
77 #include "core/dom/NodeComputedStyle.h" 78 #include "core/dom/NodeComputedStyle.h"
78 #include "core/dom/StyleEngine.h" 79 #include "core/dom/StyleEngine.h"
79 #include "core/dom/Text.h" 80 #include "core/dom/Text.h"
80 #include "core/dom/shadow/ElementShadow.h" 81 #include "core/dom/shadow/ElementShadow.h"
81 #include "core/dom/shadow/ShadowRoot.h" 82 #include "core/dom/shadow/ShadowRoot.h"
82 #include "core/frame/FrameView.h" 83 #include "core/frame/FrameView.h"
83 #include "core/frame/LocalFrame.h" 84 #include "core/frame/LocalFrame.h"
84 #include "core/frame/Settings.h" 85 #include "core/frame/Settings.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 m_printMediaType = 189 m_printMediaType =
189 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); 190 equalIgnoringCase(view->mediaType(), MediaTypeNames::print);
190 } 191 }
191 192
192 StyleResolver::~StyleResolver() {} 193 StyleResolver::~StyleResolver() {}
193 194
194 void StyleResolver::dispose() { 195 void StyleResolver::dispose() {
195 m_matchedPropertiesCache.clear(); 196 m_matchedPropertiesCache.clear();
196 } 197 }
197 198
199 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) {
200 m_tracker = tracker;
201 }
202
198 void StyleResolver::lazyAppendAuthorStyleSheets( 203 void StyleResolver::lazyAppendAuthorStyleSheets(
199 unsigned firstNew, 204 unsigned firstNew,
200 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { 205 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
201 unsigned size = styleSheets.size(); 206 unsigned size = styleSheets.size();
202 for (unsigned i = firstNew; i < size; ++i) 207 for (unsigned i = firstNew; i < size; ++i)
203 m_pendingStyleSheets.add(styleSheets[i].get()); 208 m_pendingStyleSheets.add(styleSheets[i].get());
204 } 209 }
205 210
206 void StyleResolver::removePendingAuthorStyleSheets( 211 void StyleResolver::removePendingAuthorStyleSheets(
207 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { 212 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 const CSSValue* value = 757 const CSSValue* value =
753 it->properties->getPropertyCSSValue(CSSPropertyDisplay); 758 it->properties->getPropertyCSSValue(CSSPropertyDisplay);
754 if (value && value->isIdentifierValue() && 759 if (value && value->isIdentifierValue() &&
755 toCSSIdentifierValue(*value).getValueID() == CSSValueBlock) 760 toCSSIdentifierValue(*value).getValueID() == CSSValueBlock)
756 UseCounter::count( 761 UseCounter::count(
757 element->document(), 762 element->document(),
758 UseCounter::SummaryElementWithDisplayBlockAuthorRule); 763 UseCounter::SummaryElementWithDisplayBlockAuthorRule);
759 } 764 }
760 } 765 }
761 766
767 if (m_tracker)
768 addMatchedRulesToTracker(collector);
769
762 if (element->computedStyle() && 770 if (element->computedStyle() &&
763 element->computedStyle()->textAutosizingMultiplier() != 771 element->computedStyle()->textAutosizingMultiplier() !=
764 state.style()->textAutosizingMultiplier()) { 772 state.style()->textAutosizingMultiplier()) {
765 // Preserve the text autosizing multiplier on style recalc. Autosizer will 773 // Preserve the text autosizing multiplier on style recalc. Autosizer will
766 // update it during layout if needed. 774 // update it during layout if needed.
767 // NOTE: this must occur before applyMatchedProperties for correct 775 // NOTE: this must occur before applyMatchedProperties for correct
768 // computation of font-relative lengths. 776 // computation of font-relative lengths.
769 state.style()->setTextAutosizingMultiplier( 777 state.style()->setTextAutosizingMultiplier(
770 element->computedStyle()->textAutosizingMultiplier()); 778 element->computedStyle()->textAutosizingMultiplier());
771 state.style()->setUnique(); 779 state.style()->setUnique();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 if (!baseComputedStyle) { 934 if (!baseComputedStyle) {
927 // Check UA, user and author rules. 935 // Check UA, user and author rules.
928 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 936 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
929 state.style()); 937 state.style());
930 collector.setPseudoStyleRequest(pseudoStyleRequest); 938 collector.setPseudoStyleRequest(pseudoStyleRequest);
931 939
932 matchUARules(collector); 940 matchUARules(collector);
933 matchAuthorRules(*state.element(), collector); 941 matchAuthorRules(*state.element(), collector);
934 collector.finishAddingAuthorRulesForTreeScope(); 942 collector.finishAddingAuthorRulesForTreeScope();
935 943
944 if (m_tracker)
945 addMatchedRulesToTracker(collector);
946
936 if (!collector.matchedResult().hasMatchedProperties()) 947 if (!collector.matchedResult().hasMatchedProperties())
937 return false; 948 return false;
938 949
939 applyMatchedProperties(state, collector.matchedResult()); 950 applyMatchedProperties(state, collector.matchedResult());
940 applyCallbackSelectors(state); 951 applyCallbackSelectors(state);
941 952
942 // Cache our original display. 953 // Cache our original display.
943 state.style()->setOriginalDisplay(state.style()->display()); 954 state.style()->setOriginalDisplay(state.style()->display());
944 955
945 // FIXME: Passing 0 as the Element* introduces a lot of complexity 956 // FIXME: Passing 0 as the Element* introduces a lot of complexity
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1059 }
1049 1060
1050 void StyleResolver::updateFont(StyleResolverState& state) { 1061 void StyleResolver::updateFont(StyleResolverState& state) {
1051 state.fontBuilder().createFont(document().styleEngine().fontSelector(), 1062 state.fontBuilder().createFont(document().styleEngine().fontSelector(),
1052 state.mutableStyleRef()); 1063 state.mutableStyleRef());
1053 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes( 1064 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes(
1054 state.style(), state.rootElementStyle())); 1065 state.style(), state.rootElementStyle()));
1055 state.setConversionZoom(state.style()->effectiveZoom()); 1066 state.setConversionZoom(state.style()->effectiveZoom());
1056 } 1067 }
1057 1068
1069 void StyleResolver::addMatchedRulesToTracker(
1070 const ElementRuleCollector& collector) {
1071 for (auto matchedRule : collector.matchedRulesList())
1072 m_tracker->track(matchedRule.ruleData()->rule());
1073 }
1074
1058 StyleRuleList* StyleResolver::styleRulesForElement(Element* element, 1075 StyleRuleList* StyleResolver::styleRulesForElement(Element* element,
1059 unsigned rulesToInclude) { 1076 unsigned rulesToInclude) {
1060 DCHECK(element); 1077 DCHECK(element);
1061 StyleResolverState state(document(), element); 1078 StyleResolverState state(document(), element);
1062 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1079 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1063 state.style()); 1080 state.style());
1064 collector.setMode(SelectorChecker::CollectingStyleRules); 1081 collector.setMode(SelectorChecker::CollectingStyleRules);
1065 collectPseudoRulesForElement(*element, collector, PseudoIdNone, 1082 collectPseudoRulesForElement(*element, collector, PseudoIdNone,
1066 rulesToInclude); 1083 rulesToInclude);
1067 return collector.matchedStyleRuleList(); 1084 return collector.matchedStyleRuleList();
1068 } 1085 }
1069 1086
1070 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element, 1087 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element,
1071 PseudoId pseudoId, 1088 PseudoId pseudoId,
1072 unsigned rulesToInclude) { 1089 unsigned rulesToInclude) {
1073 DCHECK(element); 1090 DCHECK(element);
1074 StyleResolverState state(document(), element); 1091 StyleResolverState state(document(), element);
1075 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1092 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1076 state.style()); 1093 state.style());
1077 collector.setMode(SelectorChecker::CollectingCSSRules); 1094 collector.setMode(SelectorChecker::CollectingCSSRules);
1078 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude); 1095 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude);
1096
1097 if (m_tracker)
1098 addMatchedRulesToTracker(collector);
1079 return collector.matchedCSSRuleList(); 1099 return collector.matchedCSSRuleList();
1080 } 1100 }
1081 1101
1082 CSSRuleList* StyleResolver::cssRulesForElement(Element* element, 1102 CSSRuleList* StyleResolver::cssRulesForElement(Element* element,
1083 unsigned rulesToInclude) { 1103 unsigned rulesToInclude) {
1084 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude); 1104 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude);
1085 } 1105 }
1086 1106
1087 void StyleResolver::collectPseudoRulesForElement( 1107 void StyleResolver::collectPseudoRulesForElement(
1088 const Element& element, 1108 const Element& element,
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 1779
1760 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1780 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1761 state.style()); 1781 state.style());
1762 collector.setMode(SelectorChecker::CollectingStyleRules); 1782 collector.setMode(SelectorChecker::CollectingStyleRules);
1763 collector.setIncludeEmptyRules(true); 1783 collector.setIncludeEmptyRules(true);
1764 1784
1765 MatchRequest matchRequest(watchedSelectorsRuleSet); 1785 MatchRequest matchRequest(watchedSelectorsRuleSet);
1766 collector.collectMatchingRules(matchRequest); 1786 collector.collectMatchingRules(matchRequest);
1767 collector.sortAndTransferMatchedRules(); 1787 collector.sortAndTransferMatchedRules();
1768 1788
1789 if (m_tracker)
1790 addMatchedRulesToTracker(collector);
1791
1769 StyleRuleList* rules = collector.matchedStyleRuleList(); 1792 StyleRuleList* rules = collector.matchedStyleRuleList();
1770 if (!rules) 1793 if (!rules)
1771 return; 1794 return;
1772 for (size_t i = 0; i < rules->size(); i++) 1795 for (size_t i = 0; i < rules->size(); i++)
1773 state.style()->addCallbackSelector( 1796 state.style()->addCallbackSelector(
1774 rules->at(i)->selectorList().selectorsText()); 1797 rules->at(i)->selectorList().selectorsText());
1775 } 1798 }
1776 1799
1777 void StyleResolver::computeFont(ComputedStyle* style, 1800 void StyleResolver::computeFont(ComputedStyle* style,
1778 const StylePropertySet& propertySet) { 1801 const StylePropertySet& propertySet) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 1849
1827 DEFINE_TRACE(StyleResolver) { 1850 DEFINE_TRACE(StyleResolver) {
1828 visitor->trace(m_matchedPropertiesCache); 1851 visitor->trace(m_matchedPropertiesCache);
1829 visitor->trace(m_medium); 1852 visitor->trace(m_medium);
1830 visitor->trace(m_viewportDependentMediaQueryResults); 1853 visitor->trace(m_viewportDependentMediaQueryResults);
1831 visitor->trace(m_deviceDependentMediaQueryResults); 1854 visitor->trace(m_deviceDependentMediaQueryResults);
1832 visitor->trace(m_selectorFilter); 1855 visitor->trace(m_selectorFilter);
1833 visitor->trace(m_styleSharingLists); 1856 visitor->trace(m_styleSharingLists);
1834 visitor->trace(m_pendingStyleSheets); 1857 visitor->trace(m_pendingStyleSheets);
1835 visitor->trace(m_document); 1858 visitor->trace(m_document);
1859 visitor->trace(m_tracker);
1836 } 1860 }
1837 1861
1838 } // namespace blink 1862 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698