bug 652378 - dexpcom nsAccessible::GetDescription() r=surkov

From 474b06dc24586199d7abf30235b8202b595e9edd Mon Sep 17 00:00:00 2001
---
 accessible/src/atk/nsAccessibleWrap.cpp            |   10 +--
 accessible/src/base/nsAccessible.cpp               |   62 +++++++++++---------
 accessible/src/base/nsAccessible.h                 |    5 ++
 accessible/src/base/nsApplicationAccessible.cpp    |    5 +-
 accessible/src/base/nsApplicationAccessible.h      |    2 +-
 accessible/src/base/nsDocAccessible.cpp            |   15 ++---
 accessible/src/base/nsDocAccessible.h              |    2 +-
 accessible/src/html/nsHTMLImageMapAccessible.cpp   |    6 +-
 accessible/src/html/nsHTMLImageMapAccessible.h     |    2 +-
 accessible/src/html/nsHTMLSelectAccessible.cpp     |   13 ++--
 accessible/src/html/nsHTMLSelectAccessible.h       |    2 +-
 accessible/src/html/nsHTMLTableAccessible.cpp      |   19 +++----
 accessible/src/html/nsHTMLTableAccessible.h        |    2 +-
 accessible/src/mac/mozAccessible.mm                |    5 +-
 accessible/src/msaa/nsAccessibleWrap.cpp           |    4 +-
 accessible/src/xforms/nsXFormsAccessible.cpp       |   18 ++----
 accessible/src/xforms/nsXFormsAccessible.h         |    5 +-
 .../src/xforms/nsXFormsFormControlsAccessible.cpp  |   11 +--
 .../src/xforms/nsXFormsFormControlsAccessible.h    |    4 +-
 .../src/xforms/nsXFormsWidgetsAccessible.cpp       |    5 +-
 accessible/src/xforms/nsXFormsWidgetsAccessible.h  |    2 +-
 accessible/src/xul/nsXULComboboxAccessible.cpp     |   21 ++-----
 accessible/src/xul/nsXULComboboxAccessible.h       |    2 +-
 accessible/src/xul/nsXULListboxAccessible.h        |    2 +-
 accessible/src/xul/nsXULMenuAccessible.cpp         |    9 +--
 accessible/src/xul/nsXULMenuAccessible.h           |    2 +-
 26 files changed, 106 insertions(+), 129 deletions(-)
This commit is contained in:
Trevor Saunders 2011-04-23 09:14:05 -04:00
parent 01393bfa6e
commit 8fa9ad97db
27 changed files with 114 additions and 128 deletions

View File

@ -718,20 +718,18 @@ const gchar *
getDescriptionCB(AtkObject *aAtkObj)
{
nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
if (!accWrap) {
if (!accWrap || accWrap->IsDefunct())
return nsnull;
}
/* nsIAccessible is responsible for the non-NULL description */
nsAutoString uniDesc;
nsresult rv = accWrap->GetDescription(uniDesc);
NS_ENSURE_SUCCESS(rv, nsnull);
accWrap->Description(uniDesc);
NS_ConvertUTF8toUTF16 objDesc(aAtkObj->description);
if (!uniDesc.Equals(objDesc)) {
if (!uniDesc.Equals(objDesc))
atk_object_set_description(aAtkObj,
NS_ConvertUTF16toUTF8(uniDesc).get());
}
return aAtkObj->description;
}

View File

