[webkit-changes] [WebKit/WebKit] af9631: [IFC][Floats] Floats with clear may be placed inco...

Alan Baradlay noreply at github.com
Wed Feb 22 05:28:27 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: af963178be93b40684f69cf4753845cdcceb2fdd
      https://github.com/WebKit/WebKit/commit/af963178be93b40684f69cf4753845cdcceb2fdd
  Author: Alan Baradlay <zalan at apple.com>
  Date:   2023-02-22 (Wed, 22 Feb 2023)

  Changed paths:
    A LayoutTests/fast/inline/inline-content-with-float-clear-expected.html
    A LayoutTests/fast/inline/inline-content-with-float-clear.html
    M Source/WebCore/layout/floats/FloatingContext.cpp
    M Source/WebCore/layout/floats/FloatingContext.h
    M Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp
    M Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h

  Log Message:
  -----------
  [IFC][Floats] Floats with clear may be placed incorrectly
https://bugs.webkit.org/show_bug.cgi?id=252712

Reviewed by Antti Koivisto.

When placing a float with clear (meaning that this float may be placed under any current floats),
we should consider the entire (horizontally) available space when checking if the float box fits.

Currently before placing the float, we check if it fits by consulting the remaining available space on the current line.
However in case of clear, the float may fall to a subsequent vertical position where the available space is different.

Consider the following case:
<div style="width: 20px">
  <div id=f1 style="float: left; width: 10px;></div>
  <img id=i style="width: 10px">
  <div id=f2 style="float: left; clear: left; width: 5px">
</div>
 ______________
|  _____  ___  |
| |     ||   | |
| | f1  || i | |
|  ----- |   | |
|        |   | |
|        |   | |
|        |   | |
|         ---  |
 --------------

We should be able to place 'f2' right below 'f1'. The available space right at the bottom of 'f1' is 10px.
 ______________
|  _____  ___  |
| |     ||   | |
| | f1  || i | |
|  ----- |   | |
|  _____ |   | |
| |     ||   | |
| | f2  ||   | |
|  -----  ---  |
 --------------

However currently we treat 'f2' as a regular float and check if there's enough space next to 'f1'. We find the
next available vertical position at the bottom of 'I'.

 ______________
|  _____  ___  |
| |     ||   | |
| | f1  || i | |
|  ----- |   | |
|        |   | |
|        |   | |
|        |   | |
|  _____  ---  |
 -|     |------
  | f2  |
   -----

In this patch,
1, move "shouldBePlaced" logic to a dedicated function "shouldTryToPlaceFloatBox" (LineBuilder::tryPlacingFloatBox is getting too busy)
2, when checking for available space in shouldTryToPlaceFloatBox, consult the clear property -at this point just check against the full available space.
3, after computing where the float would go, check if this position over-constrains the line content (i.e. float does not fit)

* LayoutTests/fast/inline/inline-content-with-float-clear-expected.html: Added.
* LayoutTests/fast/inline/inline-content-with-float-clear.html: Added.
* Source/WebCore/layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::positionForFloat const):
(WebCore::Layout::FloatingContext::positionForNonFloatingFloatAvoider const):
(WebCore::Layout::FloatingContext::verticalPositionWithClearance const):
(WebCore::Layout::FloatingContext::toFloatItem const):
(WebCore::Layout::FloatingContext::isLogicalLeftPositioned const):
(WebCore::Layout::FloatingContext::isFloatingCandidateLeftPositionedInFloatingState const):
(WebCore::Layout::FloatingContext::clearInFloatingState const):
(WebCore::Layout::FloatingContext::isFloatingCandidateLogicallyLeftPositioned const): Deleted.
(WebCore::Layout::FloatingContext::logicalClear const): Deleted.
* Source/WebCore/layout/floats/FloatingContext.h:
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::layoutInlineContent):
(WebCore::Layout::LineBuilder::initialize):
(WebCore::Layout::LineBuilder::adjustGeometryForInitialLetterIfNeeded):
(WebCore::Layout::LineBuilder::shouldTryToPlaceFloatCandidate const):
(WebCore::Layout::haveEnoughSpaceForFloatWithClear):
(WebCore::Layout::LineBuilder::tryPlacingFloatBox):
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h:

Canonical link: https://commits.webkit.org/260674@main




More information about the webkit-changes mailing list