Commit d2427961 authored by weinig@apple.com's avatar weinig@apple.com

WebCore: Fix for https://bugs.webkit.org/show_bug.cgi?id=29219

Document.elementFromPoint() should take page scroll into consideration

Reviewed by Anders Carlsson.

Test: fast/dom/elementFromPoint-relative-to-viewport.html

* dom/Document.cpp:
(WebCore::Document::elementFromPoint):
(WebCore::Document::caretRangeFromPoint):

LayoutTests: Test for https://bugs.webkit.org/show_bug.cgi?id=29219
Document.elementFromPoint() should take page scroll into consideration

Reviewed by Anders Carlsson.

* fast/dom/elementFromPoint-relative-to-viewport-expected.txt: Added.
* fast/dom/elementFromPoint-relative-to-viewport.html: Added.
* fast/events/offsetX-offsetY.html: Change to use clientX/Y instead of pageX/Y.
* fast/forms/slider-transformed.html: Ditto.
* fast/forms/slider-zoomed.html: Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48334 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4ff6c71c
2009-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Anders Carlsson.
Test for https://bugs.webkit.org/show_bug.cgi?id=29219
Document.elementFromPoint() should take page scroll into consideration
* fast/dom/elementFromPoint-relative-to-viewport-expected.txt: Added.
* fast/dom/elementFromPoint-relative-to-viewport.html: Added.
* fast/events/offsetX-offsetY.html: Change to use clientX/Y instead of pageX/Y.
* fast/forms/slider-transformed.html: Ditto.
* fast/forms/slider-zoomed.html: Ditto.
2009-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Maciej Stachowiak.
......
This test document.elementFromPoint is evaluated in with respect to the viewport, not the document.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS unscrolledBox is '0'
PASS scrolledDownBox is '15'
PASS scrolledRightBox is '3'
PASS scrolledDownAndRightBox is '18'
PASS successfullyParsed is true
TEST COMPLETE
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<style>
#test {
width: 100px;
outline: 1px solid black;
}
.testItem {
z-index: 100;
display: inline-block;
width: 20px;
height: 20px;
outline: 1px solid red;
}
#pusher {
width: 1000px;
height: 1000px;
outline: 1px solid black;
}
</style>
<p id="description"></p>
<div id="console"></div>
<div id="testArea">
<br>
<div id="test"></div>
<div id="pusher">This box is here to create scrollbars.</div>
</div>
<script>
window.onclick = function(e)
{
alert(e.clientX + " " + e.clientY + " " + document.elementFromPoint(e.clientX, e.clientY).textContent);
}
if (window.layoutTestController)
layoutTestController.dumpAsText();
var element = document.getElementById('test');
for (var i = 0; i < 25; ++i) {
var item = document.createElement("div");
item.className = "testItem";
item.textContent = String(i);
element.appendChild(item);
}
description('This test document.elementFromPoint is evaluated in with respect to the viewport, not the document.');
var unScrolledBoundingBox = element.getBoundingClientRect();
var testX = unScrolledBoundingBox.left + 10;
var testY = unScrolledBoundingBox.top + 10;
// Get initial box.
var unscrolledBox = document.elementFromPoint(testX, testY).textContent;
// Test scrolling down
window.scrollTo(0, 50);
var scrolledDownBox = document.elementFromPoint(testX, testY).textContent;
// Test scrolling right
window.scrollTo(50, 0);
var scrolledRightBox = document.elementFromPoint(testX, testY).textContent;
// Test scrolling down and right
window.scrollTo(50, 50);
var scrolledDownAndRightBox = document.elementFromPoint(testX, testY).textContent;
// Reset
window.scrollTo(0, 0);
shouldBe("unscrolledBox", "'0'");
shouldBe("scrolledDownBox", "'15'");
shouldBe("scrolledRightBox", "'3'");
shouldBe("scrolledDownAndRightBox", "'18'");
if (window.layoutTestController) {
var area = document.getElementById('testArea');
area.parentNode.removeChild(area);
}
successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
......@@ -52,7 +52,7 @@
ev.expectedElement = expectedElementID;
ev.expectedOffsetX = expectedOffsetX;
ev.expectedOffsetY = expectedOffsetY;
var target = document.elementFromPoint(ev.pageX, ev.pageY);
var target = document.elementFromPoint(ev.clientX, ev.clientY);
target.dispatchEvent(ev);
}
......
......@@ -21,7 +21,7 @@
{
var ev = document.createEvent("MouseEvent");
ev.initMouseEvent(eventType, true, true, window, 1, 1, 1, clientX, clientY, false, false, false, false, 0, document);
var target = document.elementFromPoint(ev.pageX, ev.pageY);
var target = document.elementFromPoint(ev.clientX, ev.clientY);
target.dispatchEvent(ev);
}
......
......@@ -22,7 +22,7 @@
{
var ev = document.createEvent("MouseEvent");
ev.initMouseEvent(eventType, true, true, window, 1, 1, 1, clientX, clientY, false, false, false, false, 0, document);
var target = document.elementFromPoint(ev.pageX, ev.pageY);
var target = document.elementFromPoint(ev.clientX, ev.clientY);
target.dispatchEvent(ev);
}
......
2009-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Anders Carlsson.
Fix for https://bugs.webkit.org/show_bug.cgi?id=29219
Document.elementFromPoint() should take page scroll into consideration
Test: fast/dom/elementFromPoint-relative-to-viewport.html
* dom/Document.cpp:
(WebCore::Document::elementFromPoint):
(WebCore::Document::caretRangeFromPoint):
2009-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Maciej Stachowiak.
......@@ -927,16 +927,25 @@ KURL Document::baseURI() const
Element* Document::elementFromPoint(int x, int y) const
{
// FIXME: Share code between this and caretRangeFromPoint.
if (!renderer())
return 0;
Frame* frame = this->frame();
if (!frame)
return 0;
FrameView* frameView = frame->view();
if (!frameView)
return 0;
HitTestRequest request(HitTestRequest::ReadOnly |
HitTestRequest::Active);
float zoomFactor = frame->pageZoomFactor();
IntPoint point = roundedIntPoint(FloatPoint(x * zoomFactor, y * zoomFactor)) + view()->scrollOffset();
float zoomFactor = frame() ? frame()->pageZoomFactor() : 1.0f;
if (!frameView->boundsRect().contains(point))
return 0;
HitTestResult result(roundedIntPoint(FloatPoint(x * zoomFactor, y * zoomFactor)));
renderView()->layer()->hitTest(request, result);
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
HitTestResult result(point);
renderView()->layer()->hitTest(request, result);
Node* n = result.innerNode();
while (n && !n->isElementNode())
......@@ -948,6 +957,7 @@ Element* Document::elementFromPoint(int x, int y) const
PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
{
// FIXME: Share code between this and elementFromPoint.
if (!renderer())
return 0;
Frame* frame = this->frame();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment