-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IFC] Introduce RangeBasedLineBuilder
https://bugs.webkit.org/show_bug.cgi?id=271359 Reviewed by Antti Koivisto. RangeBasedLineBuilder is meant to support a mix of content where a simplified line builder can be used on well-defined content range(s). Currently it supports a very simple case only where text content is nested inside an inline box. e.g. <div><span>this is text only content</span></div> In this case we can use the TextOnlySimpleLineBuilder for the nested content while adjusting the result with the enclosing inline box geometry. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp: (WebCore::Layout::InlineFormattingContext::layout): * Source/WebCore/layout/formattingContexts/inline/InlineLine.h: * Source/WebCore/layout/formattingContexts/inline/RangeBasedLineBuilder.cpp: Added. (WebCore::Layout::RangeBasedLineBuilder::RangeBasedLineBuilder): (WebCore::Layout::RangeBasedLineBuilder::layoutInlineContent): (WebCore::Layout::RangeBasedLineBuilder::isEligibleForRangeInlineLayout): * Source/WebCore/layout/formattingContexts/inline/RangeBasedLineBuilder.h: Added. Canonical link: https://commits.webkit.org/276509@main
- Loading branch information
1 parent
b29e92b
commit 639f7f3
Showing
12 changed files
with
213 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
Source/WebCore/layout/formattingContexts/inline/RangeBasedLineBuilder.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "RangeBasedLineBuilder.h" | ||
|
||
namespace WebCore { | ||
namespace Layout { | ||
|
||
RangeBasedLineBuilder::RangeBasedLineBuilder(InlineFormattingContext& inlineFormattingContext, HorizontalConstraints rootHorizontalConstraints, const InlineItemList& inlineItemList) | ||
: AbstractLineBuilder(inlineFormattingContext, inlineFormattingContext.root(), rootHorizontalConstraints, inlineItemList) | ||
, m_textOnlySimpleLineBuilder(inlineFormattingContext, downcast<ElementBox>(inlineItemList[0].layoutBox()), rootHorizontalConstraints, inlineItemList) | ||
{ | ||
} | ||
|
||
LineLayoutResult RangeBasedLineBuilder::layoutInlineContent(const LineInput& lineInput, const std::optional<PreviousLine>& previousLine) | ||
{ | ||
// 1. Shrink the layout range that we can run text-only builder on (currently it's just the opening/closing inline box) | ||
// 2. Run text-only line builder | ||
// 3. Insert/append the missing inline box run | ||
auto isFirstLine = !lineInput.needsLayoutRange.startIndex(); | ||
|
||
auto adjustedNeedsLayoutRange = [&] { | ||
auto needsLayoutRange = lineInput.needsLayoutRange; | ||
if (isFirstLine) { | ||
ASSERT(m_inlineItemList[0].isInlineBoxStart()); | ||
ASSERT(!needsLayoutRange.start.offset); | ||
// Skip leading InlineItemStart (e.g. <span>) | ||
++needsLayoutRange.start.index; | ||
} | ||
// SKip trailing InlineItemEnd (e.g. </span>) | ||
ASSERT(m_inlineItemList.last().isInlineBoxEnd()); | ||
ASSERT(!needsLayoutRange.end.offset); | ||
--needsLayoutRange.end.index; | ||
return needsLayoutRange; | ||
}; | ||
auto needsLayoutRange = adjustedNeedsLayoutRange(); | ||
ASSERT(!needsLayoutRange.isEmpty()); | ||
|
||
auto lineLayoutResult = m_textOnlySimpleLineBuilder.layoutInlineContent({ needsLayoutRange, lineInput.initialLogicalRect }, previousLine); | ||
|
||
auto insertLeadingInlineBoxRun = [&] { | ||
auto& leadingInlineItem = m_inlineItemList.first(); | ||
ASSERT(leadingInlineItem.isInlineBoxStart()); | ||
|
||
if (isFirstLine) { | ||
ASSERT(!previousLine); | ||
lineLayoutResult.inlineContent.insert(0, { leadingInlineItem, leadingInlineItem.firstLineStyle(), { } }); | ||
lineLayoutResult.inlineItemRange.start = lineInput.needsLayoutRange.start; | ||
return; | ||
} | ||
// Subsequent lines need leading spanning inline box run. | ||
lineLayoutResult.inlineContent.insert(0, { leadingInlineItem, { }, { } }); | ||
}; | ||
insertLeadingInlineBoxRun(); | ||
|
||
auto appendTrailingInlineBoxRunIfNeeded = [&] { | ||
if (lineLayoutResult.inlineItemRange.end != needsLayoutRange.end) | ||
return; | ||
auto& trailingInlineItem = m_inlineItemList.last(); | ||
lineLayoutResult.inlineContent.append({ trailingInlineItem, isFirstLine ? trailingInlineItem.firstLineStyle() : trailingInlineItem.style(), lineLayoutResult.contentGeometry.logicalWidth }); | ||
lineLayoutResult.inlineItemRange.end = lineInput.needsLayoutRange.end; | ||
}; | ||
appendTrailingInlineBoxRunIfNeeded(); | ||
|
||
return lineLayoutResult; | ||
} | ||
|
||
bool RangeBasedLineBuilder::isEligibleForRangeInlineLayout(const InlineFormattingContext& inlineFormattingContext, const InlineContentCache::InlineItems& inlineItems, const PlacedFloats& placedFloats) | ||
{ | ||
if (inlineItems.isEmpty()) | ||
return false; | ||
// Range based line builder only supports the following content <inline box>eligible for text only layout</inline box> | ||
auto& inlineItemList = inlineItems.content(); | ||
auto isFullyNestedContent = inlineItems.inlineBoxCount() == 1 && inlineItemList.first().isInlineBoxStart() && inlineItemList.last().isInlineBoxEnd() && inlineItemList.size() > 2; | ||
if (!isFullyNestedContent) | ||
return false; | ||
|
||
auto& inlineBox = inlineItemList.first().layoutBox(); | ||
auto& inlineBoxGeometry = inlineFormattingContext.geometryForBox(inlineBox); | ||
if (inlineBoxGeometry.horizontalMarginBorderAndPadding()) { | ||
// FIXME: Add start decoration support is just a matter of shrinking the available space for the first line (or on subsequent lines when decoration break is present) | ||
return false; | ||
} | ||
if (inlineBox.style().boxDecorationBreak() != RenderStyle::initialBoxDecorationBreak()) | ||
return false; | ||
|
||
// Check the nested text content. | ||
if (!inlineItems.hasTextAndLineBreakOnlyContent() || inlineItems.requiresVisualReordering() || !placedFloats.isEmpty()) | ||
return false; | ||
|
||
if (!TextOnlySimpleLineBuilder::isEligibleForSimplifiedInlineLayoutByStyle(inlineFormattingContext.root().style()) || !TextOnlySimpleLineBuilder::isEligibleForSimplifiedInlineLayoutByStyle(inlineBox.style())) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
} | ||
} | ||
|
Oops, something went wrong.