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

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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const HeapVector<Member<StyleRule>>& watchedSelectors = 207 const HeapVector<Member<StyleRule>>& watchedSelectors =
208 watch->watchedCallbackSelectors(); 208 watch->watchedCallbackSelectors();
209 if (!watchedSelectors.size()) 209 if (!watchedSelectors.size())
210 return; 210 return;
211 m_watchedSelectorsRules = RuleSet::create(); 211 m_watchedSelectorsRules = RuleSet::create();
212 for (unsigned i = 0; i < watchedSelectors.size(); ++i) 212 for (unsigned i = 0; i < watchedSelectors.size(); ++i)
213 m_watchedSelectorsRules->addStyleRule(watchedSelectors[i].get(), 213 m_watchedSelectorsRules->addStyleRule(watchedSelectors[i].get(),
214 RuleHasNoSpecialState); 214 RuleHasNoSpecialState);
215 } 215 }
216 216
217 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) {
218 m_tracker = tracker;
219 }
220
217 void StyleResolver::lazyAppendAuthorStyleSheets( 221 void StyleResolver::lazyAppendAuthorStyleSheets(
218 unsigned firstNew, 222 unsigned firstNew,
219 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { 223 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
220 unsigned size = styleSheets.size(); 224 unsigned size = styleSheets.size();
221 for (unsigned i = firstNew; i < size; ++i) 225 for (unsigned i = firstNew; i < size; ++i)
222 m_pendingStyleSheets.add(styleSheets[i].get()); 226 m_pendingStyleSheets.add(styleSheets[i].get());
223 } 227 }
224 228
225 void StyleResolver::removePendingAuthorStyleSheets( 229 void StyleResolver::removePendingAuthorStyleSheets(
226 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { 230 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 const CSSValue* value = 843 const CSSValue* value =
840 it->properties->getPropertyCSSValue(CSSPropertyDisplay); 844 it->properties->getPropertyCSSValue(CSSPropertyDisplay);
841 if (value && value->isIdentifierValue() && 845 if (value && value->isIdentifierValue() &&
842 toCSSIdentifierValue(*value).getValueID() == CSSValueBlock) 846 toCSSIdentifierValue(*value).getValueID() == CSSValueBlock)
843 UseCounter::count( 847 UseCounter::count(
844 element->document(), 848 element->document(),
845 UseCounter::SummaryElementWithDisplayBlockAuthorRule); 849 UseCounter::SummaryElementWithDisplayBlockAuthorRule);
846 } 850 }
847 } 851 }
848 852
853 addMatchedRulesToTracker(collector);
854
849 if (element->computedStyle() && 855 if (element->computedStyle() &&
850 element->computedStyle()->textAutosizingMultiplier() != 856 element->computedStyle()->textAutosizingMultiplier() !=
851 state.style()->textAutosizingMultiplier()) { 857 state.style()->textAutosizingMultiplier()) {
852 // Preserve the text autosizing multiplier on style recalc. Autosizer will 858 // Preserve the text autosizing multiplier on style recalc. Autosizer will
853 // update it during layout if needed. 859 // update it during layout if needed.
854 // NOTE: this must occur before applyMatchedProperties for correct 860 // NOTE: this must occur before applyMatchedProperties for correct
855 // computation of font-relative lengths. 861 // computation of font-relative lengths.
856 state.style()->setTextAutosizingMultiplier( 862 state.style()->setTextAutosizingMultiplier(
857 element->computedStyle()->textAutosizingMultiplier()); 863 element->computedStyle()->textAutosizingMultiplier());
858 state.style()->setUnique(); 864 state.style()->setUnique();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 if (!baseComputedStyle) { 1019 if (!baseComputedStyle) {
1014 // Check UA, user and author rules. 1020 // Check UA, user and author rules.
1015 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1021 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1016 state.style()); 1022 state.style());
1017 collector.setPseudoStyleRequest(pseudoStyleRequest); 1023 collector.setPseudoStyleRequest(pseudoStyleRequest);
1018 1024
1019 matchUARules(collector); 1025 matchUARules(collector);
1020 matchAuthorRules(*state.element(), collector); 1026 matchAuthorRules(*state.element(), collector);
1021 collector.finishAddingAuthorRulesForTreeScope(); 1027 collector.finishAddingAuthorRulesForTreeScope();
1022 1028
1029 addMatchedRulesToTracker(collector);
1030
1023 if (!collector.matchedResult().hasMatchedProperties()) 1031 if (!collector.matchedResult().hasMatchedProperties())
1024 return false; 1032 return false;
1025 1033
1026 applyMatchedProperties(state, collector.matchedResult()); 1034 applyMatchedProperties(state, collector.matchedResult());
1027 applyCallbackSelectors(state); 1035 applyCallbackSelectors(state);
1028 1036
1029 // Cache our original display. 1037 // Cache our original display.
1030 state.style()->setOriginalDisplay(state.style()->display()); 1038 state.style()->setOriginalDisplay(state.style()->display());
1031 1039
1032 // FIXME: Passing 0 as the Element* introduces a lot of complexity 1040 // FIXME: Passing 0 as the Element* introduces a lot of complexity
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1143 }
1136 1144
1137 void StyleResolver::updateFont(StyleResolverState& state) { 1145 void StyleResolver::updateFont(StyleResolverState& state) {
1138 state.fontBuilder().createFont(document().styleEngine().fontSelector(), 1146 state.fontBuilder().createFont(document().styleEngine().fontSelector(),
1139 state.mutableStyleRef()); 1147 state.mutableStyleRef());
1140 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes( 1148 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes(
1141 state.style(), state.rootElementStyle())); 1149 state.style(), state.rootElementStyle()));
1142 state.setConversionZoom(state.style()->effectiveZoom()); 1150 state.setConversionZoom(state.style()->effectiveZoom());
1143 } 1151 }
1144 1152
1153 void StyleResolver::addMatchedRulesToTracker(
1154 const ElementRuleCollector& collector) {
1155 if (!m_tracker)
1156 return;
1157
1158 for (auto matchedRule : collector.matchedRulesList())
1159 m_tracker->markRuleAsUsed(matchedRule.ruleData()->rule());
1160 }
1161
1145 StyleRuleList* StyleResolver::styleRulesForElement(Element* element, 1162 StyleRuleList* StyleResolver::styleRulesForElement(Element* element,
1146 unsigned rulesToInclude) { 1163 unsigned rulesToInclude) {
1147 ASSERT(element); 1164 ASSERT(element);
1148 StyleResolverState state(document(), element); 1165 StyleResolverState state(document(), element);
1149 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1166 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1150 state.style()); 1167 state.style());
1151 collector.setMode(SelectorChecker::CollectingStyleRules); 1168 collector.setMode(SelectorChecker::CollectingStyleRules);
1152 collectPseudoRulesForElement(*element, collector, PseudoIdNone, 1169 collectPseudoRulesForElement(*element, collector, PseudoIdNone,
1153 rulesToInclude); 1170 rulesToInclude);
1154 return collector.matchedStyleRuleList(); 1171 return collector.matchedStyleRuleList();
1155 } 1172 }
1156 1173
1157 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element, 1174 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element,
1158 PseudoId pseudoId, 1175 PseudoId pseudoId,
1159 unsigned rulesToInclude) { 1176 unsigned rulesToInclude) {
1160 ASSERT(element); 1177 ASSERT(element);
1161 StyleResolverState state(document(), element); 1178 StyleResolverState state(document(), element);
1162 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1179 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1163 state.style()); 1180 state.style());
1164 collector.setMode(SelectorChecker::CollectingCSSRules); 1181 collector.setMode(SelectorChecker::CollectingCSSRules);
1165 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude); 1182 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude);
1183
1184 addMatchedRulesToTracker(collector);
1166 return collector.matchedCSSRuleList(); 1185 return collector.matchedCSSRuleList();
1167 } 1186 }
1168 1187
1169 CSSRuleList* StyleResolver::cssRulesForElement(Element* element, 1188 CSSRuleList* StyleResolver::cssRulesForElement(Element* element,
1170 unsigned rulesToInclude) { 1189 unsigned rulesToInclude) {
1171 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude); 1190 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude);
1172 } 1191 }
1173 1192
1174 void StyleResolver::collectPseudoRulesForElement( 1193 void StyleResolver::collectPseudoRulesForElement(
1175 const Element& element, 1194 const Element& element,
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1863
1845 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1864 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1846 state.style()); 1865 state.style());
1847 collector.setMode(SelectorChecker::CollectingStyleRules); 1866 collector.setMode(SelectorChecker::CollectingStyleRules);
1848 collector.setIncludeEmptyRules(true); 1867 collector.setIncludeEmptyRules(true);
1849 1868
1850 MatchRequest matchRequest(m_watchedSelectorsRules.get()); 1869 MatchRequest matchRequest(m_watchedSelectorsRules.get());
1851 collector.collectMatchingRules(matchRequest); 1870 collector.collectMatchingRules(matchRequest);
1852 collector.sortAndTransferMatchedRules(); 1871 collector.sortAndTransferMatchedRules();
1853 1872
1873 addMatchedRulesToTracker(collector);
1874
1854 StyleRuleList* rules = collector.matchedStyleRuleList(); 1875 StyleRuleList* rules = collector.matchedStyleRuleList();
1855 if (!rules) 1876 if (!rules)
1856 return; 1877 return;
1857 for (size_t i = 0; i < rules->size(); i++) 1878 for (size_t i = 0; i < rules->size(); i++)
1858 state.style()->addCallbackSelector( 1879 state.style()->addCallbackSelector(
1859 rules->at(i)->selectorList().selectorsText()); 1880 rules->at(i)->selectorList().selectorsText());
1860 } 1881 }
1861 1882
1862 void StyleResolver::computeFont(ComputedStyle* style, 1883 void StyleResolver::computeFont(ComputedStyle* style,
1863 const StylePropertySet& propertySet) { 1884 const StylePropertySet& propertySet) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 visitor->trace(m_viewportDependentMediaQueryResults); 1936 visitor->trace(m_viewportDependentMediaQueryResults);
1916 visitor->trace(m_deviceDependentMediaQueryResults); 1937 visitor->trace(m_deviceDependentMediaQueryResults);
1917 visitor->trace(m_selectorFilter); 1938 visitor->trace(m_selectorFilter);
1918 visitor->trace(m_features); 1939 visitor->trace(m_features);
1919 visitor->trace(m_siblingRuleSet); 1940 visitor->trace(m_siblingRuleSet);
1920 visitor->trace(m_uncommonAttributeRuleSet); 1941 visitor->trace(m_uncommonAttributeRuleSet);
1921 visitor->trace(m_watchedSelectorsRules); 1942 visitor->trace(m_watchedSelectorsRules);
1922 visitor->trace(m_styleSharingLists); 1943 visitor->trace(m_styleSharingLists);
1923 visitor->trace(m_pendingStyleSheets); 1944 visitor->trace(m_pendingStyleSheets);
1924 visitor->trace(m_document); 1945 visitor->trace(m_document);
1946 visitor->trace(m_tracker);
1925 } 1947 }
1926 1948
1927 } // namespace blink 1949 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698