Bug 740747 - dexpcom nsAccessible::GetName, r=surkov, tbsaunde

This commit is contained in:
Mark Capella 2012-05-01 12:08:31 +09:00
Родитель c93f80ef1d
Коммит bf3257ec42
26 изменённых файлов: 145 добавлений и 146 удалений

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

@ -690,14 +690,15 @@ ApplicationAccessibleWrap::Unload()
// }
}
NS_IMETHODIMP
ApplicationAccessibleWrap::GetName(nsAString& aName)
ENameValueFlag
ApplicationAccessibleWrap::Name(nsString& aName)
{
// ATK doesn't provide a way to obtain an application name (for example,
// Firefox or Thunderbird) like IA2 does. Thus let's return an application
// name as accessible name that was used to get a branding name (for example,
// Minefield aka nightly Firefox or Daily aka nightly Thunderbird).
return GetAppName(aName);
GetAppName(aName);
return eNameOK;
}
NS_IMETHODIMP

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

@ -57,8 +57,7 @@ public:
virtual bool Init();
// nsAccessible
NS_IMETHOD GetName(nsAString &aName);
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual bool AppendChild(nsAccessible* aChild);
virtual bool RemoveChild(nsAccessible* aChild);

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

@ -682,20 +682,16 @@ const gchar *
getNameCB(AtkObject* aAtkObj)
{
nsAccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj);
if (!accWrap) {
if (!accWrap)
return nsnull;
}
/* nsIAccessible is responsible for the non-NULL name */
nsAutoString uniName;
nsresult rv = accWrap->GetName(uniName);
NS_ENSURE_SUCCESS(rv, nsnull);
accWrap->Name(uniName);
NS_ConvertUTF8toUTF16 objName(aAtkObj->name);
if (!uniName.Equals(objName)) {
atk_object_set_name(aAtkObj,
NS_ConvertUTF16toUTF8(uniName).get());
}
if (!uniName.Equals(objName))
atk_object_set_name(aAtkObj, NS_ConvertUTF16toUTF8(uniName).get());
return aAtkObj->name;
}
@ -1043,8 +1039,8 @@ nsAccessibleWrap::FirePlatformEvent(AccEvent* aEvent)
case nsIAccessibleEvent::EVENT_NAME_CHANGE:
{
nsString newName;
accessible->GetName(newName);
nsAutoString newName;
accessible->Name(newName);
NS_ConvertUTF16toUTF8 utf8Name(newName);
if (!atkObj->name || !utf8Name.Equals(atkObj->name))
atk_object_set_name(atkObj, utf8Name.get());

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

@ -211,7 +211,7 @@ private:
nsAutoString role; \
GetAccService()->GetStringRole(aAccessible->Role(), role); \
nsAutoString name; \
aAccessible->GetName(name); \
aAccessible->Name(name); \
printf(" role: %s, name: %s; ", NS_ConvertUTF16toUTF8(role).get(), \
NS_ConvertUTF16toUTF8(name).get()); \
A11YDEBUG_FOCUS_LOG_DOMNODE(aAccessible->GetNode()) \

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

@ -209,10 +209,9 @@ nsAccessible::nsAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
NS_ConvertUTF16toUTF8(content->NodeInfo()->QualifiedName()).get(),
(void *)content.get());
nsAutoString buf;
if (NS_SUCCEEDED(GetName(buf))) {
Name(buf);
printf(" Name:[%s]", NS_ConvertUTF16toUTF8(buf).get());
}
}
printf("\n");
}
#endif
@ -278,45 +277,52 @@ nsAccessible::GetName(nsAString& aName)
if (IsDefunct())
return NS_ERROR_FAILURE;
nsAutoString name;
Name(name);
aName.Assign(name);
return NS_OK;
}
ENameValueFlag
nsAccessible::Name(nsString& aName)
{
aName.Truncate();
GetARIAName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
nsCOMPtr<nsIXBLAccessible> xblAccessible(do_QueryInterface(mContent));
if (xblAccessible) {
xblAccessible->GetAccessibleName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
}
nsresult rv = GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
// In the end get the name from tooltip.
nsIAtom *tooltipAttr = nsnull;
if (mContent->IsHTML())
tooltipAttr = nsGkAtoms::title;
else if (mContent->IsXUL())
tooltipAttr = nsGkAtoms::tooltiptext;
else
return NS_OK;
// XXX: if CompressWhiteSpace worked on nsAString we could avoid a copy.
nsAutoString name;
if (mContent->GetAttr(kNameSpaceID_None, tooltipAttr, name)) {
name.CompressWhitespace();
aName = name;
return NS_OK_NAME_FROM_TOOLTIP;
if (mContent->IsHTML()) {
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, aName)) {
aName.CompressWhitespace();
return eNameFromTooltip;
}
} else if (mContent->IsXUL()) {
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext, aName)) {
aName.CompressWhitespace();
return eNameFromTooltip;
}
} else {
return eNameOK;
}
if (rv != NS_OK_EMPTY_NAME)
aName.SetIsVoid(true);
return NS_OK;
return eNameOK;
}
NS_IMETHODIMP
@ -364,7 +370,7 @@ nsAccessible::Description(nsString& aDescription)
nsGkAtoms::title;
if (mContent->GetAttr(kNameSpaceID_None, descAtom, aDescription)) {
nsAutoString name;
GetName(name);
Name(name);
if (name.IsEmpty() || aDescription == name)
// Don't use tooltip for a description if this object
// has no name or the tooltip is the same as the name

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

@ -65,9 +65,25 @@ class nsHTMLImageMapAccessible;
class nsHTMLLIAccessible;
struct nsRoleMapEntry;
class Relation;
namespace mozilla {
namespace a11y {
class TableAccessible;
/**
* Name type flags.
*/
enum ENameValueFlag {
/**
* Name either
* a) present (not empty): !name.IsEmpty()
* b) no name (was missed): name.IsVoid()
* c) was left empty by the author on demand: name.IsEmpty() && !name.IsVoid()
*/
eNameOK,
eNameFromTooltip // Tooltip was used as a name
};
}
}
class nsTextAccessible;
@ -140,6 +156,11 @@ public:
*/
virtual void Value(nsString& aValue);
/**
* Get the name of this accessible.
*/
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
/**
* Return DOM node associated with this accessible.
*/

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

@ -213,26 +213,26 @@ NS_IMPL_RELEASE_INHERITED(nsDocAccessible, nsHyperTextAccessible)
////////////////////////////////////////////////////////////////////////////////
// nsIAccessible
NS_IMETHODIMP
nsDocAccessible::GetName(nsAString& aName)
ENameValueFlag
nsDocAccessible::Name(nsString& aName)
{
nsresult rv = NS_OK;
aName.Truncate();
if (mParent) {
rv = mParent->GetName(aName); // Allow owning iframe to override the name
mParent->Name(aName); // Allow owning iframe to override the name
}
if (aName.IsEmpty()) {
// Allow name via aria-labelledby or title attribute
rv = nsAccessible::GetName(aName);
nsAccessible::Name(aName);
}
if (aName.IsEmpty()) {
rv = GetTitle(aName); // Try title element
GetTitle(aName); // Try title element
}
if (aName.IsEmpty()) { // Last resort: use URL
rv = GetURL(aName);
GetURL(aName);
}
return rv;
return eNameOK;
}
// nsAccessible public method

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

@ -92,7 +92,6 @@ public:
virtual ~nsDocAccessible();
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
NS_IMETHOD TakeFocus(void);
@ -111,6 +110,7 @@ public:
virtual nsIDocument* GetDocumentNode() const { return mDocument; }
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual void Description(nsString& aDescription);
virtual nsAccessible* FocusedChild();
virtual mozilla::a11y::role NativeRole();

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

@ -110,27 +110,22 @@ nsRootAccessible::~nsRootAccessible()
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessible
// nsAccessible
/* readonly attribute AString name; */
NS_IMETHODIMP
nsRootAccessible::GetName(nsAString& aName)
ENameValueFlag
nsRootAccessible::Name(nsString& aName)
{
aName.Truncate();
if (!mDocument) {
return NS_ERROR_FAILURE;
}
if (mRoleMapEntry) {
nsAccessible::GetName(aName);
if (!aName.IsEmpty()) {
return NS_OK;
}
nsAccessible::Name(aName);
if (!aName.IsEmpty())
return eNameOK;
}
nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(mDocument);
return document->GetTitle(aName);
document->GetTitle(aName);
return eNameOK;
}
role

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

@ -62,9 +62,6 @@ public:
nsIPresShell* aPresShell);
virtual ~nsRootAccessible();
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
@ -72,6 +69,7 @@ public:
virtual void Shutdown();
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual Relation RelationByType(PRUint32 aType);
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();

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

