Commit 1a646775 authored by James Wallace-Lee's avatar James Wallace-Lee Committed by Commit Bot

Notify textChanged if button's children change

When a button's textContent changes, post a textChanged notification.
A button's textContent is a child of the button container, but in the
accessibility tree button elements cannot have children, so
ChildrenChanged previously did not update the button.

Bug: 793078
Test: DumpAccessibilityTreeTest.AccessibilityButtonContentChanged
Change-Id: I2be389c77763cb60fd2fc9951070370856b0c894
Reviewed-on: https://chromium-review.googlesource.com/1110658
Commit-Queue: James Wallace-Lee <jamwalla@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570786}
parent 80be7ab8
......@@ -1006,6 +1006,16 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityButton) {
RunHtmlTest(FILE_PATH_LITERAL("button.html"));
}
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
AccessibilityButtonAltChanged) {
RunHtmlTest(FILE_PATH_LITERAL("button-alt-changed.html"));
}
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
AccessibilityButtonContentChanged) {
RunHtmlTest(FILE_PATH_LITERAL("button-content-changed.html"));
}
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityButtonNameCalc) {
RunHtmlTest(FILE_PATH_LITERAL("button-name-calc.html"));
}
......
rootWebArea
++genericContainer name='Done'
++button name='After'
<!--
@BLINK-ALLOW:name=*
@WAIT-FOR:Done
-->
<!DOCTYPE html>
<html>
<body>
<div id="status" aria-label="Working"></div>
<button>
<img alt="Before"></img>
</button>
<script>
setTimeout(function() {
document.querySelector('img').setAttribute("alt", "After");
document.getElementById('status').setAttribute('aria-label', 'Done');
}, 100);
</script>
</body>
</html>
rootWebArea
++genericContainer name='Done'
++button name='After '
<!--
@BLINK-ALLOW:name=*
@WAIT-FOR:Done
-->
<!DOCTYPE html>
<html>
<body>
<div id="status" aria-label="Working"></div>
<button>
<p>
<div id="txt">Before</div>
</p>
</button>
<script>
setTimeout(function() {
document.getElementById('txt').textContent = 'After';
document.getElementById('status').setAttribute('aria-label', 'Done');
}, 100);
</script>
</body>
</html>
......@@ -83,6 +83,7 @@ class CORE_EXPORT AXObjectCache
// Called when a node has just been attached, so we can make sure we have the
// right subclass of AXObject.
virtual void UpdateCacheAfterNodeIsAttached(Node*) = 0;
virtual void DidInsertChildrenOfNode(Node*) = 0;
virtual void HandleAttributeChanged(const QualifiedName& attr_name,
Element*) = 0;
......
......@@ -351,6 +351,9 @@ void ContainerNode::DidInsertNodeVector(
DispatchChildInsertionEvents(*target_node);
}
DispatchSubtreeModifiedEvent();
if (AXObjectCache* cache = GetDocument().GetOrCreateAXObjectCache())
cache->DidInsertChildrenOfNode(this);
}
class ContainerNode::AdoptAndInsertBefore {
......
......@@ -699,6 +699,20 @@ void AXObjectCacheImpl::UpdateCacheAfterNodeIsAttached(Node* node) {
MaybeNewRelationTarget(node, obj);
}
void AXObjectCacheImpl::DidInsertChildrenOfNode(Node* node) {
// If a node is inserted that is a descendant of a leaf node in the
// accessibility tree, notify the root of that subtree that its children have
// changed.
if (!node)
return;
if (AXObject* obj = Get(node)) {
TextChanged(obj, node);
} else {
DidInsertChildrenOfNode(NodeTraversal::Parent(*node));
}
}
void AXObjectCacheImpl::ChildrenChanged(Node* node) {
ChildrenChanged(Get(node), node);
}
......
......@@ -132,6 +132,7 @@ class MODULES_EXPORT AXObjectCacheImpl
// Called when a node has just been attached, so we can make sure we have the
// right subclass of AXObject.
void UpdateCacheAfterNodeIsAttached(Node*) override;
void DidInsertChildrenOfNode(Node*) override;
void HandleAttributeChanged(const QualifiedName& attr_name,
Element*) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment