| Differences between
and this patch
- a/Source/WebCore/ChangeLog +71 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2021-10-05  Antti Koivisto  <antti@apple.com>
2
3
        [LFC][Integration] Split BoxIterator into a base class and LeafBoxIterator
4
        https://bugs.webkit.org/show_bug.cgi?id=231229
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        LeafBoxIterator contains function for traversing non-inline boxes.
9
        BoxIterator becomes a non-instantiated base class.
10
11
        This is in preparation for adding InlineBoxIterator.
12
13
        * dom/Position.cpp:
14
        (WebCore::Position::inlineRunAndOffset const):
15
        * editing/InlineRunAndOffset.h:
16
        * editing/RenderedPosition.cpp:
17
        (WebCore::RenderedPosition::RenderedPosition):
18
        (WebCore::RenderedPosition::previousLeafOnLine const):
19
        (WebCore::RenderedPosition::nextLeafOnLine const):
20
        * editing/RenderedPosition.h:
21
        * editing/VisibleUnits.cpp:
22
        (WebCore::isTextOrLineBreakRun):
23
        (WebCore::previousTextOrLineBreakRun):
24
        (WebCore::nextTextOrLineBreakRun):
25
        (WebCore::startTextOrLineBreakRun):
26
        (WebCore::endTextOrLineBreakRun):
27
        (WebCore::logicallyPreviousRun):
28
        (WebCore::logicallyNextRun):
29
        (WebCore::visualWordPosition):
30
        * layout/integration/InlineIteratorBox.cpp:
31
        (WebCore::InlineIterator::Box::nextOnLine const):
32
        (WebCore::InlineIterator::Box::previousOnLine const):
33
        (WebCore::InlineIterator::Box::nextOnLineIgnoringLineBreak const):
34
        (WebCore::InlineIterator::Box::previousOnLineIgnoringLineBreak const):
35
        (WebCore::InlineIterator::LeafBoxIterator::LeafBoxIterator):
36
        (WebCore::InlineIterator::LeafBoxIterator::traverseNextOnLine):
37
        (WebCore::InlineIterator::LeafBoxIterator::traversePreviousOnLine):
38
        (WebCore::InlineIterator::LeafBoxIterator::traverseNextOnLineIgnoringLineBreak):
39
        (WebCore::InlineIterator::LeafBoxIterator::traversePreviousOnLineIgnoringLineBreak):
40
        (WebCore::InlineIterator::LeafBoxIterator::traverseNextOnLineInLogicalOrder):
41
        (WebCore::InlineIterator::LeafBoxIterator::traversePreviousOnLineInLogicalOrder):
42
        (WebCore::InlineIterator::boxFor):
43
        (WebCore::InlineIterator::BoxIterator::traverseNextOnLine): Deleted.
44
        (WebCore::InlineIterator::BoxIterator::traversePreviousOnLine): Deleted.
45
        (WebCore::InlineIterator::BoxIterator::traverseNextOnLineIgnoringLineBreak): Deleted.
46
        (WebCore::InlineIterator::BoxIterator::traversePreviousOnLineIgnoringLineBreak): Deleted.
47
        (WebCore::InlineIterator::BoxIterator::traverseNextOnLineInLogicalOrder): Deleted.
48
        (WebCore::InlineIterator::BoxIterator::traversePreviousOnLineInLogicalOrder): Deleted.
49
        * layout/integration/InlineIteratorBox.h:
50
        (WebCore::InlineIterator::BoxIterator::BoxIterator):
51
        * layout/integration/InlineIteratorLine.cpp:
52
        (WebCore::InlineIterator::Line::firstRun const):
53
        (WebCore::InlineIterator::Line::lastRun const):
54
        (WebCore::InlineIterator::Line::logicalStartRun const):
55
        (WebCore::InlineIterator::Line::logicalEndRun const):
56
        (WebCore::InlineIterator::Line::logicalStartRunWithNode const):
57
        (WebCore::InlineIterator::Line::logicalEndRunWithNode const):
58
        (WebCore::InlineIterator::Line::closestRunForPoint const):
59
        (WebCore::InlineIterator::Line::closestRunForLogicalLeftPosition const):
60
        (WebCore::InlineIterator::Line::firstSelectedBox const):
61
        (WebCore::InlineIterator::Line::lastSelectedBox const):
62
        * layout/integration/InlineIteratorLine.h:
63
        * layout/integration/InlineIteratorTextBox.cpp:
64
        (WebCore::InlineIterator::TextBoxIterator::TextBoxIterator):
65
        * layout/integration/InlineIteratorTextBox.h:
66
        * layout/integration/LayoutIntegrationLineLayout.cpp:
67
        (WebCore::LayoutIntegration::LineLayout::boxFor const):
68
        * layout/integration/LayoutIntegrationLineLayout.h:
69
        * rendering/RenderBlockFlow.cpp:
70
        (WebCore::RenderBlockFlow::positionForPointWithInlineChildren):
71
1
2021-10-04  Myles C. Maxfield  <mmaxfield@apple.com>
72
2021-10-04  Myles C. Maxfield  <mmaxfield@apple.com>
2
73
3
        Stop parsing context-sensitive colors in override-color
74
        Stop parsing context-sensitive colors in override-color