@ -48,6 +48,8 @@
#include "nsArrayUtils.h"
using namespace mozilla::a11y;
#define NS_OK_NO_NAME_CLAUSE_HANDLED \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 0x24)
@ -227,19 +229,16 @@ nsTextEquivUtils::AppendFromAccessible(nsAccessible *aAccessible,
return rv;
}
nsAutoString text;
nsresult rv = aAccessible->GetName(text);
NS_ENSURE_SUCCESS(rv, rv);
bool isEmptyTextEquiv = true;
// If the name is from tooltip then append it to result string in the end
// (see h. step of name computation guide).
if (rv != NS_OK_NAME_FROM_TOOLTIP)
nsAutoString text;
if (aAccessible->Name(text) != eNameFromTooltip)
isEmptyTextEquiv = !AppendString(aString, text);
// Implementation of f. step.
rv = AppendFromValue(aAccessible, aString);
nsresult rv = AppendFromValue(aAccessible, aString);
NS_ENSURE_SUCCESS(rv, rv);
if (rv != NS_OK_NO_NAME_CLAUSE_HANDLED)

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

@ -96,8 +96,8 @@ ApplicationAccessible::GetPreviousSibling(nsIAccessible** aPreviousSibling)
return NS_OK;
}
NS_IMETHODIMP
ApplicationAccessible::GetName(nsAString& aName)
ENameValueFlag
ApplicationAccessible::Name(nsString& aName)
{
aName.Truncate();
@ -105,12 +105,14 @@ ApplicationAccessible::GetName(nsAString& aName)
mozilla::services::GetStringBundleService();
NS_ASSERTION(bundleService, "String bundle service must be present!");
NS_ENSURE_STATE(bundleService);
if (!bundleService)
return eNameOK;
nsCOMPtr<nsIStringBundle> bundle;
nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties",
getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return eNameOK;
nsXPIDLString appName;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
@ -121,7 +123,7 @@ ApplicationAccessible::GetName(nsAString& aName)
}
aName.Assign(appName);
return NS_OK;
return eNameOK;
}
void

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

