Bug 98781. Active Accessibility: XUL <image> element support. sr=hyatt, r=jgaunt

This commit is contained in:
aaronl%netscape.com 2001-09-25 22:32:32 +00:00
Родитель 913685a2fb
Коммит 2cddb7e586
15 изменённых файлов: 149 добавлений и 42 удалений

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

@ -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);

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

@ -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<nsIWeakReference> 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<nsIContent> content;
(*aRealFrame)->GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
if (!content || !node)
return NS_ERROR_FAILURE;
*aNode = node;
NS_IF_ADDREF(*aNode);

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

@ -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<nsIDOMXULElement> xulElement(do_QueryInterface(aContent));
if (xulElement) {
nsCOMPtr<nsIDOMElement> 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<nsITextContent> textContent(do_QueryInterface(aContent));
if (textContent) {
if (textContent) {
// If it's a text node, but node a comment node, append the text
nsCOMPtr<nsIDOMComment> commentNode(do_QueryInterface(aContent));
if (!commentNode) {
PRBool isHTMLBlock = PR_FALSE;
@ -1372,17 +1404,20 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent
}
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLBRElement> 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<nsIDOMHTMLImageElement> imageContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent;
if (!imageContent)
inputContent = do_QueryInterface(aContent);
if (imageContent || inputContent) {
nsCOMPtr<nsIDOMElement> 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;
}

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

@ -120,6 +120,8 @@ protected:
virtual void GetPresContext(nsCOMPtr<nsIPresContext>& 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<nsIDOMNode> mDOMNode;

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

@ -52,7 +52,7 @@
// --- image -----
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame, nsIWeakReference* aShell):
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsLinkableAccessible(aDOMNode, aShell)
{
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));

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

@ -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);

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

@ -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<nsIWeakReference> 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<nsIContent> content;
(*aRealFrame)->GetContent(getter_AddRefs(content));
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
if (!content || !node)
return NS_ERROR_FAILURE;
*aNode = node;
NS_IF_ADDREF(*aNode);

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

@ -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<nsIDOMXULElement> xulElement(do_QueryInterface(aContent));
if (xulElement) {
nsCOMPtr<nsIDOMElement> 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<nsITextContent> textContent(do_QueryInterface(aContent));
if (textContent) {
if (textContent) {
// If it's a text node, but node a comment node, append the text
nsCOMPtr<nsIDOMComment> commentNode(do_QueryInterface(aContent));
if (!commentNode) {
PRBool isHTMLBlock = PR_FALSE;
@ -1372,17 +1404,20 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent
}
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLBRElement> 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<nsIDOMHTMLImageElement> imageContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent;
if (!imageContent)
inputContent = do_QueryInterface(aContent);
if (imageContent || inputContent) {
nsCOMPtr<nsIDOMElement> 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;
}

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

@ -120,6 +120,8 @@ protected:
virtual void GetPresContext(nsCOMPtr<nsIPresContext>& 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<nsIDOMNode> mDOMNode;

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

@ -52,7 +52,7 @@
// --- image -----
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame, nsIWeakReference* aShell):
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsLinkableAccessible(aDOMNode, aShell)
{
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));

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

@ -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);

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

@ -37,6 +37,7 @@ XPIDLSRCS = \
nsIDOMXULControlElement.idl \
nsIDOMXULLabeledControlEl.idl \
nsIDOMXULCheckboxElement.idl \
nsIDOMXULImageElement.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -33,6 +33,7 @@ XPIDLSRCS = \
.\nsIDOMXULControlElement.idl \
.\nsIDOMXULLabeledControlEl.idl \
.\nsIDOMXULCheckboxElement.idl \
.\nsIDOMXULImageElement.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -225,5 +225,21 @@
</implementation>
</binding>
<binding id="image">
<implementation implements="nsIDOMXULImageElement, nsIAccessibleProvider">
<property name="src"
onget="return this.getAttribute('src');"
onset="this.setAttribute('src',val); return val;"/>
<property name="accessible">
<getter>
<![CDATA[
var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
return (accService? accService.createXULImageAccessible(this): null);
]]>
</getter>
</property>
</implementation>
</binding>
</bindings>

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

@ -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 {