Diff
Modified: trunk/Source/WebCore/ChangeLog (288316 => 288317)
--- trunk/Source/WebCore/ChangeLog 2022-01-20 21:11:04 UTC (rev 288316)
+++ trunk/Source/WebCore/ChangeLog 2022-01-20 21:18:21 UTC (rev 288317)
@@ -1,3 +1,22 @@
+2022-01-20 Alan Bujtas <za...@apple.com>
+
+ [LFC][IFC] LineBuilder::layoutInlineContent should take PreviousLine
+ https://bugs.webkit.org/show_bug.cgi?id=235403
+
+ Reviewed by Antti Koivisto.
+
+ Let's pass in a PreviousLine struct to LineBuilder::layoutInlineContent instead of individual variables about the previous line.
+ This is in preparation for supporting unicode-bidi: plaintext where we need to know if the previous line ends in a line break or not.
+
+ * layout/formattingContexts/inline/InlineFormattingContext.cpp:
+ (WebCore::Layout::InlineFormattingContext::lineLayout):
+ (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthForConstraint const):
+ * layout/formattingContexts/inline/InlineLineBuilder.cpp:
+ (WebCore::Layout::LineBuilder::layoutInlineContent):
+ (WebCore::Layout::LineBuilder::computedIntrinsicWidth):
+ (WebCore::Layout::LineBuilder::initialize):
+ * layout/formattingContexts/inline/InlineLineBuilder.h:
+
2022-01-20 Kimmo Kinnunen <kkinnu...@apple.com>
Implement WebGL GPU buffer texture upload path for Cocoa getUserMedia camera streams
Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp (288316 => 288317)
--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp 2022-01-20 21:11:04 UTC (rev 288316)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp 2022-01-20 21:18:21 UTC (rev 288317)
@@ -203,22 +203,12 @@
auto& formattingState = this->formattingState();
formattingState.boxes().reserveInitialCapacity(formattingState.inlineItems().size());
InlineLayoutUnit lineLogicalTop = constraints.logicalTop();
- struct PreviousLine {
- LineBuilder::InlineItemRange range;
- size_t overflowContentLength { 0 };
- std::optional<InlineLayoutUnit> overflowLogicalWidth;
- };
- std::optional<PreviousLine> previousLine;
+ auto previousLine = std::optional<LineBuilder::PreviousLine> { };
auto& floatingState = formattingState.floatingState();
auto floatingContext = FloatingContext { *this, floatingState };
- auto isFirstLine = formattingState.lines().isEmpty();
auto lineBuilder = LineBuilder { *this, floatingState, constraints.horizontal(), inlineItems };
while (!needsLayoutRange.isEmpty()) {
- // Turn previous line's overflow content length into the next line's leading content partial length.
- // "sp[<-line break->]lit_content" -> overflow length: 11 -> leading partial content length: 11.
- auto partialLeadingContentLength = previousLine ? previousLine->overflowContentLength : 0;
- auto leadingLogicalWidth = previousLine ? previousLine->overflowLogicalWidth : std::nullopt;
auto initialLineHeight = [&]() -> InlineLayoutUnit {
if (layoutState().inStandardsMode())
return root().style().computedLineHeight();
@@ -225,13 +215,12 @@
return formattingQuirks().initialLineHeight();
}();
auto initialLineConstraints = InlineRect { lineLogicalTop, constraints.horizontal().logicalLeft, constraints.horizontal().logicalWidth, initialLineHeight };
- auto lineContent = lineBuilder.layoutInlineContent(needsLayoutRange, partialLeadingContentLength, leadingLogicalWidth, initialLineConstraints, isFirstLine);
+ auto lineContent = lineBuilder.layoutInlineContent(needsLayoutRange, initialLineConstraints, previousLine);
auto lineLogicalRect = computeGeometryForLineContent(lineContent);
auto lineContentRange = lineContent.inlineItemRange;
if (!lineContentRange.isEmpty()) {
ASSERT(needsLayoutRange.start < lineContentRange.end);
- isFirstLine = false;
lineLogicalTop = formattingGeometry().logicalTopForNextLine(lineContent, lineLogicalRect.bottom(), floatingContext);
if (lineContent.isLastLineWithInlineContent) {
// The final content height of this inline formatting context should include the cleared floats as well.
@@ -242,7 +231,7 @@
if (lastInlineItemNeedsPartialLayout) {
auto lineLayoutHasAdvanced = !previousLine
|| lineContentRange.end > previousLine->range.end
- || (previousLine->overflowContentLength && previousLine->overflowContentLength > lineContent.partialTrailingContentLength);
+ || (previousLine->overflowContent && previousLine->overflowContent->partialContentLength > lineContent.partialTrailingContentLength);
if (!lineLayoutHasAdvanced) {
ASSERT_NOT_REACHED();
// Move over to the next run if we are stuck on this partial content (when the overflow content length remains the same).
@@ -251,7 +240,12 @@
}
}
needsLayoutRange.start = lastInlineItemNeedsPartialLayout ? lineContentRange.end - 1 : lineContentRange.end;
- previousLine = PreviousLine { lineContentRange, lineContent.partialTrailingContentLength, lineContent.overflowLogicalWidth };
+ auto overflowContent = std::optional<LineBuilder::PreviousLine::OverflowContent> { };
+ if (lineContent.partialTrailingContentLength)
+ overflowContent = { lineContent.partialTrailingContentLength, lineContent.overflowLogicalWidth };
+ else if (lineContent.overflowLogicalWidth)
+ overflowContent = { { }, *lineContent.overflowLogicalWidth };
+ previousLine = LineBuilder::PreviousLine { lineContentRange, overflowContent };
continue;
}
// Floats prevented us placing any content on the line.
@@ -440,12 +434,12 @@
auto layoutRange = LineBuilder::InlineItemRange { 0 , inlineItems.size() };
auto maximumLineWidth = InlineLayoutUnit { };
auto maximumFloatWidth = LayoutUnit { };
- auto isFirstLine = true;
+ auto previousLine = std::optional<LineBuilder::PreviousLine> { };
while (!layoutRange.isEmpty()) {
- auto intrinsicContent = lineBuilder.computedIntrinsicWidth(layoutRange, isFirstLine);
+ auto intrinsicContent = lineBuilder.computedIntrinsicWidth(layoutRange, previousLine);
layoutRange.start = intrinsicContent.inlineItemRange.end;
maximumLineWidth = std::max(maximumLineWidth, intrinsicContent.logicalWidth);
- isFirstLine = false;
+ previousLine = LineBuilder::PreviousLine { };
// FIXME: Add support for clear.
for (auto* floatBox : intrinsicContent.floats)
maximumFloatWidth += geometryForBox(*floatBox).marginBoxWidth();
Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp (288316 => 288317)
--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp 2022-01-20 21:11:04 UTC (rev 288316)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp 2022-01-20 21:18:21 UTC (rev 288317)
@@ -305,9 +305,9 @@
InlineLayoutUnit marginStart { 0 };
bool isConstrainedByFloat { false };
};
-LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, size_t partialLeadingContentLength, std::optional<InlineLayoutUnit> overflowingLogicalWidth, const InlineRect& initialLineLogicalRect, bool isFirstLine)
+LineBuilder::LineContent LineBuilder::layoutInlineContent(const InlineItemRange& needsLayoutRange, const InlineRect& lineLogicalRect, const std::optional<PreviousLine>& previousLine)
{
- initialize(initialConstraintsForLine(initialLineLogicalRect, isFirstLine), isFirstLine, needsLayoutRange.start, partialLeadingContentLength, overflowingLogicalWidth);
+ initialize(initialConstraintsForLine(lineLogicalRect, !previousLine), needsLayoutRange.start, previousLine);
auto committedContent = placeInlineContent(needsLayoutRange);
auto committedRange = close(needsLayoutRange, committedContent);
@@ -361,12 +361,12 @@
, lineRuns };
}
-LineBuilder::IntrinsicContent LineBuilder::computedIntrinsicWidth(const InlineItemRange& needsLayoutRange, bool isFirstLine)
+LineBuilder::IntrinsicContent LineBuilder::computedIntrinsicWidth(const InlineItemRange& needsLayoutRange, const std::optional<PreviousLine>& previousLine)
{
ASSERT(isInIntrinsicWidthMode());
auto lineLogicalWidth = *intrinsicWidthMode() == IntrinsicWidthMode::Maximum ? maxInlineLayoutUnit() : 0.f;
- auto lineConstraints = initialConstraintsForLine({ 0, 0, lineLogicalWidth, 0 }, isFirstLine);
- initialize(lineConstraints, isFirstLine, needsLayoutRange.start, { }, { });
+ auto lineConstraints = initialConstraintsForLine({ 0, 0, lineLogicalWidth, 0 }, !previousLine);
+ initialize(lineConstraints, needsLayoutRange.start, previousLine);
auto committedContent = placeInlineContent(needsLayoutRange);
auto committedRange = close(needsLayoutRange, committedContent);
@@ -374,12 +374,14 @@
return { committedRange, lineWidth, m_floats };
}
-void LineBuilder::initialize(const UsedConstraints& lineConstraints, bool isFirstLine, size_t leadingInlineItemIndex, size_t partialLeadingContentLength, std::optional<InlineLayoutUnit> overflowingLogicalWidth)
+void LineBuilder::initialize(const UsedConstraints& lineConstraints, size_t leadingInlineItemIndex, const std::optional<PreviousLine>& previousLine)
{
- m_isFirstLine = isFirstLine;
+ m_isFirstLine = !previousLine;
m_floats.clear();
m_lineSpanningInlineBoxes.clear();
m_wrapOpportunityList.clear();
+ m_overflowingLogicalWidth = { };
+ m_partialLeadingTextItem = { };
auto createLineSpanningInlineBoxes = [&] {
auto isRootLayoutBox = [&](auto& containerBox) {
@@ -422,13 +424,13 @@
m_lineLogicalRect.expandHorizontally(-m_lineMarginStart);
m_contentIsConstrainedByFloat = lineConstraints.isConstrainedByFloat;
- if (partialLeadingContentLength) {
- ASSERT(!isFirstLine);
- m_partialLeadingTextItem = downcast<InlineTextItem>(m_inlineItems[leadingInlineItemIndex]).right(partialLeadingContentLength, overflowingLogicalWidth);
- m_overflowingLogicalWidth = { };
- } else {
- m_partialLeadingTextItem = { };
- m_overflowingLogicalWidth = overflowingLogicalWidth;
+ if (previousLine && previousLine->overflowContent) {
+ if (previousLine->overflowContent->partialContentLength) {
+ // Turn previous line's overflow content length into the next line's leading content partial length.
+ // "sp[<-line break->]lit_content" -> overflow length: 11 -> leading partial content length: 11.
+ m_partialLeadingTextItem = downcast<InlineTextItem>(m_inlineItems[leadingInlineItemIndex]).right(previousLine->overflowContent->partialContentLength, previousLine->overflowContent->width);
+ } else
+ m_overflowingLogicalWidth = previousLine->overflowContent->width;
}
}
Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h (288316 => 288317)
--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h 2022-01-20 21:11:04 UTC (rev 288316)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h 2022-01-20 21:18:21 UTC (rev 288317)
@@ -50,6 +50,14 @@
size_t start { 0 };
size_t end { 0 };
};
+ struct PreviousLine {
+ InlineItemRange range;
+ struct OverflowContent {
+ size_t partialContentLength { 0 };
+ std::optional<InlineLayoutUnit> width { };
+ };
+ std::optional<OverflowContent> overflowContent { };
+ };
using FloatList = Vector<const Box*>;
struct LineContent {
InlineItemRange inlineItemRange;
@@ -68,7 +76,7 @@
Vector<int32_t> visualOrderList;
const Line::RunList& runs;
};
- LineContent layoutInlineContent(const InlineItemRange&, size_t partialLeadingContentLength, std::optional<InlineLayoutUnit> overflowingLogicalWidth, const InlineRect& initialLineLogicalRect, bool isFirstLine);
+ LineContent layoutInlineContent(const InlineItemRange&, const InlineRect& lineLogicalRect, const std::optional<PreviousLine>&);
struct IntrinsicContent {
InlineItemRange inlineItemRange;
@@ -75,7 +83,7 @@
InlineLayoutUnit logicalWidth { 0 };
const FloatList& floats;
};
- IntrinsicContent computedIntrinsicWidth(const InlineItemRange&, bool isFirstLine);
+ IntrinsicContent computedIntrinsicWidth(const InlineItemRange&, const std::optional<PreviousLine>&);
private:
void candidateContentForLine(LineCandidate&, size_t inlineItemIndex, const InlineItemRange& needsLayoutRange, InlineLayoutUnit currentLogicalRight);
@@ -99,7 +107,7 @@
size_t rebuildLine(const InlineItemRange& needsLayoutRange, const InlineItem& lastInlineItemToAdd);
size_t rebuildLineForTrailingSoftHyphen(const InlineItemRange& layoutRange);
void commitPartialContent(const InlineContentBreaker::ContinuousContent::RunList&, const InlineContentBreaker::Result::PartialTrailingContent&);
- void initialize(const UsedConstraints&, bool isFirstLine, size_t leadingInlineTextItemIndex, size_t partialLeadingContentLength, std::optional<InlineLayoutUnit> overflowingLogicalWidth);
+ void initialize(const UsedConstraints&, size_t leadingInlineTextItemIndex, const std::optional<PreviousLine>&);
struct CommittedContent {
size_t inlineItemCount { 0 };
size_t partialTrailingContentLength { 0 };