@ -272,54 +272,60 @@ nsAccessible::GetName(nsAString& aName)
return NS_OK;
}
NS_IMETHODIMP nsAccessible::GetDescription(nsAString& aDescription)
NS_IMETHODIMP
nsAccessible::GetDescription(nsAString& aDescription)
{
if (IsDefunct())
return NS_ERROR_FAILURE;
nsAutoString desc;
Description(desc);
aDescription.Assign(desc);
return NS_OK;
}
void
nsAccessible::Description(nsString& aDescription)
{
// There are 4 conditions that make an accessible have no accDescription:
// 1. it's a text node; or
// 2. It has no DHTML describedby property
// 3. it doesn't have an accName; or
// 4. its title attribute already equals to its accName nsAutoString name;
if (!mContent->IsNodeOfType(nsINode::eTEXT)) {
nsAutoString description;
nsresult rv = nsTextEquivUtils::
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
description);
NS_ENSURE_SUCCESS(rv, rv);
if (mContent->IsNodeOfType(nsINode::eTEXT))
return;
if (description.IsEmpty()) {
PRBool isXUL = mContent->IsXUL();
if (isXUL) {
// Try XUL <description control="[id]">description text</description>
XULDescriptionIterator iter(GetDocAccessible(), mContent);
nsAccessible* descr = nsnull;
while ((descr = iter.Next())) {
nsTextEquivUtils::
AppendTextEquivFromContent(this, descr->GetContent(), &description);
}
nsTextEquivUtils::
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
aDescription);
if (aDescription.IsEmpty()) {
PRBool isXUL = mContent->IsXUL();
if (isXUL) {
// Try XUL <description control="[id]">description text</description>
XULDescriptionIterator iter(GetDocAccessible(), mContent);
nsAccessible* descr = nsnull;
while ((descr = iter.Next()))
nsTextEquivUtils::AppendTextEquivFromContent(this, descr->GetContent(),
&aDescription);
}
if (description.IsEmpty()) {
if (aDescription.IsEmpty()) {
nsIAtom *descAtom = isXUL ? nsAccessibilityAtoms::tooltiptext :
nsAccessibilityAtoms::title;
if (mContent->GetAttr(kNameSpaceID_None, descAtom, description)) {
if (mContent->GetAttr(kNameSpaceID_None, descAtom, aDescription)) {
nsAutoString name;
GetName(name);
if (name.IsEmpty() || description == 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
description.Truncate();
}
aDescription.Truncate();
}
}
}
description.CompressWhitespace();
aDescription = description;
}
return NS_OK;
aDescription.CompressWhitespace();
}
// mask values for ui.key.chromeAccess and ui.key.contentAccess

View File

@ -119,6 +119,11 @@ public:
//////////////////////////////////////////////////////////////////////////////
// Public methods
/**
* get the description of this accessible
*/
virtual void Description(nsString& aDescription);
/**
* Returns the accessible name specified by ARIA.
*/

View File

@ -127,11 +127,10 @@ nsApplicationAccessible::GetValue(nsAString &aValue)
return NS_OK;
}
NS_IMETHODIMP
nsApplicationAccessible::GetDescription(nsAString &aDescription)
void
nsApplicationAccessible::Description(nsString &aDescription)
{
aDescription.Truncate();
return NS_OK;
}
NS_IMETHODIMP

View File

@ -92,7 +92,6 @@ public:
NS_IMETHOD GetPreviousSibling(nsIAccessible **aPreviousSibling);
NS_IMETHOD GetName(nsAString &aName);
NS_IMETHOD GetValue(nsAString &aValue);
NS_IMETHOD GetDescription(nsAString &aDescription);
NS_IMETHOD GetKeyboardShortcut(nsAString &aKeyboardShortcut);
NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
NS_IMETHOD GroupPosition(PRInt32 *aGroupLevel, PRInt32 *aSimilarItemsInGroup,
@ -123,6 +122,7 @@ public:
// nsAccessible
virtual void ApplyARIAState(PRUint64* aState);
virtual void Description(nsString& aDescription);
virtual PRUint32 NativeRole();
virtual PRUint64 State();
virtual PRUint64 NativeState();

View File

@ -273,21 +273,16 @@ nsDocAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
}
}
NS_IMETHODIMP
nsDocAccessible::GetDescription(nsAString& aDescription)
void
nsDocAccessible::Description(nsString& aDescription)
{
if (mParent)
mParent->GetDescription(aDescription);
mParent->Description(aDescription);
if (aDescription.IsEmpty()) {
nsAutoString description;
if (aDescription.IsEmpty())
nsTextEquivUtils::
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
description);
aDescription = description;
}
return NS_OK;
aDescription);
}
// nsAccessible public method

