bug 559773 - make html5 progress element accessible r=marcoz,trev

From ed8e50f56d7c619a6df4ac906a5887d9788d58e2 Mon Sep 17 00:00:00 2001
https://bugzilla.mozilla.org/show_bug.cgi?id=559773
---
 accessible/src/base/nsAccessibilityAtomList.h      |    1 +
 accessible/src/base/nsAccessibilityService.cpp     |    9 +-
 accessible/src/base/nsFormControlAccessible.cpp    |  137 ++++++++++++++++++++
 accessible/src/base/nsFormControlAccessible.h      |   22 +++
 accessible/src/html/nsHTMLFormControlAccessible.h  |    5 +
 accessible/src/xul/nsXULFormControlAccessible.cpp  |  133 -------------------
 accessible/src/xul/nsXULFormControlAccessible.h    |   21 +---
 accessible/tests/mochitest/Makefile.in             |    3 +-
 accessible/tests/mochitest/value/Makefile.in       |   55 ++++++++
 .../{test_value.html => value/test_general.html}   |    4 +-
 .../tests/mochitest/value/test_progress.html       |   63 +++++++++
 .../{test_value.xul => value/test_progress.xul}    |    8 +-
 12 files changed, 303 insertions(+), 158 deletions(-)
 create mode 100644 accessible/tests/mochitest/value/Makefile.in
 rename accessible/tests/mochitest/{test_value.html => value/test_general.html} (98%)
 create mode 100644 accessible/tests/mochitest/value/test_progress.html
 rename accessible/tests/mochitest/{test_value.xul => value/test_progress.xul} (93%)

--HG--
rename : accessible/tests/mochitest/test_value.html => accessible/tests/mochitest/value/test_general.html
rename : accessible/tests/mochitest/test_value.xul => accessible/tests/mochitest/value/test_progress.xul
This commit is contained in:
Alexander Surkov 2011-05-11 22:55:12 -04:00
Родитель 92fadb988d
Коммит 9ca063a8a9
12 изменённых файлов: 310 добавлений и 160 удалений

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

@ -144,6 +144,7 @@ ACCESSIBILITY_ATOM(optgroup, "optgroup")
ACCESSIBILITY_ATOM(option, "option")
ACCESSIBILITY_ATOM(output, "output")
ACCESSIBILITY_ATOM(panel, "panel") // XUL
ACCESSIBILITY_ATOM(progress, "progress")
ACCESSIBILITY_ATOM(q, "q")
ACCESSIBILITY_ATOM(select, "select")
ACCESSIBILITY_ATOM(select1, "select1") // XForms

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

@ -1432,7 +1432,7 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent,
break;
case nsIAccessibleProvider::XULProgressMeter:
accessible = new nsXULProgressMeterAccessible(aContent, aWeakShell);
accessible = new XULProgressMeterAccessible(aContent, aWeakShell);
break;
case nsIAccessibleProvider::XULStatusBar:
@ -1691,6 +1691,13 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame,
return accessible;
}
if (tag == nsAccessibilityAtoms::progress) {
nsAccessible* accessible =
new HTMLProgressMeterAccessible(aContent, aWeakShell);
NS_IF_ADDREF(accessible);
return accessible;
}
return nsnull;
}

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

@ -44,6 +44,143 @@
#include "nsIDOMXULElement.h"
#include "nsIDOMXULControlElement.h"
////////////////////////////////////////////////////////////////////////////////
// ProgressMeterAccessible
////////////////////////////////////////////////////////////////////////////////
template class ProgressMeterAccessible<1>;
template class ProgressMeterAccessible<100>;
////////////////////////////////////////////////////////////////////////////////
// nsISupports
template<int Max>
NS_IMPL_ADDREF_INHERITED(ProgressMeterAccessible<Max>, nsFormControlAccessible)
template<int Max>
NS_IMPL_RELEASE_INHERITED(ProgressMeterAccessible<Max>, nsFormControlAccessible)
template<int Max>
NS_IMPL_QUERY_INTERFACE_INHERITED1(ProgressMeterAccessible<Max>,
nsFormControlAccessible,
nsIAccessibleValue)
////////////////////////////////////////////////////////////////////////////////
// nsAccessible
template<int Max>
PRUint32
ProgressMeterAccessible<Max>::NativeRole()
{
return nsIAccessibleRole::ROLE_PROGRESSBAR;
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessibleValue
template<int Max>
NS_IMETHODIMP
ProgressMeterAccessible<Max>::GetValue(nsAString& aValue)
{
nsresult rv = nsFormControlAccessible::GetValue(aValue);
NS_ENSURE_SUCCESS(rv, rv);
if (!aValue.IsEmpty())
return NS_OK;
double maxValue = 0;
rv = GetMaximumValue(&maxValue);
NS_ENSURE_SUCCESS(rv, rv);
double curValue = 0;
rv = GetCurrentValue(&curValue);
NS_ENSURE_SUCCESS(rv, rv);
// Treat the current value bigger than maximum as 100%.
double percentValue = (curValue < maxValue) ?
(curValue / maxValue) * 100 : 100;
nsAutoString value;
value.AppendFloat(percentValue); // AppendFloat isn't available on nsAString
value.AppendLiteral("%");
aValue = value;
return NS_OK;
}
template<int Max>
NS_IMETHODIMP
ProgressMeterAccessible<Max>::GetMaximumValue(double* aMaximumValue)
{
nsresult rv = nsFormControlAccessible::GetMaximumValue(aMaximumValue);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
nsAutoString value;
if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::max, value)) {
PRInt32 result = NS_OK;
*aMaximumValue = value.ToDouble(&result);
return result;
}
*aMaximumValue = Max;
return NS_OK;
}
template<int Max>
NS_IMETHODIMP
ProgressMeterAccessible<Max>::GetMinimumValue(double* aMinimumValue)
{
nsresult rv = nsFormControlAccessible::GetMinimumValue(aMinimumValue);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
*aMinimumValue = 0;
return NS_OK;
}
template<int Max>
NS_IMETHODIMP
ProgressMeterAccessible<Max>::GetMinimumIncrement(double* aMinimumIncrement)
{
nsresult rv = nsFormControlAccessible::GetMinimumIncrement(aMinimumIncrement);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
*aMinimumIncrement = 0;
return NS_OK;
}
template<int Max>
NS_IMETHODIMP
ProgressMeterAccessible<Max>::GetCurrentValue(double* aCurrentValue)
{
nsresult rv = nsFormControlAccessible::GetCurrentValue(aCurrentValue);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
nsAutoString attrValue;
mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, attrValue);
// Return zero value if there is no attribute or its value is empty.
if (attrValue.IsEmpty())
return NS_OK;
PRInt32 error = NS_OK;
double value = attrValue.ToDouble(&error);
if (NS_FAILED(error))
return NS_OK; // Zero value because of wrong markup.
*aCurrentValue = value;
return NS_OK;
}
template<int Max>
NS_IMETHODIMP
ProgressMeterAccessible<Max>::SetCurrentValue(double aValue)
{
return NS_ERROR_FAILURE; // Progress meters are readonly.
}
////////////////////////////////////////////////////////////////////////////////
// nsRadioButtonAccessible
////////////////////////////////////////////////////////////////////////////////

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

@ -43,6 +43,28 @@
typedef nsLeafAccessible nsFormControlAccessible;
/**
* Generic class used for progress meters.
*/
template<int Max>
class ProgressMeterAccessible: public nsFormControlAccessible
{
public:
ProgressMeterAccessible(nsIContent* aContent, nsIWeakReference* aShell) :
nsFormControlAccessible(aContent, aShell)
{
}
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEVALUE
// nsIAccessible
NS_IMETHOD GetValue(nsAString &aValue);
// nsAccessible
virtual PRUint32 NativeRole();
};
/**
* Generic class used for radio buttons.
*/

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

@ -42,6 +42,11 @@
#include "nsFormControlAccessible.h"
#include "nsHyperTextAccessibleWrap.h"
/**
* Accessible for HTML progress element.
*/
typedef ProgressMeterAccessible<1> HTMLProgressMeterAccessible;
/**
* Accessible for HTML input@type="checkbox".
*/

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

