Bug 1826194 part 2: When calculating a text equivalent, walk the flat tree instead of only direct children. r=morgan

Previously, when calculating a text equivalent by walking the DOM tree, we only walked direct children of a DOM node.
However, a slot element is a placeholder for content which comes from outside of a shadow root.
In order to include this content when a slot isn't accessible (e.g. because it is hidden), we need to walk the DOM flat tree instead.

Differential Revision: https://phabricator.services.mozilla.com/D181841
This commit is contained in:
James Teh 2023-06-28 01:18:18 +00:00
Родитель 33bfc9b615
Коммит 983b81b013
2 изменённых файлов: 9 добавлений и 2 удалений

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

@ -11,6 +11,7 @@
#include "LocalAccessible-inl.h"
#include "AccIterator.h"
#include "nsCoreUtils.h"
#include "mozilla/dom/ChildIterator.h"
#include "mozilla/dom/Text.h"
#include "nsIContentInlines.h"
@ -123,8 +124,9 @@ nsresult nsTextEquivUtils::AppendTextEquivFromTextContent(nsIContent* aContent,
nsresult nsTextEquivUtils::AppendFromDOMChildren(nsIContent* aContent,
nsAString* aString) {
for (nsIContent* childContent = aContent->GetFirstChild(); childContent;
childContent = childContent->GetNextSibling()) {
auto iter =
dom::AllChildrenIterator(aContent, nsIContent::eAllChildren, true);
while (nsIContent* childContent = iter.GetNextChild()) {
nsresult rv = AppendFromDOMNode(childContent, aString);
NS_ENSURE_SUCCESS(rv, rv);
}

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

@ -264,6 +264,8 @@
const shadowRoot = getNode("shadowHost").shadowRoot;
const shadowButtonVisibleText = shadowRoot.getElementById("shadowButtonVisibleText");
testName(shadowButtonVisibleText, "shadowButtonVisibleText");
const shadowButtonHiddenText = shadowRoot.getElementById("shadowButtonHiddenText");
testName(shadowButtonHiddenText, "shadowButtonHiddenText");
SimpleTest.finish();
}
@ -736,10 +738,13 @@
<!-- aria-labelledby referring to a slot -->
<div id="shadowHost">
shadowButtonVisibleText
<span slot="hiddenSlot">shadowButtonHiddenText</span>
</div>
<template id="shadowTemplate">
<input type="button" id="shadowButtonVisibleText" aria-labelledby="visibleSlot">
<slot id="visibleSlot"></slot>
<input type="button" id="shadowButtonHiddenText" aria-labelledby="hiddenSlot">
<slot id="hiddenSlot" name="hiddenSlot" hidden></slot>
</template>
<script>
const shadowHost = document.getElementById("shadowHost");