View File

@ -93,7 +93,6 @@ public:
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
NS_IMETHOD GetFocusedChild(nsIAccessible **aFocusedChild);
NS_IMETHOD TakeFocus(void);
@ -114,6 +113,7 @@ public:
virtual nsIDocument* GetDocumentNode() const { return mDocument; }
// nsAccessible
virtual void Description(nsString& aDescription);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();
virtual void ApplyARIAState(PRUint64* aState);

View File

@ -168,8 +168,8 @@ nsHTMLAreaAccessible::GetNameInternal(nsAString & aName)
return NS_OK;
}
NS_IMETHODIMP
nsHTMLAreaAccessible::GetDescription(nsAString& aDescription)
void
nsHTMLAreaAccessible::Description(nsString& aDescription)
{
aDescription.Truncate();
@ -177,8 +177,6 @@ nsHTMLAreaAccessible::GetDescription(nsAString& aDescription)
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mContent));
if (area)
area->GetShape(aDescription);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -87,11 +87,11 @@ public:
nsHTMLAreaAccessible(nsIContent *aContent, nsIWeakReference *aShell);
// nsIAccessible
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
// nsAccessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual PRUint64 NativeState();
virtual nsAccessible* GetChildAtPoint(PRInt32 aX, PRInt32 aY,

View File

@ -727,18 +727,19 @@ nsHTMLComboboxAccessible::NativeState()
return state;
}
NS_IMETHODIMP nsHTMLComboboxAccessible::GetDescription(nsAString& aDescription)
void
nsHTMLComboboxAccessible::Description(nsString& aDescription)
{
aDescription.Truncate();
// First check to see if combo box itself has a description, perhaps through
// tooltip (title attribute) or via aria-describedby
nsAccessible::GetDescription(aDescription);
if (!aDescription.IsEmpty()) {
return NS_OK;
}
nsAccessible::Description(aDescription);
if (!aDescription.IsEmpty())
return;
// Use description of currently focused option
nsAccessible *option = GetFocusedOptionAccessible();
return option ? option->GetDescription(aDescription) : NS_OK;
if (option)
option->Description(aDescription);
}
nsAccessible *

View File

@ -184,7 +184,6 @@ public:
// nsIAccessible
NS_IMETHOD GetValue(nsAString& _retval);
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD DoAction(PRUint8 index);
NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
@ -193,6 +192,7 @@ public:
virtual void Shutdown();
// nsAccessible
virtual void Description(nsString& aDescription);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();
virtual void InvalidateChildren();

View File

@ -1260,14 +1260,14 @@ nsHTMLTableAccessible::GetCellAt(PRInt32 aRowIndex,
return rv;
}
NS_IMETHODIMP nsHTMLTableAccessible::GetDescription(nsAString& aDescription)
void
nsHTMLTableAccessible::Description(nsString& aDescription)
{
// Helpful for debugging layout vs. data tables
aDescription.Truncate();
nsAccessible::GetDescription(aDescription);
if (!aDescription.IsEmpty()) {
return NS_OK;
}
nsAccessible::Description(aDescription);
if (!aDescription.IsEmpty())
return;
nsCOMPtr<nsIAccessible> captionAccessible;
GetCaption(getter_AddRefs(captionAccessible));
@ -1276,10 +1276,9 @@ NS_IMETHODIMP nsHTMLTableAccessible::GetDescription(nsAString& aDescription)
nsCOMPtr<nsIDOMNode> captionNode;
captionAccessNode->GetDOMNode(getter_AddRefs(captionNode));
nsCOMPtr<nsIContent> captionContent = do_QueryInterface(captionNode);
if (captionContent) {
nsTextEquivUtils::
AppendTextEquivFromContent(this, captionContent, &aDescription);
}
if (captionContent)
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
&aDescription);
}
#ifdef SHOW_LAYOUT_HEURISTIC
if (aDescription.IsEmpty()) {
@ -1291,8 +1290,6 @@ NS_IMETHODIMP nsHTMLTableAccessible::GetDescription(nsAString& aDescription)
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
#endif
#endif
return NS_OK;
}
PRBool

