Changeset 263597 in webkit


Ignore:
Timestamp:
Jun 26, 2020 4:26:54 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][BFC] Add support for <center>
https://bugs.webkit.org/show_bug.cgi?id=213649

Reviewed by Antti Koivisto.

Source/WebCore:

Adjust the margin box to center the block content (this is very similar to [style="margin-left: auto; margin-right: auto;"]).

Test: fast/layoutformattingcontext/center-alignment-with-block-content-simple.html

  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):

LayoutTests:

  • fast/layoutformattingcontext/center-alignment-with-block-content-simple-expected.html: Added.
  • fast/layoutformattingcontext/center-alignment-with-block-content-simple.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r263594 r263597  
     12020-06-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC] Add support for <center>
     4        https://bugs.webkit.org/show_bug.cgi?id=213649
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * fast/layoutformattingcontext/center-alignment-with-block-content-simple-expected.html: Added.
     9        * fast/layoutformattingcontext/center-alignment-with-block-content-simple.html: Added.
     10
    1112020-06-26  Karl Rackler  <rackler@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r263588 r263597  
     12020-06-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC] Add support for <center>
     4        https://bugs.webkit.org/show_bug.cgi?id=213649
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Adjust the margin box to center the block content (this is very similar to [style="margin-left: auto; margin-right: auto;"]).
     9
     10        Test: fast/layoutformattingcontext/center-alignment-with-block-content-simple.html
     11
     12        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     13        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
     14
    1152020-06-26  Jason Lawrence  <lawrence.j@apple.com>
    216
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r263260 r263597  
    141141
    142142        auto containingBlockWidth = horizontalConstraints.logicalWidth;
     143        auto& containingBlockStyle = layoutBox.containingBlock().style();
    143144        auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
    144145
     
    160161        // #2
    161162        if (width && computedHorizontalMargin.start && computedHorizontalMargin.end) {
    162             if (layoutBox.containingBlock().style().isLeftToRightDirection()) {
     163            if (containingBlockStyle.isLeftToRightDirection()) {
    163164                usedHorizontalMargin.start = *computedHorizontalMargin.start;
    164165                usedHorizontalMargin.end = containingBlockWidth - (usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight);
     
    193194        }
    194195
     196        auto shouldApplyCenterAlignForBlockContent = containingBlockStyle.textAlign() == TextAlignMode::WebKitCenter && (computedHorizontalMargin.start || computedHorizontalMargin.end);
     197        if (shouldApplyCenterAlignForBlockContent) {
     198            auto borderBoxWidth = (borderLeft + paddingLeft  + *width + paddingRight + borderRight);
     199            auto marginStart = computedHorizontalMargin.start.valueOr(0);
     200            auto marginEnd = computedHorizontalMargin.end.valueOr(0);
     201            auto centeredLogicalLeftForMarginBox = std::max((containingBlockWidth - borderBoxWidth - marginStart - marginEnd) / 2, 0_lu);
     202            usedHorizontalMargin.start = centeredLogicalLeftForMarginBox + marginStart;
     203            usedHorizontalMargin.end = containingBlockWidth - borderBoxWidth - marginStart + marginEnd;
     204        }
    195205        ASSERT(width);
    196206
Note: See TracChangeset for help on using the changeset viewer.