[go: up one dir, main page]

Place list markers correctly when the line has shifted to avoid floats

Bug: 784793
Change-Id: Ib41a9a940acddf8737c261c3d14b39bf683aece4
Reviewed-on: https://chromium-review.googlesource.com/789930
Commit-Queue: Robert Hogan <robhogan@gmail.com>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520689}
diff --git a/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-5-expected.html b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-5-expected.html
new file mode 100644
index 0000000..ea2726cf
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-5-expected.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<style>
+.float {
+  float: left;
+  width: 100%;
+  background: lightgray;
+}
+</style>
+<p>crbug.com/784793: The list marker should be to the left not the right.</p>
+<div>
+  <div class="float">float</div>
+  <ul>
+    <li>
+      a
+    </li>
+  </ul>
+</div>
diff --git a/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-5.html b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-5.html
new file mode 100644
index 0000000..50ec3b9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-5.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<style>
+.float {
+  float: left;
+  width: 100%;
+  background: lightgray;
+}
+</style>
+<p>crbug.com/784793: The list marker should be to the left not the right.</p>
+<div>
+  <div class="float">float</div>
+  <ul>
+    <li>
+    <script>
+      document.body.offsetTop;
+    </script>
+      a
+    </li>
+  </ul>
+</div>
diff --git a/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-6-expected.html b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-6-expected.html
new file mode 100644
index 0000000..35a699c8
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-6-expected.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<style>
+.float {
+  float: left;
+  width: 100%;
+  background: lightgray;
+}
+</style>
+<p>crbug.com/784793: The list marker should be to the left not the right.</p>
+<div style="direction:rtl">
+  <div class="float">float</div>
+  <ul>
+    <li>
+      a
+    </li>
+  </ul>
+</div>
diff --git a/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-6.html b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-6.html
new file mode 100644
index 0000000..9b440fd
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/lists/list-marker-avoid-float-6.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<style>
+.float {
+  float: left;
+  width: 100%;
+  background: lightgray;
+}
+</style>
+<p>crbug.com/784793: The list marker should be to the left not the right.</p>
+<div style="direction:rtl">
+  <div class="float">float</div>
+  <ul>
+    <li>
+    <script>
+      document.body.offsetTop;
+    </script>
+      a
+    </li>
+  </ul>
+</div>
diff --git a/third_party/WebKit/Source/core/layout/LayoutListItem.cpp b/third_party/WebKit/Source/core/layout/LayoutListItem.cpp
index e0493e2..8aa15ff 100644
--- a/third_party/WebKit/Source/core/layout/LayoutListItem.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutListItem.cpp
@@ -343,13 +343,22 @@
     if (need_block_direction_align_)
       AlignMarkerInBlockDirection();
 
+    // We figured out the inline position of the marker before laying out the
+    // line so that floats later in the line don't interfere with it. However
+    // if the line has shifted down then that position will be too far out.
+    // So we always take the lowest value of (1) the position of the marker
+    // if we calculate it now and (2) the inline position we calculated before
+    // laying out the line.
     // TODO(jchaffraix): Propagating the overflow to the line boxes seems
     // pretty wrong (https://crbug.com/554160).
     // FIXME: Need to account for relative positioning in the layout overflow.
     if (Style()->IsLeftToRightDirection()) {
-      marker_logical_left = marker_->LineOffset() - line_offset -
-                            PaddingStart() - BorderStart() +
-                            marker_->MarginStart();
+      LayoutUnit marker_line_offset =
+          std::min(marker_->LineOffset(),
+                   LogicalLeftOffsetForLine(marker_->LogicalTop(),
+                                            kDoNotIndentText, LayoutUnit()));
+      marker_logical_left = marker_line_offset - line_offset - PaddingStart() -
+                            BorderStart() + marker_->MarginStart();
       marker_->InlineBoxWrapper()->MoveInInlineDirection(
           marker_logical_left - marker_old_logical_left);
       for (InlineFlowBox* box = marker_->InlineBoxWrapper()->Parent(); box;
@@ -380,9 +389,12 @@
           hit_self_painting_layer = true;
       }
     } else {
-      marker_logical_left = marker_->LineOffset() - line_offset +
-                            PaddingStart() + BorderStart() +
-                            marker_->MarginEnd();
+      LayoutUnit marker_line_offset =
+          std::max(marker_->LineOffset(),
+                   LogicalRightOffsetForLine(marker_->LogicalTop(),
+                                             kDoNotIndentText, LayoutUnit()));
+      marker_logical_left = marker_line_offset - line_offset + PaddingStart() +
+                            BorderStart() + marker_->MarginEnd();
       marker_->InlineBoxWrapper()->MoveInInlineDirection(
           marker_logical_left - marker_old_logical_left);
       for (InlineFlowBox* box = marker_->InlineBoxWrapper()->Parent(); box;