From cd94beaab78d2f6fd1b0b3b8c0d7d68647ac8eec Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Fri, 10 Oct 2008 20:26:55 +0800 Subject: [PATCH] Bug 453591 - reorganize nsAccessible::GetName to handle ARIA for non XUL/HTML elements, r=marcoz, aaronlev --- accessible/src/base/nsAccessible.cpp | 132 ++++++++++-------- accessible/src/base/nsAccessible.h | 32 +++++ accessible/src/base/nsDocAccessible.cpp | 6 +- accessible/src/html/nsHTMLAreaAccessible.cpp | 19 +-- accessible/src/html/nsHTMLAreaAccessible.h | 4 +- .../src/html/nsHTMLFormControlAccessible.cpp | 52 +++---- .../src/html/nsHTMLFormControlAccessible.h | 23 ++- accessible/src/html/nsHTMLImageAccessible.cpp | 17 ++- accessible/src/html/nsHTMLImageAccessible.h | 2 +- accessible/src/html/nsHTMLLinkAccessible.cpp | 9 +- accessible/src/html/nsHTMLLinkAccessible.h | 4 +- .../src/html/nsHTMLSelectAccessible.cpp | 51 +++---- accessible/src/html/nsHTMLSelectAccessible.h | 20 ++- accessible/src/html/nsHTMLTableAccessible.cpp | 6 +- accessible/src/html/nsHTMLTableAccessible.h | 12 +- accessible/src/html/nsHTMLTextAccessible.cpp | 11 +- accessible/src/html/nsHTMLTextAccessible.h | 30 +++- .../src/msaa/nsXULMenuAccessibleWrap.cpp | 3 +- accessible/src/msaa/nsXULMenuAccessibleWrap.h | 2 + .../src/msaa/nsXULTreeAccessibleWrap.cpp | 3 +- accessible/src/xforms/nsXFormsAccessible.cpp | 23 +-- accessible/src/xforms/nsXFormsAccessible.h | 6 +- .../xforms/nsXFormsFormControlsAccessible.cpp | 9 +- .../xforms/nsXFormsFormControlsAccessible.h | 5 +- .../src/xforms/nsXFormsWidgetsAccessible.cpp | 7 +- .../src/xforms/nsXFormsWidgetsAccessible.h | 5 +- .../src/xul/nsXULColorPickerAccessible.cpp | 6 +- .../src/xul/nsXULColorPickerAccessible.h | 6 +- .../src/xul/nsXULFormControlAccessible.cpp | 6 +- .../src/xul/nsXULFormControlAccessible.h | 6 +- accessible/src/xul/nsXULMenuAccessible.cpp | 34 ++--- accessible/src/xul/nsXULMenuAccessible.h | 33 ++++- accessible/src/xul/nsXULSelectAccessible.cpp | 15 +- accessible/src/xul/nsXULSelectAccessible.h | 9 +- accessible/src/xul/nsXULTabAccessible.cpp | 8 +- accessible/src/xul/nsXULTabAccessible.h | 6 +- accessible/src/xul/nsXULTextAccessible.cpp | 29 ++-- accessible/src/xul/nsXULTextAccessible.h | 16 ++- accessible/src/xul/nsXULTreeAccessible.cpp | 1 + accessible/src/xul/nsXULTreeAccessible.h | 2 +- .../tests/mochitest/nsIAccessible_name.js | 6 +- 41 files changed, 379 insertions(+), 297 deletions(-) diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index ddb6e5176484..314c4224da84 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -220,6 +220,12 @@ nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsAccessible))) { + *aInstancePtr = static_cast(this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) { nsCOMPtr content(do_QueryInterface(mDOMNode)); if (!content) { @@ -301,26 +307,19 @@ NS_IMETHODIMP nsAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry) return NS_OK; } -NS_IMETHODIMP nsAccessible::GetName(nsAString& aName) +NS_IMETHODIMP +nsAccessible::GetName(nsAString& aName) { aName.Truncate(); - nsCOMPtr content(do_QueryInterface(mDOMNode)); - if (!content) { - return NS_ERROR_FAILURE; // Node shut down - } - PRBool canAggregateName = mRoleMapEntry && - mRoleMapEntry->nameRule == eNameOkFromChildren; + if (IsDefunct()) + return NS_ERROR_FAILURE; - if (content->IsNodeOfType(nsINode::eHTML)) { - return GetHTMLName(aName, canAggregateName); - } + GetARIAName(aName); + if (!aName.IsEmpty()) + return NS_OK; - if (content->IsNodeOfType(nsINode::eXUL)) { - return GetXULName(aName, canAggregateName); - } - - return NS_OK; + return GetNameInternal(aName); } NS_IMETHODIMP nsAccessible::GetDescription(nsAString& aDescription) @@ -1816,15 +1815,13 @@ nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aNa return NS_OK; nsAutoString ids; - if (!content->GetAttr(kNameSpaceID_None, aIDProperty, ids)) { - return NS_ERROR_FAILURE; - } + if (!content->GetAttr(kNameSpaceID_None, aIDProperty, ids)) + return NS_OK; + ids.CompressWhitespace(PR_TRUE, PR_TRUE); nsCOMPtr domDoc = do_QueryInterface(content->GetOwnerDoc()); NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE); - - nsresult rv = NS_ERROR_FAILURE; // Support idlist as in aria-labelledby="id1 id2 id3" while (!ids.IsEmpty()) { @@ -1849,13 +1846,13 @@ nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aNa return NS_OK; } // We have a label content - rv = AppendFlatStringFromSubtree(content, &aName); + nsresult rv = AppendFlatStringFromSubtree(content, &aName); if (NS_SUCCEEDED(rv)) { aName.CompressWhitespace(); } } - return rv; + return NS_OK; } /** @@ -1865,27 +1862,13 @@ nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aNa */ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtree) { - nsCOMPtr content(do_QueryInterface(mDOMNode)); - if (!content) { - return NS_ERROR_FAILURE; // Node shut down - } - - // Check for aria-label property - nsAutoString label; - if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) { - aLabel = label; + nsCOMPtr content = GetRoleContent(mDOMNode); + if (!content) return NS_OK; - } - - // Check for aria-labelledby relationship property - nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label); - if (NS_SUCCEEDED(rv)) { - aLabel = label; - return rv; - } nsIContent *labelContent = GetHTMLLabelContent(content); if (labelContent) { + nsAutoString label; AppendFlatStringFromSubtree(labelContent, &label); label.CompressWhitespace(); if (!label.IsEmpty()) { @@ -1924,24 +1907,10 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre */ nsresult nsAccessible::GetXULName(nsAString& aLabel, PRBool aCanAggregateSubtree) { - nsCOMPtr content(do_QueryInterface(mDOMNode)); - NS_ASSERTION(content, "No nsIContent for DOM node"); - - // First check for label override via aria-label property - nsAutoString label; - if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) { - aLabel = label; - return NS_OK; - } - - // Second check for label override via aria-labelledby relationship - nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label); - if (NS_SUCCEEDED(rv)) { - aLabel = label; - return rv; - } - // CASE #1 (via label attribute) -- great majority of the cases + nsresult rv = NS_OK; + + nsAutoString label; nsCOMPtr labeledEl(do_QueryInterface(mDOMNode)); if (labeledEl) { rv = labeledEl->GetLabel(label); @@ -1965,6 +1934,10 @@ nsresult nsAccessible::GetXULName(nsAString& aLabel, PRBool aCanAggregateSubtree } // CASES #2 and #3 ------ label as a child or + nsCOMPtr content = GetRoleContent(mDOMNode); + if (!content) + return NS_OK; + if (NS_FAILED(rv) || label.IsEmpty()) { label.Truncate(); nsIContent *labelContent = @@ -3580,6 +3553,53 @@ nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLe return NS_OK; } +//////////////////////////////////////////////////////////////////////////////// +// nsAccessible public methods + +nsresult +nsAccessible::GetARIAName(nsAString& aName) +{ + nsCOMPtr content = GetRoleContent(mDOMNode); + if (!content) + return NS_OK; + + // First check for label override via aria-label property + nsAutoString label; + if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) { + aName = label; + return NS_OK; + } + + // Second check for label override via aria-labelledby relationship + nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label); + if (NS_SUCCEEDED(rv)) + aName = label; + + return rv; +} + +nsresult +nsAccessible::GetNameInternal(nsAString& aName) +{ + PRBool canAggregateName = mRoleMapEntry && + mRoleMapEntry->nameRule == eNameOkFromChildren; + + nsCOMPtr content = GetRoleContent(mDOMNode); + if (!content) + return NS_OK; + + if (content->IsNodeOfType(nsINode::eHTML)) + return GetHTMLName(aName, canAggregateName); + + if (content->IsNodeOfType(nsINode::eXUL)) + return GetXULName(aName, canAggregateName); + + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsAccessible private methods + already_AddRefed nsAccessible::GetFirstAvailableAccessible(nsIDOMNode *aStartNode, PRBool aRequireLeaf) { diff --git a/accessible/src/base/nsAccessible.h b/accessible/src/base/nsAccessible.h index c0361244ba4d..e8442701b86a 100644 --- a/accessible/src/base/nsAccessible.h +++ b/accessible/src/base/nsAccessible.h @@ -91,6 +91,14 @@ private: }; +#define NS_ACCESSIBLE_IMPL_CID \ +{ /* 4E36C7A8-9203-4ef9-B619-271DDF6BB839 */ \ + 0x4e36c7a8, \ + 0x9203, \ + 0x4ef9, \ + { 0xb6, 0x19, 0x27, 0x1d, 0xdf, 0x6b, 0xb8, 0x39 } \ +} + class nsAccessible : public nsAccessNodeWrap, public nsIAccessible, public nsPIAccessible, @@ -110,15 +118,32 @@ public: NS_DECL_NSIACCESSIBLEHYPERLINK NS_DECL_NSIACCESSIBLESELECTABLE NS_DECL_NSIACCESSIBLEVALUE + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSIBLE_IMPL_CID) // nsIAccessNode NS_IMETHOD Shutdown(); + ////////////////////////////////////////////////////////////////////////////// + // Public methods + + /** + * Returns the accessible name specified by ARIA. + */ + nsresult GetARIAName(nsAString& aName); + + /** + * Returns the accessible name provided by native markup. It doesn't take + * into account ARIA stuffs used to specify the name. + */ + virtual nsresult GetNameInternal(nsAString& aName); + /** * Return the state of accessible that doesn't take into account ARIA states. * Use nsIAccessible::finalState() to get all states for accessible. If * second argument is omitted then second bit field of accessible state won't * be calculated. + * + * XXX: should be renamed into GetStateInternal */ NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); @@ -128,6 +153,11 @@ public: */ virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); + ////////////////////////////////////////////////////////////////////////////// + // Helper methods + // + // XXX: should be moved into utility class + #ifdef DEBUG_A11Y static PRBool IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible); #endif @@ -286,6 +316,8 @@ protected: PRInt32 mAccChildCount; }; +NS_DEFINE_STATIC_IID_ACCESSOR(nsAccessible, + NS_ACCESSIBLE_IMPL_CID) #endif diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index 6f7d93547205..94f22c4b3a3d 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -176,7 +176,8 @@ NS_INTERFACE_MAP_END_INHERITING(nsHyperTextAccessible) NS_IMPL_ADDREF_INHERITED(nsDocAccessible, nsHyperTextAccessible) NS_IMPL_RELEASE_INHERITED(nsDocAccessible, nsHyperTextAccessible) -NS_IMETHODIMP nsDocAccessible::GetName(nsAString& aName) +NS_IMETHODIMP +nsDocAccessible::GetName(nsAString& aName) { nsresult rv = NS_OK; aName.Truncate(); @@ -184,7 +185,8 @@ NS_IMETHODIMP nsDocAccessible::GetName(nsAString& aName) rv = mParent->GetName(aName); // Allow owning iframe to override the name } if (aName.IsEmpty()) { - rv = nsAccessible::GetName(aName); // Allow name via aria-labelledby or title attribute + // Allow name via aria-labelledby or title attribute + rv = nsAccessible::GetName(aName); } if (aName.IsEmpty()) { rv = GetTitle(aName); // Try title element diff --git a/accessible/src/html/nsHTMLAreaAccessible.cpp b/accessible/src/html/nsHTMLAreaAccessible.cpp index b31fccb265c6..30d0467b9408 100644 --- a/accessible/src/html/nsHTMLAreaAccessible.cpp +++ b/accessible/src/html/nsHTMLAreaAccessible.cpp @@ -58,21 +58,14 @@ nsHTMLAreaAccessible:: //////////////////////////////////////////////////////////////////////////////// // nsIAccessible -NS_IMETHODIMP -nsHTMLAreaAccessible::GetName(nsAString & aName) +nsresult +nsHTMLAreaAccessible::GetNameInternal(nsAString & aName) { - aName.Truncate(); + nsresult rv = nsAccessible::GetNameInternal(aName); + NS_ENSURE_SUCCESS(rv, rv); - if (IsDefunct()) - return NS_ERROR_FAILURE; - - if (mRoleMapEntry) { - nsresult rv = nsAccessible::GetName(aName); - NS_ENSURE_SUCCESS(rv, rv); - - if (!aName.IsEmpty()) - return NS_OK; - } + if (!aName.IsEmpty()) + return NS_OK; nsCOMPtr content(do_QueryInterface(mDOMNode)); if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, diff --git a/accessible/src/html/nsHTMLAreaAccessible.h b/accessible/src/html/nsHTMLAreaAccessible.h index ad1e1a9f068a..057a94b71aba 100644 --- a/accessible/src/html/nsHTMLAreaAccessible.h +++ b/accessible/src/html/nsHTMLAreaAccessible.h @@ -52,7 +52,6 @@ public: nsIWeakReference* aShell); // nsIAccessible - NS_IMETHOD GetName(nsAString & aName); NS_IMETHOD GetDescription(nsAString& aDescription); NS_IMETHOD GetFirstChild(nsIAccessible **_retval); @@ -62,6 +61,9 @@ public: NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height); NS_IMETHOD GetChildAtPoint(PRInt32 aX, PRInt32 aY, nsIAccessible **aAccessible) { NS_ENSURE_ARG_POINTER(aAccessible); NS_ADDREF(*aAccessible = this); return NS_OK; } // Don't walk into these + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; #endif diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index 32e49d756e53..e1ba79298716 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -275,27 +275,15 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetRole(PRUint32 *_retval) return NS_OK; } -NS_IMETHODIMP -nsHTMLButtonAccessible::GetName(nsAString& aName) +nsresult +nsHTMLButtonAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - nsCOMPtr content(do_QueryInterface(mDOMNode)); - if (!content) { - return NS_ERROR_FAILURE; // Node shut down - } - nsAutoString name; - // Prefer aria-labelledby attribute for name - if (content->HasAttr(kNameSpaceID_None, - nsAccessibilityAtoms::aria_label) || - content->HasAttr(kNameSpaceID_None, - nsAccessibilityAtoms::aria_labelledby)) { - GetHTMLName(name, PR_FALSE); - } + GetHTMLName(name, PR_FALSE); if (name.IsEmpty()) { // no label from HTML or ARIA + nsCOMPtr content(do_QueryInterface(mDOMNode)); if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, name) && !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, @@ -408,11 +396,17 @@ nsHTMLTextFieldAccessible::GetName(nsAString& aName) { aName.Truncate(); - nsCOMPtr content = do_QueryInterface(mDOMNode); - if (!content) { + if (IsDefunct()) return NS_ERROR_FAILURE; - } - nsresult rv = GetHTMLName(aName, PR_FALSE); + + nsresult rv = GetARIAName(aName); + NS_ENSURE_SUCCESS(rv, rv); + + if (!aName.IsEmpty()) + return NS_OK; + + nsCOMPtr content = do_QueryInterface(mDOMNode); + rv = nsAccessible::GetHTMLName(aName, PR_FALSE); if (NS_FAILED(rv) || !aName.IsEmpty() || !content->GetBindingParent()) { return rv; } @@ -614,20 +608,14 @@ nsIContent* nsHTMLGroupboxAccessible::GetLegend() return nsnull; } -NS_IMETHODIMP -nsHTMLGroupboxAccessible::GetName(nsAString& aName) +nsresult +nsHTMLGroupboxAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); + nsresult rv = nsAccessible::GetNameInternal(aName); + NS_ENSURE_SUCCESS(rv, rv); - if (!mDOMNode) { - return NS_ERROR_FAILURE; - } - if (mRoleMapEntry) { - nsAccessible::GetName(aName); - if (!aName.IsEmpty()) { - return NS_OK; - } - } + if (!aName.IsEmpty()) + return NS_OK; nsIContent *legendContent = GetLegend(); if (legendContent) { diff --git a/accessible/src/html/nsHTMLFormControlAccessible.h b/accessible/src/html/nsHTMLFormControlAccessible.h index b3fc167a7756..5545ff8cf303 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/accessible/src/html/nsHTMLFormControlAccessible.h @@ -73,12 +73,16 @@ public: enum { eAction_Click = 0 }; nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD DoAction(PRUint8 index); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsHTML4ButtonAccessible : public nsHyperTextAccessibleWrap @@ -88,12 +92,19 @@ public: enum { eAction_Click = 0 }; nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetName(nsAString& aName) { aName.Truncate(); return GetHTMLName(aName, PR_TRUE); } NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD DoAction(PRUint8 index); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName) + { + return GetHTMLName(aName, PR_TRUE); + } }; class nsHTMLTextFieldAccessible : public nsHyperTextAccessibleWrap @@ -106,6 +117,7 @@ public: NS_DECL_ISUPPORTS_INHERITED + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetValue(nsAString& _retval); @@ -122,9 +134,14 @@ class nsHTMLGroupboxAccessible : public nsHyperTextAccessibleWrap { public: nsHTMLGroupboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aRole); - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); + protected: nsIContent* GetLegend(); }; diff --git a/accessible/src/html/nsHTMLImageAccessible.cpp b/accessible/src/html/nsHTMLImageAccessible.cpp index a0769c62d4fd..7b70dd454726 100644 --- a/accessible/src/html/nsHTMLImageAccessible.cpp +++ b/accessible/src/html/nsHTMLImageAccessible.cpp @@ -126,16 +126,15 @@ nsHTMLImageAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } - -/* wstring getName (); */ -NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& aName) +NS_IMETHODIMP +nsHTMLImageAccessible::GetName(nsAString& aName) { aName.Truncate(); + if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr content(do_QueryInterface(mDOMNode)); - NS_ASSERTION(content, "Image node always supports nsIContent"); // No alt attribute means AT can repair if there is no accessible name // alt="" with no title or aria-labelledby means image is presentational and @@ -147,8 +146,16 @@ NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& aName) content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby)) { // Use HTML label or DHTML accessibility's label or labelledby attribute for name // GetHTMLName will also try title attribute as a last resort - GetHTMLName(aName, PR_FALSE); + nsresult rv = GetARIAName(aName); + NS_ENSURE_SUCCESS(rv, rv); + + if (!aName.IsEmpty()) + return NS_OK; + + rv = GetHTMLName(aName, PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); } + if (aName.IsEmpty()) { // No name from alt or aria-labelledby content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, aName); if (!hasAltAttrib && aName.IsEmpty()) { diff --git a/accessible/src/html/nsHTMLImageAccessible.h b/accessible/src/html/nsHTMLImageAccessible.h index 49123d020c5f..b5ee1233a685 100644 --- a/accessible/src/html/nsHTMLImageAccessible.h +++ b/accessible/src/html/nsHTMLImageAccessible.h @@ -58,9 +58,9 @@ public: nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); // nsIAccessible - NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *_retval); + NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetNumActions(PRUint8 *aNumActions); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD DoAction(PRUint8 index); diff --git a/accessible/src/html/nsHTMLLinkAccessible.cpp b/accessible/src/html/nsHTMLLinkAccessible.cpp index bd42e37c3527..60f14d0a1b39 100644 --- a/accessible/src/html/nsHTMLLinkAccessible.cpp +++ b/accessible/src/html/nsHTMLLinkAccessible.cpp @@ -57,14 +57,9 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLLinkAccessible, nsHyperTextAccessibleWrap, //////////////////////////////////////////////////////////////////////////////// // nsIAccessible -NS_IMETHODIMP -nsHTMLLinkAccessible::GetName(nsAString& aName) +nsresult +nsHTMLLinkAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - if (IsDefunct()) - return NS_ERROR_FAILURE; - nsCOMPtr content(do_QueryInterface(mDOMNode)); nsresult rv = AppendFlatStringFromSubtree(content, &aName); NS_ENSURE_SUCCESS(rv, rv); diff --git a/accessible/src/html/nsHTMLLinkAccessible.h b/accessible/src/html/nsHTMLLinkAccessible.h index a9adeac02e3e..98406a6caa58 100644 --- a/accessible/src/html/nsHTMLLinkAccessible.h +++ b/accessible/src/html/nsHTMLLinkAccessible.h @@ -50,7 +50,6 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIAccessible - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetRole(PRUint32 *aRole); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetValue(nsAString& aValue); @@ -62,6 +61,9 @@ public: // nsIAccessibleHyperLink NS_IMETHOD GetURI(PRInt32 aIndex, nsIURI **aURI); + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); + protected: enum { eAction_Jump = 0 }; diff --git a/accessible/src/html/nsHTMLSelectAccessible.cpp b/accessible/src/html/nsHTMLSelectAccessible.cpp index 7c12b595b98d..11f44b146492 100644 --- a/accessible/src/html/nsHTMLSelectAccessible.cpp +++ b/accessible/src/html/nsHTMLSelectAccessible.cpp @@ -510,45 +510,33 @@ NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetRole(PRUint32 *aRole) return NS_OK; } -/** - * Get our Name from our Content's subtree - */ -NS_IMETHODIMP -nsHTMLSelectOptionAccessible::GetName(nsAString& aName) +nsresult +nsHTMLSelectOptionAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - // CASE #1 -- great majority of the cases // find the label attribute - this is what the W3C says we should use - nsCOMPtr domElement(do_QueryInterface(mDOMNode)); - if (!domElement) - return NS_ERROR_FAILURE; - - nsresult rv = domElement->GetAttribute(NS_LITERAL_STRING("label"), aName) ; - if (NS_SUCCEEDED(rv) && !aName.IsEmpty()) { + nsCOMPtr content(do_QueryInterface(mDOMNode)); + content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::label, aName); + if (!aName.IsEmpty()) return NS_OK; - } // CASE #2 -- no label parameter, get the first child, // use it if it is a text node - nsCOMPtr child; - mDOMNode->GetFirstChild(getter_AddRefs(child)); + nsCOMPtr text = content->GetChildAt(0); + if (!text) + return NS_OK; - if (child) { - nsCOMPtr text = do_QueryInterface(child); - if (text && text->IsNodeOfType(nsINode::eTEXT)) { - nsAutoString txtValue; - rv = AppendFlatStringFromContentNode(text, &txtValue); - NS_ENSURE_SUCCESS(rv, rv); + if (text->IsNodeOfType(nsINode::eTEXT)) { + nsAutoString txtValue; + nsresult rv = AppendFlatStringFromContentNode(text, &txtValue); + NS_ENSURE_SUCCESS(rv, rv); - // Temp var (txtValue) needed until CompressWhitespace built for nsAString - txtValue.CompressWhitespace(); - aName.Assign(txtValue); - return NS_OK; - } + // Temp var (txtValue) needed until CompressWhitespace built for nsAString + txtValue.CompressWhitespace(); + aName.Assign(txtValue); + return NS_OK; } - - aName.Truncate(); + return NS_OK; } @@ -1383,14 +1371,11 @@ NS_IMETHODIMP nsHTMLComboboxButtonAccessible::GetParent(nsIAccessible **aParent) return NS_OK; } -/** - * Gets the name from GetActionName() - */ NS_IMETHODIMP nsHTMLComboboxButtonAccessible::GetName(nsAString& aName) { + // Native anonymous content, no way to use ARIA here. aName.Truncate(); - return GetActionName(eAction_Click, aName); } diff --git a/accessible/src/html/nsHTMLSelectAccessible.h b/accessible/src/html/nsHTMLSelectAccessible.h index dfb154954ece..df4b912ae16f 100644 --- a/accessible/src/html/nsHTMLSelectAccessible.h +++ b/accessible/src/html/nsHTMLSelectAccessible.h @@ -84,7 +84,11 @@ public: nsHTMLSelectableAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell); virtual ~nsHTMLSelectableAccessible() {} - NS_IMETHOD GetName(nsAString &aName) { return GetHTMLName(aName, PR_FALSE); } + // nsAccessible + virtual nsresult GetNameInternal(nsAString &aName) + { + return GetHTMLName(aName, PR_FALSE); + } protected: @@ -156,13 +160,15 @@ public: nsHTMLSelectOptionAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell); virtual ~nsHTMLSelectOptionAccessible() {} - /* ----- nsIAccessible ----- */ + // nsIAccessible NS_IMETHOD DoAction(PRUint8 index); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *aRole); - NS_IMETHOD GetName(nsAString& aName); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); nsIFrame* GetBoundsFrame(); @@ -268,18 +274,22 @@ public: nsHTMLComboboxButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell); virtual ~nsHTMLComboboxButtonAccessible() {} - /* ----- nsIAccessible ----- */ + // nsIAccessible NS_IMETHOD DoAction(PRUint8 index); NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD GetParent(nsIAccessible **_retval); - NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); + NS_IMETHOD GetName(nsAString& aName); + + // nsIAccessNode NS_IMETHOD GetUniqueID(void **aUniqueID); +protected: virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame); }; + #endif /* diff --git a/accessible/src/html/nsHTMLTableAccessible.cpp b/accessible/src/html/nsHTMLTableAccessible.cpp index ee1070797bd5..c161e4c1d86e 100644 --- a/accessible/src/html/nsHTMLTableAccessible.cpp +++ b/accessible/src/html/nsHTMLTableAccessible.cpp @@ -204,11 +204,11 @@ nsHTMLTableAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -NS_IMETHODIMP nsHTMLTableAccessible::GetName(nsAString& aName) +nsresult +nsHTMLTableAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); // Default name is blank + nsAccessible::GetNameInternal(aName); - nsAccessible::GetName(aName); if (aName.IsEmpty()) { nsCOMPtr content(do_QueryInterface(mDOMNode)); if (content) { diff --git a/accessible/src/html/nsHTMLTableAccessible.h b/accessible/src/html/nsHTMLTableAccessible.h index 70c6e00208a2..cd3d959c541d 100644 --- a/accessible/src/html/nsHTMLTableAccessible.h +++ b/accessible/src/html/nsHTMLTableAccessible.h @@ -67,17 +67,23 @@ class nsHTMLTableAccessible : public nsAccessibleWrap, public nsIAccessibleTable { public: + nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIACCESSIBLETABLE - nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aResult); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetName(nsAString& aResult); - virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); NS_IMETHOD GetDescription(nsAString& aDescription); NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated); + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); + virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); + + // nsHTMLTableAccessible + /** * Returns true if the column index is in the valid column range. * diff --git a/accessible/src/html/nsHTMLTextAccessible.cpp b/accessible/src/html/nsHTMLTextAccessible.cpp index 44fd29ff1311..18316c00dca4 100644 --- a/accessible/src/html/nsHTMLTextAccessible.cpp +++ b/accessible/src/html/nsHTMLTextAccessible.cpp @@ -53,8 +53,10 @@ nsTextAccessibleWrap(aDomNode, aShell) { } -NS_IMETHODIMP nsHTMLTextAccessible::GetName(nsAString& aName) +NS_IMETHODIMP +nsHTMLTextAccessible::GetName(nsAString& aName) { + // Text node, ARIA can't be used. aName.Truncate(); return AppendTextTo(aName, 0, PR_UINT32_MAX); } @@ -143,7 +145,8 @@ nsHTMLBRAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -NS_IMETHODIMP nsHTMLBRAccessible::GetName(nsAString& aName) +nsresult +nsHTMLBRAccessible::GetNameInternal(nsAString& aName) { aName = static_cast('\n'); // Newline char return NS_OK; @@ -158,7 +161,8 @@ nsTextAccessible(aDomNode, aShell) { } -NS_IMETHODIMP nsHTMLLabelAccessible::GetName(nsAString& aReturn) +nsresult +nsHTMLLabelAccessible::GetNameInternal(nsAString& aReturn) { nsresult rv = NS_ERROR_FAILURE; nsCOMPtr content(do_QueryInterface(mDOMNode)); @@ -312,6 +316,7 @@ nsHTMLListBulletAccessible::Shutdown() NS_IMETHODIMP nsHTMLListBulletAccessible::GetName(nsAString &aName) { + // Native anonymous content, ARIA can't be used. aName = mBulletText; return NS_OK; } diff --git a/accessible/src/html/nsHTMLTextAccessible.h b/accessible/src/html/nsHTMLTextAccessible.h index 1502fb6ad4ba..977a411172cf 100644 --- a/accessible/src/html/nsHTMLTextAccessible.h +++ b/accessible/src/html/nsHTMLTextAccessible.h @@ -52,9 +52,11 @@ public: nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); // nsIAccessible - NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); + NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetRole(PRUint32 *aRole); + + // nsAccessible virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); }; @@ -69,22 +71,31 @@ class nsHTMLBRAccessible : public nsLeafAccessible { public: nsHTMLBRAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aRole); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetName(nsAString& aName); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsHTMLLabelAccessible : public nsTextAccessible { public: nsHTMLLabelAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + NS_DECL_ISUPPORTS_INHERITED - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetFirstChild(nsIAccessible **aFirstChild); NS_IMETHOD GetLastChild(nsIAccessible **aLastChild); NS_IMETHOD GetChildCount(PRInt32 *aAccChildCount); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsHTMLListBulletAccessible : public nsLeafAccessible @@ -100,8 +111,8 @@ public: NS_IMETHOD Shutdown(); // nsIAccessible - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetRole(PRUint32 *aRole); + NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); // Don't cache via unique ID -- bullet accessible shares the same dom node as @@ -138,13 +149,18 @@ class nsHTMLLIAccessible : public nsLinkableAccessible public: nsHTMLLIAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell, const nsAString& aBulletText); - NS_IMETHOD Shutdown(); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = nsIAccessibleRole::ROLE_LISTITEM; return NS_OK; } NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetName(nsAString& aName) { aName.SetIsVoid(PR_TRUE); return mRoleMapEntry ? nsAccessible::GetName(aName) : NS_OK; } NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height); - void CacheChildren(); // Include bullet accessible + + // nsPIAccessNode + NS_IMETHOD Shutdown(); + protected: + void CacheChildren(); // Include bullet accessible + nsRefPtr mBulletAccessible; }; diff --git a/accessible/src/msaa/nsXULMenuAccessibleWrap.cpp b/accessible/src/msaa/nsXULMenuAccessibleWrap.cpp index 41bcd4318136..8fcfca11b187 100755 --- a/accessible/src/msaa/nsXULMenuAccessibleWrap.cpp +++ b/accessible/src/msaa/nsXULMenuAccessibleWrap.cpp @@ -49,7 +49,8 @@ nsXULMenuitemAccessible(aDOMNode, aShell) { } -NS_IMETHODIMP nsXULMenuitemAccessibleWrap::GetName(nsAString& aName) +NS_IMETHODIMP +nsXULMenuitemAccessibleWrap::GetName(nsAString& aName) { // XXX This should be done in get_accName() so that nsIAccessible::GetName()] // provides the same results on all platforms diff --git a/accessible/src/msaa/nsXULMenuAccessibleWrap.h b/accessible/src/msaa/nsXULMenuAccessibleWrap.h index 3a6caedd9eba..041f9bb03017 100755 --- a/accessible/src/msaa/nsXULMenuAccessibleWrap.h +++ b/accessible/src/msaa/nsXULMenuAccessibleWrap.h @@ -45,6 +45,8 @@ class nsXULMenuitemAccessibleWrap : public nsXULMenuitemAccessible public: nsXULMenuitemAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell); virtual ~nsXULMenuitemAccessibleWrap() {} + + // nsIAccessible NS_IMETHOD GetName(nsAString& aName); }; diff --git a/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp b/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp index 68b2896a0905..da905c8387df 100644 --- a/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp +++ b/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp @@ -113,7 +113,8 @@ NS_IMETHODIMP nsXULTreeitemAccessibleWrap::GetBounds(PRInt32 *x, PRInt32 *y, PRI return NS_OK; } -NS_IMETHODIMP nsXULTreeitemAccessibleWrap::GetName(nsAString& aName) +NS_IMETHODIMP +nsXULTreeitemAccessibleWrap::GetName(nsAString& aName) { NS_ENSURE_STATE(mTree); nsCOMPtr cols; diff --git a/accessible/src/xforms/nsXFormsAccessible.cpp b/accessible/src/xforms/nsXFormsAccessible.cpp index 9def060850c4..096143514a73 100755 --- a/accessible/src/xforms/nsXFormsAccessible.cpp +++ b/accessible/src/xforms/nsXFormsAccessible.cpp @@ -221,28 +221,9 @@ nsXFormsAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -NS_IMETHODIMP -nsXFormsAccessible::GetName(nsAString& aName) +nsresult +nsXFormsAccessible::GetNameInternal(nsAString& aName) { - nsCOMPtr content(do_QueryInterface(mDOMNode)); - if (!content) { - return NS_ERROR_FAILURE; // Node shut down - } - - // Check for ARIA label property - nsAutoString name; - if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, name)) { - aName = name; - return NS_OK; - } - - // Check for ARIA labelledby relationship property - nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, name); - if (NS_SUCCEEDED(rv) && !name.IsEmpty()) { - aName = name; - return NS_OK; - } - // search the xforms:label element return GetBoundChildElementValue(NS_LITERAL_STRING("label"), aName); } diff --git a/accessible/src/xforms/nsXFormsAccessible.h b/accessible/src/xforms/nsXFormsAccessible.h index 6116d451ad07..9ac310675135 100755 --- a/accessible/src/xforms/nsXFormsAccessible.h +++ b/accessible/src/xforms/nsXFormsAccessible.h @@ -79,12 +79,12 @@ public: // that it is bound to. NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - // Returns value of child xforms 'label' element. - NS_IMETHOD GetName(nsAString& aName); - // Returns value of child xforms 'hint' element. NS_IMETHOD GetDescription(nsAString& aDescription); + // Returns value of child xforms 'label' element. + virtual nsresult GetNameInternal(nsAString& aName); + // Appends ARIA 'datatype' property based on datatype of instance node that // element is bound to. virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); diff --git a/accessible/src/xforms/nsXFormsFormControlsAccessible.cpp b/accessible/src/xforms/nsXFormsFormControlsAccessible.cpp index bfbba0a36a8e..90f76094a84c 100755 --- a/accessible/src/xforms/nsXFormsFormControlsAccessible.cpp +++ b/accessible/src/xforms/nsXFormsFormControlsAccessible.cpp @@ -55,14 +55,11 @@ nsXFormsLabelAccessible::GetRole(PRUint32 *aRole) return NS_OK; } -NS_IMETHODIMP -nsXFormsLabelAccessible::GetName(nsAString& aName) +nsresult +nsXFormsLabelAccessible::GetNameInternal(nsAString& aName) { // XXX Correct name calculation for this, see bug 453594. - nsAutoString name; - nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, name); - aName = name; - return rv; + return NS_OK; } NS_IMETHODIMP diff --git a/accessible/src/xforms/nsXFormsFormControlsAccessible.h b/accessible/src/xforms/nsXFormsFormControlsAccessible.h index 2d2d072ea278..1cf44da15a18 100755 --- a/accessible/src/xforms/nsXFormsFormControlsAccessible.h +++ b/accessible/src/xforms/nsXFormsFormControlsAccessible.h @@ -50,9 +50,12 @@ class nsXFormsLabelAccessible : public nsXFormsAccessible public: nsXFormsLabelAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell); + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aRole); - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetDescription(nsAString& aDescription); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; /** diff --git a/accessible/src/xforms/nsXFormsWidgetsAccessible.cpp b/accessible/src/xforms/nsXFormsWidgetsAccessible.cpp index 9c8fcea11471..42a16566ada0 100644 --- a/accessible/src/xforms/nsXFormsWidgetsAccessible.cpp +++ b/accessible/src/xforms/nsXFormsWidgetsAccessible.cpp @@ -186,10 +186,11 @@ nsXFormsComboboxPopupWidgetAccessible::GetValue(nsAString& aValue) return NS_OK; } -NS_IMETHODIMP -nsXFormsComboboxPopupWidgetAccessible::GetName(nsAString& aName) +nsresult +nsXFormsComboboxPopupWidgetAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); + // Override nsXFormsAccessible::GetName() to prevent name calculation by + // XForms rules. return NS_OK; } diff --git a/accessible/src/xforms/nsXFormsWidgetsAccessible.h b/accessible/src/xforms/nsXFormsWidgetsAccessible.h index 12b1fe643af6..301da03661a9 100644 --- a/accessible/src/xforms/nsXFormsWidgetsAccessible.h +++ b/accessible/src/xforms/nsXFormsWidgetsAccessible.h @@ -85,12 +85,15 @@ public: nsXFormsComboboxPopupWidgetAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell); + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aRole); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetValue(nsAString& aValue); - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetDescription(nsAString& aDescription); + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); +protected: void CacheChildren(); }; diff --git a/accessible/src/xul/nsXULColorPickerAccessible.cpp b/accessible/src/xul/nsXULColorPickerAccessible.cpp index b121d3ab7891..79d56df3b3a7 100644 --- a/accessible/src/xul/nsXULColorPickerAccessible.cpp +++ b/accessible/src/xul/nsXULColorPickerAccessible.cpp @@ -92,11 +92,9 @@ nsXULColorPickerTileAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState return NS_OK; } -NS_IMETHODIMP -nsXULColorPickerTileAccessible::GetName(nsAString& aName) +nsresult +nsXULColorPickerTileAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - return GetXULName(aName); } diff --git a/accessible/src/xul/nsXULColorPickerAccessible.h b/accessible/src/xul/nsXULColorPickerAccessible.h index 7cb0943479d7..2f59778b90c2 100644 --- a/accessible/src/xul/nsXULColorPickerAccessible.h +++ b/accessible/src/xul/nsXULColorPickerAccessible.h @@ -46,10 +46,14 @@ class nsXULColorPickerTileAccessible : public nsFormControlAccessible { public: nsXULColorPickerTileAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetValue(nsAString& _retval); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsXULColorPickerAccessible : public nsXULColorPickerTileAccessible diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index 01578140c31d..841fcd977ec7 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -417,11 +417,9 @@ NS_IMETHODIMP nsXULGroupboxAccessible::GetRole(PRUint32 *aRole) return NS_OK; } -NS_IMETHODIMP -nsXULGroupboxAccessible::GetName(nsAString& aName) +nsresult +nsXULGroupboxAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - nsCOMPtr label; GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABELLED_BY, getter_AddRefs(label)); diff --git a/accessible/src/xul/nsXULFormControlAccessible.h b/accessible/src/xul/nsXULFormControlAccessible.h index 912d7956b645..925109c8934e 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.h +++ b/accessible/src/xul/nsXULFormControlAccessible.h @@ -91,9 +91,13 @@ class nsXULGroupboxAccessible : public nsAccessibleWrap { public: nsXULGroupboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); - NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsXULProgressMeterAccessible : public nsFormControlAccessible diff --git a/accessible/src/xul/nsXULMenuAccessible.cpp b/accessible/src/xul/nsXULMenuAccessible.cpp index 8abe5a2c35f4..fc8f7836b5d9 100644 --- a/accessible/src/xul/nsXULMenuAccessible.cpp +++ b/accessible/src/xul/nsXULMenuAccessible.cpp @@ -389,17 +389,11 @@ nsXULMenuitemAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -NS_IMETHODIMP -nsXULMenuitemAccessible::GetName(nsAString& aName) +nsresult +nsXULMenuitemAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - nsCOMPtr element(do_QueryInterface(mDOMNode)); - if (!element) { - return NS_ERROR_FAILURE; - } - element->GetAttribute(NS_LITERAL_STRING("label"), aName); - + nsCOMPtr content(do_QueryInterface(mDOMNode)); + content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::label, aName); return NS_OK; } @@ -581,11 +575,9 @@ nsXULMenuSeparatorAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -NS_IMETHODIMP -nsXULMenuSeparatorAccessible::GetName(nsAString& aName) +nsresult +nsXULMenuSeparatorAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - return NS_OK; } @@ -696,14 +688,9 @@ void nsXULMenupopupAccessible::GenerateMenu(nsIDOMNode *aNode) } } -NS_IMETHODIMP -nsXULMenupopupAccessible::GetName(nsAString& aName) +nsresult +nsXULMenupopupAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - if (!mDOMNode) - return NS_ERROR_FAILURE; - nsCOMPtr content(do_QueryInterface(mDOMNode)); while (content && aName.IsEmpty()) { content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::label, aName); @@ -757,11 +744,10 @@ nsXULMenubarAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) } -NS_IMETHODIMP -nsXULMenubarAccessible::GetName(nsAString& aName) +nsresult +nsXULMenubarAccessible::GetNameInternal(nsAString& aName) { aName.AssignLiteral("Application"); - return NS_OK; } diff --git a/accessible/src/xul/nsXULMenuAccessible.h b/accessible/src/xul/nsXULMenuAccessible.h index efbb8bbbca5f..3ad2ca068bdc 100644 --- a/accessible/src/xul/nsXULMenuAccessible.h +++ b/accessible/src/xul/nsXULMenuAccessible.h @@ -76,8 +76,8 @@ public: enum { eAction_Click = 0 }; nsXULMenuitemAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD Init(); - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetDescription(nsAString& aDescription); NS_IMETHOD GetKeyboardShortcut(nsAString& _retval); NS_IMETHOD GetDefaultKeyBinding(nsAString& aKeyBinding); @@ -86,7 +86,14 @@ public: NS_IMETHOD DoAction(PRUint8 index); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD GetNumActions(PRUint8 *_retval); + + // nsPIAccessNode + NS_IMETHOD Init(); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); + NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren); }; @@ -94,21 +101,31 @@ class nsXULMenuSeparatorAccessible : public nsXULMenuitemAccessible { public: nsXULMenuSeparatorAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD DoAction(PRUint8 index); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD GetNumActions(PRUint8 *_retval); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsXULMenupopupAccessible : public nsXULSelectableAccessible { public: nsXULMenupopupAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD GetRole(PRUint32 *_retval); + NS_IMETHOD GetRole(PRUint32 *aRole); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); + + // nsXULMenupopupAccessible static already_AddRefed FindInNodeList(nsIDOMNodeList *aNodeList, nsIAtom *aAtom, PRUint32 aNameSpaceID); static void GenerateMenu(nsIDOMNode *aNode); @@ -118,9 +135,13 @@ class nsXULMenubarAccessible : public nsAccessibleWrap { public: nsXULMenubarAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *_retval); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; #endif diff --git a/accessible/src/xul/nsXULSelectAccessible.cpp b/accessible/src/xul/nsXULSelectAccessible.cpp index 8891e43e7225..9e4be4803fc4 100644 --- a/accessible/src/xul/nsXULSelectAccessible.cpp +++ b/accessible/src/xul/nsXULSelectAccessible.cpp @@ -107,11 +107,9 @@ nsXULColumnItemAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -NS_IMETHODIMP -nsXULColumnItemAccessible::GetName(nsAString& aName) +nsresult +nsXULColumnItemAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - return GetXULName(aName); } @@ -859,14 +857,9 @@ nsXULListitemAccessible::GetListAccessible() * If there is a Listcell as a child ( not anonymous ) use it, otherwise * default to getting the name from GetXULName */ -NS_IMETHODIMP -nsXULListitemAccessible::GetName(nsAString& aName) +nsresult +nsXULListitemAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - if (!mDOMNode) - return NS_ERROR_FAILURE; - nsCOMPtr child; if (NS_SUCCEEDED(mDOMNode->GetFirstChild(getter_AddRefs(child)))) { nsCOMPtr childElement (do_QueryInterface(child)); diff --git a/accessible/src/xul/nsXULSelectAccessible.h b/accessible/src/xul/nsXULSelectAccessible.h index 8b931ec779da..4e532490a53e 100644 --- a/accessible/src/xul/nsXULSelectAccessible.h +++ b/accessible/src/xul/nsXULSelectAccessible.h @@ -71,13 +71,15 @@ public: // nsIAccessible NS_IMETHOD GetRole(PRUint32 *aRole); - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetNumActions(PRUint8 *aNumActions); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD DoAction(PRUint8 aIndex); + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); + enum { eAction_Click = 0 }; }; @@ -135,8 +137,7 @@ public: nsXULListitemAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell); virtual ~nsXULListitemAccessible() {} - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetName(nsAString& _retval); + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetActionName(PRUint8 index, nsAString& aName); @@ -144,6 +145,8 @@ public: NS_IMETHOD GetDescription(nsAString& aDesc) { return nsAccessibleWrap::GetDescription(aDesc); } NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren); + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); protected: diff --git a/accessible/src/xul/nsXULTabAccessible.cpp b/accessible/src/xul/nsXULTabAccessible.cpp index 73b3a241d085..edb196dcdcea 100644 --- a/accessible/src/xul/nsXULTabAccessible.cpp +++ b/accessible/src/xul/nsXULTabAccessible.cpp @@ -296,12 +296,10 @@ NS_IMETHODIMP nsXULTabsAccessible::GetValue(nsAString& _retval) return NS_OK; } -/** no name*/ -NS_IMETHODIMP -nsXULTabsAccessible::GetName(nsAString& aName) +nsresult +nsXULTabsAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - + // no name return NS_OK; } diff --git a/accessible/src/xul/nsXULTabAccessible.h b/accessible/src/xul/nsXULTabAccessible.h index 12c3f2e2b97f..a053a8e8a294 100644 --- a/accessible/src/xul/nsXULTabAccessible.h +++ b/accessible/src/xul/nsXULTabAccessible.h @@ -85,10 +85,14 @@ class nsXULTabsAccessible : public nsXULSelectableAccessible { public: nsXULTabsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetValue(nsAString& _retval); - NS_IMETHOD GetName(nsAString& _retval); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; /** diff --git a/accessible/src/xul/nsXULTextAccessible.cpp b/accessible/src/xul/nsXULTextAccessible.cpp index 73e03bd733ee..5c729749ffb1 100644 --- a/accessible/src/xul/nsXULTextAccessible.cpp +++ b/accessible/src/xul/nsXULTextAccessible.cpp @@ -55,19 +55,15 @@ nsHyperTextAccessibleWrap(aDomNode, aShell) { } -/* wstring getName (); */ -NS_IMETHODIMP -nsXULTextAccessible::GetName(nsAString& aName) +nsresult +nsXULTextAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - nsCOMPtr content(do_QueryInterface(mDOMNode)); - if (!content) { - return NS_ERROR_FAILURE; // Node shut down - } + // if the value attr doesn't exist, the screen reader must get the accessible text // from the accessible text interface or from the children - return content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, aName); + content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, aName); + return NS_OK; } NS_IMETHODIMP @@ -120,11 +116,9 @@ nsLeafAccessible(aDomNode, aShell) { } -NS_IMETHODIMP -nsXULTooltipAccessible::GetName(nsAString& aName) +nsresult +nsXULTooltipAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - return GetXULName(aName, PR_TRUE); } @@ -174,14 +168,9 @@ nsXULLinkAccessible::GetValue(nsAString& aValue) return NS_OK; } -NS_IMETHODIMP -nsXULLinkAccessible::GetName(nsAString& aName) +nsresult +nsXULLinkAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - if (IsDefunct()) - return NS_ERROR_FAILURE; - nsCOMPtr content(do_QueryInterface(mDOMNode)); content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, aName); if (!aName.IsEmpty()) diff --git a/accessible/src/xul/nsXULTextAccessible.h b/accessible/src/xul/nsXULTextAccessible.h index 7a12c55c291c..fb4784a80d6c 100644 --- a/accessible/src/xul/nsXULTextAccessible.h +++ b/accessible/src/xul/nsXULTextAccessible.h @@ -51,11 +51,15 @@ class nsXULTextAccessible : public nsHyperTextAccessibleWrap public: nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = nsIAccessibleRole::ROLE_LABEL; return NS_OK; } NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsXULTooltipAccessible : public nsLeafAccessible @@ -63,9 +67,13 @@ class nsXULTooltipAccessible : public nsLeafAccessible public: nsXULTooltipAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetName(nsAString& _retval); + + // nsIAccessible NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *_retval); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsXULLinkAccessible : public nsHyperTextAccessibleWrap @@ -77,7 +85,6 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIAccessible - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetRole(PRUint32 *aRole); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetValue(nsAString& aValue); @@ -89,6 +96,9 @@ public: // nsIAccessibleHyperLink NS_IMETHOD GetURI(PRInt32 aIndex, nsIURI **aURI); + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); + protected: enum { eAction_Jump = 0 }; diff --git a/accessible/src/xul/nsXULTreeAccessible.cpp b/accessible/src/xul/nsXULTreeAccessible.cpp index 51f59cc25cd2..1c431d9b79f8 100644 --- a/accessible/src/xul/nsXULTreeAccessible.cpp +++ b/accessible/src/xul/nsXULTreeAccessible.cpp @@ -795,6 +795,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::Shutdown() NS_IMETHODIMP nsXULTreeitemAccessible::GetName(nsAString& aName) { + // XXX: we should take into account ARIA usage for content tree. aName.Truncate(); if (IsDefunct()) diff --git a/accessible/src/xul/nsXULTreeAccessible.h b/accessible/src/xul/nsXULTreeAccessible.h index 23ad8b329d27..b7e7a3fcc5cf 100644 --- a/accessible/src/xul/nsXULTreeAccessible.h +++ b/accessible/src/xul/nsXULTreeAccessible.h @@ -111,7 +111,7 @@ public: NS_IMETHOD Shutdown(); // nsIAccessible - NS_IMETHOD GetName(nsAString& _retval); + NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetNumActions(PRUint8 *_retval); diff --git a/accessible/tests/mochitest/nsIAccessible_name.js b/accessible/tests/mochitest/nsIAccessible_name.js index 1cf35e662360..161d201cc409 100644 --- a/accessible/tests/mochitest/nsIAccessible_name.js +++ b/accessible/tests/mochitest/nsIAccessible_name.js @@ -5,6 +5,10 @@ function testName(aID, aName) ok(false, "No accessible for " + aID + "!"); } - is(acc.name, aName, "Wrong name of the accessible for " + aID); + try { + is(acc.name, aName, "Wrong name of the accessible for " + aID); + } catch (e) { + ok(false, "Can't get name of the accessible for " + aID); + } return acc; }