From 46d8e24afa2c9972bf972043e8dc19938d032c1b Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Thu, 11 Jul 2013 04:29:27 -0500 Subject: [PATCH] Bug 891805 - Cache caret position at the start of a drag in text edits, and use that when initiating selection. r=rsilveira --- .../content/helperui/SelectionHelperUI.js | 20 +++++++++++++++++-- .../browser_selection_contenteditable.js | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/browser/metro/base/content/helperui/SelectionHelperUI.js b/browser/metro/base/content/helperui/SelectionHelperUI.js index fc9c67c527f..2ed06fb5216 100644 --- a/browser/metro/base/content/helperui/SelectionHelperUI.js +++ b/browser/metro/base/content/helperui/SelectionHelperUI.js @@ -610,6 +610,16 @@ var SelectionHelperUI = { this.startMark.position(targetMark.xPos, targetMark.yPos); this.endMark.position(targetMark.xPos, targetMark.yPos); + // We delay transitioning until we know which direction the user is dragging + // based on a hysteresis value in the drag marker code. Down in our caller, we + // cache the first drag position in _cachedCaretPos so we can select from the + // initial caret drag position. Use those values if we have them. (Note + // _cachedCaretPos has already been translated in _getMarkerBaseMessage.) + let xpos = this._cachedCaretPos ? this._cachedCaretPos.xPos : + this._msgTarget.ctobx(targetMark.xPos, true); + let ypos = this._cachedCaretPos ? this._cachedCaretPos.yPos : + this._msgTarget.ctoby(targetMark.yPos, true); + // Start the selection monocle drag. SelectionHandler relies on this // for getting initialized. This will also trigger a message back for // monocle positioning. Note, markerDragMove is still on the stack in @@ -617,8 +627,8 @@ var SelectionHelperUI = { this._sendAsyncMessage("Browser:SelectionSwitchMode", { newMode: "selection", change: targetMark.tag, - xPos: this._msgTarget.ctobx(targetMark.xPos, true), - yPos: this._msgTarget.ctoby(targetMark.yPos, true), + xPos: xpos, + yPos: ypos, }); }, @@ -1097,6 +1107,7 @@ var SelectionHelperUI = { markerDragStart: function markerDragStart(aMarker) { let json = this._getMarkerBaseMessage(aMarker.tag); if (aMarker.tag == "caret") { + this._cachedCaretPos = null; this._sendAsyncMessage("Browser:CaretMove", json); return; } @@ -1123,8 +1134,13 @@ var SelectionHelperUI = { this._transitionFromCaretToSelection(aDirection); return false; } + // Cache for when we start the drag in _transitionFromCaretToSelection. + if (!this._cachedCaretPos) { + this._cachedCaretPos = this._getMarkerBaseMessage(aMarker.tag).caret; + } return true; } + this._cachedCaretPos = null; // We'll re-display these after the drag is complete. this._hideMonocles(); diff --git a/browser/metro/base/tests/mochitest/browser_selection_contenteditable.js b/browser/metro/base/tests/mochitest/browser_selection_contenteditable.js index 0a32a90a379..8fd00719ca8 100644 --- a/browser/metro/base/tests/mochitest/browser_selection_contenteditable.js +++ b/browser/metro/base/tests/mochitest/browser_selection_contenteditable.js @@ -38,7 +38,7 @@ gTests.push({ let div = gWindow.document.getElementById("testdiv"); ok(div, "have the div"); - sendElementTap(gWindow, div, 295); // end of 'outlook.com' + sendElementTap(gWindow, div, 287); // end of 'outlook.com' yield waitForCondition(function () { return SelectionHelperUI.isCaretUIVisible;