Bug 1025815 - caretPositionFromPoint needs to account for CSS transforms. r=bz

MozReview-Commit-ID: 1cTUyd0x6xy

--HG--
extra : rebase_source : 2194519fa3417dc8a8fe63db5b773e56daa38b16
This commit is contained in:
Kestrel 2018-05-08 18:09:32 +08:00
parent 27baa6b4f2
commit 63bbad4332
2 changed files with 15 additions and 4 deletions

View File

@ -9967,10 +9967,13 @@ nsIDocument::CaretPositionFromPoint(float aX, float aY)
return nullptr;
}
// GetContentOffsetsFromPoint requires frame-relative coordinates, so we need
// to adjust to frame-relative coordinates before we can perform this call.
// It should also not take into account the padding of the frame.
nsPoint adjustedPoint = pt - ptFrame->GetOffsetTo(rootFrame);
// We require frame-relative coordinates for GetContentOffsetsFromPoint.
nsPoint aOffset;
nsCOMPtr<nsIWidget> widget = nsContentUtils::GetWidget(ps, &aOffset);
LayoutDeviceIntPoint refPoint =
nsContentUtils::ToWidgetPoint(CSSPoint(aX, aY), aOffset, GetPresContext());
nsPoint adjustedPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(widget, refPoint, ptFrame);
nsFrame::ContentOffsets offsets =
ptFrame->GetContentOffsetsFromPoint(adjustedPoint);

View File

@ -105,6 +105,12 @@
Math.round(test6Rect.top + (test6Rect.height / 2)),
5, "test6");
// Check the first and last characters of the transformed div.
var test7Element = document.getElementById('test7');
var test7Rect = test7Element.getBoundingClientRect();
checkOffsetsFromPoint(Math.round(test7Rect.left + 1), Math.round(test7Rect.top + 1), 0, 'test7');
checkOffsetsFromPoint(Math.round(test7Rect.right - 1), Math.round(test7Rect.top + 1), 13, 'test7');
SimpleTest.finish();
}
@ -116,6 +122,8 @@
<span id="test2" style="color: blue;">abc, abc, abc</span><br>
<textarea id="test3">abc</textarea><input id="test4" value="abcdef"><br><br>
<marquee>marquee</marquee>
<!-- Translate test7 while staying within confines of the test viewport -->
<div id="test7" style="transform: translate(140px, -20px); display: inline-block;">abc, abc, abc</div>
</div>
<input id="test5" value="The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled `ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it." type="text">
<input id="test6" type="number" style="width:150px; height:57px;" value="31415"><br>