Commit 4ff6c71c authored by weinig@apple.com's avatar weinig@apple.com

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

Document.caretRangeFromPoint should take the scroll offset into account before hit testing

Reviewed by Maciej Stachowiak.

In accordance with the CSSOM View Module spec, Document.caretRangeFromPoint should interpret
the point passed to it as relative to the viewport, not the document.

Test: fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html

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

LayoutTests: Test for https://bugs.webkit.org/show_bug.cgi?id=29217
Document.caretRangeFromPoint should take the scroll offset into account before hit testing

Reviewed by Maciej Stachowiak.

* fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt: Added.
* fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48333 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent de8887b1
2009-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Maciej Stachowiak.
Test for https://bugs.webkit.org/show_bug.cgi?id=29217
Document.caretRangeFromPoint should take the scroll offset into account before hit testing
* fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt: Added.
* fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html: Added.
2009-09-11 Oliver Hunt <oliver@apple.com>
Reviewed by Sam Weinig.
......
This box is here to create scrollbars.
Testing with no scroll
PASS: range.startContainer == element.firstChild.
PASS: range.startOffset == 0.
Test scrolling down
PASS: range.startContainer == element.firstChild.
PASS: range.startOffset == 12.
Test scrolling right
PASS: range.startContainer == element.firstChild.
PASS: range.startOffset == 2.
Test scrolling down and right
PASS: range.startContainer == element.firstChild.
PASS: range.startOffset == 14.
<html>
<head>
<style>
#test {
width: 100px;
font-family: "Ahem";
}
#pusher {
width: 1000px;
height: 1000px;
outline: 1px solid black;
}
</style>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
var _log = "";
function log(msg)
{
_log += msg + "\n";
}
function swapInLog()
{
var element = document.getElementById('test');
var parent = element.parentNode;
if (window.layoutTestController)
parent.removeChild(element);
var console = document.createElement("pre");
console.textContent = _log;
parent.appendChild(console);
}
var element;
function test(pos, __expectedContainer, __expectedOffset)
{
var expectedContainer = eval(__expectedContainer);
var expectedOffset = eval(__expectedOffset);
var range = document.caretRangeFromPoint(pos.x, pos.y);
if (range.startContainer == expectedContainer) {
log("PASS: range.startContainer == " + __expectedContainer + ".");
} else {
log("FAIL: range.startContainer == " + range.startContainer + ".");
}
if (range.startOffset == expectedOffset) {
log("PASS: range.startOffset == " + __expectedOffset + ".");
} else {
log("FAIL: range.startOffset == " + range.startOffset + ".");
}
}
window.onload = function()
{
element = document.getElementById('test');
text = element.firstChild;
var positionToTest = { x: 15, y: 15 };
log("Testing with no scroll");
test(positionToTest, "element.firstChild", "0");
log("Test scrolling down");
window.scrollTo(0, 25);
test(positionToTest, "element.firstChild", "12");
log("Test scrolling right");
window.scrollTo(25, 0);
test(positionToTest, "element.firstChild", "2");
log("Test scrolling down and right");
window.scrollTo(25, 25);
test(positionToTest, "element.firstChild", "14");
swapInLog();
}
</script>
</head>
<body>
<div id="test">xxxxx xxxxx xxxxx xxxxx</div>
<div id="pusher">This box is here to create scrollbars.</div>
</body>
</html>
2009-09-12 Sam Weinig <sam@webkit.org>
Reviewed by Maciej Stachowiak.
Fix for https://bugs.webkit.org/show_bug.cgi?id=29217
Document.caretRangeFromPoint should take the scroll offset into account before hit testing
In accordance with the CSSOM View Module spec, Document.caretRangeFromPoint should interpret
the point passed to it as relative to the viewport, not the document.
Test: fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html
* dom/Document.cpp:
(WebCore::Document::caretRangeFromPoint):
2009-09-11 Chris Marrin <cmarrin@apple.com>
Reviewed by Oliver Hunt.
......@@ -953,13 +953,13 @@ PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
Frame* frame = this->frame();
if (!frame)
return 0;
float zoomFactor = frame->pageZoomFactor();
IntPoint point = roundedIntPoint(FloatPoint(x * zoomFactor, y * zoomFactor));
FrameView* frameView = frame->view();
if (!frameView)
return 0;
float zoomFactor = frame->pageZoomFactor();
IntPoint point = roundedIntPoint(FloatPoint(x * zoomFactor, y * zoomFactor)) + view()->scrollOffset();
if (!frameView->boundsRect().contains(point))
return 0;
......
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