зеркало из https://github.com/mozilla/gecko-dev.git
Bug 429547 - Support aria-activedescendant usage in nsIAccesible::TakeFocus(), r=aaronlev, a=dsicore
This commit is contained in:
Родитель
fea63841de
Коммит
6f9da8afdc
|
@ -1440,20 +1440,54 @@ NS_IMETHODIMP nsAccessible::TakeSelection()
|
|||
}
|
||||
|
||||
/* void takeFocus (); */
|
||||
NS_IMETHODIMP nsAccessible::TakeFocus()
|
||||
{
|
||||
nsCOMPtr<nsIDOMNSHTMLElement> htmlElement(do_QueryInterface(mDOMNode));
|
||||
NS_IMETHODIMP
|
||||
nsAccessible::TakeFocus()
|
||||
{
|
||||
if (IsDefunct())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
||||
|
||||
nsIFrame *frame = GetFrame();
|
||||
NS_ENSURE_STATE(frame);
|
||||
|
||||
// If the current element can't take real DOM focus and if it has an ID and
|
||||
// ancestor with a the aria-activedescendant attribute present, then set DOM
|
||||
// focus to that ancestor and set aria-activedescendant on the ancestor to
|
||||
// the ID of the desired element.
|
||||
if (!frame->IsFocusable()) {
|
||||
nsAutoString id;
|
||||
if (content && nsAccUtils::GetID(content, id)) {
|
||||
|
||||
nsCOMPtr<nsIContent> ancestorContent = content;
|
||||
while ((ancestorContent = ancestorContent->GetParent()) &&
|
||||
!ancestorContent->HasAttr(kNameSpaceID_None,
|
||||
nsAccessibilityAtoms::aria_activedescendant));
|
||||
|
||||
if (ancestorContent) {
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
||||
if (presShell) {
|
||||
nsIFrame *frame = presShell->GetPrimaryFrameFor(ancestorContent);
|
||||
if (frame && frame->IsFocusable()) {
|
||||
|
||||
content = ancestorContent;
|
||||
content->SetAttr(kNameSpaceID_None,
|
||||
nsAccessibilityAtoms::aria_activedescendant,
|
||||
id, PR_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNSHTMLElement> htmlElement(do_QueryInterface(content));
|
||||
if (htmlElement) {
|
||||
// HTML Elements also set the caret position
|
||||
// in order to affect tabbing order
|
||||
return htmlElement->Focus();
|
||||
}
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
||||
if (!content) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
content->SetFocus(GetPresContext());
|
||||
|
||||
content->SetFocus(GetPresContext());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES =\
|
||||
test_aria_activedescendant.html \
|
||||
test_bug368835.xul \
|
||||
test_bug420863.html \
|
||||
test_groupattrs.xul \
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=429547
|
||||
-->
|
||||
<head>
|
||||
<title>Table indexes chrome tests</title>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
|
||||
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
|
||||
const ELEMENT_NODE = Components.interfaces.nsIDOMNode.ELEMENT_NODE;
|
||||
|
||||
var gAccRetrieval = null;
|
||||
var gContainerFocused = false;
|
||||
|
||||
function doTest()
|
||||
{
|
||||
var focusHandler = {
|
||||
handleEvent: function handleEvent(aEvent) {
|
||||
var target = aEvent.target;
|
||||
if (target.nodeType == ELEMENT_NODE &&
|
||||
target.getAttribute("id") == "container")
|
||||
gContainerFocused = true;
|
||||
}
|
||||
};
|
||||
|
||||
var container = document.getElementById("container");
|
||||
container.addEventListener("focus", focusHandler, false);
|
||||
|
||||
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
|
||||
getService(nsIAccessibleRetrieval);
|
||||
|
||||
var item2 = document.getElementById("item2");
|
||||
var item2Acc = null;
|
||||
try {
|
||||
item2Acc = gAccRetrieval.getAccessibleFor(item2);
|
||||
} catch (e) {}
|
||||
ok (item2Acc,
|
||||
"The element with ID and an ancestor with 'aria-activedescedant' attribute should be accessible.");
|
||||
|
||||
if (item2Acc)
|
||||
item2Acc.takeFocus();
|
||||
|
||||
ok(gContainerFocused,
|
||||
"Container with active descedant didn't recieved the focus.");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(doTest);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=429547"
|
||||
title="Support aria-activedescendant usage in nsIAccesible::TakeFocus()">
|
||||
Mozilla Bug 429547
|
||||
</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<div aria-activedescendant="item1" id="container" tabindex="1">
|
||||
<div id="item1">item1</div>
|
||||
<div id="item2">item2</div>
|
||||
<div id="item3">item3</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче