Changeset 212693 in webkit


Ignore:
Timestamp:
Feb 20, 2017 6:12:04 PM (7 years ago)
Author:
Alan Bujtas
Message:

Simple line layout: Implement absoluteQuadsForRange.
https://bugs.webkit.org/show_bug.cgi?id=168613
<rdar://problem/30614618>

Reviewed by Simon Fraser.

Source/WebCore:

This patch ensures that the commonly used Range::getClientRects calls do not
throw us off of the simple line layout path.

Test: fast/dom/Range/simple-line-layout-getclientrects.html

  • rendering/RenderText.cpp:

(WebCore::RenderText::absoluteQuadsForRange):

  • rendering/SimpleLineLayoutFunctions.cpp:

(WebCore::SimpleLineLayout::collectAbsoluteQuadsForRange): Special case empty ranges with multiple empty runs.

  • rendering/SimpleLineLayoutFunctions.h:
  • rendering/SimpleLineLayoutResolver.cpp:

(WebCore::SimpleLineLayout::RunResolver::rangeForRendererWithOffsets):

  • rendering/SimpleLineLayoutResolver.h:

LayoutTests:

  • fast/dom/Range/simple-line-layout-getclientrects-expected.html: Added.
  • fast/dom/Range/simple-line-layout-getclientrects.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r212691 r212693  
     12017-02-20  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Implement absoluteQuadsForRange.
     4        https://bugs.webkit.org/show_bug.cgi?id=168613
     5        <rdar://problem/30614618>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * fast/dom/Range/simple-line-layout-getclientrects-expected.html: Added.
     10        * fast/dom/Range/simple-line-layout-getclientrects.html: Added.
     11
    1122017-02-20  Ryan Haddad  <ryanhaddad@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r212691 r212693  
     12017-02-20  Zalan Bujtas  <zalan@apple.com>
     2
     3        Simple line layout: Implement absoluteQuadsForRange.
     4        https://bugs.webkit.org/show_bug.cgi?id=168613
     5        <rdar://problem/30614618>
     6
     7        Reviewed by Simon Fraser.
     8
     9        This patch ensures that the commonly used Range::getClientRects calls do not
     10        throw us off of the simple line layout path.
     11
     12        Test: fast/dom/Range/simple-line-layout-getclientrects.html
     13
     14        * rendering/RenderText.cpp:
     15        (WebCore::RenderText::absoluteQuadsForRange):
     16        * rendering/SimpleLineLayoutFunctions.cpp:
     17        (WebCore::SimpleLineLayout::collectAbsoluteQuadsForRange): Special case empty ranges with multiple empty runs.
     18        * rendering/SimpleLineLayoutFunctions.h:
     19        * rendering/SimpleLineLayoutResolver.cpp:
     20        (WebCore::SimpleLineLayout::RunResolver::rangeForRendererWithOffsets):
     21        * rendering/SimpleLineLayoutResolver.h:
     22
    1232017-02-20  Ryan Haddad  <ryanhaddad@apple.com>
    224
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r212615 r212693  
    423423Vector<FloatQuad> RenderText::absoluteQuadsForRange(unsigned start, unsigned end, bool useSelectionHeight, bool* wasFixed) const
    424424{
    425     const_cast<RenderText&>(*this).ensureLineBoxes();
    426 
    427425    // Work around signed/unsigned issues. This function takes unsigneds, and is often passed UINT_MAX
    428     // to mean "all the way to the end". InlineTextBox coordinates are unsigneds, so changing this 
    429     // function to take ints causes various internal mismatches. But selectionRect takes ints, and 
    430     // passing UINT_MAX to it causes trouble. Ideally we'd change selectionRect to take unsigneds, but 
     426    // to mean "all the way to the end". InlineTextBox coordinates are unsigneds, so changing this
     427    // function to take ints causes various internal mismatches. But selectionRect takes ints, and
     428    // passing UINT_MAX to it causes trouble. Ideally we'd change selectionRect to take unsigneds, but
    431429    // that would cause many ripple effects, so for now we'll just clamp our unsigned parameters to INT_MAX.
    432430    ASSERT(end == UINT_MAX || end <= INT_MAX);
     
    434432    start = std::min(start, static_cast<unsigned>(INT_MAX));
    435433    end = std::min(end, static_cast<unsigned>(INT_MAX));
    436    
     434    if (simpleLineLayout() && !useSelectionHeight)
     435        return collectAbsoluteQuadsForRange(*this, start, end, *simpleLineLayout(), wasFixed);
     436    const_cast<RenderText&>(*this).ensureLineBoxes();
    437437    return m_lineBoxes.absoluteQuadsForRange(*this, start, end, useSelectionHeight, wasFixed);
    438438}
  • trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp

    r212615 r212693  
    233233}
    234234
     235Vector<FloatQuad> collectAbsoluteQuadsForRange(const RenderObject& renderer, unsigned start, unsigned end, const Layout& layout, bool* wasFixed)
     236{
     237    auto& style = downcast<RenderBlockFlow>(*renderer.parent()).style();
     238    Vector<FloatQuad> quads;
     239    auto resolver = runResolver(downcast<RenderBlockFlow>(*renderer.parent()), layout);
     240    for (auto run : resolver.rangeForRendererWithOffsets(renderer, start, end)) {
     241        // This run is fully contained.
     242        if (start <= run.start() && end >= run.end()) {
     243            quads.append(renderer.localToAbsoluteQuad(FloatQuad(run.rect()), UseTransforms, wasFixed));
     244            continue;
     245        }
     246        // Partially contained run.
     247        TextRun textRun(run.text(), run.logicalLeft(), run.expansion(), run.expansionBehavior());
     248        textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
     249        LayoutRect runRect(run.rect());
     250        // Special case empty ranges.
     251        if (start == end) {
     252            runRect.setWidth(0);
     253            quads.append(renderer.localToAbsoluteQuad(FloatQuad(runRect), UseTransforms, wasFixed));
     254            continue;
     255        }
     256        ASSERT(start < run.end());
     257        ASSERT(end > run.start());
     258        auto localStart = std::max(run.start(), start) - run.start();
     259        auto localEnd = std::min(run.end(), end) - run.start();
     260        style.fontCascade().adjustSelectionRectForText(textRun, runRect, localStart, localEnd);
     261        quads.append(renderer.localToAbsoluteQuad(FloatQuad(runRect), UseTransforms, wasFixed));
     262    }
     263    return quads;
     264}
     265
    235266#if ENABLE(TREE_DEBUGGING)
    236267static void printPrefix(int& printedCharacters, int depth)
  • trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.h

    r212615 r212693  
    5959Vector<FloatQuad> collectAbsoluteQuads(const RenderObject&, const Layout&, bool* wasFixed);
    6060unsigned textOffsetForPoint(const LayoutPoint&, const RenderText&, const Layout&);
     61Vector<FloatQuad> collectAbsoluteQuadsForRange(const RenderObject&, unsigned start, unsigned end, const Layout&, bool* wasFixed);
    6162
    6263LayoutUnit lineHeightFromFlow(const RenderBlockFlow&);
  • trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp

    r212615 r212693  
    220220}
    221221
     222Range<RunResolver::Iterator> RunResolver::rangeForRendererWithOffsets(const RenderObject& renderer, unsigned startOffset, unsigned endOffset) const
     223{
     224    ASSERT(startOffset <= endOffset);
     225    auto range = rangeForRenderer(renderer);
     226    auto it = range.begin();
     227    // Advance to the firt run with the start offset inside.
     228    while (it != range.end() && (*it).end() <= startOffset)
     229        ++it;
     230    if (it == range.end())
     231        return { end(), end() };
     232    auto rangeBegin = it;
     233    // Special case empty ranges that start at the edge of the run. Apparently normal line layout include those.
     234    if (endOffset == startOffset && (*it).start() == endOffset)
     235        return { rangeBegin, ++it };
     236    // Advance beyond the last run with the end offset.
     237    while (it != range.end() && (*it).start() < endOffset)
     238        ++it;
     239    return { rangeBegin, it };
     240}
     241
    222242LineResolver::Iterator::Iterator(RunResolver::Iterator runIterator)
    223243    : m_runIterator(runIterator)
  • trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h

    r212615 r212693  
    117117    Range<Iterator> rangeForRenderer(const RenderObject&) const;
    118118    Iterator runForPoint(const LayoutPoint&) const;
     119    Range<Iterator> rangeForRendererWithOffsets(const RenderObject&, unsigned start, unsigned end) const;
    119120
    120121private:
Note: See TracChangeset for help on using the changeset viewer.