From 0c12a12bbd6cedc78fc5b04c68ef72312e60612d Mon Sep 17 00:00:00 2001 From: James Teh Date: Thu, 26 Jan 2023 23:43:08 +0000 Subject: [PATCH] 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 --- accessible/generic/DocAccessible.cpp | 3 ++ .../tests/browser/bounds/browser_position.js | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index 034fd10b061c..2daa2c2dd3c0 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -1562,6 +1562,9 @@ void DocAccessible::SendAccessiblesWillMove() { // moved. if (!acc->IsDefunct() && acc->IsInDocument()) { ids.AppendElement(reinterpret_cast(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()) { diff --git a/accessible/tests/browser/bounds/browser_position.js b/accessible/tests/browser/bounds/browser_position.js index 6c0e6a553e35..2da5f4f857a8 100644 --- a/accessible/tests/browser/bounds/browser_position.js +++ b/accessible/tests/browser/bounds/browser_position.js @@ -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( + ` +
+

1

+
+

2

+
+
+ `, + 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 } +);