View File

@ -131,11 +131,11 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_TABLEACCESSIBLE_IMPL_CID)
// nsIAccessible
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD GetRelationByType(PRUint32 aRelationType,
nsIAccessibleRelation **aRelation);
// nsAccessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();

View File

@ -518,8 +518,11 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mGeckoAccessible->IsDefunct())
return nil;
nsAutoString desc;
mGeckoAccessible->GetDescription (desc);
mGeckoAccessible->Description(desc);
return desc.IsEmpty() ? nil : [NSString stringWithCharacters:desc.BeginReading() length:desc.Length()];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;

View File

@ -333,11 +333,11 @@ __try {
*pszDescription = NULL;
nsAccessible *xpAccessible = GetXPAccessibleFor(varChild);
if (!xpAccessible)
if (!xpAccessible || xpAccessible->IsDefunct())
return E_FAIL;
nsAutoString description;
xpAccessible->GetDescription(description);
xpAccessible->Description(description);
*pszDescription = ::SysAllocStringLen(description.get(),
description.Length());

View File

@ -197,21 +197,15 @@ nsXFormsAccessible::GetNameInternal(nsAString& aName)
return GetBoundChildElementValue(NS_LITERAL_STRING("label"), aName);
}
NS_IMETHODIMP
nsXFormsAccessible::GetDescription(nsAString& aDescription)
void
nsXFormsAccessible::Description(nsString& aDescription)
{
nsAutoString description;
nsresult rv = nsTextEquivUtils::
nsTextEquivUtils::
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
description);
aDescription);
if (NS_SUCCEEDED(rv) && !description.IsEmpty()) {
aDescription = description;
return NS_OK;
}
// search the xforms:hint element
return GetBoundChildElementValue(NS_LITERAL_STRING("hint"), aDescription);
if (aDescription.IsEmpty())
GetBoundChildElementValue(NS_LITERAL_STRING("hint"), aDescription);
}
PRBool

View File

@ -77,10 +77,9 @@ public:
// Returns value of instance node that xforms element is bound to.
NS_IMETHOD GetValue(nsAString& aValue);
// Returns value of child xforms 'hint' element.
NS_IMETHOD GetDescription(nsAString& aDescription);
// nsAccessible
// Returns value of child xforms 'hint' element.
virtual void Description(nsString& aDescription);
// Returns value of child xforms 'label' element.
virtual nsresult GetNameInternal(nsAString& aName);

View File

@ -64,15 +64,12 @@ nsXFormsLabelAccessible::GetNameInternal(nsAString& aName)
return NS_OK;
}
NS_IMETHODIMP
nsXFormsLabelAccessible::GetDescription(nsAString& aDescription)
void
nsXFormsLabelAccessible::Description(nsString& aDescription)
{
nsAutoString description;
nsresult rv = nsTextEquivUtils::
nsTextEquivUtils::
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
description);
aDescription = description;
return rv;
aDescription);
}

View File

@ -50,10 +50,8 @@ class nsXFormsLabelAccessible : public nsXFormsAccessible
public:
nsXFormsLabelAccessible(nsIContent *aContent, nsIWeakReference *aShell);
// nsIAccessible
NS_IMETHOD GetDescription(nsAString& aDescription);
// nsAccessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual PRUint32 NativeRole();
};

View File

@ -177,11 +177,10 @@ nsXFormsComboboxPopupWidgetAccessible::GetNameInternal(nsAString& aName)
return NS_OK;
}
NS_IMETHODIMP
nsXFormsComboboxPopupWidgetAccessible::GetDescription(nsAString& aDescription)
void
nsXFormsComboboxPopupWidgetAccessible::Description(nsString& aDescription)
{
aDescription.Truncate();
return NS_OK;
}
void

View File

