зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1648944 - Part 2: Fire selectionchange at document from text controls r=masayuki,smaug
Differential Revision: https://phabricator.services.mozilla.com/D86701
This commit is contained in:
Родитель
b09a40408c
Коммит
36a55d0f1c
|
@ -146,8 +146,9 @@ void SelectionChangeEventDispatcher::OnSelectionChange(Document* aDoc,
|
||||||
nsCOMPtr<nsINode> target = textControl ? textControl : aDoc;
|
nsCOMPtr<nsINode> target = textControl ? textControl : aDoc;
|
||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
|
CanBubble canBubble = textControl ? CanBubble::eYes : CanBubble::eNo;
|
||||||
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
||||||
new AsyncEventDispatcher(target, eSelectionChange, CanBubble::eNo);
|
new AsyncEventDispatcher(target, eSelectionChange, canBubble);
|
||||||
asyncDispatcher->PostDOMEvent();
|
asyncDispatcher->PostDOMEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2106,7 +2106,7 @@ void TextControlState::SetSelectionRange(
|
||||||
if (IsSelectionCached() &&
|
if (IsSelectionCached() &&
|
||||||
StaticPrefs::dom_select_events_textcontrols_selectionchange_enabled()) {
|
StaticPrefs::dom_select_events_textcontrols_selectionchange_enabled()) {
|
||||||
asyncDispatcher = new AsyncEventDispatcher(
|
asyncDispatcher = new AsyncEventDispatcher(
|
||||||
mTextCtrlElement, eSelectionChange, CanBubble::eNo);
|
mTextCtrlElement, eSelectionChange, CanBubble::eYes);
|
||||||
asyncDispatcher->PostDOMEvent();
|
asyncDispatcher->PostDOMEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,13 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node
|
||||||
|
*/
|
||||||
|
function isProperSelectionChangeTarget(node) {
|
||||||
|
return node === document || node === input || node === textarea;
|
||||||
|
}
|
||||||
|
|
||||||
// The main test
|
// The main test
|
||||||
parent.add_task(async function() {
|
parent.add_task(async function() {
|
||||||
await spin();
|
await spin();
|
||||||
|
@ -70,8 +77,8 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener('selectionchange', function(aEvent) {
|
document.addEventListener('selectionchange', function(aEvent) {
|
||||||
is(aEvent.originalTarget, document,
|
ok(isProperSelectionChangeTarget(aEvent.target),
|
||||||
"The original target of selectionchange should be the document");
|
"The target of selectionchange should be one of document, input, or textarea");
|
||||||
console.log(selectionchange);
|
console.log(selectionchange);
|
||||||
selectionchange++;
|
selectionchange++;
|
||||||
});
|
});
|
||||||
|
@ -341,11 +348,11 @@
|
||||||
await mouseAction(elt("input"), 50, "mousedown", 0, 0, 0, 0);
|
await mouseAction(elt("input"), 50, "mousedown", 0, 0, 0, 0);
|
||||||
|
|
||||||
selectstartTarget = elt("input");
|
selectstartTarget = elt("input");
|
||||||
await mouseAction(elt("input"), 100, "mousemove", 1, 0, 1, 0);
|
await mouseAction(elt("input"), 100, "mousemove", 1, 1, 1, 0);
|
||||||
|
|
||||||
// Moving it more shouldn't trigger a start (move back to empty)
|
// Moving it more shouldn't trigger a start (move back to empty)
|
||||||
await mouseAction(elt("input"), 75, "mousemove", 0, 0, 1, 0);
|
await mouseAction(elt("input"), 75, "mousemove", 0, 1, 1, 0);
|
||||||
await mouseAction(elt("input"), 50, "mousemove", 0, 0, 1, 0);
|
await mouseAction(elt("input"), 50, "mousemove", 0, 1, 1, 0);
|
||||||
|
|
||||||
// Wiggling the mouse a little such that it doesn't select any
|
// Wiggling the mouse a little such that it doesn't select any
|
||||||
// characters shouldn't trigger a selection
|
// characters shouldn't trigger a selection
|
||||||
|
@ -354,7 +361,7 @@
|
||||||
// Moving the mouse again from an empty selection should trigger a
|
// Moving the mouse again from an empty selection should trigger a
|
||||||
// selectstart
|
// selectstart
|
||||||
selectstartTarget = elt("input");
|
selectstartTarget = elt("input");
|
||||||
await mouseAction(elt("input"), 25, "mousemove", 1, 0, 1, 0);
|
await mouseAction(elt("input"), 25, "mousemove", 1, 1, 1, 0);
|
||||||
|
|
||||||
// Releasing the mouse shouldn't do anything
|
// Releasing the mouse shouldn't do anything
|
||||||
await mouseAction(elt("input"), 25, "mouseup", 0, 0, 0, 0);
|
await mouseAction(elt("input"), 25, "mouseup", 0, 0, 0, 0);
|
||||||
|
@ -365,17 +372,17 @@
|
||||||
|
|
||||||
// Clicking in an random location should move the selection, but
|
// Clicking in an random location should move the selection, but
|
||||||
// not perform a selectstart
|
// not perform a selectstart
|
||||||
await mouseAction(elt("input"), 50, "click", 0, 0, 1, 0);
|
await mouseAction(elt("input"), 50, "click", 0, 1, 1, 0);
|
||||||
|
|
||||||
// Clicking there again should do nothing
|
// Clicking there again should do nothing
|
||||||
await mouseAction(elt("input"), 50, "click", 0, 0, 0, 0);
|
await mouseAction(elt("input"), 50, "click", 0, 0, 0, 0);
|
||||||
|
|
||||||
// Selecting a region, and canceling the selectstart should mean that the
|
// Selecting a region, and canceling the selectstart should mean that the
|
||||||
// selection remains collapsed
|
// selection remains collapsed
|
||||||
await mouseAction(elt("input"), 75, "mousedown", 0, 0, 1, 0);
|
await mouseAction(elt("input"), 75, "mousedown", 0, 1, 1, 0);
|
||||||
cancel = true;
|
cancel = true;
|
||||||
selectstartTarget = elt("input");
|
selectstartTarget = elt("input");
|
||||||
await mouseAction(elt("input"), 100, "mousemove", 1, 0, 1, 0);
|
await mouseAction(elt("input"), 100, "mousemove", 1, 1, 1, 0);
|
||||||
await mouseAction(elt("input"), 100, "mouseup", 0, 0, 0, 0);
|
await mouseAction(elt("input"), 100, "mouseup", 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
@ -396,11 +403,11 @@
|
||||||
await mouseAction(elt("textarea"), 50, "mousedown", 0, 0, 0, 0);
|
await mouseAction(elt("textarea"), 50, "mousedown", 0, 0, 0, 0);
|
||||||
|
|
||||||
selectstartTarget = elt("textarea");
|
selectstartTarget = elt("textarea");
|
||||||
await mouseAction(elt("textarea"), 100, "mousemove", 1, 0, 0, 1);
|
await mouseAction(elt("textarea"), 100, "mousemove", 1, 1, 0, 1);
|
||||||
|
|
||||||
// Moving it more shouldn't trigger a start (move back to empty)
|
// Moving it more shouldn't trigger a start (move back to empty)
|
||||||
await mouseAction(elt("textarea"), 75, "mousemove", 0, 0, 0, 1);
|
await mouseAction(elt("textarea"), 75, "mousemove", 0, 1, 0, 1);
|
||||||
await mouseAction(elt("textarea"), 50, "mousemove", 0, 0, 0, 1);
|
await mouseAction(elt("textarea"), 50, "mousemove", 0, 1, 0, 1);
|
||||||
|
|
||||||
// Wiggling the mouse a little such that it doesn't select any
|
// Wiggling the mouse a little such that it doesn't select any
|
||||||
// characters shouldn't trigger a selection
|
// characters shouldn't trigger a selection
|
||||||
|
@ -409,7 +416,7 @@
|
||||||
// Moving the mouse again from an empty selection should trigger a
|
// Moving the mouse again from an empty selection should trigger a
|
||||||
// selectstart
|
// selectstart
|
||||||
selectstartTarget = elt("textarea");
|
selectstartTarget = elt("textarea");
|
||||||
await mouseAction(elt("textarea"), 25, "mousemove", 1, 0, 0, 1);
|
await mouseAction(elt("textarea"), 25, "mousemove", 1, 1, 0, 1);
|
||||||
|
|
||||||
// Releasing the mouse shouldn't do anything
|
// Releasing the mouse shouldn't do anything
|
||||||
await mouseAction(elt("textarea"), 25, "mouseup", 0, 0, 0, 0);
|
await mouseAction(elt("textarea"), 25, "mouseup", 0, 0, 0, 0);
|
||||||
|
@ -420,17 +427,17 @@
|
||||||
|
|
||||||
// Clicking in an random location should move the selection, but not perform a
|
// Clicking in an random location should move the selection, but not perform a
|
||||||
// selectstart
|
// selectstart
|
||||||
await mouseAction(elt("textarea"), 50, "click", 0, 0, 0, 1);
|
await mouseAction(elt("textarea"), 50, "click", 0, 1, 0, 1);
|
||||||
|
|
||||||
// Clicking there again should do nothing
|
// Clicking there again should do nothing
|
||||||
await mouseAction(elt("textarea"), 50, "click", 0, 0, 0, 0);
|
await mouseAction(elt("textarea"), 50, "click", 0, 0, 0, 0);
|
||||||
|
|
||||||
// Selecting a region, and canceling the selectstart should mean that the
|
// Selecting a region, and canceling the selectstart should mean that the
|
||||||
// selection remains collapsed
|
// selection remains collapsed
|
||||||
await mouseAction(elt("textarea"), 75, "mousedown", 0, 0, 0, 1);
|
await mouseAction(elt("textarea"), 75, "mousedown", 0, 1, 0, 1);
|
||||||
cancel = true;
|
cancel = true;
|
||||||
selectstartTarget = elt("textarea");
|
selectstartTarget = elt("textarea");
|
||||||
await mouseAction(elt("textarea"), 100, "mousemove", 1, 0, 0, 1);
|
await mouseAction(elt("textarea"), 100, "mousemove", 1, 1, 0, 1);
|
||||||
await mouseAction(elt("textarea"), 100, "mouseup", 0, 0, 0, 0);
|
await mouseAction(elt("textarea"), 100, "mouseup", 0, 0, 0, 0);
|
||||||
|
|
||||||
// Marking the input and textarea as display: none and then as visible again
|
// Marking the input and textarea as display: none and then as visible again
|
||||||
|
|
Загрузка…
Ссылка в новой задаче