Changeset 224034 in webkit


Ignore:
Timestamp:
Oct 26, 2017 11:51:33 AM (6 years ago)
Author:
Antti Koivisto
Message:

Remove unnecessary whitespace invalidation logic from RenderTreeUpdater
https://bugs.webkit.org/show_bug.cgi?id=178786

Reviewed by Zalan Bujtas.

RenderTreeUpdater::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded is a somewhat complex
and confusing function for figuring out if some whitespace-only text node might need to have its
rendering status recomputed. However actually computing if a text renderer is needed is not expensive.
We can simply do it for all whitespace nodes after a sibling mutation.

This also removes a set that could have stale renderer pointers in it (they were never dereferenced).

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::addChildIgnoringContinuation):

Fix a display:contents bug exposed by this change. With display:contents a text renderer may have an anonymous
inline wrapper and we need to take it into account when the text renderer is the beforeChild.

Tested by imported/w3c/web-platform-tests/css/css-display-3/display-contents-state-change-001.html

  • style/RenderTreeUpdater.cpp:

(WebCore::RenderTreeUpdater::updateRenderTree):

Call updateTextRenderer() for all whitespace-only text nodes after a change in siblings.
In normal update case it just figures out quickly (by calling textRendererIsNeeded)
that there are no changes and bails out.

(WebCore::RenderTreeUpdater::updateElementRenderer):
(WebCore::RenderTreeUpdater::updateTextRenderer):
(WebCore::RenderTreeUpdater::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded): Deleted.

No longer needed. Just mark that there have been changes to siblings instead.

  • style/RenderTreeUpdater.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r224033 r224034  
     12017-10-26  Antti Koivisto  <antti@apple.com>
     2
     3        Remove unnecessary whitespace invalidation logic from RenderTreeUpdater
     4        https://bugs.webkit.org/show_bug.cgi?id=178786
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        RenderTreeUpdater::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded is a somewhat complex
     9        and confusing function for figuring out if some whitespace-only text node might need to have its
     10        rendering status recomputed. However actually computing if a text renderer is needed is not expensive.
     11        We can simply do it for all whitespace nodes after a sibling mutation.
     12
     13        This also removes a set that could have stale renderer pointers in it (they were never dereferenced).
     14
     15        * rendering/RenderBlock.cpp:
     16        (WebCore::RenderBlock::addChildIgnoringContinuation):
     17
     18            Fix a display:contents bug exposed by this change. With display:contents a text renderer may have an anonymous
     19            inline wrapper and we need to take it into account when the text renderer is the beforeChild.
     20
     21            Tested by imported/w3c/web-platform-tests/css/css-display-3/display-contents-state-change-001.html
     22
     23        * style/RenderTreeUpdater.cpp:
     24        (WebCore::RenderTreeUpdater::updateRenderTree):
     25
     26            Call updateTextRenderer() for all whitespace-only text nodes after a change in siblings.
     27            In normal update case it just figures out quickly (by calling textRendererIsNeeded)
     28            that there are no changes and bails out.
     29
     30        (WebCore::RenderTreeUpdater::updateElementRenderer):
     31        (WebCore::RenderTreeUpdater::updateTextRenderer):
     32        (WebCore::RenderTreeUpdater::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded): Deleted.
     33
     34            No longer needed. Just mark that there have been changes to siblings instead.
     35
     36        * style/RenderTreeUpdater.h:
     37
    1382017-10-26  Myles C. Maxfield  <mmaxfield@apple.com>
    239
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r223476 r224034  
    555555
    556556        if (beforeChildContainer->isAnonymous()) {
     557            if (beforeChildContainer->isInline()) {
     558                ASSERT(RenderText::findByDisplayContentsInlineWrapperCandidate(*beforeChildContainer) == beforeChild);
     559                addChild(WTFMove(newChild), beforeChildContainer);
     560                return;
     561            }
    557562            // If the requested beforeChild is not one of our children, then this is because
    558563            // there is an anonymous container within this object that contains the beforeChild.
  • trunk/Source/WebCore/style/RenderTreeUpdater.cpp

    r223848 r224034  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    175175            auto& text = downcast<Text>(node);
    176176            auto* textUpdate = m_styleUpdate->textUpdate(text);
    177             if ((parent().updates && parent().updates->update.change == Style::Detach) || textUpdate || m_invalidatedWhitespaceOnlyTextSiblings.contains(&text))
     177            bool didCreateParent = parent().updates && parent().updates->update.change == Style::Detach;
     178            bool mayNeedUpdateWhitespaceOnlyRenderer = parent().didCreateOrDestroyChildRenderer && text.containsOnlyWhitespace();
     179            if (didCreateParent || textUpdate || mayNeedUpdateWhitespaceOnlyRenderer)
    178180                updateTextRenderer(text, textUpdate);
    179181
     
    212214
    213215    popParentsToDepth(0);
    214 
    215     m_invalidatedWhitespaceOnlyTextSiblings.clear();
    216216}
    217217
     
    314314        auto teardownType = update.style->display() == NONE ? TeardownType::RendererUpdateCancelingAnimations : TeardownType::RendererUpdate;
    315315        tearDownRenderers(element, teardownType);
     316
     317        parent().didCreateOrDestroyChildRenderer = true;
    316318    }
    317319
     
    327329            element.willAttachRenderers();
    328330        createRenderer(element, RenderStyle::clone(*update.style));
    329         invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(element);
     331
     332        parent().didCreateOrDestroyChildRenderer = true;
    330333        return;
    331334    }
     
    481484        }
    482485        tearDownRenderer(text);
    483         invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
     486        parent().didCreateOrDestroyChildRenderer = true;
    484487        return;
    485488    }
     
    487490        return;
    488491    createTextRenderer(text, renderTreePosition(), textUpdate);
    489     invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
    490 }
    491 
    492 void RenderTreeUpdater::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node& current)
    493 {
    494     // FIXME: This needs to traverse in composed tree order.
    495 
    496     // This function finds sibling text renderers where the results of textRendererIsNeeded may have changed as a result of
    497     // the current node gaining or losing the renderer. This can only affect white space text nodes.
    498     for (Node* sibling = current.nextSibling(); sibling; sibling = sibling->nextSibling()) {
    499         if (is<Element>(*sibling)) {
    500             if (m_styleUpdate->elementUpdates(downcast<Element>(*sibling)))
    501                 return;
    502             // Text renderers beyond rendered elements can't be affected.
    503             if (sibling->renderer())
    504                 return;
    505             continue;
    506         }
    507         if (!is<Text>(*sibling))
    508             continue;
    509         Text& textSibling = downcast<Text>(*sibling);
    510         if (m_styleUpdate->textUpdate(textSibling))
    511             return;
    512         if (!textSibling.containsOnlyWhitespace())
    513             continue;
    514         m_invalidatedWhitespaceOnlyTextSiblings.add(&textSibling);
    515     }
     492    parent().didCreateOrDestroyChildRenderer = true;
    516493}
    517494
  • trunk/Source/WebCore/style/RenderTreeUpdater.h

    r223848 r224034  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6262    void updateElementRenderer(Element&, const Style::ElementUpdate&);
    6363    void createRenderer(Element&, RenderStyle&&);
    64     void invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node&);
    6564    void updateBeforeDescendants(Element&, const Style::ElementUpdates*);
    6665    void updateAfterDescendants(Element&, const Style::ElementUpdates*);
     
    7271        const Style::ElementUpdates* updates { nullptr };
    7372        std::optional<RenderTreePosition> renderTreePosition;
     73
     74        bool didCreateOrDestroyChildRenderer { false };
    7475        RenderObject* previousChildRenderer { nullptr };
    7576
     
    9697    Vector<Parent> m_parentStack;
    9798
    98     HashSet<Text*> m_invalidatedWhitespaceOnlyTextSiblings;
    99 
    10099    std::unique_ptr<GeneratedContent> m_generatedContent;
    101100};
Note: See TracChangeset for help on using the changeset viewer.