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

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

Issue 15871005: Avoid N^2 walk placing renderers when building the render tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adding a mitigation for the perf regression to Element::recalcStyle. Created 7 years, 5 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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 StyleResolver(Document*, bool matchAuthorAndUserStyles); 139 StyleResolver(Document*, bool matchAuthorAndUserStyles);
140 ~StyleResolver(); 140 ~StyleResolver();
141 141
142 // Using these during tree walk will allow style selector to optimize child and descendant selector lookups. 142 // Using these during tree walk will allow style selector to optimize child and descendant selector lookups.
143 void pushParentElement(Element*); 143 void pushParentElement(Element*);
144 void popParentElement(Element*); 144 void popParentElement(Element*);
145 void pushParentShadowRoot(const ShadowRoot*); 145 void pushParentShadowRoot(const ShadowRoot*);
146 void popParentShadowRoot(const ShadowRoot*); 146 void popParentShadowRoot(const ShadowRoot*);
147 147
148 PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, StyleSharingBehavior = AllowStyleSharing, 148 PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, StyleSharingBehavior = AllowStyleSharing,
149 RuleMatchingBehavior = MatchAllRules, RenderRegion* regionForStyling = 0 ); 149 RuleMatchingBehavior = MatchAllRules, RenderRegion* regionForStyling = 0 , int childIndex = 0);
150
151 // childIndex's origin is 1, and avoids unnecessary tree walks to resolve nt h/nth-last selectors.
152 PassRefPtr<RenderStyle> styleForElement(Element* element, int childIndex)
153 {
154 return styleForElement(element, 0, AllowStyleSharing, MatchAllRules, 0, childIndex);
155 }
150 156
151 void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList&) ; 157 void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList&) ;
152 158
153 PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleReq uest&, RenderStyle* parentStyle); 159 PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleReq uest&, RenderStyle* parentStyle);
154 160
155 PassRefPtr<RenderStyle> styleForPage(int pageIndex); 161 PassRefPtr<RenderStyle> styleForPage(int pageIndex);
156 PassRefPtr<RenderStyle> defaultStyleForElement(); 162 PassRefPtr<RenderStyle> defaultStyleForElement();
157 PassRefPtr<RenderStyle> styleForText(Text*); 163 PassRefPtr<RenderStyle> styleForText(Text*);
158 164
159 static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0); 165 static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
(...skipping 20 matching lines...) Expand all
180 186
181 void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setB uildInDocumentOrder(enabled); } 187 void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setB uildInDocumentOrder(enabled); }
182 bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildI nDocumentOrder(); } 188 bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildI nDocumentOrder(); }
183 189
184 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scope) 190 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scope)
185 { 191 {
186 return m_styleTree.ensureScopedStyleResolver(scope ? scope : document()) ; 192 return m_styleTree.ensureScopedStyleResolver(scope ? scope : document()) ;
187 } 193 }
188 194
189 private: 195 private:
190 void initElement(Element*); 196 void initElement(Element*, int childIndex = 0);
191 RenderStyle* locateSharedStyle(); 197 RenderStyle* locateSharedStyle();
192 bool styleSharingCandidateMatchesRuleSet(RuleSet*); 198 bool styleSharingCandidateMatchesRuleSet(RuleSet*);
193 Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const; 199 Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
194 Element* findSiblingForStyleSharing(Node*, unsigned& count) const; 200 Element* findSiblingForStyleSharing(Node*, unsigned& count) const;
195 bool canShareStyleWithElement(Element*) const; 201 bool canShareStyleWithElement(Element*) const;
196 202
197 PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyf rame*, KeyframeValue&); 203 PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyf rame*, KeyframeValue&);
198 204
199 public: 205 public:
200 // These methods will give back the set of rules that matched for a given el ement (or a pseudo-element). 206 // These methods will give back the set of rules that matched for a given el ement (or a pseudo-element).
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 PseudoId ignoreDynamicPseudo = NOPSEUDO; 479 PseudoId ignoreDynamicPseudo = NOPSEUDO;
474 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches) 480 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches)
475 return true; 481 return true;
476 } 482 }
477 return false; 483 return false;
478 } 484 }
479 485
480 } // namespace WebCore 486 } // namespace WebCore
481 487
482 #endif // StyleResolver_h 488 #endif // StyleResolver_h
OLDNEW
« no previous file with comments | « Source/core/css/SiblingTraversalStrategies.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698