Merge 3809: [LayoutNG] Fix negative margin in RTL
When there're negative inline margins, |ResolveInlineMargins|
computes incorrect inline-end margin, which affects line
offset in RTL. The inline-end margin computed here is not
used for layout in LTR that the problem was visible only in
RTL.
(cherry picked from commit 39c4a9924378db8c51ab3769a66efa3b1e71f203)
Bug: 971403
Change-Id: I8cfc6e303649d66b91c95ed1f7a30295c67bcad6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1647907
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#667647}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1653750
Reviewed-by: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#236}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc b/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc
index 662f0d2..9b9feab 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc
@@ -1022,8 +1022,14 @@
auto_margins.inline_end = opportunity.rect.InlineSize() -
fragment.InlineSize() - auto_margins.inline_start;
} else {
+ LayoutUnit inline_size = fragment.InlineSize();
+ // Negative margins are not used to determine opportunity, but need to take
+ // them into account for positioning.
+ LayoutUnit inline_margin = child_data.margins.InlineSum();
+ if (inline_margin < 0)
+ inline_size += inline_margin;
ResolveInlineMargins(child_style, Style(), opportunity.rect.InlineSize(),
- fragment.InlineSize(), &auto_margins);
+ inline_size, &auto_margins);
}
LayoutUnit child_bfc_line_offset = opportunity.rect.start_offset.line_offset +
diff --git a/third_party/blink/web_tests/external/wpt/css/CSS2/normal-flow/negative-margin-001-ref.html b/third_party/blink/web_tests/external/wpt/css/CSS2/normal-flow/negative-margin-001-ref.html
new file mode 100644
index 0000000..e98059a
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/css/CSS2/normal-flow/negative-margin-001-ref.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<style>
+html, body {
+ margin: 0;
+}
+html {
+ margin-left: 10px;
+}
+outer {
+ display: block;
+ border: blue 10px solid;
+ width: 100px;
+}
+inner {
+ display: block;
+ border: orange 10px solid;
+ margin-left: -20px;
+ margin-right: -50px;
+ height: 10px;
+}
+</style>
+<body>
+ <outer>
+ <inner></inner>
+ </outer>
+ <outer>
+ <inner></inner>
+ </outer>
+ <outer>
+ <inner></inner>
+ </outer>
+ <outer>
+ <inner></inner>
+ </outer>
+</body>
diff --git a/third_party/blink/web_tests/external/wpt/css/CSS2/normal-flow/negative-margin-001.html b/third_party/blink/web_tests/external/wpt/css/CSS2/normal-flow/negative-margin-001.html
new file mode 100644
index 0000000..597516d5
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/css/CSS2/normal-flow/negative-margin-001.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<title>Negative margins in LTR/RTL and BFC/non-BFC</title>
+<link rel="author" title="Koji Ishii" href="kojii@chromium.org">
+<link rel="help" href="https://www.w3.org/TR/CSS22/box.html#margin-properties" title="Margin properties">
+<link rel="match" href="negative-margin-001-ref.html">
+<style>
+html, body {
+ margin: 0;
+}
+html {
+ margin-left: 10px;
+}
+outer {
+ display: block;
+ border: blue 10px solid;
+ width: 100px;
+}
+inner {
+ display: block;
+ border: orange 10px solid;
+ margin-left: -20px;
+ margin-right: -50px;
+ height: 10px;
+}
+inner.bfc {
+ overflow: hidden;
+}
+</style>
+<body>
+ <outer>
+ <inner></inner>
+ </outer>
+ <outer dir="rtl">
+ <inner></inner>
+ </outer>
+ <outer>
+ <inner class="bfc"></inner>
+ </outer>
+ <outer dir="rtl">
+ <inner class="bfc"></inner>
+ </outer>
+</body>