@ -463,139 +463,6 @@ nsXULGroupboxAccessible::GetRelationByType(PRUint32 aRelationType,
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsXULProgressMeterAccessible
////////////////////////////////////////////////////////////////////////////////
nsXULProgressMeterAccessible::
nsXULProgressMeterAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
nsFormControlAccessible(aContent, aShell)
{
}
NS_IMPL_ISUPPORTS_INHERITED1(nsXULProgressMeterAccessible,
nsFormControlAccessible,
nsIAccessibleValue)
// nsAccessible
PRUint32
nsXULProgressMeterAccessible::NativeRole()
{
return nsIAccessibleRole::ROLE_PROGRESSBAR;
}
// nsIAccessibleValue
NS_IMETHODIMP
nsXULProgressMeterAccessible::GetValue(nsAString& aValue)
{
nsresult rv = nsFormControlAccessible::GetValue(aValue);
NS_ENSURE_SUCCESS(rv, rv);
if (!aValue.IsEmpty())
return NS_OK;
double maxValue = 0;
rv = GetMaximumValue(&maxValue);
NS_ENSURE_SUCCESS(rv, rv);
if (maxValue != 1) {
double curValue = 0;
rv = GetCurrentValue(&curValue);
NS_ENSURE_SUCCESS(rv, rv);
double percentValue = (curValue / maxValue) * 100;
nsAutoString value;
value.AppendFloat(percentValue); // AppendFloat isn't available on nsAString
value.AppendLiteral("%");
aValue = value;
return NS_OK;
}
mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, aValue);
if (aValue.IsEmpty())
aValue.AppendLiteral("0"); // Empty value for progress meter = 0%
aValue.AppendLiteral("%");
return NS_OK;
}
NS_IMETHODIMP
nsXULProgressMeterAccessible::GetMaximumValue(double *aMaximumValue)
{
nsresult rv = nsFormControlAccessible::GetMaximumValue(aMaximumValue);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
nsAutoString value;
if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::max, value)) {
PRInt32 result = NS_OK;
*aMaximumValue = value.ToDouble(&result);
return result;
}
*aMaximumValue = 1; // 100% = 1;
return NS_OK;
}
NS_IMETHODIMP
nsXULProgressMeterAccessible::GetMinimumValue(double *aMinimumValue)
{
nsresult rv = nsFormControlAccessible::GetMinimumValue(aMinimumValue);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
*aMinimumValue = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXULProgressMeterAccessible::GetMinimumIncrement(double *aMinimumIncrement)
{
nsresult rv = nsFormControlAccessible::GetMinimumIncrement(aMinimumIncrement);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
*aMinimumIncrement = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXULProgressMeterAccessible::GetCurrentValue(double *aCurrentValue)
{
nsresult rv = nsFormControlAccessible::GetCurrentValue(aCurrentValue);
if (rv != NS_OK_NO_ARIA_VALUE)
return rv;
nsAutoString attrValue;
mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, attrValue);
// Return zero value if there is no attribute or its value is empty.
if (attrValue.IsEmpty())
return NS_OK;
PRInt32 error = NS_OK;
double value = attrValue.ToDouble(&error);
if (NS_FAILED(error))
return NS_OK; // Zero value because of wrong markup.
// If no max value then value is between 0 and 1 (refer to GetMaximumValue()
// method where max value is assumed to be equal to 1 in this case).
if (!mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::max))
value /= 100;
*aCurrentValue = value;
return NS_OK;
}
NS_IMETHODIMP
nsXULProgressMeterAccessible::SetCurrentValue(double aValue)
{
return NS_ERROR_FAILURE; // Progress meters are readonly!
}
////////////////////////////////////////////////////////////////////////////////
// nsXULRadioButtonAccessible
////////////////////////////////////////////////////////////////////////////////

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

