Restore pre-r118852 behavior for EllipsisBox::nodeAtPoint()
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Feb 2013 01:48:09 +0000 (01:48 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Feb 2013 01:48:09 +0000 (01:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109277

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/flexbox/line-clamp-link-after-ellipsis.html

Roll out r118852. Enough time has passed that this can't be done
mechanically, so transcribe the old method definition to current
WebCore interfaces.

* rendering/EllipsisBox.cpp:
(WebCore::EllipsisBox::markupBox): EllipsisBox no longer has
m_markupBox, so break the logic for finding the markup box from
paintMarkupBox() into its own function.
(WebCore::EllipsisBox::paintMarkupBox): Call markupBox().
(WebCore::EllipsisBox::nodeAtPoint): Transcribe the pre-r118852 implementation.
* rendering/EllipsisBox.h:
(EllipsisBox): Declare markupBox().

LayoutTests:

Remove test added by r118852 and add a test that verifies the original
expected behavior.

* fast/css/text-overflow-ellipsis-hit-test-expected.txt: Removed.
* fast/css/text-overflow-ellipsis-hit-test.html: Removed.
* fast/flexbox/line-clamp-link-after-ellipsis-expected.txt: Added.
* fast/flexbox/line-clamp-link-after-ellipsis.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/css/text-overflow-ellipsis-hit-test-expected.txt [deleted file]
LayoutTests/fast/css/text-overflow-ellipsis-hit-test.html [deleted file]
LayoutTests/fast/flexbox/line-clamp-link-after-ellipsis-expected.txt [new file with mode: 0644]
LayoutTests/fast/flexbox/line-clamp-link-after-ellipsis.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/EllipsisBox.cpp
Source/WebCore/rendering/EllipsisBox.h

index ab3b82dfaf8bf0a965f1d31f34a58284b8b092fd..e7712d0a2bb44689e088f659bbd3f125cb89e4e7 100644 (file)
@@ -1,3 +1,18 @@
+2013-02-08  Andy Estes  <aestes@apple.com>
+
+        Restore pre-r118852 behavior for EllipsisBox::nodeAtPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=109277
+
+        Reviewed by Simon Fraser.
+
+        Remove test added by r118852 and add a test that verifies the original
+        expected behavior.
+
+        * fast/css/text-overflow-ellipsis-hit-test-expected.txt: Removed.
+        * fast/css/text-overflow-ellipsis-hit-test.html: Removed.
+        * fast/flexbox/line-clamp-link-after-ellipsis-expected.txt: Added.
+        * fast/flexbox/line-clamp-link-after-ellipsis.html: Added.
+
 2013-02-08  Stephen Chenney  <schenney@chromium.org>
 
         [Chromium] Expectation modification after r142327
diff --git a/LayoutTests/fast/css/text-overflow-ellipsis-hit-test-expected.txt b/LayoutTests/fast/css/text-overflow-ellipsis-hit-test-expected.txt
deleted file mode 100644 (file)
index e39a09e..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-This tests the hit-testing of text-overflow:ellipsis. Click and hover events should be unaffected by the ellipsis.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS test.firstElementChild.textContent is "clicked"
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/fast/css/text-overflow-ellipsis-hit-test.html b/LayoutTests/fast/css/text-overflow-ellipsis-hit-test.html
deleted file mode 100644 (file)
index a177eac..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<style>
-#test {
-text-overflow: ellipsis;
-width: 3em;
-overflow: hidden;
-white-space: nowrap;
-position: absolute;
-left: 10px;
-top: 10px;
-font-size: 20px;
-font-family: ahem;
-}
-</style>
-<script src="../js/resources/js-test-pre.js"></script>
-</head>
-<body>
-<div id="test"><a href="#" onclick="this.textContent='clicked'">unclicked</a></div>
-<script>
-description('This tests the hit-testing of text-overflow:ellipsis. Click and hover events should be unaffected by the ellipsis.');
-
-var test = document.getElementById("test");
-
-if (window.eventSender) {
-  eventSender.mouseMoveTo(40, 20);
-  eventSender.mouseDown();
-  eventSender.mouseUp();
-}
-
-shouldBeEqualToString("test.firstElementChild.textContent", "clicked");
-
-// Clean up after ourselves
-test.parentNode.removeChild(test);
-</script>
-<script src="../js/resources/js-test-post.js"></script>
-</body>
-</html>
diff --git a/LayoutTests/fast/flexbox/line-clamp-link-after-ellipsis-expected.txt b/LayoutTests/fast/flexbox/line-clamp-link-after-ellipsis-expected.txt
new file mode 100644 (file)
index 0000000..f471434
--- /dev/null
@@ -0,0 +1,12 @@
+Test that links painted after the ellipsis of a flexbox using -webkit-line-clamp is hit-testable.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.getElementsByTagName('a')[0].textContent is "clicked"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+line one
+line twoclicked
+
diff --git a/LayoutTests/fast/flexbox/line-clamp-link-after-ellipsis.html b/LayoutTests/fast/flexbox/line-clamp-link-after-ellipsis.html
new file mode 100644 (file)
index 0000000..c17d5ed
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+<style>
+span#container {
+    display: inline-block; /* clamp the width of the enclosing P to its contents */
+}
+
+div#flexbox {
+    -webkit-box-orient: vertical;
+    -webkit-line-clamp: 1;
+    display: -webkit-box;
+    overflow-y: hidden;
+}
+</style>
+</head>
+<body>
+<span id="container">
+    <div id="flexbox">line one<br>line two<a id="link" href="#" onclick="this.textContent='clicked'">not clicked</a></div>
+</span>
+<script>
+description('Test that links painted after the ellipsis of a flexbox using -webkit-line-clamp is hit-testable.');
+
+var divRect = document.getElementById("flexbox").getBoundingClientRect();
+var aRect = document.getElementById("link").getBoundingClientRect();
+var clickX = divRect.left + divRect.width - (aRect.width / 2);
+var clickY = divRect.top + divRect.height  - (aRect.height / 2);
+
+if (window.eventSender) {
+    eventSender.mouseMoveTo(clickX, clickY);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
+
+shouldBeEqualToString("document.getElementsByTagName('a')[0].textContent", "clicked");
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index afedc07489ac7aeae8c4f7d8ccabad194b7cc8b4..dc5c86f6d965b546e158a03ab3a63c4e6975de55 100644 (file)
@@ -1,3 +1,25 @@
+2013-02-08  Andy Estes  <aestes@apple.com>
+
+        Restore pre-r118852 behavior for EllipsisBox::nodeAtPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=109277
+
+        Reviewed by Simon Fraser.
+
+        Test: fast/flexbox/line-clamp-link-after-ellipsis.html
+
+        Roll out r118852. Enough time has passed that this can't be done
+        mechanically, so transcribe the old method definition to current
+        WebCore interfaces.
+
+        * rendering/EllipsisBox.cpp:
+        (WebCore::EllipsisBox::markupBox): EllipsisBox no longer has
+        m_markupBox, so break the logic for finding the markup box from
+        paintMarkupBox() into its own function.
+        (WebCore::EllipsisBox::paintMarkupBox): Call markupBox().
+        (WebCore::EllipsisBox::nodeAtPoint): Transcribe the pre-r118852 implementation.
+        * rendering/EllipsisBox.h:
+        (EllipsisBox): Declare markupBox().
+
 2013-02-08  Eric Carlson  <eric.carlson@apple.com>
 
         [Mac] In-band closed caption tracks are not always initialized correctly
index 0f03f1d0f4f130884f4cc2ee8753c5dcb3d111d3..3f7c92593405dcc9fd38da8da3f201b6c0aeba7a 100644 (file)
@@ -69,26 +69,35 @@ void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La
     paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style);
 }
 
-void EllipsisBox::paintMarkupBox(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, RenderStyle* style)
+InlineBox* EllipsisBox::markupBox() const
 {
     if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock())
-        return;
+        return 0;
 
     RenderBlock* block = toRenderBlock(m_renderer);
     RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1);
     if (!lastLine)
-        return;
+        return 0;
 
     // If the last line-box on the last line of a block is a link, -webkit-line-clamp paints that box after the ellipsis.
     // It does not actually move the link.
     InlineBox* anchorBox = lastLine->lastChild();
     if (!anchorBox || !anchorBox->renderer()->style()->isLink())
+        return 0;
+
+    return anchorBox;
+}
+
+void EllipsisBox::paintMarkupBox(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, RenderStyle* style)
+{
+    InlineBox* markupBox = this->markupBox();
+    if (!markupBox)
         return;
 
     LayoutPoint adjustedPaintOffset = paintOffset;
-    adjustedPaintOffset.move(x() + m_logicalWidth - anchorBox->x(),
-        y() + style->fontMetrics().ascent() - (anchorBox->y() + anchorBox->renderer()->style(isFirstLineStyle())->fontMetrics().ascent()));
-    anchorBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom);
+    adjustedPaintOffset.move(x() + m_logicalWidth - markupBox->x(),
+        y() + style->fontMetrics().ascent() - (markupBox->y() + markupBox->renderer()->style(isFirstLineStyle())->fontMetrics().ascent()));
+    markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom);
 }
 
 IntRect EllipsisBox::selectionRect()
@@ -121,8 +130,28 @@ void EllipsisBox::paintSelection(GraphicsContext* context, const LayoutPoint& pa
     context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), roundedIntPoint(LayoutPoint(x() + paintOffset.x(), y() + paintOffset.y() + top)), h, c, style->colorSpace());
 }
 
-bool EllipsisBox::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, LayoutUnit, LayoutUnit)
+bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
 {
+    LayoutPoint adjustedLocation = accumulatedOffset + roundedLayoutPoint(topLeft());
+
+    // Hit test the markup box.
+    if (InlineBox* markupBox = this->markupBox()) {
+        RenderStyle* style = m_renderer->style(isFirstLineStyle());
+        LayoutUnit mtx = adjustedLocation.x() + m_logicalWidth - markupBox->x();
+        LayoutUnit mty = adjustedLocation.y() + style->fontMetrics().ascent() - (markupBox->y() + markupBox->renderer()->style(isFirstLineStyle())->fontMetrics().ascent());
+        if (markupBox->nodeAtPoint(request, result, locationInContainer, LayoutPoint(mtx, mty), lineTop, lineBottom)) {
+            renderer()->updateHitTestResult(result, locationInContainer.point() - LayoutSize(mtx, mty));
+            return true;
+        }
+    }
+
+    LayoutRect boundsRect(adjustedLocation, LayoutSize(m_logicalWidth, m_height));
+    if (visibleToHitTesting() && boundsRect.intersects(HitTestLocation::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) {
+        renderer()->updateHitTestResult(result, locationInContainer.point() - toLayoutSize(adjustedLocation));
+        if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, locationInContainer, boundsRect))
+            return true;
+    }
+
     return false;
 }
 
index 699767847e606f4f9688a6185142cb199ed8a533..f1fb0d1e7b0d5d3dee89ac99f2254b6f72e21501 100644 (file)
@@ -49,6 +49,7 @@ private:
     virtual int height() const { return m_height; }
     virtual RenderObject::SelectionState selectionState() { return m_selectionState; }
     void paintSelection(GraphicsContext*, const LayoutPoint&, RenderStyle*, const Font&);
+    InlineBox* markupBox() const;
 
     bool m_shouldPaintMarkupBox;
     int m_height;