Bug 1130258 - Avoid closing wrong Text Selection, r=wesj

This commit is contained in:
Mark Capella 2015-02-25 01:43:35 -05:00
parent 49c682130a
commit 5fa9517129
5 changed files with 69 additions and 21 deletions

View File

@ -43,6 +43,7 @@ class TextSelection extends Layer implements GeckoEventListener {
private final DrawListener mDrawListener;
private boolean mDraggingHandles;
private int selectionID; // Unique ID provided for each selection action.
private float mViewLeft;
private float mViewTop;
private float mViewZoom;
@ -131,6 +132,7 @@ class TextSelection extends Layer implements GeckoEventListener {
public void run() {
try {
if (event.equals("TextSelection:ShowHandles")) {
selectionID = message.getInt("selectionID");
final JSONArray handles = message.getJSONArray("handles");
for (int i=0; i < handles.length(); i++) {
String handle = handles.getString(i);
@ -315,7 +317,17 @@ class TextSelection extends Layer implements GeckoEventListener {
public void onDestroyActionMode(ActionModeCompat mode) {
mActionMode = null;
mCallback = null;
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("TextSelection:End", null));
final JSONObject args = new JSONObject();
try {
args.put("selectionID", selectionID);
} catch (JSONException e) {
Log.e(LOGTAG, "Error building JSON arguments for TextSelection:End", e);
return;
}
final GeckoEvent event =
GeckoEvent.createBroadcastEvent("TextSelection:End", args.toString());
GeckoAppShell.sendEventToGecko(event);
}
}
}

View File

@ -102,7 +102,8 @@ function testLTR_selectAll() {
]).then(function() {
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(!sh.isSelectionActive(),
@ -171,7 +172,8 @@ function testRTL_selectAll() {
]).then(function() {
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(!sh.isSelectionActive(),
@ -216,7 +218,8 @@ function testLTR_dragFocusHandleToSelf() {
let focusDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_dragFocusHandleToSelf - Test Starts."),
@ -275,7 +278,8 @@ function testLTR_dragAnchorHandleToSelf() {
let anchorDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_dragAnchorHandleToSelf - Test Starts."),
@ -333,7 +337,8 @@ function testRTL_dragFocusHandleToSelf() {
let focusDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_dragFocusHandleToSelf - Test Starts."),
@ -392,7 +397,8 @@ function testRTL_dragAnchorHandleToSelf() {
let anchorDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_dragAnchorHandleToSelf - Test Starts."),

View File

@ -208,7 +208,12 @@ function testCloseSelection() {
// Various ways to close an active selection.
]).then(function() {
sh.startSelection(inputNode);
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: -1}));
return ok(sh.isSelectionActive(), "unrelated TextSelection:End should not close active selection");
}).then(function() {
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return ok(!sh.isSelectionActive(), "TextSelection:End should close active selection");
}).then(function() {
@ -310,7 +315,8 @@ function testAttachCaret() {
]);
}).then(function() {
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at end of testAttachCaret"),

View File

@ -77,7 +77,8 @@ function testLTR_selectionPoints() {
let midpointSelText = sh._getSelectedText();
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
selectionExists(selection, "LTR Selection existed at points"),
@ -121,7 +122,8 @@ function testRTL_selectionPoints() {
let midpointSelText = sh._getSelectedText();
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
selectionExists(selection, "RTL Selection existed at points"),
@ -186,7 +188,8 @@ function test_selectionLineHeight() {
]).then(function() {
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
greaterThan(selectionLineHeight, 0, "Distance from one line to another " +
@ -237,7 +240,8 @@ function testLTR_moveFocusHandleDown() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveFocusHandleDown - Test Starts."),
@ -302,7 +306,8 @@ function testLTR_moveFocusHandleUp() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveFocusHandleUp - Test Starts."),
@ -370,7 +375,8 @@ function testLTR_moveAnchorHandleUp() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveAnchorHandleUp - Test Starts."),
@ -434,7 +440,8 @@ function testLTR_moveAnchorHandleDown() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveAnchorHandleDown - Test Starts."),
@ -502,7 +509,8 @@ function testRTL_moveFocusHandleDown() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveFocusHandleDown - Test Starts."),
@ -566,7 +574,8 @@ function testRTL_moveFocusHandleUp() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveFocusHandleUp - Test Starts."),
@ -634,7 +643,8 @@ function testRTL_moveAnchorHandleUp() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveAnchorHandleUp - Test Starts."),
@ -698,7 +708,8 @@ function testRTL_moveAnchorHandleDown() {
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End", {});
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveAnchorHandleDown - Test Starts."),

View File

@ -44,6 +44,7 @@ var SelectionHandler = {
_focusIsRTL: false,
_activeType: 0, // TYPE_NONE
_selectionID: 0, // Unique Selection ID
_draggingHandles: false, // True while user drags text selection handles
_dragStartAnchorOffset: null, // Editables need initial pos during HandleMove events
@ -134,10 +135,19 @@ var SelectionHandler = {
}
break;
}
case "Tab:Selected":
case "TextSelection:End":
this._closeSelection();
break;
case "TextSelection:End":
let data = JSON.parse(aData);
// End the requested selection only.
if (this._selectionID === data.selectionID) {
this._closeSelection();
}
break;
case "TextSelection:Action":
for (let type in this.actions) {
if (this.actions[type].id == aData) {
@ -365,6 +375,7 @@ var SelectionHandler = {
// Determine position and show handles, open actionbar
this._positionHandles(positions);
Messaging.sendRequest({
selectionID: this._selectionID,
type: "TextSelection:ShowHandles",
handles: [this.HANDLE_TYPE_ANCHOR, this.HANDLE_TYPE_FOCUS]
});
@ -756,6 +767,7 @@ var SelectionHandler = {
// Determine position and show caret, open actionbar
this._positionHandles();
Messaging.sendRequest({
selectionID: this._selectionID,
type: "TextSelection:ShowHandles",
handles: [this.HANDLE_TYPE_CARET]
});
@ -777,6 +789,7 @@ var SelectionHandler = {
aElement.focus();
}
this._selectionID++;
this._stopDraggingHandles();
this._contentWindow = aElement.ownerDocument.defaultView;
this._targetIsRTL = (this._contentWindow.getComputedStyle(aElement, "").direction == "rtl");