- a/Source/WebCore/dom/Position.cpp -1 / +1 lines
Lines 1210-1216 InlineRunAndOffset Position::inlineRunAndOffset(Affinity affinity, TextDirection a/Source/WebCore/dom/Position.cpp_sec1
1210
    if (!renderer)
1210
    if (!renderer)
1211
        return { { }, caretOffset };
1211
        return { { }, caretOffset };
1212
1212
1213
    InlineIterator::BoxIterator run;
1213
    InlineIterator::LeafBoxIterator run;
1214
1214
1215
    if (renderer->isBR()) {
1215
    if (renderer->isBR()) {
1216
        auto& lineBreakRenderer = downcast<RenderLineBreak>(*renderer);
1216
        auto& lineBreakRenderer = downcast<RenderLineBreak>(*renderer);
- a/Source/WebCore/editing/InlineRunAndOffset.h -1 / +1 lines
Lines 30-36 a/Source/WebCore/editing/InlineRunAndOffset.h_sec1
30
namespace WebCore {
30
namespace WebCore {
31
31
32
struct InlineRunAndOffset {
32
struct InlineRunAndOffset {
33
    InlineIterator::BoxIterator run { };
33
    InlineIterator::LeafBoxIterator run { };
34
    unsigned offset { 0 };
34
    unsigned offset { 0 };
35
};
35
};
36
36
- a/Source/WebCore/editing/RenderedPosition.cpp -3 / +3 lines
Lines 69-75 RenderedPosition::RenderedPosition() a/Source/WebCore/editing/RenderedPosition.cpp_sec1
69
{
69
{
70
}
70
}
71
71
72
RenderedPosition::RenderedPosition(const RenderObject* renderer, InlineIterator::BoxIterator run, unsigned offset)
72
RenderedPosition::RenderedPosition(const RenderObject* renderer, InlineIterator::LeafBoxIterator run, unsigned offset)
73
    : m_renderer(renderer)
73
    : m_renderer(renderer)
74
    , m_run(run)
74
    , m_run(run)
75
    , m_offset(offset)
75
    , m_offset(offset)
Lines 95-108 RenderedPosition::RenderedPosition(const Position& position, Affinity affinity) a/Source/WebCore/editing/RenderedPosition.cpp_sec2
95
        m_renderer = rendererFromPosition(position);
95
        m_renderer = rendererFromPosition(position);
96
}
96
}
97
97
98
InlineIterator::BoxIterator RenderedPosition::previousLeafOnLine() const
98
InlineIterator::LeafBoxIterator RenderedPosition::previousLeafOnLine() const
99
{
99
{
100
    if (!m_previousLeafOnLine)
100
    if (!m_previousLeafOnLine)
101
        m_previousLeafOnLine = m_run->previousOnLineIgnoringLineBreak();
101
        m_previousLeafOnLine = m_run->previousOnLineIgnoringLineBreak();
102
    return *m_previousLeafOnLine;
102
    return *m_previousLeafOnLine;
103
}
103
}
104
104
105
InlineIterator::BoxIterator RenderedPosition::nextLeafOnLine() const
105
InlineIterator::LeafBoxIterator RenderedPosition::nextLeafOnLine() const
106
{
106
{
107
    if (!m_nextLeafOnLine)
107
    if (!m_nextLeafOnLine)
108
        m_nextLeafOnLine = m_run->nextOnLineIgnoringLineBreak();
108
        m_nextLeafOnLine = m_run->nextOnLineIgnoringLineBreak();
- a/Source/WebCore/editing/RenderedPosition.h -6 / +6 lines
Lines 72-92 public: a/Source/WebCore/editing/RenderedPosition.h_sec1
72
72
73
private:
73
private:
74
    bool operator==(const RenderedPosition&) const { return false; }
74
    bool operator==(const RenderedPosition&) const { return false; }
75
    explicit RenderedPosition(const RenderObject*, InlineIterator::BoxIterator, unsigned offset);
75
    explicit RenderedPosition(const RenderObject*, InlineIterator::LeafBoxIterator, unsigned offset);
76
76
77
    InlineIterator::BoxIterator previousLeafOnLine() const;
77
    InlineIterator::LeafBoxIterator previousLeafOnLine() const;
78
    InlineIterator::BoxIterator nextLeafOnLine() const;
78
    InlineIterator::LeafBoxIterator nextLeafOnLine() const;
79
    bool atLeftmostOffsetInBox() const { return m_run && m_offset == m_run->leftmostCaretOffset(); }
79
    bool atLeftmostOffsetInBox() const { return m_run && m_offset == m_run->leftmostCaretOffset(); }
80
    bool atRightmostOffsetInBox() const { return m_run && m_offset == m_run->rightmostCaretOffset(); }
80
    bool atRightmostOffsetInBox() const { return m_run && m_offset == m_run->rightmostCaretOffset(); }
81
    bool atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel, unsigned char bidiLevelOfRun) const;
81
    bool atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel, unsigned char bidiLevelOfRun) const;
82
    bool atRightBoundaryOfBidiRun(ShouldMatchBidiLevel, unsigned char bidiLevelOfRun) const;
82
    bool atRightBoundaryOfBidiRun(ShouldMatchBidiLevel, unsigned char bidiLevelOfRun) const;
83
83
84
    const RenderObject* m_renderer { nullptr };
84
    const RenderObject* m_renderer { nullptr };
85
    InlineIterator::BoxIterator m_run;
85
    InlineIterator::LeafBoxIterator m_run;
86
    unsigned m_offset { 0 };
86
    unsigned m_offset { 0 };
87
87
88
    mutable std::optional<InlineIterator::BoxIterator> m_previousLeafOnLine;
88
    mutable std::optional<InlineIterator::LeafBoxIterator> m_previousLeafOnLine;
89
    mutable std::optional<InlineIterator::BoxIterator> m_nextLeafOnLine;
89
    mutable std::optional<InlineIterator::LeafBoxIterator> m_nextLeafOnLine;
90
};
90
};
91
91
92
bool renderObjectContainsPosition(const RenderObject*, const Position&);
92
bool renderObjectContainsPosition(const RenderObject*, const Position&);
- a/Source/WebCore/editing/VisibleUnits.cpp -8 / +8 lines
Lines 124-135 static Position nextLineCandidatePosition(Node* node, const VisiblePosition& vis a/Source/WebCore/editing/VisibleUnits.cpp_sec1
124
    return Position();
124
    return Position();
125
}
125
}
126
126
127
static bool isTextOrLineBreakRun(InlineIterator::BoxIterator run)
127
static bool isTextOrLineBreakRun(InlineIterator::LeafBoxIterator run)
128
{
128
{
129
    return run && (run->isText() || run->renderer().isBR());
129
    return run && (run->isText() || run->renderer().isBR());
130
}
130
}
131
131
132
static InlineIterator::BoxIterator previousTextOrLineBreakRun(InlineIterator::BoxIterator run)
132
static InlineIterator::LeafBoxIterator previousTextOrLineBreakRun(InlineIterator::LeafBoxIterator run)
133
{
133
{
134
    while (run) {
134
    while (run) {
135
        run.traversePreviousOnLineInLogicalOrder();
135
        run.traversePreviousOnLineInLogicalOrder();
Lines 139-145 static InlineIterator::BoxIterator previousTextOrLineBreakRun(InlineIterator::Bo a/Source/WebCore/editing/VisibleUnits.cpp_sec2
139
    return { };
139
    return { };
140
}
140
}
141
141
142
static InlineIterator::BoxIterator nextTextOrLineBreakRun(InlineIterator::BoxIterator run)
142
static InlineIterator::LeafBoxIterator nextTextOrLineBreakRun(InlineIterator::LeafBoxIterator run)
143
{
143
{
144
    while (run) {
144
    while (run) {
145
        run.traverseNextOnLineInLogicalOrder();
145
        run.traverseNextOnLineInLogicalOrder();
Lines 149-155 static InlineIterator::BoxIterator nextTextOrLineBreakRun(InlineIterator::BoxIte a/Source/WebCore/editing/VisibleUnits.cpp_sec3
149
    return { };
149
    return { };
150
}
150
}
151
151
152
static InlineIterator::BoxIterator startTextOrLineBreakRun(InlineIterator::LineIterator line)
152
static InlineIterator::LeafBoxIterator startTextOrLineBreakRun(InlineIterator::LineIterator line)
153
{
153
{
154
    auto run = line->logicalStartRun();
154
    auto run = line->logicalStartRun();
155
    if (isTextOrLineBreakRun(run))
155
    if (isTextOrLineBreakRun(run))
Lines 157-163 static InlineIterator::BoxIterator startTextOrLineBreakRun(InlineIterator::LineI a/Source/WebCore/editing/VisibleUnits.cpp_sec4
157
    return nextTextOrLineBreakRun(run);
157
    return nextTextOrLineBreakRun(run);
158
}
158
}
159
159
160
static InlineIterator::BoxIterator endTextOrLineBreakRun(InlineIterator::LineIterator line)
160
static InlineIterator::LeafBoxIterator endTextOrLineBreakRun(InlineIterator::LineIterator line)
161
{
161
{
162
    auto run = line->logicalEndRun();
162
    auto run = line->logicalEndRun();
163
    if (isTextOrLineBreakRun(run))
163
    if (isTextOrLineBreakRun(run))
Lines 165-171 static InlineIterator::BoxIterator endTextOrLineBreakRun(InlineIterator::LineIte a/Source/WebCore/editing/VisibleUnits.cpp_sec5
165
    return previousTextOrLineBreakRun(run);
165
    return previousTextOrLineBreakRun(run);
166
}
166
}
167
167
168
static const InlineIterator::BoxIterator logicallyPreviousRun(const VisiblePosition& visiblePosition, InlineIterator::BoxIterator startRun, bool& previousBoxInDifferentLine)
168
static const InlineIterator::LeafBoxIterator logicallyPreviousRun(const VisiblePosition& visiblePosition, InlineIterator::LeafBoxIterator startRun, bool& previousBoxInDifferentLine)
169
{
169
{
170
    if (auto previousRun = previousTextOrLineBreakRun(startRun))
170
    if (auto previousRun = previousTextOrLineBreakRun(startRun))
171
        return previousRun;
171
        return previousRun;
Lines 203-209 static const InlineIterator::BoxIterator logicallyPreviousRun(const VisiblePosit a/Source/WebCore/editing/VisibleUnits.cpp_sec6
203
}
203
}
204
204
205
205
206
static const InlineIterator::BoxIterator logicallyNextRun(const VisiblePosition& visiblePosition, InlineIterator::BoxIterator startRun, bool& nextBoxInDifferentLine)
206
static const InlineIterator::LeafBoxIterator logicallyNextRun(const VisiblePosition& visiblePosition, InlineIterator::LeafBoxIterator startRun, bool& nextBoxInDifferentLine)
207
{
207
{
208
    if (auto nextRun = nextTextOrLineBreakRun(startRun))
208
    if (auto nextRun = nextTextOrLineBreakRun(startRun))
209
        return nextRun;
209
        return nextRun;
Lines 315-321 static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition a/Source/WebCore/editing/VisibleUnits.cpp_sec7
315
    visiblePosition.deepEquivalent().document()->updateLayoutIgnorePendingStylesheets();
315
    visiblePosition.deepEquivalent().document()->updateLayoutIgnorePendingStylesheets();
316
316
317
    TextDirection blockDirection = directionOfEnclosingBlock(visiblePosition.deepEquivalent());
317
    TextDirection blockDirection = directionOfEnclosingBlock(visiblePosition.deepEquivalent());
318
    InlineIterator::BoxIterator previouslyVisitedRun;
318
    InlineIterator::LeafBoxIterator previouslyVisitedRun;
319
    VisiblePosition current = visiblePosition;
319
    VisiblePosition current = visiblePosition;
320
    std::optional<VisiblePosition> previousPosition;
320
    std::optional<VisiblePosition> previousPosition;
321
    UBreakIterator* iter = nullptr;
321
    UBreakIterator* iter = nullptr;
- a/Source/WebCore/layout/integration/InlineIteratorBox.cpp -17 / +27 lines
Lines 58-81 bool BoxIterator::atEnd() const a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec1
58
    });
58
    });
59
}
59
}
60
60
61
BoxIterator Box::nextOnLine() const
61
LeafBoxIterator Box::nextOnLine() const
62
{
62
{
63
    return BoxIterator(*this).traverseNextOnLine();
63
    return LeafBoxIterator(*this).traverseNextOnLine();
64
}
64
}
65
65
66
BoxIterator Box::previousOnLine() const
66
LeafBoxIterator Box::previousOnLine() const
67
{
67
{
68
    return BoxIterator(*this).traversePreviousOnLine();
68
    return LeafBoxIterator(*this).traversePreviousOnLine();
69
}
69
}
70
70
71
BoxIterator Box::nextOnLineIgnoringLineBreak() const
71
LeafBoxIterator Box::nextOnLineIgnoringLineBreak() const
72
{
72
{
73
    return BoxIterator(*this).traverseNextOnLineIgnoringLineBreak();
73
    return LeafBoxIterator(*this).traverseNextOnLineIgnoringLineBreak();
74
}
74
}
75
75
76
BoxIterator Box::previousOnLineIgnoringLineBreak() const
76
LeafBoxIterator Box::previousOnLineIgnoringLineBreak() const
77
{
77
{
78
    return BoxIterator(*this).traversePreviousOnLineIgnoringLineBreak();
78
    return LeafBoxIterator(*this).traversePreviousOnLineIgnoringLineBreak();
79
}
79
}
80
80
81
LineIterator Box::line() const
81
LineIterator Box::line() const
Lines 106-112 RenderObject::HighlightState Box::selectionState() const a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec2
106
    return renderer().selectionState();
106
    return renderer().selectionState();
107
}
107
}
108
108
109
BoxIterator& BoxIterator::traverseNextOnLine()
109
LeafBoxIterator::LeafBoxIterator(Box::PathVariant&& pathVariant)
110
    : BoxIterator(WTFMove(pathVariant))
111
{
112
}
113
114
LeafBoxIterator::LeafBoxIterator(const Box& run)
115
    : BoxIterator(run)
116
{
117
}
118
119
LeafBoxIterator& LeafBoxIterator::traverseNextOnLine()
110
{
120
{
111
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
121
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
112
        path.traverseNextOnLine();
122
        path.traverseNextOnLine();
Lines 114-120 BoxIterator& BoxIterator::traverseNextOnLine() a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec3
114
    return *this;
124
    return *this;
115
}
125
}
116
126
117
BoxIterator& BoxIterator::traversePreviousOnLine()
127
LeafBoxIterator& LeafBoxIterator::traversePreviousOnLine()
118
{
128
{
119
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
129
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
120
        path.traversePreviousOnLine();
130
        path.traversePreviousOnLine();
Lines 122-128 BoxIterator& BoxIterator::traversePreviousOnLine() a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec4
122
    return *this;
132
    return *this;
123
}
133
}
124
134
125
BoxIterator& BoxIterator::traverseNextOnLineIgnoringLineBreak()
135
LeafBoxIterator& LeafBoxIterator::traverseNextOnLineIgnoringLineBreak()
126
{
136
{
127
    do {
137
    do {
128
        traverseNextOnLine();
138
        traverseNextOnLine();
Lines 130-136 BoxIterator& BoxIterator::traverseNextOnLineIgnoringLineBreak() a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec5
130
    return *this;
140
    return *this;
131
}
141
}
132
142
133
BoxIterator& BoxIterator::traversePreviousOnLineIgnoringLineBreak()
143
LeafBoxIterator& LeafBoxIterator::traversePreviousOnLineIgnoringLineBreak()
134
{
144
{
135
    do {
145
    do {
136
        traversePreviousOnLine();
146
        traversePreviousOnLine();
Lines 138-144 BoxIterator& BoxIterator::traversePreviousOnLineIgnoringLineBreak() a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec6
138
    return *this;
148
    return *this;
139
}
149
}
140
150
141
BoxIterator& BoxIterator::traverseNextOnLineInLogicalOrder()
151
LeafBoxIterator& LeafBoxIterator::traverseNextOnLineInLogicalOrder()
142
{
152
{
143
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
153
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
144
        path.traverseNextOnLineInLogicalOrder();
154
        path.traverseNextOnLineInLogicalOrder();
Lines 146-152 BoxIterator& BoxIterator::traverseNextOnLineInLogicalOrder() a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec7
146
    return *this;
156
    return *this;
147
}
157
}
148
158
149
BoxIterator& BoxIterator::traversePreviousOnLineInLogicalOrder()
159
LeafBoxIterator& LeafBoxIterator::traversePreviousOnLineInLogicalOrder()
150
{
160
{
151
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
161
    WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
152
        path.traversePreviousOnLineInLogicalOrder();
162
        path.traversePreviousOnLineInLogicalOrder();
Lines 154-160 BoxIterator& BoxIterator::traversePreviousOnLineInLogicalOrder() a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec8
154
    return *this;
164
    return *this;
155
}
165
}
156
166
157
BoxIterator boxFor(const RenderLineBreak& renderer)
167
LeafBoxIterator boxFor(const RenderLineBreak& renderer)
158
{
168
{
159
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
169
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
160
    if (auto* lineLayout = LayoutIntegration::LineLayout::containing(renderer))
170
    if (auto* lineLayout = LayoutIntegration::LineLayout::containing(renderer))
Lines 163-169 BoxIterator boxFor(const RenderLineBreak& renderer) a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec9
163
    return { BoxLegacyPath(renderer.inlineBoxWrapper()) };
173
    return { BoxLegacyPath(renderer.inlineBoxWrapper()) };
164
}
174
}
165
175
166
BoxIterator boxFor(const RenderBox& renderer)
176
LeafBoxIterator boxFor(const RenderBox& renderer)
167
{
177
{
168
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
178
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
169
    if (auto* lineLayout = LayoutIntegration::LineLayout::containing(renderer))
179
    if (auto* lineLayout = LayoutIntegration::LineLayout::containing(renderer))
Lines 173-179 BoxIterator boxFor(const RenderBox& renderer) a/Source/WebCore/layout/integration/InlineIteratorBox.cpp_sec10
173
}
183
}
174
184
175
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
185
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
176
BoxIterator boxFor(const LayoutIntegration::InlineContent& content, size_t boxIndex)
186
LeafBoxIterator boxFor(const LayoutIntegration::InlineContent& content, size_t boxIndex)
177
{
187
{
178
    return { BoxModernPath { content, boxIndex } };
188
    return { BoxModernPath { content, boxIndex } };
179
}
189
}
- a/Source/WebCore/layout/integration/InlineIteratorBox.h -18 / +27 lines
Lines 40-45 namespace InlineIterator { a/Source/WebCore/layout/integration/InlineIteratorBox.h_sec1
40
40
41
class LineIterator;
41
class LineIterator;
42
class BoxIterator;
42
class BoxIterator;
43
class LeafBoxIterator;
43
class TextBoxIterator;
44
class TextBoxIterator;
44
45
45
struct EndIterator { };
46
struct EndIterator { };
Lines 90-104 public: a/Source/WebCore/layout/integration/InlineIteratorBox.h_sec2
90
    const InlineDisplay::Box* inlineBox() const;
91
    const InlineDisplay::Box* inlineBox() const;
91
#endif
92
#endif
92
93
93
    BoxIterator nextOnLine() const;
94
    LeafBoxIterator nextOnLine() const;
94
    BoxIterator previousOnLine() const;
95
    LeafBoxIterator previousOnLine() const;
95
    BoxIterator nextOnLineIgnoringLineBreak() const;
96
    LeafBoxIterator nextOnLineIgnoringLineBreak() const;
96
    BoxIterator previousOnLineIgnoringLineBreak() const;
97
    LeafBoxIterator previousOnLineIgnoringLineBreak() const;
97
98
98
    LineIterator line() const;
99
    LineIterator line() const;
99
100
100
protected:
101
protected:
101
    friend class BoxIterator;
102
    friend class BoxIterator;
103
    friend class LeafBoxIterator;
102
    friend class TextBoxIterator;
104
    friend class TextBoxIterator;
103
105
104
    // To help with debugging.
106
    // To help with debugging.
Lines 112-121 protected: a/Source/WebCore/layout/integration/InlineIteratorBox.h_sec3
112
114
113
class BoxIterator {
115
class BoxIterator {
114
public:
116
public:
115
    BoxIterator() : m_box(BoxLegacyPath { nullptr, { } }) { };
116
    BoxIterator(Box::PathVariant&&);
117
    BoxIterator(const Box&);
118
119
    explicit operator bool() const { return !atEnd(); }
117
    explicit operator bool() const { return !atEnd(); }
120
118
121
    bool operator==(const BoxIterator&) const;
119
    bool operator==(const BoxIterator&) const;
Lines 129-149 public: a/Source/WebCore/layout/integration/InlineIteratorBox.h_sec4
129
127
130
    bool atEnd() const;
128
    bool atEnd() const;
131
129
132
    BoxIterator& traverseNextOnLine();
133
    BoxIterator& traversePreviousOnLine();
134
    BoxIterator& traverseNextOnLineIgnoringLineBreak();
135
    BoxIterator& traversePreviousOnLineIgnoringLineBreak();
136
    BoxIterator& traverseNextOnLineInLogicalOrder();
137
    BoxIterator& traversePreviousOnLineInLogicalOrder();
138
139
protected:
130
protected:
131
    BoxIterator() : m_box(BoxLegacyPath { nullptr, { } }) { };
132
    BoxIterator(Box::PathVariant&&);
133
    BoxIterator(const Box&);
134
140
    Box m_box;
135
    Box m_box;
141
};
136
};
142
137
143
BoxIterator boxFor(const RenderLineBreak&);
138
class LeafBoxIterator : public BoxIterator {
144
BoxIterator boxFor(const RenderBox&);
139
public:
140
    LeafBoxIterator() = default;
141
    LeafBoxIterator(Box::PathVariant&&);
142
    LeafBoxIterator(const Box&);
143
144
    LeafBoxIterator& traverseNextOnLine();
145
    LeafBoxIterator& traversePreviousOnLine();
146
    LeafBoxIterator& traverseNextOnLineIgnoringLineBreak();
147
    LeafBoxIterator& traversePreviousOnLineIgnoringLineBreak();
148
    LeafBoxIterator& traverseNextOnLineInLogicalOrder();
149
    LeafBoxIterator& traversePreviousOnLineInLogicalOrder();
150
};
151
152
LeafBoxIterator boxFor(const RenderLineBreak&);
153
LeafBoxIterator boxFor(const RenderBox&);
145
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
154
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
146
BoxIterator boxFor(const LayoutIntegration::InlineContent&, size_t boxIndex);
155
LeafBoxIterator boxFor(const LayoutIntegration::InlineContent&, size_t boxIndex);
147
#endif
156
#endif
148
157
149
// -----------------------------------------------
158
// -----------------------------------------------
- a/Source/WebCore/layout/integration/InlineIteratorInlineBox.h +86 lines
Line 0 a/Source/WebCore/layout/integration/InlineIteratorInlineBox.h_sec1
1
/*
2
 * Copyright (C) 2021 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 "InlineIteratorBox.h"
29
#include "LegacyInlineFlowBox.h"
30
31
namespace WebCore {
32
33
namespace InlineIterator {
34
35
class InlineBoxIterator;
36
37
class InlineBox : public Box {
38
public:
39
    InlineBox(PathVariant&&);
40
41
    const RenderBoxModelObject& renderer() const { return downcast<RenderBoxModelObject>(Box::renderer()); }
42
43
    // FIXME: Remove. For intermediate porting steps only.
44
    const LegacyInlineFlowBox* legacyInlineBox() const { return downcast<LegacyInlineFlowBox>(Box::legacyInlineBox()); }
45
46
    InlineBoxIterator nextInlineBox() const;
47
    InlineBoxIterator previousInlineBox() const;
48
    InlineBoxIterator iterator() const;
49
};
50
51
class InlineBoxIterator : public BoxIterator {
52
public:
53
    InlineBoxIterator() { }
54
    InlineBoxIterator(Box::PathVariant&&);
55
    InlineBoxIterator(const Box&);
56
57
    const InlineBox& operator*() const { return get(); }
58
    const InlineBox* operator->() const { return &get(); }
59
60
    InlineBoxIterator& traverseNextInlineBox();
61
    InlineBoxIterator& traversePreviousInlineBox();
62
63
private:
64
    const InlineBox& get() const { return downcast<InlineBox>(m_box); }
65
};
66
67
InlineBoxIterator inlineBoxFor(const LegacyInlineFlowBox&);
68
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
69
InlineBoxIterator inlineBoxFor(const LayoutIntegration::InlineContent&, size_t boxIndex);
70
#endif
71
72
inline InlineBoxIterator InlineBox::iterator() const
73
{
74
    return { *this };
75
}
76
77
}
78
}
79
80
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::InlineIterator::InlineBox)
81
static bool isType(const WebCore::InlineIterator::Box& box) { return box.isInlineBox(); }
82
SPECIALIZE_TYPE_TRAITS_END()
83
84
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::InlineIterator::InlineBoxIterator)
85
static bool isType(const WebCore::InlineIterator::BoxIterator& box) { return !box || box->isInlineBox(); }
86
SPECIALIZE_TYPE_TRAITS_END()
- a/Source/WebCore/layout/integration/InlineIteratorLine.cpp -14 / +14 lines
Lines 101-135 LineIterator Line::previous() const a/Source/WebCore/layout/integration/InlineIteratorLine.cpp_sec1
101
    return LineIterator(*this).traversePrevious();
101
    return LineIterator(*this).traversePrevious();
102
}
102
}
103
103
104
BoxIterator Line::firstRun() const
104
LeafBoxIterator Line::firstRun() const
105
{
105
{
106
    return WTF::switchOn(m_pathVariant, [](auto& path) -> BoxIterator {
106
    return WTF::switchOn(m_pathVariant, [](auto& path) -> LeafBoxIterator {
107
        return { path.firstRun() };
107
        return { path.firstRun() };
108
    });
108
    });
109
}
109
}
110
110
111
BoxIterator Line::lastRun() const
111
LeafBoxIterator Line::lastRun() const
112
{
112
{
113
    return WTF::switchOn(m_pathVariant, [](auto& path) -> BoxIterator {
113
    return WTF::switchOn(m_pathVariant, [](auto& path) -> LeafBoxIterator {
114
        return { path.lastRun() };
114
        return { path.lastRun() };
115
    });
115
    });
116
}
116
}
117
117
118
BoxIterator Line::logicalStartRun() const
118
LeafBoxIterator Line::logicalStartRun() const
119
{
119
{
120
    return WTF::switchOn(m_pathVariant, [](auto& path) -> BoxIterator {
120
    return WTF::switchOn(m_pathVariant, [](auto& path) -> LeafBoxIterator {
121
        return { path.logicalStartRun() };
121
        return { path.logicalStartRun() };
122
    });
122
    });
123
}
123
}
124
124
125
BoxIterator Line::logicalEndRun() const
125
LeafBoxIterator Line::logicalEndRun() const
126
{
126
{
127
    return WTF::switchOn(m_pathVariant, [](auto& path) -> BoxIterator {
127
    return WTF::switchOn(m_pathVariant, [](auto& path) -> LeafBoxIterator {
128
        return { path.logicalEndRun() };
128
        return { path.logicalEndRun() };
129
    });
129
    });
130
}
130
}
131
131
132
BoxIterator Line::logicalStartRunWithNode() const
132
LeafBoxIterator Line::logicalStartRunWithNode() const
133
{
133
{
134
    for (auto run = logicalStartRun(); run; run.traverseNextOnLineInLogicalOrder()) {
134
    for (auto run = logicalStartRun(); run; run.traverseNextOnLineInLogicalOrder()) {
135
        if (run->renderer().node())
135
        if (run->renderer().node())
Lines 138-144 BoxIterator Line::logicalStartRunWithNode() const a/Source/WebCore/layout/integration/InlineIteratorLine.cpp_sec2
138
    return { };
138
    return { };
139
}
139
}
140
140
141
BoxIterator Line::logicalEndRunWithNode() const
141
LeafBoxIterator Line::logicalEndRunWithNode() const
142
{
142
{
143
    for (auto run = logicalEndRun(); run; run.traversePreviousOnLineInLogicalOrder()) {
143
    for (auto run = logicalEndRun(); run; run.traversePreviousOnLineInLogicalOrder()) {
144
        if (run->renderer().node())
144
        if (run->renderer().node())
Lines 147-158 BoxIterator Line::logicalEndRunWithNode() const a/Source/WebCore/layout/integration/InlineIteratorLine.cpp_sec3
147
    return { };
147
    return { };
148
}
148
}
149
149
150
BoxIterator Line::closestRunForPoint(const IntPoint& pointInContents, bool editableOnly) const
150
LeafBoxIterator Line::closestRunForPoint(const IntPoint& pointInContents, bool editableOnly) const
151
{
151
{
152
    return closestRunForLogicalLeftPosition(isHorizontal() ? pointInContents.x() : pointInContents.y(), editableOnly);
152
    return closestRunForLogicalLeftPosition(isHorizontal() ? pointInContents.x() : pointInContents.y(), editableOnly);
153
}
153
}
154
154
155
BoxIterator Line::closestRunForLogicalLeftPosition(int leftPosition, bool editableOnly) const
155
LeafBoxIterator Line::closestRunForLogicalLeftPosition(int leftPosition, bool editableOnly) const
156
{
156
{
157
    auto isEditable = [&](auto run) {
157
    auto isEditable = [&](auto run) {
158
        return run && run->renderer().node() && run->renderer().node()->hasEditableStyle();
158
        return run && run->renderer().node() && run->renderer().node()->hasEditableStyle();
Lines 229-235 RenderObject::HighlightState Line::selectionState() const a/Source/WebCore/layout/integration/InlineIteratorLine.cpp_sec4
229
    return state;
229
    return state;
230
}
230
}
231
231
232
BoxIterator Line::firstSelectedBox() const
232
LeafBoxIterator Line::firstSelectedBox() const
233
{
233
{
234
    for (auto box = firstRun(); box; box.traverseNextOnLine()) {
234
    for (auto box = firstRun(); box; box.traverseNextOnLine()) {
235
        if (box->selectionState() != RenderObject::HighlightState::None)
235
        if (box->selectionState() != RenderObject::HighlightState::None)
Lines 238-244 BoxIterator Line::firstSelectedBox() const a/Source/WebCore/layout/integration/InlineIteratorLine.cpp_sec5
238
    return { };
238
    return { };
239
}
239
}
240
240
241
BoxIterator Line::lastSelectedBox() const
241
LeafBoxIterator Line::lastSelectedBox() const
242
{
242
{
243
    for (auto box = lastRun(); box; box.traversePreviousOnLine()) {
243
    for (auto box = lastRun(); box; box.traversePreviousOnLine()) {
244
        if (box->selectionState() != RenderObject::HighlightState::None)
244
        if (box->selectionState() != RenderObject::HighlightState::None)
- a/Source/WebCore/layout/integration/InlineIteratorLine.h -11 / +11 lines
Lines 35-41 namespace InlineIterator { a/Source/WebCore/layout/integration/InlineIteratorLine.h_sec1
35
35
36
class LineIterator;
36
class LineIterator;
37
class PathIterator;
37
class PathIterator;
38
class BoxIterator;
38
class LeafBoxIterator;
39
39
40
struct EndLineIterator { };
40
struct EndLineIterator { };
41
41
Lines 81-102 public: a/Source/WebCore/layout/integration/InlineIteratorLine.h_sec2
81
81
82
    bool isFirst() const;
82
    bool isFirst() const;
83
83
84
    BoxIterator firstRun() const;
84
    LeafBoxIterator firstRun() const;
85
    BoxIterator lastRun() const;
85
    LeafBoxIterator lastRun() const;
86
86
87
    LineIterator next() const;
87
    LineIterator next() const;
88
    LineIterator previous() const;
88
    LineIterator previous() const;
89
89
90
    BoxIterator closestRunForPoint(const IntPoint& pointInContents, bool editableOnly) const;
90
    LeafBoxIterator closestRunForPoint(const IntPoint& pointInContents, bool editableOnly) const;
91
    BoxIterator closestRunForLogicalLeftPosition(int position, bool editableOnly = false) const;
91
    LeafBoxIterator closestRunForLogicalLeftPosition(int position, bool editableOnly = false) const;
92
92
93
    BoxIterator logicalStartRun() const;
93
    LeafBoxIterator logicalStartRun() const;
94
    BoxIterator logicalEndRun() const;
94
    LeafBoxIterator logicalEndRun() const;
95
    BoxIterator logicalStartRunWithNode() const;
95
    LeafBoxIterator logicalStartRunWithNode() const;
96
    BoxIterator logicalEndRunWithNode() const;
96
    LeafBoxIterator logicalEndRunWithNode() const;
97
    
97
    
98
    BoxIterator firstSelectedBox() const;
98
    LeafBoxIterator firstSelectedBox() const;
99
    BoxIterator lastSelectedBox() const;
99
    LeafBoxIterator lastSelectedBox() const;
100
100
101
private:
101
private:
102
    friend class LineIterator;
102
    friend class LineIterator;
- a/Source/WebCore/layout/integration/InlineIteratorTextBox.cpp -2 / +2 lines
Lines 77-88 const FontCascade& TextBox::fontCascade() const a/Source/WebCore/layout/integration/InlineIteratorTextBox.cpp_sec1
77
}
77
}
78
78
79
TextBoxIterator::TextBoxIterator(Box::PathVariant&& pathVariant)
79
TextBoxIterator::TextBoxIterator(Box::PathVariant&& pathVariant)
80
    : BoxIterator(WTFMove(pathVariant))
80
    : LeafBoxIterator(WTFMove(pathVariant))
81
{
81
{
82
}
82
}
83
83
84
TextBoxIterator::TextBoxIterator(const Box& box)
84
TextBoxIterator::TextBoxIterator(const Box& box)
85
    : BoxIterator(box)
85
    : LeafBoxIterator(box)
86
{
86
{
87
}
87
}
88
88
- a/Source/WebCore/layout/integration/InlineIteratorTextBox.h -1 / +1 lines
Lines 63-69 public: a/Source/WebCore/layout/integration/InlineIteratorTextBox.h_sec1
63
    TextBoxIterator nextTextBoxInTextOrder() const;
63
    TextBoxIterator nextTextBoxInTextOrder() const;
64
};
64
};
65
65
66
class TextBoxIterator : public BoxIterator {
66
class TextBoxIterator : public LeafBoxIterator {
67
public:
67
public:
68
    TextBoxIterator() { }
68
    TextBoxIterator() { }
69
    TextBoxIterator(Box::PathVariant&&);
69
    TextBoxIterator(Box::PathVariant&&);
- a/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp -1 / +1 lines
Lines 404-410 InlineIterator::TextBoxIterator LineLayout::textBoxesFor(const RenderText& rende a/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp_sec1
404
    return InlineIterator::textBoxFor(*m_inlineContent, *firstIndex);
404
    return InlineIterator::textBoxFor(*m_inlineContent, *firstIndex);
405
}
405
}
406
406
407
InlineIterator::BoxIterator LineLayout::boxFor(const RenderElement& renderElement) const
407
InlineIterator::LeafBoxIterator LineLayout::boxFor(const RenderElement& renderElement) const
408
{
408
{
409
    if (!m_inlineContent)
409
    if (!m_inlineContent)
410
        return { };
410
        return { };
- a/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h -1 / +1 lines
Lines 97-103 public: a/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.h_sec1
97
    bool hitTest(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint& accumulatedOffset, HitTestAction);
97
    bool hitTest(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint& accumulatedOffset, HitTestAction);
98
98
99
    InlineIterator::TextBoxIterator textBoxesFor(const RenderText&) const;
99
    InlineIterator::TextBoxIterator textBoxesFor(const RenderText&) const;
100
    InlineIterator::BoxIterator boxFor(const RenderElement&) const;
100
    InlineIterator::LeafBoxIterator boxFor(const RenderElement&) const;
101
    InlineIterator::LineIterator firstLine() const;
101
    InlineIterator::LineIterator firstLine() const;
102
    InlineIterator::LineIterator lastLine() const;
102
    InlineIterator::LineIterator lastLine() const;
103
103
- a/Source/WebCore/rendering/RenderBlockFlow.cpp -1 / +1 lines
Lines 3550-3556 VisiblePosition RenderBlockFlow::positionForPointWithInlineChildren(const Layout a/Source/WebCore/rendering/RenderBlockFlow.cpp_sec1
3550
    bool blocksAreFlipped = style().isFlippedBlocksWritingMode();
3550
    bool blocksAreFlipped = style().isFlippedBlocksWritingMode();
3551
3551
3552
    // look for the closest line box in the root box which is at the passed-in y coordinate
3552
    // look for the closest line box in the root box which is at the passed-in y coordinate
3553
    InlineIterator::BoxIterator closestRun;
3553
    InlineIterator::LeafBoxIterator closestRun;
3554
    InlineIterator::LineIterator firstLineWithChildren;
3554
    InlineIterator::LineIterator firstLineWithChildren;
3555
    InlineIterator::LineIterator lastLineWithChildren;
3555
    InlineIterator::LineIterator lastLineWithChildren;
3556
    for (auto line = firstLine; line; line.traverseNext()) {
3556
    for (auto line = firstLine; line; line.traverseNext()) {

Return to Bug 231229