Factor complex line layout path out from RenderBlockFlow
[WebKit-https.git] / Source / WebCore / rendering / ComplexLineLayout.h
1 /*
2  * Copyright (C) 2019 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include "InlineFlowBox.h"
29 #include "LineWidth.h"
30 #include "RenderLineBoxList.h"
31 #include "RenderStyleConstants.h"
32 #include "TrailingObjects.h"
33
34 namespace WebCore {
35
36 class BidiContext;
37 class FloatingObject;
38 class FloatWithRect;
39 class FrameViewLayoutContext;
40 class InlineBox;
41 class InlineIterator;
42 class LineInfo;
43 class LineLayoutState;
44 class RenderBlockFlow;
45 class RenderObject;
46 class RenderRubyRun;
47 class RootInlineBox;
48 class VerticalPositionCache;
49 struct BidiStatus;
50 struct WordMeasurement;
51
52 template <class Run> class BidiRunList;
53 typedef Vector<WordMeasurement, 64> WordMeasurements;
54
55 class ComplexLineLayout {
56     WTF_MAKE_FAST_ALLOCATED;
57 public:
58     ComplexLineLayout(RenderBlockFlow&);
59     ~ComplexLineLayout();
60
61     RenderLineBoxList& lineBoxes() { return m_lineBoxes; }
62     const RenderLineBoxList& lineBoxes() const { return m_lineBoxes; }
63
64     RootInlineBox* firstRootBox() const { return downcast<RootInlineBox>(m_lineBoxes.firstLineBox()); }
65     RootInlineBox* lastRootBox() const { return downcast<RootInlineBox>(m_lineBoxes.lastLineBox()); }
66
67     void layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom);
68
69     LayoutUnit startAlignedOffsetForLine(LayoutUnit position, IndentTextOrNot shouldIndentText);
70     RootInlineBox* constructLine(BidiRunList<BidiRun>&, const LineInfo&);
71     bool positionNewFloatOnLine(const FloatingObject& newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo&, LineWidth&);
72     void addOverflowFromInlineChildren();
73
74     static void appendRunsForObject(BidiRunList<BidiRun>*, int start, int end, RenderObject&, InlineBidiResolver&);
75
76 private:
77     std::unique_ptr<RootInlineBox> createRootInlineBox();
78     RootInlineBox* createAndAppendRootInlineBox();
79     static InlineBox* createInlineBoxForRenderer(RenderObject*, bool isRootLineBox, bool isOnlyRun = false);
80     InlineFlowBox* createLineBoxes(RenderObject*, const LineInfo&, InlineBox*);
81     TextAlignMode textAlignmentForLine(bool endsWithSoftBreak) const;
82     void setMarginsForRubyRun(BidiRun*, RenderRubyRun&, RenderObject* previousObject, const LineInfo&);
83     void updateRubyForJustifiedText(RenderRubyRun&, BidiRun&, const Vector<unsigned, 16>& expansionOpportunities, unsigned& expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth, size_t&);
84     void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, const Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float totalLogicalWidth, float availableLogicalWidth);
85     void updateLogicalWidthForAlignment(const TextAlignMode&, const RootInlineBox*, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount);
86     void computeInlineDirectionPositionsForLine(RootInlineBox*, const LineInfo&, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&, WordMeasurements&);
87     BidiRun* computeInlineDirectionPositionsForSegment(RootInlineBox*, const LineInfo&, TextAlignMode, float& logicalLeft, float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap&, VerticalPositionCache&, WordMeasurements&);
88     void removeInlineBox(BidiRun&, const RootInlineBox&) const;
89     void computeBlockDirectionPositionsForLine(RootInlineBox*, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache&);
90     inline BidiRun* handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext);
91     void appendFloatingObjectToLastLine(FloatingObject&);
92     RootInlineBox* createLineBoxesFromBidiRuns(unsigned bidiLevel, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo&, VerticalPositionCache&, BidiRun* trailingSpaceRun, WordMeasurements&);
93     void layoutRunsAndFloats(LineLayoutState&, bool hasInlineChild);
94     inline const InlineIterator& restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver&,  const InlineIterator& oldEnd);
95     void layoutRunsAndFloatsInRange(LineLayoutState&, InlineBidiResolver&, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines);
96     void reattachCleanLineFloats(RootInlineBox& cleanLine, LayoutUnit delta, bool isFirstCleanLine);
97     void linkToEndLineIfNeeded(LineLayoutState&);
98     void checkFloatInCleanLine(RootInlineBox& cleanLine, RenderBox& floatBoxOnCleanLine, FloatWithRect& matchingFloatWithRect, bool& encounteredNewFloat, bool& dirtiedByFloat);
99     RootInlineBox* determineStartPosition(LineLayoutState&, InlineBidiResolver&);
100     void determineEndPosition(LineLayoutState&, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus);
101     bool checkPaginationAndFloatsAtEndLine(LineLayoutState&);
102     bool lineWidthForPaginatedLineChanged(RootInlineBox* rootBox, LayoutUnit lineDelta, RenderFragmentedFlow*) const;
103     bool matchedEndLine(LineLayoutState&, const InlineBidiResolver&, const InlineIterator& endLineStart, const BidiStatus& endLineStatus);
104     void deleteEllipsisLineBoxes();
105     void checkLinesForTextOverflow();
106     void updateFragmentForLine(RootInlineBox*) const;
107
108     const RenderStyle& style() const;
109     const FrameViewLayoutContext& layoutContext() const;
110
111     RenderBlockFlow& m_flow;
112     RenderLineBoxList m_lineBoxes;
113 };
114
115 };