2009-03-04 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Mar 2009 19:58:46 +0000 (19:58 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Mar 2009 19:58:46 +0000 (19:58 +0000)
        Reviewed by Dave Hyatt

        https://bugs.webkit.org/show_bug.cgi?id=24361

        Reinstate code that sets result.innerNode when hitTest() returns true,
        but never filled in the innerNode. Fixes hit testing of generated content.

        Test: fast/css-generated-content/hit-test-generated-content.html

        * rendering/RenderLayer.cpp:
        (WebCore::RenderLayer::hitTestContents):

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

LayoutTests/ChangeLog
LayoutTests/fast/css-generated-content/hit-test-generated-content.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/RenderLayer.cpp

index 058d9675f26ea8d8644d7cb1ca79c6c22defbdf1..0fe64c0fd9ce8fdbecf7716e75b22273782a64e3 100644 (file)
@@ -1,3 +1,16 @@
+2009-03-04  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Dave Hyatt
+        
+        https://bugs.webkit.org/show_bug.cgi?id=24361
+        
+        Test hit testing on generated content.
+
+        * fast/css-generated-content/hit-test-generated-content.html: Added.
+        * platform/mac/fast/css-generated-content/hit-test-generated-content-expected.checksum: Added.
+        * platform/mac/fast/css-generated-content/hit-test-generated-content-expected.png: Added.
+        * platform/mac/fast/css-generated-content/hit-test-generated-content-expected.txt: Added.
+
 2009-03-03  David Hyatt  <hyatt@apple.com>
 
         Test case for https://bugs.webkit.org/show_bug.cgi?id=24201
diff --git a/LayoutTests/fast/css-generated-content/hit-test-generated-content.html b/LayoutTests/fast/css-generated-content/hit-test-generated-content.html
new file mode 100644 (file)
index 0000000..70a048a
--- /dev/null
@@ -0,0 +1,42 @@
+<html>
+<head>
+<style>
+#target {
+  position: relative;
+  width: 100px;
+  height: 100px;
+}
+
+#target::before {
+  position: absolute;
+  top: 0;
+  left: 0;
+  width: 100%;
+  height: 100%;
+  background-color: gray;
+  content: "";
+}
+
+</style>
+<script type="text/javascript" charset="utf-8">
+  function runTest()
+  {
+    var hitElement = document.elementFromPoint(58, 58);
+    var results = document.getElementById('results')
+    if (hitElement && hitElement.id == 'target')
+      results.innerHTML = 'elementFromPoint found target: PASS';
+    else
+      results.innerHTML = 'elementFromPoint did not find target: FAIL';
+  }
+</script>
+</head>
+<body onload="runTest()">
+
+<p>Tests hit testing on generated content</p>
+<div id="target">&nbsp;</div>
+
+<div id="results">
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.checksum b/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.checksum
new file mode 100644 (file)
index 0000000..c1a8bf9
--- /dev/null
@@ -0,0 +1 @@
+210c1269c3953dda51ca2c819ca6fd0c
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.png b/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.png
new file mode 100644 (file)
index 0000000..94b3e4d
Binary files /dev/null and b/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.txt b/LayoutTests/platform/mac/fast/css-generated-content/hit-test-generated-content-expected.txt
new file mode 100644 (file)
index 0000000..8b90e16
--- /dev/null
@@ -0,0 +1,18 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 233x18
+          text run at (0,0) width 233: "Tests hit testing on generated content"
+      RenderBlock {DIV} at (0,134) size 784x18
+        RenderText {#text} at (0,0) size 243x18
+          text run at (0,0) width 243: "elementFromPoint found target: PASS"
+layer at (8,42) size 100x100
+  RenderBlock (relative positioned) {DIV} at (0,34) size 100x100
+    RenderText {#text} at (0,0) size 4x18
+      text run at (0,0) width 4: " "
+layer at (8,42) size 100x100
+  RenderBlock (positioned) at (0,0) size 100x100 [bgcolor=#808080]
+    RenderText at (0,0) size 0x0
index 98cc1d240550552a9080e3821c3b0b2aa63da595..9e1ac3a652ca299a6c87486974bae8b0a5cabbc8 100644 (file)
@@ -1,3 +1,17 @@
+2009-03-04  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Dave Hyatt
+        
+        https://bugs.webkit.org/show_bug.cgi?id=24361
+        
+        Reinstate code that sets result.innerNode when hitTest() returns true,
+        but never filled in the innerNode. Fixes hit testing of generated content.
+
+        Test: fast/css-generated-content/hit-test-generated-content.html
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::hitTestContents):
+
 2009-03-04  Adam Barth  <abath@webkit.org>
 
         Reviewed by Alexey Proskuryakov.
index 409292479a3d33cd4942e380c900c5fb8c90d509..a9e0d369330a6ff3e513945e92cc57c229bd37ec 100644 (file)
@@ -2382,10 +2382,25 @@ RenderLayer* RenderLayer::hitTestLayer(RenderLayer* rootLayer, RenderLayer* cont
 
 bool RenderLayer::hitTestContents(const HitTestRequest& request, HitTestResult& result, const IntRect& layerBounds, const IntPoint& hitTestPoint, HitTestFilter hitTestFilter) const
 {
-    return renderer()->hitTest(request, result, hitTestPoint,
+    if (!renderer()->hitTest(request, result, hitTestPoint,
                             layerBounds.x() - renderBoxX(),
                             layerBounds.y() - renderBoxY(), 
-                            hitTestFilter);
+                            hitTestFilter))
+        return false;
+
+    // For positioned generated content, we might still not have a
+    // node by the time we get to the layer level, since none of
+    // the content in the layer has an element. So just walk up
+    // the tree.
+    if (!result.innerNode() || !result.innerNonSharedNode()) {
+        Node* e = enclosingElement();
+        if (!result.innerNode())
+            result.setInnerNode(e);
+        if (!result.innerNonSharedNode())
+            result.setInnerNonSharedNode(e);
+    }
+        
+    return true;
 }
 
 void RenderLayer::updateClipRects(const RenderLayer* rootLayer)