@ -91,9 +91,9 @@ public:
// nsIAccessible
NS_IMETHOD GetValue(nsAString& aValue);
NS_IMETHOD GetDescription(nsAString& aDescription);
// nsAccessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();

View File

@ -112,32 +112,25 @@ nsXULComboboxAccessible::GetValue(nsAString& aValue)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULComboboxAccessible::GetDescription(nsAString& aDescription)
void
nsXULComboboxAccessible::Description(nsString& aDescription)
{
aDescription.Truncate();
if (IsDefunct())
return NS_ERROR_FAILURE;
// Use description of currently focused option
nsCOMPtr<nsIDOMXULMenuListElement> menuListElm(do_QueryInterface(mContent));
if (!menuListElm)
return NS_ERROR_FAILURE;
return;
nsCOMPtr<nsIDOMXULSelectControlItemElement> focusedOptionItem;
menuListElm->GetSelectedItem(getter_AddRefs(focusedOptionItem));
nsCOMPtr<nsIContent> focusedOptionContent =
do_QueryInterface(focusedOptionItem);
if (focusedOptionContent) {
nsAccessible *focusedOption =
GetAccService()->GetAccessibleInWeakShell(focusedOptionContent, mWeakShell);
NS_ENSURE_TRUE(focusedOption, NS_ERROR_FAILURE);
return focusedOption->GetDescription(aDescription);
nsAccessible* focusedOptionAcc = GetAccService()->
GetAccessibleInWeakShell(focusedOptionContent, mWeakShell);
if (focusedOptionAcc)
focusedOptionAcc->Description(aDescription);
}
return NS_OK;
}
PRBool

View File

@ -55,12 +55,12 @@ public:
// nsIAccessible
NS_IMETHOD GetValue(nsAString& aValue);
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD DoAction(PRUint8 aIndex);
NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
// nsAccessible
virtual void Description(nsString& aDescription);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();
virtual PRBool GetAllowsAnonChildAccessibles();

View File

@ -861,6 +861,15 @@ nsXULListitemAccessible::GetListAccessible()
return GetAccService()->GetAccessibleInWeakShell(listContent, mWeakShell);
}
////////////////////////////////////////////////////////////////////////////////
// nsXULListitemAccessible nsAccessible
void
nsXULListitemAccessible::Description(nsString& aDesc)
{
nsAccessibleWrap::Description(aDesc);
}
////////////////////////////////////////////////////////////////////////////////
// nsXULListitemAccessible. nsIAccessible

View File

@ -123,9 +123,9 @@ public:
// nsIAccessible
NS_IMETHOD GetActionName(PRUint8 index, nsAString& aName);
// Don't use XUL menuitems's description attribute
NS_IMETHOD GetDescription(nsAString& aDesc) { return nsAccessibleWrap::GetDescription(aDesc); }
// nsAccessible
virtual void Description(nsString& aDesc);
virtual nsresult GetNameInternal(nsAString& aName);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();

View File

@ -378,16 +378,11 @@ nsXULMenuitemAccessible::GetNameInternal(nsAString& aName)
return NS_OK;
}
NS_IMETHODIMP
nsXULMenuitemAccessible::GetDescription(nsAString& aDescription)
void
nsXULMenuitemAccessible::Description(nsString& aDescription)
{
if (IsDefunct())
return NS_ERROR_FAILURE;
mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::description,
aDescription);
return NS_OK;
}
//return menu accesskey: N or Alt+F

View File

@ -82,7 +82,6 @@ public:
nsXULMenuitemAccessible(nsIContent *aContent, nsIWeakReference *aShell);
// nsIAccessible
NS_IMETHOD GetDescription(nsAString& aDescription);
NS_IMETHOD GetKeyboardShortcut(nsAString& _retval);
NS_IMETHOD GetDefaultKeyBinding(nsAString& aKeyBinding);
NS_IMETHOD DoAction(PRUint8 index);
@ -90,6 +89,7 @@ public:
NS_IMETHOD GetNumActions(PRUint8 *_retval);
// nsAccessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual PRUint32 NativeRole();
virtual PRUint64 NativeState();