Bug 1770878: Don't fire collapsed selection events on the container of a focused text field. r=morgan

These events were clobbering the text field selection in the cache.
They aren't useful to clients anyway.

Differential Revision: https://phabricator.services.mozilla.com/D151004
This commit is contained in:
James Teh 2022-07-14 00:50:38 +00:00
Родитель e83581aacd
Коммит 4ea684224b
2 изменённых файлов: 61 добавлений и 2 удалений

Просмотреть файл

@ -127,9 +127,17 @@ void SelectionManager::RemoveDocSelectionListener(PresShell* aPresShell) {
void SelectionManager::ProcessTextSelChangeEvent(AccEvent* aEvent) {
// Fire selection change event if it's not pure caret-move selection change,
// i.e. the accessible has or had not collapsed selection.
// i.e. the accessible has or had not collapsed selection. Also, it must not
// be a collapsed selection on the container of a focused text field, since
// the text field has an independent selection and will thus fire its own
// selection events.
AccTextSelChangeEvent* event = downcast_accEvent(aEvent);
if (!event->IsCaretMoveOnly()) nsEventShell::FireEvent(aEvent);
if (!event->IsCaretMoveOnly() &&
!(event->mSel->IsCollapsed() && event->mSel != mCurrCtrlNormalSel &&
FocusMgr() && FocusMgr()->FocusedAccessible() &&
FocusMgr()->FocusedAccessible()->IsTextField())) {
nsEventShell::FireEvent(aEvent);
}
// Fire caret move event if there's a caret in the selection.
nsINode* caretCntrNode = nsCoreUtils::GetDOMNodeFromDOMPoint(

Просмотреть файл

@ -1136,3 +1136,54 @@ addAccessibleTask(
remoteIframe: !isWinNoCache,
}
);
/**
* Tabbing to an input selects all its text. Test that the cached selection
*reflects this. This has to be done separately from the other selection tests
* because prior contentEditable selection changes the events that get fired.
*/
addAccessibleTask(
`
<button id="before">Before</button>
<input id="input" value="test">
`,
async function(browser, docAcc) {
// The tab order is different when there's an iframe, so focus a control
// before the input to make tab consistent.
info("Focusing before");
const before = findAccessibleChildByID(docAcc, "before");
// Focusing a button fires a selection event. We must swallow this to
// avoid confusing the later test.
let events = waitForOrderedEvents([
[EVENT_FOCUS, before],
[EVENT_TEXT_SELECTION_CHANGED, docAcc],
]);
before.takeFocus();
await events;
const input = findAccessibleChildByID(docAcc, "input", [nsIAccessibleText]);
info("Tabbing to input");
events = waitForEvents(
{
expected: [
[EVENT_FOCUS, input],
[EVENT_TEXT_SELECTION_CHANGED, input],
],
unexpected: [[EVENT_TEXT_SELECTION_CHANGED, docAcc]],
},
"input",
false,
(args, task) => invokeContentTask(browser, args, task)
);
EventUtils.synthesizeKey("KEY_Tab");
await events;
testSelectionRange(browser, input, input, 0, input, 4);
testTextGetSelection(input, 0, 4, 0);
},
{
chrome: true,
topLevel: !isWinNoCache,
iframe: !isWinNoCache,
remoteIframe: !isWinNoCache,
}
);