@ -79,7 +79,6 @@ public:
NS_IMETHOD GetParent(nsIAccessible **aParent);
NS_IMETHOD GetNextSibling(nsIAccessible **aNextSibling);
NS_IMETHOD GetPreviousSibling(nsIAccessible **aPreviousSibling);
NS_IMETHOD GetName(nsAString &aName);
NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
NS_IMETHOD GroupPosition(PRInt32 *aGroupLevel, PRInt32 *aSimilarItemsInGroup,
PRInt32 *aPositionInGroup);
@ -101,6 +100,7 @@ public:
virtual bool IsPrimaryForNode() const;
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual void ApplyARIAState(PRUint64* aState);
virtual void Description(nsString& aDescription);
virtual void Value(nsString& aValue);

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

@ -594,7 +594,7 @@ nsHTMLComboboxAccessible::Value(nsString& aValue)
// Use accessible name of selected option.
nsAccessible* option = SelectedOption();
if (option)
option->GetName(aValue);
option->Name(aValue);
}
PRUint8

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

@ -68,12 +68,12 @@ nsHTMLTextAccessible::
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTextAccessible, nsTextAccessible)
NS_IMETHODIMP
nsHTMLTextAccessible::GetName(nsAString& aName)
ENameValueFlag
nsHTMLTextAccessible::Name(nsString& aName)
{
// Text node, ARIA can't be used.
aName = mText;
return NS_OK;
return eNameOK;
}
role
@ -348,14 +348,11 @@ nsHTMLListBulletAccessible::IsPrimaryForNode() const
////////////////////////////////////////////////////////////////////////////////
// nsHTMLListBulletAccessible: nsAccessible
NS_IMETHODIMP
nsHTMLListBulletAccessible::GetName(nsAString &aName)
ENameValueFlag
nsHTMLListBulletAccessible::Name(nsString &aName)
{
aName.Truncate();
if (IsDefunct())
return NS_ERROR_FAILURE;
// Native anonymous content, ARIA can't be used. Get list bullet text.
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
NS_ASSERTION(blockFrame, "No frame for list item!");
@ -366,7 +363,7 @@ nsHTMLListBulletAccessible::GetName(nsAString &aName)
aName.Append(' ');
}
return NS_OK;
return eNameOK;
}
role

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

