Changeset 166173 in webkit


Ignore:
Timestamp:
Mar 24, 2014, 9:49:39 AM (11 years ago)
Author:
Antti Koivisto
Message:

Invalidate sibling text node style when needed instead of attaching synchronously
https://bugs.webkit.org/show_bug.cgi?id=130590

Reviewed by Andreas Kling.

Make things simpler.

  • style/StyleResolveTree.cpp:

(WebCore::Style::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded):

Just invalidate instead of calling attach directly.
Rename to match.

(WebCore::Style::textRendererIsNeeded):
(WebCore::Style::createTextRendererIfNeeded):

Move all testing to textRendererIsNeeded.

(WebCore::Style::updateTextRendererAfterContentChange):

Call resolveTextNode instead of re-implementing the same thing.

(WebCore::Style::resolveLocal):
(WebCore::Style::resolveTextNode):

Avoid unnecessary reattaching.
Rename for consistency.

(WebCore::Style::resolveShadowTree):
(WebCore::Style::resolveTree):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r166172 r166173  
     12014-03-24  Antti Koivisto  <antti@apple.com>
     2
     3        Invalidate sibling text node style when needed instead of attaching synchronously
     4        https://bugs.webkit.org/show_bug.cgi?id=130590
     5
     6        Reviewed by Andreas Kling.
     7       
     8        Make things simpler.
     9
     10        * style/StyleResolveTree.cpp:
     11        (WebCore::Style::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded):
     12       
     13            Just invalidate instead of calling attach directly.
     14            Rename to match.
     15
     16        (WebCore::Style::textRendererIsNeeded):
     17        (WebCore::Style::createTextRendererIfNeeded):
     18       
     19            Move all testing to textRendererIsNeeded.
     20
     21        (WebCore::Style::updateTextRendererAfterContentChange):
     22       
     23            Call resolveTextNode instead of re-implementing the same thing.
     24
     25        (WebCore::Style::resolveLocal):
     26        (WebCore::Style::resolveTextNode):
     27       
     28            Avoid unnecessary reattaching.
     29            Rename for consistency.
     30
     31        (WebCore::Style::resolveShadowTree):
     32        (WebCore::Style::resolveTree):
     33       
    1342014-03-24  Zsolt Borbely  <zsborbely.u-szeged@partner.samsung.com>
    235
  • TabularUnified trunk/Source/WebCore/style/StyleResolveTree.cpp

    r166144 r166173  
    6565static void attachTextRenderer(Text&, ContainerNode& renderingParentNode);
    6666static void detachRenderTree(Element&, DetachType);
     67static void resolveTextNode(Text&, ContainerNode& renderingParentNode);
    6768static void resolveTree(Element&, ContainerNode& renderingParentNode, Change);
    6869
     
    295296}
    296297
    297 static void reattachTextRenderersForWhitespaceOnlySiblingsAfterAttachIfNeeded(Node& current, ContainerNode& renderingParentNode)
     298static void invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node& current)
    298299{
    299300    if (isInsertionPoint(current))
     
    302303    // the current node gaining or losing the renderer. This can only affect white space text nodes.
    303304    for (Node* sibling = current.nextSibling(); sibling; sibling = sibling->nextSibling()) {
    304         // Siblings haven't been attached yet. They will be handled normally when they are.
    305         if (sibling->styleChangeType() == ReconstructRenderTree)
     305        if (sibling->needsStyleRecalc())
    306306            return;
    307307        if (sibling->isElementNode()) {
     
    313313        if (!sibling->isTextNode())
    314314            continue;
    315         Text& textSibling = *toText(sibling);
    316         if (!textSibling.length() || !textSibling.containsOnlyWhitespace())
    317             return;
    318         Text& whitespaceTextSibling = textSibling;
    319         bool hadRenderer = whitespaceTextSibling.renderer();
    320         detachTextRenderer(whitespaceTextSibling);
    321         attachTextRenderer(whitespaceTextSibling, renderingParentNode);
    322         // No changes, futher renderers can't be affected.
    323         if (hadRenderer == !!whitespaceTextSibling.renderer())
    324             return;
    325     }
    326 }
    327 
    328 static bool textRendererIsNeeded(const Text& textNode, const RenderObject& parentRenderer, const RenderStyle& style)
    329 {
     315        Text& textSibling = toText(*sibling);
     316        if (!textSibling.containsOnlyWhitespace())
     317            continue;
     318        textSibling.setNeedsStyleRecalc();
     319    }
     320}
     321
     322static bool textRendererIsNeeded(const Text& textNode, ContainerNode& renderingParentNode)
     323{
     324    if (!renderingParentNode.renderer())
     325        return false;
     326    RenderElement& parentRenderer = *renderingParentNode.renderer();
     327    if (!parentRenderer.canHaveChildren())
     328        return false;
     329    if (!renderingParentNode.childShouldCreateRenderer(textNode))
     330        return false;
     331
    330332    if (textNode.isEditingText())
    331333        return true;
    332334    if (!textNode.length())
    333335        return false;
    334     if (style.display() == NONE)
     336    if (parentRenderer.style().display() == NONE)
    335337        return false;
    336338    if (!textNode.containsOnlyWhitespace())
     
    339341    if (parentRenderer.isTable() || parentRenderer.isTableRow() || parentRenderer.isTableSection() || parentRenderer.isRenderTableCol() || parentRenderer.isFrameSet())
    340342        return false;
    341     if (style.preserveNewline()) // pre/pre-wrap/pre-line always make renderers.
     343    if (parentRenderer.style().preserveNewline()) // pre/pre-wrap/pre-line always make renderers.
    342344        return true;
    343345
     
    354356            return false;
    355357       
    356         RenderObject* first = toRenderElement(parentRenderer).firstChild();
     358        RenderObject* first = parentRenderer.firstChild();
    357359        while (first && first->isFloatingOrOutOfFlowPositioned())
    358360            first = first->nextSibling();
     
    370372    ASSERT(!textNode.renderer());
    371373
    372     RenderElement* parentRenderer = renderingParentNode.renderer();
    373     if (!parentRenderer || !parentRenderer->canHaveChildren())
    374         return;
    375     if (!renderingParentNode.childShouldCreateRenderer(textNode))
    376         return;
    377 
    378     const auto& style = parentRenderer->style();
    379 
    380     if (!textRendererIsNeeded(textNode, *parentRenderer, style))
    381         return;
     374    if (!textRendererIsNeeded(textNode, renderingParentNode))
     375        return;
     376    RenderElement& parentRenderer = *renderingParentNode.renderer();
     377    const auto& style = parentRenderer.style();
    382378
    383379    auto newRenderer = textNode.createTextRenderer(style);
    384380    ASSERT(newRenderer);
    385381
    386     if (!parentRenderer->isChildAllowed(*newRenderer, style))
     382    if (!parentRenderer.isChildAllowed(*newRenderer, style))
    387383        return;
    388384
    389385    // Make sure the RenderObject already knows it is going to be added to a RenderFlowThread before we set the style
    390386    // for the first time. Otherwise code using inRenderFlowThread() in the styleWillChange and styleDidChange will fail.
    391     newRenderer->setFlowThreadState(parentRenderer->flowThreadState());
     387    newRenderer->setFlowThreadState(parentRenderer.flowThreadState());
    392388
    393389    RenderObject* nextRenderer = nextSiblingRenderer(textNode, renderingParentNode);
    394390    textNode.setRenderer(newRenderer.get());
    395391    // Parent takes care of the animations, no need to call setAnimatableStyle.
    396     parentRenderer->addChild(newRenderer.leakPtr(), nextRenderer);
     392    parentRenderer.addChild(newRenderer.leakPtr(), nextRenderer);
    397393}
    398394
     
    413409void updateTextRendererAfterContentChange(Text& textNode, unsigned offsetOfReplacedData, unsigned lengthOfReplacedData)
    414410{
    415     RenderText* textRenderer = textNode.renderer();
    416411    ContainerNode* renderingParentNode = NodeRenderingTraversal::parent(&textNode);
    417412    if (!renderingParentNode)
    418413        return;
    419     if (!textRenderer) {
    420         attachTextRenderer(textNode, *renderingParentNode);
    421         reattachTextRenderersForWhitespaceOnlySiblingsAfterAttachIfNeeded(textNode, *renderingParentNode);
    422         return;
    423     }
    424     if (!textRendererIsNeeded(textNode, *renderingParentNode->renderer(), textRenderer->style())) {
    425         detachTextRenderer(textNode);
    426         attachTextRenderer(textNode, *renderingParentNode);
    427         reattachTextRenderersForWhitespaceOnlySiblingsAfterAttachIfNeeded(textNode, *renderingParentNode);
    428         return;
    429     }
    430     textRenderer->setTextWithOffset(textNode.dataImpl(), offsetOfReplacedData, lengthOfReplacedData);
     414
     415    bool hadRenderer = textNode.renderer();
     416    resolveTextNode(textNode, *renderingParentNode);
     417
     418    if (hadRenderer && textNode.renderer())
     419        textNode.renderer()->setTextWithOffset(textNode.dataImpl(), offsetOfReplacedData, lengthOfReplacedData);
    431420}
    432421
     
    679668            detachRenderTree(current, ReattachDetach);
    680669        attachRenderTree(current, renderingParentNode, newStyle.release());
    681         reattachTextRenderersForWhitespaceOnlySiblingsAfterAttachIfNeeded(current, renderingParentNode);
     670        invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(current);
    682671
    683672        return Detach;
     
    710699}
    711700
    712 static void updateTextStyle(Text& text, ContainerNode& renderingParentNode)
    713 {
    714     RenderText* renderer = text.renderer();
    715 
    716     if (!text.needsStyleRecalc())
    717         return;
    718     if (renderer)
    719         renderer->setText(text.dataImpl());
    720     else {
    721         attachTextRenderer(text, renderingParentNode);
    722         reattachTextRenderersForWhitespaceOnlySiblingsAfterAttachIfNeeded(text, renderingParentNode);
    723     }
     701void resolveTextNode(Text& text, ContainerNode& renderingParentNode)
     702{
    724703    text.clearNeedsStyleRecalc();
     704
     705    bool hasRenderer = text.renderer();
     706    bool needsRenderer = textRendererIsNeeded(text, renderingParentNode);
     707    if (hasRenderer) {
     708        if (needsRenderer)
     709            return;
     710        detachTextRenderer(text);
     711        invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
     712        return;
     713    }
     714    if (!needsRenderer)
     715        return;
     716    attachTextRenderer(text, renderingParentNode);
     717    invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
    725718}
    726719
     
    728721{
    729722    for (Node* child = shadowRoot.firstChild(); child; child = child->nextSibling()) {
    730         if (child->isTextNode()) {
    731             updateTextStyle(*toText(child), *shadowRoot.hostElement());
     723        if (child->isTextNode() && child->needsStyleRecalc()) {
     724            resolveTextNode(*toText(child), *shadowRoot.hostElement());
    732725            continue;
    733726        }
     
    845838        bool forceCheckOfAnyElementSibling = false;
    846839        for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
    847             if (child->isTextNode()) {
    848                 updateTextStyle(*toText(child), current);
     840            if (child->isTextNode() && child->needsStyleRecalc()) {
     841                resolveTextNode(*toText(child), current);
    849842                continue;
    850843            }
Note: See TracChangeset for help on using the changeset viewer.