Bug 438782 – Links should not unconditionally receive an accessible action of jump, r=MarcoZ

This commit is contained in:
Alexander Surkov 2008-06-20 13:50:27 +08:00
parent 360b3ef7a6
commit f88da4bbe8
3 changed files with 56 additions and 2 deletions

View File

@ -143,6 +143,9 @@ nsHTMLLinkAccessible::GetNumActions(PRUint8 *aNumActions)
{
NS_ENSURE_ARG_POINTER(aNumActions);
if (!IsLinked())
return nsHyperTextAccessible::GetNumActions(aNumActions);
*aNumActions = 1;
return NS_OK;
}
@ -150,8 +153,12 @@ nsHTMLLinkAccessible::GetNumActions(PRUint8 *aNumActions)
NS_IMETHODIMP
nsHTMLLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
{
// Action 0 (default action): Jump to link
aName.Truncate();
if (!IsLinked())
return nsHyperTextAccessible::GetActionName(aIndex, aName);
// Action 0 (default action): Jump to link
if (aIndex != eAction_Jump)
return NS_ERROR_INVALID_ARG;
@ -162,6 +169,9 @@ nsHTMLLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
NS_IMETHODIMP
nsHTMLLinkAccessible::DoAction(PRUint8 aIndex)
{
if (!IsLinked())
return nsHyperTextAccessible::DoAction(aIndex);
// Action 0 (default action): Jump to link
if (aIndex != eAction_Jump)
return NS_ERROR_INVALID_ARG;
@ -190,3 +200,20 @@ nsHTMLLinkAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
return link->GetHrefURI(aURI);
}
////////////////////////////////////////////////////////////////////////////////
// Protected members
PRBool
nsHTMLLinkAccessible::IsLinked()
{
nsCOMPtr<nsILink> link(do_QueryInterface(mDOMNode));
if (!link)
return PR_FALSE;
nsLinkState linkState;
nsresult rv = link->GetLinkState(linkState);
return NS_SUCCEEDED(rv) && linkState != eLinkState_NotLink &&
linkState != eLinkState_Unknown;
}

View File

@ -64,6 +64,11 @@ public:
protected:
enum { eAction_Jump = 0 };
/**
* Returns true if the link has href attribute.
*/
PRBool IsLinked();
};
#endif

View File

@ -62,6 +62,22 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
+ aID + "!");
}
function testAction(aId, aAcc, aActionName)
{
var numActions = aActionName ? 1 : 0;
is(aAcc.numActions, numActions,
"Wrong actions number for ID " + aId);
try {
is(aAcc.getActionName(0), aActionName,
"Wrong action name for ID " + aId);
} catch (e) {
if (numActions)
ok(false, "Exception on action name getting for ID " + aId);
else
ok(true, "Correct action name for ID " + aId);
}
}
function doTest()
{
// Mapping needed state flags for easier handling.
@ -131,6 +147,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates("AriaHyperlink", ariaHyperlinkAcc,
(state_focusable | state_focused | state_linked),
(ext_state_horizontal), (0));
testAction("AriaHyperlink", ariaHyperlinkAcc, "click");
//////////////////////////////////////////////////////////////////////////
// ARIA hyperlink with status invalid
@ -227,6 +244,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates("emptyLink", EmptyHLAcc,
(state_focusable | state_linked),
(ext_state_horizontal), (0));
testAction("emptyLink", EmptyHLAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// normal hyperlink with embedded span
@ -251,6 +269,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates("LinkWithSpan", hyperlinkWithSpanAcc,
(state_focusable | state_focused | state_linked),
(ext_state_horizontal), (0));
testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Named anchor, should never have state_linked
@ -268,6 +287,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates("namedAnchor", namedAnchorAcc,
(state_selectable),
(ext_state_horizontal), (state_focusable | state_linked));
testAction("namedAnchor", namedAnchorAcc, "");
//////////////////////////////////////////////////////////////////////////
// No link (hasn't any attribute), should never have state_linked
@ -285,6 +305,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates("noLink", noLinkAcc,
0,
(ext_state_horizontal), (state_focusable | state_linked));
testAction("noLink", noLinkAcc, "");
//////////////////////////////////////////////////////////////////////////
// Link with registered 'click' event, should have state_linked
@ -302,6 +323,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
testStates("linkWithClick", linkWithClickAcc,
(state_linked),
(ext_state_horizontal), 0);
testAction("linkWithClick", linkWithClickAcc, "click");
//////////////////////////////////////////////////////////////////////////
// Maps to group links (bug 431615).