Skip to content

Commit

Permalink
[IFC][Integration] Enable intrusive floats coming from rtl inline dir…
Browse files Browse the repository at this point in the history
…ection

https://bugs.webkit.org/show_bug.cgi?id=245528

Reviewed by Antti Koivisto.

Let's convert the incoming, intrusive float's directions (left, right, inline-start, inline-end) and coordinates to logical values (e.g. a left float should treated as "right" when the inline direction is rtl).
This enables the following type of content:
  <div style="direction: rtl">
    <img float-left>
    <div>this is rtl inline direction content with intrusive float box</div>
  </div>

* Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::canUseForLineLayoutWithReason):
* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::prepareFloatingState):

Canonical link: https://commits.webkit.org/254770@main
  • Loading branch information
alanbaradlay committed Sep 22, 2022
1 parent 03fb5fd commit 3317fbd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ OptionSet<AvoidanceReason> canUseForLineLayoutWithReason(const RenderBlockFlow&
ADD_REASONS_AND_RETURN_IF_NEEDED(styleReasons, reasons, includeReasons);

if (flow.containsFloats()) {
auto intrusiveFloatsWithMismatchingInlineDirection = flow.containingBlock() && (flow.containingBlock()->style().isLeftToRightDirection() != flow.style().isLeftToRightDirection() || !flow.style().isLeftToRightDirection());
auto intrusiveFloatsWithMismatchingInlineDirection = flow.containingBlock() && flow.containingBlock()->style().isLeftToRightDirection() != flow.style().isLeftToRightDirection();
if (intrusiveFloatsWithMismatchingInlineDirection)
SET_REASON_AND_RETURN_IF_NEEDED(FlowHasUnsupportedFloat, reasons, includeReasons);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,39 @@ void LineLayout::prepareFloatingState()
if (!flow().containsFloats())
return;

if (flow().containingBlock())
floatingState.setIsLeftToRightDirection(flow().containingBlock()->style().isLeftToRightDirection());
auto& rootGeometry = m_layoutState.geometryForRootBox();
auto isHorizontalWritingMode = flow().containingBlock() ? flow().containingBlock()->style().isHorizontalWritingMode() : true;
auto isLeftToRightInlineDirection = flow().containingBlock() ? flow().containingBlock()->style().isLeftToRightDirection() : true;
floatingState.setIsLeftToRightDirection(isLeftToRightInlineDirection);
for (auto& floatingObject : *flow().floatingObjectSet()) {
auto& visualRect = floatingObject->frameRect();
auto position = floatingObject->type() == FloatingObject::FloatRight
? Layout::FloatingState::FloatItem::Position::Right
: Layout::FloatingState::FloatItem::Position::Left;
auto logicalPosition = [&] {
switch (floatingObject->renderer().style().floating()) {
case Float::Left:
return isLeftToRightInlineDirection ? Layout::FloatingState::FloatItem::Position::Left : Layout::FloatingState::FloatItem::Position::Right;
case Float::Right:
return isLeftToRightInlineDirection ? Layout::FloatingState::FloatItem::Position::Right : Layout::FloatingState::FloatItem::Position::Left;
case Float::InlineStart:
return Layout::FloatingState::FloatItem::Position::Left;
case Float::InlineEnd:
return Layout::FloatingState::FloatItem::Position::Right;
default:
ASSERT_NOT_REACHED();
return Layout::FloatingState::FloatItem::Position::Left;
}
};

auto boxGeometry = Layout::BoxGeometry { };
// FIXME: We are flooring here for legacy compatibility.
// See FloatingObjects::intervalForFloatingObject and RenderBlockFlow::clearFloats.
auto logicalTop = visualRect.y().floor();
auto logicalHeight = visualRect.maxY().floor() - logicalTop;
auto logicalRect = flow().style().isHorizontalWritingMode() ? LayoutRect(visualRect.x(), logicalTop, visualRect.width(), logicalHeight)
: LayoutRect(logicalTop, visualRect.x(), logicalHeight, visualRect.width());
auto logicalRect = [&] {
// FIXME: We are flooring here for legacy compatibility. See FloatingObjects::intervalForFloatingObject and RenderBlockFlow::clearFloats.
auto logicalTop = isHorizontalWritingMode ? LayoutUnit(visualRect.y().floor()) : visualRect.x();
auto logicalLeft = isHorizontalWritingMode ? visualRect.x() : LayoutUnit(visualRect.y().floor());
auto logicalHeight = (isHorizontalWritingMode ? LayoutUnit(visualRect.maxY().floor()) : visualRect.maxX()) - logicalTop;
auto logicalWidth = (isHorizontalWritingMode ? visualRect.maxX() : LayoutUnit(visualRect.maxY().floor())) - logicalLeft;
if (!isLeftToRightInlineDirection)
logicalLeft = rootGeometry.borderBoxWidth() - (logicalLeft + logicalWidth);
return LayoutRect { logicalLeft, logicalTop, logicalWidth, logicalHeight };
}();

boxGeometry.setLogicalTopLeft(logicalRect.location());
boxGeometry.setContentBoxWidth(logicalRect.width());
Expand All @@ -511,7 +530,7 @@ void LineLayout::prepareFloatingState()
boxGeometry.setPadding({ });
boxGeometry.setHorizontalMargin({ });
boxGeometry.setVerticalMargin({ });
floatingState.append({ position, boxGeometry });
floatingState.append({ logicalPosition(), boxGeometry });
}
}

Expand Down

0 comments on commit 3317fbd

Please sign in to comment.