Changeset 199054 in webkit


Ignore:
Timestamp:
Apr 5, 2016, 3:29:31 AM (9 years ago)
Author:
Antti Koivisto
Message:

Use RenderTreeUpdater for text node mutations
https://bugs.webkit.org/show_bug.cgi?id=156107

Reviewed by Andreas Kling.

Source/WebCore:

Use the new mechanism for updating render tree after text node content changes.

  • dom/CharacterData.cpp:

(WebCore::CharacterData::parserAppendData):
(WebCore::CharacterData::setDataAndUpdate):

  • dom/Text.cpp:

(WebCore::Text::createWithLengthLimit):
(WebCore::Text::updateRendererAfterContentChange):

Update using RenderTreeUpdater.

(WebCore::Text::formatForDebugger):

  • dom/Text.h:

(WebCore::Text::Text):

  • style/StyleTreeResolver.cpp:

(WebCore::Style::TreeResolver::styleForElement):
(WebCore::Style::resetStyleForNonRenderedDescendants):
(WebCore::Style::TreeResolver::resolveElement):
(WebCore::Style::elementImplicitVisibility):
(WebCore::Style::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded): Deleted.
(WebCore::Style::textRendererIsNeeded): Deleted.
(WebCore::Style::createTextRendererIfNeeded): Deleted.
(WebCore::Style::attachTextRenderer): Deleted.
(WebCore::Style::detachTextRenderer): Deleted.
(WebCore::Style::updateTextRendererAfterContentChange): Deleted.
(WebCore::Style::resolveTextNode): Deleted.

Kill the old code paths.

  • style/StyleTreeResolver.h:

LayoutTests:

Mostly just revert non-rendered whitespace related changes from the earlier patches.

  • editing/style/remove-underline-from-stylesheet-expected.txt:
  • editing/style/typing-style-003-expected.txt:
  • platform/ios-simulator/editing/style/typing-style-003-expected.txt: Removed.
  • platform/mac-wk2/editing/mac/spelling/autocorrection-contraction-expected.txt:
  • platform/mac/editing/inserting/editable-html-element-expected.txt:
  • platform/mac/editing/inserting/editing-empty-divs-expected.txt:
  • platform/mac/editing/inserting/insert-at-end-02-expected.txt:
  • platform/mac/editing/pasteboard/4989774-expected.txt:
  • platform/mac/editing/selection/4983858-expected.txt:
