Changeset 234085 in webkit


Ignore:
Timestamp:
Jul 21, 2018 11:49:23 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Add verification for inline text runs.
https://bugs.webkit.org/show_bug.cgi?id=187879

Reviewed by Antti Koivisto.

  • layout/Verification.cpp:

(WebCore::Layout::outputMismatchingSimpleLineInformationIfNeeded):
(WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded):
(WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):
(WebCore::Layout::verifyAndOutputSubtree):
(WebCore::Layout::outputMismatchingBoxInformationIfNeeded): Deleted.

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::layout const):

  • layout/inlineformatting/InlineFormattingState.h:

(WebCore::Layout::InlineFormattingState::addLayoutRuns):
(WebCore::Layout::InlineFormattingState::layoutRuns const):

  • layout/layouttree/LayoutTreeBuilder.cpp:

(WebCore::Layout::outputLayoutBox):
(WebCore::Layout::outputLayoutTree):
(WebCore::Layout::TreeBuilder::showLayoutTree):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r234084 r234085  
     12018-07-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add verification for inline text runs.
     4        https://bugs.webkit.org/show_bug.cgi?id=187879
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * layout/Verification.cpp:
     9        (WebCore::Layout::outputMismatchingSimpleLineInformationIfNeeded):
     10        (WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded):
     11        (WebCore::Layout::outputMismatchingBlockBoxInformationIfNeeded):
     12        (WebCore::Layout::verifyAndOutputSubtree):
     13        (WebCore::Layout::outputMismatchingBoxInformationIfNeeded): Deleted.
     14        * layout/inlineformatting/InlineFormattingContext.cpp:
     15        (WebCore::Layout::InlineFormattingContext::layout const):
     16        * layout/inlineformatting/InlineFormattingState.h:
     17        (WebCore::Layout::InlineFormattingState::addLayoutRuns):
     18        (WebCore::Layout::InlineFormattingState::layoutRuns const):
     19        * layout/layouttree/LayoutTreeBuilder.cpp:
     20        (WebCore::Layout::outputLayoutBox):
     21        (WebCore::Layout::outputLayoutTree):
     22        (WebCore::Layout::TreeBuilder::showLayoutTree):
     23
    1242018-07-21  Zalan Bujtas  <zalan@apple.com>
    225
  • trunk/Source/WebCore/layout/Verification.cpp

    r233469 r234085  
    3030
    3131#include "DisplayBox.h"
     32#include "InlineTextBox.h"
    3233#include "LayoutBox.h"
    3334#include "LayoutContainer.h"
     
    4041namespace Layout {
    4142
    42 static bool outputMismatchingBoxInformationIfNeeded(TextStream& stream, const LayoutContext& context, const RenderBox& renderer, const Box& layoutBox)
     43static bool outputMismatchingSimpleLineInformationIfNeeded(TextStream& stream, const LayoutContext& layoutContext, const RenderBlockFlow& blockFlow, const Container& inlineFormattingRoot)
     44{
     45    auto* lineLayoutData = blockFlow.simpleLineLayout();
     46    if (!lineLayoutData) {
     47        ASSERT_NOT_REACHED();
     48        return true;
     49    }
     50
     51    auto& inlineFormattingState = const_cast<LayoutContext&>(layoutContext).establishedFormattingState(inlineFormattingRoot);
     52    ASSERT(is<InlineFormattingState>(inlineFormattingState));
     53    auto& layoutRuns = downcast<InlineFormattingState>(inlineFormattingState).layoutRuns();
     54
     55    if (layoutRuns.size() != lineLayoutData->runCount()) {
     56        stream << "Mismatching number of runs: simple runs(" << lineLayoutData->runCount() << ") layout runs(" << layoutRuns.size() << ")";
     57        stream.nextLine();
     58        return true;
     59    }
     60
     61    auto mismatched = false;
     62    for (unsigned i = 0; i < lineLayoutData->runCount(); ++i) {
     63        auto& simpleRun = lineLayoutData->runAt(i);
     64        auto& layoutRun = layoutRuns[i];
     65
     66        if (simpleRun.start == layoutRun.start() && simpleRun.end == layoutRun.end() && simpleRun.logicalLeft == layoutRun.left() && simpleRun.logicalRight == layoutRun.right())
     67            continue;
     68
     69        stream << "Mismatching: simple run(" << simpleRun.start << ", " << simpleRun.end << ") (" << simpleRun.logicalLeft << ", " << simpleRun.logicalRight << ") layout run(" << layoutRun.start() << ", " << layoutRun.end() << ") (" << layoutRun.left() << ", " << layoutRun.right() << ")";
     70        stream.nextLine();
     71        mismatched = true;
     72    }
     73    return mismatched;
     74}
     75
     76static bool outputMismatchingComplexLineInformationIfNeeded(TextStream& stream, const LayoutContext& layoutContext, const RenderBlockFlow& blockFlow, const Container& inlineFormattingRoot)
     77{
     78    auto& inlineFormattingState = const_cast<LayoutContext&>(layoutContext).establishedFormattingState(inlineFormattingRoot);
     79    ASSERT(is<InlineFormattingState>(inlineFormattingState));
     80    auto& layoutRuns = downcast<InlineFormattingState>(inlineFormattingState).layoutRuns();
     81
     82    auto mismatched = false;
     83    unsigned layoutRunIndex = 0;
     84    for (auto* rootLine = blockFlow.firstRootBox(); rootLine; rootLine = rootLine->nextRootBox()) {
     85        for (auto* lineBox = rootLine->firstChild(); lineBox; lineBox = lineBox->nextOnLine()) {
     86            if (!is<InlineTextBox>(lineBox))
     87                continue;
     88
     89            if (layoutRunIndex >= layoutRuns.size()) {
     90                // FIXME: <span>foobar</span>foobar generates 2 inline text boxes while we only generate one layout run (which is much better, since it enables us to do kerning across inline elements).
     91                stream << "Mismatching number of runs: layout runs(" << layoutRuns.size() << ")";
     92                stream.nextLine();
     93                return true;
     94            }
     95
     96            auto& layoutRun = layoutRuns[layoutRunIndex];
     97            auto& inlineTextBox = downcast<InlineTextBox>(*lineBox);
     98            if (inlineTextBox.start() == layoutRun.start() && inlineTextBox.end() == layoutRun.end() && inlineTextBox.logicalLeft() == layoutRun.left() && inlineTextBox.logicalRight() == layoutRun.right()) {
     99                stream << "Mismatching: simple run(" << inlineTextBox.start() << ", " << inlineTextBox.end() << ") (" << inlineTextBox.logicalLeft() << ", " << inlineTextBox.logicalRight() << ") layout run(" << layoutRun.start() << ", " << layoutRun.end() << ") (" << layoutRun.left() << ", " << layoutRun.right() << ")";
     100                stream.nextLine();
     101                mismatched = true;
     102            }
     103            ++layoutRunIndex;
     104        }
     105    }
     106    return mismatched;
     107}
     108
     109static bool outputMismatchingBlockBoxInformationIfNeeded(TextStream& stream, const LayoutContext& context, const RenderBox& renderer, const Box& layoutBox)
    43110{
    44111    bool firstMismatchingRect = true;
     
    93160static bool verifyAndOutputSubtree(TextStream& stream, const LayoutContext& context, const RenderBox& renderer, const Box& layoutBox)
    94161{
    95     auto mismtachingGeometry = outputMismatchingBoxInformationIfNeeded(stream, context, renderer, layoutBox);
     162    auto mismtachingGeometry = outputMismatchingBlockBoxInformationIfNeeded(stream, context, renderer, layoutBox);
    96163
    97164    if (!is<Container>(layoutBox))
     
    108175        }
    109176
    110         auto mismatchingSubtreeGeometry = verifyAndOutputSubtree(stream, context, downcast<RenderBox>(*childRenderer), *childBox);
    111         mismtachingGeometry |= mismatchingSubtreeGeometry;
     177        if (is<RenderBlockFlow>(*childRenderer) && childBox->establishesInlineFormattingContext()) {
     178            ASSERT(childRenderer->childrenInline());
     179            auto& blockFlow = downcast<RenderBlockFlow>(*childRenderer);
     180            auto& formattingRoot = downcast<Container>(*childBox);
     181            mismtachingGeometry |= blockFlow.lineLayoutPath() == RenderBlockFlow::SimpleLinesPath ? outputMismatchingSimpleLineInformationIfNeeded(stream, context, blockFlow, formattingRoot) : outputMismatchingComplexLineInformationIfNeeded(stream, context, blockFlow, formattingRoot);
     182        } else {
     183            auto mismatchingSubtreeGeometry = verifyAndOutputSubtree(stream, context, downcast<RenderBox>(*childRenderer), *childBox);
     184            mismtachingGeometry |= mismatchingSubtreeGeometry;
     185        }
    112186
    113187        childBox = childBox->nextSibling();
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r234084 r234085  
    5252}
    5353
    54 void InlineFormattingContext::layout(LayoutContext& layoutContext, FormattingState&) const
     54void InlineFormattingContext::layout(LayoutContext& layoutContext, FormattingState& inlineFormattingState) const
    5555{
    5656    if (!is<Container>(root()))
     
    9191    auto lineRight = formattingRootDisplayBox.contentBoxRight();
    9292
    93     auto textRuns = textContentProvider.textRuns();
    9493    SimpleLineBreaker::LineConstraintList constraints;
    9594    constraints.append({ { }, lineLeft, lineRight });
    96     SimpleLineBreaker simpleLineBreaker(textRuns, textContentProvider, WTFMove(constraints), formattingRoot.style());
    97     auto layoutRuns = simpleLineBreaker.runs();
     95    auto textRunList = textContentProvider.textRuns();
     96    SimpleLineBreaker simpleLineBreaker(textRunList, textContentProvider, WTFMove(constraints), formattingRoot.style());
     97
     98    // Since we don't yet have a display tree context for inline boxes, let's just cache the runs on the state so that they can be verified against the sll/inline tree runs later.
     99    ASSERT(is<InlineFormattingState>(inlineFormattingState));
     100    downcast<InlineFormattingState>(inlineFormattingState).addLayoutRuns(simpleLineBreaker.runs());
    98101
    99102    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> layout context(" << &layoutContext << ") formatting root(" << &root() << ")");
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h

    r233469 r234085  
    2929
    3030#include "FormattingState.h"
     31#include "Runs.h"
    3132#include <wtf/IsoMalloc.h>
    3233
     
    4142    InlineFormattingState(Ref<FloatingState>&&, const LayoutContext&);
    4243    virtual ~InlineFormattingState();
     44
     45    // This is temporary. We need to construct a display tree context for inlines.
     46    void addLayoutRuns(Vector<LayoutRun>&& layoutRuns) { m_layoutRuns = WTFMove(layoutRuns); }
     47    const Vector<LayoutRun>& layoutRuns() const { return m_layoutRuns; }
     48
     49private:
     50    Vector<LayoutRun> m_layoutRuns;
    4351};
    4452
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r233482 r234085  
    119119
    120120#if ENABLE(TREE_DEBUGGING)
    121 static void outputLayoutBox(TextStream& stream, const Box& layoutBox, const Display::Box& displayBox, unsigned depth)
     121static void outputLayoutBox(TextStream& stream, const Box& layoutBox, const Display::Box* displayBox, unsigned depth)
    122122{
    123123    unsigned printedCharacters = 0;
     
    135135    } else
    136136        stream << "box";
    137     stream << " at [" << displayBox.left() << " " << displayBox.top() << "] size [" << displayBox.width() << " " << displayBox.height() << "]";
     137    // FIXME: Inline text runs don't create display boxes yet.
     138    if (displayBox)
     139        stream << " at [" << displayBox->left() << " " << displayBox->top() << "] size [" << displayBox->width() << " " << displayBox->height() << "]";
    138140    stream << " object [" << &layoutBox << "]";
    139141
     
    144146{
    145147    for (auto& child : childrenOfType<Box>(rootContainer)) {
    146         outputLayoutBox(stream, child, *layoutContext.displayBoxForLayoutBox(child), depth);
     148        outputLayoutBox(stream, child, layoutContext.displayBoxForLayoutBox(child), depth);
    147149        if (is<Container>(child))
    148150            outputLayoutTree(layoutContext, stream, downcast<Container>(child), depth + 1);
     
    153155{
    154156    TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect);
    155     outputLayoutBox(stream, layoutBox, *layoutContext.displayBoxForLayoutBox(layoutBox), 0);
     157    outputLayoutBox(stream, layoutBox, layoutContext.displayBoxForLayoutBox(layoutBox), 0);
    156158    outputLayoutTree(layoutContext, stream, layoutBox, 1);
    157159    WTFLogAlways("%s", stream.release().utf8().data());
Note: See TracChangeset for help on using the changeset viewer.