Changeset 252979 in webkit


Ignore:
Timestamp:
Dec 2, 2019 1:28:57 AM (4 years ago)
Author:
Antti Koivisto
Message:

[LFC][Render tree] Support LFC in LineLayoutTraversal
https://bugs.webkit.org/show_bug.cgi?id=204727

Reviewed by Zalan Bujtas.

Add support for traversing LFC inline layout to TextBoxIterator and ElementBoxIterator.
This makes render tree dumps and TextIterator work with LFC layout.

  • Headers.cmake:
  • WebCore.xcodeproj/project.pbxproj:
  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):

  • layout/RenderBlockFlowLineLayout.cpp:

(WebCore::Layout::RenderBlockFlowLineLayout::layout):
(WebCore::Layout::RenderBlockFlowLineLayout::inlineResults const):
(WebCore::Layout::RenderBlockFlowLineLayout::textBoxesFor const):
(WebCore::Layout::RenderBlockFlowLineLayout::elementBoxFor const):

  • layout/RenderBlockFlowLineLayout.h:
  • layout/Verification.cpp:

(WebCore::Layout::outputMismatchingSimpleLineInformationIfNeeded):
(WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded):

  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const):

  • layout/displaytree/DisplayPainter.cpp:

(WebCore::Display::paintInlineContent):

  • layout/displaytree/DisplayRun.h:

(WebCore::Display::Run::layoutBox const):

Replace style with layout box weak pointer. This allows finding runs for a given box.

(WebCore::Display::Run::style const):

Get style from the layout box.

(WebCore::Display::Run::Run):

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
(WebCore::Layout::InlineFormattingContext::invalidateFormattingState):

  • layout/inlineformatting/InlineFormattingContextQuirks.cpp:

(WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):

  • layout/inlineformatting/InlineFormattingState.h:

(WebCore::Layout::InlineFormattingState::results const):
(WebCore::Layout::InlineFormattingState::clearResults):
(WebCore::Layout::InlineFormattingState::ensureResults):
(WebCore::Layout::InlineFormattingState::displayRuns const): Deleted.
(WebCore::Layout::InlineFormattingState::displayRuns): Deleted.
(WebCore::Layout::InlineFormattingState::lineBoxes const): Deleted.
(WebCore::Layout::InlineFormattingState::lineBoxes): Deleted.
(WebCore::Layout::InlineFormattingState::addLineBox): Deleted.
(WebCore::Layout::InlineFormattingState::lineBoxForRun const): Deleted.
(WebCore::Layout::InlineFormattingState::addDisplayRun): Deleted.
(WebCore::Layout::InlineFormattingState::resetDisplayRuns): Deleted.

  • layout/inlineformatting/InlineLineBuilder.cpp:

(WebCore::Layout::LineBuilder::alignContentVertically):
(WebCore::Layout::LineBuilder::adjustBaselineAndLineHeight):

  • layout/displaytree/DisplayInlineContent.h: Copied from Source/WebCore/layout/RenderBlockFlowLineLayout.h.

(WebCore::Display::InlineContent::lineBoxForRun const):

Factor into a struct. Make it refcounted for safe access from line layout iterators.

(WebCore::Layout::outputInlineRuns):

  • rendering/line/LineLayoutTraversal.cpp:

(WebCore::LineLayoutTraversal::TextBoxIterator::TextBoxIterator):
(WebCore::LineLayoutTraversal::flowForText):
(WebCore::LineLayoutTraversal::firstTextBoxFor):
(WebCore::LineLayoutTraversal::firstTextBoxInTextOrderFor):
(WebCore::LineLayoutTraversal::ElementBoxIterator::ElementBoxIterator):
(WebCore::LineLayoutTraversal::elementBoxFor):

  • rendering/line/LineLayoutTraversal.h:
  • rendering/line/LineLayoutTraversalDisplayRunPath.h: Added.

(WebCore::LineLayoutTraversal::linePosition):
(WebCore::LineLayoutTraversal::DisplayRunPath::DisplayRunPath):

New path for traversing display runs.

(WebCore::LineLayoutTraversal::DisplayRunPath::rect const):
(WebCore::LineLayoutTraversal::DisplayRunPath::logicalRect const):
(WebCore::LineLayoutTraversal::DisplayRunPath::isLeftToRightDirection const):
(WebCore::LineLayoutTraversal::DisplayRunPath::dirOverride const):
(WebCore::LineLayoutTraversal::DisplayRunPath::isLineBreak const):
(WebCore::LineLayoutTraversal::DisplayRunPath::hasHyphen const):
(WebCore::LineLayoutTraversal::DisplayRunPath::text const):
(WebCore::LineLayoutTraversal::DisplayRunPath::localStartOffset const):
(WebCore::LineLayoutTraversal::DisplayRunPath::localEndOffset const):
(WebCore::LineLayoutTraversal::DisplayRunPath::length const):
(WebCore::LineLayoutTraversal::DisplayRunPath::isLastOnLine const):
(WebCore::LineLayoutTraversal::DisplayRunPath::isLast const):
(WebCore::LineLayoutTraversal::DisplayRunPath::traverseNextTextBoxInVisualOrder):
(WebCore::LineLayoutTraversal::DisplayRunPath::traverseNextTextBoxInTextOrder):
(WebCore::LineLayoutTraversal::DisplayRunPath::operator== const):
(WebCore::LineLayoutTraversal::DisplayRunPath::atEnd const):
(WebCore::LineLayoutTraversal::DisplayRunPath::displayRuns const):
(WebCore::LineLayoutTraversal::DisplayRunPath::firstRun const):
(WebCore::LineLayoutTraversal::DisplayRunPath::run const):

