Bug 195688 [ATK Accessibility] move nsIAccessibleHyperText support from nsHTMLIFrameAccessible to nsAccessibleHyperText

r=bolian.yin
Not in the default build
This commit is contained in:
kyle.yuan%sun.com 2003-03-24 09:36:04 +00:00
Родитель 5ec0699818
Коммит d98e5035da
6 изменённых файлов: 93 добавлений и 230 удалений

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

@ -1395,6 +1395,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULToolbarSeparatorAccessible(nsIDOM
NS_IMETHODIMP nsAccessibilityService::CreateXULTooltipAccessible(nsIDOMNode *aNode, nsIAccessible **_retval)
{
#ifdef MOZ_XUL
#ifndef MOZ_ACCESSIBILITY_ATK
nsCOMPtr<nsIWeakReference> weakShell;
GetShellFromNode(aNode, getter_AddRefs(weakShell));
@ -1403,6 +1404,9 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULTooltipAccessible(nsIDOMNode *aNo
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*_retval);
#else
*_retval = nsnull;
#endif // MOZ_ACCESSIBILITY_ATK
#else
*_retval = nsnull;
#endif // MOZ_XUL
@ -1631,6 +1635,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode,
frame->GetAccessible(getter_AddRefs(newAcc));
#ifndef MOZ_ACCESSIBILITY_ATK
// ---- If link, create link accessible ----
if (!newAcc) {
// is it a link?
@ -1640,6 +1645,7 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode,
newAcc = new nsHTMLLinkAccessible(aNode, weakShell);
}
}
#endif //MOZ_ACCESSIBILITY_ATK
// ---- If <select> <option>, create select option accessible

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

@ -95,6 +95,8 @@ public:
NS_IMETHOD AccTakeFocus(void);
NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval);
NS_IMETHOD GetFocusedNode(nsIDOMNode **aFocusedNode);
#ifdef MOZ_ACCESSIBILITY_ATK
static nsresult GetParentBlockNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aBlockNode);
#endif
@ -112,7 +114,6 @@ protected:
NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAString *aFlatString);
NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAString *aFlatString);
NS_IMETHOD AppendStringWithSpaces(nsAString *aFlatString, const nsAString& textEquivalent);
NS_IMETHOD GetFocusedNode(nsIDOMNode **aFocusedNode);
NS_IMETHOD CacheOptimizations(nsIAccessible *aParent, PRInt32 aSiblingIndex, nsIDOMNodeList *aSiblingList);
NS_IMETHOD HandleEvent(PRUint32 aEvent, nsIAccessible *aTarget, void * aData);
// helper method to verify frames

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

