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

Side by Side Diff: Source/core/dom/Element.cpp

Issue 198783003: Recalc sibling styles for forward positional rules on mutations only. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased. Created 6 years, 9 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 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 return; 1822 return;
1823 1823
1824 RenderStyle* style = renderStyle(); 1824 RenderStyle* style = renderStyle();
1825 1825
1826 // :empty selector. 1826 // :empty selector.
1827 checkForEmptyStyleChange(style); 1827 checkForEmptyStyleChange(style);
1828 1828
1829 if (!style || (needsStyleRecalc() && childrenAffectedByPositionalRules())) 1829 if (!style || (needsStyleRecalc() && childrenAffectedByPositionalRules()))
1830 return; 1830 return;
1831 1831
1832 // Forward positional selectors include the ~ selector, nth-child, nth-of-ty pe, first-of-type and only-of-type. 1832 // Forward positional selectors include nth-child, nth-of-type, first-of-typ e and only-of-type.
1833 // The indirect adjacent selector is the ~ selector.
1833 // Backward positional selectors include nth-last-child, nth-last-of-type, l ast-of-type and only-of-type. 1834 // Backward positional selectors include nth-last-child, nth-last-of-type, l ast-of-type and only-of-type.
1834 // We have to invalidate everything following the insertion point in the for ward case, and everything before the insertion point in the 1835 // We have to invalidate everything following the insertion point in the for ward and indirect adjacent case,
1835 // backward case. 1836 // and everything before the insertion point in the backward case.
1836 // |afterChange| is 0 in the parser callback case, so we won't do any work f or the forward case if we don't have to. 1837 // |afterChange| is 0 in the parser callback case, so we won't do any work f or the forward case if we don't have to.
1837 // For performance reasons we just mark the parent node as changed, since we don't want to make childrenChanged O(n^2) by crawling all our kids 1838 // For performance reasons we just mark the parent node as changed, since we don't want to make childrenChanged O(n^2) by crawling all our kids
1838 // here. recalcStyle will then force a walk of the children when it sees tha t this has happened. 1839 // here. recalcStyle will then force a walk of the children when it sees tha t this has happened.
1839 if ((childrenAffectedByForwardPositionalRules() && afterChange) || (children AffectedByBackwardPositionalRules() && beforeChange)) { 1840 if (((childrenAffectedByForwardPositionalRules() || childrenAffectedByIndire ctAdjacentRules()) && afterChange)
1841 || (childrenAffectedByBackwardPositionalRules() && beforeChange)) {
1840 setNeedsStyleRecalc(SubtreeStyleChange); 1842 setNeedsStyleRecalc(SubtreeStyleChange);
1841 return; 1843 return;
1842 } 1844 }
1843 1845
1844 // :first-child. In the parser callback case, we don't have to check anythi ng, since we were right the first time. 1846 // :first-child. In the parser callback case, we don't have to check anythi ng, since we were right the first time.
1845 // In the DOM case, we only need to do something if |afterChange| is not 0. 1847 // In the DOM case, we only need to do something if |afterChange| is not 0.
1846 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block. 1848 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block.
1847 if (childrenAffectedByFirstChildRules() && afterChange) { 1849 if (childrenAffectedByFirstChildRules() && afterChange) {
1848 // Find our new first child. 1850 // Find our new first child.
1849 Element* newFirstChild = ElementTraversal::firstWithin(*this); 1851 Element* newFirstChild = ElementTraversal::firstWithin(*this);
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 void Element::setChildrenAffectedByLastChildRules() 2537 void Element::setChildrenAffectedByLastChildRules()
2536 { 2538 {
2537 ensureElementRareData().setChildrenAffectedByLastChildRules(true); 2539 ensureElementRareData().setChildrenAffectedByLastChildRules(true);
2538 } 2540 }
2539 2541
2540 void Element::setChildrenAffectedByDirectAdjacentRules() 2542 void Element::setChildrenAffectedByDirectAdjacentRules()
2541 { 2543 {
2542 ensureElementRareData().setChildrenAffectedByDirectAdjacentRules(true); 2544 ensureElementRareData().setChildrenAffectedByDirectAdjacentRules(true);
2543 } 2545 }
2544 2546
2547 void Element::setChildrenAffectedByIndirectAdjacentRules()
2548 {
2549 ensureElementRareData().setChildrenAffectedByIndirectAdjacentRules(true);
2550 }
2551
2545 void Element::setChildrenAffectedByForwardPositionalRules() 2552 void Element::setChildrenAffectedByForwardPositionalRules()
2546 { 2553 {
2547 ensureElementRareData().setChildrenAffectedByForwardPositionalRules(true); 2554 ensureElementRareData().setChildrenAffectedByForwardPositionalRules(true);
2548 } 2555 }
2549 2556
2550 void Element::setChildrenAffectedByBackwardPositionalRules() 2557 void Element::setChildrenAffectedByBackwardPositionalRules()
2551 { 2558 {
2552 ensureElementRareData().setChildrenAffectedByBackwardPositionalRules(true); 2559 ensureElementRareData().setChildrenAffectedByBackwardPositionalRules(true);
2553 } 2560 }
2554 2561
2555 void Element::setChildIndex(unsigned index) 2562 void Element::setChildIndex(unsigned index)
2556 { 2563 {
2557 ElementRareData& rareData = ensureElementRareData(); 2564 ElementRareData& rareData = ensureElementRareData();
2558 if (RenderStyle* style = renderStyle()) 2565 if (RenderStyle* style = renderStyle())
2559 style->setUnique(); 2566 style->setUnique();
2560 rareData.setChildIndex(index); 2567 rareData.setChildIndex(index);
2561 } 2568 }
2562 2569
2563 bool Element::childrenSupportStyleSharing() const 2570 bool Element::childrenSupportStyleSharing() const
2564 { 2571 {
2565 if (!hasRareData()) 2572 if (!hasRareData())
2566 return true; 2573 return true;
2567 return !rareDataChildrenAffectedByFocus() 2574 return !rareDataChildrenAffectedByFocus()
2568 && !rareDataChildrenAffectedByHover() 2575 && !rareDataChildrenAffectedByHover()
2569 && !rareDataChildrenAffectedByActive() 2576 && !rareDataChildrenAffectedByActive()
2570 && !rareDataChildrenAffectedByDrag() 2577 && !rareDataChildrenAffectedByDrag()
2571 && !rareDataChildrenAffectedByFirstChildRules() 2578 && !rareDataChildrenAffectedByFirstChildRules()
2572 && !rareDataChildrenAffectedByLastChildRules() 2579 && !rareDataChildrenAffectedByLastChildRules()
2573 && !rareDataChildrenAffectedByDirectAdjacentRules() 2580 && !rareDataChildrenAffectedByDirectAdjacentRules()
2581 && !rareDataChildrenAffectedByIndirectAdjacentRules()
2574 && !rareDataChildrenAffectedByForwardPositionalRules() 2582 && !rareDataChildrenAffectedByForwardPositionalRules()
2575 && !rareDataChildrenAffectedByBackwardPositionalRules(); 2583 && !rareDataChildrenAffectedByBackwardPositionalRules();
2576 } 2584 }
2577 2585
2578 bool Element::rareDataStyleAffectedByEmpty() const 2586 bool Element::rareDataStyleAffectedByEmpty() const
2579 { 2587 {
2580 ASSERT(hasRareData()); 2588 ASSERT(hasRareData());
2581 return elementRareData()->styleAffectedByEmpty(); 2589 return elementRareData()->styleAffectedByEmpty();
2582 } 2590 }
2583 2591
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2616 ASSERT(hasRareData()); 2624 ASSERT(hasRareData());
2617 return elementRareData()->childrenAffectedByLastChildRules(); 2625 return elementRareData()->childrenAffectedByLastChildRules();
2618 } 2626 }
2619 2627
2620 bool Element::rareDataChildrenAffectedByDirectAdjacentRules() const 2628 bool Element::rareDataChildrenAffectedByDirectAdjacentRules() const
2621 { 2629 {
2622 ASSERT(hasRareData()); 2630 ASSERT(hasRareData());
2623 return elementRareData()->childrenAffectedByDirectAdjacentRules(); 2631 return elementRareData()->childrenAffectedByDirectAdjacentRules();
2624 } 2632 }
2625 2633
2634 bool Element::rareDataChildrenAffectedByIndirectAdjacentRules() const
2635 {
2636 ASSERT(hasRareData());
2637 return elementRareData()->childrenAffectedByIndirectAdjacentRules();
2638 }
2639
2626 bool Element::rareDataChildrenAffectedByForwardPositionalRules() const 2640 bool Element::rareDataChildrenAffectedByForwardPositionalRules() const
2627 { 2641 {
2628 ASSERT(hasRareData()); 2642 ASSERT(hasRareData());
2629 return elementRareData()->childrenAffectedByForwardPositionalRules(); 2643 return elementRareData()->childrenAffectedByForwardPositionalRules();
2630 } 2644 }
2631 2645
2632 bool Element::rareDataChildrenAffectedByBackwardPositionalRules() const 2646 bool Element::rareDataChildrenAffectedByBackwardPositionalRules() const
2633 { 2647 {
2634 ASSERT(hasRareData()); 2648 ASSERT(hasRareData());
2635 return elementRareData()->childrenAffectedByBackwardPositionalRules(); 2649 return elementRareData()->childrenAffectedByBackwardPositionalRules();
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
3540 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3554 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3541 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3555 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3542 if (isHTMLOptionElement(*this) || isHTMLOptGroupElement(*this)) 3556 if (isHTMLOptionElement(*this) || isHTMLOptGroupElement(*this))
3543 return false; 3557 return false;
3544 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3558 if (FullscreenElementStack::isActiveFullScreenElement(this))
3545 return false; 3559 return false;
3546 return true; 3560 return true;
3547 } 3561 }
3548 3562
3549 } // namespace WebCore 3563 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698