Simple line layout: Hittest always returns the first renderer in the block.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Apr 2017 20:03:55 +0000 (20:03 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Apr 2017 20:03:55 +0000 (20:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170520
<rdar://problem/30979175>

Reviewed by Antti Koivisto.

Source/WebCore:

This is incorrect now with <br> support (multiple renderers within the same block flow).

Test: fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html

* rendering/RenderText.cpp:
(WebCore::RenderText::positionForPoint): Related fix. We don't yet support positionForPoint with multiple renderes.
* rendering/SimpleLineLayoutFlowContents.h:
(WebCore::SimpleLineLayout::FlowContents::segmentForRun): Empty runs are all valid.
* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::hitTestFlow):
(WebCore::SimpleLineLayout::collectFlowOverflow):
* rendering/SimpleLineLayoutResolver.cpp:
(WebCore::SimpleLineLayout::LineResolver::Iterator::operator*): This should eventually return a list of renderes.
* rendering/SimpleLineLayoutResolver.h:
(WebCore::SimpleLineLayout::RunResolver::flowContents):

LayoutTests:

* fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point-expected.html: Added.
* fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/SimpleLineLayoutFlowContents.h
Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp
Source/WebCore/rendering/SimpleLineLayoutResolver.cpp
Source/WebCore/rendering/SimpleLineLayoutResolver.h

index 146d0f9..769c018 100644 (file)
@@ -1,3 +1,14 @@
+2017-04-06  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Hittest always returns the first renderer in the block.
+        https://bugs.webkit.org/show_bug.cgi?id=170520
+        <rdar://problem/30979175>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point-expected.html: Added.
+        * fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html: Added.
+
 2017-03-31  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebCrypto] Add support for AES-CTR
diff --git a/LayoutTests/fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point-expected.html b/LayoutTests/fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point-expected.html
new file mode 100644 (file)
index 0000000..cb2f2b9
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that simple line layout hittest finds the same offset as normal line layout hittest.</title>
+<style>
+body {
+    margin: 0px;
+}
+
+div { 
+    line-height: 20px; 
+}
+</style>
+<script>
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+</head>
+<body>
+<div>f</div>
+<div>f<br>fo</div>
+<div>f<br>fo<br>foo</div>
+<div>f<br>fo<br>foo<br>foob</div>
+<div>f<br>fo<br>foo<br>foob<br>fooba</div>
+<div>f<br>fo<br>foo<br>foob<br>fooba<br>foobar</div>
+<script>
+var hittestResults = "";
+hittestResults += document.caretRangeFromPoint(5, 10).startOffset;
+hittestResults += document.caretRangeFromPoint(10, 50).startOffset;
+hittestResults += document.caretRangeFromPoint(12, 90).startOffset;
+hittestResults += document.caretRangeFromPoint(20, 190).startOffset;
+hittestResults += document.caretRangeFromPoint(25, 270).startOffset;
+hittestResults += document.caretRangeFromPoint(30, 410).startOffset;
+document.body.innerText = hittestResults
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html b/LayoutTests/fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html
new file mode 100644 (file)
index 0000000..5c63087
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that simple line layout hittest finds the same offset as normal line layout hittest.</title>
+<style>
+body {
+    margin: 0px;
+}
+
+div { 
+    line-height: 20px; 
+}
+</style>
+</head>
+<body>
+<div>f</div>
+<div>f<br>fo</div>
+<div>f<br>fo<br>foo</div>
+<div>f<br>fo<br>foo<br>foob</div>
+<div>f<br>fo<br>foo<br>foob<br>fooba</div>
+<div>f<br>fo<br>foo<br>foob<br>fooba<br>foobar</div>
+<script>
+var hittestResults = "";
+hittestResults += document.caretRangeFromPoint(5, 10).startOffset;
+hittestResults += document.caretRangeFromPoint(10, 50).startOffset;
+hittestResults += document.caretRangeFromPoint(12, 90).startOffset;
+hittestResults += document.caretRangeFromPoint(20, 190).startOffset;
+hittestResults += document.caretRangeFromPoint(25, 270).startOffset;
+hittestResults += document.caretRangeFromPoint(30, 410).startOffset;
+document.body.innerText = hittestResults
+</script>
+</body>
+</html>
index d9d4a06..78d70d2 100644 (file)
@@ -1,3 +1,27 @@
+2017-04-06  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Hittest always returns the first renderer in the block.
+        https://bugs.webkit.org/show_bug.cgi?id=170520
+        <rdar://problem/30979175>
+
+        Reviewed by Antti Koivisto.
+
+        This is incorrect now with <br> support (multiple renderers within the same block flow).
+
+        Test: fast/dom/Document/CaretRangeFromPoint/simple-line-layout-hittest-with-caret-range-from-point.html
+
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::positionForPoint): Related fix. We don't yet support positionForPoint with multiple renderes. 
+        * rendering/SimpleLineLayoutFlowContents.h:
+        (WebCore::SimpleLineLayout::FlowContents::segmentForRun): Empty runs are all valid.
+        * rendering/SimpleLineLayoutFunctions.cpp:
+        (WebCore::SimpleLineLayout::hitTestFlow):
+        (WebCore::SimpleLineLayout::collectFlowOverflow):
+        * rendering/SimpleLineLayoutResolver.cpp:
+        (WebCore::SimpleLineLayout::LineResolver::Iterator::operator*): This should eventually return a list of renderes.
+        * rendering/SimpleLineLayoutResolver.h:
+        (WebCore::SimpleLineLayout::RunResolver::flowContents):
+
 2017-04-06  Jon Davis  <jond@apple.com>
 
         Updates feature status for recently shipped features
