Changeset 207755 in webkit


Ignore:
Timestamp:
Oct 24, 2016 2:50:47 AM (7 years ago)
Author:
Antti Koivisto
Message:

Avoid unnecessary full style resolution in getComputedStyle for non-inherited properties
https://bugs.webkit.org/show_bug.cgi?id=163875

Reviewed by Andreas Kling.

Source/WebCore:

Test: fast/css/getComputedStyle/getComputedStyle-style-resolution.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::hasValidStyleForProperty):

For non-inherited properties we don't need to update style even if some ancestor style is invalid
as long as explicit 'inherit' is not being used.
We still need to update if we find out that the whole subtree we are in is invalid.

(WebCore::updateStyleIfNeededForProperty):

Pass the property.

(WebCore::ComputedStyleExtractor::customPropertyValue):
(WebCore::ComputedStyleExtractor::propertyValue):
(WebCore::CSSComputedStyleDeclaration::length):
(WebCore::elementOrItsAncestorNeedsStyleRecalc): Deleted.
(WebCore::updateStyleIfNeededForElement): Deleted.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::colorFromPrimitiveValue):

Mark style as using explicit inheritance if 'currentcolor' value is used.

LayoutTests:

  • fast/css/getComputedStyle/getComputedStyle-style-resolution-expected.txt: Added.
  • fast/css/getComputedStyle/getComputedStyle-style-resolution.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r207754 r207755  
     12016-10-23  Antti Koivisto  <antti@apple.com>
     2
     3        Avoid unnecessary full style resolution in getComputedStyle for non-inherited properties
     4        https://bugs.webkit.org/show_bug.cgi?id=163875
     5
     6        Reviewed by Andreas Kling.
     7
     8        * fast/css/getComputedStyle/getComputedStyle-style-resolution-expected.txt: Added.
     9        * fast/css/getComputedStyle/getComputedStyle-style-resolution.html: Added.
     10
    1112016-10-24  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r207754 r207755  
     12016-10-23  Antti Koivisto  <antti@apple.com>
     2
     3        Avoid unnecessary full style resolution in getComputedStyle for non-inherited properties
     4        https://bugs.webkit.org/show_bug.cgi?id=163875
     5
     6        Reviewed by Andreas Kling.
     7
     8        Test: fast/css/getComputedStyle/getComputedStyle-style-resolution.html
     9
     10        * css/CSSComputedStyleDeclaration.cpp:
     11        (WebCore::hasValidStyleForProperty):
     12
     13            For non-inherited properties we don't need to update style even if some ancestor style is invalid
     14            as long as explicit 'inherit' is not being used.
     15            We still need to update if we find out that the whole subtree we are in is invalid.
     16
     17        (WebCore::updateStyleIfNeededForProperty):
     18
     19            Pass the property.
     20
     21        (WebCore::ComputedStyleExtractor::customPropertyValue):
     22        (WebCore::ComputedStyleExtractor::propertyValue):
     23        (WebCore::CSSComputedStyleDeclaration::length):
     24        (WebCore::elementOrItsAncestorNeedsStyleRecalc): Deleted.
     25        (WebCore::updateStyleIfNeededForElement): Deleted.
     26        * css/StyleResolver.cpp:
     27        (WebCore::StyleResolver::colorFromPrimitiveValue):
     28
     29            Mark style as using explicit inheritance if 'currentcolor' value is used.
     30
    1312016-10-24  Youenn Fablet  <youenn@apple.com>
    232
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r207686 r207755  
    5858#include "FontTaggedSettings.h"
    5959#include "HTMLFrameOwnerElement.h"
     60#include "NodeRenderStyle.h"
    6061#include "Pair.h"
    6162#include "PseudoElement.h"
     
    23382339}
    23392340
     2341static bool isImplicitlyInheritedGridOrFlexProperty(CSSPropertyID propertyID)
     2342{
     2343    // It would be nice if grid and flex worked within normal CSS mechanisms and not invented their own inheritance system.
     2344    switch (propertyID) {
     2345    case CSSPropertyAlignSelf:
     2346#if ENABLE(CSS_GRID_LAYOUT)
     2347    case CSSPropertyJustifySelf:
     2348    case CSSPropertyJustifyItems:
     2349#endif
     2350    // FIXME: In StyleResolver::adjustRenderStyle z-index is adjusted based on the parent display property for grid/flex.
     2351    case CSSPropertyZIndex:
     2352        return true;
     2353    default:
     2354        return false;
     2355    }
     2356}
     2357
    23402358RefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
    23412359{
     
    23482366}
    23492367
    2350 static inline bool elementOrItsAncestorNeedsStyleRecalc(Element& element)
    2351 {
    2352     if (element.needsStyleRecalc())
     2368static inline bool hasValidStyleForProperty(Element& element, CSSPropertyID propertyID)
     2369{
     2370    if (element.styleValidity() != Style::Validity::Valid)
     2371        return false;
     2372    if (element.document().hasPendingForcedStyleRecalc())
     2373        return false;
     2374    if (!element.document().childNeedsStyleRecalc())
    23532375        return true;
    2354     if (element.document().hasPendingForcedStyleRecalc())
    2355         return true;
    2356     if (!element.document().childNeedsStyleRecalc())
    2357         return false;
     2376
     2377    bool isInherited = CSSProperty::isInheritedProperty(propertyID) || isImplicitlyInheritedGridOrFlexProperty(propertyID);
     2378    bool maybeExplicitlyInherited = !isInherited;
    23582379
    23592380    const auto* currentElement = &element;
    23602381    for (auto& ancestor : composedTreeAncestors(element)) {
    2361         if (ancestor.needsStyleRecalc())
    2362             return true;
     2382        if (ancestor.styleValidity() >= Style::Validity::SubtreeInvalid)
     2383            return false;
     2384
     2385        if (maybeExplicitlyInherited) {
     2386            auto* style = currentElement->renderStyle();
     2387            maybeExplicitlyInherited = !style || style->hasExplicitlyInheritedProperties();
     2388        }
     2389
     2390        if ((isInherited || maybeExplicitlyInherited) && ancestor.styleValidity() == Style::Validity::ElementInvalid)
     2391            return false;
    23632392
    23642393        if (ancestor.directChildNeedsStyleRecalc() && currentElement->styleIsAffectedByPreviousSibling())
    2365             return true;
     2394            return false;
    23662395
    23672396        currentElement = &ancestor;
    23682397    }
    2369     return false;
    2370 }
    2371 
    2372 static bool updateStyleIfNeededForElement(Element& element)
     2398
     2399    return true;
     2400}
     2401
     2402static bool updateStyleIfNeededForProperty(Element& element, CSSPropertyID propertyID)
    23732403{
    23742404    auto& document = element.document();
     
    23762406    document.styleScope().flushPendingUpdate();
    23772407
    2378     if (!elementOrItsAncestorNeedsStyleRecalc(element))
     2408    if (hasValidStyleForProperty(element, propertyID))
    23792409        return false;
    23802410
     
    24692499        return nullptr;
    24702500   
    2471     if (updateStyleIfNeededForElement(*styledElement)) {
     2501    if (updateStyleIfNeededForProperty(*styledElement, CSSPropertyCustom)) {
    24722502        // Style update may change styledElement() to PseudoElement or back.
    24732503        styledElement = this->styledElement();
     
    25012531        Document& document = m_element->document();
    25022532
    2503         if (updateStyleIfNeededForElement(*styledElement)) {
     2533        if (updateStyleIfNeededForProperty(*styledElement, propertyID)) {
    25042534            // Style update may change styledElement() to PseudoElement or back.
    25052535            styledElement = this->styledElement();
     
    39784008unsigned CSSComputedStyleDeclaration::length() const
    39794009{
    3980     updateStyleIfNeededForElement(m_element.get());
     4010    updateStyleIfNeededForProperty(m_element.get(), CSSPropertyCustom);
    39814011
    39824012    auto* style = m_element->computedStyle(m_pseudoElementSpecifier);
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r207669 r207755  
    18181818        return RenderTheme::focusRingColor();
    18191819    case CSSValueCurrentcolor:
     1820        // Color is an inherited property so depending on it effectively makes the property inherited.
     1821        state.style()->setHasExplicitlyInheritedProperties();
    18201822        return state.style()->color();
    18211823    default: {
Note: See TracChangeset for help on using the changeset viewer.