Changeset 159579 in webkit


Ignore:
Timestamp:
Nov 20, 2013, 1:23:19 PM (11 years ago)
Author:
Antti Koivisto
Message:

Simple line layout should support floats
https://bugs.webkit.org/show_bug.cgi?id=124666

Reviewed by Dave Hyatt.

Source/WebCore:

Tests: fast/text/simple-lines-float-compare.html

fast/text/simple-lines-float.html

  • rendering/line/LineWidth.h:

(WebCore::LineWidth::logicalLeftOffset):

Expose the left offset so we don't need to recompute it.

  • rendering/SimpleLineLayout.cpp:

(WebCore::SimpleLineLayout::canUseFor):
(WebCore::SimpleLineLayout::computeLineLeft):

Include the left offset from floats.

(WebCore::SimpleLineLayout::createTextRuns):

Keep the flow height updated during the loop as LineWidth reads the current position from there.

  • rendering/SimpleLineLayoutResolver.h:

(WebCore::SimpleLineLayout::RunResolver::Run::rect):
(WebCore::SimpleLineLayout::RunResolver::Run::baseline):
(WebCore::SimpleLineLayout::RunResolver::RunResolver):
(WebCore::SimpleLineLayout::RunResolver::lineIndexForHeight):

We now bake the border and the padding to the line left offset. No need to add it during resolve.