index eb27f66..2c88ac5 100644 (file)
@@ -443,8 +443,8 @@ Vector<FloatQuad> RenderText::absoluteQuadsForRange(unsigned start, unsigned end
 
 Position RenderText::positionForPoint(const LayoutPoint& point)
 {
-    if (auto* layout = simpleLineLayout()) {
-        auto position = Position(textNode(), SimpleLineLayout::textOffsetForPoint(point, *this, *layout));
+    if (simpleLineLayout() && parent()->firstChild() == parent()->lastChild()) {
+        auto position = Position(textNode(), SimpleLineLayout::textOffsetForPoint(point, *this, *simpleLineLayout()));
         ASSERT(position == positionForPoint(point, nullptr).deepEquivalent());
         return position;
     }
index c1cf5a0..1a7d655 100644 (file)
@@ -63,7 +63,7 @@ private:
 
 inline const FlowContents::Segment& FlowContents::segmentForRun(unsigned start, unsigned end) const
 {
-    ASSERT(start < end);
+    ASSERT(start <= end);
     auto& lastSegment = m_segments[m_lastSegmentIndex];
     if (lastSegment.start <= start && end <= lastSegment.end)
         return m_segments[m_lastSegmentIndex];
index 5335de6..e09e1cd 100644 (file)
@@ -148,20 +148,20 @@ bool hitTestFlow(const RenderBlockFlow& flow, const Layout& layout, const HitTes
     if (style.visibility() != VISIBLE || style.pointerEvents() == PE_NONE)
         return false;
 
-    RenderObject& renderer = *flow.firstChild();
     LayoutRect rangeRect = locationInContainer.boundingBox();
     rangeRect.moveBy(-accumulatedOffset);
-
     auto resolver = lineResolver(flow, layout);
-    for (FloatRect lineRect : resolver.rangeForRect(rangeRect)) {
+    auto range = resolver.rangeForRect(rangeRect);
+    for (auto it = range.begin(), end = range.end(); it != end; ++it) {
+        auto lineRect = *it;
         lineRect.moveBy(accumulatedOffset);
         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;
     }
-
     return false;
 }
 
index 2ec55db..f2fbd9a 100644 (file)
@@ -272,7 +272,7 @@ LineResolver::Iterator::Iterator(RunResolver::Iterator runIterator)
 {
 }
 
-const FloatRect LineResolver::Iterator::operator*() const
+FloatRect LineResolver::Iterator::operator*() const
 {
     unsigned currentLine = m_runIterator.lineIndex();
     auto it = m_runIterator;
@@ -282,6 +282,13 @@ const FloatRect LineResolver::Iterator::operator*() const
     return rect;
 }
 
+const RenderObject& LineResolver::Iterator::renderer() const
+{
+    // FIXME: This works as long as we've got only one renderer per line.
+    auto run = *m_runIterator;
+    return m_runIterator.resolver().flowContents().segmentForRun(run.start(), run.end()).renderer;
+}
+
 LineResolver::LineResolver(const RenderBlockFlow& flow, const Layout& layout)
     : m_runResolver(flow, layout)
 {
index 304d634..b4c2d37 100644 (file)
@@ -98,6 +98,7 @@ public:
     RunResolver(const RenderBlockFlow&, const Layout&);
 
     const RenderBlockFlow& flow() const { return m_flowRenderer; }
+    const FlowContents& flowContents() const { return m_flowContents; }
     Iterator begin() const;
     Iterator end() const;
 
@@ -125,8 +126,6 @@ private:
 
 class LineResolver {
 public:
-    class Iterator;
-
     class Iterator {
     public:
         explicit Iterator(RunResolver::Iterator);
@@ -135,11 +134,12 @@ public:
         bool operator==(const Iterator&) const;
         bool operator!=(const Iterator&) const;
 
-        const FloatRect operator*() const;
+        FloatRect operator*() const;
+        // FIXME: Use a list to support multiple renderers per line.
+        const RenderObject& renderer() const;
 
     private:
         RunResolver::Iterator m_runIterator;
-        LayoutRect m_rect;
     };
 
     LineResolver(const RenderBlockFlow&, const Layout&);