@ -55,10 +55,8 @@ public:
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();
@ -129,13 +127,11 @@ class nsHTMLListBulletAccessible : public nsLeafAccessible
public:
nsHTMLListBulletAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
// nsAccessNode
virtual bool IsPrimaryForNode() const;
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,

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

@ -514,7 +514,7 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString title;
mGeckoAccessible->GetName (title);
mGeckoAccessible->Name(title);
return title.IsEmpty() ? nil : [NSString stringWithCharacters:title.BeginReading() length:title.Length()];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;

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

@ -285,9 +285,7 @@ __try {
return CO_E_OBJNOTCONNECTED;
nsAutoString name;
nsresult rv = xpAccessible->GetName(name);
if (NS_FAILED(rv))
return GetHRESULT(rv);
xpAccessible->Name(name);
// The name was not provided, e.g. no alt attribute for an image. A screen
// reader may choose to invent its own accessible name, e.g. from an image src

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

@ -38,6 +38,8 @@
#include "nsXULMenuAccessibleWrap.h"
#include "nsINameSpaceManager.h"
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// nsXULMenuAccessibleWrap
////////////////////////////////////////////////////////////////////////////////
@ -48,21 +50,19 @@ nsXULMenuitemAccessibleWrap::
{
}
NS_IMETHODIMP
nsXULMenuitemAccessibleWrap::GetName(nsAString& aName)
ENameValueFlag
nsXULMenuitemAccessibleWrap::Name(nsString& aName)
{
// XXX This should be done in get_accName() so that nsIAccessible::GetName()]
// provides the same results on all platforms
nsresult rv = nsXULMenuitemAccessible::GetName(aName);
if (NS_FAILED(rv)) {
return rv;
}
nsXULMenuitemAccessible::Name(aName);
if (aName.IsEmpty())
return eNameOK;
nsAutoString accel;
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accel);
if (!accel.IsEmpty()) {
if (!accel.IsEmpty())
aName += NS_LITERAL_STRING("\t") + accel;
}
return NS_OK;
return eNameOK;
}

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

@ -47,7 +47,7 @@ public:
virtual ~nsXULMenuitemAccessibleWrap() {}
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
};
#endif

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

@ -66,13 +66,13 @@ nsXULAlertAccessible::NativeState()
return nsAccessible::NativeState() | states::ALERT;
}
NS_IMETHODIMP
nsXULAlertAccessible::GetName(nsAString& aName)
ENameValueFlag
nsXULAlertAccessible::Name(nsString& aName)
{
// Screen readers need to read contents of alert, not the accessible name.
// If we have both some screen readers will read the alert twice.
aName.Truncate();
return NS_OK;
return eNameOK;
}
////////////////////////////////////////////////////////////////////////////////

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

@ -51,10 +51,8 @@ public:
NS_DECL_ISUPPORTS_INHERITED
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();

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

