Changeset 229368 in webkit


Ignore:
Timestamp:
Mar 7, 2018 10:27:55 AM (6 years ago)
Author:
Antti Koivisto
Message:

checkForSiblingStyleChanges should use internal versions of the invalidation functions
https://bugs.webkit.org/show_bug.cgi?id=183405
<rdar://problem/38218310>

Reviewed by Zalan Bujtas.

Non-internal invalidateStyleForElement/Subtree() implement sibling combinator invalidation. Checking this
is only needed if the element in question changed somehow. In checkForSiblingStyleChanges we know that
another element changed and we really just want to invalidate.

  • css/SelectorChecker.cpp:

(WebCore::isFirstOfType):
(WebCore::SelectorChecker::checkOne const):

Also make :first-of-type use ChildrenAffectedByForwardPositionalRules for invalidation similar to :last-of-type
for more correct invalidation.

  • dom/Element.cpp:

(WebCore::checkForSiblingStyleChanges):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r229363 r229368  
     12018-03-07  Antti Koivisto  <antti@apple.com>
     2
     3        checkForSiblingStyleChanges should use internal versions of the invalidation functions
     4        https://bugs.webkit.org/show_bug.cgi?id=183405
     5        <rdar://problem/38218310>
     6
     7        Reviewed by Zalan Bujtas.
     8
     9        Non-internal invalidateStyleForElement/Subtree() implement sibling combinator invalidation. Checking this
     10        is only needed if the element in question changed somehow. In checkForSiblingStyleChanges we know that
     11        another element changed and we really just want to invalidate.
     12
     13        * css/SelectorChecker.cpp:
     14        (WebCore::isFirstOfType):
     15        (WebCore::SelectorChecker::checkOne const):
     16
     17        Also make :first-of-type use ChildrenAffectedByForwardPositionalRules for invalidation similar to :last-of-type
     18        for more correct invalidation.
     19
     20        * dom/Element.cpp:
     21        (WebCore::checkForSiblingStyleChanges):
     22
    1232018-03-07  Yusuke Suzuki  <utatane.tea@gmail.com>
    224
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r229307 r229368  
    104104}
    105105
    106 static inline bool isFirstOfType(SelectorChecker::CheckingContext& checkingContext, const Element& element, const QualifiedName& type)
     106static inline bool isFirstOfType(const Element& element, const QualifiedName& type)
    107107{
    108108    for (const Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(*sibling)) {
    109         addStyleRelation(checkingContext, *sibling, Style::Relation::AffectsNextSibling);
    110 
    111109        if (sibling->hasTagName(type))
    112110            return false;
     
    746744        case CSSSelector::PseudoClassFirstOfType:
    747745            // first-of-type matches the first element of its type
    748             if (element.parentElement()) {
    749                 addStyleRelation(checkingContext, element, Style::Relation::AffectedByPreviousSibling);
    750                 return isFirstOfType(checkingContext, element, element.tagQName());
     746            if (auto* parentElement = element.parentElement()) {
     747                addStyleRelation(checkingContext, *parentElement, Style::Relation::ChildrenAffectedByForwardPositionalRules);
     748                return isFirstOfType(element, element.tagQName());
    751749            }
    752750            break;
     
    786784            // FIXME: This selector is very slow.
    787785            if (Element* parentElement = element.parentElement()) {
    788                 addStyleRelation(checkingContext, element, Style::Relation::AffectedByPreviousSibling);
     786                addStyleRelation(checkingContext, *parentElement, Style::Relation::ChildrenAffectedByForwardPositionalRules);
    789787                addStyleRelation(checkingContext, *parentElement, Style::Relation::ChildrenAffectedByBackwardPositionalRules);
    790788                if (!parentElement->isFinishedParsingChildren())
    791789                    return false;
    792                 return isFirstOfType(checkingContext, element, element.tagQName()) && isLastOfType(element, element.tagQName());
     790                return isFirstOfType(element, element.tagQName()) && isLastOfType(element, element.tagQName());
    793791            }
    794792            break;
  • trunk/Source/WebCore/dom/Element.cpp

    r229307 r229368  
    14811481}
    14821482
    1483 static void invalidateSiblingsIfNeeded(Element& element)
    1484 {
    1485     if (!element.affectsNextSiblingElementStyle())
    1486         return;
    1487     auto* parent = element.parentElement();
    1488     if (parent && parent->styleValidity() >= Style::Validity::SubtreeInvalid)
    1489         return;
    1490 
    1491     for (auto* sibling = element.nextElementSibling(); sibling; sibling = sibling->nextElementSibling()) {
     1483static void invalidateForSiblingCombinators(Element* sibling)
     1484{
     1485    for (; sibling; sibling = sibling->nextElementSibling()) {
    14921486        if (sibling->styleIsAffectedByPreviousSibling())
    14931487            sibling->invalidateStyleForSubtreeInternal();
     
    14951489            return;
    14961490    }
     1491}
     1492
     1493static void invalidateSiblingsIfNeeded(Element& element)
     1494{
     1495    if (!element.affectsNextSiblingElementStyle())
     1496        return;
     1497    auto* parent = element.parentElement();
     1498    if (parent && parent->styleValidity() >= Style::Validity::SubtreeInvalid)
     1499        return;
     1500
     1501    invalidateForSiblingCombinators(element.nextElementSibling());
    14971502}
    14981503
     
    20282033            auto* style = elementAfterChange->renderStyle();
    20292034            if (!style || style->firstChildState())
    2030                 elementAfterChange->invalidateStyleForSubtree();
     2035                elementAfterChange->invalidateStyleForSubtreeInternal();
    20312036        }
    20322037
     
    20352040            auto* style = newFirstElement->renderStyle();
    20362041            if (!style || !style->firstChildState())
    2037                 newFirstElement->invalidateStyleForSubtree();
     2042                newFirstElement->invalidateStyleForSubtreeInternal();
    20382043        }
    20392044    }
     
    20482053            auto* style = elementBeforeChange->renderStyle();
    20492054            if (!style || style->lastChildState())
    2050                 elementBeforeChange->invalidateStyleForSubtree();
     2055                elementBeforeChange->invalidateStyleForSubtreeInternal();
    20512056        }
    20522057
     
    20562061            auto* style = newLastElement->renderStyle();
    20572062            if (!style || !style->lastChildState())
    2058                 newLastElement->invalidateStyleForSubtree();
     2063                newLastElement->invalidateStyleForSubtreeInternal();
    20592064        }
    20602065    }
    20612066
    2062     if (elementAfterChange) {
    2063         if (elementAfterChange->styleIsAffectedByPreviousSibling())
    2064             elementAfterChange->invalidateStyleForSubtree();
    2065         else if (elementAfterChange->affectsNextSiblingElementStyle()) {
    2066             Element* elementToInvalidate = elementAfterChange;
    2067             do {
    2068                 elementToInvalidate = elementToInvalidate->nextElementSibling();
    2069             } while (elementToInvalidate && !elementToInvalidate->styleIsAffectedByPreviousSibling());
    2070 
    2071             if (elementToInvalidate)
    2072                 elementToInvalidate->invalidateStyleForSubtree();
    2073         }
    2074     }
     2067    invalidateForSiblingCombinators(elementAfterChange);
    20752068
    20762069    // We have to invalidate everything following the insertion point in the forward case, and everything before the insertion point in the
     
    20782071    if (parent.childrenAffectedByForwardPositionalRules()) {
    20792072        for (auto* next = elementAfterChange; next; next = next->nextElementSibling())
    2080             next->invalidateStyleForSubtree();
     2073            next->invalidateStyleForSubtreeInternal();
    20812074    }
    20822075    // Backward positional selectors include nth-last-child, nth-last-of-type, last-of-type and only-of-type.
    20832076    if (parent.childrenAffectedByBackwardPositionalRules()) {
    20842077        for (auto* previous = elementBeforeChange; previous; previous = previous->previousElementSibling())
    2085             previous->invalidateStyleForSubtree();
     2078            previous->invalidateStyleForSubtreeInternal();
    20862079    }
    20872080}
Note: See TracChangeset for help on using the changeset viewer.