Location:
trunk/Source/WebCore
Files:
1 added
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252977 r252979  
     12019-12-02  Antti Koivisto  <antti@apple.com>
     2
     3        [LFC][Render tree] Support LFC in LineLayoutTraversal
     4        https://bugs.webkit.org/show_bug.cgi?id=204727
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Add support for traversing LFC inline layout to TextBoxIterator and ElementBoxIterator.
     9        This makes render tree dumps and TextIterator work with LFC layout.
     10
     11        * Headers.cmake:
     12        * WebCore.xcodeproj/project.pbxproj:
     13        * layout/FormattingContextGeometry.cpp:
     14        (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
     15        * layout/RenderBlockFlowLineLayout.cpp:
     16        (WebCore::Layout::RenderBlockFlowLineLayout::layout):
     17        (WebCore::Layout::RenderBlockFlowLineLayout::inlineResults const):
     18        (WebCore::Layout::RenderBlockFlowLineLayout::textBoxesFor const):
     19        (WebCore::Layout::RenderBlockFlowLineLayout::elementBoxFor const):
     20        * layout/RenderBlockFlowLineLayout.h:
     21        * layout/Verification.cpp:
     22        (WebCore::Layout::outputMismatchingSimpleLineInformationIfNeeded):
     23        (WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded):
     24        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     25        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
     26        * layout/blockformatting/BlockMarginCollapse.cpp:
     27        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const):
     28        * layout/displaytree/DisplayPainter.cpp:
     29        (WebCore::Display::paintInlineContent):
     30        * layout/displaytree/DisplayRun.h:
     31        (WebCore::Display::Run::layoutBox const):
     32
     33        Replace style with layout box weak pointer. This allows finding runs for a given box.
     34
     35        (WebCore::Display::Run::style const):
     36
     37        Get style from the layout box.
     38
     39        (WebCore::Display::Run::Run):
     40        * layout/inlineformatting/InlineFormattingContext.cpp:
     41        (WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
     42        (WebCore::Layout::InlineFormattingContext::invalidateFormattingState):
     43        * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
     44        (WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):
     45        * layout/inlineformatting/InlineFormattingState.h:
     46        (WebCore::Layout::InlineFormattingState::results const):
     47        (WebCore::Layout::InlineFormattingState::clearResults):
     48        (WebCore::Layout::InlineFormattingState::ensureResults):
     49        (WebCore::Layout::InlineFormattingState::displayRuns const): Deleted.
     50        (WebCore::Layout::InlineFormattingState::displayRuns): Deleted.
     51        (WebCore::Layout::InlineFormattingState::lineBoxes const): Deleted.
     52        (WebCore::Layout::InlineFormattingState::lineBoxes): Deleted.
     53        (WebCore::Layout::InlineFormattingState::addLineBox): Deleted.
     54        (WebCore::Layout::InlineFormattingState::lineBoxForRun const): Deleted.
     55        (WebCore::Layout::InlineFormattingState::addDisplayRun): Deleted.
     56        (WebCore::Layout::InlineFormattingState::resetDisplayRuns): Deleted.
     57        * layout/inlineformatting/InlineLineBuilder.cpp:
     58        (WebCore::Layout::LineBuilder::alignContentVertically):
     59        (WebCore::Layout::LineBuilder::adjustBaselineAndLineHeight):
     60        * layout/displaytree/DisplayInlineContent.h: Copied from Source/WebCore/layout/RenderBlockFlowLineLayout.h.
     61        (WebCore::Display::InlineContent::lineBoxForRun const):
     62
     63        Factor into a struct. Make it refcounted for safe access from line layout iterators.
     64
     65        (WebCore::Layout::outputInlineRuns):
     66        * rendering/line/LineLayoutTraversal.cpp:
     67        (WebCore::LineLayoutTraversal::TextBoxIterator::TextBoxIterator):
     68        (WebCore::LineLayoutTraversal::flowForText):
     69        (WebCore::LineLayoutTraversal::firstTextBoxFor):
     70        (WebCore::LineLayoutTraversal::firstTextBoxInTextOrderFor):
     71        (WebCore::LineLayoutTraversal::ElementBoxIterator::ElementBoxIterator):
     72        (WebCore::LineLayoutTraversal::elementBoxFor):
     73        * rendering/line/LineLayoutTraversal.h:
     74        * rendering/line/LineLayoutTraversalDisplayRunPath.h: Added.
     75        (WebCore::LineLayoutTraversal::linePosition):
     76        (WebCore::LineLayoutTraversal::DisplayRunPath::DisplayRunPath):
     77
     78        New path for traversing display runs.
     79
     80        (WebCore::LineLayoutTraversal::DisplayRunPath::rect const):
     81        (WebCore::LineLayoutTraversal::DisplayRunPath::logicalRect const):
     82        (WebCore::LineLayoutTraversal::DisplayRunPath::isLeftToRightDirection const):
     83        (WebCore::LineLayoutTraversal::DisplayRunPath::dirOverride const):
     84        (WebCore::LineLayoutTraversal::DisplayRunPath::isLineBreak const):
     85        (WebCore::LineLayoutTraversal::DisplayRunPath::hasHyphen const):
     86        (WebCore::LineLayoutTraversal::DisplayRunPath::text const):
     87        (WebCore::LineLayoutTraversal::DisplayRunPath::localStartOffset const):
     88        (WebCore::LineLayoutTraversal::DisplayRunPath::localEndOffset const):
     89        (WebCore::LineLayoutTraversal::DisplayRunPath::length const):
     90        (WebCore::LineLayoutTraversal::DisplayRunPath::isLastOnLine const):
     91        (WebCore::LineLayoutTraversal::DisplayRunPath::isLast const):
     92        (WebCore::LineLayoutTraversal::DisplayRunPath::traverseNextTextBoxInVisualOrder):
     93        (WebCore::LineLayoutTraversal::DisplayRunPath::traverseNextTextBoxInTextOrder):
     94        (WebCore::LineLayoutTraversal::DisplayRunPath::operator== const):
     95        (WebCore::LineLayoutTraversal::DisplayRunPath::atEnd const):
     96        (WebCore::LineLayoutTraversal::DisplayRunPath::displayRuns const):
     97        (WebCore::LineLayoutTraversal::DisplayRunPath::firstRun const):
     98        (WebCore::LineLayoutTraversal::DisplayRunPath::run const):
     99
    11002019-12-01  Tim Horton  <timothy_horton@apple.com>
    2101
  • trunk/Source/WebCore/Headers.cmake

    r252959 r252979  
    13221322    rendering/line/LineLayoutTraversal.h
    13231323    rendering/line/LineLayoutTraversalComplexPath.h
     1324    rendering/line/LineLayoutTraversalDisplayRunPath.h
    13241325    rendering/line/LineLayoutTraversalSimplePath.h
    13251326    rendering/line/LineWidth.h
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r252966 r252979  
    20432043                6FA4454E898F2FC168BC38C1 /* JSBeforeUnloadEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E04A27BED2F81F98E9022B /* JSBeforeUnloadEvent.h */; };
    20442044                6FB11B5C21783FD000E2A574 /* TextUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB11B5921783FCF00E2A574 /* TextUtil.h */; settings = {ATTRIBUTES = (Private, ); }; };
    2045                 6FB47E632277425A00C7BCB0 /* InlineLineBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB47E612277425A00C7BCB0 /* InlineLineBox.h */; };
     2045                6FB47E632277425A00C7BCB0 /* InlineLineBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB47E612277425A00C7BCB0 /* InlineLineBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
    20462046                6FB5E214221F2453003989CF /* ContentChangeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB5E212221F2447003989CF /* ContentChangeObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
    20472047                6FCE1A1A22618ABD004F0343 /* DisplayRun.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FCE1A1822618AB3004F0343 /* DisplayRun.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    48194819                E44B4BB4141650D7002B1D8B /* SelectorChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = E44B4BB2141650D7002B1D8B /* SelectorChecker.h */; };
    48204820                E44FA1851BCA6B5A0091B6EF /* ComposedTreeIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E44FA1841BCA6B5A0091B6EF /* ComposedTreeIterator.h */; };
     4821                E451C628239293EC00993190 /* LineLayoutTraversalDisplayRunPath.h in Headers */ = {isa = PBXBuildFile; fileRef = E451C627239293EB00993190 /* LineLayoutTraversalDisplayRunPath.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4822                E451C6312394027900993190 /* LayoutUnits.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F73918C2106CEDD006AF262 /* LayoutUnits.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4823                E451C6322394031A00993190 /* MarginTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FE7AA2621C37B6300296DCD /* MarginTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4824                E451C6342394058F00993190 /* DisplayInlineContent.h in Headers */ = {isa = PBXBuildFile; fileRef = E451C6332394058E00993190 /* DisplayInlineContent.h */; settings = {ATTRIBUTES = (Private, ); }; };
    48214825                E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = E45322AA140CE267005A0F92 /* SelectorQuery.h */; };
    48224826                E45BA6AA2374926C004DFC07 /* MatchedDeclarationsCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */; };
     
    1515015154                E44FA1841BCA6B5A0091B6EF /* ComposedTreeIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComposedTreeIterator.h; sourceTree = "<group>"; };
    1515115155                E44FA1861BCA91560091B6EF /* ComposedTreeIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComposedTreeIterator.cpp; sourceTree = "<group>"; };
     15156                E451C627239293EB00993190 /* LineLayoutTraversalDisplayRunPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineLayoutTraversalDisplayRunPath.h; sourceTree = "<group>"; };
     15157                E451C6332394058E00993190 /* DisplayInlineContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayInlineContent.h; sourceTree = "<group>"; };
    1515215158                E45322A9140CE267005A0F92 /* SelectorQuery.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorQuery.cpp; sourceTree = "<group>"; };
    1515315159                E45322AA140CE267005A0F92 /* SelectorQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorQuery.h; sourceTree = "<group>"; };
     
    1671516721                                1199FA5A208E3C7F002358CC /* DisplayBox.cpp */,
    1671616722                                1199FA59208E3C7F002358CC /* DisplayBox.h */,
     16723                                E451C6332394058E00993190 /* DisplayInlineContent.h */,
    1671716724                                6F77868523491AC6004D9636 /* DisplayPainter.cpp */,
    1671816725                                6F77868723491AD7004D9636 /* DisplayPainter.h */,
     
    2873228739                                E484A33D23055303009ADE6A /* LineLayoutTraversal.cpp */,
    2873328740                                E484A33B23055303009ADE6A /* LineLayoutTraversal.h */,
     28741                                E4343D242392778F00EBBB66 /* LineLayoutTraversalComplexPath.h */,
     28742                                E451C627239293EB00993190 /* LineLayoutTraversalDisplayRunPath.h */,
    2873428743                                E4343D212392778300EBBB66 /* LineLayoutTraversalSimplePath.h */,
    28735                                 E4343D242392778F00EBBB66 /* LineLayoutTraversalComplexPath.h */,
    2873628744                                FFDBC046183D27B700407109 /* LineWidth.cpp */,
    2873728745                                FFDBC045183D27B700407109 /* LineWidth.h */,
     
    3004130049                                A871DB2A0A150BD600B12A68 /* HTMLTableCellElement.h in Headers */,
    3004230050                                A871DB2F0A150BD600B12A68 /* HTMLTableColElement.h in Headers */,
     30051                                E451C628239293EC00993190 /* LineLayoutTraversalDisplayRunPath.h in Headers */,
    3004330052                                A871DB270A150BD600B12A68 /* HTMLTableElement.h in Headers */,
    3004430053                                A871DB2C0A150BD600B12A68 /* HTMLTablePartElement.h in Headers */,
     
    3015230161                                2D5A5931152525D00036EE51 /* ImageOrientation.h in Headers */,
    3015330162                                72283F0E230B268C00F5D828 /* ImagePaintingOptions.h in Headers */,
     30163                                E451C6322394031A00993190 /* MarginTypes.h in Headers */,
    3015430164                                B51A2F3F17D7D3AE0072517A /* ImageQualityController.h in Headers */,
    3015530165                                49291E4B134172C800E753DE /* ImageRenderingMode.h in Headers */,
     
    3248732497                                B2227ADD0D00BF220071B782 /* SVGTransformDistance.h in Headers */,
    3248832498                                B2227ADF0D00BF220071B782 /* SVGTransformList.h in Headers */,
     32499                                E451C6312394027900993190 /* LayoutUnits.h in Headers */,
    3248932500                                7CE58D581DD7D96D00128552 /* SVGTransformValue.h in Headers */,
    3249032501                                B2227AE20D00BF220071B782 /* SVGTRefElement.h in Headers */,
     
    3281632827                                D3F3D36A1A69B7B90059FC2B /* WebGLRenderingContextBase.h in Headers */,
    3281732828                                6F995A221A7078B100A735F4 /* WebGLSampler.h in Headers */,
     32829                                E451C6342394058F00993190 /* DisplayInlineContent.h in Headers */,
    3281832830                                49C7B9E31042D32F0009D447 /* WebGLShader.h in Headers */,
    3281932831                                A07D3358152B632D001B6393 /* WebGLShaderPrecisionFormat.h in Headers */,
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r252942 r252979  
    132132    auto& formattingRootContainer = downcast<Container>(layoutBox);
    133133    if (formattingRootContainer.establishesInlineFormattingContext()) {
    134         auto& lineBoxes = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRootContainer)).lineBoxes();
     134        auto& lineBoxes = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRootContainer)).displayInlineContent()->lineBoxes;
    135135        // Even empty containers generate one line.
    136136        ASSERT(!lineBoxes.isEmpty());
  • trunk/Source/WebCore/layout/RenderBlockFlowLineLayout.cpp

    r252942 r252979  
    3737#include "PaintInfo.h"
    3838#include "RenderBlockFlow.h"
     39#include "RenderLineBreak.h"
    3940#include "RuntimeEnabledFeatures.h"
    4041#include "SimpleLineLayout.h"
     
    7980    layoutContext.layout(m_flow.contentSize(), invalidationState);
    8081
    81     auto& lineBoxes = downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(rootContainer)).lineBoxes();
     82    auto& lineBoxes = downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(rootContainer)).displayInlineContent()->lineBoxes;
    8283    auto height = lineBoxes.last().logicalBottom();
    8384
     
    8990{
    9091    return m_layoutState ? m_layoutState->displayBoxForLayoutBox(m_layoutState->root()).contentBoxHeight() : 0_lu;
     92}
     93
     94const Display::InlineContent* RenderBlockFlowLineLayout::displayInlineContent() const
     95{
     96    return downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(m_treeContent->rootLayoutBox())).displayInlineContent();
    9197}
    9298
     
    103109}
    104110
     111LineLayoutTraversal::TextBoxIterator RenderBlockFlowLineLayout::textBoxesFor(const RenderText& renderText) const
     112{
     113    auto* inlineContent = displayInlineContent();
     114    if (!inlineContent)
     115        return { };
     116    auto* layoutBox = m_treeContent->layoutBoxForRenderer(renderText);
     117    ASSERT(layoutBox);
     118
     119    Optional<size_t> firstIndex = 0;
     120    size_t lastIndex = 0;
     121    for (size_t i = 0; i < inlineContent->runs.size(); ++i) {
     122        auto& run =  inlineContent->runs[i];
     123        if (&run.layoutBox() == layoutBox) {
     124            if (!firstIndex)
     125                firstIndex = i;
     126            lastIndex = i;
     127        }
     128    }
     129    if (!firstIndex)
     130        return { };
     131
     132    return { LineLayoutTraversal::DisplayRunPath(*inlineContent, *firstIndex, lastIndex + 1) };
     133}
     134
     135LineLayoutTraversal::ElementBoxIterator RenderBlockFlowLineLayout::elementBoxFor(const RenderLineBreak& renderLineBreak) const
     136{
     137    auto* inlineContent = displayInlineContent();
     138    if (!inlineContent)
     139        return { };
     140    auto* layoutBox = m_treeContent->layoutBoxForRenderer(renderLineBreak);
     141    ASSERT(layoutBox);
     142
     143    for (size_t i = 0; i < inlineContent->runs.size(); ++i) {
     144        auto& run =  inlineContent->runs[i];
     145        if (&run.layoutBox() == layoutBox)
     146            return { LineLayoutTraversal::DisplayRunPath(*inlineContent, i, i + 1) };
     147    }
     148
     149    return { };
     150}
     151
    105152}
    106153}
  • trunk/Source/WebCore/layout/RenderBlockFlowLineLayout.h

    r252893 r252979  
    2929
    3030#include "LayoutPoint.h"
     31#include "LineLayoutTraversal.h"
    3132
    3233namespace WebCore {
     
    3435class GraphicsContext;
    3536class RenderBlockFlow;
     37class RenderLineBreak;
    3638struct PaintInfo;
     39
     40namespace Display {
     41struct InlineContent;
     42}
    3743
    3844namespace Layout {
     
    5056
    5157    void layout();
    52    
    5358    LayoutUnit contentBoxHeight() const;
     59    const Display::InlineContent* displayInlineContent() const;
    5460
    5561    void paint(PaintInfo&, const LayoutPoint& paintOffset);
     62
     63    LineLayoutTraversal::TextBoxIterator textBoxesFor(const RenderText&) const;
     64    LineLayoutTraversal::ElementBoxIterator elementBoxFor(const RenderLineBreak&) const;
    5665
    5766private:
  • trunk/Source/WebCore/layout/Verification.cpp

    r252942 r252979  
    7777
    7878    auto& inlineFormattingState = layoutState.establishedFormattingState(inlineFormattingRoot);
    79     ASSERT(is<InlineFormattingState>(inlineFormattingState));
    80     auto& displayRuns = downcast<InlineFormattingState>(inlineFormattingState).displayRuns();
     79    auto* displayInlineContent = downcast<InlineFormattingState>(inlineFormattingState).displayInlineContent();
     80    if (!displayInlineContent) {
     81        ASSERT_NOT_REACHED();
     82        return true;
     83    }
     84
     85    auto& displayRuns = displayInlineContent->runs;
    8186
    8287    if (displayRuns.size() != lineLayoutData->runCount()) {
     
    158163{
    159164    auto& inlineFormattingState = layoutState.establishedFormattingState(inlineFormattingRoot);
    160     ASSERT(is<InlineFormattingState>(inlineFormattingState));
    161     auto& displayRuns = downcast<InlineFormattingState>(inlineFormattingState).displayRuns();
     165
     166    auto* displayInlineContent = downcast<InlineFormattingState>(inlineFormattingState).displayInlineContent();
     167    if (!displayInlineContent) {
     168        ASSERT_NOT_REACHED();
     169        return true;
     170    }
     171    auto& displayRuns = displayInlineContent->runs;
    162172
    163173    // Collect inlineboxes.
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r252942 r252979  
    7373        auto& layoutContainer = downcast<Container>(layoutBox);
    7474        if (layoutContainer.establishesInlineFormattingContext()) {
    75             auto& lineBoxes = downcast<InlineFormattingState>(layoutState().establishedFormattingState(layoutContainer)).lineBoxes();
     75            auto& lineBoxes = downcast<InlineFormattingState>(layoutState().establishedFormattingState(layoutContainer)).displayInlineContent()->lineBoxes;
    7676            // Even empty containers generate one line.
    7777            ASSERT(!lineBoxes.isEmpty());
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r252942 r252979  
    396396            auto isConsideredEmpty = [&] {
    397397                auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(layoutContainer));
    398                 for (auto& lineBox : formattingState.lineBoxes()) {
     398                for (auto& lineBox : formattingState.displayInlineContent()->lineBoxes) {
    399399                    if (!lineBox.isConsideredEmpty())
    400400                        return false;
  • trunk/Source/WebCore/layout/displaytree/DisplayInlineContent.h

    r252978 r252979  
    2828#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    2929
    30 #include "LayoutPoint.h"
     30#include "DisplayRun.h"
     31#include "InlineLineBox.h"
     32#include <wtf/Vector.h>
    3133
    3234namespace WebCore {
     35namespace Display {
    3336
    34 class GraphicsContext;
    35 class RenderBlockFlow;
    36 struct PaintInfo;
     37struct InlineContent : public RefCounted<InlineContent> {
     38    using Runs = Vector<Run, 10>;
     39    using LineBoxes = Vector<Layout::LineBox, 5>;
    3740
    38 namespace Layout {
     41    Runs runs;
     42    LineBoxes lineBoxes;
    3943
    40 class LayoutTreeContent;
    41 class LayoutState;
    42 
    43 class RenderBlockFlowLineLayout {
    44     WTF_MAKE_FAST_ALLOCATED;
    45 public:
    46     RenderBlockFlowLineLayout(const RenderBlockFlow&);
    47     ~RenderBlockFlowLineLayout();
    48 
    49     static bool canUseFor(const RenderBlockFlow&);
    50 
    51     void layout();
    52    
    53     LayoutUnit contentBoxHeight() const;
    54 
    55     void paint(PaintInfo&, const LayoutPoint& paintOffset);
    56 
    57 private:
    58     const RenderBlockFlow& m_flow;
    59     std::unique_ptr<LayoutTreeContent> m_treeContent;
    60     std::unique_ptr<LayoutState> m_layoutState;
     44    const Layout::LineBox& lineBoxForRun(const Run& run) const { return lineBoxes[run.lineIndex()]; }
    6145};
    6246
  • trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp

    r252942 r252979  
    113113static void paintInlineContent(GraphicsContext& context, const Box& rootAbsoluteDisplayBox, const Layout::InlineFormattingState& formattingState)
    114114{
    115     auto& displayRuns = formattingState.displayRuns();
     115    auto* displayInlineContent = formattingState.displayInlineContent();
     116    if (!displayInlineContent)
     117        return;
     118
     119    auto& displayRuns = displayInlineContent->runs;
    116120    if (displayRuns.isEmpty())
    117121        return;
     
    125129            auto logicalLeft = rootAbsoluteDisplayBox.left() + run.logicalLeft();
    126130            // FIXME: Add non-baseline align painting
    127             auto& lineBox = formattingState.lineBoxForRun(run);
     131            auto& lineBox = displayInlineContent->lineBoxForRun(run);
    128132            auto baselineOffset = rootAbsoluteDisplayBox.top() + lineBox.logicalTop() + lineBox.baselineOffset();
    129133            if (auto expansionContext = textContext->expansion())
  • trunk/Source/WebCore/layout/displaytree/DisplayRun.h

    r252932 r252979  
    2929
    3030#include "DisplayRect.h"
     31#include "LayoutBox.h"
    3132#include "LayoutUnit.h"
    3233#include "RenderStyle.h"
     
    6869    };
    6970
    70     Run(size_t lineIndex, const RenderStyle&, const Rect& logicalRect, Optional<TextContext> = WTF::nullopt);
     71    Run(size_t lineIndex, const Layout::Box&, const Rect& logicalRect, Optional<TextContext> = WTF::nullopt);
    7172
    7273    size_t lineIndex() const { return m_lineIndex; }
     
    9899    CachedImage* image() const { return m_cachedImage; }
    99100
    100     const RenderStyle& style() const { return m_style; }
     101    const Layout::Box& layoutBox() const { return *m_layoutBox; }
     102    const RenderStyle& style() const { return m_layoutBox->style(); }
    101103
    102104private:
    103105    // FIXME: Find out the Display::Run <-> paint style setup.
    104106    const size_t m_lineIndex;
    105     const RenderStyle& m_style;
     107    WeakPtr<const Layout::Box> m_layoutBox;
    106108    CachedImage* m_cachedImage { nullptr };
    107109    Rect m_logicalRect;
     
    109111};
    110112
    111 inline Run::Run(size_t lineIndex, const RenderStyle& style, const Rect& logicalRect, Optional<TextContext> textContext)
     113inline Run::Run(size_t lineIndex, const Layout::Box& layoutBox, const Rect& logicalRect, Optional<TextContext> textContext)
    112114    : m_lineIndex(lineIndex)
    113     , m_style(style)
     115    , m_layoutBox(makeWeakPtr(layoutBox))
    114116    , m_logicalRect(logicalRect)
    115117    , m_textContext(textContext)
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r252958 r252979  
    427427    }
    428428
    429     auto lineIndex = formattingState.lineBoxes().size();
    430     formattingState.addLineBox(LineBox { lineContent.lineBox });
     429    auto& inlineContent = formattingState.ensureDisplayInlineContent();
     430
     431    auto lineIndex = inlineContent.lineBoxes.size();
     432    inlineContent.lineBoxes.append(LineBox { lineContent.lineBox });
    431433
    432434    // Compute box final geometry.
     
    442444        auto initiatesInlineRun = !lineRun.isContainerStart() && !lineRun.isContainerEnd() && !lineRun.isCollapsedToVisuallyEmpty();
    443445        if (initiatesInlineRun)
    444             formattingState.addDisplayRun({ lineIndex, lineRun.layoutBox().style(), lineRun.logicalRect(), lineRun.textContext() });
     446            inlineContent.runs.append({ lineIndex, lineRun.layoutBox(), lineRun.logicalRect(), lineRun.textContext() });
    445447
    446448        if (lineRun.isForcedLineBreak()) {
     
    502504    // Find out what we need to invalidate. This is where we add some smarts to do partial line layout.
    503505    // For now let's just clear the runs.
    504     formattingState().resetDisplayRuns();
     506    formattingState().clearDisplayInlineContent();
    505507    // FIXME: This is also where we would delete inline items if their content changed.
    506508}
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp

    r252942 r252979  
    6464            if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) {
    6565                auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(downcast<Container>(layoutBox)));
    66                 ASSERT(!formattingState.lineBoxes().isEmpty());
    67                 auto inlineBlockBaseline = formattingState.lineBoxes().last().baseline();
     66                auto inlineBlockBaseline = formattingState.displayInlineContent()->lineBoxes.last().baseline();
    6867                if (inlineBlockBaseline.descent())
    6968                    return false;
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h

    r252942 r252979  
    2828#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    2929
     30#include "DisplayInlineContent.h"
    3031#include "DisplayRun.h"
    3132#include "FormattingState.h"
     
    3334#include "InlineLineBox.h"
    3435#include <wtf/IsoMalloc.h>
    35 #include <wtf/OptionSet.h>
    3636
    3737namespace WebCore {
     
    5151    void addInlineItem(std::unique_ptr<InlineItem>&& inlineItem) { m_inlineItems.append(WTFMove(inlineItem)); }
    5252
    53     using DisplayRuns = Vector<Display::Run, 10>;
    54     using LineBoxes = Vector<LineBox, 5>;
    55 
    56     const DisplayRuns& displayRuns() const { return m_displayRuns; }
    57     DisplayRuns& displayRuns() { return m_displayRuns; }
    58     void addDisplayRun(Display::Run&&);
    59     void resetDisplayRuns();
    60 
    61     const LineBoxes& lineBoxes() const { return m_lineBoxes; }
    62     LineBoxes& lineBoxes() { return m_lineBoxes; }
    63     void addLineBox(LineBox&& lineBox) { m_lineBoxes.append(lineBox); }
    64 
    65     const LineBox& lineBoxForRun(const Display::Run& displayRun) const { return m_lineBoxes[displayRun.lineIndex()]; }
     53    const Display::InlineContent* displayInlineContent() const { return m_displayInlineContent.get(); }
     54    Display::InlineContent& ensureDisplayInlineContent();
     55    void clearDisplayInlineContent() { m_displayInlineContent = nullptr; }
    6656
    6757private:
     
    6959    InlineItems m_inlineItems;
    7060
    71     // Line layout results
    72     DisplayRuns m_displayRuns;
    73     LineBoxes m_lineBoxes;
     61    RefPtr<Display::InlineContent> m_displayInlineContent;
    7462};
    7563
    76 inline void InlineFormattingState::addDisplayRun(Display::Run&& displayRun)
     64inline Display::InlineContent& InlineFormattingState::ensureDisplayInlineContent()
    7765{
    78     m_displayRuns.append(WTFMove(displayRun));
    79 }
    80 
    81 inline void InlineFormattingState::resetDisplayRuns()
    82 {
    83     m_displayRuns.clear();
    84     // Resetting the runs means no more line boxes either.
    85     m_lineBoxes.clear();
    86 
     66    if (!m_displayInlineContent)
     67        m_displayInlineContent = adoptRef(*new Display::InlineContent);
     68    return *m_displayInlineContent;
    8769}
    8870
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp

    r252972 r252979  
    262262                auto& formattingState = downcast<InlineFormattingState>(layoutState().establishedFormattingState(downcast<Container>(layoutBox)));
    263263                // Spec makes us generate at least one line -even if it is empty.
    264                 ASSERT(!formattingState.lineBoxes().isEmpty());
    265                 auto inlineBlockBaselineOffset = formattingState.lineBoxes().last().baselineOffset();
     264                auto inlineBlockBaselineOffset = formattingState.displayInlineContent()->lineBoxes.last().baselineOffset();
    266265                // The inline-block's baseline offset is relative to its content box. Let's convert it relative to the margin box.
    267266                //   inline-block
     
    600599                auto& formattingState = downcast<InlineFormattingState>(layoutState().establishedFormattingState(downcast<Container>(layoutBox)));
    601600                // Spec makes us generate at least one line -even if it is empty.
    602                 ASSERT(!formattingState.lineBoxes().isEmpty());
    603                 auto& lastLineBox = formattingState.lineBoxes().last();
     601                auto& lastLineBox = formattingState.displayInlineContent()->lineBoxes.last();
    604602                auto inlineBlockBaseline = lastLineBox.baseline();
    605603                auto beforeHeight = boxGeometry.marginBefore() + boxGeometry.borderTop() + boxGeometry.paddingTop().valueOr(0);
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r252942 r252979  
    312312{
    313313    auto& inlineFormattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(inlineFormattingRoot));
    314     auto& displayRuns = inlineFormattingState.displayRuns();
    315     auto& lineBoxes = inlineFormattingState.lineBoxes();
     314    auto* displayInlineContent = inlineFormattingState.displayInlineContent();
     315    if (!displayInlineContent)
     316        return;
     317
     318    auto& displayRuns = displayInlineContent->runs;
     319    auto& lineBoxes = displayInlineContent->lineBoxes;
    316320
    317321    unsigned printedCharacters = 0;
  • trunk/Source/WebCore/rendering/line/LineLayoutTraversal.cpp

    r252959 r252979  
    2727#include "LineLayoutTraversal.h"
    2828
     29#include "RenderBlockFlowLineLayout.h"
    2930#include "RenderLineBreak.h"
    3031
     
    3233namespace LineLayoutTraversal {
    3334
    34 TextBoxIterator::TextBoxIterator(const InlineTextBox* inlineTextBox)
    35     : m_textBox(ComplexPath { inlineTextBox, { } })
    36 {
    37 }
    38 TextBoxIterator::TextBoxIterator(Vector<const InlineTextBox*>&& sorted, size_t index)
    39     : m_textBox(ComplexPath { index < sorted.size() ? sorted[index] : nullptr, WTFMove(sorted), index })
    40 {
    41 }
    42 
    43 TextBoxIterator::TextBoxIterator(SimpleLineLayout::RunResolver::Iterator iterator, SimpleLineLayout::RunResolver::Iterator end)
    44     : m_textBox(SimplePath { iterator, end })
     35TextBoxIterator::TextBoxIterator(Box::PathVariant&& pathVariant)
     36    : m_textBox(WTFMove(pathVariant))
    4537{
    4638}
     
    7971}
    8072
     73static const RenderBlockFlow& flowForText(const RenderText& text)
     74{
     75    return downcast<RenderBlockFlow>(*text.containingBlockForObjectInFlow());
     76}
     77
    8178TextBoxIterator firstTextBoxFor(const RenderText& text)
    8279{
    83     if (auto* simpleLineLayout = text.simpleLineLayout()) {
     80    auto& flow = flowForText(text);
     81
     82    if (auto* simpleLineLayout = flow.simpleLineLayout()) {
    8483        auto range = simpleLineLayout->runResolver().rangeForRenderer(text);
    85         return { range.begin(), range.end() };
     84        return { SimplePath { range.begin(), range.end() } };
    8685    }
    8786
    88     return TextBoxIterator { text.firstTextBox() };
     87#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     88    if (auto* lfcLineLayout = flow.lfcLineLayout())
     89        return lfcLineLayout->textBoxesFor(text);
     90#endif
     91
     92    return { ComplexPath { text.firstTextBox() } };
    8993}
    9094
    9195TextBoxIterator firstTextBoxInTextOrderFor(const RenderText& text)
    9296{
    93     if (!text.simpleLineLayout() && text.containsReversedText()) {
     97    auto& flow = flowForText(text);
     98
     99    if (flow.complexLineLayout() && text.containsReversedText() && text.firstTextBox()) {
    94100        Vector<const InlineTextBox*> sortedTextBoxes;
    95101        for (auto* textBox = text.firstTextBox(); textBox; textBox = textBox->nextTextBox())
    96102            sortedTextBoxes.append(textBox);
    97103        std::sort(sortedTextBoxes.begin(), sortedTextBoxes.end(), InlineTextBox::compareByStart);
    98         return TextBoxIterator { WTFMove(sortedTextBoxes), 0 };
     104        auto* first = sortedTextBoxes[0];
     105        return { ComplexPath { first, WTFMove(sortedTextBoxes), 0 } };
    99106    }
    100107
     
    107114}
    108115
    109 ElementBoxIterator::ElementBoxIterator(const InlineElementBox* inlineElementBox)
    110     : m_box(ComplexPath { inlineElementBox, { } })
    111 {
    112 }
    113 ElementBoxIterator::ElementBoxIterator(SimpleLineLayout::RunResolver::Iterator iterator, SimpleLineLayout::RunResolver::Iterator end)
    114     : m_box(SimplePath { iterator, end })
     116ElementBoxIterator::ElementBoxIterator(Box::PathVariant&& pathVariant)
     117    : m_box(WTFMove(pathVariant))
    115118{
    116119}
     
    125128ElementBoxIterator elementBoxFor(const RenderLineBreak& renderElement)
    126129{
    127     if (auto& parent = *renderElement.parent(); is<RenderBlockFlow>(parent)) {
    128         if (auto* simpleLineLayout = downcast<RenderBlockFlow>(parent).simpleLineLayout()) {
    129             auto range = simpleLineLayout->runResolver().rangeForRenderer(renderElement);
    130             return { range.begin(), range.end() };
    131         }
     130    auto* containingBlock = renderElement.containingBlock();
     131    if (!is<RenderBlockFlow>(containingBlock))
     132        return { };
     133
     134    auto& flow = downcast<RenderBlockFlow>(*containingBlock);
     135
     136    if (auto* simpleLineLayout = flow.simpleLineLayout()) {
     137        auto range = simpleLineLayout->runResolver().rangeForRenderer(renderElement);
     138        return { SimplePath(range.begin(), range.end()) };
    132139    }
    133140
    134     return ElementBoxIterator { renderElement.inlineBoxWrapper() };
     141#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     142    if (auto* lfcLineLayout = flow.lfcLineLayout())
     143        return lfcLineLayout->elementBoxFor(renderElement);
     144#endif
     145
     146    return { ComplexPath(renderElement.inlineBoxWrapper()) };
    135147}
    136148
  • trunk/Source/WebCore/rendering/line/LineLayoutTraversal.h

    r252959 r252979  
    2828#include "InlineElementBox.h"
    2929#include "LineLayoutTraversalComplexPath.h"
     30#include "LineLayoutTraversalDisplayRunPath.h"
    3031#include "LineLayoutTraversalSimplePath.h"
    3132#include "RenderText.h"
     
    4849class Box {
    4950public:
    50     using PathVariant = Variant<SimplePath, ComplexPath>;
     51    using PathVariant = Variant<
     52#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     53        DisplayRunPath,
     54#endif
     55        ComplexPath,
     56        SimplePath
     57    >;
    5158
    5259    Box(PathVariant&&);
     
    8592public:
    8693    TextBoxIterator() : m_textBox(ComplexPath { nullptr, { } }) { };
    87 
    88     explicit TextBoxIterator(const InlineTextBox*);
    89     TextBoxIterator(Vector<const InlineTextBox*>&& sorted, size_t index);
    90     TextBoxIterator(SimpleLineLayout::RunResolver::Iterator, SimpleLineLayout::RunResolver::Iterator end);
     94    TextBoxIterator(Box::PathVariant&&);
    9195
    9296    TextBoxIterator& operator++() { return traverseNextInVisualOrder(); }
     
    114118public:
    115119    ElementBoxIterator() : m_box(ComplexPath { nullptr, { } }) { };
    116 
    117     explicit ElementBoxIterator(const InlineElementBox*);
    118     ElementBoxIterator(SimpleLineLayout::RunResolver::Iterator, SimpleLineLayout::RunResolver::Iterator end);
     120    ElementBoxIterator(Box::PathVariant&&);
    119121
    120122    explicit operator bool() const { return !atEnd(); }
Note: See TracChangeset for help on using the changeset viewer.