Changeset 114784 in webkit


Ignore:
Timestamp:
Apr 20, 2012 2:40:26 PM (12 years ago)
Author:
mitz@apple.com
Message:

Source/WebCore: <rdar://problem/10786000> Selection highlights of lines in adjoining blocks can overlap
https://bugs.webkit.org/show_bug.cgi?id=84489

Reviewed by Anders Carlsson.

Test: fast/block/line-layout/selection-highlight-overlap.html

  • rendering/EllipsisBox.cpp:

(WebCore::EllipsisBox::selectionRect): Changed to use
selection{Top,Height}AdjustedForPrecedingBlock().

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paintSelection): Ditto.

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::inlineSelectionGaps): Ditto.
(WebCore::RenderBlock::blockBeforeWithinSelectionRoot): Added. Returns the block which is
likely to contain the selected line just before the first line in this block, if it is
within the same selection root.

  • rendering/RenderBlock.h:
  • rendering/RootInlineBox.cpp:

(WebCore::RootInlineBox::selectionTopAdjustedForPrecedingBlock): Added. If the selection
starts before our block, finds the last line in the preceding block and adjusts the selection
top to avoid overlap with that line’s selection bottom.

  • rendering/RootInlineBox.h:

(WebCore::RootInlineBox::selectionHeightAdjustedForPrecedingBlock): Added. Like
selectionHeight(), but uses selectionTopAdjustedForPrecedingBlock().

LayoutTests: Selection highlights of lines in adjoining blocks can overlap
https://bugs.webkit.org/show_bug.cgi?id=84489

