From 2cddb7e586affb4ca779df073857591993e2366c Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Tue, 25 Sep 2001 22:32:32 +0000 Subject: [PATCH] Bug 98781. Active Accessibility: XUL element support. sr=hyatt, r=jgaunt --- accessible/public/nsIAccessibilityService.idl | 1 + .../src/base/nsAccessibilityService.cpp | 26 ++++++---- accessible/src/base/nsAccessible.cpp | 51 +++++++++++++++---- accessible/src/base/nsAccessible.h | 2 + accessible/src/html/nsHTMLImageAccessible.cpp | 2 +- accessible/src/html/nsHTMLImageAccessible.h | 2 +- accessible/src/nsAccessibilityService.cpp | 26 ++++++---- accessible/src/nsAccessible.cpp | 51 +++++++++++++++---- accessible/src/nsAccessible.h | 2 + accessible/src/nsHTMLImageAccessible.cpp | 2 +- accessible/src/nsHTMLImageAccessible.h | 2 +- dom/public/idl/xul/Makefile.in | 1 + dom/public/idl/xul/makefile.win | 1 + .../resources/content/bindings/general.xml | 16 ++++++ xpfe/global/resources/content/xul.css | 6 +++ 15 files changed, 149 insertions(+), 42 deletions(-) diff --git a/accessible/public/nsIAccessibilityService.idl b/accessible/public/nsIAccessibilityService.idl index 45d7e0306289..71775058be86 100644 --- a/accessible/public/nsIAccessibilityService.idl +++ b/accessible/public/nsIAccessibilityService.idl @@ -43,6 +43,7 @@ interface nsIAccessibilityService : nsISupports nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame); nsIAccessible createHTML4ButtonAccessible(in nsISupports aFrame); nsIAccessible createHTMLTextAccessible(in nsISupports aFrame); + nsIAccessible createXULImageAccessible(in nsIDOMNode aNode); nsIAccessible createHTMLImageAccessible(in nsISupports aFrame); nsIAccessible createHTMLAreaAccessible(in nsIWeakReference aPresShell, in nsIDOMNode aDOMNode, in nsIAccessible aAccParent); nsIAccessible createHTMLTableAccessible(in nsISupports aFrame); diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index bc88cfc1b003..62641508e937 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -315,6 +315,19 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTableCellAccessible(nsISupports return NS_OK; } +NS_IMETHODIMP nsAccessibilityService::CreateXULImageAccessible(nsIDOMNode *aNode, nsIAccessible **_retval) +{ + nsCOMPtr weakShell; + GetShellFromNode(aNode, getter_AddRefs(weakShell)); + + *_retval = new nsHTMLImageAccessible(aNode, weakShell); + if (! *_retval) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*_retval); + return NS_OK; +} + /* nsIAccessible createHTMLImageAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ NS_IMETHODIMP nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFrame, nsIAccessible **_retval) { @@ -324,15 +337,8 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFr nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node)); if (NS_FAILED(rv)) return rv; - nsIImageFrame* imageFrame = nsnull; - - // not using a nsCOMPtr frames don't support them. - aFrame->QueryInterface(NS_GET_IID(nsIImageFrame), (void**)&imageFrame); - if (!imageFrame) - return NS_ERROR_FAILURE; - - *_retval = new nsHTMLImageAccessible(node, imageFrame, weakShell); + *_retval = new nsHTMLImageAccessible(node, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -400,6 +406,8 @@ NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aR nsCOMPtr content; (*aRealFrame)->GetContent(getter_AddRefs(content)); nsCOMPtr node(do_QueryInterface(content)); + if (!content || !node) + return NS_ERROR_FAILURE; *aNode = node; NS_IF_ADDREF(*aNode); diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index db1d5cdd2198..0a1112db76b0 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -66,6 +66,7 @@ #include "nsIDOMHTMLImageElement.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLBRElement.h" +#include "nsIDOMXULElement.h" #include "nsIAtom.h" #include "nsHTMLAtoms.h" #include "nsLayoutAtoms.h" @@ -1330,11 +1331,42 @@ NS_IMETHODIMP nsAccessible::AccTakeFocus() return NS_OK; } +NS_IMETHODIMP nsAccessible::AppendStringWithSpaces(nsAWritableString *aFlatString, nsAReadableString& textEquivalent) +{ + // Insert spaces to insure that words from controls aren't jammed together + if (!textEquivalent.IsEmpty()) { + aFlatString->Append(NS_LITERAL_STRING(" ")); + aFlatString->Append(textEquivalent); + aFlatString->Append(NS_LITERAL_STRING(" ")); + } + return NS_OK; +} + +/* + * AppendFlatStringFromContentNode and AppendFlatStringFromSubtree + * + * This method will glean useful text, in whatever form it exists, from any content node given to it. + * It is used by any decendant of nsAccessible that needs to get text from a single node, as + * well as by nsAccessible::AppendFlatStringFromSubtree, which gleans and concatenates text from any node and + * that node's decendants. + */ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString) { + nsAutoString textEquivalent; + nsCOMPtr xulElement(do_QueryInterface(aContent)); + if (xulElement) { + nsCOMPtr elt(do_QueryInterface(aContent)); + NS_ASSERTION(elt, "No DOM element for content node!"); + elt->GetAttribute(NS_LITERAL_STRING("value"), textEquivalent); // Prefer value over tooltiptext + if (textEquivalent.IsEmpty()) + elt->GetAttribute(NS_LITERAL_STRING("tooltiptext"), textEquivalent); + return AppendStringWithSpaces(aFlatString, textEquivalent); + } + nsCOMPtr textContent(do_QueryInterface(aContent)); - if (textContent) { + if (textContent) { + // If it's a text node, but node a comment node, append the text nsCOMPtr commentNode(do_QueryInterface(aContent)); if (!commentNode) { PRBool isHTMLBlock = PR_FALSE; @@ -1372,17 +1404,20 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent } return NS_OK; } + nsCOMPtr brElement(do_QueryInterface(aContent)); - if (brElement) { + if (brElement) { // If it's a line break, insert a space so that words aren't jammed together aFlatString->Append(NS_LITERAL_STRING(" ")); return NS_OK; } nsCOMPtr imageContent(do_QueryInterface(aContent)); - nsCOMPtr inputContent(do_QueryInterface(aContent)); + nsCOMPtr inputContent; + if (!imageContent) + inputContent = do_QueryInterface(aContent); if (imageContent || inputContent) { nsCOMPtr elt(do_QueryInterface(aContent)); - nsAutoString textEquivalent; + NS_ASSERTION(elt, "No DOM element for content node!"); elt->GetAttribute(NS_LITERAL_STRING("alt"), textEquivalent); if (textEquivalent.IsEmpty()) elt->GetAttribute(NS_LITERAL_STRING("title"), textEquivalent); @@ -1390,13 +1425,9 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent elt->GetAttribute(NS_LITERAL_STRING("name"), textEquivalent); if (textEquivalent.IsEmpty()) elt->GetAttribute(NS_LITERAL_STRING("src"), textEquivalent); - if (!textEquivalent.IsEmpty()) { - aFlatString->Append(NS_LITERAL_STRING(" ")); - aFlatString->Append(textEquivalent); - aFlatString->Append(NS_LITERAL_STRING(" ")); - return NS_OK; - } + return AppendStringWithSpaces(aFlatString, textEquivalent); } + return NS_OK; } diff --git a/accessible/src/base/nsAccessible.h b/accessible/src/base/nsAccessible.h index 669a7c4afca9..a71e1998ec0e 100644 --- a/accessible/src/base/nsAccessible.h +++ b/accessible/src/base/nsAccessible.h @@ -120,6 +120,8 @@ protected: virtual void GetPresContext(nsCOMPtr& aContext); NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString); NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString); + NS_IMETHOD AppendStringWithSpaces(nsAWritableString *aFlatString, nsAReadableString& textEquivalent); + // Data Members nsCOMPtr mDOMNode; diff --git a/accessible/src/html/nsHTMLImageAccessible.cpp b/accessible/src/html/nsHTMLImageAccessible.cpp index 5135a1439fa9..39540874f0b8 100644 --- a/accessible/src/html/nsHTMLImageAccessible.cpp +++ b/accessible/src/html/nsHTMLImageAccessible.cpp @@ -52,7 +52,7 @@ // --- image ----- -nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame, nsIWeakReference* aShell): +nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): nsLinkableAccessible(aDOMNode, aShell) { nsCOMPtr element(do_QueryInterface(aDOMNode)); diff --git a/accessible/src/html/nsHTMLImageAccessible.h b/accessible/src/html/nsHTMLImageAccessible.h index d67a554e1a32..b00ce5032c94 100644 --- a/accessible/src/html/nsHTMLImageAccessible.h +++ b/accessible/src/html/nsHTMLImageAccessible.h @@ -54,7 +54,7 @@ class nsHTMLImageAccessible : public nsLinkableAccessible { public: - nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIImageFrame *imageFrame, nsIWeakReference* aShell); + nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); NS_IMETHOD GetAccName(nsAWritableString& _retval); NS_IMETHOD GetAccState(PRUint32 *_retval); NS_IMETHOD GetAccRole(PRUint32 *_retval); diff --git a/accessible/src/nsAccessibilityService.cpp b/accessible/src/nsAccessibilityService.cpp index bc88cfc1b003..62641508e937 100644 --- a/accessible/src/nsAccessibilityService.cpp +++ b/accessible/src/nsAccessibilityService.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -315,6 +315,19 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTableCellAccessible(nsISupports return NS_OK; } +NS_IMETHODIMP nsAccessibilityService::CreateXULImageAccessible(nsIDOMNode *aNode, nsIAccessible **_retval) +{ + nsCOMPtr weakShell; + GetShellFromNode(aNode, getter_AddRefs(weakShell)); + + *_retval = new nsHTMLImageAccessible(aNode, weakShell); + if (! *_retval) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*_retval); + return NS_OK; +} + /* nsIAccessible createHTMLImageAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ NS_IMETHODIMP nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFrame, nsIAccessible **_retval) { @@ -324,15 +337,8 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFr nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node)); if (NS_FAILED(rv)) return rv; - nsIImageFrame* imageFrame = nsnull; - - // not using a nsCOMPtr frames don't support them. - aFrame->QueryInterface(NS_GET_IID(nsIImageFrame), (void**)&imageFrame); - if (!imageFrame) - return NS_ERROR_FAILURE; - - *_retval = new nsHTMLImageAccessible(node, imageFrame, weakShell); + *_retval = new nsHTMLImageAccessible(node, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -400,6 +406,8 @@ NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aR nsCOMPtr content; (*aRealFrame)->GetContent(getter_AddRefs(content)); nsCOMPtr node(do_QueryInterface(content)); + if (!content || !node) + return NS_ERROR_FAILURE; *aNode = node; NS_IF_ADDREF(*aNode); diff --git a/accessible/src/nsAccessible.cpp b/accessible/src/nsAccessible.cpp index db1d5cdd2198..0a1112db76b0 100644 --- a/accessible/src/nsAccessible.cpp +++ b/accessible/src/nsAccessible.cpp @@ -66,6 +66,7 @@ #include "nsIDOMHTMLImageElement.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLBRElement.h" +#include "nsIDOMXULElement.h" #include "nsIAtom.h" #include "nsHTMLAtoms.h" #include "nsLayoutAtoms.h" @@ -1330,11 +1331,42 @@ NS_IMETHODIMP nsAccessible::AccTakeFocus() return NS_OK; } +NS_IMETHODIMP nsAccessible::AppendStringWithSpaces(nsAWritableString *aFlatString, nsAReadableString& textEquivalent) +{ + // Insert spaces to insure that words from controls aren't jammed together + if (!textEquivalent.IsEmpty()) { + aFlatString->Append(NS_LITERAL_STRING(" ")); + aFlatString->Append(textEquivalent); + aFlatString->Append(NS_LITERAL_STRING(" ")); + } + return NS_OK; +} + +/* + * AppendFlatStringFromContentNode and AppendFlatStringFromSubtree + * + * This method will glean useful text, in whatever form it exists, from any content node given to it. + * It is used by any decendant of nsAccessible that needs to get text from a single node, as + * well as by nsAccessible::AppendFlatStringFromSubtree, which gleans and concatenates text from any node and + * that node's decendants. + */ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString) { + nsAutoString textEquivalent; + nsCOMPtr xulElement(do_QueryInterface(aContent)); + if (xulElement) { + nsCOMPtr elt(do_QueryInterface(aContent)); + NS_ASSERTION(elt, "No DOM element for content node!"); + elt->GetAttribute(NS_LITERAL_STRING("value"), textEquivalent); // Prefer value over tooltiptext + if (textEquivalent.IsEmpty()) + elt->GetAttribute(NS_LITERAL_STRING("tooltiptext"), textEquivalent); + return AppendStringWithSpaces(aFlatString, textEquivalent); + } + nsCOMPtr textContent(do_QueryInterface(aContent)); - if (textContent) { + if (textContent) { + // If it's a text node, but node a comment node, append the text nsCOMPtr commentNode(do_QueryInterface(aContent)); if (!commentNode) { PRBool isHTMLBlock = PR_FALSE; @@ -1372,17 +1404,20 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent } return NS_OK; } + nsCOMPtr brElement(do_QueryInterface(aContent)); - if (brElement) { + if (brElement) { // If it's a line break, insert a space so that words aren't jammed together aFlatString->Append(NS_LITERAL_STRING(" ")); return NS_OK; } nsCOMPtr imageContent(do_QueryInterface(aContent)); - nsCOMPtr inputContent(do_QueryInterface(aContent)); + nsCOMPtr inputContent; + if (!imageContent) + inputContent = do_QueryInterface(aContent); if (imageContent || inputContent) { nsCOMPtr elt(do_QueryInterface(aContent)); - nsAutoString textEquivalent; + NS_ASSERTION(elt, "No DOM element for content node!"); elt->GetAttribute(NS_LITERAL_STRING("alt"), textEquivalent); if (textEquivalent.IsEmpty()) elt->GetAttribute(NS_LITERAL_STRING("title"), textEquivalent); @@ -1390,13 +1425,9 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent elt->GetAttribute(NS_LITERAL_STRING("name"), textEquivalent); if (textEquivalent.IsEmpty()) elt->GetAttribute(NS_LITERAL_STRING("src"), textEquivalent); - if (!textEquivalent.IsEmpty()) { - aFlatString->Append(NS_LITERAL_STRING(" ")); - aFlatString->Append(textEquivalent); - aFlatString->Append(NS_LITERAL_STRING(" ")); - return NS_OK; - } + return AppendStringWithSpaces(aFlatString, textEquivalent); } + return NS_OK; } diff --git a/accessible/src/nsAccessible.h b/accessible/src/nsAccessible.h index 669a7c4afca9..a71e1998ec0e 100644 --- a/accessible/src/nsAccessible.h +++ b/accessible/src/nsAccessible.h @@ -120,6 +120,8 @@ protected: virtual void GetPresContext(nsCOMPtr& aContext); NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString); NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString); + NS_IMETHOD AppendStringWithSpaces(nsAWritableString *aFlatString, nsAReadableString& textEquivalent); + // Data Members nsCOMPtr mDOMNode; diff --git a/accessible/src/nsHTMLImageAccessible.cpp b/accessible/src/nsHTMLImageAccessible.cpp index 5135a1439fa9..39540874f0b8 100644 --- a/accessible/src/nsHTMLImageAccessible.cpp +++ b/accessible/src/nsHTMLImageAccessible.cpp @@ -52,7 +52,7 @@ // --- image ----- -nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame, nsIWeakReference* aShell): +nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): nsLinkableAccessible(aDOMNode, aShell) { nsCOMPtr element(do_QueryInterface(aDOMNode)); diff --git a/accessible/src/nsHTMLImageAccessible.h b/accessible/src/nsHTMLImageAccessible.h index d67a554e1a32..b00ce5032c94 100644 --- a/accessible/src/nsHTMLImageAccessible.h +++ b/accessible/src/nsHTMLImageAccessible.h @@ -54,7 +54,7 @@ class nsHTMLImageAccessible : public nsLinkableAccessible { public: - nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIImageFrame *imageFrame, nsIWeakReference* aShell); + nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); NS_IMETHOD GetAccName(nsAWritableString& _retval); NS_IMETHOD GetAccState(PRUint32 *_retval); NS_IMETHOD GetAccRole(PRUint32 *_retval); diff --git a/dom/public/idl/xul/Makefile.in b/dom/public/idl/xul/Makefile.in index bdd88ee38b57..29e4203029d3 100644 --- a/dom/public/idl/xul/Makefile.in +++ b/dom/public/idl/xul/Makefile.in @@ -37,6 +37,7 @@ XPIDLSRCS = \ nsIDOMXULControlElement.idl \ nsIDOMXULLabeledControlEl.idl \ nsIDOMXULCheckboxElement.idl \ + nsIDOMXULImageElement.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/public/idl/xul/makefile.win b/dom/public/idl/xul/makefile.win index 21cbe82ae9ea..08a69f131299 100644 --- a/dom/public/idl/xul/makefile.win +++ b/dom/public/idl/xul/makefile.win @@ -33,6 +33,7 @@ XPIDLSRCS = \ .\nsIDOMXULControlElement.idl \ .\nsIDOMXULLabeledControlEl.idl \ .\nsIDOMXULCheckboxElement.idl \ + .\nsIDOMXULImageElement.idl \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/xpfe/global/resources/content/bindings/general.xml b/xpfe/global/resources/content/bindings/general.xml index 1fd192ce119a..1943922cccde 100644 --- a/xpfe/global/resources/content/bindings/general.xml +++ b/xpfe/global/resources/content/bindings/general.xml @@ -225,5 +225,21 @@ + + + + + + + + + + + diff --git a/xpfe/global/resources/content/xul.css b/xpfe/global/resources/content/xul.css index 75a47847548f..8e2af2293f50 100644 --- a/xpfe/global/resources/content/xul.css +++ b/xpfe/global/resources/content/xul.css @@ -136,6 +136,12 @@ iframe { -moz-binding: url("chrome://global/content/bindings/general.xml#iframe"); } +/********** image **********/ + +image { + -moz-binding: url("chrome://global/content/bindings/general.xml#image"); +} + /********** checkbox **********/ checkbox {