Location:
trunk
Files:
1 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r199034 r199054  
     12016-04-05  Antti Koivisto  <antti@apple.com>
     2
     3        Use RenderTreeUpdater for text node mutations
     4        https://bugs.webkit.org/show_bug.cgi?id=156107
     5
     6        Reviewed by Andreas Kling.
     7
     8        Mostly just revert non-rendered whitespace related changes from the earlier patches.
     9
     10        * editing/style/remove-underline-from-stylesheet-expected.txt:
     11        * editing/style/typing-style-003-expected.txt:
     12        * platform/ios-simulator/editing/style/typing-style-003-expected.txt: Removed.
     13        * platform/mac-wk2/editing/mac/spelling/autocorrection-contraction-expected.txt:
     14        * platform/mac/editing/inserting/editable-html-element-expected.txt:
     15        * platform/mac/editing/inserting/editing-empty-divs-expected.txt:
     16        * platform/mac/editing/inserting/insert-at-end-02-expected.txt:
     17        * platform/mac/editing/pasteboard/4989774-expected.txt:
     18        * platform/mac/editing/selection/4983858-expected.txt:
     19
    1202016-04-04  Zalan Bujtas  <zalan@apple.com>
    221
  • trunk/LayoutTests/editing/mac/spelling/autocorrection-contraction-expected.txt

    r198943 r199054  
    280280            text run at (0,0) width 154: "would' wouldn't"
    281281            text run at (153,0) width 7: " "
    282 caret: position 16 of child 0 {#text} of child 6 {DIV} of child 3 {DIV} of body
     282caret: position 16 of child 0 {#text} of child 5 {DIV} of child 3 {DIV} of body
  • trunk/LayoutTests/editing/mac/spelling/autocorrection-removing-underline-after-paste-expected.txt

    r198943 r199054  
    8383        RenderBlock {DIV} at (14,70) size 756x28
    8484          RenderBR {BR} at (0,0) size 0x28
    85 caret: position 0 of child 0 {BR} of child 5 {DIV} of child 5 {DIV} of body
     85caret: position 0 of child 0 {BR} of child 4 {DIV} of child 5 {DIV} of body
  • trunk/LayoutTests/editing/mac/spelling/autocorrection-removing-underline-expected.txt

    r198943 r199054  
    7979        RenderBlock {DIV} at (14,42) size 756x28
    8080          RenderBR {BR} at (0,0) size 0x28
    81 caret: position 0 of child 0 {BR} of child 3 {DIV} of child 5 {DIV} of body
     81caret: position 0 of child 0 {BR} of child 2 {DIV} of child 5 {DIV} of body
  • trunk/LayoutTests/editing/mac/spelling/autocorrection-simple-expected.txt

    r198943 r199054  
    138138          RenderText {#text} at (0,0) size 138x28
    139139            text run at (0,0) width 138: "the notational,"
    140 caret: position 15 of child 0 {#text} of child 3 {DIV} of child 7 {DIV} of body
     140caret: position 15 of child 0 {#text} of child 2 {DIV} of child 7 {DIV} of body
  • trunk/LayoutTests/editing/style/remove-underline-from-stylesheet-expected.txt

    r198943 r199054  
    7777| "<#selection-anchor>xxxxxx<#selection-focus>"
    7878| " xxxxxx"
    79 | "
    80 "
    8179| <span>
    8280|   id="test"
  • trunk/LayoutTests/editing/style/typing-style-003-expected.txt

    r198943 r199054  
    5353xxxxxxxxxxxxxxx
    5454execTypeCharacterCommand: x <span id="test"></span>
    55 execTypeCharacterCommand: xx <span id="test"></span>
    56 execTypeCharacterCommand: xxx <span id="test"></span>
    57 execBoldCommand: xxx <span id="test"></span>
    58 execTypeCharacterCommand: xxx<b>x</b> <span id="test"></span>
     55execTypeCharacterCommand: xx<span id="test"></span>
     56execTypeCharacterCommand: xxx<span id="test"></span>
     57execBoldCommand: xxx<span id="test"></span>
     58execTypeCharacterCommand: xxx<b>x</b><span id="test"></span>
    5959execTypeCharacterCommand: xxx<b>xx</b><span id="test"></span>
    6060execTypeCharacterCommand: xxx<b>xxx</b><span id="test"></span>
  • trunk/LayoutTests/fast/dom/beforeload/remove-bad-object-in-beforeload-listener-expected.txt

    r198943 r199054  
    22
    33PASS
    4 
  • trunk/LayoutTests/fast/dom/beforeload/remove-flash-in-beforeload-listener-expected.txt

    r198943 r199054  
    22
    33PASS
    4 
  • trunk/LayoutTests/platform/mac-wk2/editing/mac/spelling/autocorrection-contraction-expected.txt

    r198943 r199054  
    260260            text run at (0,0) width 166: "wouldn' wouldn't"
    261261            text run at (165,0) width 7: " "
    262 caret: position 17 of child 0 {#text} of child 6 {DIV} of child 3 {DIV} of body
     262caret: position 17 of child 0 {#text} of child 5 {DIV} of child 3 {DIV} of body
  • trunk/LayoutTests/platform/mac/editing/inserting/editable-html-element-expected.txt

    r198943 r199054  
    2323          text run at (766,18) width 5: " "
    2424          text run at (0,36) width 132: "block flow element)."
     25        RenderText {#text} at (0,0) size 0x0
    2526      RenderBlock {DIV} at (0,54) size 784x18
    2627        RenderBR {BR} at (0,0) size 0x18
  • trunk/LayoutTests/platform/mac/editing/inserting/editing-empty-divs-expected.txt

    r198943 r199054  
    6666        RenderText {#text} at (1,1) size 8x18
    6767          text run at (1,1) width 8: "c"
     68        RenderText {#text} at (0,0) size 0x0
    6869      RenderBlock {P} at (0,268) size 784x18
    6970        RenderText {#text} at (0,0) size 240x18
     
    8182          RenderText {#text} at (0,0) size 8x18
    8283            text run at (0,0) width 8: "c"
     84          RenderText {#text} at (0,0) size 0x0
    8385        RenderBlock {P} at (1,35) size 706x0
    8486caret: position 1 of child 0 {#text} of child 21 {DIV} of body
  • trunk/LayoutTests/platform/mac/editing/inserting/insert-at-end-02-expected.txt

    r198943 r199054  
    3030          RenderText {#text} at (0,0) size 8x18
    3131            text run at (0,0) width 8: "x"
     32          RenderText {#text} at (0,0) size 0x0
    3233caret: position 1 of child 5 {#text} of child 5 {DIV} of body
  • trunk/LayoutTests/platform/mac/editing/pasteboard/4989774-expected.txt

    r198943 r199054  
    1313        text run at (735,103) width 5: " "
    1414        text run at (0,121) width 364: "several pictures above all in the same line/paragraph."
     15      RenderText {#text} at (0,0) size 0x0
     16      RenderText {#text} at (0,0) size 0x0
    1517caret: position 164 of child 4 {#text} of body
  • trunk/LayoutTests/platform/mac/editing/selection/4983858-expected.txt

    r198943 r199054  
    1111          text run at (780,0) width 4: " "
    1212          text run at (0,18) width 165: "below should be selected:"
     13        RenderText {#text} at (0,0) size 0x0
    1314      RenderBlock {DIV} at (0,36) size 784x18
    1415        RenderText {#text} at (0,0) size 22x18
  • trunk/LayoutTests/plugins/focus-expected.txt

    r198943 r199054  
    2525
    2626   Fallback contents.     Fallback contents. Fallback contents.     
    27 
  • trunk/Source/WebCore/ChangeLog

    r199053 r199054  
     12016-04-05  Antti Koivisto  <antti@apple.com>
     2
     3        Use RenderTreeUpdater for text node mutations
     4        https://bugs.webkit.org/show_bug.cgi?id=156107
     5
     6        Reviewed by Andreas Kling.
     7
     8        Use the new mechanism for updating render tree after text node content changes.
     9
     10        * dom/CharacterData.cpp:
     11        (WebCore::CharacterData::parserAppendData):
     12        (WebCore::CharacterData::setDataAndUpdate):
     13        * dom/Text.cpp:
     14        (WebCore::Text::createWithLengthLimit):
     15        (WebCore::Text::updateRendererAfterContentChange):
     16
     17            Update using RenderTreeUpdater.
     18
     19        (WebCore::Text::formatForDebugger):
     20        * dom/Text.h:
     21        (WebCore::Text::Text):
     22        * style/StyleTreeResolver.cpp:
     23        (WebCore::Style::TreeResolver::styleForElement):
     24        (WebCore::Style::resetStyleForNonRenderedDescendants):
     25        (WebCore::Style::TreeResolver::resolveElement):
     26        (WebCore::Style::elementImplicitVisibility):
     27        (WebCore::Style::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded): Deleted.
     28        (WebCore::Style::textRendererIsNeeded): Deleted.
     29        (WebCore::Style::createTextRendererIfNeeded): Deleted.
     30        (WebCore::Style::attachTextRenderer): Deleted.
     31        (WebCore::Style::detachTextRenderer): Deleted.
     32        (WebCore::Style::updateTextRendererAfterContentChange): Deleted.
     33        (WebCore::Style::resolveTextNode): Deleted.
     34
     35            Kill the old code paths.
     36
     37        * style/StyleTreeResolver.h:
     38
    1392016-04-05  Hunseop Jeong  <hs85.jeong@samsung.com>
    240
  • trunk/Source/WebCore/dom/CharacterData.cpp

    r195264 r199054  
    3333#include "RenderText.h"
    3434#include "StyleInheritedData.h"
    35 #include "StyleTreeResolver.h"
    3635#include "TextBreakIterator.h"
    3736#include <wtf/Ref.h>
     
    9089
    9190    ASSERT(!renderer() || is<Text>(*this));
    92     if (is<Text>(*this))
    93         Style::updateTextRendererAfterContentChange(downcast<Text>(*this), oldLength, 0);
     91    if (is<Text>(*this) && parentNode())
     92        downcast<Text>(*this).updateRendererAfterContentChange(oldLength, 0);
    9493
    9594    document().incDOMTreeVersion();
     
    189188
    190189    ASSERT(!renderer() || is<Text>(*this));
    191     if (is<Text>(*this))
    192         Style::updateTextRendererAfterContentChange(downcast<Text>(*this), offsetOfReplacedData, oldLength);
     190    if (is<Text>(*this) && parentNode())
     191        downcast<Text>(*this).updateRendererAfterContentChange(offsetOfReplacedData, oldLength);
    193192
    194193    if (is<ProcessingInstruction>(*this))
  • trunk/Source/WebCore/dom/Text.cpp

    r195264 r199054  
    2727#include "RenderSVGInlineText.h"
    2828#include "RenderText.h"
     29#include "RenderTreeUpdater.h"
    2930#include "SVGElement.h"
    3031#include "SVGNames.h"
     
    3334#include "StyleInheritedData.h"
    3435#include "StyleResolver.h"
     36#include "StyleUpdate.h"
    3537#include "TextNodeTraversal.h"
    3638#include <wtf/CheckedArithmetic.h>
     
    217219    return result;
    218220}
     221
     222void Text::updateRendererAfterContentChange(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData)
     223{
     224    ASSERT(parentNode());
     225    if (styleChangeType() == ReconstructRenderTree)
     226        return;
     227
     228    auto textUpdate = std::make_unique<Style::Update>(document());
     229    textUpdate->addText(*this);
     230
     231    RenderTreeUpdater renderTreeUpdater(document());
     232    renderTreeUpdater.commit(WTFMove(textUpdate));
     233
     234    if (auto* renderer = this->renderer())
     235        renderer->setTextWithOffset(data(), offsetOfReplacedData, lengthOfReplacedData);
     236}
     237
    219238
    220239#if ENABLE(TREE_DEBUGGING)
  • trunk/Source/WebCore/dom/Text.h

    r197566 r199054  
    5454    RenderText* renderer() const;
    5555
     56    void updateRendererAfterContentChange(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData);
     57
    5658protected:
    5759    Text(Document& document, const String& data, ConstructionType type)
  • trunk/Source/WebCore/style/RenderTreeUpdater.cpp

    r199008 r199054  
    9191    ASSERT(&m_document == &styleUpdate->document());
    9292
    93     if (!m_document.shouldCreateRenderers())
     93    if (!m_document.shouldCreateRenderers() || !m_document.renderView())
    9494        return;
    9595
  • trunk/Source/WebCore/style/StyleTreeResolver.cpp

    r198990 r199054  
    5151namespace Style {
    5252
    53 static void attachTextRenderer(Text&, RenderTreePosition&);
    54 static void resolveTextNode(Text&, RenderTreePosition&);
    55 
    5653class SelectorFilterPusher {
    5754public:
     
    180177}
    181178
    182 static void invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node& current)
    183 {
    184     // FIXME: This needs to traverse in composed tree order.
    185 
    186     // This function finds sibling text renderers where the results of textRendererIsNeeded may have changed as a result of
    187     // the current node gaining or losing the renderer. This can only affect white space text nodes.
    188     for (Node* sibling = current.nextSibling(); sibling; sibling = sibling->nextSibling()) {
    189         if (sibling->needsStyleRecalc())
    190             return;
    191         if (is<Element>(*sibling)) {
    192             // Text renderers beyond rendered elements can't be affected.
    193             if (!sibling->renderer() || RenderTreePosition::isRendererReparented(*sibling->renderer()))
    194                 continue;
    195             return;
    196         }
    197         if (!is<Text>(*sibling))
    198             continue;
    199         Text& textSibling = downcast<Text>(*sibling);
    200         if (!textSibling.containsOnlyWhitespace())
    201             continue;
    202         textSibling.setNeedsStyleRecalc();
    203     }
    204 }
    205 
    206 static bool textRendererIsNeeded(const Text& textNode, const RenderTreePosition& renderTreePosition)
    207 {
    208     const RenderElement& parentRenderer = renderTreePosition.parent();
    209     if (!parentRenderer.canHaveChildren())
    210         return false;
    211     if (parentRenderer.element() && !parentRenderer.element()->childShouldCreateRenderer(textNode))
    212         return false;
    213     if (textNode.isEditingText())
    214         return true;
    215     if (!textNode.length())
    216         return false;
    217     if (!textNode.containsOnlyWhitespace())
    218         return true;
    219     // This text node has nothing but white space. We may still need a renderer in some cases.
    220     if (parentRenderer.isTable() || parentRenderer.isTableRow() || parentRenderer.isTableSection() || parentRenderer.isRenderTableCol() || parentRenderer.isFrameSet())
    221         return false;
    222     if (parentRenderer.style().preserveNewline()) // pre/pre-wrap/pre-line always make renderers.
    223         return true;
    224 
    225     RenderObject* previousRenderer = renderTreePosition.previousSiblingRenderer(textNode);
    226     if (previousRenderer && previousRenderer->isBR()) // <span><br/> <br/></span>
    227         return false;
    228 
    229     if (parentRenderer.isRenderInline()) {
    230         // <span><div/> <div/></span>
    231         if (previousRenderer && !previousRenderer->isInline())
    232             return false;
    233     } else {
    234         if (parentRenderer.isRenderBlock() && !parentRenderer.childrenInline() && (!previousRenderer || !previousRenderer->isInline()))
    235             return false;
    236        
    237         RenderObject* first = parentRenderer.firstChild();
    238         while (first && first->isFloatingOrOutOfFlowPositioned())
    239             first = first->nextSibling();
    240         RenderObject* nextRenderer = renderTreePosition.nextSiblingRenderer(textNode);
    241         if (!first || nextRenderer == first) {
    242             // Whitespace at the start of a block just goes away. Don't even make a render object for this text.
    243             return false;
    244         }
    245     }
    246     return true;
    247 }
    248 
    249 static void createTextRendererIfNeeded(Text& textNode, RenderTreePosition& renderTreePosition)
    250 {
    251     ASSERT(!textNode.renderer());
    252 
    253     if (!textRendererIsNeeded(textNode, renderTreePosition))
    254         return;
    255 
    256     auto newRenderer = textNode.createTextRenderer(renderTreePosition.parent().style());
    257     ASSERT(newRenderer);
    258 
    259     renderTreePosition.computeNextSibling(textNode);
    260 
    261     if (!renderTreePosition.canInsert(*newRenderer))
    262         return;
    263 
    264     // Make sure the RenderObject already knows it is going to be added to a RenderFlowThread before we set the style
    265     // for the first time. Otherwise code using inRenderFlowThread() in the styleWillChange and styleDidChange will fail.
    266     newRenderer->setFlowThreadState(renderTreePosition.parent().flowThreadState());
    267 
    268     textNode.setRenderer(newRenderer.get());
    269     renderTreePosition.insert(*newRenderer.leakPtr());
    270 }
    271 
    272 void attachTextRenderer(Text& textNode, RenderTreePosition& renderTreePosition)
    273 {
    274     createTextRendererIfNeeded(textNode, renderTreePosition);
    275 
    276     textNode.clearNeedsStyleRecalc();
    277 }
    278 
    279179void detachTextRenderer(Text& textNode)
    280180{
     
    282182        textNode.renderer()->destroyAndCleanupAnonymousWrappers();
    283183    textNode.setRenderer(0);
    284 }
    285 
    286 void updateTextRendererAfterContentChange(Text& textNode, unsigned offsetOfReplacedData, unsigned lengthOfReplacedData)
    287 {
    288     auto* renderingParentNode = composedTreeAncestors(textNode).first();
    289     if (!renderingParentNode || !renderingParentNode->renderer())
    290         return;
    291 
    292     bool hadRenderer = textNode.renderer();
    293 
    294     RenderTreePosition renderTreePosition(*renderingParentNode->renderer());
    295     resolveTextNode(textNode, renderTreePosition);
    296 
    297     if (hadRenderer && textNode.renderer())
    298         textNode.renderer()->setTextWithOffset(textNode.data(), offsetOfReplacedData, lengthOfReplacedData);
    299184}
    300185
     
    446331}
    447332
    448 void resolveTextNode(Text& text, RenderTreePosition& renderTreePosition)
    449 {
    450     text.clearNeedsStyleRecalc();
    451 
    452     bool hasRenderer = text.renderer();
    453     bool needsRenderer = textRendererIsNeeded(text, renderTreePosition);
    454     if (hasRenderer) {
    455         if (needsRenderer)
    456             return;
    457         detachTextRenderer(text);
    458         invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
    459         return;
    460     }
    461     if (!needsRenderer)
    462         return;
    463     attachTextRenderer(text, renderTreePosition);
    464     invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
    465 }
    466 
    467333#if PLATFORM(IOS)
    468334static EVisibility elementImplicitVisibility(const Element* element)
  • trunk/Source/WebCore/style/StyleTreeResolver.h

    r198943 r199054  
    113113void detachTextRenderer(Text&);
    114114
    115 void updateTextRendererAfterContentChange(Text&, unsigned offsetOfReplacedData, unsigned lengthOfReplacedData);
    116 
    117115void queuePostResolutionCallback(std::function<void ()>);
    118116bool postResolutionCallbacksAreSuspended();
  • trunk/Source/WebCore/style/StyleUpdate.cpp

    r198943 r199054  
    6464{
    6565    ASSERT(!m_elements.contains(&element));
    66     ASSERT(!parent || composedTreeAncestors(element).first() == parent);
     66    ASSERT(composedTreeAncestors(element).first() == parent);
    6767
    6868    addPossibleRoot(parent);
     
    7373{
    7474    ASSERT(!m_texts.contains(&text));
    75     ASSERT(!parent || composedTreeAncestors(text).first() == parent);
     75    ASSERT(composedTreeAncestors(text).first() == parent);
    7676
    7777    addPossibleRoot(parent);
    7878    m_texts.add(&text);
     79}
     80
     81void Update::addText(Text& text)
     82{
     83    addText(text, composedTreeAncestors(text).first());
    7984}
    8085
  • trunk/Source/WebCore/style/StyleUpdate.h

    r198943 r199054  
    6767    void addElement(Element&, Element* parent, ElementUpdate&);
    6868    void addText(Text&, Element* parent);
     69    void addText(Text&);
    6970
    7071private:
Note: See TracChangeset for help on using the changeset viewer.