Bug 862054 - Update bounds utility methods in SelectionHandler to properly calculate offsets for form inputs in sub frames. r=bbondy

This commit is contained in:
Jim Mathies 2013-04-23 08:51:03 -05:00
parent c6c2deab99
commit f26a64041b
2 changed files with 25 additions and 6 deletions

View File

@ -282,9 +282,10 @@ let Content = {
// A tap on a form input triggers touch input caret selection // A tap on a form input triggers touch input caret selection
if (Util.isTextInput(element) && if (Util.isTextInput(element) &&
aEvent.mozInputSource == Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH) { aEvent.mozInputSource == Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH) {
let { offsetX, offsetY } = Util.translateToTopLevelWindow(element);
sendAsyncMessage("Content:SelectionCaret", { sendAsyncMessage("Content:SelectionCaret", {
xPos: aEvent.clientX, xPos: aEvent.clientX + offsetX,
yPos: aEvent.clientY yPos: aEvent.clientY + offsetY
}); });
} }
}, },

View File

@ -574,7 +574,8 @@ var SelectionHandler = {
_restrictSelectionRectToEditBounds: function _restrictSelectionRectToEditBounds() { _restrictSelectionRectToEditBounds: function _restrictSelectionRectToEditBounds() {
if (!this._targetIsEditable) if (!this._targetIsEditable)
return; return;
let bounds = this._getTargetClientRect();
let bounds = this._getTargetBrowserRect();
if (this._cache.start.xPos < bounds.left) if (this._cache.start.xPos < bounds.left)
this._cache.start.xPos = bounds.left; this._cache.start.xPos = bounds.left;
if (this._cache.end.xPos < bounds.left) if (this._cache.end.xPos < bounds.left)
@ -794,7 +795,7 @@ var SelectionHandler = {
* @return new constrained point struct * @return new constrained point struct
*/ */
_constrainPointWithinControl: function _cpwc(aPoint, aHalfLineHeight) { _constrainPointWithinControl: function _cpwc(aPoint, aHalfLineHeight) {
let bounds = this._getTargetClientRect(); let bounds = this._getTargetBrowserRect();
let point = { xPos: aPoint.xPos, yPos: aPoint.yPos }; let point = { xPos: aPoint.xPos, yPos: aPoint.yPos };
if (point.xPos <= bounds.left) if (point.xPos <= bounds.left)
point.xPos = bounds.left + 2; point.xPos = bounds.left + 2;
@ -815,7 +816,7 @@ var SelectionHandler = {
* Works on client coordinates. * Works on client coordinates.
*/ */
_pointOrientationToRect: function _pointOrientationToRect(aPoint) { _pointOrientationToRect: function _pointOrientationToRect(aPoint) {
let bounds = this._targetElement.getBoundingClientRect(); let bounds = this._getTargetBrowserRect();
let result = { left: 0, right: 0, top: 0, bottom: 0 }; let result = { left: 0, right: 0, top: 0, bottom: 0 };
if (aPoint.xPos <= bounds.left) if (aPoint.xPos <= bounds.left)
result.left = bounds.left - aPoint.xPos; result.left = bounds.left - aPoint.xPos;
@ -1103,7 +1104,7 @@ var SelectionHandler = {
// height of the target element // height of the target element
let targetHeight = this._cache.element.bottom - this._cache.element.top; let targetHeight = this._cache.element.bottom - this._cache.element.top;
// height of the browser view. // height of the browser view.
let viewBottom = this._targetElement.ownerDocument.defaultView.innerHeight; let viewBottom = content.innerHeight;
// If the target is shorter than the new content height, we can go ahead // If the target is shorter than the new content height, we can go ahead
// and center it. // and center it.
@ -1294,10 +1295,27 @@ var SelectionHandler = {
return seldata; return seldata;
}, },
/*
* Returns bounds of the element relative to the inner sub frame it sits
* in.
*/
_getTargetClientRect: function _getTargetClientRect() { _getTargetClientRect: function _getTargetClientRect() {
return this._targetElement.getBoundingClientRect(); return this._targetElement.getBoundingClientRect();
}, },
/*
* Returns bounds of the element relative to the top level browser.
*/
_getTargetBrowserRect: function _getTargetBrowserRect() {
let client = this._getTargetClientRect();
return {
left: client.left + this._contentOffset.x,
top: client.top + this._contentOffset.y,
right: client.right + this._contentOffset.x,
bottom: client.bottom + this._contentOffset.y
};
},
/* /*
* Translate a top level client point to frame relative client point. * Translate a top level client point to frame relative client point.
*/ */