Reviewed by Anders Carlsson.

  • fast/block/line-layout/selection-highlight-overlap-expected.html: Added.
  • fast/block/line-layout/selection-highlight-overlap.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r114777 r114784  
     12012-04-20  Dan Bernstein  <mitz@apple.com>
     2
     3        Selection highlights of lines in adjoining blocks can overlap
     4        https://bugs.webkit.org/show_bug.cgi?id=84489
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * fast/block/line-layout/selection-highlight-overlap-expected.html: Added.
     9        * fast/block/line-layout/selection-highlight-overlap.html: Added.
     10
    1112012-04-20  Dmitry Titov  <dimich@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r114783 r114784  
     12012-04-20  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/10786000> Selection highlights of lines in adjoining blocks can overlap
     4        https://bugs.webkit.org/show_bug.cgi?id=84489
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Test: fast/block/line-layout/selection-highlight-overlap.html
     9
     10        * rendering/EllipsisBox.cpp:
     11        (WebCore::EllipsisBox::selectionRect): Changed to use
     12        selection{Top,Height}AdjustedForPrecedingBlock().
     13        * rendering/InlineTextBox.cpp:
     14        (WebCore::InlineTextBox::paintSelection): Ditto.
     15        * rendering/RenderBlock.cpp:
     16        (WebCore::RenderBlock::inlineSelectionGaps): Ditto.
     17        (WebCore::RenderBlock::blockBeforeWithinSelectionRoot): Added. Returns the block which is
     18        likely to contain the selected line just before the first line in this block, if it is
     19        within the same selection root.
     20        * rendering/RenderBlock.h:
     21        * rendering/RootInlineBox.cpp:
     22        (WebCore::RootInlineBox::selectionTopAdjustedForPrecedingBlock): Added. If the selection
     23        starts before our block, finds the last line in the preceding block and adjusts the selection
     24        top to avoid overlap with that line’s selection bottom.
     25        * rendering/RootInlineBox.h:
     26        (WebCore::RootInlineBox::selectionHeightAdjustedForPrecedingBlock): Added. Like
     27        selectionHeight(), but uses selectionTopAdjustedForPrecedingBlock().
     28
    1292012-04-20  Xianzhu Wang  <wangxianzhu@chromium.org>
    230
  • trunk/Source/WebCore/rendering/EllipsisBox.cpp

    r112512 r114784  
    7979    const Font& font = style->font();
    8080    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    81     return enclosingIntRect(font.selectionRectForText(RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x(), y() + root()->selectionTop()), root()->selectionHeight()));
     81    return enclosingIntRect(font.selectionRectForText(RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x(), y() + root()->selectionTopAdjustedForPrecedingBlock()), root()->selectionHeightAdjustedForPrecedingBlock()));
    8282}
    8383
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r114220 r114784  
    842842        ePos = textRun.length();
    843843
    844     int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
    845     int selHeight = selectionHeight();
     844    LayoutUnit selectionBottom = root()->selectionBottom();
     845    LayoutUnit selectionTop = root()->selectionTopAdjustedForPrecedingBlock();
     846
     847    int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop;
     848    int selHeight = max<LayoutUnit>(0, selectionBottom - selectionTop);
     849
    846850    FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
    847851
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r114537 r114784  
    32143214    // Now paint the gaps for the lines.
    32153215    for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) {
    3216         LayoutUnit selTop =  curr->selectionTop();
    3217         LayoutUnit selHeight = curr->selectionHeight();
     3216        LayoutUnit selTop =  curr->selectionTopAdjustedForPrecedingBlock();
     3217        LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock();
    32183218
    32193219        if (!containsStart && !lastSelectedLine &&
     
    34053405    }
    34063406    return logicalRight;
     3407}
     3408
     3409RenderBlock* RenderBlock::blockBeforeWithinSelectionRoot(LayoutSize& offset) const
     3410{
     3411    if (isSelectionRoot())
     3412        return 0;
     3413
     3414    const RenderBox* object = this;
     3415    RenderBox* sibling;
     3416    do {
     3417        sibling = object->previousSiblingBox();
     3418        while (sibling && (!sibling->isRenderBlock() || toRenderBlock(sibling)->isSelectionRoot()))
     3419            sibling = sibling->previousSiblingBox();
     3420
     3421        offset -= LayoutSize(object->logicalLeft(), object->logicalTop());
     3422        object = object->parentBox();
     3423    } while (!sibling && object && object->isRenderBlock() && !toRenderBlock(object)->isSelectionRoot());
     3424
     3425    if (!sibling)
     3426        return 0;
     3427
     3428    offset += LayoutSize(sibling->logicalLeft(), sibling->logicalTop());
     3429
     3430    RenderObject* child = sibling->lastChild();
     3431    while (child && child->isRenderBlock()) {
     3432        sibling = toRenderBlock(child);
     3433        offset += LayoutSize(sibling->logicalLeft(), sibling->logicalTop());
     3434        child = sibling->lastChild();
     3435    }
     3436    return toRenderBlock(sibling);
    34073437}
    34083438
  • trunk/Source/WebCore/rendering/RenderBlock.h

    r113885 r114784  
    211211                                        RenderObject* selObj, LayoutUnit logicalRight, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*);
    212212    void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap);
     213    RenderBlock* blockBeforeWithinSelectionRoot(LayoutSize& offset) const;
     214
    213215    LayoutRect logicalRectToPhysicalRect(const LayoutPoint& physicalPosition, const LayoutRect& logicalRect);
    214216       
     
    802804    LayoutUnit logicalLeftSelectionOffset(RenderBlock* rootBlock, LayoutUnit position);
    803805    LayoutUnit logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position);
    804    
     806
    805807    virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
    806808    virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
  • trunk/Source/WebCore/rendering/RootInlineBox.cpp

    r113221 r114784  
    546546}
    547547
     548LayoutUnit RootInlineBox::selectionTopAdjustedForPrecedingBlock() const
     549{
     550    LayoutUnit top = selectionTop();
     551
     552    RenderObject::SelectionState blockSelectionState = root()->block()->selectionState();
     553    if (blockSelectionState != RenderObject::SelectionInside && blockSelectionState != RenderObject::SelectionEnd)
     554        return top;
     555
     556    LayoutSize offsetToBlockBefore;
     557    if (RenderBlock* block = root()->block()->blockBeforeWithinSelectionRoot(offsetToBlockBefore)) {
     558        if (RootInlineBox* lastLine = block->lastRootBox()) {
     559            RenderObject::SelectionState lastLineSelectionState = lastLine->selectionState();
     560            if (lastLineSelectionState != RenderObject::SelectionInside && lastLineSelectionState != RenderObject::SelectionStart)
     561                return top;
     562
     563            LayoutUnit lastLineSelectionBottom = lastLine->selectionBottom() + offsetToBlockBefore.height();
     564            top = max(top, lastLineSelectionBottom);
     565        }
     566    }
     567
     568    return top;
     569}
     570
    548571LayoutUnit RootInlineBox::selectionBottom() const
    549572{
  • trunk/Source/WebCore/rendering/RootInlineBox.h

    r113221 r114784  
    6363    LayoutUnit selectionBottom() const;
    6464    LayoutUnit selectionHeight() const { return max<LayoutUnit>(0, selectionBottom() - selectionTop()); }
     65
     66    LayoutUnit selectionTopAdjustedForPrecedingBlock() const;
     67    LayoutUnit selectionHeightAdjustedForPrecedingBlock() const { return max<LayoutUnit>(0, selectionBottom() - selectionTopAdjustedForPrecedingBlock()); }
    6568
    6669    int blockDirectionPointInLine() const { return max(lineTop(), selectionTop()); }
Note: See TracChangeset for help on using the changeset viewer.