Title: [263597] trunk
Revision
263597
Author
za...@apple.com
Date
2020-06-26 16:26:54 -0700 (Fri, 26 Jun 2020)

Log 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (263596 => 263597)


--- trunk/LayoutTests/ChangeLog	2020-06-26 23:23:47 UTC (rev 263596)
+++ trunk/LayoutTests/ChangeLog	2020-06-26 23:26:54 UTC (rev 263597)
@@ -1,3 +1,13 @@
+2020-06-26  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][BFC] Add support for <center>
+        https://bugs.webkit.org/show_bug.cgi?id=213649
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/center-alignment-with-block-content-simple-expected.html: Added.
+        * fast/layoutformattingcontext/center-alignment-with-block-content-simple.html: Added.
+
 2020-06-26  Karl Rackler  <rack...@apple.com>
 
         Remove expectation for imported/w3c/canvas/2d.line.cap.round.html as they are passing. 

Added: trunk/LayoutTests/fast/layoutformattingcontext/center-alignment-with-block-content-simple-expected.html (0 => 263597)


--- trunk/LayoutTests/fast/layoutformattingcontext/center-alignment-with-block-content-simple-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/center-alignment-with-block-content-simple-expected.html	2020-06-26 23:26:54 UTC (rev 263597)
@@ -0,0 +1,19 @@
+<!DOCTYPE html><!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+.center {
+    width: 50px;
+    height: 50px;
+    background-color: green;
+    position: relative;
+}
+
+.container {
+    width: 100px;
+    height: 50px;
+    background-color: blue;
+}
+</style>
+<div class=container><div class=center style="left: 25px"></div></div>
+<div class=container><div class=center style="left: 50px;"></div></div>
+<div class=container><div class=center></div></div>
+<div class=container><div class=center style="left: 25px"></div></div>

Added: trunk/LayoutTests/fast/layoutformattingcontext/center-alignment-with-block-content-simple.html (0 => 263597)


--- trunk/LayoutTests/fast/layoutformattingcontext/center-alignment-with-block-content-simple.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/center-alignment-with-block-content-simple.html	2020-06-26 23:26:54 UTC (rev 263597)
@@ -0,0 +1,17 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+center {
+    width: 100px;
+    background-color: blue;
+}
+
+div {
+    width: 50px;
+    height: 50px;
+    background-color: green;
+}
+</style>
+<center><div></div></center>
+<center><div style="margin-left: 50px;"></div></center>
+<center><div style="margin-right: 50px;"></div></center>
+<center><div style="display: table;"></div></center>

Modified: trunk/Source/WebCore/ChangeLog (263596 => 263597)


--- trunk/Source/WebCore/ChangeLog	2020-06-26 23:23:47 UTC (rev 263596)
+++ trunk/Source/WebCore/ChangeLog	2020-06-26 23:26:54 UTC (rev 263597)
@@ -1,3 +1,17 @@
+2020-06-26  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][BFC] Add support for <center>
+        https://bugs.webkit.org/show_bug.cgi?id=213649
+
+        Reviewed by Antti Koivisto.
+
+        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):
+
 2020-06-26  Jason Lawrence  <lawrenc...@apple.com>
 
         Unreviewed, reverting r263511, r263514, and r263565.

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (263596 => 263597)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2020-06-26 23:23:47 UTC (rev 263596)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2020-06-26 23:26:54 UTC (rev 263597)
@@ -140,6 +140,7 @@
         //    edges of the containing block.
 
         auto containingBlockWidth = horizontalConstraints.logicalWidth;
+        auto& containingBlockStyle = layoutBox.containingBlock().style();
         auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
 
         auto width = overrideHorizontalValues.width ? overrideHorizontalValues.width : computedWidth(layoutBox, containingBlockWidth);
@@ -159,7 +160,7 @@
 
         // #2
         if (width && computedHorizontalMargin.start && computedHorizontalMargin.end) {
-            if (layoutBox.containingBlock().style().isLeftToRightDirection()) {
+            if (containingBlockStyle.isLeftToRightDirection()) {
                 usedHorizontalMargin.start = *computedHorizontalMargin.start;
                 usedHorizontalMargin.end = containingBlockWidth - (usedHorizontalMargin.start + borderLeft + paddingLeft + *width + paddingRight + borderRight);
             } else {
@@ -192,6 +193,15 @@
             usedHorizontalMargin = { horizontalSpaceForMargin / 2, horizontalSpaceForMargin / 2 };
         }
 
+        auto shouldApplyCenterAlignForBlockContent = containingBlockStyle.textAlign() == TextAlignMode::WebKitCenter && (computedHorizontalMargin.start || computedHorizontalMargin.end);
+        if (shouldApplyCenterAlignForBlockContent) {
+            auto borderBoxWidth = (borderLeft + paddingLeft  + *width + paddingRight + borderRight);
+            auto marginStart = computedHorizontalMargin.start.valueOr(0);
+            auto marginEnd = computedHorizontalMargin.end.valueOr(0);
+            auto centeredLogicalLeftForMarginBox = std::max((containingBlockWidth - borderBoxWidth - marginStart - marginEnd) / 2, 0_lu);
+            usedHorizontalMargin.start = centeredLogicalLeftForMarginBox + marginStart;
+            usedHorizontalMargin.end = containingBlockWidth - borderBoxWidth - marginStart + marginEnd;
+        }
         ASSERT(width);
 
         return ContentWidthAndMargin { *width, usedHorizontalMargin, computedHorizontalMargin };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to