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