LayoutTests:

  • fast/text/simple-lines-float-compare-expected.html: Added.
  • fast/text/simple-lines-float-compare.html: Added.
  • fast/text/simple-lines-float-expected.html: Added.
  • fast/text/simple-lines-float.html: Added.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r159575 r159579  
     12013-11-20  Antti Koivisto  <antti@apple.com>
     2
     3        Simple line layout should support floats
     4        https://bugs.webkit.org/show_bug.cgi?id=124666
     5
     6        Reviewed by Dave Hyatt.
     7
     8        * fast/text/simple-lines-float-compare-expected.html: Added.
     9        * fast/text/simple-lines-float-compare.html: Added.
     10        * fast/text/simple-lines-float-expected.html: Added.
     11        * fast/text/simple-lines-float.html: Added.
     12
    1132013-11-20  Robert Hogan  <robert@webkit.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r159578 r159579  
     12013-11-20  Antti Koivisto  <antti@apple.com>
     2
     3        Simple line layout should support floats
     4        https://bugs.webkit.org/show_bug.cgi?id=124666
     5
     6        Reviewed by Dave Hyatt.
     7
     8        Tests: fast/text/simple-lines-float-compare.html
     9               fast/text/simple-lines-float.html
     10
     11        * rendering/line/LineWidth.h:
     12        (WebCore::LineWidth::logicalLeftOffset):
     13       
     14            Expose the left offset so we don't need to recompute it.
     15
     16        * rendering/SimpleLineLayout.cpp:
     17        (WebCore::SimpleLineLayout::canUseFor):
     18        (WebCore::SimpleLineLayout::computeLineLeft):
     19       
     20            Include the left offset from floats.
     21
     22        (WebCore::SimpleLineLayout::createTextRuns):
     23       
     24            Keep the flow height updated during the loop as LineWidth reads the current position from there.
     25
     26        * rendering/SimpleLineLayoutResolver.h:
     27        (WebCore::SimpleLineLayout::RunResolver::Run::rect):
     28        (WebCore::SimpleLineLayout::RunResolver::Run::baseline):
     29        (WebCore::SimpleLineLayout::RunResolver::RunResolver):
     30        (WebCore::SimpleLineLayout::RunResolver::lineIndexForHeight):
     31       
     32            We now bake the border and the padding to the line left offset. No need to add it during resolve.
     33
    1342013-11-20  Alexey Proskuryakov  <ap@apple.com>
    235
  • trunk/Source/WebCore/rendering/SimpleLineLayout.cpp

    r159194 r159579  
    4343#include "RenderView.h"
    4444#include "Settings.h"
    45 #include "SimpleLineLayoutResolver.h"
     45#include "SimpleLineLayoutFunctions.h"
    4646#include "Text.h"
    4747#include "TextPaintStyle.h"
     
    106106    if (!flow.firstChild()->isText())
    107107        return false;
    108     // Supporting floats would be very beneficial.
    109     if (flow.containsFloats())
    110         return false;
    111108    if (!flow.isHorizontalWritingMode())
    112109        return false;
     
    183180        return false;
    184181    const RenderText& textRenderer = toRenderText(*flow.firstChild());
     182    if (flow.containsFloats()) {
     183        // We can't use the code path if any lines would need to be shifted below floats. This is because we don't keep per-line y coordinates.
     184        // It is enough to test the first line width only as currently all floats must be overhanging.
     185        if (textRenderer.minLogicalWidth() > LineWidth(const_cast<RenderBlockFlow&>(flow), false, DoNotIndentText).availableWidth())
     186            return false;
     187    }
    185188    if (textRenderer.isCombineText() || textRenderer.isCounter() || textRenderer.isQuote() || textRenderer.isTextFragment()
    186189#if ENABLE(SVG)
     
    374377}
    375378
    376 static float computeLineLeft(ETextAlign textAlign, float remainingWidth)
    377 {
     379static float computeLineLeft(ETextAlign textAlign, const LineWidth& lineWidth)
     380{
     381    float remainingWidth = lineWidth.availableWidth() - lineWidth.committedWidth();
     382    float left = lineWidth.logicalLeftOffset();
    378383    switch (textAlign) {
    379384    case LEFT:
    380385    case WEBKIT_LEFT:
    381386    case TASTART:
    382         return 0;
     387        return left;
    383388    case RIGHT:
    384389    case WEBKIT_RIGHT:
    385390    case TAEND:
    386         return std::max<float>(remainingWidth, 0);
     391        return left + std::max<float>(remainingWidth, 0);
    387392    case CENTER:
    388393    case WEBKIT_CENTER:
    389         return std::max<float>(remainingWidth / 2, 0);
     394        return left + std::max<float>(remainingWidth / 2, 0);
    390395    case JUSTIFY:
    391396        break;
     
    413418    const unsigned textLength = textRenderer.textLength();
    414419
     420    LayoutUnit borderAndPaddingBefore = flow.borderAndPaddingBefore();
     421    LayoutUnit lineHeight = lineHeightFromFlow(flow);
     422
    415423    LazyLineBreakIterator lineBreakIterator(textRenderer.text(), flow.style().locale());
    416424
     
    422430        unsigned lineStart = lineEnd;
    423431
     432        // LineWidth reads the current y position from the flow so keep it updated.
     433        flow.setLogicalHeight(lineHeight * lineCount + borderAndPaddingBefore);
    424434        LineWidth lineWidth(flow, false, DoNotIndentText);
     435
    425436        auto lineRuns = createLineRuns(lineStart, lineWidth, lineBreakIterator, style, text, textLength, textRenderer);
    426437
     
    431442        lineRuns.last().isEndOfLine = true;
    432443
    433         float lineLeft = computeLineLeft(style.textAlign, lineWidth.availableWidth() - lineWidth.committedWidth());
     444        float lineLeft = computeLineLeft(style.textAlign, lineWidth);
    434445        adjustRunOffsets(lineRuns, lineLeft);
    435446
  • trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h

    r159560 r159579  
    109109    const LayoutUnit m_lineHeight;
    110110    const LayoutUnit m_baseline;
     111    const LayoutUnit m_borderAndPaddingBefore;
    111112    const float m_ascent;
    112113    const float m_descent;
    113     const LayoutPoint m_contentOffset;
    114114};
    115115
     
    167167    auto& run = m_iterator.simpleRun();
    168168
    169     LayoutPoint linePosition(floor(run.left), resolver.m_lineHeight * m_iterator.lineIndex() + resolver.m_baseline - resolver.m_ascent);
     169    float baselinePosition = resolver.m_lineHeight * m_iterator.lineIndex() + resolver.m_baseline;
     170    LayoutPoint linePosition(floor(run.left), baselinePosition - resolver.m_ascent + resolver.m_borderAndPaddingBefore);
    170171    LayoutSize lineSize(ceil(run.right) - floor(run.left), resolver.m_ascent + resolver.m_descent);
    171     return LayoutRect(linePosition + resolver.m_contentOffset, lineSize);
     172    return LayoutRect(linePosition, lineSize);
    172173}
    173174
     
    177178    auto& run = m_iterator.simpleRun();
    178179
    179     float baselineY = resolver.m_lineHeight * m_iterator.lineIndex() + resolver.m_baseline;
    180     return FloatPoint(run.left, baselineY) + resolver.m_contentOffset;
     180    float baselinePosition = resolver.m_lineHeight * m_iterator.lineIndex() + resolver.m_baseline;
     181    return FloatPoint(run.left, baselinePosition + resolver.m_borderAndPaddingBefore);
    181182}
    182183
     
    254255    , m_lineHeight(lineHeightFromFlow(flow))
    255256    , m_baseline(baselineFromFlow(flow))
     257    , m_borderAndPaddingBefore(flow.borderAndPaddingBefore())
    256258    , m_ascent(flow.style().font().fontMetrics().ascent())
    257259    , m_descent(flow.style().font().fontMetrics().descent())
    258     , m_contentOffset(flow.borderLeft() + flow.paddingLeft(), flow.borderTop() + flow.paddingTop())
    259260{
    260261}
     
    273274{
    274275    ASSERT(m_lineHeight);
    275     float y = std::max<float>(height - m_contentOffset.y() - m_baseline + m_ascent, 0);
     276    float y = std::max<float>(height - m_borderAndPaddingBefore - m_baseline + m_ascent, 0);
    276277    return std::min<unsigned>(y / m_lineHeight, m_layout.lineCount() - 1);
    277278}
  • trunk/Source/WebCore/rendering/line/LineWidth.h

    r159569 r159579  
    5757    float committedWidth() const { return m_committedWidth; }
    5858    float availableWidth() const { return m_availableWidth; }
     59    float logicalLeftOffset() const { return m_left; }
    5960
    6061    void updateAvailableWidth(LayoutUnit minimumHeight = 0);
Note: See TracChangeset for help on using the changeset viewer.