Bug 1226000 - control may pick up its name from wrong label, r=yzen

This commit is contained in:
Alexander Surkov 2015-11-24 14:44:24 -05:00
parent 18a59c1a5f
commit f074f0378b
7 changed files with 45 additions and 39 deletions

View File

@ -9,7 +9,7 @@
#include "XULTreeAccessible.h"
#endif
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLLabelElement.h"
using namespace mozilla;
using namespace mozilla::a11y;
@ -134,6 +134,14 @@ HTMLLabelIterator::
{
}
bool
HTMLLabelIterator::IsLabel(Accessible* aLabel)
{
dom::HTMLLabelElement* labelEl =
dom::HTMLLabelElement::FromContent(aLabel->GetContent());
return labelEl && labelEl->GetControl() == mAcc->GetContent();
}
Accessible*
HTMLLabelIterator::Next()
{
@ -141,8 +149,9 @@ HTMLLabelIterator::Next()
// element, or <label> ancestor which implicitly point to it.
Accessible* label = nullptr;
while ((label = mRelIter.Next())) {
if (label->GetContent()->IsHTMLElement(nsGkAtoms::label))
if (IsLabel(label)) {
return label;
}
}
// Ignore ancestor label on not widget accessible.
@ -154,14 +163,14 @@ HTMLLabelIterator::Next()
// document.
Accessible* walkUp = mAcc->Parent();
while (walkUp && !walkUp->IsDoc()) {
nsIContent* walkUpElm = walkUp->GetContent();
if (walkUpElm->IsHTMLElement(nsGkAtoms::label) &&
!walkUpElm->HasAttr(kNameSpaceID_None, nsGkAtoms::_for)) {
nsIContent* walkUpEl = walkUp->GetContent();
if (IsLabel(walkUp) &&
!walkUpEl->HasAttr(kNameSpaceID_None, nsGkAtoms::_for)) {
mLabelFilter = eSkipAncestorLabel; // prevent infinite loop
return walkUp;
}
if (walkUpElm->IsHTMLElement(nsGkAtoms::form))
if (walkUpEl->IsHTMLElement(nsGkAtoms::form))
break;
walkUp = walkUp->Parent();

View File

@ -130,6 +130,8 @@ private:
HTMLLabelIterator(const HTMLLabelIterator&);
HTMLLabelIterator& operator = (const HTMLLabelIterator&);
bool IsLabel(Accessible* aLabel);
RelatedAccIterator mRelIter;
// XXX: replace it on weak reference (bug 678429), it's safe to use raw
// pointer now because iterators life cycle is short.

View File

@ -68,7 +68,7 @@ HTMLLabelAccessible::RelationByType(RelationType aType)
{
Relation rel = AccessibleWrap::RelationByType(aType);
if (aType == RelationType::LABEL_FOR) {
RefPtr<dom::HTMLLabelElement> label = dom::HTMLLabelElement::FromContent(mContent);
dom::HTMLLabelElement* label = dom::HTMLLabelElement::FromContent(mContent);
rel.AppendTarget(mDoc, label->GetControl());
}

View File

@ -197,15 +197,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates(linkAcc, STATE_LINKED, 0);
testAction(id, linkAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Link with label, no name from the subtree (bug 438325).
id = "linkWithLabelNoNameFromSubtree";
linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
testThis(id, linkAcc, ROLE_LINK, 1, "Link with label and nested image:",
true, 450, 451);
testStates(linkAcc, STATE_LINKED, 0);
testAction(id, linkAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Text accessible shouldn't implement nsIAccessibleHyperLink
var res = isAccessible(getNode("namedAnchor").firstChild,
@ -278,10 +269,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
><br>Link with title attribute (name from nested image): <a
id="linkWithTitleNameFromImg" href="http://www.heise.de/"
title="Link with title"><img src="" alt="The title for link"/></a
><br><label for="linkWithLabelNoNameFromSubtree">Link with label and nested image: </label><a
id="linkWithLabelNoNameFromSubtree"
href="http://www.heise.de/"><img src=""/></a
><br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass), also see the bug 431615:<br
><br><br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass), also see the bug 431615:<br
><map id="linksmap" title="Site navigation"><ul
><li><a href="http://mozilla.org">About the project</a></li
><li><a href="http://mozilla.org">Sites and sounds</a></li

View File

@ -92,50 +92,55 @@
<rule attr="aria-label" type="string"/>
</ruleset>
<ruleset id="HTMLElm:Head">
<ruleset id="HTMLControl:Head">
<ruleset ref="ARIA"/>
<rule elm="label" elmattr="for"/>
</ruleset>
<!-- general -->
<ruleset id="HTMLControl">
<ruleset ref="ARIA"/>
<rule elm="label" elmattr="for"/>
<ruleset ref="HTMLControl:Head"/>
<rule fromsubtree="true"/>
<rule attr="title" type="string"/>
</ruleset>
<ruleset id="HTMLElm">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="ARIA"/>
<rule attr="title" type="string"/>
</ruleset>
<!-- specific -->
<ruleset id="HTMLARIAGridCell">
<ruleset ref="ARIA"/>
<rule fromsubtree="true"/>
<rule attr="title" type="string"/>
</ruleset>
<ruleset id="HTMLInputButton">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="HTMLControl:Head"/>
<rule attr="value" type="string" explict-name="false" reordered="true"/>
<rule attr="title" type="string"/>
</ruleset>
<ruleset id="HTMLInputSubmit" defaultName="Submit Query">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="HTMLControl:Head"/>
<rule attr="value" type="string" explict-name="false" textchanged="true"/>
</ruleset>
<ruleset id="HTMLInputReset" defaultName="Reset">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="HTMLControl:Head"/>
<rule attr="value" type="string" explict-name="false" textchanged="true"/>
</ruleset>
<ruleset id="HTMLInputImage">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="HTMLControl:Head"/>
<rule attr="alt" type="string" recreated="true"/>
<rule attr="value" type="string" recreated="true"/>
<rule attr="title" type="string"/>
</ruleset>
<ruleset id="HTMLInputImageNoValidSrc" defaultName="Submit Query">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="HTMLControl:Head"/>
<rule attr="alt" type="string" explict-name="false" recreated="true"/>
<rule attr="value" type="string" explict-name="false" recreated="true"/>
</ruleset>
@ -160,7 +165,7 @@
</ruleset>
<ruleset id="HTMLTable">
<ruleset ref="HTMLElm:Head"/>
<ruleset ref="ARIA"/>
<rule elm="caption"/>
<rule attr="summary" type="string"/>
<rule attr="title" type="string"/>
@ -321,7 +326,7 @@
</markup>
<markup id="HTMLTdARIAGridCellTest"
ref="html:table/html:tr/html:td" ruleset="HTMLControl">
ref="html:table/html:tr/html:td" ruleset="HTMLARIAGridCell">
<html:span id="l1" textequiv="test2">test2</html:span>
<html:span id="l2" textequiv="test3">test3</html:span>
<html:label for="gc" textequiv="test4">test4</html:label>

View File

@ -120,6 +120,10 @@
// Multiple label elements for single button
testName("btn_label_multi", "label1label2");
// Multiple controls inside a label element
testName("ctrl_in_label_1", "Enable a button control");
testName("ctrl_in_label_2", "button");
//////////////////////////////////////////////////////////////////////////
// name from children
@ -447,6 +451,12 @@
<label for="btn_label_multi">label2</label>
<button id="btn_label_multi">button</button>
<!-- a label containing more than one controls -->
<label>
Enable <input id="ctrl_in_label_1" type="checkbox"> a
<input id="ctrl_in_label_2" type="button" value="button"> control
</label>
<!-- name from children -->
<span id="btn_children" role="button">14</span>

View File

@ -23,9 +23,6 @@
// aria-labelledby
testName("aria_labelledby", "text");
// html:label
testName("label", "label");
// name from content
testName("namefromcontent", "1");
@ -71,11 +68,6 @@
aria-labelledby="text">1</a>
<br/>
<!-- label, preferred to name from content -->
<label for="label">label</label>
<a id="label" href="mozilla.org">1</a>
<br/>
<!-- name from content, preferred to @title -->
<a id="namefromcontent" href="mozilla.org"
title="title">1</a>