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

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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 m_printMediaType = 187 m_printMediaType =
187 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); 188 equalIgnoringCase(view->mediaType(), MediaTypeNames::print);
188 } 189 }
189 190
190 StyleResolver::~StyleResolver() {} 191 StyleResolver::~StyleResolver() {}
191 192
192 void StyleResolver::dispose() { 193 void StyleResolver::dispose() {
193 m_matchedPropertiesCache.clear(); 194 m_matchedPropertiesCache.clear();
194 } 195 }
195 196
197 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) {
198 m_tracker = tracker;
199 }
200
196 void StyleResolver::lazyAppendAuthorStyleSheets( 201 void StyleResolver::lazyAppendAuthorStyleSheets(
197 unsigned firstNew, 202 unsigned firstNew,
198 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { 203 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
199 unsigned size = styleSheets.size(); 204 unsigned size = styleSheets.size();
200 for (unsigned i = firstNew; i < size; ++i) 205 for (unsigned i = firstNew; i < size; ++i)
201 m_pendingStyleSheets.add(styleSheets[i].get()); 206 m_pendingStyleSheets.add(styleSheets[i].get());
202 } 207 }
203 208
204 void StyleResolver::removePendingAuthorStyleSheets( 209 void StyleResolver::removePendingAuthorStyleSheets(
205 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { 210 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 const CSSValue* value = 755 const CSSValue* value =
751 it->properties->getPropertyCSSValue(CSSPropertyDisplay); 756 it->properties->getPropertyCSSValue(CSSPropertyDisplay);
752 if (value && value->isIdentifierValue() && 757 if (value && value->isIdentifierValue() &&
753 toCSSIdentifierValue(*value).getValueID() == CSSValueBlock) 758 toCSSIdentifierValue(*value).getValueID() == CSSValueBlock)
754 UseCounter::count( 759 UseCounter::count(
755 element->document(), 760 element->document(),
756 UseCounter::SummaryElementWithDisplayBlockAuthorRule); 761 UseCounter::SummaryElementWithDisplayBlockAuthorRule);
757 } 762 }
758 } 763 }
759 764
765 if (m_tracker)
766 addMatchedRulesToTracker(collector);
767
760 if (element->computedStyle() && 768 if (element->computedStyle() &&
761 element->computedStyle()->textAutosizingMultiplier() != 769 element->computedStyle()->textAutosizingMultiplier() !=
762 state.style()->textAutosizingMultiplier()) { 770 state.style()->textAutosizingMultiplier()) {
763 // Preserve the text autosizing multiplier on style recalc. Autosizer will 771 // Preserve the text autosizing multiplier on style recalc. Autosizer will
764 // update it during layout if needed. 772 // update it during layout if needed.
765 // NOTE: this must occur before applyMatchedProperties for correct 773 // NOTE: this must occur before applyMatchedProperties for correct
766 // computation of font-relative lengths. 774 // computation of font-relative lengths.
767 state.style()->setTextAutosizingMultiplier( 775 state.style()->setTextAutosizingMultiplier(
768 element->computedStyle()->textAutosizingMultiplier()); 776 element->computedStyle()->textAutosizingMultiplier());
769 state.style()->setUnique(); 777 state.style()->setUnique();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 if (!baseComputedStyle) { 932 if (!baseComputedStyle) {
925 // Check UA, user and author rules. 933 // Check UA, user and author rules.
926 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 934 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
927 state.style()); 935 state.style());
928 collector.setPseudoStyleRequest(pseudoStyleRequest); 936 collector.setPseudoStyleRequest(pseudoStyleRequest);
929 937
930 matchUARules(collector); 938 matchUARules(collector);
931 matchAuthorRules(*state.element(), collector); 939 matchAuthorRules(*state.element(), collector);
932 collector.finishAddingAuthorRulesForTreeScope(); 940 collector.finishAddingAuthorRulesForTreeScope();
933 941
942 if (m_tracker)
943 addMatchedRulesToTracker(collector);
944
934 if (!collector.matchedResult().hasMatchedProperties()) 945 if (!collector.matchedResult().hasMatchedProperties())
935 return false; 946 return false;
936 947
937 applyMatchedProperties(state, collector.matchedResult()); 948 applyMatchedProperties(state, collector.matchedResult());
938 applyCallbackSelectors(state); 949 applyCallbackSelectors(state);
939 950
940 // Cache our original display. 951 // Cache our original display.
941 state.style()->setOriginalDisplay(state.style()->display()); 952 state.style()->setOriginalDisplay(state.style()->display());
942 953
943 // FIXME: Passing 0 as the Element* introduces a lot of complexity 954 // FIXME: Passing 0 as the Element* introduces a lot of complexity
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 } 1058 }
1048 1059
1049 void StyleResolver::updateFont(StyleResolverState& state) { 1060 void StyleResolver::updateFont(StyleResolverState& state) {
1050 state.fontBuilder().createFont(document().styleEngine().fontSelector(), 1061 state.fontBuilder().createFont(document().styleEngine().fontSelector(),
1051 state.mutableStyleRef()); 1062 state.mutableStyleRef());
1052 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes( 1063 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes(
1053 state.style(), state.rootElementStyle())); 1064 state.style(), state.rootElementStyle()));
1054 state.setConversionZoom(state.style()->effectiveZoom()); 1065 state.setConversionZoom(state.style()->effectiveZoom());
1055 } 1066 }
1056 1067
1068 void StyleResolver::addMatchedRulesToTracker(
1069 const ElementRuleCollector& collector) {
1070 collector.addMatchedRulesToTracker(m_tracker);
1071 }
1072
1057 StyleRuleList* StyleResolver::styleRulesForElement(Element* element, 1073 StyleRuleList* StyleResolver::styleRulesForElement(Element* element,
1058 unsigned rulesToInclude) { 1074 unsigned rulesToInclude) {
1059 DCHECK(element); 1075 DCHECK(element);
1060 StyleResolverState state(document(), element); 1076 StyleResolverState state(document(), element);
1061 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1077 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1062 state.style()); 1078 state.style());
1063 collector.setMode(SelectorChecker::CollectingStyleRules); 1079 collector.setMode(SelectorChecker::CollectingStyleRules);
1064 collectPseudoRulesForElement(*element, collector, PseudoIdNone, 1080 collectPseudoRulesForElement(*element, collector, PseudoIdNone,
1065 rulesToInclude); 1081 rulesToInclude);
1066 return collector.matchedStyleRuleList(); 1082 return collector.matchedStyleRuleList();
1067 } 1083 }
1068 1084
1069 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element, 1085 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element,
1070 PseudoId pseudoId, 1086 PseudoId pseudoId,
1071 unsigned rulesToInclude) { 1087 unsigned rulesToInclude) {
1072 DCHECK(element); 1088 DCHECK(element);
1073 StyleResolverState state(document(), element); 1089 StyleResolverState state(document(), element);
1074 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1090 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1075 state.style()); 1091 state.style());
1076 collector.setMode(SelectorChecker::CollectingCSSRules); 1092 collector.setMode(SelectorChecker::CollectingCSSRules);
1077 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude); 1093 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude);
1094
1095 if (m_tracker)
1096 addMatchedRulesToTracker(collector);
1078 return collector.matchedCSSRuleList(); 1097 return collector.matchedCSSRuleList();
1079 } 1098 }
1080 1099
1081 CSSRuleList* StyleResolver::cssRulesForElement(Element* element, 1100 CSSRuleList* StyleResolver::cssRulesForElement(Element* element,
1082 unsigned rulesToInclude) { 1101 unsigned rulesToInclude) {
1083 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude); 1102 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude);
1084 } 1103 }
1085 1104
1086 void StyleResolver::collectPseudoRulesForElement( 1105 void StyleResolver::collectPseudoRulesForElement(
1087 const Element& element, 1106 const Element& element,
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 1805
1787 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, 1806 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
1788 state.style()); 1807 state.style());
1789 collector.setMode(SelectorChecker::CollectingStyleRules); 1808 collector.setMode(SelectorChecker::CollectingStyleRules);
1790 collector.setIncludeEmptyRules(true); 1809 collector.setIncludeEmptyRules(true);
1791 1810
1792 MatchRequest matchRequest(watchedSelectorsRuleSet); 1811 MatchRequest matchRequest(watchedSelectorsRuleSet);
1793 collector.collectMatchingRules(matchRequest); 1812 collector.collectMatchingRules(matchRequest);
1794 collector.sortAndTransferMatchedRules(); 1813 collector.sortAndTransferMatchedRules();
1795 1814
1815 if (m_tracker)
1816 addMatchedRulesToTracker(collector);
1817
1796 StyleRuleList* rules = collector.matchedStyleRuleList(); 1818 StyleRuleList* rules = collector.matchedStyleRuleList();
1797 if (!rules) 1819 if (!rules)
1798 return; 1820 return;
1799 for (size_t i = 0; i < rules->size(); i++) 1821 for (size_t i = 0; i < rules->size(); i++)
1800 state.style()->addCallbackSelector( 1822 state.style()->addCallbackSelector(
1801 rules->at(i)->selectorList().selectorsText()); 1823 rules->at(i)->selectorList().selectorsText());
1802 } 1824 }
1803 1825
1804 void StyleResolver::computeFont(ComputedStyle* style, 1826 void StyleResolver::computeFont(ComputedStyle* style,
1805 const StylePropertySet& propertySet) { 1827 const StylePropertySet& propertySet) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 1875
1854 DEFINE_TRACE(StyleResolver) { 1876 DEFINE_TRACE(StyleResolver) {
1855 visitor->trace(m_matchedPropertiesCache); 1877 visitor->trace(m_matchedPropertiesCache);
1856 visitor->trace(m_medium); 1878 visitor->trace(m_medium);
1857 visitor->trace(m_viewportDependentMediaQueryResults); 1879 visitor->trace(m_viewportDependentMediaQueryResults);
1858 visitor->trace(m_deviceDependentMediaQueryResults); 1880 visitor->trace(m_deviceDependentMediaQueryResults);
1859 visitor->trace(m_selectorFilter); 1881 visitor->trace(m_selectorFilter);
1860 visitor->trace(m_styleSharingLists); 1882 visitor->trace(m_styleSharingLists);
1861 visitor->trace(m_pendingStyleSheets); 1883 visitor->trace(m_pendingStyleSheets);
1862 visitor->trace(m_document); 1884 visitor->trace(m_document);
1885 visitor->trace(m_tracker);
1863 } 1886 }
1864 1887
1865 } // namespace blink 1888 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698