Bug 1811972: When an Accessible is moved in the tree, queue a bounds cache update. r=morgan

When an Accessible is moved, it's possible it is re-parented.
In that case, since our cached bounds are relative to the parent, the bounds are now incorrect.
To fix this, queue a bounds cache update whenever an Accessible is moved.
This will also trigger when an Accessible remains under the same parent.
However, because we cache bounds in LocalAccessible, we won't actually push a cache update unless the bounds really changed.

Differential Revision: https://phabricator.services.mozilla.com/D167866
This commit is contained in:
James Teh 2023-01-26 23:43:08 +00:00
Родитель 933cc122ea
Коммит 0c12a12bbd
2 изменённых файлов: 41 добавлений и 0 удалений

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

@ -1562,6 +1562,9 @@ void DocAccessible::SendAccessiblesWillMove() {
// moved.
if (!acc->IsDefunct() && acc->IsInDocument()) {
ids.AppendElement(reinterpret_cast<uintptr_t>(acc->UniqueID()));
// acc might have been re-parented. Since we cache bounds relative to the
// parent, we need to update the cache.
QueueCacheUpdate(acc, CacheDomain::Bounds);
}
}
if (!ids.IsEmpty()) {

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

@ -4,6 +4,9 @@
"use strict";
/* import-globals-from ../../mochitest/role.js */
loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
/**
* Test changing the left/top CSS properties.
*/
@ -63,3 +66,38 @@ addAccessibleTask(
},
{ chrome: true, topLevel: true, remoteIframe: true }
);
/**
* Test bounds when an Accessible is re-parented.
*/
addAccessibleTask(
`
<div id="container">
<p style="height: 300px;">1</p>
<div class="pParent">
<p id="p2">2</p>
</div>
</div>
`,
async function(browser, docAcc) {
const paraTree = { PARAGRAPH: [{ TEXT_LEAF: [] }] };
const container = findAccessibleChildByID(docAcc, "container");
testAccessibleTree(container, { SECTION: [paraTree, paraTree] });
await testBoundsWithContent(docAcc, "p2", browser);
// Add a click listener to the div containing p2. This will cause an
// Accessible to be created for that div, which didn't have one before.
info("Adding click listener to pParent");
let reordered = waitForEvent(EVENT_REORDER, container);
await invokeContentTask(browser, [], () => {
content.document
.querySelector(".pParent")
.addEventListener("click", function() {});
});
await reordered;
testAccessibleTree(container, {
SECTION: [paraTree, { SECTION: [paraTree] }],
});
await testBoundsWithContent(docAcc, "p2", browser);
},
{ chrome: true, topLevel: true, remoteIframe: true }
);