@ -1176,16 +1176,13 @@ NS_IMPL_RELEASE_INHERITED(nsXULTreeItemAccessible, nsXULTreeItemAccessibleBase)
////////////////////////////////////////////////////////////////////////////////
// nsXULTreeItemAccessible: nsIAccessible implementation
NS_IMETHODIMP
nsXULTreeItemAccessible::GetName(nsAString& aName)
ENameValueFlag
nsXULTreeItemAccessible::Name(nsString& aName)
{
aName.Truncate();
if (IsDefunct())
return NS_ERROR_FAILURE;
GetCellName(mColumn, aName);
return NS_OK;
return eNameOK;
}
////////////////////////////////////////////////////////////////////////////////
@ -1197,7 +1194,7 @@ nsXULTreeItemAccessible::Init()
if (!nsXULTreeItemAccessibleBase::Init())
return false;
GetName(mCachedName);
Name(mCachedName);
return true;
}
@ -1235,7 +1232,7 @@ nsXULTreeItemAccessible::RowInvalidated(PRInt32 aStartColIdx,
PRInt32 aEndColIdx)
{
nsAutoString name;
GetName(name);
Name(name);
if (name != mCachedName) {
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE, this);

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

@ -267,13 +267,12 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULTreeItemAccessible,
nsXULTreeItemAccessibleBase)
NS_IMETHOD GetName(nsAString& aName);
// nsAccessNode
virtual bool Init();
virtual void Shutdown();
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual mozilla::a11y::role NativeRole();
// nsXULTreeItemAccessibleBase

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

@ -657,14 +657,11 @@ nsXULTreeGridRowAccessible::NativeRole()
return roles::ROW;
}
NS_IMETHODIMP
nsXULTreeGridRowAccessible::GetName(nsAString& aName)
ENameValueFlag
nsXULTreeGridRowAccessible::Name(nsString& aName)
{
aName.Truncate();
if (IsDefunct())
return NS_ERROR_FAILURE;
// XXX: the row name sholdn't be a concatenation of cell names (bug 664384).
nsCOMPtr<nsITreeColumn> column = nsCoreUtils::GetFirstSensibleColumn(mTree);
while (column) {
@ -678,7 +675,7 @@ nsXULTreeGridRowAccessible::GetName(nsAString& aName)
column = nsCoreUtils::GetNextSensibleColumn(column);
}
return NS_OK;
return eNameOK;
}
nsAccessible*
@ -844,13 +841,13 @@ nsXULTreeGridCellAccessible::FocusedChild()
return nsnull;
}
NS_IMETHODIMP
nsXULTreeGridCellAccessible::GetName(nsAString& aName)
ENameValueFlag
nsXULTreeGridCellAccessible::Name(nsString& aName)
{
aName.Truncate();
if (IsDefunct() || !mTreeView)
return NS_ERROR_FAILURE;
if (!mTreeView)
return eNameOK;
mTreeView->GetCellText(mRow, mColumn, aName);
@ -862,7 +859,7 @@ nsXULTreeGridCellAccessible::GetName(nsAString& aName)
if (aName.IsEmpty())
mTreeView->GetCellValue(mRow, mColumn, aName);
return NS_OK;
return eNameOK;
}
NS_IMETHODIMP

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

@ -103,7 +103,7 @@ public:
// nsAccessible
virtual mozilla::a11y::role NativeRole();
NS_IMETHOD GetName(nsAString& aName);
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual nsAccessible* ChildAtPoint(PRInt32 aX, PRInt32 aY,
EWhichChildAtPoint aWhichChild);
@ -155,7 +155,6 @@ public:
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
NS_IMETHOD GetBounds(PRInt32 *aX, PRInt32 *aY,
PRInt32 *aWidth, PRInt32 *aHeight);
@ -170,6 +169,7 @@ public:
virtual bool IsPrimaryForNode() const;
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual nsAccessible* FocusedChild();
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
virtual PRInt32 IndexInParent() const;