Bug 865356 - Restrict caret move coords within text inputs when invoking text selection. r=mbrubeck

This commit is contained in:
Jim Mathies 2013-05-30 10:55:36 -05:00
Родитель 66db079742
Коммит 1809ff85e8
1 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -323,7 +323,14 @@ var SelectionHandler = {
this._onFail("Unexpected, caret position isn't supported with non-inputs.");
return;
}
let cp = this._contentWindow.document.caretPositionFromPoint(aX, aY);
// SelectionHelperUI sends text input tap coordinates and a caret move
// event at the start of a monocle drag. caretPositionFromPoint isn't
// going to give us correct info if the coord is outside the edit bounds,
// so restrict the coordinates before we call cpfp.
let containedCoords = this._restrictCoordinateToEditBounds(aX, aY);
let cp = this._contentWindow.document.caretPositionFromPoint(containedCoords.xPos,
containedCoords.yPos);
let input = cp.offsetNode;
let offset = cp.offset;
input.selectionStart = input.selectionEnd = offset;
@ -603,6 +610,24 @@ var SelectionHandler = {
this._cache.caret.yPos = bounds.bottom;
},
_restrictCoordinateToEditBounds: function _restrictCoordinateToEditBounds(aX, aY) {
let result = {
xPos: aX,
yPos: aY
};
if (!this._targetIsEditable)
return result;
let bounds = this._getTargetBrowserRect();
if (aX <= bounds.left)
result.xPos = bounds.left + 1;
if (aX >= bounds.right)
result.xPos = bounds.right - 1;
if (aY <= bounds.top)
result.yPos = bounds.top + 1;
if (aY >= bounds.bottom)
result.yPos = bounds.bottom - 1;
},
/*
* _handleSelectionPoint(aMarker, aPoint, aEndOfSelection)
*