зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
52677ea55f
Коммит
8ac3b448d6
|
@ -49,7 +49,9 @@ interface nsIAccessibilityService : nsISupports
|
||||||
nsIAccessible createHTMLCheckboxAccessibleXBL(in nsIDOMNode aNode);
|
nsIAccessible createHTMLCheckboxAccessibleXBL(in nsIDOMNode aNode);
|
||||||
nsIAccessible createHTMLComboboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
|
nsIAccessible createHTMLComboboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
|
||||||
nsIAccessible createHTMLGroupboxAccessible(in nsISupports aFrame);
|
nsIAccessible createHTMLGroupboxAccessible(in nsISupports aFrame);
|
||||||
|
nsIAccessible createHTMLHRAccessible(in nsISupports aFrame);
|
||||||
nsIAccessible createHTMLImageAccessible(in nsISupports aFrame);
|
nsIAccessible createHTMLImageAccessible(in nsISupports aFrame);
|
||||||
|
nsIAccessible createHTMLLabelAccessible(in nsISupports aFrame);
|
||||||
nsIAccessible createHTMLListboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
|
nsIAccessible createHTMLListboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
|
||||||
nsIAccessible createHTMLNativeWindowAccessible(in nsIDOMNode aDOMNode, in nsIWeakReference aShell, in PRInt32 aHWnd);
|
nsIAccessible createHTMLNativeWindowAccessible(in nsIDOMNode aDOMNode, in nsIWeakReference aShell, in PRInt32 aHWnd);
|
||||||
nsIAccessible createHTMLPluginAccessible(in nsIDOMNode aDOMNode, in nsIWeakReference aShell);
|
nsIAccessible createHTMLPluginAccessible(in nsIDOMNode aDOMNode, in nsIWeakReference aShell);
|
||||||
|
@ -62,7 +64,6 @@ interface nsIAccessibilityService : nsISupports
|
||||||
nsIAccessible createHTMLTableHeadAccessible(in nsIDOMNode aDOMNode);
|
nsIAccessible createHTMLTableHeadAccessible(in nsIDOMNode aDOMNode);
|
||||||
nsIAccessible createHTMLTextAccessible(in nsISupports aFrame);
|
nsIAccessible createHTMLTextAccessible(in nsISupports aFrame);
|
||||||
nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame);
|
nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame);
|
||||||
nsIAccessible createHTMLHRAccessible(in nsISupports aFrame);
|
|
||||||
|
|
||||||
nsIAccessible createXULButtonAccessible(in nsIDOMNode aNode);
|
nsIAccessible createXULButtonAccessible(in nsIDOMNode aNode);
|
||||||
nsIAccessible createXULCheckboxAccessible(in nsIDOMNode aNode);
|
nsIAccessible createXULCheckboxAccessible(in nsIDOMNode aNode);
|
||||||
|
|
|
@ -839,6 +839,24 @@ nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports *aFrame, nsIAc
|
||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
nsAccessibilityService::CreateHTMLHRAccessible(nsISupports *aFrame, nsIAccessible **_retval)
|
nsAccessibilityService::CreateHTMLHRAccessible(nsISupports *aFrame, nsIAccessible **_retval)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1483,6 +1483,9 @@ NS_IMETHODIMP nsAccessible::AppendLabelFor(nsIContent *aLookNode, const nsAStrin
|
||||||
*/
|
*/
|
||||||
NS_IMETHODIMP nsAccessible::GetHTMLAccName(nsAString& _retval)
|
NS_IMETHODIMP nsAccessible::GetHTMLAccName(nsAString& _retval)
|
||||||
{
|
{
|
||||||
|
if (!mDOMNode) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
|
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
|
||||||
nsCOMPtr<nsIDOMHTMLLabelElement> labelElement;
|
nsCOMPtr<nsIDOMHTMLLabelElement> labelElement;
|
||||||
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
|
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
|
||||||
|
@ -1490,20 +1493,25 @@ NS_IMETHODIMP nsAccessible::GetHTMLAccName(nsAString& _retval)
|
||||||
|
|
||||||
nsAutoString label;
|
nsAutoString label;
|
||||||
// go up tree get name of ancestor label if there is one. Don't go up farther than form element
|
// 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);
|
labelElement = do_QueryInterface(walkUpContent);
|
||||||
if (labelElement)
|
if (labelElement)
|
||||||
rv = AppendFlatStringFromSubtree(walkUpContent, &label);
|
rv = AppendFlatStringFromSubtree(walkUpContent, &label);
|
||||||
formElement = do_QueryInterface(walkUpContent); // reached top ancestor in form
|
formElement = do_QueryInterface(walkUpContent); // reached top ancestor in form
|
||||||
|
if (formElement) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
nsCOMPtr<nsIContent> nextParent;
|
nsCOMPtr<nsIContent> nextParent;
|
||||||
walkUpContent->GetParent(*getter_AddRefs(nextParent));
|
walkUpContent->GetParent(*getter_AddRefs(nextParent));
|
||||||
|
if (!nextParent) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
walkUpContent = nextParent;
|
walkUpContent = nextParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// There can be a label targeted at this control using the for="control_id" attribute
|
// 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
|
// To save computing time, only look for those inside of a form element
|
||||||
walkUpContent = do_QueryInterface(formElement);
|
|
||||||
|
|
||||||
if (walkUpContent) {
|
if (walkUpContent) {
|
||||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
|
||||||
|
|
|
@ -97,3 +97,59 @@ NS_IMETHODIMP nsHTMLBlockAccessible::GetAccState(PRUint32 *aState)
|
||||||
*aState &= ~STATE_FOCUSABLE;
|
*aState &= ~STATE_FOCUSABLE;
|
||||||
return NS_OK;
|
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);
|
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
|
#endif
|
||||||
|
|
|
@ -919,7 +919,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
|
||||||
*aAccessible = nsnull;
|
*aAccessible = nsnull;
|
||||||
nsCOMPtr<nsIAtom> tagAtom;
|
nsCOMPtr<nsIAtom> tagAtom;
|
||||||
mContent->GetTag(*getter_AddRefs(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
|
// Only get accessibility service if we're going to use it
|
||||||
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
|
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
|
||||||
if (!accService)
|
if (!accService)
|
||||||
|
@ -928,6 +929,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
|
||||||
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
||||||
else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken <img>
|
else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken <img>
|
||||||
return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
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>
|
// Create accessible for <hr>
|
||||||
return accService->CreateHTMLHRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
return accService->CreateHTMLHRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
||||||
}
|
}
|
||||||
|
|
|
@ -919,7 +919,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
|
||||||
*aAccessible = nsnull;
|
*aAccessible = nsnull;
|
||||||
nsCOMPtr<nsIAtom> tagAtom;
|
nsCOMPtr<nsIAtom> tagAtom;
|
||||||
mContent->GetTag(*getter_AddRefs(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
|
// Only get accessibility service if we're going to use it
|
||||||
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
|
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
|
||||||
if (!accService)
|
if (!accService)
|
||||||
|
@ -928,6 +929,8 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible)
|
||||||
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
||||||
else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken <img>
|
else if (tagAtom == nsHTMLAtoms::img) // Create accessible for broken <img>
|
||||||
return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
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>
|
// Create accessible for <hr>
|
||||||
return accService->CreateHTMLHRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
return accService->CreateHTMLHRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче