зеркало из https://github.com/mozilla/gecko-dev.git
Bug 848594 - Reorganize code related to text input selection management in SelectionHandler. r=mbrubeck
This commit is contained in:
Родитель
14869500ee
Коммит
3115fbadb1
|
@ -45,7 +45,6 @@ var SelectionHandler = {
|
|||
_contentOffset: { x:0, y:0 },
|
||||
_domWinUtils: null,
|
||||
_selectionMoveActive: false,
|
||||
_lastMarker: "",
|
||||
_debugOptions: { dumpRanges: false, displayRanges: false },
|
||||
_snap: true,
|
||||
|
||||
|
@ -594,63 +593,16 @@ var SelectionHandler = {
|
|||
}
|
||||
|
||||
// Adjust our y position up such that we are sending coordinates on
|
||||
// the text line vs. below it where the monocle is positioned. This
|
||||
// applies to free floating text areas. For text inputs we'll constrain
|
||||
// coordinates further below.
|
||||
// the text line vs. below it where the monocle is positioned.
|
||||
let halfLineHeight = this._queryHalfLineHeight(aMarker, selection);
|
||||
clientPoint.yPos -= halfLineHeight;
|
||||
|
||||
// Modify selection based on monocle movement
|
||||
if (this._targetIsEditable) {
|
||||
// Check to see if we are beyond the bounds of selection in a input
|
||||
// control. If we are we want to add selection and scroll the added
|
||||
// selection into view.
|
||||
let result = this.updateTextEditSelection(clientPoint);
|
||||
|
||||
// If we're targeting a text input of any kind, make sure clientPoint
|
||||
// is contained within the bounds of the text control. For example, if
|
||||
// a user drags up too close to an upper bounds, selectAtPoint might
|
||||
// select the content above the control. This looks crappy and breaks
|
||||
// our selection rect management.
|
||||
clientPoint =
|
||||
this._constrainPointWithinControl(clientPoint, halfLineHeight);
|
||||
|
||||
// If result.trigger is true, the monocle is outside the bounds of the
|
||||
// control. If it's false, fall through to our additive text selection
|
||||
// below.
|
||||
if (result.trigger) {
|
||||
// _handleSelectionPoint is triggered by input movement, so if we've
|
||||
// tested positive for out-of-bounds scrolling here, we need to set a
|
||||
// recurring timer to keep the expected selection behavior going as
|
||||
// long as the user keeps the monocle out of bounds.
|
||||
if (!this._scrollTimer)
|
||||
this._scrollTimer = new Util.Timeout();
|
||||
this._setTextEditUpdateInterval(result.speed);
|
||||
|
||||
// Smooth the selection
|
||||
this._setContinuousSelection();
|
||||
|
||||
// Update the other monocle's position if we've dragged off to one side
|
||||
this._updateSelectionUI(result.start, result.end);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._lastMarker = aMarker;
|
||||
|
||||
// If we aren't out-of-bounds, clear the scroll timer if it exists.
|
||||
this._clearTimers();
|
||||
|
||||
// Adjusts the selection based on monocle movement
|
||||
this._adjustSelection(aMarker, clientPoint, aEndOfSelection);
|
||||
|
||||
// Update the other monocle's position. We do this because the dragging
|
||||
// monocle may reset the static monocle to a new position if the dragging
|
||||
// monocle drags ahead or behind the other.
|
||||
if (aMarker == "start") {
|
||||
this._updateSelectionUI(false, true);
|
||||
this._adjustEditableSelection(aMarker, clientPoint,
|
||||
halfLineHeight, aEndOfSelection);
|
||||
} else {
|
||||
this._updateSelectionUI(true, false);
|
||||
this._adjustSelection(aMarker, clientPoint, aEndOfSelection);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -659,6 +611,59 @@ var SelectionHandler = {
|
|||
*/
|
||||
|
||||
/*
|
||||
* _adjustEditableSelection
|
||||
*
|
||||
* Based on a monocle marker and position, adds or subtracts from the
|
||||
* existing selection in editable controls. Handles auto-scroll as well.
|
||||
*
|
||||
* @param the marker currently being manipulated
|
||||
* @param aAdjustedClientPoint client point adjusted for line height.
|
||||
* @param aHalfLineHeight half line height in pixels
|
||||
* @param aEndOfSelection indicates if this is the end of a selection
|
||||
* move, in which case we may want to snap to the end of a word or
|
||||
* sentence.
|
||||
*/
|
||||
_adjustEditableSelection: function _adjustEditableSelection(aMarker,
|
||||
aAdjustedClientPoint,
|
||||
aHalfLineHeight,
|
||||
aEndOfSelection) {
|
||||
// Test to see if we need to handle auto-scroll in cases where the
|
||||
// monocle is outside the bounds of the control. This also handles
|
||||
// adjusting selection if out-of-bounds is true.
|
||||
let result = this.updateTextEditSelection(aAdjustedClientPoint);
|
||||
|
||||
// If result.trigger is true, the monocle is outside the bounds of the
|
||||
// control.
|
||||
if (result.trigger) {
|
||||
// _handleSelectionPoint is triggered by input movement, so if we've
|
||||
// tested positive for out-of-bounds scrolling here, we need to set a
|
||||
// recurring timer to keep the expected selection behavior going as
|
||||
// long as the user keeps the monocle out of bounds.
|
||||
this._setTextEditUpdateInterval(result.speed);
|
||||
|
||||
// Smooth the selection
|
||||
this._setContinuousSelection();
|
||||
|
||||
// Update the other monocle's position if we've dragged off to one side
|
||||
this._updateSelectionUI(result.start, result.end);
|
||||
} else {
|
||||
// If we aren't out-of-bounds, clear the scroll timer if it exists.
|
||||
this._clearTimers();
|
||||
|
||||
// Restrict the client point to the interior of the control. Prevents
|
||||
// _adjustSelection from accidentally selecting content outside the
|
||||
// control.
|
||||
let constrainedPoint =
|
||||
this._constrainPointWithinControl(aAdjustedClientPoint, aHalfLineHeight);
|
||||
|
||||
// Add or subtract selection
|
||||
this._adjustSelection(aMarker, constrainedPoint, aEndOfSelection);
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* _adjustSelection
|
||||
*
|
||||
* Based on a monocle marker and position, adds or subtracts from the
|
||||
* existing selection.
|
||||
*
|
||||
|
@ -707,6 +712,15 @@ var SelectionHandler = {
|
|||
|
||||
// Smooth over the selection between all existing ranges.
|
||||
this._setContinuousSelection();
|
||||
|
||||
// Update the other monocle's position. We do this because the dragging
|
||||
// monocle may reset the static monocle to a new position if the dragging
|
||||
// monocle drags ahead or behind the other.
|
||||
if (aMarker == "start") {
|
||||
this._updateSelectionUI(false, true);
|
||||
} else {
|
||||
this._updateSelectionUI(true, false);
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -823,6 +837,8 @@ var SelectionHandler = {
|
|||
|
||||
_setTextEditUpdateInterval: function _setTextEditUpdateInterval(aSpeedValue) {
|
||||
let timeout = (75 - (aSpeedValue * 75));
|
||||
if (!this._scrollTimer)
|
||||
this._scrollTimer = new Util.Timeout();
|
||||
this._scrollTimer.interval(timeout, this.scrollTimerCallback);
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче