⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287083 in webkit


Ignore:
Timestamp:
Dec 15, 2021, 10:09:48 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Use the physical margin/border/padding values for inline boxes when generating the display content
https://bugs.webkit.org/show_bug.cgi?id=234346

Reviewed by Antti Koivisto.

Display content is always based on visual order. When we construct the display boxes

  • we visit the line runs in visual order
  • we make space for margin/border/padding by looking at the physical sides of the content

The visually first box may very well be logically the last and this first box's left side (again, visually)
may refer to the logical start/end values depending on the inline axis direction.

E.g in case of right to left inline direction, the border-inline-end value of an inline box should be use as the
"visually first" border on the left side of the inline box content.

It means that

  • physical values are used when creating the display boxes
  • and logical values are used throughout the layout

which in practice means that isLeftToRightDirection check should only happen before and after layout
(physical -> logical and logical -> physical respectively) but never during layout.

  • layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:

(WebCore::Layout::marginLeft):
(WebCore::Layout::marginRight):
(WebCore::Layout::borderLeft):
(WebCore::Layout::borderRight):
(WebCore::Layout::paddingLeft):
(WebCore::Layout::paddingRight):
(WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287081 r287083  
     12021-12-15  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Use the physical margin/border/padding values for inline boxes when generating the display content
     4        https://bugs.webkit.org/show_bug.cgi?id=234346
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Display content is always based on visual order. When we construct the display boxes
     9          - we visit the line runs in visual order
     10          - we make space for margin/border/padding by looking at the physical sides of the content
     11        The visually first box may very well be logically the last and this first box's left side (again, visually)
     12        may refer to the logical start/end values depending on the inline axis direction.
     13
     14        E.g in case of right to left inline direction, the border-inline-end value of an inline box should be use as the
     15        "visually first" border on the left side of the inline box content.   
     16
     17        It means that
     18         - physical values are used when creating the display boxes
     19         - and logical values are used throughout the layout
     20        which in practice means that isLeftToRightDirection check should only happen before and after layout
     21        (physical -> logical and logical -> physical respectively) but never during layout.
     22
     23        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
     24        (WebCore::Layout::marginLeft):
     25        (WebCore::Layout::marginRight):
     26        (WebCore::Layout::borderLeft):
     27        (WebCore::Layout::borderRight):
     28        (WebCore::Layout::paddingLeft):
     29        (WebCore::Layout::paddingRight):
     30        (WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox):
     31
    1322021-12-15  Yoshiaki Jitsukawa  <yoshiaki.jitsukawa@sony.com>
    233
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp

    r287043 r287083  
    4242namespace Layout {
    4343
     44static inline LayoutUnit marginLeft(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
     45{
     46    return isLeftToRightDirection ? boxGeometry.marginStart() : boxGeometry.marginEnd();
     47}
     48
     49static inline LayoutUnit marginRight(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
     50{
     51    return isLeftToRightDirection ? boxGeometry.marginEnd() : boxGeometry.marginStart();
     52}
     53
     54static inline LayoutUnit borderLeft(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
     55{
     56    return isLeftToRightDirection ? boxGeometry.borderStart() : boxGeometry.borderEnd();
     57}
     58
     59static inline LayoutUnit borderRight(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
     60{
     61    return isLeftToRightDirection ? boxGeometry.borderEnd() : boxGeometry.borderStart();
     62}
     63
     64static inline LayoutUnit paddingLeft(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
     65{
     66    return isLeftToRightDirection ? boxGeometry.paddingStart().value_or(0_lu) : boxGeometry.paddingEnd().value_or(0_lu);
     67}
     68
     69static inline LayoutUnit paddingRight(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
     70{
     71    return isLeftToRightDirection ? boxGeometry.paddingEnd().value_or(0_lu) : boxGeometry.paddingStart().value_or(0_lu);
     72}
     73
    4474static inline OptionSet<InlineDisplay::Box::PositionWithinInlineLevelBox> isFirstLastBox(const InlineLevelBox& inlineBox)
    4575{
     
    425455void InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& contentRightInVisualOrder, InlineLayoutUnit lineBoxLogicalTop, const DisplayBoxTree& displayBoxTree, DisplayBoxes& boxes, const LineBox& lineBox)
    426456{
     457    auto isLeftToRightDirection = root().style().isLeftToRightDirection();
    427458    // Non-inline box display boxes just need a horizontal adjustment while
    428459    // inline box type of display boxes need
     
    436467        contentRightInVisualOrder += displayBox.width();
    437468        if (displayBox.isAtomicInlineLevelBox() || displayBox.isGenericInlineLevelBox())
    438             contentRightInVisualOrder += formattingState().boxGeometry(layoutBox).marginEnd();
     469            contentRightInVisualOrder += marginRight(formattingState().boxGeometry(layoutBox), isLeftToRightDirection);
    439470        return;
    440471    }
     
    447478            return displayBox.setRect(visualRect, visualRect);
    448479
    449         contentRightInVisualOrder += boxGeometry.marginStart();
    450         auto visualRectWithMarginStart = InlineRect { visualRect.top(), contentRightInVisualOrder, visualRect.width(), visualRect.height() };
    451         displayBox.setRect(visualRectWithMarginStart, visualRectWithMarginStart);
    452         contentRightInVisualOrder += boxGeometry.borderAndPaddingStart();
     480        contentRightInVisualOrder += marginLeft(boxGeometry, isLeftToRightDirection);
     481        auto visualRectWithMarginLeft = InlineRect { visualRect.top(), contentRightInVisualOrder, visualRect.width(), visualRect.height() };
     482        displayBox.setRect(visualRectWithMarginLeft, visualRectWithMarginLeft);
     483        contentRightInVisualOrder += borderLeft(boxGeometry, isLeftToRightDirection) + paddingLeft(boxGeometry, isLeftToRightDirection);
    453484    };
    454485    beforeInlineBoxContent();
     
    461492            return displayBox.setRight(contentRightInVisualOrder);
    462493
    463         contentRightInVisualOrder += boxGeometry.borderAndPaddingEnd();
     494        contentRightInVisualOrder += borderRight(boxGeometry, isLeftToRightDirection) + paddingRight(boxGeometry, isLeftToRightDirection);
    464495        displayBox.setRight(contentRightInVisualOrder);
    465         contentRightInVisualOrder += boxGeometry.marginEnd();
     496        contentRightInVisualOrder += marginRight(boxGeometry, isLeftToRightDirection);
    466497    };
    467498    afterInlineBoxContent();
Note: See TracChangeset for help on using the changeset viewer.