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

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

Issue 16629006: Revert 151996 "Avoid N^2 walk placing renderers when building th..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Update to head Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/css/resolver/StyleResolverState.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 553 }
554 554
555 // Now check SMIL animation override style. 555 // Now check SMIL animation override style.
556 if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledEleme nt() && m_state.styledElement()->isSVGElement()) 556 if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledEleme nt() && m_state.styledElement()->isSVGElement())
557 collector.addElementStyleProperties(toSVGElement(m_state.styledElement() )->animatedSMILStyleProperties(), false /* isCacheable */); 557 collector.addElementStyleProperties(toSVGElement(m_state.styledElement() )->animatedSMILStyleProperties(), false /* isCacheable */);
558 558
559 if (m_state.styledElement() && m_state.styledElement()->hasActiveAnimations( )) 559 if (m_state.styledElement() && m_state.styledElement()->hasActiveAnimations( ))
560 collector.matchedResult().isCacheable = false; 560 collector.matchedResult().isCacheable = false;
561 } 561 }
562 562
563 inline void StyleResolver::initElement(Element* e, int childIndex) 563 inline void StyleResolver::initElement(Element* e)
564 { 564 {
565 if (m_state.element() != e) { 565 if (m_state.element() != e) {
566 m_state.initElement(e, childIndex); 566 m_state.initElement(e);
567 if (e && e == e->document()->documentElement()) { 567 if (e && e == e->document()->documentElement()) {
568 e->document()->setDirectionSetOnDocumentElement(false); 568 e->document()->setDirectionSetOnDocumentElement(false);
569 e->document()->setWritingModeSetOnDocumentElement(false); 569 e->document()->setWritingModeSetOnDocumentElement(false);
570 } 570 }
571 } 571 }
572 } 572 }
573 573
574 static const unsigned cStyleSearchThreshold = 10; 574 static const unsigned cStyleSearchThreshold = 10;
575 static const unsigned cStyleSearchLevelThreshold = 10; 575 static const unsigned cStyleSearchLevelThreshold = 10;
576 576
(...skipping 16 matching lines...) Expand all
593 if (p->inlineStyle()) 593 if (p->inlineStyle())
594 return 0; 594 return 0;
595 if (p->isSVGElement() && toSVGElement(p)->animatedSMILStyleProperties()) 595 if (p->isSVGElement() && toSVGElement(p)->animatedSMILStyleProperties())
596 return 0; 596 return 0;
597 if (p->hasID() && m_features.idsInRules.contains(p->idForStyleResolution().i mpl())) 597 if (p->hasID() && m_features.idsInRules.contains(p->idForStyleResolution().i mpl()))
598 return 0; 598 return 0;
599 599
600 RenderStyle* parentStyle = p->renderStyle(); 600 RenderStyle* parentStyle = p->renderStyle();
601 unsigned subcount = 0; 601 unsigned subcount = 0;
602 Node* thisCousin = p; 602 Node* thisCousin = p;
603 Node* currentNode = p->nextSibling(); 603 Node* currentNode = p->previousSibling();
604 604
605 // Reserve the tries for this level. This effectively makes sure that the al gorithm 605 // Reserve the tries for this level. This effectively makes sure that the al gorithm
606 // will never go deeper than cStyleSearchLevelThreshold levels into recursio n. 606 // will never go deeper than cStyleSearchLevelThreshold levels into recursio n.
607 visitedNodeCount += cStyleSearchThreshold; 607 visitedNodeCount += cStyleSearchThreshold;
608 while (thisCousin) { 608 while (thisCousin) {
609 while (currentNode) { 609 while (currentNode) {
610 ++subcount; 610 ++subcount;
611 if (!currentNode->hasScopedHTMLStyleChild() && currentNode->renderSt yle() == parentStyle && currentNode->lastChild() 611 if (!currentNode->hasScopedHTMLStyleChild() && currentNode->renderSt yle() == parentStyle && currentNode->lastChild()
612 && currentNode->isElementNode() && !parentElementPreventsSharing (toElement(currentNode)) 612 && currentNode->isElementNode() && !parentElementPreventsSharing (toElement(currentNode))
613 && !toElement(currentNode)->shadow() 613 && !toElement(currentNode)->shadow()
614 ) { 614 ) {
615 // Adjust for unused reserved tries. 615 // Adjust for unused reserved tries.
616 visitedNodeCount -= cStyleSearchThreshold - subcount; 616 visitedNodeCount -= cStyleSearchThreshold - subcount;
617 return currentNode->lastChild(); 617 return currentNode->lastChild();
618 } 618 }
619 if (subcount >= cStyleSearchThreshold) 619 if (subcount >= cStyleSearchThreshold)
620 return 0; 620 return 0;
621 currentNode = currentNode->nextSibling(); 621 currentNode = currentNode->previousSibling();
622 } 622 }
623 currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeC ount); 623 currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeC ount);
624 thisCousin = currentNode; 624 thisCousin = currentNode;
625 } 625 }
626 626
627 return 0; 627 return 0;
628 } 628 }
629 629
630 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet) 630 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet)
631 { 631 {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (element->isWebVTTElement() && state.element()->isWebVTTElement() && toWe bVTTElement(element)->isPastNode() != toWebVTTElement(state.element())->isPastNo de()) 807 if (element->isWebVTTElement() && state.element()->isWebVTTElement() && toWe bVTTElement(element)->isPastNode() != toWebVTTElement(state.element())->isPastNo de())
808 return false; 808 return false;
809 809
810 if (element == element->document()->webkitCurrentFullScreenElement() || stat e.element() == state.document()->webkitCurrentFullScreenElement()) 810 if (element == element->document()->webkitCurrentFullScreenElement() || stat e.element() == state.document()->webkitCurrentFullScreenElement())
811 return false; 811 return false;
812 return true; 812 return true;
813 } 813 }
814 814
815 inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsi gned& count) const 815 inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsi gned& count) const
816 { 816 {
817 for (; node; node = node->nextSibling()) { 817 for (; node; node = node->previousSibling()) {
818 if (!node->isStyledElement()) 818 if (!node->isStyledElement())
819 continue; 819 continue;
820 if (canShareStyleWithElement(static_cast<StyledElement*>(node))) 820 if (canShareStyleWithElement(static_cast<StyledElement*>(node)))
821 break; 821 break;
822 if (count++ == cStyleSearchThreshold) 822 if (count++ == cStyleSearchThreshold)
823 return 0; 823 return 0;
824 } 824 }
825 return static_cast<StyledElement*>(node); 825 return static_cast<StyledElement*>(node);
826 } 826 }
827 827
(...skipping 24 matching lines...) Expand all
852 // When a dialog is first shown, its style is mutated to center it in the 852 // When a dialog is first shown, its style is mutated to center it in the
853 // viewport. So the styles can't be shared since the viewport position and 853 // viewport. So the styles can't be shared since the viewport position and
854 // size may be different each time a dialog is opened. 854 // size may be different each time a dialog is opened.
855 if (state.element()->hasTagName(dialogTag)) 855 if (state.element()->hasTagName(dialogTag))
856 return 0; 856 return 0;
857 857
858 // Cache whether state.element is affected by any known class selectors. 858 // Cache whether state.element is affected by any known class selectors.
859 // FIXME: This shouldn't be a member variable. The style sharing code could be factored out of StyleResolver. 859 // FIXME: This shouldn't be a member variable. The style sharing code could be factored out of StyleResolver.
860 state.setElementAffectedByClassRules(state.element() && state.element()->has Class() && classNamesAffectedByRules(state.element()->classNames())); 860 state.setElementAffectedByClassRules(state.element() && state.element()->has Class() && classNamesAffectedByRules(state.element()->classNames()));
861 861
862 // Check next siblings and their cousins. 862 // Check previous siblings and their cousins.
863 unsigned count = 0; 863 unsigned count = 0;
864 unsigned visitedNodeCount = 0; 864 unsigned visitedNodeCount = 0;
865 StyledElement* shareElement = 0; 865 StyledElement* shareElement = 0;
866 Node* cousinList = state.styledElement()->nextSibling(); 866 Node* cousinList = state.styledElement()->previousSibling();
867 while (cousinList) { 867 while (cousinList) {
868 shareElement = findSiblingForStyleSharing(cousinList, count); 868 shareElement = findSiblingForStyleSharing(cousinList, count);
869 if (shareElement) 869 if (shareElement)
870 break; 870 break;
871 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCo unt); 871 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCo unt);
872 } 872 }
873 873
874 // If we have exhausted all our budget or our cousins. 874 // If we have exhausted all our budget or our cousins.
875 if (!shareElement) 875 if (!shareElement)
876 return 0; 876 return 0;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 } 1071 }
1072 1072
1073 static inline bool isAtShadowBoundary(const Element* element) 1073 static inline bool isAtShadowBoundary(const Element* element)
1074 { 1074 {
1075 if (!element) 1075 if (!element)
1076 return false; 1076 return false;
1077 ContainerNode* parentNode = element->parentNode(); 1077 ContainerNode* parentNode = element->parentNode();
1078 return parentNode && parentNode->isShadowRoot(); 1078 return parentNode && parentNode->isShadowRoot();
1079 } 1079 }
1080 1080
1081 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior, 1081 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent,
1082 RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling, int c hildIndex) 1082 StyleSharingBehavior sharingBehavior, RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling)
1083 { 1083 {
1084 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer 1084 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer
1085 // will vanish if a style recalc happens during loading. 1085 // will vanish if a style recalc happens during loading.
1086 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStyles heetsLoaded() && !element->renderer()) { 1086 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStyles heetsLoaded() && !element->renderer()) {
1087 if (!s_styleNotYetAvailable) { 1087 if (!s_styleNotYetAvailable) {
1088 s_styleNotYetAvailable = RenderStyle::create().leakRef(); 1088 s_styleNotYetAvailable = RenderStyle::create().leakRef();
1089 s_styleNotYetAvailable->setDisplay(NONE); 1089 s_styleNotYetAvailable->setDisplay(NONE);
1090 s_styleNotYetAvailable->font().update(m_fontSelector); 1090 s_styleNotYetAvailable->font().update(m_fontSelector);
1091 } 1091 }
1092 element->document()->setHasNodesWithPlaceholderStyle(); 1092 element->document()->setHasNodesWithPlaceholderStyle();
1093 return s_styleNotYetAvailable; 1093 return s_styleNotYetAvailable;
1094 } 1094 }
1095 1095
1096 StyleResolverState& state = m_state; 1096 StyleResolverState& state = m_state;
1097 initElement(element, childIndex); 1097 initElement(element);
1098 state.initForStyleResolve(document(), element, defaultParent, regionForStyli ng); 1098 state.initForStyleResolve(document(), element, defaultParent, regionForStyli ng);
1099 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi nt()) { 1099 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi nt()) {
1100 RenderStyle* sharedStyle = locateSharedStyle(); 1100 RenderStyle* sharedStyle = locateSharedStyle();
1101 if (sharedStyle) { 1101 if (sharedStyle) {
1102 state.clear(); 1102 state.clear();
1103 return sharedStyle; 1103 return sharedStyle;
1104 } 1104 }
1105 } 1105 }
1106 1106
1107 if (state.parentStyle()) { 1107 if (state.parentStyle()) {
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 info.addMember(m_state, "state"); 3731 info.addMember(m_state, "state");
3732 3732
3733 // FIXME: move this to a place where it would be called only once? 3733 // FIXME: move this to a place where it would be called only once?
3734 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle"); 3734 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle");
3735 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl e"); 3735 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl e");
3736 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle" ); 3736 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle" );
3737 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo urceStyle"); 3737 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo urceStyle");
3738 } 3738 }
3739 3739
3740 } // namespace WebCore 3740 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/css/resolver/StyleResolverState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698