@ -46,6 +46,11 @@
#include "nsXULMenuAccessible.h"
#include "nsHyperTextAccessibleWrap.h"
/**
* Used for XUL progressmeter element.
*/
typedef ProgressMeterAccessible<100> XULProgressMeterAccessible;
/**
* Used for XUL button.
*
@ -138,22 +143,6 @@ public:
virtual nsresult GetNameInternal(nsAString& aName);
};
/**
* Used for XUL progressmeter element.
*/
class nsXULProgressMeterAccessible : public nsFormControlAccessible
{
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEVALUE
public:
nsXULProgressMeterAccessible(nsIContent *aContent, nsIWeakReference *aShell);
NS_IMETHOD GetValue(nsAString &aValue);
// nsAccessible
virtual PRUint32 NativeRole();
};
/**
* Used for XUL radio element (radio button).
*/

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

@ -57,6 +57,7 @@ DIRS = \
text \
tree \
treeupdate \
value \
$(null)
include $(DEPTH)/config/autoconf.mk
@ -109,8 +110,6 @@ _TEST_FILES =\
test_text_caret.html \
test_textboxes.html \
test_textboxes.xul \
test_value.html \
test_value.xul \
testTextboxes.js \
text.js \
treeview.css \

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

@ -0,0 +1,55 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Alexander Surkov <surkov.alexander@gmail.com> (original author)
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = accessible/value
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES =\
test_general.html \
test_progress.html \
test_progress.xul \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)

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

@ -22,10 +22,10 @@
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="common.js"></script>
src="../common.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/chrome-harness.js"/>
src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript">
function doTest()
@ -39,7 +39,7 @@
}
var rootDir = getRootDirectory(window.location.href);
var href = rootDir.path + "foo";
var href = getRootDirectory(window.location.href) + "foo";
// roles that can't live as nsHTMLLinkAccessibles
testValue("aria_menuitem_link", "");
@ -68,6 +68,11 @@
title="Do not expose a11y info specific to hyperlinks when role is overridden using ARIA">
Mozilla Bug 494807
</a><br />
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<a id="aria_menuitem_link" role="menuitem" href="foo">menuitem</a>
<a id="aria_button_link" role="button" href="foo">button</a>
@ -77,7 +82,7 @@
<a id="aria_application_link" role="application" href="foo">app</a>
<a id="aria_main_link" role="main" href="foo">main</a>
<a id="aria_navigation_link" role="navigation" href="foo">nav</a>
<!-- strange edge case: please don't do this in the wild -->
<a id="aria_link_link" role="link" href="foo">link</a>

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

@ -0,0 +1,63 @@
<html>
<head>
<title>nsIAccessible value testing for progress element</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"
src="../common.js"></script>
<script type="application/javascript"
src="../value.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript">
function doTest()
{
// HTML5 progress element tests
testValue("pr_indeterminate", "0%", 0, 0, 1, 0);
testValue("pr_zero", "0%", 0, 0, 1, 0);
testValue("pr_zeropointfive", "50%", 0.5, 0, 1, 0);
testValue("pr_one", "100%", 1, 0, 1, 0);
testValue("pr_42", "100%", 42, 0, 1, 0);
testValue("pr_21", "50%", 21, 0, 42, 0);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=559773"
title="make HTML5 progress element accessible">
Mozilla Bug 559773
</a><br />
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<!-- HTML5 progress element -->
<progress id="pr_indeterminate">this will be read by legacy browsers</progress>
<progress id="pr_zero" value="0">this will be read by legacy browsers</progress>
<progress id="pr_zeropointfive" value="0.5">this will be read by legacy browsers</progress>
<progress id="pr_one" value="1">this will be read by legacy browsers</progress>
<progress id="pr_42" value="42">this will be read by legacy browsers</progress>
<progress id="pr_21" value="21" max="42">this will be read by legacy browsers</progress>
</body>
</html>

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

@ -12,18 +12,18 @@
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript"
src="common.js" />
src="../common.js" />
<script type="application/javascript"
src="value.js" />
src="../value.js" />
<script type="application/javascript">
<![CDATA[
function doTest()
{
// progressmeter
testValue("pm1", "50%", .5, 0, 1, 0);
testValue("pm1", "50%", 50, 0, 100, 0);
testValue("pm2", "50%", 500, 0, 1000, 0);
testValue("pm3", "0%", 0, 0, 1, 0);
testValue("pm3", "0%", 0, 0, 100, 0);
// scale
testValue("sc1", "500", 500, 0, 1000, 10);