diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index bf74d97d7580..c2f0c53f775f 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -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 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); diff --git a/dom/base/test/test_caretPositionFromPoint.html b/dom/base/test/test_caretPositionFromPoint.html index 7c8b84b16c5d..d84d0349bd65 100644 --- a/dom/base/test/test_caretPositionFromPoint.html +++ b/dom/base/test/test_caretPositionFromPoint.html @@ -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 @@ abc, abc, abc


marquee + +
abc, abc, abc