Changeset 156377 in webkit


Ignore:
Timestamp:
Sep 24, 2013, 6:01:17 PM (12 years ago)
Author:
Antti Koivisto
Message:

Clean up some uses of first/lastChildSlow
https://bugs.webkit.org/show_bug.cgi?id=121882

Reviewed by Andreas Kling.

Tighten typing and use first/lastChild instead.

  • dom/Position.cpp:

(WebCore::Position::hasRenderedNonAnonymousDescendantsWithHeight):
(WebCore::Position::isCandidate):
(WebCore::Position::getInlineBoxAndOffset):

  • dom/Position.h:
  • dom/PositionIterator.cpp:

(WebCore::PositionIterator::isCandidate):

  • editing/CompositeEditCommand.cpp:

(WebCore::CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary):

  • rendering/RenderBlock.cpp:

(WebCore::canMergeAnonymousBlock):
(WebCore::canMergeContiguousAnonymousBlocks):
(WebCore::RenderBlock::firstLineBlock):
(WebCore::RenderBlock::updateFirstLetter):

  • rendering/RenderRegion.cpp:

(WebCore::RenderRegion::setRegionObjectsRegionStyle):
(WebCore::RenderRegion::computeChildrenStyleInRegion):

  • rendering/RenderRegion.h:
  • rendering/RenderRuby.cpp:

(WebCore::rubyBeforeBlock):
(WebCore::rubyAfterBlock):
(WebCore::lastRubyRun):

  • rendering/RenderTreeAsText.cpp:

(WebCore::write):
(WebCore::writeCounterValuesFromChildren):

  • rendering/svg/RenderSVGText.cpp:

(WebCore::findPreviousAndNextAttributes):

  • style/StyleResolveTree.cpp:

