@@ -59,115 +59,121 @@ InlineContentBuilder::InlineContentBuilder(const RenderBlockFlow& blockFlow, Box
59
59
60
60
FloatRect InlineContentBuilder::build (Layout::InlineLayoutResult&& layoutResult, InlineContent& inlineContent, const Layout::InlineDamage* lineDamage) const
61
61
{
62
- auto firstDamagedLineIndex = [&]() -> std::optional<size_t > {
63
- auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
64
- if (!lineDamage || !lineDamage->start () || !displayContentFromPreviousLayout.lines .size ())
65
- return { };
66
- auto canidateLineIndex = lineDamage->start ()->lineIndex ;
67
- if (canidateLineIndex >= displayContentFromPreviousLayout.lines .size ()) {
68
- ASSERT_NOT_REACHED ();
69
- return { };
70
- }
71
- return { canidateLineIndex };
72
- }();
62
+ inlineContent.releaseCaches ();
63
+ computeIsFirstIsLastBoxAndBidiReorderingForInlineContent (layoutResult.displayContent .boxes );
73
64
74
- auto firstDamagedBoxIndex = [&]() -> std::optional<size_t > {
75
- auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
76
- return firstDamagedLineIndex ? std::make_optional (displayContentFromPreviousLayout.lines [*firstDamagedLineIndex].firstBoxIndex ()) : std::nullopt;
77
- }();
65
+ if (layoutResult.range == Layout::InlineLayoutResult::Range::Full) {
66
+ auto damagedRect = FloatRect { };
78
67
79
- auto numberOfDamagedLines = [&]() -> std::optional<size_t > {
80
- if (!firstDamagedLineIndex)
81
- return { };
82
- auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
83
- ASSERT (layoutResult.range != Layout::InlineLayoutResult::Range::Full);
84
- auto canidateLineCount = layoutResult.range == Layout::InlineLayoutResult::Range::FullFromDamage
85
- ? displayContentFromPreviousLayout.lines .size () - *firstDamagedLineIndex
86
- : layoutResult.displayContent .lines .size ();
68
+ for (auto & line : inlineContent.displayContent ().lines )
69
+ damagedRect.unite (line.inkOverflow ());
87
70
88
- if (*firstDamagedLineIndex + canidateLineCount > displayContentFromPreviousLayout.lines .size ()) {
89
- ASSERT_NOT_REACHED ();
90
- return { };
91
- }
92
- return { canidateLineCount };
93
- }();
94
-
95
- auto numberOfDamagedBoxes = [&]() -> std::optional<size_t > {
96
- if (!firstDamagedLineIndex || !numberOfDamagedLines || !firstDamagedBoxIndex)
97
- return { };
98
- auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
99
- ASSERT (*firstDamagedLineIndex + *numberOfDamagedLines <= displayContentFromPreviousLayout.lines .size ());
100
- size_t boxCount = 0 ;
101
- for (size_t i = 0 ; i < *numberOfDamagedLines; ++i)
102
- boxCount += displayContentFromPreviousLayout.lines [*firstDamagedLineIndex + i].boxCount ();
103
- ASSERT (boxCount);
104
- return { boxCount };
105
- }();
106
- auto numberOfNewLines = layoutResult.displayContent .lines .size ();
107
- auto numberOfNewBoxes = layoutResult.displayContent .boxes .size ();
108
-
109
- auto damagedRect = FloatRect { };
110
- auto adjustDamagedRectWithLineRange = [&](size_t firstLineIndex, size_t lineCount, auto & lines) {
111
- ASSERT (firstLineIndex + lineCount <= lines.size ());
112
- for (size_t i = 0 ; i < lineCount; ++i)
113
- damagedRect.unite (lines[firstLineIndex + i].inkOverflow ());
114
- };
71
+ inlineContent.displayContent ().set (WTFMove (layoutResult.displayContent ));
72
+ adjustDisplayLines (inlineContent, 0 );
115
73
116
- // Repaint the damaged content boundary.
117
- adjustDamagedRectWithLineRange (firstDamagedLineIndex.value_or (0 ), numberOfDamagedLines.value_or (inlineContent.displayContent ().lines .size ()), inlineContent.displayContent ().lines );
74
+ for (auto & line : inlineContent.displayContent ().lines )
75
+ damagedRect.unite (line.inkOverflow ());
76
+ return damagedRect;
77
+ }
118
78
119
- inlineContent. releaseCaches ();
79
+ auto handlePartialDisplayContentUpdate = [&]() -> FloatRect {
120
80
121
- computeIsFirstIsLastBoxAndBidiReorderingForInlineContent (layoutResult.displayContent .boxes );
81
+ auto firstDamagedLineIndex = [&]() -> std::optional<size_t > {
82
+ auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
83
+ if (!lineDamage || !lineDamage->start () || !displayContentFromPreviousLayout.lines .size ())
84
+ return { };
85
+ auto canidateLineIndex = lineDamage->start ()->lineIndex ;
86
+ if (canidateLineIndex >= displayContentFromPreviousLayout.lines .size ()) {
87
+ ASSERT_NOT_REACHED ();
88
+ return { };
89
+ }
90
+ return { canidateLineIndex };
91
+ }();
92
+
93
+ auto firstDamagedBoxIndex = [&]() -> std::optional<size_t > {
94
+ auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
95
+ return firstDamagedLineIndex ? std::make_optional (displayContentFromPreviousLayout.lines [*firstDamagedLineIndex].firstBoxIndex ()) : std::nullopt;
96
+ }();
97
+
98
+ auto numberOfDamagedLines = [&]() -> std::optional<size_t > {
99
+ if (!firstDamagedLineIndex)
100
+ return { };
101
+ auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
102
+ ASSERT (layoutResult.range != Layout::InlineLayoutResult::Range::Full);
103
+ auto canidateLineCount = layoutResult.range == Layout::InlineLayoutResult::Range::FullFromDamage
104
+ ? displayContentFromPreviousLayout.lines .size () - *firstDamagedLineIndex
105
+ : layoutResult.displayContent .lines .size ();
106
+
107
+ if (*firstDamagedLineIndex + canidateLineCount > displayContentFromPreviousLayout.lines .size ()) {
108
+ ASSERT_NOT_REACHED ();
109
+ return { };
110
+ }
111
+ return { canidateLineCount };
112
+ }();
113
+
114
+ auto numberOfDamagedBoxes = [&]() -> std::optional<size_t > {
115
+ if (!firstDamagedLineIndex || !numberOfDamagedLines || !firstDamagedBoxIndex)
116
+ return { };
117
+ auto & displayContentFromPreviousLayout = inlineContent.displayContent ();
118
+ ASSERT (*firstDamagedLineIndex + *numberOfDamagedLines <= displayContentFromPreviousLayout.lines .size ());
119
+ size_t boxCount = 0 ;
120
+ for (size_t i = 0 ; i < *numberOfDamagedLines; ++i)
121
+ boxCount += displayContentFromPreviousLayout.lines [*firstDamagedLineIndex + i].boxCount ();
122
+ ASSERT (boxCount);
123
+ return { boxCount };
124
+ }();
122
125
123
- switch (layoutResult.range ) {
124
- case Layout::InlineLayoutResult::Range::Full:
125
- inlineContent.displayContent ().set (WTFMove (layoutResult.displayContent ));
126
- break ;
127
- case Layout::InlineLayoutResult::Range::FullFromDamage: {
128
126
if (!firstDamagedLineIndex || !numberOfDamagedLines || !firstDamagedBoxIndex || !numberOfDamagedBoxes) {
129
- // FIXME: Not sure if inlineContent::set or silent failing is what we should do here.
130
- break ;
131
- }
132
- auto & displayContent = inlineContent.displayContent ();
133
- displayContent.remove (*firstDamagedLineIndex, *numberOfDamagedLines, *firstDamagedBoxIndex, *numberOfDamagedBoxes);
134
- displayContent.append (WTFMove (layoutResult.displayContent ));
135
- break ;
136
- }
137
- case Layout::InlineLayoutResult::Range::PartialFromDamage: {
138
- if (!firstDamagedLineIndex || !numberOfDamagedLines || !firstDamagedBoxIndex || !numberOfDamagedBoxes) {
139
- // FIXME: Not sure if inlineContent::set or silent failing is what we should do here.
140
- break ;
127
+ ASSERT_NOT_REACHED ();
128
+ return { };
141
129
}
142
- auto & displayContent = inlineContent.displayContent ();
143
- displayContent.remove (*firstDamagedLineIndex, *numberOfDamagedLines, *firstDamagedBoxIndex, *numberOfDamagedBoxes);
144
- displayContent.insert (WTFMove (layoutResult.displayContent ), *firstDamagedLineIndex, *firstDamagedBoxIndex);
145
130
146
- auto adjustCachedBoxIndexesIfNeeded = [&] {
147
- if (numberOfNewBoxes == *numberOfDamagedBoxes)
148
- return ;
149
- auto firstCleanLineIndex = *firstDamagedLineIndex + *numberOfDamagedLines;
150
- auto offset = numberOfNewBoxes - *numberOfDamagedBoxes;
151
- auto & lines = displayContent.lines ;
152
- for (size_t cleanLineIndex = firstCleanLineIndex; cleanLineIndex < lines.size (); ++cleanLineIndex) {
153
- ASSERT (lines[cleanLineIndex].firstBoxIndex () + offset > 0 );
154
- auto adjustedFirstBoxIndex = std::max<size_t >(0 , lines[cleanLineIndex].firstBoxIndex () + offset);
155
- lines[cleanLineIndex].setFirstBoxIndex (adjustedFirstBoxIndex);
156
- }
131
+ auto numberOfNewLines = layoutResult.displayContent .lines .size ();
132
+ auto numberOfNewBoxes = layoutResult.displayContent .boxes .size ();
133
+
134
+ auto damagedRect = FloatRect { };
135
+ auto adjustDamagedRectWithLineRange = [&](size_t firstLineIndex, size_t lineCount) {
136
+ auto & lines = inlineContent.displayContent ().lines ;
137
+ ASSERT (firstLineIndex + lineCount <= lines.size ());
138
+ for (size_t i = 0 ; i < lineCount; ++i)
139
+ damagedRect.unite (lines[firstLineIndex + i].inkOverflow ());
157
140
};
158
- adjustCachedBoxIndexesIfNeeded ();
159
- break ;
160
- }
161
- default :
162
- ASSERT_NOT_REACHED ();
163
- break ;
164
- }
165
141
166
- adjustDisplayLines (inlineContent, firstDamagedLineIndex.value_or (0 ));
167
- // Repaint the new content boundary.
168
- adjustDamagedRectWithLineRange (firstDamagedLineIndex.value_or (0 ), numberOfNewLines, inlineContent.displayContent ().lines );
142
+ // Repaint the damaged content boundary.
143
+ adjustDamagedRectWithLineRange (*firstDamagedLineIndex, *numberOfDamagedLines);
144
+
145
+ if (layoutResult.range == Layout::InlineLayoutResult::Range::FullFromDamage) {
146
+ auto & displayContent = inlineContent.displayContent ();
147
+ displayContent.remove (*firstDamagedLineIndex, *numberOfDamagedLines, *firstDamagedBoxIndex, *numberOfDamagedBoxes);
148
+ displayContent.append (WTFMove (layoutResult.displayContent ));
149
+ } else if (layoutResult.range == Layout::InlineLayoutResult::Range::PartialFromDamage) {
150
+ auto & displayContent = inlineContent.displayContent ();
151
+ displayContent.remove (*firstDamagedLineIndex, *numberOfDamagedLines, *firstDamagedBoxIndex, *numberOfDamagedBoxes);
152
+ displayContent.insert (WTFMove (layoutResult.displayContent ), *firstDamagedLineIndex, *firstDamagedBoxIndex);
153
+
154
+ auto adjustCachedBoxIndexesIfNeeded = [&] {
155
+ if (numberOfNewBoxes == *numberOfDamagedBoxes)
156
+ return ;
157
+ auto firstCleanLineIndex = *firstDamagedLineIndex + *numberOfDamagedLines;
158
+ auto offset = numberOfNewBoxes - *numberOfDamagedBoxes;
159
+ auto & lines = displayContent.lines ;
160
+ for (size_t cleanLineIndex = firstCleanLineIndex; cleanLineIndex < lines.size (); ++cleanLineIndex) {
161
+ ASSERT (lines[cleanLineIndex].firstBoxIndex () + offset > 0 );
162
+ auto adjustedFirstBoxIndex = std::max<size_t >(0 , lines[cleanLineIndex].firstBoxIndex () + offset);
163
+ lines[cleanLineIndex].setFirstBoxIndex (adjustedFirstBoxIndex);
164
+ }
165
+ };
166
+ adjustCachedBoxIndexesIfNeeded ();
167
+ } else
168
+ ASSERT_NOT_REACHED ();
169
169
170
- return damagedRect;
170
+ adjustDisplayLines (inlineContent, *firstDamagedLineIndex);
171
+ // Repaint the new content boundary.
172
+ adjustDamagedRectWithLineRange (*firstDamagedLineIndex, numberOfNewLines);
173
+
174
+ return damagedRect;
175
+ };
176
+ return handlePartialDisplayContentUpdate ();
171
177
}
172
178
173
179
void InlineContentBuilder::updateLineOverflow (InlineContent& inlineContent) const
0 commit comments