Updated accesibility code. NOT IN BUILD PROCCESS
This commit is contained in:
Родитель
ba6e36a8bf
Коммит
96649a1b66
|
@ -1,2 +1,3 @@
|
|||
nsIAccessibilityService.idl
|
||||
|
||||
nsIAccessible.idl
|
||||
nsIMutableAccessible.idl
|
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = accessibility
|
||||
XPIDL_MODULE= accessibility
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIAccessibilityService.idl \
|
||||
nsIAccessible.idl \
|
||||
nsIMutableAccessible.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -26,6 +26,7 @@ XPIDL_MODULE=accessibility
|
|||
XPIDLSRCS = \
|
||||
.\nsIAccessibilityService.idl \
|
||||
.\nsIAccessible.idl \
|
||||
.\nsIMutableAccessible.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -23,13 +23,15 @@
|
|||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
//#include "domstubs.idl"
|
||||
#include "nsIAccessible.idl"
|
||||
#include "domstubs.idl"
|
||||
#include "nsIMutableAccessible.idl"
|
||||
|
||||
[scriptable, uuid(68D9720A-0984-42b6-A3F5-8237ED925727)]
|
||||
interface nsIAccessibilityService : nsISupports
|
||||
{
|
||||
nsIAccessible getAccessibleFor(in nsISupports frame, in nsISupports presShell);
|
||||
nsIAccessible createRootAccessible(in nsISupports aPresShell);
|
||||
nsIAccessible createHTMLBlockAccessible(in nsIAccessible aAccessible, in nsIDOMNode aNode, in nsISupports aPresShell);
|
||||
nsIMutableAccessible createMutableAccessible(in nsIDOMNode aNode);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = accessibility
|
||||
LIBRARY_NAME = accessibility_s
|
||||
REQUIRES = xpcom rdf layout necko dom intl locale widget js appshell chrome caps pref profile
|
||||
|
||||
CPPSRCS = \
|
||||
nsAccessible.cpp \
|
||||
nsAccessibilityService.cpp \
|
||||
nsMutableAccessible.cpp \
|
||||
nsRootAccessible.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -31,6 +31,9 @@
|
|||
#include "nsIPresContext.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsRootAccessible.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsMutableAccessible.h"
|
||||
|
||||
nsAccessibilityService::nsAccessibilityService()
|
||||
{
|
||||
|
@ -43,22 +46,224 @@ nsAccessibilityService::~nsAccessibilityService()
|
|||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAccessibilityService, nsIAccessibilityService);
|
||||
|
||||
|
||||
/*
|
||||
class nsHTMLTextAccessible : public nsIAccessible
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIACCESSIBLE
|
||||
|
||||
nsHTMLTextAccessible(nsIDOMNode* aNode);
|
||||
|
||||
virtual ~nsHTMLTextAccessible();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> mNode;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsHTMLTextAccessible, nsIAccessible)
|
||||
|
||||
nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aNode)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mNode = aNode;
|
||||
}
|
||||
|
||||
nsHTMLTextAccessible::~nsHTMLTextAccessible()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccParent(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccNextSibling(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccFirstChild(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccLastChild(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccChildCount(PRInt32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(PRUnichar **_retval)
|
||||
{
|
||||
if (mNode) {
|
||||
nsAutoString value;
|
||||
mNode->GetNodeValue(value);
|
||||
*_retval = value.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccValue(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::SetAccName(const PRUnichar *name)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::SetAccValue(const PRUnichar *value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccDescription(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccRole(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccState(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccDefaultAction(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccHelp(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccFocused(PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateRight(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateLeft(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateUp(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateDown(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccAddSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccRemoveSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccExtendSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccTakeSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccTakeFocus()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccDoDefaultAction()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIAccessibilityService methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessibilityService::GetAccessibleFor(nsISupports* frame, nsISupports* context, nsIAccessible **_retval)
|
||||
nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsIAccessible **_retval)
|
||||
{
|
||||
void* ptr = nsnull;
|
||||
frame->QueryInterface(nsIFrame::GetIID(), &ptr);
|
||||
nsIFrame* f = (nsIFrame*)ptr;
|
||||
|
||||
nsCOMPtr<nsIPresContext> c = do_QueryInterface(context);
|
||||
|
||||
NS_ASSERTION(f,"Error non frame passed to accessible factory!!!");
|
||||
nsCOMPtr<nsIPresContext> c = do_QueryInterface(aPresContext);
|
||||
NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!");
|
||||
|
||||
*_retval = new nsAccessible(f,c);
|
||||
nsCOMPtr<nsIPresShell> s;
|
||||
c->GetShell(getter_AddRefs(s));
|
||||
|
||||
NS_ASSERTION(s,"Error not presshell!!");
|
||||
|
||||
*_retval = new nsRootAccessible(s);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessibilityService::CreateMutableAccessible(nsIDOMNode* aNode, nsIMutableAccessible **_retval)
|
||||
{
|
||||
*_retval = new nsMutableAccessible(aNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessibilityService::CreateHTMLBlockAccessible(nsIAccessible* aAccessible, nsIDOMNode* node, nsISupports* aPresContext, nsIAccessible **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIContent> n = do_QueryInterface(node);
|
||||
NS_ASSERTION(n,"Error non nsIContent passed to accessible factory!!!");
|
||||
|
||||
nsCOMPtr<nsIPresContext> c = do_QueryInterface(aPresContext);
|
||||
NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!");
|
||||
|
||||
nsCOMPtr<nsIPresShell> s;
|
||||
c->GetShell(getter_AddRefs(s));
|
||||
|
||||
NS_ASSERTION(s,"Error not presshell!!");
|
||||
|
||||
|
||||
*_retval = new nsHTMLBlockAccessible(aAccessible, n,s);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,13 +28,307 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsRootAccessible.h"
|
||||
|
||||
//#define DEBUG_LEAKS
|
||||
#define DEBUG_LEAKS
|
||||
|
||||
#ifdef DEBUG_LEAKS
|
||||
static gnsAccessibles = 0;
|
||||
#endif
|
||||
|
||||
|
||||
class nsFrameTreeWalker {
|
||||
public:
|
||||
nsFrameTreeWalker(nsIPresContext* aPresContext);
|
||||
nsIFrame* GetNextSibling(nsIFrame* aFrame);
|
||||
nsIFrame* GetPreviousSibling(nsIFrame* aFrame);
|
||||
nsIFrame* GetParent(nsIFrame* aFrame);
|
||||
nsIFrame* GetFirstChild(nsIFrame* aFrame);
|
||||
nsIFrame* GetLastChild(nsIFrame* aFrame);
|
||||
nsIFrame* GetChildBefore(nsIFrame* aParent, nsIFrame* aChild);
|
||||
PRInt32 GetCount(nsIFrame* aFrame);
|
||||
|
||||
static PRBool IsSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
|
||||
static void GetAccessible(nsIFrame* aFrame, nsCOMPtr<nsIAccessible>& aAccessible, nsCOMPtr<nsIContent>& aContent);
|
||||
|
||||
nsCOMPtr<nsIPresContext> mPresContext;
|
||||
nsCOMPtr<nsIAccessible> mAccessible;
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
};
|
||||
|
||||
nsFrameTreeWalker::nsFrameTreeWalker(nsIPresContext* aPresContext)
|
||||
{
|
||||
mPresContext = aPresContext;
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetParent(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get parent\n");
|
||||
|
||||
nsIFrame* parent = nsnull;
|
||||
aFrame->GetParent(&parent);
|
||||
|
||||
// if no parent then we hit the root
|
||||
// just return that top frame
|
||||
if (!parent) {
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return aFrame;
|
||||
}
|
||||
|
||||
GetAccessible(parent, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
return parent;
|
||||
|
||||
return GetParent(parent);
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetNextSibling(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get next\n");
|
||||
|
||||
// get next sibling
|
||||
nsIFrame* next = nsnull;
|
||||
aFrame->GetNextSibling(&next);
|
||||
|
||||
// skip any frames with the same content node
|
||||
while(IsSameContent(aFrame,next))
|
||||
next->GetNextSibling(&next);
|
||||
|
||||
// if failed
|
||||
if (!next)
|
||||
{
|
||||
// if parent has content
|
||||
nsIFrame* parent = nsnull;
|
||||
aFrame->GetParent(&parent);
|
||||
|
||||
// if no parent fail
|
||||
if (!parent) {
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
// fail if we reach a parent that is accessible
|
||||
GetAccessible(parent, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
{
|
||||
// fail
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
} else {
|
||||
// next on parent
|
||||
return GetNextSibling(parent);
|
||||
}
|
||||
}
|
||||
|
||||
// if next has content
|
||||
GetAccessible(next, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
{
|
||||
// done
|
||||
return next;
|
||||
}
|
||||
|
||||
// if next doesn't have node
|
||||
|
||||
// call first on next
|
||||
nsIFrame* first = GetFirstChild(next);
|
||||
|
||||
// if found
|
||||
if (first)
|
||||
return first;
|
||||
|
||||
// call next on next
|
||||
return GetNextSibling(next);
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetFirstChild(nsIFrame* aFrame)
|
||||
{
|
||||
|
||||
//printf("Get first\n");
|
||||
|
||||
// get first child
|
||||
nsIFrame* child = nsnull;
|
||||
aFrame->FirstChild(mPresContext, nsnull, &child);
|
||||
|
||||
while(child)
|
||||
{
|
||||
// if first has a content node
|
||||
GetAccessible(child, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
{
|
||||
// done
|
||||
return child;
|
||||
} else {
|
||||
// call first on child
|
||||
nsIFrame* first = GetFirstChild(child);
|
||||
|
||||
// if succeeded
|
||||
if (first)
|
||||
{
|
||||
// return child
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
||||
// get next sibling
|
||||
nsIFrame* next;
|
||||
child->GetNextSibling(&next);
|
||||
|
||||
// skip children with duplicate content nodes
|
||||
while(IsSameContent(child,next))
|
||||
next->GetNextSibling(&next);
|
||||
|
||||
child = next;
|
||||
}
|
||||
|
||||
// fail
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetChildBefore(nsIFrame* aParent, nsIFrame* aChild)
|
||||
{
|
||||
nsIFrame* child = GetFirstChild(aParent);
|
||||
|
||||
// if the child is not us
|
||||
if (child == aChild) {
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsIFrame* prev = child;
|
||||
nsCOMPtr<nsIContent> prevContent = mContent;
|
||||
nsCOMPtr<nsIAccessible> prevAccessible = mAccessible;
|
||||
|
||||
while(child)
|
||||
{
|
||||
child = GetNextSibling(child);
|
||||
|
||||
if (child == aChild)
|
||||
break;
|
||||
|
||||
prev = child;
|
||||
prevContent = mContent;
|
||||
prevAccessible = mAccessible;
|
||||
}
|
||||
|
||||
mAccessible = prevAccessible;
|
||||
mContent = prevContent;
|
||||
return prev;
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetPreviousSibling(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get previous\n");
|
||||
|
||||
nsIFrame* parent = GetParent(aFrame);
|
||||
|
||||
return GetChildBefore(parent, aFrame);
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetLastChild(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get last\n");
|
||||
|
||||
return GetChildBefore(aFrame, nsnull);
|
||||
}
|
||||
|
||||
PRInt32 nsFrameTreeWalker::GetCount(nsIFrame* aFrame)
|
||||
{
|
||||
|
||||
//printf("Get count\n");
|
||||
nsIFrame* child = GetFirstChild(aFrame);
|
||||
|
||||
PRInt32 count = 0;
|
||||
while(child)
|
||||
{
|
||||
count++;
|
||||
child = GetNextSibling(child);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
nsresult nsFrameTreeWalker::Next()
|
||||
{
|
||||
if (mCurrent == nsnull)
|
||||
return NS_OK;
|
||||
|
||||
nsIFrame* n;
|
||||
nsresult rv = mCurrent->GetNextSibling(&n);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// skip any frames with the same content node
|
||||
while(IsSameContent(mCurrent,n))
|
||||
{
|
||||
rv = n->GetNextSibling(&n);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
mPrev = mCurrent;
|
||||
mCurrent = n;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
void nsFrameTreeWalker::GetAccessible(nsIFrame* aFrame, nsCOMPtr<nsIAccessible>& aAccessible, nsCOMPtr<nsIContent>& aContent)
|
||||
{
|
||||
aContent = nsnull;
|
||||
aAccessible = nsnull;
|
||||
|
||||
aFrame->GetContent(getter_AddRefs(aContent));
|
||||
|
||||
if (!aContent)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
aContent->GetDocument(*getter_AddRefs(document));
|
||||
PRInt32 shells = document->GetNumberOfShells();
|
||||
NS_ASSERTION(shells > 0,"Error no shells!");
|
||||
nsIPresShell* shell = document->GetShellAt(0);
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(aContent, &frame);
|
||||
|
||||
if (!frame)
|
||||
return;
|
||||
|
||||
aAccessible = do_QueryInterface(aFrame);
|
||||
|
||||
if (!aAccessible)
|
||||
aAccessible = do_QueryInterface(aContent);
|
||||
|
||||
// if (aAccessible)
|
||||
// printf("Found accessible!\n");
|
||||
}
|
||||
|
||||
PRBool nsFrameTreeWalker::IsSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
||||
{
|
||||
if (!aFrame1 || !aFrame2)
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIContent> content1;
|
||||
nsCOMPtr<nsIContent> content2;
|
||||
|
||||
aFrame1->GetContent(getter_AddRefs(content1));
|
||||
aFrame2->GetContent(getter_AddRefs(content2));
|
||||
|
||||
if (content1 == content2 && content1 != nsnull)
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class nsAccessible
|
||||
*/
|
||||
|
@ -42,23 +336,14 @@ static gnsAccessibles = 0;
|
|||
//-----------------------------------------------------
|
||||
// construction
|
||||
//-----------------------------------------------------
|
||||
nsAccessible::nsAccessible(nsIFrame* aFrame, nsIPresContext* aContext)
|
||||
nsAccessible::nsAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
// get frame and node
|
||||
mFrame = aFrame;
|
||||
nsCOMPtr<nsIContent> content;
|
||||
aFrame->GetContent(getter_AddRefs(content));
|
||||
mNode = do_QueryInterface(content);
|
||||
mPresContext = aContext;
|
||||
|
||||
// see if the frame implements nsIAccessible
|
||||
mAccessible = do_QueryInterface(aFrame);
|
||||
|
||||
// if not see if its content node supports nsIAccessible
|
||||
if (!mAccessible)
|
||||
mAccessible = do_QueryInterface(content);
|
||||
mContent = aContent;
|
||||
mAccessible = aAccessible;
|
||||
mPresShell = getter_AddRefs(NS_GetWeakReference(aShell));
|
||||
|
||||
#ifdef DEBUG_LEAKS
|
||||
printf("nsAccessibles=%d\n", ++gnsAccessibles);
|
||||
|
@ -76,6 +361,7 @@ nsAccessible::~nsAccessible()
|
|||
#endif
|
||||
}
|
||||
|
||||
//NS_IMPL_ISUPPORTS2(nsAccessible, nsIAccessible, nsIAccessibleWidgetAccess);
|
||||
NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible);
|
||||
|
||||
/* readonly attribute nsIAccessible accParent; */
|
||||
|
@ -88,21 +374,32 @@ NS_IMETHODIMP nsAccessible::GetAccParent(nsIAccessible * *aAccParent)
|
|||
return rv;
|
||||
}
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsIFrame* parent;
|
||||
nsresult rv = GetFrame()->GetParent(&parent);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (parent)
|
||||
{
|
||||
*aAccParent = new nsAccessible(parent,mPresContext);
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
walker.GetParent(GetFrame());
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
|
||||
// if no content or accessible then we hit the root
|
||||
if (!walker.mContent || !walker.mAccessible)
|
||||
{
|
||||
*aAccParent = new nsRootAccessible(shell);
|
||||
NS_ADDREF(*aAccParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aAccParent = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aAccParent = nsnull;
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
/* readonly attribute nsIAccessible accNextSibling; */
|
||||
NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
|
||||
|
@ -116,16 +413,22 @@ NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
|
|||
}
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsIFrame* next;
|
||||
nsresult rv = GetFrame()->GetNextSibling(&next);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (next)
|
||||
{
|
||||
*aAccNextSibling = new nsAccessible(next,mPresContext);
|
||||
NS_ADDREF(*aAccNextSibling);
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
|
||||
nsIFrame* next = walker.GetNextSibling(GetFrame());
|
||||
|
||||
if (next && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccNextSibling = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccNextSibling);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*aAccNextSibling = nsnull;
|
||||
|
@ -144,41 +447,18 @@ NS_IMETHODIMP nsAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousS
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
// get the parent
|
||||
nsIFrame* frame = GetFrame();
|
||||
nsIFrame* parent;
|
||||
nsresult rv = frame->GetParent(&parent);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
nsIFrame* prev = walker.GetPreviousSibling(GetFrame());
|
||||
|
||||
// find us. What is the child before us.
|
||||
nsIFrame* child;
|
||||
rv = parent->FirstChild(mPresContext,nsnull,&child);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
// if the child is not us
|
||||
if (child != mFrame)
|
||||
{
|
||||
nsIFrame* prev = nsnull;
|
||||
while(child) {
|
||||
prev = child;
|
||||
rv = child->GetNextSibling(&child);
|
||||
if (NS_FAILED(rv)) {
|
||||
prev = nsnull;
|
||||
break;
|
||||
}
|
||||
|
||||
if (child == frame)
|
||||
break;
|
||||
}
|
||||
|
||||
if (prev)
|
||||
if (prev && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
*aAccPreviousSibling = new nsAccessible(prev,mPresContext);
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccPreviousSibling = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccPreviousSibling);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -200,16 +480,20 @@ NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsIFrame* child;
|
||||
nsresult rv = GetFrame()->FirstChild(mPresContext,nsnull,&child);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (child)
|
||||
{
|
||||
*aAccFirstChild = new nsAccessible(child,mPresContext);
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
return NS_OK;
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
nsIFrame* child = walker.GetFirstChild(GetFrame());
|
||||
|
||||
if (child && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccFirstChild = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*aAccFirstChild = nsnull;
|
||||
|
@ -218,38 +502,33 @@ NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
|
|||
}
|
||||
|
||||
/* readonly attribute nsIAccessible accFirstChild; */
|
||||
NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccFirstChild)
|
||||
{
|
||||
|
||||
NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccLastChild)
|
||||
{
|
||||
// delegate
|
||||
if (mAccessible) {
|
||||
nsresult rv = mAccessible->GetAccLastChild(aAccFirstChild);
|
||||
nsresult rv = mAccessible->GetAccLastChild(aAccLastChild);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsIFrame* child;
|
||||
nsresult rv = GetFrame()->FirstChild(mPresContext, nsnull,&child);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aAccFirstChild = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
nsIFrame* last = walker.GetLastChild(GetFrame());
|
||||
|
||||
if (last && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccLastChild = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccLastChild);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsIFrame* last = nsnull;
|
||||
while(child)
|
||||
{
|
||||
last = child;
|
||||
rv = child->GetNextSibling(&child);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aAccFirstChild = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
*aAccLastChild = nsnull;
|
||||
|
||||
*aAccFirstChild = new nsAccessible(last,mPresContext);
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -266,18 +545,14 @@ NS_IMETHODIMP nsAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
|
|||
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
*aAccChildCount = 0;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
nsIFrame* child;
|
||||
nsresult rv = GetFrame()->FirstChild(mPresContext,nsnull,&child);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
if (child)
|
||||
{
|
||||
child->GetNextSibling(&child);
|
||||
(*aAccChildCount)++;
|
||||
}
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
*aAccChildCount = walker.GetCount(GetFrame());
|
||||
} else
|
||||
*aAccChildCount = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -294,13 +569,15 @@ NS_IMETHODIMP nsAccessible::GetAccName(PRUnichar * *aAccName)
|
|||
}
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
if (mNode) {
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
|
||||
if (node) {
|
||||
nsAutoString name;
|
||||
mNode->GetNodeName(name);
|
||||
node->GetNodeName(name);
|
||||
*aAccName = name.ToNewUnicode() ;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aAccName = 0;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -433,8 +710,10 @@ NS_IMETHODIMP nsAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_re
|
|||
nsCOMPtr<nsIAccessible> next;
|
||||
GetAccFirstChild(getter_AddRefs(child));
|
||||
PRInt32 cx,cy,cw,ch;
|
||||
|
||||
while(child) {
|
||||
child->AccGetBounds(&cx,&cy,&cw,&ch);
|
||||
|
||||
if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch)
|
||||
{
|
||||
*_retval = child;
|
||||
|
@ -445,6 +724,7 @@ NS_IMETHODIMP nsAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_re
|
|||
child = next;
|
||||
}
|
||||
|
||||
|
||||
*_retval = this;
|
||||
NS_ADDREF(this);
|
||||
return NS_OK;
|
||||
|
@ -500,21 +780,43 @@ NS_IMETHODIMP nsAccessible::AccDoDefaultAction(void)
|
|||
/* void accGetBounds (out long x, out long y, out long width, out long height); */
|
||||
NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
||||
{
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
nsIFrame* frame = GetFrame();
|
||||
|
||||
if (!frame)
|
||||
if (!frame || !context)
|
||||
{
|
||||
*x=*y=*width=*height=0;
|
||||
*x = *y = *width = *height = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsPoint offset(0,0);
|
||||
// sum up all rects of frames with the same content node
|
||||
nsRect r;
|
||||
nsIFrame* start = frame;
|
||||
nsIFrame* next = nsnull;
|
||||
start->GetNextSibling(&next);
|
||||
|
||||
start->GetRect(r);
|
||||
|
||||
while (nsFrameTreeWalker::IsSameContent(start, next))
|
||||
{
|
||||
nsRect r2;
|
||||
next->GetRect(r2);
|
||||
r.UnionRect(r,r2);
|
||||
next->GetNextSibling(&next);
|
||||
}
|
||||
|
||||
nsPoint offset(r.x,r.y);
|
||||
|
||||
frame->GetParent(&frame);
|
||||
|
||||
nsPoint pos(0,0);
|
||||
while(frame) {
|
||||
nsIScrollableView* scrollingView;
|
||||
nsIView* view;
|
||||
// XXX hack
|
||||
frame->GetView(mPresContext, &view);
|
||||
frame->GetView(context, &view);
|
||||
if (view) {
|
||||
nsresult result = view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
|
@ -532,10 +834,8 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width,
|
|||
}
|
||||
|
||||
float t2p;
|
||||
mPresContext->GetTwipsToPixels(&t2p);
|
||||
context->GetTwipsToPixels(&t2p);
|
||||
|
||||
nsRect r;
|
||||
GetFrame()->GetRect(r);
|
||||
*x = (PRInt32)(offset.x*t2p);
|
||||
*y = (PRInt32)(offset.y*t2p);
|
||||
*width = (PRInt32)(r.width*t2p);
|
||||
|
@ -548,5 +848,115 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width,
|
|||
|
||||
nsIFrame* nsAccessible::GetFrame()
|
||||
{
|
||||
return mFrame;
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
mContent->GetDocument(*getter_AddRefs(document));
|
||||
PRInt32 shells = document->GetNumberOfShells();
|
||||
NS_ASSERTION(shells > 0,"Error no shells!");
|
||||
nsIPresShell* shell = document->GetShellAt(0);
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(mContent, &frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
void nsAccessible::GetPresContext(nsCOMPtr<nsIPresContext>& aContext)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
|
||||
if (shell) {
|
||||
shell->GetPresContext(getter_AddRefs(aContext));
|
||||
} else
|
||||
aContext = nsnull;
|
||||
}
|
||||
|
||||
/*
|
||||
nsIAccessible* nsAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresContext* aContext)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
aFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
content->GetDocument(*getter_AddRefs(document));
|
||||
PRInt32 shells = document->GetNumberOfShells();
|
||||
NS_ASSERTION(shells > 0,"Error no shells!");
|
||||
nsIPresShell* shell = document->GetShellAt(0);
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(content, &frame);
|
||||
|
||||
NS_ASSERTION(frame == aFrame,"Frames don't match!!!");
|
||||
|
||||
return CreateNewAccessible(content, aContext);
|
||||
}
|
||||
*/
|
||||
|
||||
nsIAccessible* nsAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
NS_ASSERTION(aAccessible && aContent,"Error not accessible or content");
|
||||
return new nsAccessible(aAccessible, aContent, aShell);
|
||||
}
|
||||
|
||||
|
||||
// ------- nsHTMLBlockAccessible ------
|
||||
|
||||
nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell):nsAccessible(aAccessible, aContent, aShell)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsIAccessible* nsHTMLBlockAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
NS_ASSERTION(aAccessible && aContent,"Error not accessible or content");
|
||||
return new nsHTMLBlockAccessible(aAccessible, aContent, aShell);
|
||||
}
|
||||
|
||||
/* nsIAccessible accGetAt (in long x, in long y); */
|
||||
NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval)
|
||||
{
|
||||
PRInt32 x,y,w,h;
|
||||
AccGetBounds(&x,&y,&w,&h);
|
||||
if (tx > x && tx < x + w && ty > y && ty < y + h)
|
||||
{
|
||||
nsCOMPtr<nsIAccessible> child;
|
||||
nsCOMPtr<nsIAccessible> smallestChild;
|
||||
PRInt32 smallestArea = -1;
|
||||
nsCOMPtr<nsIAccessible> next;
|
||||
GetAccFirstChild(getter_AddRefs(child));
|
||||
PRInt32 cx,cy,cw,ch;
|
||||
|
||||
while(child) {
|
||||
child->AccGetBounds(&cx,&cy,&cw,&ch);
|
||||
|
||||
// ok if there are multiple frames the contain the point
|
||||
// and they overlap then pick the smallest. We need to do this
|
||||
// for text frames.
|
||||
if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch)
|
||||
{
|
||||
if (smallestArea == -1 || cw*ch < smallestArea) {
|
||||
smallestArea = cw*ch;
|
||||
smallestChild = child;
|
||||
}
|
||||
}
|
||||
child->GetAccNextSibling(getter_AddRefs(next));
|
||||
child = next;
|
||||
}
|
||||
|
||||
if (smallestChild != nsnull)
|
||||
{
|
||||
*_retval = smallestChild;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_retval = this;
|
||||
NS_ADDREF(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_retval = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -28,28 +28,43 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class nsIFrame;
|
||||
|
||||
class nsAccessible : public nsIAccessible
|
||||
// public nsIAccessibleWidgetAccess
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIAccessibilityService methods:
|
||||
NS_DECL_NSIACCESSIBLE
|
||||
|
||||
//NS_IMETHOD AccGetWidget(nsIWidget**);
|
||||
|
||||
public:
|
||||
nsAccessible(nsIFrame* aFrame, nsIPresContext* aContext);
|
||||
~nsAccessible();
|
||||
nsAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell);
|
||||
virtual ~nsAccessible();
|
||||
|
||||
protected:
|
||||
nsIFrame* GetFrame();
|
||||
virtual nsIFrame* GetFrame();
|
||||
virtual void GetPresContext(nsCOMPtr<nsIPresContext>& aContext);
|
||||
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDOMNode> mNode;
|
||||
nsIFrame* mFrame;
|
||||
nsIPresContext* mPresContext;
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
nsWeakPtr mPresShell;
|
||||
nsCOMPtr<nsIAccessible> mAccessible;
|
||||
};
|
||||
|
||||
/* Special Accessible that knows how to handle hit detection for flowing text */
|
||||
class nsHTMLBlockAccessible : public nsAccessible
|
||||
{
|
||||
public:
|
||||
nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell);
|
||||
NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval);
|
||||
protected:
|
||||
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aFrame, nsIPresShell* aShell);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsRootAccessible.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
|
||||
//-----------------------------------------------------
|
||||
// construction
|
||||
//-----------------------------------------------------
|
||||
nsRootAccessible::nsRootAccessible(nsIPresShell* aShell):nsAccessible(nsnull,nsnull,aShell)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
// destruction
|
||||
//-----------------------------------------------------
|
||||
nsRootAccessible::~nsRootAccessible()
|
||||
{
|
||||
}
|
||||
|
||||
/* attribute wstring accName; */
|
||||
NS_IMETHODIMP nsRootAccessible::GetAccName(PRUnichar * *aAccName)
|
||||
{
|
||||
nsAutoString name;
|
||||
name.AssignWithConversion("Mozilla Document");
|
||||
*aAccName = name.ToNewUnicode() ;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// helpers
|
||||
nsIFrame* nsRootAccessible::GetFrame()
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
nsIFrame* root = nsnull;
|
||||
if (shell)
|
||||
shell->GetRootFrame(&root);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
nsIAccessible* nsRootAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
return new nsHTMLBlockAccessible(aAccessible, aContent, aShell);
|
||||
}
|
||||
|
||||
/* readonly attribute nsIAccessible accParent; */
|
||||
NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent)
|
||||
{
|
||||
*aAccParent = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring accRole; */
|
||||
NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUnichar * *aAccRole)
|
||||
{
|
||||
// failed? Lets do some default behavior
|
||||
nsAutoString a;
|
||||
a.AssignWithConversion("client");
|
||||
*aAccRole = a.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _nsRootAccessible_H_
|
||||
#define _nsRootAccessible_H_
|
||||
|
||||
#include "nsAccessible.h"
|
||||
|
||||
class nsRootAccessible : public nsAccessible
|
||||
{
|
||||
|
||||
public:
|
||||
nsRootAccessible(nsIPresShell* aShell);
|
||||
virtual ~nsRootAccessible();
|
||||
|
||||
/* attribute wstring accName; */
|
||||
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
|
||||
NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent);
|
||||
NS_IMETHOD GetAccRole(PRUnichar * *aAccRole);
|
||||
|
||||
protected:
|
||||
virtual nsIFrame* GetFrame();
|
||||
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aFrame, nsIPresShell* aShell);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -20,11 +20,13 @@
|
|||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..
|
||||
MODULE=accessability
|
||||
MODULE=accessibility
|
||||
LIBRARY_NAME=accessibility_s
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsAccessible.obj \
|
||||
.\$(OBJDIR)\nsRootAccessible.obj \
|
||||
.\$(OBJDIR)\nsMutableAccessible.obj \
|
||||
.\$(OBJDIR)\nsAccessibilityService.obj \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include "nsIPresContext.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsRootAccessible.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsMutableAccessible.h"
|
||||
|
||||
nsAccessibilityService::nsAccessibilityService()
|
||||
{
|
||||
|
@ -43,22 +46,224 @@ nsAccessibilityService::~nsAccessibilityService()
|
|||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAccessibilityService, nsIAccessibilityService);
|
||||
|
||||
|
||||
/*
|
||||
class nsHTMLTextAccessible : public nsIAccessible
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIACCESSIBLE
|
||||
|
||||
nsHTMLTextAccessible(nsIDOMNode* aNode);
|
||||
|
||||
virtual ~nsHTMLTextAccessible();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> mNode;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsHTMLTextAccessible, nsIAccessible)
|
||||
|
||||
nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aNode)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mNode = aNode;
|
||||
}
|
||||
|
||||
nsHTMLTextAccessible::~nsHTMLTextAccessible()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccParent(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccNextSibling(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccFirstChild(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccLastChild(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccChildCount(PRInt32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(PRUnichar **_retval)
|
||||
{
|
||||
if (mNode) {
|
||||
nsAutoString value;
|
||||
mNode->GetNodeValue(value);
|
||||
*_retval = value.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccValue(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::SetAccName(const PRUnichar *name)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::SetAccValue(const PRUnichar *value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccDescription(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccRole(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccState(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccDefaultAction(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccHelp(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::GetAccFocused(PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateRight(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateLeft(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateUp(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccNavigateDown(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccAddSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccRemoveSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccExtendSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccTakeSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccTakeFocus()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLTextAccessible::AccDoDefaultAction()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIAccessibilityService methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessibilityService::GetAccessibleFor(nsISupports* frame, nsISupports* context, nsIAccessible **_retval)
|
||||
nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsIAccessible **_retval)
|
||||
{
|
||||
void* ptr = nsnull;
|
||||
frame->QueryInterface(nsIFrame::GetIID(), &ptr);
|
||||
nsIFrame* f = (nsIFrame*)ptr;
|
||||
|
||||
nsCOMPtr<nsIPresContext> c = do_QueryInterface(context);
|
||||
|
||||
NS_ASSERTION(f,"Error non frame passed to accessible factory!!!");
|
||||
nsCOMPtr<nsIPresContext> c = do_QueryInterface(aPresContext);
|
||||
NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!");
|
||||
|
||||
*_retval = new nsAccessible(f,c);
|
||||
nsCOMPtr<nsIPresShell> s;
|
||||
c->GetShell(getter_AddRefs(s));
|
||||
|
||||
NS_ASSERTION(s,"Error not presshell!!");
|
||||
|
||||
*_retval = new nsRootAccessible(s);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessibilityService::CreateMutableAccessible(nsIDOMNode* aNode, nsIMutableAccessible **_retval)
|
||||
{
|
||||
*_retval = new nsMutableAccessible(aNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccessibilityService::CreateHTMLBlockAccessible(nsIAccessible* aAccessible, nsIDOMNode* node, nsISupports* aPresContext, nsIAccessible **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIContent> n = do_QueryInterface(node);
|
||||
NS_ASSERTION(n,"Error non nsIContent passed to accessible factory!!!");
|
||||
|
||||
nsCOMPtr<nsIPresContext> c = do_QueryInterface(aPresContext);
|
||||
NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!");
|
||||
|
||||
nsCOMPtr<nsIPresShell> s;
|
||||
c->GetShell(getter_AddRefs(s));
|
||||
|
||||
NS_ASSERTION(s,"Error not presshell!!");
|
||||
|
||||
|
||||
*_retval = new nsHTMLBlockAccessible(aAccessible, n,s);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,13 +28,307 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsRootAccessible.h"
|
||||
|
||||
//#define DEBUG_LEAKS
|
||||
#define DEBUG_LEAKS
|
||||
|
||||
#ifdef DEBUG_LEAKS
|
||||
static gnsAccessibles = 0;
|
||||
#endif
|
||||
|
||||
|
||||
class nsFrameTreeWalker {
|
||||
public:
|
||||
nsFrameTreeWalker(nsIPresContext* aPresContext);
|
||||
nsIFrame* GetNextSibling(nsIFrame* aFrame);
|
||||
nsIFrame* GetPreviousSibling(nsIFrame* aFrame);
|
||||
nsIFrame* GetParent(nsIFrame* aFrame);
|
||||
nsIFrame* GetFirstChild(nsIFrame* aFrame);
|
||||
nsIFrame* GetLastChild(nsIFrame* aFrame);
|
||||
nsIFrame* GetChildBefore(nsIFrame* aParent, nsIFrame* aChild);
|
||||
PRInt32 GetCount(nsIFrame* aFrame);
|
||||
|
||||
static PRBool IsSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
|
||||
static void GetAccessible(nsIFrame* aFrame, nsCOMPtr<nsIAccessible>& aAccessible, nsCOMPtr<nsIContent>& aContent);
|
||||
|
||||
nsCOMPtr<nsIPresContext> mPresContext;
|
||||
nsCOMPtr<nsIAccessible> mAccessible;
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
};
|
||||
|
||||
nsFrameTreeWalker::nsFrameTreeWalker(nsIPresContext* aPresContext)
|
||||
{
|
||||
mPresContext = aPresContext;
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetParent(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get parent\n");
|
||||
|
||||
nsIFrame* parent = nsnull;
|
||||
aFrame->GetParent(&parent);
|
||||
|
||||
// if no parent then we hit the root
|
||||
// just return that top frame
|
||||
if (!parent) {
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return aFrame;
|
||||
}
|
||||
|
||||
GetAccessible(parent, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
return parent;
|
||||
|
||||
return GetParent(parent);
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetNextSibling(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get next\n");
|
||||
|
||||
// get next sibling
|
||||
nsIFrame* next = nsnull;
|
||||
aFrame->GetNextSibling(&next);
|
||||
|
||||
// skip any frames with the same content node
|
||||
while(IsSameContent(aFrame,next))
|
||||
next->GetNextSibling(&next);
|
||||
|
||||
// if failed
|
||||
if (!next)
|
||||
{
|
||||
// if parent has content
|
||||
nsIFrame* parent = nsnull;
|
||||
aFrame->GetParent(&parent);
|
||||
|
||||
// if no parent fail
|
||||
if (!parent) {
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
// fail if we reach a parent that is accessible
|
||||
GetAccessible(parent, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
{
|
||||
// fail
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
} else {
|
||||
// next on parent
|
||||
return GetNextSibling(parent);
|
||||
}
|
||||
}
|
||||
|
||||
// if next has content
|
||||
GetAccessible(next, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
{
|
||||
// done
|
||||
return next;
|
||||
}
|
||||
|
||||
// if next doesn't have node
|
||||
|
||||
// call first on next
|
||||
nsIFrame* first = GetFirstChild(next);
|
||||
|
||||
// if found
|
||||
if (first)
|
||||
return first;
|
||||
|
||||
// call next on next
|
||||
return GetNextSibling(next);
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetFirstChild(nsIFrame* aFrame)
|
||||
{
|
||||
|
||||
//printf("Get first\n");
|
||||
|
||||
// get first child
|
||||
nsIFrame* child = nsnull;
|
||||
aFrame->FirstChild(mPresContext, nsnull, &child);
|
||||
|
||||
while(child)
|
||||
{
|
||||
// if first has a content node
|
||||
GetAccessible(child, mAccessible, mContent);
|
||||
if (mAccessible)
|
||||
{
|
||||
// done
|
||||
return child;
|
||||
} else {
|
||||
// call first on child
|
||||
nsIFrame* first = GetFirstChild(child);
|
||||
|
||||
// if succeeded
|
||||
if (first)
|
||||
{
|
||||
// return child
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
||||
// get next sibling
|
||||
nsIFrame* next;
|
||||
child->GetNextSibling(&next);
|
||||
|
||||
// skip children with duplicate content nodes
|
||||
while(IsSameContent(child,next))
|
||||
next->GetNextSibling(&next);
|
||||
|
||||
child = next;
|
||||
}
|
||||
|
||||
// fail
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetChildBefore(nsIFrame* aParent, nsIFrame* aChild)
|
||||
{
|
||||
nsIFrame* child = GetFirstChild(aParent);
|
||||
|
||||
// if the child is not us
|
||||
if (child == aChild) {
|
||||
mAccessible = nsnull;
|
||||
mContent = nsnull;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsIFrame* prev = child;
|
||||
nsCOMPtr<nsIContent> prevContent = mContent;
|
||||
nsCOMPtr<nsIAccessible> prevAccessible = mAccessible;
|
||||
|
||||
while(child)
|
||||
{
|
||||
child = GetNextSibling(child);
|
||||
|
||||
if (child == aChild)
|
||||
break;
|
||||
|
||||
prev = child;
|
||||
prevContent = mContent;
|
||||
prevAccessible = mAccessible;
|
||||
}
|
||||
|
||||
mAccessible = prevAccessible;
|
||||
mContent = prevContent;
|
||||
return prev;
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetPreviousSibling(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get previous\n");
|
||||
|
||||
nsIFrame* parent = GetParent(aFrame);
|
||||
|
||||
return GetChildBefore(parent, aFrame);
|
||||
}
|
||||
|
||||
nsIFrame* nsFrameTreeWalker::GetLastChild(nsIFrame* aFrame)
|
||||
{
|
||||
//printf("Get last\n");
|
||||
|
||||
return GetChildBefore(aFrame, nsnull);
|
||||
}
|
||||
|
||||
PRInt32 nsFrameTreeWalker::GetCount(nsIFrame* aFrame)
|
||||
{
|
||||
|
||||
//printf("Get count\n");
|
||||
nsIFrame* child = GetFirstChild(aFrame);
|
||||
|
||||
PRInt32 count = 0;
|
||||
while(child)
|
||||
{
|
||||
count++;
|
||||
child = GetNextSibling(child);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
nsresult nsFrameTreeWalker::Next()
|
||||
{
|
||||
if (mCurrent == nsnull)
|
||||
return NS_OK;
|
||||
|
||||
nsIFrame* n;
|
||||
nsresult rv = mCurrent->GetNextSibling(&n);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// skip any frames with the same content node
|
||||
while(IsSameContent(mCurrent,n))
|
||||
{
|
||||
rv = n->GetNextSibling(&n);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
mPrev = mCurrent;
|
||||
mCurrent = n;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
void nsFrameTreeWalker::GetAccessible(nsIFrame* aFrame, nsCOMPtr<nsIAccessible>& aAccessible, nsCOMPtr<nsIContent>& aContent)
|
||||
{
|
||||
aContent = nsnull;
|
||||
aAccessible = nsnull;
|
||||
|
||||
aFrame->GetContent(getter_AddRefs(aContent));
|
||||
|
||||
if (!aContent)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
aContent->GetDocument(*getter_AddRefs(document));
|
||||
PRInt32 shells = document->GetNumberOfShells();
|
||||
NS_ASSERTION(shells > 0,"Error no shells!");
|
||||
nsIPresShell* shell = document->GetShellAt(0);
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(aContent, &frame);
|
||||
|
||||
if (!frame)
|
||||
return;
|
||||
|
||||
aAccessible = do_QueryInterface(aFrame);
|
||||
|
||||
if (!aAccessible)
|
||||
aAccessible = do_QueryInterface(aContent);
|
||||
|
||||
// if (aAccessible)
|
||||
// printf("Found accessible!\n");
|
||||
}
|
||||
|
||||
PRBool nsFrameTreeWalker::IsSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
||||
{
|
||||
if (!aFrame1 || !aFrame2)
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIContent> content1;
|
||||
nsCOMPtr<nsIContent> content2;
|
||||
|
||||
aFrame1->GetContent(getter_AddRefs(content1));
|
||||
aFrame2->GetContent(getter_AddRefs(content2));
|
||||
|
||||
if (content1 == content2 && content1 != nsnull)
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class nsAccessible
|
||||
*/
|
||||
|
@ -42,23 +336,14 @@ static gnsAccessibles = 0;
|
|||
//-----------------------------------------------------
|
||||
// construction
|
||||
//-----------------------------------------------------
|
||||
nsAccessible::nsAccessible(nsIFrame* aFrame, nsIPresContext* aContext)
|
||||
nsAccessible::nsAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
// get frame and node
|
||||
mFrame = aFrame;
|
||||
nsCOMPtr<nsIContent> content;
|
||||
aFrame->GetContent(getter_AddRefs(content));
|
||||
mNode = do_QueryInterface(content);
|
||||
mPresContext = aContext;
|
||||
|
||||
// see if the frame implements nsIAccessible
|
||||
mAccessible = do_QueryInterface(aFrame);
|
||||
|
||||
// if not see if its content node supports nsIAccessible
|
||||
if (!mAccessible)
|
||||
mAccessible = do_QueryInterface(content);
|
||||
mContent = aContent;
|
||||
mAccessible = aAccessible;
|
||||
mPresShell = getter_AddRefs(NS_GetWeakReference(aShell));
|
||||
|
||||
#ifdef DEBUG_LEAKS
|
||||
printf("nsAccessibles=%d\n", ++gnsAccessibles);
|
||||
|
@ -76,6 +361,7 @@ nsAccessible::~nsAccessible()
|
|||
#endif
|
||||
}
|
||||
|
||||
//NS_IMPL_ISUPPORTS2(nsAccessible, nsIAccessible, nsIAccessibleWidgetAccess);
|
||||
NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible);
|
||||
|
||||
/* readonly attribute nsIAccessible accParent; */
|
||||
|
@ -88,21 +374,32 @@ NS_IMETHODIMP nsAccessible::GetAccParent(nsIAccessible * *aAccParent)
|
|||
return rv;
|
||||
}
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsIFrame* parent;
|
||||
nsresult rv = GetFrame()->GetParent(&parent);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (parent)
|
||||
{
|
||||
*aAccParent = new nsAccessible(parent,mPresContext);
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
walker.GetParent(GetFrame());
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
|
||||
// if no content or accessible then we hit the root
|
||||
if (!walker.mContent || !walker.mAccessible)
|
||||
{
|
||||
*aAccParent = new nsRootAccessible(shell);
|
||||
NS_ADDREF(*aAccParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aAccParent = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aAccParent = nsnull;
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
/* readonly attribute nsIAccessible accNextSibling; */
|
||||
NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
|
||||
|
@ -116,16 +413,22 @@ NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
|
|||
}
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsIFrame* next;
|
||||
nsresult rv = GetFrame()->GetNextSibling(&next);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (next)
|
||||
{
|
||||
*aAccNextSibling = new nsAccessible(next,mPresContext);
|
||||
NS_ADDREF(*aAccNextSibling);
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
|
||||
nsIFrame* next = walker.GetNextSibling(GetFrame());
|
||||
|
||||
if (next && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccNextSibling = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccNextSibling);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*aAccNextSibling = nsnull;
|
||||
|
@ -144,41 +447,18 @@ NS_IMETHODIMP nsAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousS
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
// get the parent
|
||||
nsIFrame* frame = GetFrame();
|
||||
nsIFrame* parent;
|
||||
nsresult rv = frame->GetParent(&parent);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
nsIFrame* prev = walker.GetPreviousSibling(GetFrame());
|
||||
|
||||
// find us. What is the child before us.
|
||||
nsIFrame* child;
|
||||
rv = parent->FirstChild(mPresContext,nsnull,&child);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
// if the child is not us
|
||||
if (child != mFrame)
|
||||
{
|
||||
nsIFrame* prev = nsnull;
|
||||
while(child) {
|
||||
prev = child;
|
||||
rv = child->GetNextSibling(&child);
|
||||
if (NS_FAILED(rv)) {
|
||||
prev = nsnull;
|
||||
break;
|
||||
}
|
||||
|
||||
if (child == frame)
|
||||
break;
|
||||
}
|
||||
|
||||
if (prev)
|
||||
if (prev && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
*aAccPreviousSibling = new nsAccessible(prev,mPresContext);
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccPreviousSibling = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccPreviousSibling);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -200,16 +480,20 @@ NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsIFrame* child;
|
||||
nsresult rv = GetFrame()->FirstChild(mPresContext,nsnull,&child);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (child)
|
||||
{
|
||||
*aAccFirstChild = new nsAccessible(child,mPresContext);
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
return NS_OK;
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
nsIFrame* child = walker.GetFirstChild(GetFrame());
|
||||
|
||||
if (child && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccFirstChild = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*aAccFirstChild = nsnull;
|
||||
|
@ -218,38 +502,33 @@ NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
|
|||
}
|
||||
|
||||
/* readonly attribute nsIAccessible accFirstChild; */
|
||||
NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccFirstChild)
|
||||
{
|
||||
|
||||
NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccLastChild)
|
||||
{
|
||||
// delegate
|
||||
if (mAccessible) {
|
||||
nsresult rv = mAccessible->GetAccLastChild(aAccFirstChild);
|
||||
nsresult rv = mAccessible->GetAccLastChild(aAccLastChild);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
nsIFrame* child;
|
||||
nsresult rv = GetFrame()->FirstChild(mPresContext, nsnull,&child);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aAccFirstChild = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
nsIFrame* last = walker.GetLastChild(GetFrame());
|
||||
|
||||
if (last && walker.mAccessible && walker.mContent)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
*aAccLastChild = CreateNewAccessible(walker.mAccessible, walker.mContent, shell);
|
||||
NS_ADDREF(*aAccLastChild);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsIFrame* last = nsnull;
|
||||
while(child)
|
||||
{
|
||||
last = child;
|
||||
rv = child->GetNextSibling(&child);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aAccFirstChild = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
*aAccLastChild = nsnull;
|
||||
|
||||
*aAccFirstChild = new nsAccessible(last,mPresContext);
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -266,18 +545,14 @@ NS_IMETHODIMP nsAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
|
|||
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
*aAccChildCount = 0;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
nsIFrame* child;
|
||||
nsresult rv = GetFrame()->FirstChild(mPresContext,nsnull,&child);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
if (child)
|
||||
{
|
||||
child->GetNextSibling(&child);
|
||||
(*aAccChildCount)++;
|
||||
}
|
||||
if (context) {
|
||||
nsFrameTreeWalker walker(context);
|
||||
*aAccChildCount = walker.GetCount(GetFrame());
|
||||
} else
|
||||
*aAccChildCount = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -294,13 +569,15 @@ NS_IMETHODIMP nsAccessible::GetAccName(PRUnichar * *aAccName)
|
|||
}
|
||||
|
||||
// failed? Lets do some default behavior
|
||||
if (mNode) {
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
|
||||
if (node) {
|
||||
nsAutoString name;
|
||||
mNode->GetNodeName(name);
|
||||
node->GetNodeName(name);
|
||||
*aAccName = name.ToNewUnicode() ;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aAccName = 0;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -433,8 +710,10 @@ NS_IMETHODIMP nsAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_re
|
|||
nsCOMPtr<nsIAccessible> next;
|
||||
GetAccFirstChild(getter_AddRefs(child));
|
||||
PRInt32 cx,cy,cw,ch;
|
||||
|
||||
while(child) {
|
||||
child->AccGetBounds(&cx,&cy,&cw,&ch);
|
||||
|
||||
if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch)
|
||||
{
|
||||
*_retval = child;
|
||||
|
@ -445,6 +724,7 @@ NS_IMETHODIMP nsAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_re
|
|||
child = next;
|
||||
}
|
||||
|
||||
|
||||
*_retval = this;
|
||||
NS_ADDREF(this);
|
||||
return NS_OK;
|
||||
|
@ -500,21 +780,43 @@ NS_IMETHODIMP nsAccessible::AccDoDefaultAction(void)
|
|||
/* void accGetBounds (out long x, out long y, out long width, out long height); */
|
||||
NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
||||
{
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
GetPresContext(context);
|
||||
|
||||
nsIFrame* frame = GetFrame();
|
||||
|
||||
if (!frame)
|
||||
if (!frame || !context)
|
||||
{
|
||||
*x=*y=*width=*height=0;
|
||||
*x = *y = *width = *height = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsPoint offset(0,0);
|
||||
// sum up all rects of frames with the same content node
|
||||
nsRect r;
|
||||
nsIFrame* start = frame;
|
||||
nsIFrame* next = nsnull;
|
||||
start->GetNextSibling(&next);
|
||||
|
||||
start->GetRect(r);
|
||||
|
||||
while (nsFrameTreeWalker::IsSameContent(start, next))
|
||||
{
|
||||
nsRect r2;
|
||||
next->GetRect(r2);
|
||||
r.UnionRect(r,r2);
|
||||
next->GetNextSibling(&next);
|
||||
}
|
||||
|
||||
nsPoint offset(r.x,r.y);
|
||||
|
||||
frame->GetParent(&frame);
|
||||
|
||||
nsPoint pos(0,0);
|
||||
while(frame) {
|
||||
nsIScrollableView* scrollingView;
|
||||
nsIView* view;
|
||||
// XXX hack
|
||||
frame->GetView(mPresContext, &view);
|
||||
frame->GetView(context, &view);
|
||||
if (view) {
|
||||
nsresult result = view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
|
@ -532,10 +834,8 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width,
|
|||
}
|
||||
|
||||
float t2p;
|
||||
mPresContext->GetTwipsToPixels(&t2p);
|
||||
context->GetTwipsToPixels(&t2p);
|
||||
|
||||
nsRect r;
|
||||
GetFrame()->GetRect(r);
|
||||
*x = (PRInt32)(offset.x*t2p);
|
||||
*y = (PRInt32)(offset.y*t2p);
|
||||
*width = (PRInt32)(r.width*t2p);
|
||||
|
@ -548,5 +848,115 @@ NS_IMETHODIMP nsAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width,
|
|||
|
||||
nsIFrame* nsAccessible::GetFrame()
|
||||
{
|
||||
return mFrame;
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
mContent->GetDocument(*getter_AddRefs(document));
|
||||
PRInt32 shells = document->GetNumberOfShells();
|
||||
NS_ASSERTION(shells > 0,"Error no shells!");
|
||||
nsIPresShell* shell = document->GetShellAt(0);
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(mContent, &frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
void nsAccessible::GetPresContext(nsCOMPtr<nsIPresContext>& aContext)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
|
||||
if (shell) {
|
||||
shell->GetPresContext(getter_AddRefs(aContext));
|
||||
} else
|
||||
aContext = nsnull;
|
||||
}
|
||||
|
||||
/*
|
||||
nsIAccessible* nsAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresContext* aContext)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
aFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
content->GetDocument(*getter_AddRefs(document));
|
||||
PRInt32 shells = document->GetNumberOfShells();
|
||||
NS_ASSERTION(shells > 0,"Error no shells!");
|
||||
nsIPresShell* shell = document->GetShellAt(0);
|
||||
nsIFrame* frame = nsnull;
|
||||
shell->GetPrimaryFrameFor(content, &frame);
|
||||
|
||||
NS_ASSERTION(frame == aFrame,"Frames don't match!!!");
|
||||
|
||||
return CreateNewAccessible(content, aContext);
|
||||
}
|
||||
*/
|
||||
|
||||
nsIAccessible* nsAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
NS_ASSERTION(aAccessible && aContent,"Error not accessible or content");
|
||||
return new nsAccessible(aAccessible, aContent, aShell);
|
||||
}
|
||||
|
||||
|
||||
// ------- nsHTMLBlockAccessible ------
|
||||
|
||||
nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell):nsAccessible(aAccessible, aContent, aShell)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsIAccessible* nsHTMLBlockAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
NS_ASSERTION(aAccessible && aContent,"Error not accessible or content");
|
||||
return new nsHTMLBlockAccessible(aAccessible, aContent, aShell);
|
||||
}
|
||||
|
||||
/* nsIAccessible accGetAt (in long x, in long y); */
|
||||
NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval)
|
||||
{
|
||||
PRInt32 x,y,w,h;
|
||||
AccGetBounds(&x,&y,&w,&h);
|
||||
if (tx > x && tx < x + w && ty > y && ty < y + h)
|
||||
{
|
||||
nsCOMPtr<nsIAccessible> child;
|
||||
nsCOMPtr<nsIAccessible> smallestChild;
|
||||
PRInt32 smallestArea = -1;
|
||||
nsCOMPtr<nsIAccessible> next;
|
||||
GetAccFirstChild(getter_AddRefs(child));
|
||||
PRInt32 cx,cy,cw,ch;
|
||||
|
||||
while(child) {
|
||||
child->AccGetBounds(&cx,&cy,&cw,&ch);
|
||||
|
||||
// ok if there are multiple frames the contain the point
|
||||
// and they overlap then pick the smallest. We need to do this
|
||||
// for text frames.
|
||||
if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch)
|
||||
{
|
||||
if (smallestArea == -1 || cw*ch < smallestArea) {
|
||||
smallestArea = cw*ch;
|
||||
smallestChild = child;
|
||||
}
|
||||
}
|
||||
child->GetAccNextSibling(getter_AddRefs(next));
|
||||
child = next;
|
||||
}
|
||||
|
||||
if (smallestChild != nsnull)
|
||||
{
|
||||
*_retval = smallestChild;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_retval = this;
|
||||
NS_ADDREF(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_retval = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -28,28 +28,43 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class nsIFrame;
|
||||
|
||||
class nsAccessible : public nsIAccessible
|
||||
// public nsIAccessibleWidgetAccess
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIAccessibilityService methods:
|
||||
NS_DECL_NSIACCESSIBLE
|
||||
|
||||
//NS_IMETHOD AccGetWidget(nsIWidget**);
|
||||
|
||||
public:
|
||||
nsAccessible(nsIFrame* aFrame, nsIPresContext* aContext);
|
||||
~nsAccessible();
|
||||
nsAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell);
|
||||
virtual ~nsAccessible();
|
||||
|
||||
protected:
|
||||
nsIFrame* GetFrame();
|
||||
virtual nsIFrame* GetFrame();
|
||||
virtual void GetPresContext(nsCOMPtr<nsIPresContext>& aContext);
|
||||
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDOMNode> mNode;
|
||||
nsIFrame* mFrame;
|
||||
nsIPresContext* mPresContext;
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
nsWeakPtr mPresShell;
|
||||
nsCOMPtr<nsIAccessible> mAccessible;
|
||||
};
|
||||
|
||||
/* Special Accessible that knows how to handle hit detection for flowing text */
|
||||
class nsHTMLBlockAccessible : public nsAccessible
|
||||
{
|
||||
public:
|
||||
nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell);
|
||||
NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval);
|
||||
protected:
|
||||
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aFrame, nsIPresShell* aShell);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,249 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsMutableAccessible.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsMutableAccessible, nsIAccessible)
|
||||
|
||||
nsMutableAccessible::nsMutableAccessible(nsIDOMNode* aNode)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mNode = aNode;
|
||||
mNameNodeValue = PR_FALSE;
|
||||
mNameStringSet = PR_FALSE;
|
||||
mRole.AssignWithConversion("unknown");
|
||||
mIsLeaf = PR_FALSE;
|
||||
}
|
||||
|
||||
nsMutableAccessible::~nsMutableAccessible()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::SetIsLeaf(PRBool aLeaf)
|
||||
{
|
||||
mIsLeaf = aLeaf;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void SetNodeAsNodeValue (); */
|
||||
NS_IMETHODIMP nsMutableAccessible::SetNameAsNodeValue()
|
||||
{
|
||||
mNameNodeValue = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void SetName (in wstring name); */
|
||||
NS_IMETHODIMP nsMutableAccessible::SetName(const PRUnichar *aName)
|
||||
{
|
||||
mName = aName;
|
||||
mNameStringSet = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void SetNameAsAttribute (in nsIAtom atom); */
|
||||
NS_IMETHODIMP nsMutableAccessible::SetNameAsAttribute(nsIAtom *aAttribute)
|
||||
{
|
||||
mNameAttribute = aAttribute;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void SetNameAsAttribute (in nsIAtom atom); */
|
||||
NS_IMETHODIMP nsMutableAccessible::SetRole(const PRUnichar *aRole)
|
||||
{
|
||||
mRole = aRole;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccParent(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccNextSibling(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccFirstChild(nsIAccessible **_retval)
|
||||
{
|
||||
if (mIsLeaf) {
|
||||
*_retval = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccLastChild(nsIAccessible **_retval)
|
||||
{
|
||||
if (mIsLeaf) {
|
||||
*_retval = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccChildCount(PRInt32 *_retval)
|
||||
{
|
||||
if (mIsLeaf) {
|
||||
*_retval = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccName(PRUnichar **_retval)
|
||||
{
|
||||
nsAutoString value;
|
||||
|
||||
if (mNameNodeValue) {
|
||||
mNode->GetNodeValue(value);
|
||||
} else if (mNameStringSet) {
|
||||
value = mName;
|
||||
} else if (mNameAttribute) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mNode);
|
||||
content->GetAttribute(kNameSpaceID_None, mNameAttribute, value);
|
||||
value.Trim(" ");
|
||||
} else {
|
||||
*_retval = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
*_retval = value.ToNewUnicode();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccValue(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::SetAccName(const PRUnichar *name)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::SetAccValue(const PRUnichar *value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccDescription(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccRole(PRUnichar **_retval)
|
||||
{
|
||||
*_retval = mRole.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccState(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccDefaultAction(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccHelp(PRUnichar **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::GetAccFocused(PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccNavigateRight(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccNavigateLeft(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccNavigateUp(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccNavigateDown(nsIAccessible **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccAddSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccRemoveSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccExtendSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccTakeSelection()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccTakeFocus()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMutableAccessible::AccDoDefaultAction()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _nsMutableAccessible_H_
|
||||
#define _nsMutableAccessible_H_
|
||||
|
||||
#include "nsAccessible.h"
|
||||
|
||||
#include "nsIMutableAccessible.h"
|
||||
|
||||
class nsMutableAccessible : public nsIMutableAccessible
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIACCESSIBLE
|
||||
NS_DECL_NSIMUTABLEACCESSIBLE
|
||||
|
||||
nsMutableAccessible(nsIDOMNode* aNode);
|
||||
virtual ~nsMutableAccessible();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDOMNode> mNode;
|
||||
nsAutoString mName;
|
||||
nsAutoString mRole;
|
||||
nsCOMPtr<nsIAtom> mNameAttribute;
|
||||
PRPackedBool mNameNodeValue;
|
||||
PRPackedBool mNameStringSet;
|
||||
PRPackedBool mIsLeaf;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsRootAccessible.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
|
||||
//-----------------------------------------------------
|
||||
// construction
|
||||
//-----------------------------------------------------
|
||||
nsRootAccessible::nsRootAccessible(nsIPresShell* aShell):nsAccessible(nsnull,nsnull,aShell)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
// destruction
|
||||
//-----------------------------------------------------
|
||||
nsRootAccessible::~nsRootAccessible()
|
||||
{
|
||||
}
|
||||
|
||||
/* attribute wstring accName; */
|
||||
NS_IMETHODIMP nsRootAccessible::GetAccName(PRUnichar * *aAccName)
|
||||
{
|
||||
nsAutoString name;
|
||||
name.AssignWithConversion("Mozilla Document");
|
||||
*aAccName = name.ToNewUnicode() ;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// helpers
|
||||
nsIFrame* nsRootAccessible::GetFrame()
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShell);
|
||||
nsIFrame* root = nsnull;
|
||||
if (shell)
|
||||
shell->GetRootFrame(&root);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
nsIAccessible* nsRootAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIPresShell* aShell)
|
||||
{
|
||||
return new nsHTMLBlockAccessible(aAccessible, aContent, aShell);
|
||||
}
|
||||
|
||||
/* readonly attribute nsIAccessible accParent; */
|
||||
NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent)
|
||||
{
|
||||
*aAccParent = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring accRole; */
|
||||
NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUnichar * *aAccRole)
|
||||
{
|
||||
// failed? Lets do some default behavior
|
||||
nsAutoString a;
|
||||
a.AssignWithConversion("client");
|
||||
*aAccRole = a.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _nsRootAccessible_H_
|
||||
#define _nsRootAccessible_H_
|
||||
|
||||
#include "nsAccessible.h"
|
||||
|
||||
class nsRootAccessible : public nsAccessible
|
||||
{
|
||||
|
||||
public:
|
||||
nsRootAccessible(nsIPresShell* aShell);
|
||||
virtual ~nsRootAccessible();
|
||||
|
||||
/* attribute wstring accName; */
|
||||
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
|
||||
NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent);
|
||||
NS_IMETHOD GetAccRole(PRUnichar * *aAccRole);
|
||||
|
||||
protected:
|
||||
virtual nsIFrame* GetFrame();
|
||||
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aFrame, nsIPresShell* aShell);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче