Bug 194977. Support <label> elements as ROLE_STATICTEXT like IE does, fix use of label name for controls when no form element. r=kyle, sr=henry

This commit is contained in:
aaronl%netscape.com 2003-03-06 18:50:39 +00:00
Родитель 44f512c44b
Коммит a24f59a714
7 изменённых файлов: 107 добавлений и 5 удалений

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

@ -49,7 +49,9 @@ interface nsIAccessibilityService : nsISupports
nsIAccessible createHTMLCheckboxAccessibleXBL(in nsIDOMNode aNode);
nsIAccessible createHTMLComboboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
nsIAccessible createHTMLGroupboxAccessible(in nsISupports aFrame);
nsIAccessible createHTMLHRAccessible(in nsISupports aFrame);
nsIAccessible createHTMLImageAccessible(in nsISupports aFrame);
nsIAccessible createHTMLLabelAccessible(in nsISupports aFrame);
nsIAccessible createHTMLListboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
nsIAccessible createHTMLNativeWindowAccessible(in nsIDOMNode aDOMNode, in nsIWeakReference aShell, in PRInt32 aHWnd);
nsIAccessible createHTMLPluginAccessible(in nsIDOMNode aDOMNode, in nsIWeakReference aShell);
@ -62,7 +64,6 @@ interface nsIAccessibilityService : nsISupports
nsIAccessible createHTMLTableHeadAccessible(in nsIDOMNode aDOMNode);
nsIAccessible createHTMLTextAccessible(in nsISupports aFrame);
nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame);
nsIAccessible createHTMLHRAccessible(in nsISupports aFrame);
nsIAccessible createXULButtonAccessible(in nsIDOMNode aNode);
nsIAccessible createXULCheckboxAccessible(in nsIDOMNode aNode);

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

@ -839,6 +839,24 @@ nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports *aFrame, nsIAc
return NS_OK;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLLabelAccessible(nsISupports *aFrame, nsIAccessible **_retval)
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIWeakReference> weakShell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLLabelAccessible(node, weakShell);
if (! *_retval)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLHRAccessible(nsISupports *aFrame, nsIAccessible **_retval)
{

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

@ -1483,6 +1483,9 @@ NS_IMETHODIMP nsAccessible::AppendLabelFor(nsIContent *aLookNode, const nsAStrin
*/
NS_IMETHODIMP nsAccessible::GetHTMLAccName(nsAString& _retval)
{
if (!mDOMNode) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLLabelElement> labelElement;
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
@ -1490,20 +1493,25 @@ NS_IMETHODIMP nsAccessible::GetHTMLAccName(nsAString& _retval)
nsAutoString label;
// go up tree get name of ancestor label if there is one. Don't go up farther than form element
while (walkUpContent && label.IsEmpty() && !formElement) {
while (label.IsEmpty() && !formElement) {
labelElement = do_QueryInterface(walkUpContent);
if (labelElement)
rv = AppendFlatStringFromSubtree(walkUpContent, &label);
formElement = do_QueryInterface(walkUpContent); // reached top ancestor in form
if (formElement) {
break;
}
nsCOMPtr<nsIContent> nextParent;
walkUpContent->GetParent(*getter_AddRefs(nextParent));
if (!nextParent) {
break;
}
walkUpContent = nextParent;
}
// There can be a label targeted at this control using the for="control_id" attribute
// To save computing time, only look for those inside of a form element
walkUpContent = do_QueryInterface(formElement);
if (walkUpContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));

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

@ -97,3 +97,59 @@ NS_IMETHODIMP nsHTMLBlockAccessible::GetAccState(PRUint32 *aState)
*aState &= ~STATE_FOCUSABLE;
return NS_OK;
}
nsHTMLLabelAccessible::nsHTMLLabelAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsTextAccessible(aDomNode, aShell)
{
}
NS_IMETHODIMP nsHTMLLabelAccessible::GetAccName(nsAString& aReturn)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsAutoString name;
if (content)
rv = AppendFlatStringFromSubtree(content, &name);
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAString
name.CompressWhitespace();
aReturn = name;
}
return rv;
}
NS_IMETHODIMP nsHTMLLabelAccessible::GetAccRole(PRUint32 *aRole)
{
*aRole = ROLE_STATICTEXT;
return NS_OK;
}
NS_IMETHODIMP nsHTMLLabelAccessible::GetAccState(PRUint32 *aState)
{
nsTextAccessible::GetAccState(aState);
*aState &= (STATE_LINKED|STATE_TRAVERSED); // Only use link states
return NS_OK;
}
NS_IMETHODIMP nsHTMLLabelAccessible::GetAccFirstChild(nsIAccessible **aAccFirstChild)
{
// A <label> is not necessarily a leaf!
return nsAccessible::GetAccFirstChild(aAccFirstChild);
}
/* readonly attribute nsIAccessible accFirstChild; */
NS_IMETHODIMP nsHTMLLabelAccessible::GetAccLastChild(nsIAccessible **aAccLastChild)
{
// A <label> is not necessarily a leaf!
return nsAccessible::GetAccLastChild(aAccLastChild);
}
/* readonly attribute long accChildCount; */
NS_IMETHODIMP nsHTMLLabelAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
{
// A <label> is not necessarily a leaf!
return nsAccessible::GetAccChildCount(aAccChildCount);
}

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

@ -72,4 +72,17 @@ public:
NS_IMETHOD GetAccState(PRUint32 *aState);
};
class nsHTMLLabelAccessible : public nsTextAccessible
{
public:
nsHTMLLabelAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **aAccFirstChild);
NS_IMETHOD GetAccLastChild(nsIAccessible **aAccLastChild);
NS_IMETHOD GetAccChildCount(PRInt32 *aAccChildCount);
};
#endif

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

@ -919,7 +919,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
*aAccessible = nsnull;
nsCOMPtr<nsIAtom> tagAtom;
mContent->GetTag(*getter_AddRefs(tagAtom));
if (tagAtom == nsHTMLAtoms::img || tagAtom == nsHTMLAtoms::input || tagAtom == nsHTMLAtoms::hr) {
if (tagAtom == nsHTMLAtoms::img || tagAtom == nsHTMLAtoms::input ||
tagAtom == nsHTMLAtoms::label || tagAtom == nsHTMLAtoms::hr) {
// Only get accessibility service if we're going to use it
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (!accService)
@ -928,6 +929,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken <img>
return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
else if (tagAtom == nsHTMLAtoms::label) // Creat accessible for <label>
return accService->CreateHTMLLabelAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
// Create accessible for <hr>
return accService->CreateHTMLHRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
}

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

@ -919,7 +919,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
*aAccessible = nsnull;
nsCOMPtr<nsIAtom> tagAtom;
mContent->GetTag(*getter_AddRefs(tagAtom));
if (tagAtom == nsHTMLAtoms::img || tagAtom == nsHTMLAtoms::input || tagAtom == nsHTMLAtoms::hr) {
if (tagAtom == nsHTMLAtoms::img || tagAtom == nsHTMLAtoms::input ||
tagAtom == nsHTMLAtoms::label || tagAtom == nsHTMLAtoms::hr) {
// Only get accessibility service if we're going to use it
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (!accService)
@ -928,6 +929,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken <img>
return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
else if (tagAtom == nsHTMLAtoms::label) // Creat accessible for <label>
return accService->CreateHTMLLabelAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
// Create accessible for <hr>
return accService->CreateHTMLHRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
}