(WebCore::Style::textRendererIsNeeded):

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156374 r156377  
     12013-09-24  Antti Koivisto  <antti@apple.com>
     2
     3        Clean up some uses of first/lastChildSlow
     4        https://bugs.webkit.org/show_bug.cgi?id=121882
     5
     6        Reviewed by Andreas Kling.
     7
     8        Tighten typing and use first/lastChild instead.
     9
     10        * dom/Position.cpp:
     11        (WebCore::Position::hasRenderedNonAnonymousDescendantsWithHeight):
     12        (WebCore::Position::isCandidate):
     13        (WebCore::Position::getInlineBoxAndOffset):
     14        * dom/Position.h:
     15        * dom/PositionIterator.cpp:
     16        (WebCore::PositionIterator::isCandidate):
     17        * editing/CompositeEditCommand.cpp:
     18        (WebCore::CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary):
     19        * rendering/RenderBlock.cpp:
     20        (WebCore::canMergeAnonymousBlock):
     21        (WebCore::canMergeContiguousAnonymousBlocks):
     22        (WebCore::RenderBlock::firstLineBlock):
     23        (WebCore::RenderBlock::updateFirstLetter):
     24        * rendering/RenderRegion.cpp:
     25        (WebCore::RenderRegion::setRegionObjectsRegionStyle):
     26        (WebCore::RenderRegion::computeChildrenStyleInRegion):
     27        * rendering/RenderRegion.h:
     28        * rendering/RenderRuby.cpp:
     29        (WebCore::rubyBeforeBlock):
     30        (WebCore::rubyAfterBlock):
     31        (WebCore::lastRubyRun):
     32        * rendering/RenderTreeAsText.cpp:
     33        (WebCore::write):
     34        (WebCore::writeCounterValuesFromChildren):
     35        * rendering/svg/RenderSVGText.cpp:
     36        (WebCore::findPreviousAndNextAttributes):
     37        * style/StyleResolveTree.cpp:
     38        (WebCore::Style::textRendererIsNeeded):
     39
    1402013-09-24  Mark Lam  <mark.lam@apple.com>
    241
  • trunk/Source/WebCore/dom/Position.cpp

    r156285 r156377  
    852852}
    853853
    854 bool Position::hasRenderedNonAnonymousDescendantsWithHeight(RenderObject* renderer)
    855 {
    856     RenderObject* stop = renderer->nextInPreOrderAfterChildren();
    857     for (RenderObject *o = renderer->firstChildSlow(); o && o != stop; o = o->nextInPreOrder())
     854bool Position::hasRenderedNonAnonymousDescendantsWithHeight(const RenderElement& renderer)
     855{
     856    RenderObject* stop = renderer.nextInPreOrderAfterChildren();
     857    for (RenderObject* o = renderer.firstChild(); o && o != stop; o = o->nextInPreOrder())
    858858        if (o->nonPseudoNode()) {
    859859            if ((o->isText() && boundingBoxLogicalHeight(o, toRenderText(o)->linesBoundingBox()))
     
    938938       
    939939    if (renderer->isRenderBlockFlow()) {
    940         if (toRenderBlock(renderer)->logicalHeight() || m_anchorNode->hasTagName(bodyTag)) {
    941             if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(renderer))
     940        RenderBlock& block = toRenderBlock(*renderer);
     941        if (block.logicalHeight() || m_anchorNode->hasTagName(bodyTag)) {
     942            if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(block))
    942943                return atFirstEditingPositionForNode() && !Position::nodeIsUserSelectNone(deprecatedNode());
    943944            return m_anchorNode->rendererIsEditable() && !Position::nodeIsUserSelectNone(deprecatedNode()) && atEditingBoundary();
     
    12301231    } else {
    12311232        inlineBox = 0;
    1232         if (canHaveChildrenForEditing(deprecatedNode()) && renderer->isRenderBlockFlow() && hasRenderedNonAnonymousDescendantsWithHeight(renderer)) {
     1233        if (canHaveChildrenForEditing(deprecatedNode()) && renderer->isRenderBlockFlow() && hasRenderedNonAnonymousDescendantsWithHeight(toRenderBlock(*renderer))) {
    12331234            // Try a visually equivalent position with possibly opposite editability. This helps in case |this| is in
    12341235            // an editable block but surrounded by non-editable positions. It acts to negate the logic at the beginning
  • trunk/Source/WebCore/dom/Position.h

    r154877 r156377  
    4242class Node;
    4343class Range;
     44class RenderElement;
    4445class RenderObject;
    4546class Text;
     
    187188    TextDirection primaryDirection() const;
    188189
    189     static bool hasRenderedNonAnonymousDescendantsWithHeight(RenderObject*);
     190    static bool hasRenderedNonAnonymousDescendantsWithHeight(const RenderElement&);
    190191    static bool nodeIsUserSelectNone(Node*);
    191192#if ENABLE(USERSELECT_ALL)
  • trunk/Source/WebCore/dom/PositionIterator.cpp

    r155366 r156377  
    161161
    162162    if (!m_anchorNode->hasTagName(htmlTag) && renderer->isRenderBlockFlow()) {
    163         if (toRenderBlock(renderer)->logicalHeight() || m_anchorNode->hasTagName(bodyTag)) {
    164             if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(renderer))
     163        RenderBlock& block = toRenderBlock(*renderer);
     164        if (block.logicalHeight() || m_anchorNode->hasTagName(bodyTag)) {
     165            if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(block))
    165166                return atStartOfNode() && !Position::nodeIsUserSelectNone(m_anchorNode);
    166167            return m_anchorNode->rendererIsEditable() && !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).atEditingBoundary();
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r156289 r156377  
    941941            // If the block is the root editable element and it contains no visible content, create a new
    942942            // block but don't try and move content into it, since there's nothing for moveParagraphs to move.
    943             if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(upstreamStart.deprecatedNode()->renderer()))
     943            if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(toRenderElement(*upstreamStart.deprecatedNode()->renderer())))
    944944                return insertNewDefaultParagraphElementAt(upstreamStart);
    945945        } else if (isBlock(upstreamEnd.deprecatedNode())) {
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r156364 r156377  
    10691069}
    10701070
    1071 static bool canMergeContiguousAnonymousBlocks(RenderObject* oldChild, RenderObject* prev, RenderObject* next)
     1071static bool canMergeAnonymousBlock(RenderBlock* anonymousBlock)
     1072{
     1073    if (anonymousBlock->beingDestroyed() || anonymousBlock->continuation())
     1074        return false;
     1075    if (anonymousBlock->isRubyRun() || anonymousBlock->isRubyBase())
     1076        return false;
     1077    return true;
     1078}
     1079
     1080static bool canMergeContiguousAnonymousBlocks(RenderObject* oldChild, RenderObject* previous, RenderObject* next)
    10721081{
    10731082    if (oldChild->documentBeingDestroyed() || oldChild->isInline() || oldChild->virtualContinuation())
    10741083        return false;
    10751084
    1076     if ((prev && (!prev->isAnonymousBlock() || toRenderBlock(prev)->continuation() || toRenderBlock(prev)->beingDestroyed()))
    1077         || (next && (!next->isAnonymousBlock() || toRenderBlock(next)->continuation() || toRenderBlock(next)->beingDestroyed())))
    1078         return false;
    1079 
    1080     // FIXME: This check isn't required when inline run-ins can't be split into continuations.
    1081     RenderObject* child = prev ? prev->firstChildSlow() : nullptr;
    1082     if (child && child->isInline() && child->isRunIn())
    1083         return false;
    1084 
    1085     if ((prev && (prev->isRubyRun() || prev->isRubyBase()))
    1086         || (next && (next->isRubyRun() || next->isRubyBase())))
    1087         return false;
    1088 
    1089     if (!prev || !next)
     1085    if (previous) {
     1086        if (!previous->isAnonymousBlock())
     1087            return false;
     1088        RenderBlock* previousAnonymousBlock = toRenderBlock(previous);
     1089        if (!canMergeAnonymousBlock(previousAnonymousBlock))
     1090            return false;
     1091        // FIXME: This check isn't required when inline run-ins can't be split into continuations.
     1092        RenderObject* child = previousAnonymousBlock->firstChild();
     1093        if (child && child->isInline() && child->isRunIn())
     1094            return false;
     1095    }
     1096    if (next) {
     1097        if (!next->isAnonymousBlock())
     1098            return false;
     1099        RenderBlock* nextAnonymousBlock = toRenderBlock(next);
     1100        if (!canMergeAnonymousBlock(nextAnonymousBlock))
     1101            return false;
     1102    }
     1103    if (!previous || !next)
    10901104        return true;
    10911105
    10921106    // Make sure the types of the anonymous blocks match up.
    1093     return prev->isAnonymousColumnsBlock() == next->isAnonymousColumnsBlock()
    1094            && prev->isAnonymousColumnSpanBlock() == next->isAnonymousColumnSpanBlock();
     1107    return previous->isAnonymousColumnsBlock() == next->isAnonymousColumnsBlock()
     1108        && previous->isAnonymousColumnSpanBlock() == next->isAnonymousColumnSpanBlock();
    10951109}
    10961110
     
    57475761        if (hasPseudo)
    57485762            break;
    5749         RenderObject* parentBlock = firstLineBlock->parent();
     5763        RenderElement* parentBlock = firstLineBlock->parent();
    57505764        // We include isRenderButton in this check because buttons are
    57515765        // implemented using flex box but should still support first-line. The
     
    57555769        // of flexbox.
    57565770        if (firstLineBlock->isReplaced() || firstLineBlock->isFloating()
    5757             || !parentBlock || parentBlock->firstChildSlow() != firstLineBlock || (!parentBlock->isRenderBlockFlow() && !parentBlock->isRenderButton()))
     5771            || !parentBlock || parentBlock->firstChild() != firstLineBlock || (!parentBlock->isRenderBlockFlow() && !parentBlock->isRenderButton()))
    57585772            break;
    5759         ASSERT_WITH_SECURITY_IMPLICATION(parentBlock->isRenderBlock());
    57605773        firstLineBlock = toRenderBlock(parentBlock);
    57615774    }
     
    57955808}
    57965809
    5797 static inline RenderElement* findFirstLetterBlock(RenderBlock* start)
    5798 {
    5799     RenderElement* firstLetterBlock = start;
     5810static inline RenderBlock* findFirstLetterBlock(RenderBlock* start)
     5811{
     5812    RenderBlock* firstLetterBlock = start;
    58005813    while (true) {
    58015814        // We include isRenderButton in these two checks because buttons are
     
    58155828            || (!parentBlock->isRenderBlockFlow() && !parentBlock->isRenderButton()))
    58165829            return 0;
    5817         firstLetterBlock = parentBlock;
     5830        firstLetterBlock = toRenderBlock(parentBlock);
    58185831    }
    58195832
     
    59495962    // FIXME: We need to destroy the first-letter object if it is no longer the first child. Need to find
    59505963    // an efficient way to check for that situation though before implementing anything.
    5951     RenderObject* firstLetterBlock = findFirstLetterBlock(this);
     5964    RenderElement* firstLetterBlock = findFirstLetterBlock(this);
    59525965    if (!firstLetterBlock)
    59535966        return;
    59545967
    5955     // Drill into inlines looking for our first text child.
    5956     RenderObject* currChild = firstLetterBlock->firstChildSlow();
    5957     while (currChild) {
    5958         if (currChild->isText())
     5968    // Drill into inlines looking for our first text descendant.
     5969    RenderObject* descendant = firstLetterBlock->firstChild();
     5970    while (descendant) {
     5971        if (descendant->isText())
    59595972            break;
    5960         if (currChild->isListMarker())
    5961             currChild = currChild->nextSibling();
    5962         else if (currChild->isFloatingOrOutOfFlowPositioned()) {
    5963             if (currChild->style()->styleType() == FIRST_LETTER) {
    5964                 currChild = currChild->firstChildSlow();
     5973        RenderElement& current = toRenderElement(*descendant);
     5974        if (current.isListMarker())
     5975            descendant = current.nextSibling();
     5976        else if (current.isFloatingOrOutOfFlowPositioned()) {
     5977            if (current.style()->styleType() == FIRST_LETTER) {
     5978                descendant = current.firstChild();
    59655979                break;
    59665980            }
    5967             currChild = currChild->nextSibling();
    5968         } else if (currChild->isReplaced() || currChild->isRenderButton() || currChild->isMenuList())
     5981            descendant = current.nextSibling();
     5982        } else if (current.isReplaced() || current.isRenderButton() || current.isMenuList())
    59695983            break;
    5970         else if (currChild->style()->hasPseudoStyle(FIRST_LETTER) && currChild->canHaveGeneratedChildren())  {
     5984        else if (current.style()->hasPseudoStyle(FIRST_LETTER) && current.canHaveGeneratedChildren())  {
    59715985            // We found a lower-level node with first-letter, which supersedes the higher-level style
    5972             firstLetterBlock = currChild;
    5973             currChild = currChild->firstChildSlow();
     5986            firstLetterBlock = &current;
     5987            descendant = current.firstChild();
    59745988        } else
    5975             currChild = currChild->firstChildSlow();
    5976     }
    5977 
    5978     if (!currChild)
     5989            descendant = current.firstChild();
     5990    }
     5991
     5992    if (!descendant)
    59795993        return;
    59805994
    59815995    // If the child already has style, then it has already been created, so we just want
    59825996    // to update it.
    5983     if (currChild->parent()->style()->styleType() == FIRST_LETTER) {
    5984         updateFirstLetterStyle(firstLetterBlock, currChild);
    5985         return;
    5986     }
    5987 
    5988     if (!currChild->isText())
     5997    if (descendant->parent()->style()->styleType() == FIRST_LETTER) {
     5998        updateFirstLetterStyle(firstLetterBlock, descendant);
     5999        return;
     6000    }
     6001
     6002    if (!descendant->isText())
    59896003        return;
    59906004
     
    59936007    LayoutStateDisabler layoutStateDisabler(&view());
    59946008
    5995     createFirstLetterRenderer(firstLetterBlock, toRenderText(currChild));
     6009    createFirstLetterRenderer(firstLetterBlock, toRenderText(descendant));
    59966010}
    59976011
  • trunk/Source/WebCore/rendering/RenderRegion.cpp

    r156285 r156377  
    498498            continue;
    499499
    500         RenderObject* object = element->renderer();
     500        RenderElement* object = element->renderer();
    501501        // If the content node does not flow any of its children in this region,
    502502        // we do not compute any style for them in this region.
     
    579579}
    580580
    581 void RenderRegion::computeChildrenStyleInRegion(const RenderObject* object)
    582 {
    583     for (RenderObject* child = object->firstChildSlow(); child; child = child->nextSibling()) {
     581void RenderRegion::computeChildrenStyleInRegion(const RenderElement* object)
     582{
     583    for (RenderObject* child = object->firstChild(); child; child = child->nextSibling()) {
    584584
    585585        RenderObjectRegionStyleMap::iterator it = m_renderObjectRegionStyle.find(child);
     
    601601        setObjectStyleInRegion(child, childStyleInRegion, objectRegionStyleCached);
    602602
    603         computeChildrenStyleInRegion(child);
     603        if (child->isRenderElement())
     604            computeChildrenStyleInRegion(toRenderElement(child));
    604605    }
    605606}
  • trunk/Source/WebCore/rendering/RenderRegion.h

    r156093 r156377  
    191191
    192192    PassRefPtr<RenderStyle> computeStyleInRegion(const RenderObject*);
    193     void computeChildrenStyleInRegion(const RenderObject*);
     193    void computeChildrenStyleInRegion(const RenderElement*);
    194194    void setObjectStyleInRegion(RenderObject*, PassRefPtr<RenderStyle>, bool objectRegionStyleCached);
    195195
  • trunk/Source/WebCore/rendering/RenderRuby.cpp

    r156312 r156377  
    7272}
    7373
    74 static inline RenderBlock* rubyBeforeBlock(const RenderObject* ruby)
    75 {
    76     RenderObject* child = ruby->firstChildSlow();
     74static inline RenderBlock* rubyBeforeBlock(const RenderElement* ruby)
     75{
     76    RenderObject* child = ruby->firstChild();
    7777    return isRubyBeforeBlock(child) ? toRenderBlock(child) : 0;
    7878}
    7979
    80 static inline RenderBlock* rubyAfterBlock(const RenderObject* ruby)
    81 {
    82     RenderObject* child = ruby->lastChildSlow();
     80static inline RenderBlock* rubyAfterBlock(const RenderElement* ruby)
     81{
     82    RenderObject* child = ruby->lastChild();
    8383    return isRubyAfterBlock(child) ? toRenderBlock(child) : 0;
    8484}
     
    9292}
    9393
    94 static RenderRubyRun* lastRubyRun(const RenderObject* ruby)
    95 {
    96     RenderObject* child = ruby->lastChildSlow();
     94static RenderRubyRun* lastRubyRun(const RenderElement* ruby)
     95{
     96    RenderObject* child = ruby->lastChild();
    9797    if (child && !child->isRubyRun())
    9898        child = child->previousSibling();
  • trunk/Source/WebCore/rendering/RenderTreeAsText.cpp

    r156285 r156377  
    596596            writeTextRun(ts, text, *box);
    597597        }
    598     }
    599 
    600     for (RenderObject* child = o.firstChildSlow(); child; child = child->nextSibling()) {
    601         if (child->hasLayer())
    602             continue;
    603         write(ts, *child, indent + 1, behavior);
     598    } else {
     599        for (RenderObject* child = toRenderElement(o).firstChild(); child; child = child->nextSibling()) {
     600            if (child->hasLayer())
     601                continue;
     602            write(ts, *child, indent + 1, behavior);
     603        }
    604604    }
    605605
     
    915915}
    916916
    917 static void writeCounterValuesFromChildren(TextStream& stream, RenderObject* parent, bool& isFirstCounter)
     917static void writeCounterValuesFromChildren(TextStream& stream, RenderElement* parent, bool& isFirstCounter)
    918918{
    919919    if (!parent)
    920920        return;
    921     for (RenderObject* child = parent->firstChildSlow(); child; child = child->nextSibling()) {
     921    for (RenderObject* child = parent->firstChild(); child; child = child->nextSibling()) {
    922922        if (child->isCounter()) {
    923923            if (!isFirstCounter)
  • trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp

    r156285 r156377  
    136136}
    137137
    138 static inline bool findPreviousAndNextAttributes(RenderObject* start, RenderSVGInlineText* locateElement, bool& stopAfterNext, SVGTextLayoutAttributes*& previous, SVGTextLayoutAttributes*& next)
     138static inline bool findPreviousAndNextAttributes(RenderElement* start, RenderSVGInlineText* locateElement, bool& stopAfterNext, SVGTextLayoutAttributes*& previous, SVGTextLayoutAttributes*& next)
    139139{
    140140    ASSERT(start);
    141141    ASSERT(locateElement);
    142142    // FIXME: Make this iterative.
    143     for (RenderObject* child = start->firstChildSlow(); child; child = child->nextSibling()) {
     143    for (RenderObject* child = start->firstChild(); child; child = child->nextSibling()) {
    144144        if (child->isSVGInlineText()) {
    145145            RenderSVGInlineText* text = toRenderSVGInlineText(child);
     
    161161            continue;
    162162
    163         if (findPreviousAndNextAttributes(child, locateElement, stopAfterNext, previous, next))
     163        if (findPreviousAndNextAttributes(toRenderElement(child), locateElement, stopAfterNext, previous, next))
    164164            return true;
    165165    }
  • trunk/Source/WebCore/style/StyleResolveTree.cpp

    r156285 r156377  
    341341            return false;
    342342       
    343         RenderObject* first = parentRenderer.firstChildSlow();
     343        RenderObject* first = toRenderElement(parentRenderer).firstChild();
    344344        while (first && first->isFloatingOrOutOfFlowPositioned())
    345345            first = first->nextSibling();
Note: See TracChangeset for help on using the changeset viewer.