Changeset 69890 in webkit


Ignore:
Timestamp:
Oct 15, 2010, 3:27:52 PM (15 years ago)
Author:
mitz@apple.com
Message:

Clean up RenderFlexibleBox::applyLineClamp()
https://bugs.webkit.org/show_bug.cgi?id=47743

Reviewed by Adele Peterson.

  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::applyLineClamp):

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r69889 r69890  
     12010-10-15  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Adele Peterson.
     4
     5        Clean up RenderFlexibleBox::applyLineClamp()
     6        https://bugs.webkit.org/show_bug.cgi?id=47743
     7
     8        * rendering/RenderFlexibleBox.cpp:
     9        (WebCore::RenderFlexibleBox::applyLineClamp):
     10
    1112010-10-15  Alexey Proskuryakov  <ap@apple.com>
    212
  • trunk/WebCore/rendering/RenderFlexibleBox.cpp

    r69628 r69890  
    914914{
    915915    int maxLineCount = 0;
    916     RenderBox* child = iterator.first();
    917     while (child) {
    918         if (!child->isPositioned()) {
    919             if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())) ||
    920                 (child->style()->height().isAuto() && child->isBlockFlow() && !child->needsLayout())) {
    921                 child->setChildNeedsLayout(true, false);
    922                
    923                 // Dirty all the positioned objects.
    924                 if (child->isRenderBlock()) {
    925                     toRenderBlock(child)->markPositionedObjectsForLayout();
    926                     toRenderBlock(child)->clearTruncation();
    927                 }
    928             }
    929             child->layoutIfNeeded();
    930             if (child->style()->height().isAuto() && child->isBlockFlow())
    931                 maxLineCount = max(maxLineCount, toRenderBlock(child)->lineCount());
     916    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     917        if (child->isPositioned())
     918            continue;
     919
     920        if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))
     921            || (child->style()->height().isAuto() && child->isBlockFlow() && !child->needsLayout())) {
     922            child->setChildNeedsLayout(true, false);
     923
     924            // Dirty all the positioned objects.
     925            if (child->isRenderBlock()) {
     926                toRenderBlock(child)->markPositionedObjectsForLayout();
     927                toRenderBlock(child)->clearTruncation();
     928            }
    932929        }
    933         child = iterator.next();
    934     }
    935    
    936     // Get the # of lines and then alter all block flow children with auto height to use the
     930        child->layoutIfNeeded();
     931        if (child->style()->height().isAuto() && child->isBlockFlow())
     932            maxLineCount = max(maxLineCount, toRenderBlock(child)->lineCount());
     933    }
     934
     935    // Get the number of lines and then alter all block flow children with auto height to use the
    937936    // specified height. We always try to leave room for at least one line.
    938937    LineClampValue lineClamp = style()->lineClamp();
    939938    int numVisibleLines = lineClamp.isPercentage() ? max(1, (maxLineCount + 1) * lineClamp.value() / 100) : lineClamp.value();
    940     if (numVisibleLines < maxLineCount) {
    941         for (child = iterator.first(); child; child = iterator.next()) {
    942             if (child->isPositioned() || !child->style()->height().isAuto() || !child->isBlockFlow())
    943                 continue;
    944            
    945             RenderBlock* blockChild = toRenderBlock(child);
    946             int lineCount = blockChild->lineCount();
    947             if (lineCount <= numVisibleLines)
    948                 continue;
    949            
    950             int newHeight = blockChild->heightForLineCount(numVisibleLines);
    951             if (newHeight == child->height())
    952                 continue;
    953            
    954             child->setChildNeedsLayout(true, false);
    955             child->setOverrideSize(newHeight);
    956             m_flexingChildren = true;
    957             child->layoutIfNeeded();
    958             m_flexingChildren = false;
    959             child->setOverrideSize(-1);
    960            
    961             // FIXME: For now don't support RTL.
    962             if (style()->direction() != LTR)
    963                 continue;
    964            
    965             // Get the last line
    966             RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount-1);
    967             if (!lastLine)
    968                 continue;
    969            
    970             RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines-1);
    971             if (!lastVisibleLine)
    972                 continue;
    973            
    974             const UChar ellipsisAndSpace[2] = { horizontalEllipsis, ' ' };
    975             DEFINE_STATIC_LOCAL(AtomicString, ellipsisAndSpaceStr, (ellipsisAndSpace, 2));
    976             DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
    977             const Font& font = style(numVisibleLines == 1)->font();
    978            
    979             // Get ellipsis width, and if the last child is an anchor, it will go after the ellipsis, so add in a space and the anchor width too
    980             int totalWidth;
    981             InlineBox* anchorBox = lastLine->lastChild();
    982             if (anchorBox && anchorBox->renderer()->node() && anchorBox->renderer()->node()->isLink())
    983                 totalWidth = anchorBox->logicalWidth() + font.width(TextRun(ellipsisAndSpace, 2));
    984             else {
    985                 anchorBox = 0;
    986                 totalWidth = font.width(TextRun(&horizontalEllipsis, 1));
    987             }
    988            
    989             // See if this width can be accommodated on the last visible line
    990             RenderBlock* destBlock = toRenderBlock(lastVisibleLine->renderer());
    991             RenderBlock* srcBlock = toRenderBlock(lastLine->renderer());
    992            
    993             // FIXME: Directions of src/destBlock could be different from our direction and from one another.
    994             if (srcBlock->style()->direction() != LTR)
    995                 continue;
    996             if (destBlock->style()->direction() != LTR)
    997                 continue;
    998             int ltr = true;
    999            
    1000             int blockRightEdge = destBlock->logicalRightOffsetForLine(lastVisibleLine->y(), false);
    1001             int blockLeftEdge = destBlock->logicalLeftOffsetForLine(lastVisibleLine->y(), false);
    1002            
    1003             int blockEdge = ltr ? blockRightEdge : blockLeftEdge;
    1004             if (!lastVisibleLine->canAccommodateEllipsis(ltr, blockEdge,
    1005                                                          lastVisibleLine->x() + lastVisibleLine->logicalWidth(),
    1006                                                          totalWidth))
    1007                 continue;
    1008            
    1009             // Let the truncation code kick in.
    1010             lastVisibleLine->placeEllipsis(anchorBox ? ellipsisAndSpaceStr : ellipsisStr, ltr, blockLeftEdge, blockRightEdge, totalWidth, anchorBox);
    1011             destBlock->setHasMarkupTruncation(true);
     939    if (numVisibleLines >= maxLineCount)
     940        return;
     941
     942    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     943        if (child->isPositioned() || !child->style()->height().isAuto() || !child->isBlockFlow())
     944            continue;
     945       
     946        RenderBlock* blockChild = toRenderBlock(child);
     947        int lineCount = blockChild->lineCount();
     948        if (lineCount <= numVisibleLines)
     949            continue;
     950       
     951        int newHeight = blockChild->heightForLineCount(numVisibleLines);
     952        if (newHeight == child->height())
     953            continue;
     954       
     955        child->setChildNeedsLayout(true, false);
     956        child->setOverrideSize(newHeight);
     957        m_flexingChildren = true;
     958        child->layoutIfNeeded();
     959        m_flexingChildren = false;
     960        child->setOverrideSize(-1);
     961
     962        // FIXME: For now don't support RTL.
     963        if (style()->direction() != LTR)
     964            continue;
     965
     966        // Get the last line
     967        RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount-1);
     968        if (!lastLine)
     969            continue;
     970
     971        RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines-1);
     972        if (!lastVisibleLine)
     973            continue;
     974
     975        const UChar ellipsisAndSpace[2] = { horizontalEllipsis, ' ' };
     976        DEFINE_STATIC_LOCAL(AtomicString, ellipsisAndSpaceStr, (ellipsisAndSpace, 2));
     977        DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
     978        const Font& font = style(numVisibleLines == 1)->font();
     979
     980        // Get ellipsis width, and if the last child is an anchor, it will go after the ellipsis, so add in a space and the anchor width too
     981        int totalWidth;
     982        InlineBox* anchorBox = lastLine->lastChild();
     983        if (anchorBox && anchorBox->renderer()->node() && anchorBox->renderer()->node()->isLink())
     984            totalWidth = anchorBox->logicalWidth() + font.width(TextRun(ellipsisAndSpace, 2));
     985        else {
     986            anchorBox = 0;
     987            totalWidth = font.width(TextRun(&horizontalEllipsis, 1));
    1012988        }
     989
     990        // See if this width can be accommodated on the last visible line
     991        RenderBlock* destBlock = toRenderBlock(lastVisibleLine->renderer());
     992        RenderBlock* srcBlock = toRenderBlock(lastLine->renderer());
     993       
     994        // FIXME: Directions of src/destBlock could be different from our direction and from one another.
     995        if (!srcBlock->style()->isLeftToRightDirection())
     996            continue;
     997
     998        bool leftToRight = destBlock->style()->isLeftToRightDirection();
     999        if (!leftToRight)
     1000            continue;
     1001
     1002        int blockRightEdge = destBlock->logicalRightOffsetForLine(lastVisibleLine->y(), false);
     1003        int blockLeftEdge = destBlock->logicalLeftOffsetForLine(lastVisibleLine->y(), false);
     1004
     1005        int blockEdge = leftToRight ? blockRightEdge : blockLeftEdge;
     1006        if (!lastVisibleLine->canAccommodateEllipsis(leftToRight, blockEdge, lastVisibleLine->x() + lastVisibleLine->logicalWidth(), totalWidth))
     1007            continue;
     1008
     1009        // Let the truncation code kick in.
     1010        lastVisibleLine->placeEllipsis(anchorBox ? ellipsisAndSpaceStr : ellipsisStr, leftToRight, blockLeftEdge, blockRightEdge, totalWidth, anchorBox);
     1011        destBlock->setHasMarkupTruncation(true);
    10131012    }
    10141013}
Note: See TracChangeset for help on using the changeset viewer.