Changeset 155949 in webkit


Ignore:
Timestamp:
Sep 17, 2013, 5:33:29 AM (11 years ago)
Author:
Antti Koivisto
Message:

Move text caret rect computation to root inline box
https://bugs.webkit.org/show_bug.cgi?id=121479

Reviewed by Andreas Kling.

For future code sharing.

  • rendering/RenderText.cpp:

(WebCore::RenderText::localCaretRect):

  • rendering/RootInlineBox.cpp:

(WebCore::RootInlineBox::computeCaretRect):

  • rendering/RootInlineBox.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155948 r155949  
     12013-09-17  Antti Koivisto  <antti@apple.com>
     2
     3        Move text caret rect computation to root inline box
     4        https://bugs.webkit.org/show_bug.cgi?id=121479
     5
     6        Reviewed by Andreas Kling.
     7
     8        For future code sharing.
     9
     10        * rendering/RenderText.cpp:
     11        (WebCore::RenderText::localCaretRect):
     12        * rendering/RootInlineBox.cpp:
     13        (WebCore::RootInlineBox::computeCaretRect):
     14        * rendering/RootInlineBox.h:
     15
    1162013-09-17  Alberto Garcia  <berto@igalia.com>
    217
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r155944 r155949  
    660660        return LayoutRect();
    661661
    662     ASSERT(inlineBox->isInlineTextBox());
    663     if (!inlineBox->isInlineTextBox())
    664         return LayoutRect();
    665 
    666662    InlineTextBox* box = toInlineTextBox(inlineBox);
    667 
    668     const RootInlineBox& rootBox = box->root();
    669     int height = rootBox.selectionHeight();
    670     int top = rootBox.selectionTop();
    671 
    672     // Go ahead and round left to snap it to the nearest pixel.
    673663    float left = box->positionForOffset(caretOffset);
    674 
    675     // Distribute the caret's width to either side of the offset.
    676     int caretWidthLeftOfOffset = caretWidth / 2;
    677     left -= caretWidthLeftOfOffset;
    678     int caretWidthRightOfOffset = caretWidth - caretWidthLeftOfOffset;
    679 
    680     left = roundf(left);
    681 
    682     float rootLeft = rootBox.logicalLeft();
    683     float rootRight = rootBox.logicalRight();
    684 
    685     // FIXME: should we use the width of the root inline box or the
    686     // width of the containing block for this?
    687     if (extraWidthToEndOfLine)
    688         *extraWidthToEndOfLine = (rootBox.logicalWidth() + rootLeft) - (left + 1);
    689 
    690     RenderBlock* cb = containingBlock();
    691     RenderStyle* cbStyle = cb->style();
    692 
    693     float leftEdge;
    694     float rightEdge;
    695     leftEdge = min<float>(0, rootLeft);
    696     rightEdge = max<float>(cb->logicalWidth(), rootRight);
    697 
    698     bool rightAligned = false;
    699     switch (cbStyle->textAlign()) {
    700     case RIGHT:
    701     case WEBKIT_RIGHT:
    702         rightAligned = true;
    703         break;
    704     case LEFT:
    705     case WEBKIT_LEFT:
    706     case CENTER:
    707     case WEBKIT_CENTER:
    708         break;
    709     case JUSTIFY:
    710     case TASTART:
    711         rightAligned = !cbStyle->isLeftToRightDirection();
    712         break;
    713     case TAEND:
    714         rightAligned = cbStyle->isLeftToRightDirection();
    715         break;
    716     }
    717 
    718     if (rightAligned) {
    719         left = max(left, leftEdge);
    720         left = min(left, rootRight - caretWidth);
    721     } else {
    722         left = min(left, rightEdge - caretWidthRightOfOffset);
    723         left = max(left, rootLeft);
    724     }
    725 
    726     return style()->isHorizontalWritingMode() ? IntRect(left, top, caretWidth, height) : IntRect(top, left, height, caretWidth);
     664    return box->root().computeCaretRect(left, caretWidth, extraWidthToEndOfLine);
    727665}
    728666
  • trunk/Source/WebCore/rendering/RootInlineBox.cpp

    r155944 r155949  
    522522}
    523523
     524IntRect RootInlineBox::computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const
     525{
     526    int height = selectionHeight();
     527    int top = selectionTop();
     528
     529    // Distribute the caret's width to either side of the offset.
     530    float left = logicalLeftPosition;
     531    int caretWidthLeftOfOffset = caretWidth / 2;
     532    left -= caretWidthLeftOfOffset;
     533    int caretWidthRightOfOffset = caretWidth - caretWidthLeftOfOffset;
     534    left = roundf(left);
     535
     536    float rootLeft = logicalLeft();
     537    float rootRight = logicalRight();
     538
     539    if (extraWidthToEndOfLine)
     540        *extraWidthToEndOfLine = (logicalWidth() + rootLeft) - (left + caretWidth);
     541
     542    RenderStyle* blockStyle = block().style();
     543
     544    bool rightAligned = false;
     545    switch (blockStyle->textAlign()) {
     546    case RIGHT:
     547    case WEBKIT_RIGHT:
     548        rightAligned = true;
     549        break;
     550    case LEFT:
     551    case WEBKIT_LEFT:
     552    case CENTER:
     553    case WEBKIT_CENTER:
     554        break;
     555    case JUSTIFY:
     556    case TASTART:
     557        rightAligned = !blockStyle->isLeftToRightDirection();
     558        break;
     559    case TAEND:
     560        rightAligned = blockStyle->isLeftToRightDirection();
     561        break;
     562    }
     563
     564    float leftEdge = std::min<float>(0, rootLeft);
     565    float rightEdge = std::max<float>(block().logicalWidth(), rootRight);
     566
     567    if (rightAligned) {
     568        left = std::max(left, leftEdge);
     569        left = std::min(left, rootRight - caretWidth);
     570    } else {
     571        left = std::min(left, rightEdge - caretWidthRightOfOffset);
     572        left = std::max(left, rootLeft);
     573    }
     574    return blockStyle->isHorizontalWritingMode() ? IntRect(left, top, caretWidth, height) : IntRect(top, left, height, caretWidth);
     575}
     576
    524577RenderObject::SelectionState RootInlineBox::selectionState()
    525578{
  • trunk/Source/WebCore/rendering/RootInlineBox.h

    r155944 r155949  
    135135    GapRects lineSelectionGap(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
    136136        LayoutUnit selTop, LayoutUnit selHeight, const LogicalSelectionOffsetCaches&, const PaintInfo*);
     137
     138    IntRect computeCaretRect(float logicalLeftPosition, unsigned caretWidth, LayoutUnit* extraWidthToEndOfLine) const;
    137139
    138140    RenderBlock& block() const;
Note: See TracChangeset for help on using the changeset viewer.