Changeset 87964 in webkit


Ignore:
Timestamp:
Jun 2, 2011 4:49:08 PM (13 years ago)
Author:
leviw@chromium.org
Message:

2011-06-02 Levi Weintraub <leviw@chromium.org>

Reviewed by Eric Seidel.

Teach InlineBox about FloatPoint
https://bugs.webkit.org/show_bug.cgi?id=44412

Original patch by Eric Seidel. Updated by me.

This is another step towards more point/size
usage throughout the rendering tree.

Added left(), right(), top(), and bottom() methods
to InlineBox. Removed m_x, and m_y and replaced them
with a single m_topLeft member.

No new tests since this is just a refactoring.

  • rendering/EllipsisBox.cpp: (WebCore::EllipsisBox::paint): (WebCore::EllipsisBox::selectionRect): (WebCore::EllipsisBox::paintSelection): (WebCore::EllipsisBox::nodeAtPoint):
  • rendering/EllipsisBox.h: (WebCore::EllipsisBox::EllipsisBox):
  • rendering/InlineBox.cpp: (WebCore::InlineBox::adjustPosition): (WebCore::InlineBox::canAccommodateEllipsis):
  • rendering/InlineBox.h: (WebCore::InlineBox::InlineBox): (WebCore::InlineBox::setX): (WebCore::InlineBox::x): (WebCore::InlineBox::left): (WebCore::InlineBox::setY): (WebCore::InlineBox::y): (WebCore::InlineBox::top): (WebCore::InlineBox::topLeft): (WebCore::InlineBox::right): (WebCore::InlineBox::bottom): (WebCore::InlineBox::logicalLeft): (WebCore::InlineBox::setLogicalLeft): (WebCore::InlineBox::logicalTop): (WebCore::InlineBox::setLogicalTop): (WebCore::InlineBox::logicalFrameRect):
  • rendering/InlineFlowBox.h: (WebCore::InlineFlowBox::frameRectIncludingLineHeight):
  • rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::placeEllipsisBox): (WebCore::InlineTextBox::paintTextMatchMarker): (WebCore::InlineTextBox::computeRectForReplacementMarker):
  • rendering/RenderText.cpp: (WebCore::RenderText::firstRunX): (WebCore::RenderText::firstRunY):
  • rendering/RenderTreeAsText.cpp: (WebCore::writeTextRun):
  • rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::placeEllipsis):
  • rendering/svg/RenderSVGText.cpp: (WebCore::RenderSVGText::positionForPoint):
  • rendering/svg/SVGInlineTextBox.h: (WebCore::SVGInlineTextBox::selectionTop):
  • rendering/svg/SVGRootInlineBox.cpp: (WebCore::SVGRootInlineBox::closestLeafChildForPosition):
Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87961 r87964  
     12011-06-02  Levi Weintraub  <leviw@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Teach InlineBox about FloatPoint
     6        https://bugs.webkit.org/show_bug.cgi?id=44412
     7
     8        Original patch by Eric Seidel. Updated by me.
     9
     10        This is another step towards more point/size
     11        usage throughout the rendering tree.
     12
     13        Added left(), right(), top(), and bottom() methods
     14        to InlineBox. Removed m_x, and m_y and replaced them
     15        with a single m_topLeft member.
     16
     17        No new tests since this is just a refactoring.
     18
     19        * rendering/EllipsisBox.cpp:
     20        (WebCore::EllipsisBox::paint):
     21        (WebCore::EllipsisBox::selectionRect):
     22        (WebCore::EllipsisBox::paintSelection):
     23        (WebCore::EllipsisBox::nodeAtPoint):
     24        * rendering/EllipsisBox.h:
     25        (WebCore::EllipsisBox::EllipsisBox):
     26        * rendering/InlineBox.cpp:
     27        (WebCore::InlineBox::adjustPosition):
     28        (WebCore::InlineBox::canAccommodateEllipsis):
     29        * rendering/InlineBox.h:
     30        (WebCore::InlineBox::InlineBox):
     31        (WebCore::InlineBox::setX):
     32        (WebCore::InlineBox::x):
     33        (WebCore::InlineBox::left):
     34        (WebCore::InlineBox::setY):
     35        (WebCore::InlineBox::y):
     36        (WebCore::InlineBox::top):
     37        (WebCore::InlineBox::topLeft):
     38        (WebCore::InlineBox::right):
     39        (WebCore::InlineBox::bottom):
     40        (WebCore::InlineBox::logicalLeft):
     41        (WebCore::InlineBox::setLogicalLeft):
     42        (WebCore::InlineBox::logicalTop):
     43        (WebCore::InlineBox::setLogicalTop):
     44        (WebCore::InlineBox::logicalFrameRect):
     45        * rendering/InlineFlowBox.h:
     46        (WebCore::InlineFlowBox::frameRectIncludingLineHeight):
     47        * rendering/InlineTextBox.cpp:
     48        (WebCore::InlineTextBox::placeEllipsisBox):
     49        (WebCore::InlineTextBox::paintTextMatchMarker):
     50        (WebCore::InlineTextBox::computeRectForReplacementMarker):
     51        * rendering/RenderText.cpp:
     52        (WebCore::RenderText::firstRunX):
     53        (WebCore::RenderText::firstRunY):
     54        * rendering/RenderTreeAsText.cpp:
     55        (WebCore::writeTextRun):
     56        * rendering/RootInlineBox.cpp:
     57        (WebCore::RootInlineBox::placeEllipsis):
     58        * rendering/svg/RenderSVGText.cpp:
     59        (WebCore::RenderSVGText::positionForPoint):
     60        * rendering/svg/SVGInlineTextBox.h:
     61        (WebCore::SVGInlineTextBox::selectionTop):
     62        * rendering/svg/SVGRootInlineBox.cpp:
     63        (WebCore::SVGRootInlineBox::closestLeafChildForPosition):
     64
    1652011-06-02  Jian Li  <jianli@chromium.org>
    266
  • trunk/Source/WebCore/rendering/EllipsisBox.cpp

    r87753 r87964  
    5656
    5757    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    58     context->drawText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(m_x + paintOffset.x(), m_y + paintOffset.y() + style->fontMetrics().ascent()));
     58    context->drawText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x() + paintOffset.x(), y() + paintOffset.y() + style->fontMetrics().ascent()));
    5959
    6060    // Restore the regular fill color.
     
    6868        // Paint the markup box
    6969        IntPoint adjustedPaintOffset = paintOffset;
    70         adjustedPaintOffset.move(m_x + m_logicalWidth - m_markupBox->x(),
    71             m_y + style->fontMetrics().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(m_firstLine)->fontMetrics().ascent()));
     70        adjustedPaintOffset.move(x() + m_logicalWidth - m_markupBox->x(),
     71            y() + style->fontMetrics().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(m_firstLine)->fontMetrics().ascent()));
    7272        m_markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom);
    7373    }
     
    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(m_x + tx, m_y + ty + root()->selectionTop()), root()->selectionHeight()));
     81    return enclosingIntRect(font.selectionRectForText(RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x() + tx, y() + ty + root()->selectionTop()), root()->selectionHeight()));
    8282}
    8383
     
    9595
    9696    GraphicsContextStateSaver stateSaver(*context);
    97     int y = root()->selectionTop();
     97    int top = root()->selectionTop();
    9898    int h = root()->selectionHeight();
    99     context->clip(IntRect(m_x + tx, y + ty, m_logicalWidth, h));
     99    context->clip(IntRect(x() + tx, top + ty, m_logicalWidth, h));
    100100    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    101     context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(m_x + tx, m_y + ty + y), h, c, style->colorSpace());
     101    context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x() + tx, y() + ty + top), h, c, style->colorSpace());
    102102}
    103103
    104104bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const IntPoint& pointInContainer, int tx, int ty, int lineTop, int lineBottom)
    105105{
    106     tx += m_x;
    107     ty += m_y;
     106    tx += x();
     107    ty += y();
    108108
    109109    // Hit test the markup box.
  • trunk/Source/WebCore/rendering/EllipsisBox.h

    r87753 r87964  
    3232    EllipsisBox(RenderObject* obj, const AtomicString& ellipsisStr, InlineFlowBox* parent,
    3333                int width, int height, int y, bool firstLine, bool isVertical, InlineBox* markupBox)
    34         : InlineBox(obj, 0, y, width, firstLine, true, false, false, isVertical, 0, 0, parent)
     34        : InlineBox(obj, FloatPoint(0, y), width, firstLine, true, false, false, isVertical, 0, 0, parent)
    3535        , m_height(height)
    3636        , m_str(ellipsisStr)
  • trunk/Source/WebCore/rendering/InlineBox.cpp

    r87753 r87964  
    187187void InlineBox::adjustPosition(float dx, float dy)
    188188{
    189     m_x += dx;
    190     m_y += dy;
     189    m_topLeft.move(dx, dy);
    191190
    192191    if (m_renderer->isReplaced())
     
    307306        return true;
    308307   
    309     IntRect boxRect(m_x, 0, m_logicalWidth, 10);
     308    IntRect boxRect(left(), 0, m_logicalWidth, 10);
    310309    IntRect ellipsisRect(ltr ? blockEdge - ellipsisWidth : blockEdge, 0, ellipsisWidth, 10);
    311310    return !(boxRect.intersects(ellipsisRect));
  • trunk/Source/WebCore/rendering/InlineBox.h

    r87771 r87964  
    4040        , m_parent(0)
    4141        , m_renderer(obj)
    42         , m_x(0)
    43         , m_y(0)
    4442        , m_logicalWidth(0)
    4543        , m_firstLine(false)
     
    6967    }
    7068
    71     InlineBox(RenderObject* obj, float x, float y, float logicalWidth, bool firstLine, bool constructed,
     69    InlineBox(RenderObject* obj, FloatPoint topLeft, float logicalWidth, bool firstLine, bool constructed,
    7270              bool dirty, bool extracted, bool isHorizontal, InlineBox* next, InlineBox* prev, InlineFlowBox* parent)
    7371        : m_next(next)
     
    7573        , m_parent(parent)
    7674        , m_renderer(obj)
    77         , m_x(x)
    78         , m_y(y)
     75        , m_topLeft(topLeft)
    7976        , m_logicalWidth(logicalWidth)
    8077        , m_firstLine(firstLine)
     
    227224
    228225    // x() is the left side of the box in the containing block's coordinate system.
    229     void setX(float x) { m_x = x; }
    230     float x() const { return m_x; }
     226    void setX(float x) { m_topLeft.setX(x); }
     227    float x() const { return m_topLeft.x(); }
     228    float left() const { return m_topLeft.x(); }
    231229
    232230    // y() is the top side of the box in the containing block's coordinate system.
    233     void setY(float y) { m_y = y; }
    234     float y() const { return m_y; }
     231    void setY(float y) { m_topLeft.setY(y); }
     232    float y() const { return m_topLeft.y(); }
     233    float top() const { return m_topLeft.y(); }
     234
     235    const FloatPoint& topLeft() const { return m_topLeft; }
    235236
    236237    float width() const { return isHorizontal() ? logicalWidth() : logicalHeight(); }
    237238    float height() const { return isHorizontal() ? logicalHeight() : logicalWidth(); }
     239    float right() const { return left() + width(); }
     240    float bottom() const { return top() + height(); }
    238241
    239242    // The logicalLeft position is the left edge of the line box in a horizontal line and the top edge in a vertical line.
    240     float logicalLeft() const { return isHorizontal() ? m_x : m_y; }
     243    float logicalLeft() const { return isHorizontal() ? m_topLeft.x() : m_topLeft.y(); }
    241244    float logicalRight() const { return logicalLeft() + logicalWidth(); }
    242245    void setLogicalLeft(float left)
    243246    {
    244247        if (isHorizontal())
    245             m_x = left;
     248            setX(left);
    246249        else
    247             m_y = left;
     250            setY(left);
    248251    }
    249252    int pixelSnappedLogicalLeft() const { return logicalLeft(); }
     
    251254
    252255    // The logicalTop[ position is the top edge of the line box in a horizontal line and the left edge in a vertical line.
    253     int logicalTop() const { return isHorizontal() ? m_y : m_x; }
     256    int logicalTop() const { return isHorizontal() ? m_topLeft.y() : m_topLeft.x(); }
    254257    int logicalBottom() const { return logicalTop() + logicalHeight(); }
    255258    void setLogicalTop(int top)
    256259    {
    257260        if (isHorizontal())
    258             m_y = top;
     261            setY(top);
    259262        else
    260             m_x = top;
     263            setX(top);
    261264    }
    262265
     
    268271    int logicalHeight() const;
    269272
    270     FloatRect logicalFrameRect() const { return isHorizontal() ? IntRect(m_x, m_y, m_logicalWidth, logicalHeight()) : IntRect(m_y, m_x, m_logicalWidth, logicalHeight()); }
     273    FloatRect logicalFrameRect() const { return isHorizontal() ? IntRect(m_topLeft.x(), m_topLeft.y(), m_logicalWidth, logicalHeight()) : IntRect(m_topLeft.y(), m_topLeft.x(), m_logicalWidth, logicalHeight()); }
    271274
    272275    virtual int baselinePosition(FontBaseline baselineType) const { return boxModelObject()->baselinePosition(baselineType, m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine); }
     
    331334    RenderObject* m_renderer;
    332335
    333     float m_x;
    334     float m_y;
     336    FloatPoint m_topLeft;
    335337    float m_logicalWidth;
    336338   
  • trunk/Source/WebCore/rendering/InlineFlowBox.h

    r87753 r87964  
    256256    {
    257257        if (isHorizontal())
    258             return FloatRect(m_x, lineTop, width(), lineBottom - lineTop);
    259         return FloatRect(lineTop, m_y, lineBottom - lineTop, height());
     258            return FloatRect(m_topLeft.x(), lineTop, width(), lineBottom - lineTop);
     259        return FloatRect(lineTop, m_topLeft.y(), lineBottom - lineTop, height());
    260260    }
    261261   
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r87866 r87964  
    243243    // LTR: the left edge of the ellipsis is to the left of our text run.
    244244    // RTL: the right edge of the ellipsis is to the right of our text run.
    245     bool ltrFullTruncation = flowIsLTR && ellipsisX <= m_x;
    246     bool rtlFullTruncation = !flowIsLTR && ellipsisX >= (m_x + m_logicalWidth);
     245    bool ltrFullTruncation = flowIsLTR && ellipsisX <= left();
     246    bool rtlFullTruncation = !flowIsLTR && ellipsisX >= left() + logicalWidth();
    247247    if (ltrFullTruncation || rtlFullTruncation) {
    248248        // Too far.  Just set full truncation, but return -1 and let the ellipsis just be placed at the edge of the box.
     
    252252    }
    253253
    254     bool ltrEllipsisWithinBox = flowIsLTR && (ellipsisX < m_x + m_logicalWidth);
    255     bool rtlEllipsisWithinBox = !flowIsLTR && (ellipsisX > m_x);
     254    bool ltrEllipsisWithinBox = flowIsLTR && (ellipsisX < right());
     255    bool rtlEllipsisWithinBox = !flowIsLTR && (ellipsisX > left());
    256256    if (ltrEllipsisWithinBox || rtlEllipsisWithinBox) {
    257257        foundBox = true;
     
    264264          // Width in pixels of the visible portion of the box, excluding the ellipsis.
    265265          int visibleBoxWidth = visibleRightEdge - visibleLeftEdge  - ellipsisWidth;
    266           ellipsisX = ltr ? m_x + visibleBoxWidth : m_x + m_logicalWidth - visibleBoxWidth;
     266          ellipsisX = ltr ? left() + visibleBoxWidth : right() - visibleBoxWidth;
    267267        }
    268268
     
    272272            // and the ellipsis edge.
    273273            m_truncation = cFullTruncation;
    274             return min(ellipsisX, m_x);
     274            return min(ellipsisX, x());
    275275        }
    276276
     
    288288        // have a situation such as |Hello| -> |...He|
    289289        if (flowIsLTR)
    290             return m_x + widthOfVisibleText;
     290            return left() + widthOfVisibleText;
    291291        else
    292             return (m_x + m_logicalWidth) - widthOfVisibleText - ellipsisWidth;
     292            return right() - widthOfVisibleText - ellipsisWidth;
    293293    }
    294294    return -1;
     
    10521052
    10531053    // Always compute and store the rect associated with this marker. The computed rect is in absolute coordinates.
    1054     IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(m_x, selectionTop()), selHeight, sPos, ePos));
     1054    IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(x(), selectionTop()), selHeight, sPos, ePos));
    10551055    markerRect = renderer()->localToAbsoluteQuad(FloatRect(markerRect)).enclosingBoundingBox();
    10561056    toRenderedDocumentMarker(marker)->setRenderedRect(markerRect);
     
    10711071{
    10721072    // Replacement markers are not actually drawn, but their rects need to be computed for hit testing.
    1073     int y = selectionTop();
     1073    int top = selectionTop();
    10741074    int h = selectionHeight();
    10751075   
     
    10771077    int ePos = min(marker->endOffset() - m_start, (unsigned)m_len);
    10781078    TextRun run = constructTextRun(style, font);
    1079     IntPoint startPoint = IntPoint(m_x, y);
     1079    IntPoint startPoint = IntPoint(x(), top);
    10801080   
    10811081    // Compute and store the rect associated with this marker.
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r87936 r87964  
    981981float RenderText::firstRunX() const
    982982{
    983     return m_firstTextBox ? m_firstTextBox->m_x : 0;
     983    return m_firstTextBox ? m_firstTextBox->x() : 0;
    984984}
    985985
    986986float RenderText::firstRunY() const
    987987{
    988     return m_firstTextBox ? m_firstTextBox->m_y : 0;
     988    return m_firstTextBox ? m_firstTextBox->y() : 0;
    989989}
    990990   
  • trunk/Source/WebCore/rendering/RenderTreeAsText.cpp

    r87467 r87964  
    495495    // FIXME: For now use an "enclosingIntRect" model for x, y and logicalWidth, although this makes it harder
    496496    // to detect any changes caused by the conversion to floating point. :(
    497     int x = run.m_x;
    498     int y = run.m_y;
    499     int logicalWidth = ceilf(run.m_x + run.m_logicalWidth) - x;
     497    int x = run.x();
     498    int y = run.y();
     499    int logicalWidth = ceilf(run.left() + run.logicalWidth()) - x;
    500500
    501501    // FIXME: Table cell adjustment is temporary until results can be updated.
  • trunk/Source/WebCore/rendering/RootInlineBox.cpp

    r87866 r87964  
    115115    // FIXME: Do we need an RTL version of this?
    116116    if (ltr && (x() + logicalWidth() + ellipsisWidth) <= blockRightEdge) {
    117         ellipsisBox->m_x = x() + logicalWidth();
     117        ellipsisBox->setX(x() + logicalWidth());
    118118        return;
    119119    }
     
    123123    // truncated).
    124124    bool foundBox = false;
    125     ellipsisBox->m_x = placeEllipsisBox(ltr, blockLeftEdge, blockRightEdge, ellipsisWidth, foundBox);
     125    ellipsisBox->setX(placeEllipsisBox(ltr, blockLeftEdge, blockRightEdge, ellipsisWidth, foundBox));
    126126}
    127127
  • trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp

    r86705 r87964  
    222222        return createVisiblePosition(0, DOWNSTREAM);
    223223
    224     return closestBox->renderer()->positionForPoint(IntPoint(pointInContents.x(), closestBox->m_y));
     224    return closestBox->renderer()->positionForPoint(IntPoint(pointInContents.x(), closestBox->y()));
    225225}
    226226
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.h

    r87753 r87964  
    4141    void setLogicalHeight(int height) { m_logicalHeight = height; }
    4242
    43     virtual int selectionTop() { return m_y; }
     43    virtual int selectionTop() { return top(); }
    4444    virtual int selectionHeight() { return m_logicalHeight; }
    4545    virtual int offsetForPosition(float x, bool includePartialGlyphs = true) const;
  • trunk/Source/WebCore/rendering/svg/SVGRootInlineBox.cpp

    r87753 r87964  
    210210        if (!leaf->isSVGInlineTextBox())
    211211            continue;
    212         if (point.y() < leaf->m_y)
    213             continue;
    214         if (point.y() > leaf->m_y + leaf->virtualLogicalHeight())
     212        if (point.y() < leaf->y())
     213            continue;
     214        if (point.y() > leaf->y() + leaf->virtualLogicalHeight())
    215215            continue;
    216216
    217217        closestLeaf = leaf;
    218         if (point.x() < leaf->m_x + leaf->m_logicalWidth)
     218        if (point.x() < leaf->left() + leaf->logicalWidth())
    219219            return leaf;
    220220    }
Note: See TracChangeset for help on using the changeset viewer.