@ -52,7 +52,7 @@
* Typically, it's a paragraph of text, a cell of table, etc.
*/
NS_IMPL_ISUPPORTS1(nsAccessibleHyperText, nsIAccessibleText)
NS_IMPL_ISUPPORTS2(nsAccessibleHyperText, nsIAccessibleHyperText, nsIAccessibleText)
nsAccessibleHyperText::nsAccessibleHyperText(nsIDOMNode* aDomNode, nsIWeakReference* aShell)
{
@ -372,4 +372,84 @@ NS_IMETHODIMP nsAccessibleHyperText::RemoveSelection(PRInt32 aSelectionNum)
return NS_ERROR_NOT_IMPLEMENTED;
}
// ------- nsIAccessibleHyperText ---------------
/* readonly attribute long links; */
NS_IMETHODIMP nsAccessibleHyperText::GetLinks(PRInt32 *aLinks)
{
*aLinks = 0;
PRUint32 index, count;
mTextChildren->Count(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mTextChildren->ElementAt(index)));
nsCOMPtr<nsIDOMNode> parentNode;
domNode->GetParentNode(getter_AddRefs(parentNode));
nsCOMPtr<nsILink> link(do_QueryInterface(parentNode));
if (link)
(*aLinks)++;
}
return NS_OK;
}
/* nsIAccessibleHyperLink getLink (in long index); */
NS_IMETHODIMP nsAccessibleHyperText::GetLink(PRInt32 aIndex, nsIAccessibleHyperLink **aLink)
{
PRUint32 index, count, linkCount = 0;
mTextChildren->Count(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mTextChildren->ElementAt(index)));
nsCOMPtr<nsIDOMNode> parentNode;
// text node maybe a child of a link node
domNode->GetParentNode(getter_AddRefs(parentNode));
nsCOMPtr<nsILink> link(do_QueryInterface(parentNode));
if (link) {
if (linkCount++ == aIndex) {
nsCOMPtr<nsIWeakReference> weakShell;
nsAccessibilityService::GetShellFromNode(parentNode, getter_AddRefs(weakShell));
NS_ENSURE_TRUE(weakShell, NS_ERROR_FAILURE);
*aLink = new nsHTMLLinkAccessible(parentNode, weakShell);
NS_IF_ADDREF(*aLink);
break;
}
}
}
return NS_OK;
}
/* long getLinkIndex (in long charIndex); */
NS_IMETHODIMP nsAccessibleHyperText::GetLinkIndex(PRInt32 aCharIndex, PRInt32 *aLinkIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* long getSelectedLinkIndex (); */
NS_IMETHODIMP nsAccessibleHyperText::GetSelectedLinkIndex(PRInt32 *aSelectedLinkIndex)
{
*aSelectedLinkIndex = -1;
nsCOMPtr<nsIDOMNode> focusedNode;
NS_REINTERPRET_CAST(nsAccessible*, this)->GetFocusedNode(getter_AddRefs(focusedNode));
PRUint32 index, count, linkCount = 0;
mTextChildren->Count(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mTextChildren->ElementAt(index)));
nsCOMPtr<nsIDOMNode> parentNode;
// text node maybe a child of a link node
domNode->GetParentNode(getter_AddRefs(parentNode));
nsCOMPtr<nsILink> link(do_QueryInterface(parentNode));
if (link) {
linkCount++;
if (parentNode == focusedNode) {
*aSelectedLinkIndex = linkCount;
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
#endif //MOZ_ACCESSIBILITY_ATK

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

@ -46,9 +46,11 @@
#ifdef MOZ_ACCESSIBILITY_ATK
class nsAccessibleHyperText : public nsIAccessibleText
class nsAccessibleHyperText : public nsIAccessibleHyperText,
public nsIAccessibleText
{
NS_DECL_ISUPPORTS
NS_DECL_NSIACCESSIBLEHYPERTEXT
NS_DECL_NSIACCESSIBLETEXT
public:

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

@ -46,7 +46,7 @@
#include "nsReadableUtils.h"
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLIFrameRootAccessible, nsRootAccessible);
NS_IMPL_ISUPPORTS_INHERITED3(nsHTMLIFrameAccessible, nsBlockAccessible, nsIAccessibleDocument, nsIAccessibleHyperText, nsIAccessibleEventReceiver)
NS_IMPL_ISUPPORTS_INHERITED2(nsHTMLIFrameAccessible, nsBlockAccessible, nsIAccessibleDocument, nsIAccessibleEventReceiver)
nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *aDoc):
nsBlockAccessible(aNode, aShell), nsDocAccessibleMixin(aDoc), mRootAccessible(aRoot)
@ -137,219 +137,6 @@ NS_IMETHODIMP nsHTMLIFrameAccessible::GetCaretAccessible(nsIAccessibleCaret **aC
return NS_OK;
}
// ------- nsIAccessibleHyperText ---------------
/* readonly attribute long links; */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetLinks(PRInt32 *aLinks)
{
*aLinks = GetLinksFromAccNode(this);
return NS_OK;
}
/* nsIAccessibleHyperLink getLink (in long index); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetLink(PRInt32 aIndex,
nsIAccessibleHyperLink **aLink)
{
return GetLinkFromAccNode(aIndex, this, aLink);
}
/* long getLinkIndex (in long charIndex); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetLinkIndex(PRInt32 aCharIndex,
PRInt32 *aLinkIndex)
{
return GetLinkIndexFromAccNode(this, aCharIndex, aLinkIndex);
}
/* long getSelectedLinkIndex (); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetSelectedLinkIndex(PRInt32 *aSelectedLinkIndex)
{
*aSelectedLinkIndex = -1;
nsCOMPtr<nsIDOMNode> focusedNode;
GetFocusedNode(getter_AddRefs(focusedNode));
PRInt32 index, links = GetLinksFromAccNode(this);
for (index = 0; index < links; index++) {
nsCOMPtr<nsIAccessibleHyperLink> hyperLink;
GetLink(index, getter_AddRefs(hyperLink));
nsCOMPtr<nsIAccessible> acc(do_QueryInterface(hyperLink));
if (acc) {
nsCOMPtr<nsIDOMNode> linkNode;
acc->AccGetDOMNode(getter_AddRefs(linkNode));
if (focusedNode == linkNode) {
*aSelectedLinkIndex = index;
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
//helper function for nsIAccessibleHyperText
PRBool nsHTMLIFrameAccessible::IsHyperLink(nsIAccessible *aAccNode)
{
nsCOMPtr<nsIAccessibleHyperLink> hyperlink(do_QueryInterface(aAccNode));
return hyperlink? PR_TRUE: PR_FALSE;
}
PRInt32 nsHTMLIFrameAccessible::GetLinksFromAccNode(nsIAccessible *aAccNode)
{
PRInt32 rv = IsHyperLink(aAccNode) ? 1 : 0;
// Here, all the links of accChild should be summed up
nsCOMPtr<nsIAccessible> childa;
nsCOMPtr<nsIAccessible> child;
aAccNode->GetAccFirstChild(getter_AddRefs(child));
while (child) {
rv += GetLinksFromAccNode(child);
child->GetAccNextSibling(getter_AddRefs(childa));
child = childa;
}
//end for summing up accChildren's links
return rv;
}
nsresult nsHTMLIFrameAccessible::GetLinkFromAccNode(PRInt32 aIndex,
nsIAccessible *aAccNode,
nsIAccessibleHyperLink **_retval)
{
PRInt32 links;
//firstly, to see whether beginning node is a hyperlink
links = 0;
if (aIndex < 0) {
//of course, the aIndex is not right.
*_retval = nsnull;
return NS_ERROR_INVALID_ARG;
}
if (IsHyperLink(aAccNode)) {
links = 1;
if (0 == aIndex) {
return CallQueryInterface(aAccNode, _retval);
}
}
//navigate all accChildren to getLink for the aIndex
nsCOMPtr<nsIAccessible> child;
nsCOMPtr<nsIAccessible> childa;
aIndex = aIndex - links;
aAccNode->GetAccFirstChild(getter_AddRefs(child));
while (child) {
links = GetLinksFromAccNode(child);
if (aIndex < links) {
return GetLinkFromAccNode(aIndex, child, _retval);
}
aIndex -= links;
child->GetAccNextSibling(getter_AddRefs(childa));
child = childa;
}
//end of navigate accChild
*_retval = nsnull;
return NS_ERROR_INVALID_ARG;
}
PRInt32 nsHTMLIFrameAccessible::GetAccNodeCharLength(nsIAccessible *aAccNode)
{
PRUint32 role;
PRInt32 childCharLength;
nsAutoString tempAccName;
PRInt32 rv = 0;
role = ROLE_NOTHING;
aAccNode->GetAccRole(&role);
//ROLE_TEXT
if (ROLE_TEXT == role) {
aAccNode->GetAccName(tempAccName);
rv = tempAccName.Length();
}
//sum up the number all accChildren's characters
nsCOMPtr<nsIAccessible> childa;
nsCOMPtr<nsIAccessible> child;
aAccNode->GetAccFirstChild(getter_AddRefs(child));
while (child) {
childCharLength = GetAccNodeCharLength(child);
rv += childCharLength;
child->GetAccNextSibling(getter_AddRefs(childa));
child = childa;
}
return rv;
}
// *_retval is zero-based index, so -1 for no index.
// be careful, charIndex is zero-index, but length is not.
nsresult nsHTMLIFrameAccessible::GetLinkIndexFromAccNode(nsIAccessible *aAccNode,
PRInt32 aCharIndex,
PRInt32 *_retval)
{
nsresult rv;
PRUint32 role;
nsAutoString tempAccName;
PRInt32 charLength;
PRInt32 links;
*_retval = -1;
links = 0;
charLength = 0;
role = ROLE_NOTHING;
aAccNode->GetAccRole(&role);
// if the beginning node is hyperlink
if (IsHyperLink(aAccNode)) {
charLength = GetAccNodeCharLength(aAccNode);
if (aCharIndex < charLength) {
*_retval = 0;
return NS_OK;
}
*_retval = -1;
return NS_OK;
}
//begin to count char length
if (ROLE_TEXT == role) {
aAccNode->GetAccName(tempAccName);
charLength = tempAccName.Length();
if (aCharIndex < charLength) {
*_retval = -1;
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
if (IsHyperLink(aAccNode)) {
links = 1;
}
//exam the beginning node end
//getLinkIndex from accChildren
nsCOMPtr<nsIAccessible> childa;
nsCOMPtr<nsIAccessible> child;
PRInt32 childCharLength;
PRInt32 childLinks;
aAccNode->GetAccFirstChild(getter_AddRefs(child));
while (child) {
childCharLength = GetAccNodeCharLength(child);
if (aCharIndex < charLength + childCharLength) {
rv = GetLinkIndexFromAccNode(child, aCharIndex - charLength, _retval);
*_retval += links;
return rv;
}
charLength += childCharLength;
childLinks = GetLinksFromAccNode(child);
links += childLinks;
child->GetAccNextSibling(getter_AddRefs(childa));
child = childa;
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP nsHTMLIFrameAccessible::AddAccessibleEventListener(nsIAccessibleEventListener *aListener)
{
nsCOMPtr<nsIAccessibleEventReceiver> rootReceiver(do_QueryInterface(mRootAccessible));

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

@ -43,7 +43,6 @@
#include "nsRootAccessible.h"
#include "nsAccessible.h"
#include "nsIAccessibleDocument.h"
#include "nsIAccessibleHyperText.h"
#include "nsIAccessibleEventReceiver.h"
class nsIWebShell;
@ -51,13 +50,11 @@ class nsIWeakReference;
class nsHTMLIFrameAccessible : public nsBlockAccessible,
public nsIAccessibleDocument,
public nsIAccessibleHyperText,
public nsIAccessibleEventReceiver,
public nsDocAccessibleMixin
{
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEDOCUMENT
NS_DECL_NSIACCESSIBLEHYPERTEXT
public:
nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *doc);
@ -76,16 +73,6 @@ class nsHTMLIFrameAccessible : public nsBlockAccessible,
protected:
nsCOMPtr<nsIAccessible> mRootAccessible;
//helper function for nsIAccessibleHyperText
PRBool IsHyperLink(nsIAccessible *aAccNode);
PRInt32 GetLinksFromAccNode(nsIAccessible *aAccNode);
nsresult GetLinkFromAccNode(PRInt32 aIndex, nsIAccessible *aAccNode,
nsIAccessibleHyperLink **_retval);
PRInt32 GetAccNodeCharLength(nsIAccessible *aAccNode);
nsresult GetLinkIndexFromAccNode(nsIAccessible *aAccNode,
PRInt32 aCharIndex, PRInt32 *_retval);
};
class nsHTMLIFrameRootAccessible : public nsRootAccessible