Simple line layout: FlowContents::segmentIndexForRunSlow skips empty runs.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Apr 2017 22:48:22 +0000 (22:48 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Apr 2017 22:48:22 +0000 (22:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170552

Reviewed by Antti Koivisto.

Source/WebCore:

The compare function passed to std::lower_bound completely misses empty runs.

Test: fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html

* rendering/SimpleLineLayoutFlowContents.cpp:
(WebCore::SimpleLineLayout::FlowContents::segmentIndexForRunSlow):

LayoutTests:

* fast/text/simple-line-layout-hover-over-subsequent-linebreaks-expected.txt: Added.
* fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215124 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/text/simple-line-layout-hover-over-subsequent-linebreaks-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp
Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp

index 4630459..73dede4 100644 (file)
@@ -1,3 +1,13 @@
+2017-04-07  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: FlowContents::segmentIndexForRunSlow skips empty runs.
+        https://bugs.webkit.org/show_bug.cgi?id=170552
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text/simple-line-layout-hover-over-subsequent-linebreaks-expected.txt: Added.
+        * fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html: Added.
+
 2017-04-07  Ryan Haddad  <ryanhaddad@apple.com>
 
         Mark media/modern-media-controls/media-controller/media-controller-auto-hide-mouse-leave-after-play.html as flaky.
diff --git a/LayoutTests/fast/text/simple-line-layout-hover-over-subsequent-linebreaks-expected.txt b/LayoutTests/fast/text/simple-line-layout-hover-over-subsequent-linebreaks-expected.txt
new file mode 100644 (file)
index 0000000..0df4653
--- /dev/null
@@ -0,0 +1,6 @@
+Pass if no crash or assert.
+foobar
+
+foobar
+
+
diff --git a/LayoutTests/fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html b/LayoutTests/fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html
new file mode 100644 (file)
index 0000000..6fb3cad
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests hittest on subsequent linebreaks.</title>
+</head>
+<body>
+<div id=target>Pass if no crash or assert.<br>foobar<br><br>foobar<br><br></div>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+if (window.eventSender) {
+    var x = target.offsetLeft + target.offsetWidth / 2;
+    var y = target.offsetTop + target.offsetHeight - 2;
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown();
+}
+</script>
+</body>
+</html>
index 40dc4fd..5f45d3a 100644 (file)
@@ -1,3 +1,17 @@
+2017-04-07  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: FlowContents::segmentIndexForRunSlow skips empty runs.
+        https://bugs.webkit.org/show_bug.cgi?id=170552
+
+        Reviewed by Antti Koivisto.
+
+        The compare function passed to std::lower_bound completely misses empty runs. 
+
+        Test: fast/text/simple-line-layout-hover-over-subsequent-linebreaks.html
+
+        * rendering/SimpleLineLayoutFlowContents.cpp:
+        (WebCore::SimpleLineLayout::FlowContents::segmentIndexForRunSlow):
+
 2017-04-07  Chris Dumez  <cdumez@apple.com>
 
         We should log how much CPU a background process was using when killing it due to CPU limiting
index 0a95fa9..18e5b64 100644 (file)
@@ -68,14 +68,15 @@ FlowContents::FlowContents(const RenderBlockFlow& flow)
 
 unsigned FlowContents::segmentIndexForRunSlow(unsigned start, unsigned end) const
 {
-    auto it = std::lower_bound(m_segments.begin(), m_segments.end(), start, [](const Segment& segment, unsigned start) {
-        return segment.end <= start;
+    auto isEmptyRange = start == end;
+    auto it = std::lower_bound(m_segments.begin(), m_segments.end(), start, [isEmptyRange](const Segment& segment, unsigned start) {
+        // FIXME: This always find the first empty run (.vs subsequent <br> elements)
+        return (isEmptyRange && segment.start == segment.end) ? segment.start < start : segment.end <= start;
     });
     ASSERT(it != m_segments.end());
-    ASSERT_UNUSED(end, end <= it->end);
-    auto index = it - m_segments.begin();
-    m_lastSegmentIndex = index;
-    return index;
+    ASSERT(end <= it->end);
+    m_lastSegmentIndex = it - m_segments.begin();
+    return m_lastSegmentIndex;
 }
 
 }
index e09e1cd..5340583 100644 (file)
@@ -155,9 +155,9 @@ bool hitTestFlow(const RenderBlockFlow& flow, const Layout& layout, const HitTes
     for (auto it = range.begin(), end = range.end(); it != end; ++it) {
         auto lineRect = *it;
         lineRect.moveBy(accumulatedOffset);
+        auto& renderer = const_cast<RenderObject&>(it.renderer());
         if (!locationInContainer.intersects(lineRect))
             continue;
-        auto& renderer = const_cast<RenderObject&>(it.renderer());
         renderer.updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
         if (!result.addNodeToRectBasedTestResult(renderer.node(), request, locationInContainer, lineRect))
             return true;