bug #86517 Landing of Accessible_052901_Branch4 sr=waterson

r= lots, see bug
This commit is contained in:
jgaunt%netscape.com 2001-06-30 00:25:09 +00:00
Родитель 3e8ebac447
Коммит 96a2e5ce18
102 изменённых файлов: 5869 добавлений и 2787 удалений

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

@ -8,6 +8,10 @@
<h1>How the Accessible module (accessibility.dll) works</h1>
<ul>
<p>
See also:
<a href="http://www.mozilla.org/projects/ui/accessibility/vendors-win.html">Gecko Info for Windows Accessibility Vendors</a>, a primer for vendors of 3rd party accessibility software, on how to use our MSAA and other relevant API's.
</p>
<p>
The <a href="http://lxr.mozilla.org/seamonkey/source/accessible/">Accessible module</a> is where we implement support for the <a href="http://www.microsoft.com/enable/msaa/">Microsoft Active Accessibility (MSAA) API</a>
(<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=12952">bug 12952</a>).
Support for Sun's <a href="http://www.sun.com/access/gnome/">Gnome Accessibility API</a> is part of our future plans as well.
@ -70,8 +74,8 @@ checked, etc. </li>
<li>get_accHelp: Get context sensitive help for the IAccessible.</li>
<li>get_accHelpTopic: We don't use this, it's only if the Windows help system is used.</li>
<li>get_accKeyboardShortcut: What is the keyboard shortcut for this IAccessible.</li>
<li>get_accFocus: Not sure, why aren't states used for this.</li>
<li>get_accSelection: Hmm...</li>
<li>get_accFocus: Which child is focused?</li>
<li>get_accSelection: Which children of this item are selected?</li>
<li>get_accDefaultAction: Get a description or name of the default action for this component, such as "jump" for links.</li>
<li>accSelect: Select the item associated with this IAccessible.</li>
@ -83,49 +87,66 @@ checked, etc. </li>
<li>put_accValue: Change the value.</li>
</ul>
</p>
<p>
Rather than directly implement IAccessible with an Accessible class, we have chosen to proxy to our own interface,
called nsIAccessible, which is more robust. It has the capability of supporting other new accessibility API's such
as Sun's Gnome Accessiblity API. Our nsIAccessible implementation can proxy further to a variety of classes, each specialized for a particular kind of
widget or data node.
</p>
<ul>
<li>IAccessible (MSAA) is implemented by Accessible, which proxies to nsIAccessible (Mozilla's API)</li>
<li>IAccessible is also implemented by RootAccessible, representing the root IAccessible for a window,
and also proxies to an nsIAccessible. In this case nsIAccessible will be implemented by nsRootAccessible.</li>
</ul>
<h2>The Basics</h2>
<ul>
<p>
The first thing that happens when an accessibility aid wants to watch our application is it sends the main application
window a <a href="http://lxr.mozilla.org/seamonkey/search?string=WM_GETOBJECT">WM_GETOBJECT</a> message requesting an IAccessible for the window. This event is received in mozilla/widget/src/windows/nsWindow.cpp.
Rather than directly implement IAccessible with an Accessible class, we have chosen to proxy to our own cross-platform interface,
called nsIAccessible, which is more robust. It has the capability of supporting other new accessibility API's such
as Sun's Gnome Accessiblity API. The nsIAccessible interface is implemented by a variety of classes for each of the
various objects in HTML. Each class is tailored to the specific abilities and properties of the HTML objects it applies to.
</p>
<p>
The first thing that happens when an accessibility aid wants to watch our application is calls the Windows API function
AccessibleObjectFromWindow(). This in turns sends the window in question
a <a href="http://lxr.mozilla.org/seamonkey/search?string=WM_GETOBJECT">WM_GETOBJECT</a> message requesting an IAccessible for the window.
In our case, this event is received in mozilla/widget/src/windows/nsWindow.cpp.
We send back an IAccessible interface that represents that root window. The accessibility aid will use
that IAccessible to get at the rest of the tree, by asking for it's children IAccessibles, asking the children for the
that first IAccessible to reach rest of the IAccessible hierarchy, by asking for it's children IAccessibles, asking the children for the
grandchildren IAccessibles, and so on. Until this WM_GETOBJECT message is processed, the accessibility.dll is not loaded,
so there is almost zero overhead for accessibility in Mozilla.
</p>
</ul>
<h2>How the IAccessible's are Created</h2>
<ul>
<p>
To create a RootAccessible IAccessible for the window we get a <a href="http://lxr.mozilla.org/seamonkey/search?string=WM_GETOBJECT">WM_GETOBJECT</a> message in, nsWindow.cpp first generates an internal event
called <a href="http://lxr.mozilla.org/seamonkey/search?string=NS_GETACCESSIBLE">NS_GETACCESSIBLE</a>, which is handled in nsFrame.cpp via the creation of an nsRootAccessible implementation of the nsIAccessible interface.
Next the new RootAccessible is created. RootAccessible and Accessible are both implemented
To create the root IAccessible for a window the first time it gets the <a href="http://lxr.mozilla.org/seamonkey/search?string=WM_GETOBJECT">WM_GETOBJECT</a> message in,
nsWindow.cpp first generates an internal event
called <a href="http://lxr.mozilla.org/seamonkey/search?string=NS_GETACCESSIBLE">NS_GETACCESSIBLE</a>,
which is handled in nsFrame.cpp via the creation of an nsRootAccessible implementation of the nsIAccessible interface.
The first IAccessible is then created by instantiating a RootAccessible class. This RootAccessible is also cached by
the nsWindow it's for, so that any additional WM_GETOBJECT messages use the same RootAccessible.
The RootAccessible class used to implement IAccessible here is slightly different from the normal Accessible class
that's used, in that it keeps track of event data.
RootAccessible and Accessible are both implemented
in <a href="http://lxr.mozilla.org/seamonkey/source/widget/source/windows/Accessible.cpp">
mozilla/widget/src/windows/Accessible.cpp</a>).
</P>
</ul>
<h2>The Real Power Behind IAccessible's</h2>
<ul>
<p>The implementations of IAccessible (Accessible and RootAccessible), don't know anything about Mozilla
objects. They merely proxy to our cross platform accessibility classes, which all have an nsIAccessible interface.
</h2>
<p>
The impementation for nsIAccessible knows how
The base implementation for nsIAccessible is called nsAccessible. It has default implementations for all the
nsIAccessible methods. It also knows how
to walk Mozilla's content DOM and frame tree, exposing only the objects that are needed for accessibility.
Essentially, nsAccessible knows what it needs to expose by QueryInterfacing the DOM node's primary frame for
an nsIAccessible. If it gets one, it's considered an accessible object. A frame that wishes to return
an nsIAccessible when QI'd for it, creates one of the correct type on the fly using nsIAccessibilityService.
Essentially, nsAccessible knows what it needs to expose by asking each DOM node's primary frame for
an nsIAccessible, using the GetAccessible() method. If it gets one, it's considered an accessible object.
A frame that wishes to return
an nsIAccessible GetAccessible() is called, creates one of the correct type on the fly using
nsIAccessibilityService methods built for that purpose.
</p>
<p>
The specific implementations
of nsIAccessible for each widget or content type inherit from nsGenericAccessible, which simply returns
NS_ERROR_NOT_IMPLEMENTED for every method. The specific implementation then overrides those methods
of nsIAccessible for each widget or content type inherit from nsAccessible.
Each implementation then overrides those methods
it wishes to implement, and does nothing for those methods it wants the default behavior for.
For example, the default behavior for nsIAccessible::getAccFirstChild is to
instantial a nsDOMTreeWalker, and ask it for the first child. It doesn't need to do this, however, for images,
because an implementation exists for nsHTMLImageAccessible::getAccFirstChild (returns the first image map area
for the image if one exists).
instantial a nsDOMTreeWalker, and ask it for the first child. However, nsImageAccessible overrides getAccFirstChild,
returning the first area of an image map if there is one, otherwise nsnull.
</p>
</ul>
@ -134,18 +155,22 @@ for the image if one exists).
<p>
When an accessibility-related event occurs within an application such as Mozilla, it must use NotifyWinEvent from
the Win32 API. NotifyWinEvent is passed arguments for the window the event occured in, and the number of the child
within that window. Accessibility aids use a WIN32 call to register as a listener for these events.
within that window. Accessibility aids use the Win32 call SetWinEventHook() to register as a listener for these events.
</p>
<p>
The accessibility aid is choose which events it is interested in learning more about by sending a window a WM_????
event requesting the IAccessible to the node corresponding to the
child number that had been indicated from NotifyWinEvent. In Mozilla, this creates a problem. We cannot
The accessibility aid is choose which events it is interested in learning more about by using the Win32 API call
AccessibleObjectFromEvent, requesting the IAccessible to the node corresponding to the
child number that had been indicated from NotifyWinEvent(). This ends up asking our RootAccessible for the child
IAccessible that matches the window handle and child id we indicated through NotofyWinEvent().
</p>
<p>
In Mozilla, this creates a problem. We cannot
keep track of a child number for every important accessible node in a document. We deal with this by generating fake
child IDs for the most recent accessibile events that we have generated, in a circular array.
</p>
<p>
Since there is a RootAccessible for each top level window that might generate MSAA events, that's where we do the bookkeeping
for these events and their nsIAccessible's. Whenever NotifyWinEvent is called, a new fake ID is generated (We use
for these events and their nsIAccessible's. Whenever NotifyWinEvent() is called, a new fake ID is generated (We use
negative numbers for the fake IDs). When the callback comes to request the IAccessible for that child number,
we check the circular array for that ID, and voila, we have the corresponding nsIAccessible to proxy.
</p>

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

@ -39,14 +39,13 @@ CPPSRCS = nsAccessibilityFactory.cpp
LOCAL_INCLUDES = -I$(srcdir)/../src
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libaccessibility_s.$(LIB_SUFFIX) \
$(DIST)/lib/libchrome_s.$(LIB_SUFFIX) \
$(NULL)
$(DIST)/lib/libaccessibility_s.$(LIB_SUFFIX) \
$(NULL)
EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
-lgkgfx \
$(NULL)
EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
-lgkgfx \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -25,20 +25,22 @@ LIBRARY_NAME=accessibility
MODULE_NAME=nsAccessibilityModule
CPP_OBJS=\
.\$(OBJDIR)\nsAccessibilityFactory.obj \
$(NULL)
.\$(OBJDIR)\nsAccessibilityFactory.obj \
$(NULL)
LINCS = $(LINCS) -I..\src # for implementation headers
SUB_LIBRARIES=\
$(DIST)\lib\accessibility_s.lib \
$(NULL)
SHARED_LIBRARY_LIBS=\
$(DIST)\lib\accessibility_s.lib \
$(NULL)
LLIBS=\
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\timer_s.lib \
$(DIST)\lib\gkgfx.lib \
$(LIBNSPR)
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\timer_s.lib \
$(DIST)\lib\gkgfx.lib \
$(DIST)\lib\contentshared_s.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>

Двоичные данные
accessible/macbuild/accessible.mcp

Двоичный файл не отображается.

Двоичные данные
accessible/macbuild/accessibleIDL.mcp

Двоичный файл не отображается.

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

@ -32,9 +32,14 @@ XPIDL_MODULE= accessibility
XPIDLSRCS = \
nsIAccessibilityService.idl \
nsIAccessible.idl \
nsIAccessibleDocument.idl \
nsIAccessibleEventReceiver.idl \
nsIAccessibleEventListener.idl \
nsIAccessibleSelectable.idl \
$(NULL)
EXPORTS = \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -26,8 +26,13 @@ XPIDL_MODULE=accessibility
XPIDLSRCS = \
.\nsIAccessibilityService.idl \
.\nsIAccessible.idl \
.\nsIAccessibleDocument.idl \
.\nsIAccessibleEventReceiver.idl \
.\nsIAccessibleEventListener.idl \
.\nsIAccessibleSelectable.idl \
$(NULL)
EXPORTS = \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -28,22 +28,28 @@
#include "domstubs.idl"
#include "nsIAccessible.idl"
interface nsIWeakReference;
[scriptable, uuid(68D9720A-0984-42b6-A3F5-8237ED925727)]
interface nsIAccessibilityService : nsISupports
{
nsIAccessible createRootAccessible(in nsISupports aPresContext, in nsISupports aFrame);
nsIAccessible createHTMLSelectAccessible(in nsIAtom aAccessible, in nsIDOMNode aNode, in nsISupports aPresShell);
nsIAccessible createHTMLSelectAccessible(in nsIDOMNode aNode, in nsISupports aPresShell);
nsIAccessible createHTMLSelectOptionAccessible(in nsIDOMNode aNode, in nsIAccessible aAccParent, in nsISupports aPresShell);
nsIAccessible createHTMLCheckboxAccessible(in nsISupports aFrame);
nsIAccessible createHTMLRadioButtonAccessible(in nsISupports aFrame);
nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame);
nsIAccessible createHTML4ButtonAccessible(in nsISupports aFrame);
nsIAccessible createHTMLTextAccessible(in nsISupports aFrame);
nsIAccessible createHTMLImageAccessible(in nsISupports aFrame);
nsIAccessible createHTMLAreaAccessible(in nsISupports aPresShell, in nsIDOMNode aDOMNode, in nsIAccessible aAccParent);
nsIAccessible createHTMLAreaAccessible(in nsIWeakReference aPresShell, in nsIDOMNode aDOMNode, in nsIAccessible aAccParent);
nsIAccessible createHTMLTableAccessible(in nsISupports aFrame);
nsIAccessible createHTMLTableCellAccessible(in nsISupports aFrame);
nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame);
nsIAccessible createHTMLIFrameAccessible(in nsIDOMNode aNode, in nsISupports aPresContext);
nsIAccessible createHTMLBlockAccessible(in nsIDOMNode aNode, in nsISupports aDocument);
nsIAccessible createAccessible(in nsIDOMNode aNode, in nsISupports aDocument);
nsIAccessible GetAccessibleFor(in nsIWeakReference aPresShell, in nsIDOMNode aNode);
};

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

@ -26,29 +26,28 @@
#include "nsISupports.idl"
#include "nsIDOMNode.idl"
#include "domstubs.idl"
[scriptable, uuid(B26FBE47-9A5F-42a1-822B-082461AE4D6D)]
interface nsIAccessible : nsISupports
{
nsIAccessible getAccParent();
nsIAccessible getAccNextSibling();
nsIAccessible getAccPreviousSibling();
nsIAccessible getAccFirstChild();
nsIAccessible getAccLastChild();
readonly attribute nsIAccessible accParent;
readonly attribute nsIAccessible accNextSibling;
readonly attribute nsIAccessible accPreviousSibling;
readonly attribute nsIAccessible accFirstChild;
readonly attribute nsIAccessible accLastChild;
long getAccChildCount();
wstring getAccName();
wstring getAccValue();
void setAccName(in wstring name);
void setAccValue(in wstring value);
readonly attribute long accChildCount;
attribute DOMString accName;
readonly attribute DOMString accValue;
wstring getAccDescription();
unsigned long getAccRole();
unsigned long getAccState();
unsigned long getAccExtState();
readonly attribute DOMString accDescription;
readonly attribute unsigned long accRole;
readonly attribute unsigned long accState;
readonly attribute unsigned long accExtState;
wstring getAccHelp();
nsIAccessible getAccFocused();
readonly attribute DOMString accHelp;
readonly attribute nsIAccessible accFocused;
nsIAccessible accGetAt(in long x, in long y);
@ -68,8 +67,8 @@ interface nsIAccessible : nsISupports
void accTakeSelection();
void accTakeFocus();
PRUint8 getAccNumActions();
wstring getAccActionName(in PRUint8 index);
readonly attribute PRUint8 accNumActions;
DOMString getAccActionName(in PRUint8 index);
void accDoAction(in PRUint8 index); // Action number 0 is the default action
nsIDOMNode accGetDOMNode();

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

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author: Aaron Leventhal
*
* Contributor(s):
* John Gaunt
*/
#include "nsISupports.idl"
#include "nsIAccessible.idl"
#include "domstubs.idl"
interface nsIDocument;
[scriptable, uuid(8781FC88-355F-4439-881F-6504A0A1CEB6)]
interface nsIAccessibleDocument : nsISupports
{
readonly attribute DOMString URL;
readonly attribute DOMString title;
readonly attribute DOMString mimeType;
readonly attribute DOMString docType;
DOMString getNameSpaceURIForID(in short nameSpaceID);
[noscript] nsIDocument getDocument();
};

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

@ -0,0 +1,34 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author: John Gaunt (jgaunt@netscape.com)
*
* Contributor(s):
* John Gaunt
*/
#include "nsISupports.idl"
#include "nsIAccessible.idl"
#include "nsISupportsArray.idl"
[scriptable, uuid(34d268d6-1dd2-11b2-9d63-83a5e0ada290)]
interface nsIAccessibleSelectable : nsISupports
{
nsISupportsArray GetSelectedChildren();
};

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

@ -41,10 +41,14 @@ CPPSRCS = \
nsHTMLImageAccessible.cpp \
nsHTMLAreaAccessible.cpp \
nsHTMLLinkAccessible.cpp \
nsSelectAccessible.cpp \
nsHTMLSelectAccessible.cpp \
nsGenericAccessible.cpp \
$(NULL)
EXPORTS = \
nsRootAccessible.h \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.
FORCE_STATIC_LIB = 1

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

@ -33,14 +33,18 @@
#include "nsIFrame.h"
#include "nsRootAccessible.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsLayoutAtoms.h"
#include "nsSelectAccessible.h"
#include "nsIDOMNode.h"
#include "nsHTMLTextAccessible.h"
#include "nsHTMLTableAccessible.h"
#include "nsHTMLImageAccessible.h"
#include "nsHTMLAreaAccessible.h"
#include "nsHTMLLinkAccessible.h"
#include "nsHTMLSelectAccessible.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsILink.h"
#include "nsIDocShellTreeItem.h"
// IFrame
#include "nsIDocShell.h"
@ -52,7 +56,6 @@
nsAccessibilityService::nsAccessibilityService()
{
NS_INIT_REFCNT();
//printf("################################## nsAccessibilityService\n");
}
nsAccessibilityService::~nsAccessibilityService()
@ -80,60 +83,76 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo
NS_ASSERTION(s,"Error not presshell!!");
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(s)));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(s);
//printf("################################## CreateRootAccessible\n");
*_retval = new nsRootAccessible(wr);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLSelectAccessible(nsIAtom* aPopupAtom, nsIDOMNode* node, nsISupports* aPresContext, nsIAccessible **_retval)
nsAccessibilityService::CreateHTMLSelectAccessible(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));
nsCOMPtr<nsIWeakReference> wr = getter_AddRefs(NS_GetWeakReference(s));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(s);
*_retval = new nsSelectAccessible(aPopupAtom, nsnull, node, wr);
*_retval = new nsHTMLSelectAccessible(node, wr);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
*/
return NS_ERROR_FAILURE;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLSelectOptionAccessible(nsIDOMNode* node, nsIAccessible *aAccParent, nsISupports* aPresContext, nsIAccessible **_retval)
{
nsCOMPtr<nsIPresContext> c(do_QueryInterface(aPresContext));
NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!");
nsCOMPtr<nsIPresShell> s;
c->GetShell(getter_AddRefs(s));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(s);
*_retval = new nsHTMLSelectOptionAccessible(aAccParent, node, wr);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLCheckboxAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
NS_IMETHODIMP nsAccessibilityService::CreateHTMLCheckboxAccessible(nsISupports *aFrame, nsIAccessible **_retval)
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLCheckboxAccessible(shell,node);
*_retval = new nsHTMLCheckboxAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMRadioButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -141,17 +160,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupport
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLRadioButtonAccessible(shell,node);
*_retval = new nsHTMLRadioButtonAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -159,17 +179,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLButtonAccessible(nsISupports *aF
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLButtonAccessible(shell,node);
*_retval = new nsHTMLButtonAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTML4ButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -177,17 +198,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTML4ButtonAccessible(nsISupports *a
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTML4ButtonAccessible(shell,node);
*_retval = new nsHTML4ButtonAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLTextAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -195,18 +217,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextAccessible(nsISupports *aFra
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
//printf("################################## CreateHTMLTextAccessible\n");
*_retval = new nsHTMLTextAccessible(shell, node);
*_retval = new nsHTMLTextAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
@ -215,17 +237,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTableAccessible(nsISupports *aFr
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLTableAccessible(shell, node);
*_retval = new nsHTMLTableAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLTableCellAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -233,17 +256,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTableCellAccessible(nsISupports
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLTableCellAccessible(shell, node);
*_retval = new nsHTMLTableCellAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLImageAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -251,35 +275,39 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFr
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIImageFrame> imageFrame(do_QueryInterface(aFrame));
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(shell, node, imageFrame);
*_retval = new nsHTMLImageAccessible(node, imageFrame, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLAreaAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
NS_IMETHODIMP nsAccessibilityService::CreateHTMLAreaAccessible(nsISupports *aShell, nsIDOMNode *aDOMNode, nsIAccessible *aAccParent,
NS_IMETHODIMP nsAccessibilityService::CreateHTMLAreaAccessible(nsIWeakReference *aShell, nsIDOMNode *aDOMNode, nsIAccessible *aAccParent,
nsIAccessible **_retval)
{
nsCOMPtr<nsIPresShell> shell(do_QueryInterface(aShell));
*_retval = new nsHTMLAreaAccessible(shell, aDOMNode, aAccParent);
*_retval = new nsHTMLAreaAccessible(aDOMNode, aAccParent, aShell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
@ -288,20 +316,21 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLTextFieldAccessible(shell, node);
*_retval = new nsHTMLTextFieldAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aNode)
NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aNode)
{
*aRealFrame = NS_STATIC_CAST(nsIFrame*, aFrame);
nsCOMPtr<nsIContent> content;
@ -322,7 +351,66 @@ NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aR
NS_ASSERTION(shells > 0,"Error no shells!");
#endif
return document->GetShellAt(0, aShell);
// do_GetWR only works into a |nsCOMPtr| :-(
nsCOMPtr<nsIPresShell> tempShell;
nsCOMPtr<nsIWeakReference> weak;
document->GetShellAt(0, getter_AddRefs(tempShell));
weak = do_GetWeakReference(tempShell);
NS_IF_ADDREF(*aShell = weak);
return NS_OK;
}
NS_IMETHODIMP
nsAccessibilityService::CreateAccessible(nsIDOMNode* node, nsISupports* document, nsIAccessible **_retval)
{
nsCOMPtr<nsIContent> content (do_QueryInterface(node));
nsCOMPtr<nsIDocument> d (do_QueryInterface(document));
if (!d)
return NS_ERROR_FAILURE;
#ifdef DEBUG
PRInt32 shells = d->GetNumberOfShells();
NS_ASSERTION(shells > 0,"Error no shells!");
#endif
nsCOMPtr<nsIPresShell> tempShell;
d->GetShellAt(0, getter_AddRefs(tempShell));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(tempShell);
*_retval = new nsAccessible(node, wr);
if ( *_retval ) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLBlockAccessible(nsIDOMNode* node, nsISupports* document, nsIAccessible **_retval)
{
nsCOMPtr<nsIContent> content (do_QueryInterface(node));
nsCOMPtr<nsIDocument> d (do_QueryInterface(document));
if (!d)
return NS_ERROR_FAILURE;
#ifdef DEBUG
PRInt32 shells = d->GetNumberOfShells();
NS_ASSERTION(shells > 0,"Error no shells!");
#endif
nsCOMPtr<nsIPresShell> tempShell;
d->GetShellAt(0, getter_AddRefs(tempShell));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(tempShell);
*_retval = new nsAccessible(node, wr);
if ( *_retval ) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
@ -340,7 +428,7 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports
presContext->GetShell(getter_AddRefs(presShell));
NS_ASSERTION(presShell,"Error non PresShell passed to accessible factory!!!");
nsCOMPtr<nsIWeakReference> weakRef (getter_AddRefs(NS_GetWeakReference(presShell)));
nsCOMPtr<nsIWeakReference> weakRef = do_GetWeakReference(presShell);
nsCOMPtr<nsIDocument> doc;
if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc))) && doc) {
@ -355,13 +443,22 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports
nsCOMPtr<nsIPresShell> ps;
docShell->GetPresShell(getter_AddRefs(ps));
if (ps) {
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(ps)));
//printf("################################## CreateHTMLIFrameAccessible\n");
nsCOMPtr<nsIAccessible> root = new nsHTMLIFrameRootAccessible(wr,node);
*_retval = new nsHTMLIFrameAccessible(presShell, node, root);
NS_ADDREF(*_retval);
return NS_OK;
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(ps);
nsCOMPtr<nsIDocument> innerDoc;
ps->GetDocument(getter_AddRefs(innerDoc));
if (innerDoc) {
nsCOMPtr<nsIAccessible> root = new nsHTMLIFrameRootAccessible(node, wr);
if ( root ) {
nsHTMLIFrameAccessible* frameAcc = new nsHTMLIFrameAccessible(node, root, weakRef, innerDoc);
if ( frameAcc != nsnull ) {
*_retval = NS_STATIC_CAST(nsIAccessible*, frameAcc);
if ( *_retval ) {
NS_ADDREF(*_retval);
return NS_OK;
}
}
}
}
}
}
}
@ -371,6 +468,155 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports
}
//-----------------------------------------------------------------------
// This method finds the content node in the parent document
// corresponds to the docshell
// This code is copied and pasted from nsEventStateManager.cpp
// Is also inefficient - better solution should come along as part of
// Bug 85602: "FindContentForDocShell walks entire content tree"
// Hopefully there will be a better method soon, with a public interface
nsIContent*
nsAccessibilityService::FindContentForDocShell(nsIPresShell* aPresShell,
nsIContent* aContent,
nsIDocShell* aDocShell)
{
NS_ASSERTION(aPresShell, "Pointer is null!");
NS_ASSERTION(aDocShell, "Pointer is null!");
NS_ASSERTION(aContent, "Pointer is null!");
nsCOMPtr<nsISupports> supps;
aPresShell->GetSubShellFor(aContent, getter_AddRefs(supps));
if (supps) {
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(supps));
if (docShell.get() == aDocShell)
return aContent;
}
// walk children content
PRInt32 count;
aContent->ChildCount(count);
for (PRInt32 i=0;i<count;i++) {
nsCOMPtr<nsIContent> child;
aContent->ChildAt(i, *getter_AddRefs(child));
nsIContent* foundContent = FindContentForDocShell(aPresShell, child, aDocShell);
if (foundContent != nsnull) {
return foundContent;
}
}
return nsnull;
}
void nsAccessibilityService::GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent)
{
nsCOMPtr<nsIPresContext> presContext;
aPresShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext)
return;
nsCOMPtr<nsISupports> pcContainer;
presContext->GetContainer(getter_AddRefs(pcContainer));
if (!pcContainer)
return;
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(pcContainer));
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docShell));
if (!treeItem)
return;
// Get Parent Doc
nsCOMPtr<nsIDocShellTreeItem> treeItemParent;
treeItem->GetParent(getter_AddRefs(treeItemParent));
if (!treeItemParent)
return;
nsCOMPtr<nsIDocShell> parentDS(do_QueryInterface(treeItemParent));
if (!parentDS)
return;
nsCOMPtr<nsIPresShell> parentPresShell;
parentDS->GetPresShell(getter_AddRefs(parentPresShell));
if (!parentPresShell)
return;
nsCOMPtr<nsIDocument> parentDoc;
parentPresShell->GetDocument(getter_AddRefs(parentDoc));
if (!parentDoc)
return;
nsCOMPtr<nsIContent> rootContent;
parentDoc->GetRootContent(getter_AddRefs(rootContent));
nsIContent *tempContent;
tempContent = FindContentForDocShell(parentPresShell, rootContent, docShell);
if (tempContent) {
*aOwnerContent = tempContent;
*aOwnerShell = parentPresShell;
NS_ADDREF(*aOwnerShell);
NS_ADDREF(*aOwnerContent);
}
}
/* nsIAccessible GetAccessibleFor (in nsISupports aPresShell, in nsIDOMNode aNode); */
NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIWeakReference *aPresShell, nsIDOMNode *aNode,
nsIAccessible **_retval)
{
*_retval = nsnull;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aPresShell));
if (!shell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMHTMLAreaElement> areaContent(do_QueryInterface(aNode));
if (areaContent) // Area elements are implemented in nsHTMLImageAccessible as children of the image
return PR_FALSE; // Return, otherwise the image frame looks like an accessible object in the wrong place
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aNode));
if (!content && doc) {
// This happens when we're on the document node, which will not QI to an nsIContent,
// When that happens, we try to get the outer, parent document node that contains the document
// For example, a <browser> or <iframe> element
nsCOMPtr<nsIPresShell> ownerShell;
nsCOMPtr<nsIContent> ownerContent;
GetOwnerFor(shell, getter_AddRefs(ownerShell), getter_AddRefs(ownerContent));
shell = ownerShell;
content = ownerContent;
}
if (!content)
return PR_FALSE;
nsIFrame* frame = nsnull;
shell->GetPrimaryFrameFor(content, &frame);
if (!frame)
return PR_FALSE;
nsCOMPtr<nsIAccessible> newAcc;
frame->GetAccessible(getter_AddRefs(newAcc));
if (!newAcc)
newAcc = do_QueryInterface(aNode);
if (!newAcc) {
// is it a link?
nsCOMPtr<nsILink> link(do_QueryInterface(aNode));
if (link) {
newAcc = new nsHTMLLinkAccessible(aNode, aPresShell);
}
}
if (!newAcc)
return NS_ERROR_FAILURE;
*_retval = newAcc;
NS_ADDREF(*_retval);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

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

@ -27,8 +27,12 @@
#define __nsAccessibilityService_h__
#include "nsIAccessibilityService.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsIDocShell.h"
class nsIFrame;
class nsIPresShell;
class nsIWeakReference;
class nsIDOMNode;
class nsAccessibilityService : public nsIAccessibilityService
@ -46,7 +50,9 @@ public:
public:
private:
NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aContent);
NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aContent);
void GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent);
nsIContent* FindContentForDocShell(nsIPresShell* aPresShell, nsIContent* aContent, nsIDocShell* aDocShell);
};

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

@ -21,6 +21,7 @@
*/
#include "nsAccessible.h"
#include "nsIAccessibilityService.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
@ -34,13 +35,30 @@
#include "nsIDOMElement.h"
#include "nsIEventStateManager.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsILink.h"
#include "nsHTMLLinkAccessible.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsXPIDLString.h"
#include "nsIDOMComment.h"
#include "nsITextContent.h"
#include "nsIEventStateManager.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLBRElement.h"
#include "nsIAtom.h"
#include "nsHTMLAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsGUIEvent.h"
#include "nsILink.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsReadableUtils.h"
// IFrame Helpers
#include "nsIDocShell.h"
#include "nsIWebShell.h"
@ -398,6 +416,7 @@ public:
nsCOMPtr<nsIWeakReference> mPresShell;
nsCOMPtr<nsIAccessible> mAccessible;
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIAccessibilityService> mAccService;
};
nsDOMTreeWalker::nsDOMTreeWalker(nsIWeakReference* aPresShell, nsIDOMNode* aNode)
@ -405,6 +424,7 @@ nsDOMTreeWalker::nsDOMTreeWalker(nsIWeakReference* aPresShell, nsIDOMNode* aNode
mDOMNode = aNode;
mAccessible = nsnull;
mPresShell = aPresShell;
mAccService = do_GetService("@mozilla.org/accessibilityService;1");
}
nsRect nsDOMTreeWalker::GetBounds()
@ -420,6 +440,9 @@ nsRect nsDOMTreeWalker::GetBounds()
nsIFrame* nsDOMTreeWalker::GetPrimaryFrame()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return nsnull;
nsIFrame* frame = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
shell->GetPrimaryFrameFor(content, &frame);
@ -472,7 +495,7 @@ PRBool nsDOMTreeWalker::GetParent()
if (!accessible)
accessible = do_QueryInterface(content);
if (accessible) {
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(parentPresShell)));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(parentPresShell);
accessible->AccGetDOMNode(getter_AddRefs(mDOMNode));
mAccessible = accessible;
mPresShell = wr;
@ -721,37 +744,15 @@ PRBool nsDOMTreeWalker::GetAccessible()
{
mAccessible = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
if (!content)
if (!mAccService)
return PR_FALSE;
nsCOMPtr<nsIDOMHTMLAreaElement> areaContent(do_QueryInterface(mDOMNode));
if (areaContent) // Area elements are implemented in nsHTMLImageAccessible as children of the image
return PR_FALSE; // Return, otherwise the image frame looks like an accessible object in the wrong place
nsIFrame* frame = GetPrimaryFrame();
if (!frame)
return PR_FALSE;
frame->GetAccessible(getter_AddRefs(mAccessible));
if (!mAccessible)
mAccessible = do_QueryInterface(mDOMNode);
if (!mAccessible) {
// is it a link?
nsCOMPtr<nsILink> link(do_QueryInterface(mDOMNode));
if (link) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
mAccessible = new nsHTMLLinkAccessible(shell, mDOMNode);
}
}
mAccService->GetAccessibleFor(mPresShell, mDOMNode, getter_AddRefs(mAccessible));
if (mAccessible)
return PR_TRUE;
else
return PR_FALSE;
return PR_FALSE;
}
@ -759,22 +760,21 @@ PRBool nsDOMTreeWalker::GetAccessible()
* Class nsAccessible
*/
//-----------------------------------------------------
//-------------------------`----------------------------
// construction
//-----------------------------------------------------
nsAccessible::nsAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
nsAccessible::nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell)
{
NS_INIT_REFCNT();
// get frame and node
mDOMNode = aNode;
mAccessible = aAccessible;
mPresShell = aShell;
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (shell)
shell->GetDocument(getter_AddRefs(document));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
if (content)
content->GetDocument(*getter_AddRefs(document));
if (document) {
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
document->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
@ -815,24 +815,14 @@ nsAccessible::~nsAccessible()
#endif
}
NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible);
nsresult nsAccessible::GetAccParent(nsIAccessible ** aAccParent)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccParent(aAccParent);
if (NS_SUCCEEDED(rv))
return rv;
}
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
nsDOMTreeWalker walker(mPresShell, mDOMNode);
if (walker.GetParent()) {
*aAccParent = CreateNewParentAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccParent = walker.mAccessible;
NS_ADDREF(*aAccParent);
return NS_OK;
}
@ -844,23 +834,13 @@ nsresult nsAccessible::GetAccParent(nsIAccessible ** aAccParent)
/* readonly attribute nsIAccessible accNextSibling; */
NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccNextSibling(aAccNextSibling);
if (NS_SUCCEEDED(rv))
return rv;
}
// failed? Lets do some default behavior
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetNextSibling();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccNextSibling = CreateNewNextAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccNextSibling = walker.mAccessible;
NS_ADDREF(*aAccNextSibling);
return NS_OK;
}
@ -872,22 +852,14 @@ NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
/* readonly attribute nsIAccessible accPreviousSibling; */
NS_IMETHODIMP nsAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousSibling)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccPreviousSibling(aAccPreviousSibling);
if (NS_SUCCEEDED(rv))
return rv;
}
{
// failed? Lets do some default behavior
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetPreviousSibling();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccPreviousSibling = CreateNewPreviousAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccPreviousSibling = walker.mAccessible;
NS_ADDREF(*aAccPreviousSibling);
return NS_OK;
}
@ -900,19 +872,12 @@ NS_IMETHODIMP nsAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousS
/* readonly attribute nsIAccessible accFirstChild; */
NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccFirstChild(aAccFirstChild);
if (NS_SUCCEEDED(rv))
return rv;
}
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetFirstChild();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccFirstChild = CreateNewFirstAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccFirstChild = walker.mAccessible;
NS_ADDREF(*aAccFirstChild);
return NS_OK;
}
@ -925,19 +890,12 @@ NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
/* readonly attribute nsIAccessible accFirstChild; */
NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccLastChild)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccLastChild(aAccLastChild);
if (NS_SUCCEEDED(rv))
return rv;
}
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetLastChild();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccLastChild = CreateNewLastAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccLastChild = walker.mAccessible;
NS_ADDREF(*aAccLastChild);
return NS_OK;
}
@ -950,48 +908,12 @@ NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccLastChild)
/* readonly attribute long accChildCount; */
NS_IMETHODIMP nsAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccChildCount(aAccChildCount);
if (NS_SUCCEEDED(rv))
return rv;
}
// failed? Lets do some default behavior
nsDOMTreeWalker walker(mPresShell, mDOMNode);
*aAccChildCount = walker.GetCount();
return NS_OK;
}
/* attribute wstring accName; */
NS_IMETHODIMP nsAccessible::GetAccName(PRUnichar * *aAccName)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccName(aAccName);
if (NS_SUCCEEDED(rv) && *aAccName != nsnull)
return rv;
}
*aAccName = 0;
return NS_ERROR_NOT_IMPLEMENTED;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 0;
if (mAccessible)
mAccessible->GetAccNumActions(_retval);
return NS_OK;
}
nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *aStringOut)
{
static nsCOMPtr<nsIStringBundle> stringBundle;
@ -1018,101 +940,12 @@ nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *a
return NS_OK;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
{
PRUint8 numActions;
*_retval = 0;
if (mAccessible && NS_SUCCEEDED(GetAccNumActions(&numActions)) && index<numActions) {
nsresult rv = mAccessible->GetAccActionName(index, _retval);
if (*_retval && NS_SUCCEEDED(rv)) {
nsAutoString newString;
rv = GetTranslatedString(*_retval, &newString);
if (NS_SUCCEEDED(rv)) {
delete *_retval;
*_retval = newString.ToNewUnicode();
}
}
return NS_OK; // keep key for name if can't get translated version
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::AccDoAction(PRUint8 index)
{
PRUint8 numActions;
return (mAccessible && NS_SUCCEEDED(GetAccNumActions(&numActions)) && index<numActions)?
mAccessible->AccDoAction(index): NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsAccessible::SetAccName(const PRUnichar * aAccName)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->SetAccName(aAccName);
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute wstring accValue; */
NS_IMETHODIMP nsAccessible::GetAccValue(PRUnichar * *aAccValue)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccValue(aAccValue);
if (NS_SUCCEEDED(rv) && *aAccValue != nsnull)
return rv;
}
*aAccValue = 0;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsAccessible::SetAccValue(const PRUnichar * aAccValue) { return NS_ERROR_NOT_IMPLEMENTED; }
/* readonly attribute wstring accDescription; */
NS_IMETHODIMP nsAccessible::GetAccDescription(PRUnichar * *aAccDescription)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccDescription(aAccDescription);
if (NS_SUCCEEDED(rv) && *aAccDescription != nsnull)
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute unsigned long accRole; */
NS_IMETHODIMP nsAccessible::GetAccRole(PRUint32 *aAccRole)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccRole(aAccRole);
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute wstring accState; */
/* readonly attribute wstring accState; */
NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState)
{
nsresult rv = NS_OK;
*aAccState = 0;
// delegate
if (mAccessible)
rv = mAccessible->GetAccState(aAccState);
if (NS_SUCCEEDED(rv) && mFocusController) {
nsCOMPtr<nsIDOMElement> focusedElement, currElement(do_QueryInterface(mDOMNode));
mFocusController->GetFocusedElement(getter_AddRefs(focusedElement));
@ -1123,29 +956,6 @@ NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState)
return rv;
}
NS_IMETHODIMP nsAccessible::GetAccExtState(PRUint32 *aAccExtState)
{
// delegate
if (mAccessible)
return mAccessible->GetAccExtState(aAccExtState);
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute wstring accHelp; */
NS_IMETHODIMP nsAccessible::GetAccHelp(PRUnichar * *aAccHelp)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccHelp(aAccHelp);
if (NS_SUCCEEDED(rv) && *aAccHelp != nsnull)
return rv;
}
// failed? Lets do some default behavior
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute boolean accFocused; */
NS_IMETHODIMP nsAccessible::GetAccFocused(nsIAccessible * *aAccFocused)
{
@ -1157,6 +967,11 @@ NS_IMETHODIMP nsAccessible::GetAccFocused(nsIAccessible * *aAccFocused)
nsIFrame *frame = nsnull;
if (focusedElement) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
*aAccFocused = nsnull;
return NS_OK;
}
nsCOMPtr<nsIContent> content(do_QueryInterface(focusedElement));
if (shell && content)
shell->GetPrimaryFrameFor(content, &frame);
@ -1210,86 +1025,6 @@ NS_IMETHODIMP nsAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_re
return NS_OK;
}
/* void accNavigateRight (); */
NS_IMETHODIMP nsAccessible::AccNavigateRight(nsIAccessible **_retval) { return NS_OK; }
/* void navigateLeft (); */
NS_IMETHODIMP nsAccessible::AccNavigateLeft(nsIAccessible **_retval) { return NS_OK; }
/* void navigateUp (); */
NS_IMETHODIMP nsAccessible::AccNavigateUp(nsIAccessible **_retval) { return NS_OK; }
/* void navigateDown (); */
NS_IMETHODIMP nsAccessible::AccNavigateDown(nsIAccessible **_retval) { return NS_OK; }
/* void addSelection (); */
NS_IMETHODIMP nsAccessible::AccAddSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccAddSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void removeSelection (); */
NS_IMETHODIMP nsAccessible::AccRemoveSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccRemoveSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void extendSelection (); */
NS_IMETHODIMP nsAccessible::AccExtendSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccExtendSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void takeSelection (); */
NS_IMETHODIMP nsAccessible::AccTakeSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccTakeSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void takeFocus (); */
NS_IMETHODIMP nsAccessible::AccTakeFocus(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccTakeFocus();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsAccessible::AccGetDOMNode(nsIDOMNode **_retval)
{
*_retval = mDOMNode;
@ -1597,12 +1332,6 @@ void nsAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeParent)
/* 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)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccGetBounds(x,y,width,height);
if (NS_SUCCEEDED(rv))
return rv;
}
// This routine will get the entire rectange for all the frames in this node
// -------------------------------------------------------------------------
@ -1661,6 +1390,9 @@ nsIFrame* nsAccessible::GetBoundsFrame()
nsIFrame* nsAccessible::GetFrame()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return nsnull;
nsIFrame* frame = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
shell->GetPrimaryFrameFor(content, &frame);
@ -1677,49 +1409,195 @@ void nsAccessible::GetPresContext(nsCOMPtr<nsIPresContext>& aContext)
aContext = nsnull;
}
nsIAccessible* nsAccessible::CreateNewNextAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
/* void accRemoveSelection (); */
NS_IMETHODIMP nsAccessible::AccRemoveSelection()
{
return CreateNewAccessible(aAccessible, aNode, aShell);
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
if (!control) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mDOMNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
rv = selection->Collapse(parent, 0);
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
nsIAccessible* nsAccessible::CreateNewPreviousAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
/* void accTakeSelection (); */
NS_IMETHODIMP nsAccessible::AccTakeSelection()
{
return CreateNewAccessible(aAccessible, aNode, aShell);
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
if (!control) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mDOMNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
PRInt32 offsetInParent = 0;
nsCOMPtr<nsIDOMNode> child;
rv = parent->GetFirstChild(getter_AddRefs(child));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> next;
while(child)
{
if (child == mDOMNode) {
// Collapse selection to just before desired element,
rv = selection->Collapse(parent, offsetInParent);
if (NS_FAILED(rv))
return rv;
// then extend it to just after
rv = selection->Extend(parent, offsetInParent+1);
return rv;
}
child->GetNextSibling(getter_AddRefs(next));
child = next;
offsetInParent++;
}
// didn't find a child
return NS_ERROR_FAILURE;
}
nsIAccessible* nsAccessible::CreateNewParentAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
return CreateNewAccessible(aAccessible, aNode, aShell);
/* void accTakeFocus (); */
NS_IMETHODIMP nsAccessible::AccTakeFocus()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
content->SetFocus(context);
return NS_OK;
}
nsIAccessible* nsAccessible::CreateNewFirstAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString)
{
return CreateNewAccessible(aAccessible, aNode, aShell);
nsCOMPtr<nsITextContent> textContent(do_QueryInterface(aContent));
if (textContent) {
nsCOMPtr<nsIDOMComment> commentNode(do_QueryInterface(aContent));
if (!commentNode) {
PRBool isHTMLBlock = PR_FALSE;
nsIFrame *frame;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIContent> parentContent;
aContent->GetParent(*getter_AddRefs(parentContent));
if (parentContent) {
nsresult rv = shell->GetPrimaryFrameFor(parentContent, &frame);
if (NS_SUCCEEDED(rv)) {
// If this text is inside a block level frame (as opposed to span level), we need to add spaces around that
// block's text, so we don't get words jammed together in final name
// Extra spaces will be trimmed out later
nsCOMPtr<nsIStyleContext> styleContext;
frame->GetStyleContext(getter_AddRefs(styleContext));
if (styleContext) {
const nsStyleDisplay* display = (const nsStyleDisplay*)styleContext->GetStyleData(eStyleStruct_Display);
if (display->IsBlockLevel() || display->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
isHTMLBlock = PR_TRUE;
aFlatString->Append(NS_LITERAL_STRING(" "));
}
}
}
}
nsAutoString text;
textContent->CopyText(text);
if (text.Length()>0)
aFlatString->Append(text);
if (isHTMLBlock)
aFlatString->Append(NS_LITERAL_STRING(" "));
}
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLBRElement> brElement(do_QueryInterface(aContent));
if (brElement) {
aFlatString->Append(NS_LITERAL_STRING(" "));
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLImageElement> imageContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent(do_QueryInterface(aContent));
if (imageContent || inputContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aContent));
nsAutoString textEquivalent;
elt->GetAttribute(NS_LITERAL_STRING("alt"), textEquivalent);
if (textEquivalent.IsEmpty())
elt->GetAttribute(NS_LITERAL_STRING("title"), textEquivalent);
if (textEquivalent.IsEmpty())
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 NS_OK;
}
nsIAccessible* nsAccessible::CreateNewLastAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
NS_IMETHODIMP nsAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString)
{
return CreateNewAccessible(aAccessible, aNode, aShell);
// Depth first search for all text nodes that are decendants of content node.
// Append all the text into one flat string
PRInt32 numChildren = 0;
aContent->ChildCount(numChildren);
if (numChildren == 0) {
AppendFlatStringFromContentNode(aContent, aFlatString);
return NS_OK;
}
nsIContent *contentWalker;
PRInt32 index;
for (index = 0; index < numChildren; index++) {
aContent->ChildAt(index, contentWalker);
AppendFlatStringFromSubtree(contentWalker, aFlatString);
}
return NS_OK;
}
nsIAccessible* nsAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
NS_ASSERTION(aAccessible && aNode,"Error not accessible or content");
return new nsAccessible(aAccessible, aNode, aShell);
}
// ------- nsHTMLBlockAccessible ------
nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aAccessible, aNode, aShell)
nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aNode, aShell)
{
}
nsIAccessible* nsHTMLBlockAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
NS_ASSERTION(aAccessible && aNode,"Error not accessible or content");
return new nsHTMLBlockAccessible(aAccessible, aNode, aShell);
}
/* nsIAccessible accGetAt (in long x, in long y); */
NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval)
{
@ -1775,7 +1653,170 @@ NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessi
return NS_OK;
}
//-------------
// nsLeafFrameAccessible
//-------------
nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsAccessible(aNode, aShell)
{
}
/* nsIAccessible getAccFirstChild (); */
NS_IMETHODIMP nsLeafAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* nsIAccessible getAccLastChild (); */
NS_IMETHODIMP nsLeafAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* long getAccChildCount (); */
NS_IMETHODIMP nsLeafAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 0;
return NS_OK;
}
//----------------
// nsLinkableAccessible
//----------------
nsLinkableAccessible::nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsAccessible(aNode, aShell), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE)
{
}
/* long GetAccState (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval)
{
nsAccessible::GetAccState(_retval);
*_retval |= STATE_READONLY | STATE_SELECTABLE;
if (IsALink()) {
*_retval |= STATE_FOCUSABLE | STATE_LINKED;
if (mIsLinkVisited)
*_retval |= STATE_TRAVERSED;
}
// Get current selection and find out if current node is in it
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsIFrame *frame;
if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) {
nsCOMPtr<nsISelectionController> selCon;
frame->GetSelectionController(context,getter_AddRefs(selCon));
if (selCon) {
nsCOMPtr<nsISelection> domSel;
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel));
if (domSel) {
PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE;
domSel->ContainsNode(mDOMNode, PR_TRUE, &isSelected);
domSel->GetIsCollapsed(&isCollapsed);
if (isSelected && !isCollapsed)
*_retval |=STATE_SELECTED;
}
}
}
// Focused? Do we implement that here or up the chain?
return NS_OK;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
// Action 0 (default action): Jump to link
if (index == 0) {
if (IsALink()) {
_retval = NS_LITERAL_STRING("jump");
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index)
{
// Action 0 (default action): Jump to link
if (index == 0) {
if (IsALink()) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsMouseEvent linkClickEvent;
linkClickEvent.eventStructType = NS_EVENT;
linkClickEvent.message = NS_MOUSE_LEFT_CLICK;
linkClickEvent.isShift = PR_FALSE;
linkClickEvent.isControl = PR_FALSE;
linkClickEvent.isAlt = PR_FALSE;
linkClickEvent.isMeta = PR_FALSE;
linkClickEvent.clickCount = 0;
linkClickEvent.widget = nsnull;
nsEventStatus eventStatus = nsEventStatus_eIgnore;
mLinkContent->HandleDOMEvent(presContext,
&linkClickEvent,
nsnull,
NS_EVENT_FLAG_INIT,
&eventStatus);
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
PRBool nsLinkableAccessible::IsALink()
{
if (mIsALinkCached) // Cached answer?
return mLinkContent? PR_TRUE: PR_FALSE;
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
if (walkUpContent) {
nsCOMPtr<nsIContent> tempContent = walkUpContent;
while (walkUpContent) {
nsCOMPtr<nsILink> link(do_QueryInterface(walkUpContent));
if (link) {
mLinkContent = tempContent;
mIsALinkCached = PR_TRUE;
nsLinkState linkState;
link->GetLinkState(linkState);
if (linkState == eLinkState_Visited)
mIsLinkVisited = PR_TRUE;
return PR_TRUE;
}
walkUpContent->GetParent(*getter_AddRefs(tempContent));
walkUpContent = tempContent;
}
}
mIsALinkCached = PR_TRUE; // Cached that there is no link
return PR_FALSE;
}

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

@ -24,7 +24,7 @@
#define _nsAccessible_H_
#include "nsISupports.h"
#include "nsIAccessible.h"
#include "nsGenericAccessible.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
@ -42,16 +42,26 @@ class nsIDocShell;
class nsIWebShell;
class nsIContent;
class nsAccessible : public nsIAccessible
// public nsIAccessibleWidgetAccess
class nsAccessible : public nsGenericAccessible
{
NS_DECL_ISUPPORTS
// nsIAccessibilityService methods:
NS_DECL_NSIACCESSIBLE
public:
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccFocused(nsIAccessible **_retval);
NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval);
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
NS_IMETHOD AccRemoveSelection(void);
NS_IMETHOD AccTakeSelection(void);
NS_IMETHOD AccTakeFocus(void);
NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval);
public:
nsAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual ~nsAccessible();
virtual void GetListAtomForFrame(nsIFrame* aFrame, nsIAtom*& aList) { aList = nsnull; }
@ -87,28 +97,53 @@ protected:
virtual nsIFrame* GetBoundsFrame();
virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual void GetPresContext(nsCOMPtr<nsIPresContext>& aContext);
virtual nsIAccessible* CreateNewNextAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewPreviousAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewParentAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewFirstAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewLastAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString);
NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString);
// Data Members
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIWeakReference> mPresShell;
nsCOMPtr<nsIAccessible> mAccessible;
nsCOMPtr<nsIFocusController> mFocusController;
};
/* Special Accessible that knows how to handle hit detection for flowing text */
class nsHTMLBlockAccessible : public nsAccessible
{
public:
nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval);
protected:
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aFrame, nsIWeakReference* aShell);
};
/* Leaf version of DOM Accessible
* has no children
*/
class nsLeafAccessible : public nsAccessible
{
public:
nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
};
class nsLinkableAccessible : public nsAccessible
{
public:
nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccState(PRUint32 *_retval);
protected:
PRBool IsALink();
PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link
nsCOMPtr<nsIContent> mLinkContent;
PRBool mIsLinkVisited;
};
#endif

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

@ -22,25 +22,11 @@
*/
#include "nsGenericAccessible.h"
#include "nsIEventStateManager.h"
#include "nsIFrame.h"
#include "nsCOMPtr.h"
#include "nsIWeakReference.h"
#include "nsReadableUtils.h"
#include "nsILink.h"
#include "nsIContent.h"
#include "nsITextContent.h"
#include "nsIDOMComment.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLBRElement.h"
#include "nsIAtom.h"
#include "nsHTMLAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsGUIEvent.h"
/* Implementation file */
NS_IMPL_ISUPPORTS1(nsGenericAccessible, nsIAccessible)
@ -93,31 +79,25 @@ NS_IMETHODIMP nsGenericAccessible::GetAccChildCount(PRInt32 *_retval)
}
/* wstring getAccName (); */
NS_IMETHODIMP nsGenericAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccName(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* wstring getAccValue (); */
NS_IMETHODIMP nsGenericAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccValue(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void setAccName (in wstring name); */
NS_IMETHODIMP nsGenericAccessible::SetAccName(const PRUnichar *name)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void setAccValue (in wstring value); */
NS_IMETHODIMP nsGenericAccessible::SetAccValue(const PRUnichar *value)
NS_IMETHODIMP nsGenericAccessible::SetAccName(const nsAReadableString& name)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* wstring getAccDescription (); */
NS_IMETHODIMP nsGenericAccessible::GetAccDescription(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccDescription(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -141,7 +121,7 @@ NS_IMETHODIMP nsGenericAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsGenericAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -159,7 +139,7 @@ NS_IMETHODIMP nsGenericAccessible::GetAccFocused(nsIAccessible **_retval)
}
/* wstring getAccHelp (); */
NS_IMETHODIMP nsGenericAccessible::GetAccHelp(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccHelp(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -241,356 +221,4 @@ NS_IMETHODIMP nsGenericAccessible::AccGetDOMNode(nsIDOMNode **_retval)
return NS_ERROR_NOT_IMPLEMENTED;
}
//-------------
// nsDOMAccessible
//-------------
NS_IMETHODIMP
nsDOMAccessible::QueryInterface(REFNSIID aIID, void** aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(NS_GET_IID(nsIDOMNode))) {
nsIDOMNode* node = mNode;
*aResult = (void*) node;
NS_ADDREF(node);
return NS_OK;
}
return nsGenericAccessible::QueryInterface(aIID, aResult);
}
nsDOMAccessible::nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode)
{
mPresShell = do_GetWeakReference(aShell);
mNode = aNode;
}
NS_IMETHODIMP nsDOMAccessible::AccGetDOMNode(nsIDOMNode **_retval)
{
*_retval = mNode;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
/* void accRemoveSelection (); */
NS_IMETHODIMP nsDOMAccessible::AccRemoveSelection()
{
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
rv = selection->Collapse(parent, 0);
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
/* void accTakeSelection (); */
NS_IMETHODIMP nsDOMAccessible::AccTakeSelection()
{
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
PRInt32 offsetInParent = 0;
nsCOMPtr<nsIDOMNode> child;
rv = parent->GetFirstChild(getter_AddRefs(child));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> next;
while(child)
{
if (child == mNode) {
// Collapse selection to just before desired element,
rv = selection->Collapse(parent, offsetInParent);
if (NS_FAILED(rv))
return rv;
// then extend it to just after
rv = selection->Extend(parent, offsetInParent+1);
return rv;
}
child->GetNextSibling(getter_AddRefs(next));
child = next;
offsetInParent++;
}
// didn't find a child
return NS_ERROR_FAILURE;
}
/* void accTakeFocus (); */
NS_IMETHODIMP nsDOMAccessible::AccTakeFocus()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
content->SetFocus(context);
return NS_OK;
}
NS_IMETHODIMP nsDOMAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString)
{
nsCOMPtr<nsITextContent> textContent(do_QueryInterface(aContent));
if (textContent) {
nsCOMPtr<nsIDOMComment> commentNode(do_QueryInterface(aContent));
if (!commentNode) {
PRBool isHTMLBlock = PR_FALSE;
nsIFrame *frame;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIContent> parentContent;
aContent->GetParent(*getter_AddRefs(parentContent));
if (parentContent) {
nsresult rv = shell->GetPrimaryFrameFor(parentContent, &frame);
if (NS_SUCCEEDED(rv)) {
// If this text is inside a block level frame (as opposed to span level), we need to add spaces around that
// block's text, so we don't get words jammed together in final name
// Extra spaces will be trimmed out later
nsCOMPtr<nsIStyleContext> styleContext;
frame->GetStyleContext(getter_AddRefs(styleContext));
if (styleContext) {
const nsStyleDisplay* display = (const nsStyleDisplay*)styleContext->GetStyleData(eStyleStruct_Display);
if (display->IsBlockLevel() || display->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
isHTMLBlock = PR_TRUE;
aFlatString->Append(NS_LITERAL_STRING(" "));
}
}
}
}
nsAutoString text;
textContent->CopyText(text);
if (text.Length()>0)
aFlatString->Append(text);
if (isHTMLBlock)
aFlatString->Append(NS_LITERAL_STRING(" "));
}
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLBRElement> brElement(do_QueryInterface(aContent));
if (brElement) {
aFlatString->Append(NS_LITERAL_STRING(" "));
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLImageElement> imageContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent(do_QueryInterface(aContent));
if (imageContent || inputContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aContent));
nsAutoString textEquivalent;
elt->GetAttribute(NS_LITERAL_STRING("alt"), textEquivalent);
if (textEquivalent.IsEmpty())
elt->GetAttribute(NS_LITERAL_STRING("title"), textEquivalent);
if (textEquivalent.IsEmpty())
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 NS_OK;
}
NS_IMETHODIMP nsDOMAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString)
{
// Depth first search for all text nodes that are decendants of content node.
// Append all the text into one flat string
PRInt32 numChildren = 0;
aContent->ChildCount(numChildren);
if (numChildren == 0) {
nsAutoString contentText;
AppendFlatStringFromContentNode(aContent, aFlatString);
return NS_OK;
}
nsIContent *contentWalker;
PRInt32 index;
for (index = 0; index < numChildren; index++) {
aContent->ChildAt(index, contentWalker);
AppendFlatStringFromSubtree(contentWalker, aFlatString);
}
return NS_OK;
}
//-------------
// nsLeafFrameAccessible
//-------------
nsLeafDOMAccessible::nsLeafDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsDOMAccessible(aShell, aNode)
{
}
/* nsIAccessible getAccFirstChild (); */
NS_IMETHODIMP nsLeafDOMAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* nsIAccessible getAccLastChild (); */
NS_IMETHODIMP nsLeafDOMAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* long getAccChildCount (); */
NS_IMETHODIMP nsLeafDOMAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 0;
return NS_OK;
}
//----------------
// nsLinkableAccessible
//----------------
nsLinkableAccessible::nsLinkableAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsDOMAccessible(aShell, aDomNode), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE)
{
}
/* long GetAccState (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval)
{
*_retval |= STATE_READONLY | STATE_SELECTABLE;
if (IsALink()) {
*_retval |= STATE_FOCUSABLE | STATE_LINKED;
if (mIsLinkVisited)
*_retval |= STATE_TRAVERSED;
}
// Get current selection and find out if current node is in it
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
nsIFrame *frame;
if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) {
nsCOMPtr<nsISelectionController> selCon;
frame->GetSelectionController(context,getter_AddRefs(selCon));
if (selCon) {
nsCOMPtr<nsISelection> domSel;
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel));
if (domSel) {
PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE;
domSel->ContainsNode(mNode, PR_TRUE, &isSelected);
domSel->GetIsCollapsed(&isCollapsed);
if (isSelected && !isCollapsed)
*_retval |=STATE_SELECTED;
}
}
}
// Focused? Do we implement that here or up the chain?
return NS_OK;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
{
if (index == 0) {
if (IsALink()) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("jump"));
return NS_OK;
}
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
if (IsALink()) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsMouseEvent linkClickEvent;
linkClickEvent.eventStructType = NS_EVENT;
linkClickEvent.message = NS_MOUSE_LEFT_CLICK;
linkClickEvent.isShift = PR_FALSE;
linkClickEvent.isControl = PR_FALSE;
linkClickEvent.isAlt = PR_FALSE;
linkClickEvent.isMeta = PR_FALSE;
linkClickEvent.clickCount = 0;
linkClickEvent.widget = nsnull;
nsEventStatus eventStatus = nsEventStatus_eIgnore;
mLinkContent->HandleDOMEvent(presContext, &linkClickEvent,
nsnull, NS_EVENT_FLAG_INIT, &eventStatus);
return NS_OK;
}
}
}
return NS_ERROR_NOT_IMPLEMENTED;
}
PRBool nsLinkableAccessible::IsALink()
{
if (mIsALinkCached) // Cached answer?
return mLinkContent? PR_TRUE: PR_FALSE;
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mNode));
if (walkUpContent) {
nsCOMPtr<nsIContent> tempContent = walkUpContent;
while (walkUpContent) {
nsCOMPtr<nsILink> link(do_QueryInterface(walkUpContent));
if (link) {
mLinkContent = tempContent;
mIsALinkCached = PR_TRUE;
nsLinkState linkState;
link->GetLinkState(linkState);
if (linkState == eLinkState_Visited)
mIsLinkVisited = PR_TRUE;
return PR_TRUE;
}
walkUpContent->GetParent(*getter_AddRefs(tempContent));
walkUpContent = tempContent;
}
}
mIsALinkCached = PR_TRUE; // Cached that there is no link
return PR_FALSE;
}

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

@ -47,61 +47,5 @@ class nsGenericAccessible : public nsIAccessible
virtual ~nsGenericAccessible();
};
/**
* And accessible that observes a dom node
* supports:
* - selection
* - focus
*/
class nsDOMAccessible : public nsGenericAccessible
{
public:
nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD AccTakeSelection(void);
NS_IMETHOD AccTakeFocus(void);
NS_IMETHOD AccRemoveSelection(void);
NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval);
protected:
NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString);
NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString);
nsCOMPtr<nsIWeakReference> mPresShell;
nsCOMPtr<nsIDOMNode> mNode;
};
/* Leaf version of DOM Accessible
* has no children
*/
class nsLeafDOMAccessible : public nsDOMAccessible
{
public:
nsLeafDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
};
class nsLinkableAccessible : public nsDOMAccessible
{
public:
nsLinkableAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccState(PRUint32 *_retval);
protected:
nsCOMPtr<nsIDOMNode> mDomNode;
PRBool IsALink();
PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link
nsCOMPtr<nsIContent> mLinkContent;
PRBool mIsLinkVisited;
};
#endif

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

@ -36,8 +36,19 @@
#include "nsHTMLLinkAccessible.h"
#include "nsIURI.h"
#include "nsIDocShellTreeItem.h"
#include "nsIXULDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMNSHTMLSelectElement.h"
#include "nsIAccessibleSelectable.h"
#include "nsIDOMHTMLCollection.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsXPIDLString.h"
NS_INTERFACE_MAP_BEGIN(nsRootAccessible)
NS_INTERFACE_MAP_ENTRY(nsIAccessibleDocument)
NS_INTERFACE_MAP_ENTRY(nsIAccessibleEventReceiver)
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMFormListener)
@ -45,18 +56,23 @@ NS_INTERFACE_MAP_BEGIN(nsRootAccessible)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMFormListener)
NS_INTERFACE_MAP_END_INHERITING(nsAccessible)
NS_IMPL_ADDREF_INHERITED(nsRootAccessible, nsAccessible);
NS_IMPL_RELEASE_INHERITED(nsRootAccessible, nsAccessible);
//-----------------------------------------------------
// construction
//-----------------------------------------------------
nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell):nsAccessible(nsnull,nsnull,aShell)
nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell):nsAccessible(nsnull,aShell), nsDocAccessibleMixin(aShell)
{
mListener = nsnull;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
NS_ASSERTION(shell,"Shell is gone!!! What are we doing here?");
shell->GetDocument(getter_AddRefs(mDocument));
mDOMNode = do_QueryInterface(mDocument);
nsLayoutAtoms::AddRefAtoms();
}
//-----------------------------------------------------
@ -64,24 +80,23 @@ nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell):nsAccessible(nsnull
//-----------------------------------------------------
nsRootAccessible::~nsRootAccessible()
{
nsLayoutAtoms::ReleaseAtoms();
RemoveAccessibleEventListener(mListener);
}
/* attribute wstring accName; */
NS_IMETHODIMP nsRootAccessible::GetAccName(PRUnichar * *aAccName)
NS_IMETHODIMP nsRootAccessible::GetAccName(nsAWritableString& aAccName)
{
const nsString* docTitle = mDocument->GetDocumentTitle();
if (docTitle && !docTitle->IsEmpty())
*aAccName = docTitle->ToNewUnicode();
else *aAccName = ToNewUnicode(NS_LITERAL_STRING("Document"));
return NS_OK;
return GetTitle(aAccName);
}
// helpers
nsIFrame* nsRootAccessible::GetFrame()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return nsnull;
nsIFrame* root = nsnull;
if (shell)
shell->GetRootFrame(&root);
@ -95,11 +110,6 @@ void nsRootAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
(*aRelativeFrame)->GetRect(aBounds);
}
nsIAccessible* nsRootAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
return new nsHTMLBlockAccessible(aAccessible, aNode, aShell);
}
/* readonly attribute nsIAccessible accParent; */
NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent)
{
@ -111,6 +121,11 @@ NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent)
NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUint32 *aAccRole)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
*aAccRole = 0;
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsISupports> container;
@ -131,14 +146,9 @@ NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUint32 *aAccRole)
return NS_OK;
}
NS_IMETHODIMP nsRootAccessible::GetAccValue(PRUnichar * *aAccValue)
NS_IMETHODIMP nsRootAccessible::GetAccValue(nsAWritableString& aAccValue)
{
nsCOMPtr<nsIURI> pURI;
mDocument->GetDocumentURL(getter_AddRefs(pURI));
char *path;
pURI->GetSpec(&path);
*aAccValue = ToNewUnicode(nsDependentCString(path));
return NS_OK;
return GetURL(aAccValue);
}
/* void addAccessibleEventListener (in nsIAccessibleEventListener aListener); */
@ -148,6 +158,9 @@ NS_IMETHODIMP nsRootAccessible::AddAccessibleEventListener(nsIAccessibleEventLis
{
// add an event listener to the document
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> document;
shell->GetDocument(getter_AddRefs(document));
@ -248,34 +261,33 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
#endif
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
if (node)
a = new nsHTMLLinkAccessible(shell, node);
a = new nsHTMLLinkAccessible(node, mPresShell);
}
}
if (a) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
nsCOMPtr<nsIAccessible> na(CreateNewAccessible(a, node, mPresShell));
if ( !na )
return NS_OK;
if ( eventType.EqualsIgnoreCase("focus") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, na);
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, a);
}
else if ( eventType.EqualsIgnoreCase("change") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, na);
nsCOMPtr<nsIDOMNSHTMLSelectElement> select(do_QueryInterface(content));
if ( select ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_SELECTION, a);
}
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, a);
}
else if ( eventType.EqualsIgnoreCase("CheckboxStateChange") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, na);
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, a);
}
else if ( eventType.EqualsIgnoreCase("RadiobuttonStateChange") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, na);
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, a);
}
}
}
return NS_OK;
}
// ------- nsIDOMFocusListener Methods (2) -------------
// ------- nsIDOMFocusListener Methods (1) -------------
NS_IMETHODIMP nsRootAccessible::Focus(nsIDOMEvent* aEvent)
{
@ -306,5 +318,115 @@ NS_IMETHODIMP nsRootAccessible::Select(nsIDOMEvent* aEvent) { return NS_OK; }
// gets Input events when text is entered or deleted in a textarea or input
NS_IMETHODIMP nsRootAccessible::Input(nsIDOMEvent* aEvent) { return NS_OK; }
// ------- nsIAccessibleDocument Methods (5) ---------------
NS_IMETHODIMP nsRootAccessible::GetURL(nsAWritableString& aURL)
{
return nsDocAccessibleMixin::GetURL(aURL);
}
NS_IMETHODIMP nsRootAccessible::GetTitle(nsAWritableString& aTitle)
{
return nsDocAccessibleMixin::GetTitle(aTitle);
}
NS_IMETHODIMP nsRootAccessible::GetMimeType(nsAWritableString& aMimeType)
{
return nsDocAccessibleMixin::GetMimeType(aMimeType);
}
NS_IMETHODIMP nsRootAccessible::GetDocType(nsAWritableString& aDocType)
{
return nsDocAccessibleMixin::GetDocType(aDocType);
}
NS_IMETHODIMP nsRootAccessible::GetNameSpaceURIForID(PRInt16 aNameSpaceID, nsAWritableString& aNameSpaceURI)
{
return nsDocAccessibleMixin::GetNameSpaceURIForID(aNameSpaceID, aNameSpaceURI);
}
NS_IMETHODIMP nsRootAccessible::GetDocument(nsIDocument **doc)
{
return nsDocAccessibleMixin::GetDocument(doc);
}
nsDocAccessibleMixin::nsDocAccessibleMixin(nsIDocument *aDoc):mDocument(aDoc)
{
}
nsDocAccessibleMixin::nsDocAccessibleMixin(nsIWeakReference *aPresShell)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aPresShell));
NS_ASSERTION(shell,"Shell is gone!!! What are we doing here?");
shell->GetDocument(getter_AddRefs(mDocument));
}
nsDocAccessibleMixin::~nsDocAccessibleMixin()
{
}
NS_IMETHODIMP nsDocAccessibleMixin::GetURL(nsAWritableString& aURL)
{
nsCOMPtr<nsIURI> pURI;
mDocument->GetDocumentURL(getter_AddRefs(pURI));
nsXPIDLCString path;
pURI->GetSpec(getter_Copies(path));
aURL.Assign(NS_ConvertUTF8toUCS2(path).get());
//XXXaaronl Need to use CopyUTF8toUCS2(nsDependentCString(path), aURL); when it's written
return NS_OK;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAWritableString& aTitle)
{
// This doesn't leak - we don't own the const pointer that's returned
aTitle = *(mDocument->GetDocumentTitle());
return NS_OK;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
{
if (mDocument)
return mDocument->GetContentType(aMimeType);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetDocType(nsAWritableString& aDocType)
{
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mDocument));
nsCOMPtr<nsIDOMDocumentType> docType;
if (xulDoc) {
aDocType = NS_LITERAL_STRING("window"); // doctype not implemented for XUL at time of writing - causes assertion
return NS_OK;
}
else if (domDoc && NS_SUCCEEDED(domDoc->GetDoctype(getter_AddRefs(docType))) && docType) {
return docType->GetName(aDocType);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetNameSpaceURIForID(PRInt16 aNameSpaceID, nsAWritableString& aNameSpaceURI)
{
if (mDocument) {
nsCOMPtr<nsINameSpaceManager> nameSpaceManager;
if (NS_SUCCEEDED(mDocument->GetNameSpaceManager(*getter_AddRefs(nameSpaceManager))))
return nameSpaceManager->GetNameSpaceURI(aNameSpaceID, aNameSpaceURI);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetDocument(nsIDocument **doc)
{
*doc = mDocument;
if (mDocument) {
NS_IF_ADDREF(*doc);
return NS_OK;
}
return NS_ERROR_FAILURE;
}

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

@ -26,17 +26,32 @@
#include "nsAccessible.h"
#include "nsIAccessibleEventReceiver.h"
#include "nsIAccessibleEventListener.h"
#include "nsIAccessibleDocument.h"
#include "nsIDOMFormListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDocument.h"
class nsDocAccessibleMixin
{
public:
nsDocAccessibleMixin(nsIDocument *doc);
nsDocAccessibleMixin(nsIWeakReference *aShell);
virtual ~nsDocAccessibleMixin();
NS_DECL_NSIACCESSIBLEDOCUMENT
protected:
nsCOMPtr<nsIDocument> mDocument;
};
class nsRootAccessible : public nsAccessible,
public nsDocAccessibleMixin,
public nsIAccessibleDocument,
public nsIAccessibleEventReceiver,
public nsIDOMFocusListener,
public nsIDOMFormListener
{
NS_DECL_ISUPPORTS_INHERITED
public:
@ -44,8 +59,8 @@ class nsRootAccessible : public nsAccessible,
virtual ~nsRootAccessible();
/* attribute wstring accName; */
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
NS_IMETHOD GetAccValue(PRUnichar * *aAccValue);
NS_IMETHOD GetAccName(nsAWritableString& aAccName);
NS_IMETHOD GetAccValue(nsAWritableString& aAccValue);
NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent);
NS_IMETHOD GetAccRole(PRUint32 *aAccRole);
@ -68,17 +83,17 @@ class nsRootAccessible : public nsAccessible,
NS_IMETHOD Select(nsIDOMEvent* aEvent);
NS_IMETHOD Input(nsIDOMEvent* aEvent);
protected:
virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual nsIFrame* GetFrame();
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_DECL_NSIACCESSIBLEDOCUMENT
// not a com pointer. We don't own the listener
// it is the callers responsibility to remove the listener
// otherwise we will get into circular referencing problems
nsIAccessibleEventListener* mListener;
nsCOMPtr<nsIContent> mCurrentFocus;
nsCOMPtr<nsIDocument> mDocument;
protected:
virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual nsIFrame* GetFrame();
// not a com pointer. We don't own the listener
// it is the callers responsibility to remove the listener
// otherwise we will get into circular referencing problems
nsIAccessibleEventListener* mListener;
nsCOMPtr<nsIContent> mCurrentFocus;
};

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

@ -33,23 +33,18 @@
// --- area -----
nsHTMLAreaAccessible::nsHTMLAreaAccessible(nsIPresShell *aPresShell, nsIDOMNode *aDomNode, nsIAccessible *aAccParent):
nsGenericAccessible(), mPresShell(aPresShell), mDOMNode(aDomNode), mAccParent(aAccParent)
nsHTMLAreaAccessible::nsHTMLAreaAccessible(nsIDOMNode *aDomNode, nsIAccessible *aAccParent, nsIWeakReference* aShell):
nsLinkableAccessible(aDomNode, aShell), mAccParent(aAccParent)
{
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccName(nsAWritableString & _retval)
{
*_retval = 0;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
if (elt) {
nsAutoString hrefString;
elt->GetAttribute(NS_LITERAL_STRING("title"), hrefString);
if (!hrefString.IsEmpty()) {
*_retval = hrefString.ToNewUnicode();
return NS_OK;
}
elt->GetAttribute(NS_LITERAL_STRING("title"), _retval);
}
return NS_OK;
}
@ -62,85 +57,25 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetAccRole(PRUint32 *_retval)
}
/* wstring getAccValue (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccValue(nsAWritableString& _retval)
{
*_retval = 0;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
if (elt) {
nsAutoString hrefString;
elt->GetAttribute(NS_LITERAL_STRING("href"), hrefString);
*_retval = hrefString.ToNewUnicode();
}
if (elt)
elt->GetAttribute(NS_LITERAL_STRING("href"), _retval);
return NS_OK;
}
/* wstring getAccDescription (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccDescription(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccDescription(nsAWritableString& _retval)
{
// Still to do - follow IE's standard here
*_retval = 0;
nsAutoString shapeString;
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mDOMNode));
if (area) {
area->GetShape(shapeString);
if (!shapeString.IsEmpty())
*_retval = ToNewUnicode(shapeString);
}
if (area)
area->GetShape(_retval);
return NS_OK;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("jump"));
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsHTMLAreaAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIPresContext> presContext;
mPresShell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsMouseEvent linkClickEvent;
linkClickEvent.eventStructType = NS_EVENT;
linkClickEvent.message = NS_MOUSE_LEFT_CLICK;
linkClickEvent.isShift = PR_FALSE;
linkClickEvent.isControl = PR_FALSE;
linkClickEvent.isAlt = PR_FALSE;
linkClickEvent.isMeta = PR_FALSE;
linkClickEvent.clickCount = 0;
linkClickEvent.widget = nsnull;
nsEventStatus eventStatus = nsEventStatus_eIgnore;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
content->HandleDOMEvent(presContext, &linkClickEvent,
nsnull, NS_EVENT_FLAG_INIT, &eventStatus);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccState(PRUint32 *_retval)
{
*_retval = STATE_LINKED | STATE_FOCUSABLE | STATE_READONLY;
return NS_OK;
}
/* nsIAccessible getAccFirstChild (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
@ -172,8 +107,7 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetAccParent(nsIAccessible * *aAccParent)
nsIAccessible *nsHTMLAreaAccessible::CreateAreaAccessible(nsIDOMNode *aDOMNode)
{
nsresult rv;
NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv);
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (accService) {
nsIAccessible* acc = nsnull;
accService->CreateHTMLAreaAccessible(mPresShell, aDOMNode, mAccParent, &acc);

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

@ -25,37 +25,31 @@
#define _nsHTMLAreaAccessible_H_
#include "nsGenericAccessible.h"
#include "nsHTMLLinkAccessible.h"
#include "nsAccessible.h"
/* Accessible for image map areas - must be child of image
*/
class nsHTMLAreaAccessible : public nsGenericAccessible
class nsHTMLAreaAccessible : public nsLinkableAccessible
{
public:
nsHTMLAreaAccessible(nsIPresShell *presShell, nsIDOMNode *domNode, nsIAccessible *accParent);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLAreaAccessible(nsIDOMNode *domNode, nsIAccessible *accParent, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString & _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccValue(PRUnichar **_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent);
NS_IMETHOD GetAccNextSibling(nsIAccessible * *aAccNextSibling);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible * *aAccPreviousSibling);
NS_IMETHOD GetAccDescription(PRUnichar **_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccDescription(nsAWritableString& _retval);
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
protected:
nsIAccessible *CreateAreaAccessible(nsIDOMNode *aDOMNode);
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIAccessible> mAccParent;
nsCOMPtr<nsIPresShell> mPresShell;
};
#endif

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

@ -34,8 +34,8 @@
#include "nsIDOMHTMLLabelElement.h"
#include "nsIDOMHTMLFormElement.h"
nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsLeafDOMAccessible(aShell, aNode)
nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsLeafAccessible(aNode, aShell)
{
}
@ -69,20 +69,19 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::AppendLabelFor(nsIContent *aLookNode,
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(nsAWritableString& _retval)
{
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mNode));
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLLabelElement> labelElement;
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
nsAutoString nameString;
nsresult rv = NS_OK;
nsAutoString label;
// go up tree get name of ancestor label if there is one. Don't go up farther than form element
while (walkUpContent && nameString.IsEmpty() && !formElement) {
while (walkUpContent && label.IsEmpty() && !formElement) {
labelElement = do_QueryInterface(walkUpContent);
if (labelElement)
rv = AppendFlatStringFromSubtree(walkUpContent, &nameString);
rv = AppendFlatStringFromSubtree(walkUpContent, &label);
formElement = do_QueryInterface(walkUpContent); // reached top ancestor in form
nsCOMPtr<nsIContent> nextParent;
walkUpContent->GetParent(*getter_AddRefs(nextParent));
@ -95,16 +94,16 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(PRUnichar **_retval)
walkUpContent = do_QueryInterface(formElement);
if (walkUpContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
nsAutoString forId;
elt->GetAttribute(NS_LITERAL_STRING("id"), forId);
// Actually we'll be walking down the content this time, with a depth first search
if (!forId.IsEmpty())
AppendLabelFor(walkUpContent,&forId,&nameString);
AppendLabelFor(walkUpContent,&forId,&label);
}
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
label.CompressWhitespace();
_retval.Assign(label);
return NS_OK;
}
@ -114,9 +113,10 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval)
{
// can be
// focusable, focused, checked, protected, unavailable
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
*_retval = STATE_FOCUSABLE;
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
PRBool checked = PR_FALSE;
element->GetChecked(&checked);
@ -137,8 +137,8 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval)
// --- checkbox -----
nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -157,20 +157,20 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
// check or uncheck
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
PRBool checked = PR_FALSE;
if (element)
element->GetChecked(&checked);
if (checked)
*_retval = ToNewUnicode(NS_LITERAL_STRING("uncheck"));
_retval = NS_LITERAL_STRING("uncheck");
else
*_retval = ToNewUnicode(NS_LITERAL_STRING("check"));
_retval = NS_LITERAL_STRING("check");
return NS_OK;
}
@ -180,8 +180,8 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, PRUnicha
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
if (index == 0) { // 0 is the magic value for default action
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
PRBool checked = PR_FALSE;
element->GetChecked(&checked);
element->SetChecked(checked ? PR_FALSE : PR_TRUE);
@ -193,8 +193,8 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index)
//------ Radio button -------
nsHTMLRadioButtonAccessible::nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLRadioButtonAccessible::nsHTMLRadioButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -206,10 +206,10 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("select"));
_retval = NS_LITERAL_STRING("select");
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
@ -219,7 +219,7 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccActionName(PRUint8 index, PRUni
NS_IMETHODIMP nsHTMLRadioButtonAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
element->Click();
return NS_OK;
}
@ -237,8 +237,8 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUint32 *_retval)
// ----- Button -----
nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -250,10 +250,10 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("press"));
_retval = NS_LITERAL_STRING("press");
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
@ -263,7 +263,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar
NS_IMETHODIMP nsHTMLButtonAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
element->Click();
return NS_OK;
}
@ -278,10 +278,9 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccRole(PRUint32 *_retval)
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(nsAWritableString& _retval)
{
*_retval = nsnull;
nsCOMPtr<nsIDOMHTMLInputElement> button(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> button(do_QueryInterface(mDOMNode));
if (!button)
return NS_ERROR_FAILURE;
@ -289,8 +288,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval)
nsAutoString name;
button->GetValue(name);
name.CompressWhitespace();
*_retval = name.ToNewUnicode();
_retval.Assign(name);
return NS_OK;
}
@ -298,8 +296,8 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval)
// ----- HTML 4 Button: can contain arbitrary HTML content -----
nsHTML4ButtonAccessible::nsHTML4ButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsDOMAccessible(aShell, aNode)
nsHTML4ButtonAccessible::nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLBlockAccessible(aNode, aShell)
{
}
@ -311,10 +309,10 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("press"));
_retval = NS_LITERAL_STRING("press");
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
@ -324,7 +322,7 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar
NS_IMETHODIMP nsHTML4ButtonAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
element->Click();
return NS_OK;
}
@ -341,25 +339,26 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccRole(PRUint32 *_retval)
/* long getAccState (); */
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccState(PRUint32 *_retval)
{
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
return NS_OK;
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(nsAWritableString& _retval)
{
*_retval = nsnull;
nsresult rv = NS_ERROR_FAILURE;
nsAutoString name;
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsAutoString name;
if (content)
rv = AppendFlatStringFromSubtree(content, &name);
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAWritableString
name.CompressWhitespace();
*_retval = name.ToNewUnicode();
_retval.Assign(name);
}
return rv;
@ -368,8 +367,8 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(PRUnichar **_retval)
// --- textfield -----
nsHTMLTextFieldAccessible::nsHTMLTextFieldAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLTextFieldAccessible::nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -381,13 +380,11 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccRole(PRUint32 *_retval)
}
/* wstring getAccValue (); */
NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(nsAWritableString& _retval)
{
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mDOMNode));
if (textArea) {
nsAutoString valueString;
textArea->GetValue(valueString);
*_retval = ToNewUnicode(valueString);
textArea->GetValue(_retval);
return NS_OK;
}
@ -400,12 +397,13 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccState(PRUint32 *_retval)
// can be
// focusable, focused, protected. readonly, unavailable, selected
*_retval = STATE_FOCUSABLE;
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
PRBool isReadOnly = PR_FALSE;
elt->HasAttribute(NS_LITERAL_STRING("readonly"), &isReadOnly);
if (isReadOnly)
@ -413,9 +411,13 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccState(PRUint32 *_retval)
// Get current selection and find out if current node is in it
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsIFrame *frame;
if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) {
nsCOMPtr<nsISelectionController> selCon;

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

@ -24,7 +24,7 @@
#ifndef _nsHTMLFormControlAccessible_H_
#define _nsHTMLFormControlAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsICheckboxControlFrame;
@ -33,12 +33,12 @@ class nsICheckboxControlFrame;
* - walking up to get name from label
* - support basic state
*/
class nsHTMLFormControlAccessible : public nsLeafDOMAccessible
class nsHTMLFormControlAccessible : public nsLeafAccessible
{
public:
nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
protected:
@ -49,10 +49,10 @@ class nsHTMLCheckboxAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
@ -60,10 +60,10 @@ class nsHTMLRadioButtonAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLRadioButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
@ -71,24 +71,24 @@ class nsHTMLButtonAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccName(PRUnichar **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
class nsHTML4ButtonAccessible : public nsDOMAccessible
class nsHTML4ButtonAccessible : public nsHTMLBlockAccessible
{
public:
nsHTML4ButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccName(PRUnichar **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
@ -96,9 +96,9 @@ public:
class nsHTMLTextFieldAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLTextFieldAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(PRUnichar **_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
};

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

@ -30,19 +30,55 @@
#include "nsIDocShell.h"
#include "nsIWebShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIXULDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsReadableUtils.h"
NS_INTERFACE_MAP_BEGIN(nsHTMLIFrameRootAccessible)
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMFormListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFormListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMFormListener)
NS_INTERFACE_MAP_END_INHERITING(nsRootAccessible)
nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIPresShell* aShell, nsIDOMNode* aNode, nsIAccessible* aRoot):
nsDOMAccessible(aShell, aNode)
NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible);
NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible);
NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible);
NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible);
NS_IMETHODIMP
nsHTMLIFrameAccessible::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!");
if ( !aInstancePtr )
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(NS_GET_IID(nsIAccessibleDocument))) {
*aInstancePtr = (void*)(nsIAccessibleDocument*) this;
NS_IF_ADDREF(this);
return NS_OK;
}
return nsHTMLBlockAccessible::QueryInterface(aIID, aInstancePtr);
}
nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *aDoc):
nsHTMLBlockAccessible(aNode, aShell), mRootAccessible(aRoot), nsDocAccessibleMixin(aDoc)
{
mRootAccessible = aRoot;
}
/* attribute wstring accName; */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccName(PRUnichar * *aAccName)
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccName(nsAWritableString& aAccName)
{
return mRootAccessible->GetAccName(aAccName);
return GetTitle(aAccName);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccValue(nsAWritableString& aAccValue)
{
return GetURL(aAccValue);
}
/* nsIAccessible getAccFirstChild (); */
@ -66,13 +102,51 @@ NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccChildCount(PRInt32 *_retval)
/* unsigned long getAccRole (); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccRole(PRUint32 *_retval)
{
return mRootAccessible->GetAccRole(_retval);
*_retval = ROLE_PANE;
return NS_OK;
}
// ------- nsIAccessibleDocument Methods (5) ---------------
NS_IMETHODIMP nsHTMLIFrameAccessible::GetURL(nsAWritableString& aURL)
{
return nsDocAccessibleMixin::GetURL(aURL);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetTitle(nsAWritableString& aTitle)
{
return nsDocAccessibleMixin::GetTitle(aTitle);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetMimeType(nsAWritableString& aMimeType)
{
return nsDocAccessibleMixin::GetMimeType(aMimeType);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetDocType(nsAWritableString& aDocType)
{
return nsDocAccessibleMixin::GetDocType(aDocType);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetNameSpaceURIForID(PRInt16 aNameSpaceID, nsAWritableString& aNameSpaceURI)
{
return nsDocAccessibleMixin::GetNameSpaceURIForID(aNameSpaceID, aNameSpaceURI);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetDocument(nsIDocument **doc)
{
return nsDocAccessibleMixin::GetDocument(doc);
}
//=============================//
// nsHTMLIFrameRootAccessible //
//=============================//
//-----------------------------------------------------
// construction
//-----------------------------------------------------
nsHTMLIFrameRootAccessible::nsHTMLIFrameRootAccessible(nsIWeakReference* aShell, nsIDOMNode* aNode):
nsHTMLIFrameRootAccessible::nsHTMLIFrameRootAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsRootAccessible(aShell)
{
mRealDOMNode = aNode;
@ -83,23 +157,6 @@ nsHTMLIFrameRootAccessible::nsHTMLIFrameRootAccessible(nsIWeakReference* aShell,
//-----------------------------------------------------
nsHTMLIFrameRootAccessible::~nsHTMLIFrameRootAccessible()
{
}
/* attribute wstring accName; */
NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetAccName(PRUnichar * *aAccName)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIDocument> document;
if (shell)
shell->GetDocument(getter_AddRefs(document));
if (document) {
const nsString* docTitle = document->GetDocumentTitle();
if (docTitle && !docTitle->IsEmpty()) {
*aAccName = docTitle->ToNewUnicode();
return NS_OK;
}
}
*aAccName = ToNewUnicode(NS_LITERAL_STRING("Frame"));
return NS_OK;
}
/* readonly attribute nsIAccessible accParent; */
@ -137,18 +194,16 @@ NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetAccPreviousSibling(nsIAccessible **
return NS_ERROR_NOT_IMPLEMENTED;
}
/* unsigned long getAccRole (); */
NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_PANE;
return NS_OK;
}
NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetHTMLIFrameAccessible(nsIAccessible** aAcc)
{
// Start by finding our PresShell and from that
// we get our nsIDocShell in order to walk the DocShell tree
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mPresShell));
if (!presShell) {
*aAcc = nsnull;
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
if (NS_SUCCEEDED(GetDocShellFromPS(presShell, getter_AddRefs(docShell)))) {
// Now that we have the DocShell QI
@ -183,7 +238,7 @@ NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetHTMLIFrameAccessible(nsIAccessible*
// OK, we found the content node in the parent doc
// that corresponds to this sub-doc
// Get the frame for that content
nsCOMPtr<nsIWeakReference> wr(getter_AddRefs(NS_GetWeakReference(parentPresShell)));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(parentPresShell);
nsIFrame* frame = nsnull;
parentPresShell->GetPrimaryFrameFor(content, &frame);
#ifdef NS_DEBUG_X
@ -200,7 +255,7 @@ NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetHTMLIFrameAccessible(nsIAccessible*
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
nsCOMPtr<nsIAccessible> acc(do_QueryInterface(frame));
*aAcc = CreateNewAccessible(acc, node, wr);
*aAcc = acc;
NS_IF_ADDREF(*aAcc);
return NS_OK;

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

@ -24,19 +24,27 @@
#define _nsIFrameRootAccessible_H_
#include "nsRootAccessible.h"
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
#include "nsIAccessibleDocument.h"
class nsIWebShell;
class nsIWeakReference;
class nsHTMLIFrameAccessible : public nsDOMAccessible
class nsHTMLIFrameAccessible : public nsHTMLBlockAccessible,
public nsIAccessibleDocument,
public nsDocAccessibleMixin
{
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEDOCUMENT
public:
nsHTMLIFrameAccessible(nsIPresShell* aShell, nsIDOMNode* aNode, nsIAccessible* aRoot);
nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *doc);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
NS_IMETHOD GetAccName(nsAWritableString& aAccName);
NS_IMETHOD GetAccValue(nsAWritableString& AccValue);
NS_IMETHOD GetAccRole(PRUint32 *aAccRole);
protected:
@ -45,9 +53,10 @@ class nsHTMLIFrameAccessible : public nsDOMAccessible
class nsHTMLIFrameRootAccessible : public nsRootAccessible
{
NS_DECL_ISUPPORTS_INHERITED
public:
nsHTMLIFrameRootAccessible(nsIWeakReference* aShell, nsIDOMNode* aNode);
nsHTMLIFrameRootAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual ~nsHTMLIFrameRootAccessible();
/* attribute wstring accName; */
@ -59,15 +68,9 @@ class nsHTMLIFrameRootAccessible : public nsRootAccessible
/* nsIAccessible getAccPreviousSibling (); */
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
NS_IMETHOD GetAccRole(PRUint32 *aAccRole);
protected:
NS_IMETHOD GetHTMLIFrameAccessible(nsIAccessible** aAcc);
nsCOMPtr<nsIDOMNode> mRealDOMNode;
NS_IMETHOD GetHTMLIFrameAccessible(nsIAccessible** aAcc);
nsCOMPtr<nsIDOMNode> mRealDOMNode;
};

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

@ -33,12 +33,15 @@
// --- image -----
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIPresShell* aShell, nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame):
nsLinkableAccessible(aShell, aDOMNode), mPresShell(aShell)
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame, nsIWeakReference* aShell):
nsLinkableAccessible(aDOMNode, aShell)
{
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));
nsCOMPtr<nsIDocument> doc;
aShell->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
NS_ASSERTION(shell,"Shell is gone!!! What are we doing here?");
shell->GetDocument(getter_AddRefs(doc));
nsAutoString mapElementName;
if (doc && element) {
@ -53,19 +56,21 @@ nsLinkableAccessible(aShell, aDOMNode), mPresShell(aShell)
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLImageAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLImageAccessible::GetAccName(nsAWritableString& _retval)
{
nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mNode));
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mDOMNode));
if (imageContent) {
nsAutoString nameString;
nsresult rv = AppendFlatStringFromContentNode(imageContent, &nameString);
nsAutoString name;
rv = AppendFlatStringFromContentNode(imageContent, &name);
if (NS_SUCCEEDED(rv)) {
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
// Temp var needed until CompressWhitespace built for nsAWritableString
name.CompressWhitespace();
_retval.Assign(name);
}
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
return rv;
}
/* wstring getAccRole (); */
@ -99,12 +104,12 @@ nsIAccessible *nsHTMLImageAccessible::CreateAreaAccessible(PRUint32 areaNum)
if (!domNode)
return nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv);
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (!accService)
return nsnull;
if (accService) {
nsIAccessible* acc = nsnull;
nsCOMPtr<nsISupports> presShell(do_QueryInterface(mPresShell));
accService->CreateHTMLAreaAccessible(presShell, domNode, this, &acc);
accService->CreateHTMLAreaAccessible(mPresShell, domNode, this, &acc);
return acc;
}
return nsnull;

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

@ -24,7 +24,7 @@
#ifndef _nsHTMLImageAccessible_H_
#define _nsHTMLImageAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
#include "nsIFrame.h"
#include "nsIImageFrame.h"
#include "nsIDOMHTMLMapElement.h"
@ -38,8 +38,8 @@ class nsHTMLImageAccessible : public nsLinkableAccessible
{
public:
nsHTMLImageAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode, nsIImageFrame *imageFrame);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIImageFrame *imageFrame, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
@ -48,7 +48,6 @@ public:
protected:
nsIAccessible *CreateAreaAccessible(PRUint32 areaNum);
nsCOMPtr<nsIDOMHTMLMapElement> mMapElement;
nsCOMPtr<nsIPresShell> mPresShell;
};
#endif

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

@ -32,21 +32,24 @@
#include "nsReadableUtils.h"
#include "nsIDOMElement.h"
nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsLinkableAccessible(aShell, aDomNode)
nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsLinkableAccessible(aDomNode, aShell)
{
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccName(nsAWritableString& _retval)
{
if (!IsALink()) // Also initializes private data members
return NS_ERROR_FAILURE;
nsAutoString nameString;
nsresult rv = AppendFlatStringFromSubtree(mLinkContent, &nameString);
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
nsAutoString name;
nsresult rv = AppendFlatStringFromSubtree(mLinkContent, &name);
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAWritableString
name.CompressWhitespace();
_retval.Assign(name);
}
return rv;
}
@ -58,14 +61,10 @@ NS_IMETHODIMP nsHTMLLinkAccessible::GetAccRole(PRUint32 *_retval)
return NS_OK;
}
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccValue(nsAWritableString& _retval)
{
*_retval = 0;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mNode));
if (elt) {
nsAutoString hrefString;
elt->GetAttribute(NS_LITERAL_STRING("href"), hrefString);
*_retval = hrefString.ToNewUnicode();
}
return NS_OK;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
if (elt)
return elt->GetAttribute(NS_LITERAL_STRING("href"), _retval);
return NS_ERROR_FAILURE;;
}

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

@ -24,18 +24,16 @@
#ifndef _nsHTMLLinkAccessible_H_
#define _nsHTMLLinkAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsHTMLLinkAccessible : public nsLinkableAccessible
{
public:
nsHTMLLinkAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(PRUnichar **_retval);
private:
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
};
#endif

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

@ -0,0 +1,792 @@
/* -*- Mode: C++; tab-width: 4; 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.
*
* Original Author: Eric Vaughan (evaughan@netscape.com)
*
* Contributor(s):
*/
#include "nsHTMLSelectAccessible.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsRootAccessible.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsLayoutAtoms.h"
#include "nsIDOMMenuListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsReadableUtils.h"
#include "nsIDOMHTMLCollection.h"
#include "nsISelectElement.h"
#include "nsIDOMHTMLSelectElement.h"
#include "nsIAccessibilityService.h"
#include "nsIServiceManager.h"
#include "nsIDOMHTMLOptionElement.h"
/*
* A class the represents the text field in the Select to the left
* of the drop down button
*/
class nsHTMLSelectTextFieldAccessible : public nsLeafAccessible
{
public:
nsHTMLSelectTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame);
nsCOMPtr<nsIAccessible> mParent;
};
/*
* A base class that can listen to menu events. Its used so the
* button and the window accessibles can change there name and role
* depending on whether the drop down list is dropped down on not
*/
class nsMenuListenerAccessible : public nsAccessible,
public nsIDOMMenuListener
{
public:
NS_DECL_ISUPPORTS_INHERITED
nsMenuListenerAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsMenuListenerAccessible();
// popup listener
NS_IMETHOD Create(nsIDOMEvent* aEvent);
NS_IMETHOD Close(nsIDOMEvent* aEvent);
NS_IMETHOD Destroy(nsIDOMEvent* aEvent);
NS_IMETHOD Action(nsIDOMEvent* aEvent) { return NS_OK; }
NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; }
NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; }
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
virtual void SetupMenuListener();
PRBool mRegistered;
PRBool mOpen;
};
NS_IMPL_ISUPPORTS_INHERITED(nsMenuListenerAccessible, nsAccessible, nsIDOMMenuListener)
/**
* A class that represents the button inside the Select to the right of the text field
*/
class nsHTMLSelectButtonAccessible : public nsMenuListenerAccessible
{
public:
nsHTMLSelectButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame);
nsCOMPtr<nsIAccessible> mParent;
};
/*
* A class that represents the window that lives to the right
* of the drop down button inside the Select. This is the window
* that is made visible when the button is pressed.
*/
class nsHTMLSelectWindowAccessible : public nsMenuListenerAccessible
{
public:
nsHTMLSelectWindowAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame);
nsCOMPtr<nsIAccessible> mParent;
};
/*
* The list that contains all the options in the select. It is inside the window.
*/
class nsHTMLSelectListAccessible : public nsAccessible
{
public:
nsHTMLSelectListAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsHTMLSelectListAccessible() {}
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
nsCOMPtr<nsIAccessible> mParent;
};
//--------- nsHTMLSelectAccessible -----
nsHTMLSelectAccessible::nsHTMLSelectAccessible(nsIDOMNode* aDOMNode,
nsIWeakReference* aShell)
:nsAccessible(aDOMNode, aShell)
{
}
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLSelectAccessible, nsAccessible, nsIAccessibleSelectable)
// ------------- Helper method for determination of proper Frame ------
//static
PRBool nsHTMLSelectAccessible::IsCorrectFrame( nsIFrame* aFrame, nsIAtom* aAtom ) {
if (!aFrame || !aAtom)
return PR_FALSE;
nsCOMPtr<nsIAtom> frameType;
aFrame->GetFrameType(getter_AddRefs(frameType));
if (frameType.get() != aAtom)
return PR_FALSE;
return PR_TRUE;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccValue(nsAWritableString& _retval)
{
nsCOMPtr<nsIAccessible> text;
GetAccFirstChild(getter_AddRefs(text));
if (text)
return text->GetAccValue(_retval);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_COMBOBOX;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccLastChild(nsIAccessible **_retval)
{
// create a window accessible
*_retval = new nsHTMLSelectWindowAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
// create a text field
*_retval = new nsHTMLSelectTextFieldAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccChildCount(PRInt32 *_retval)
{
// always have 3 children
*_retval = 3;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetSelectedChildren(nsISupportsArray **_retval)
{
*_retval = nsnull;
return NS_OK;
}
//-------- SelectTextFieldAccessible ------
nsHTMLSelectTextFieldAccessible::nsHTMLSelectTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsLeafAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccValue(nsAWritableString& _retval)
{
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
if ( !frame )
return NS_ERROR_FAILURE;
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return NS_ERROR_FAILURE;
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::textFrame) )
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
if (!content)
return NS_ERROR_FAILURE;
AppendFlatStringFromSubtree(content, &_retval);
return NS_OK;
}
void nsHTMLSelectTextFieldAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
{
// get our first child's frame
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
if ( !frame )
return;
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return;
frame->GetParent(aRelativeFrame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( *aRelativeFrame, nsLayoutAtoms::areaFrame) )
return;
frame->GetRect(aBounds);
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectButtonAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_STATICTEXT;
return NS_OK;
}
// --------- nsMenuListenerAccessible -----------
nsMenuListenerAccessible::nsMenuListenerAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsAccessible(aDOMNode, aShell)
{
mRegistered = PR_FALSE;
mOpen = PR_FALSE;
}
nsMenuListenerAccessible::~nsMenuListenerAccessible()
{
if (mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (eventReceiver)
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
}
}
NS_IMETHODIMP nsMenuListenerAccessible::Create(nsIDOMEvent* aEvent)
{
mOpen = PR_TRUE;
/* TBD send state change event */
return NS_OK;
}
NS_IMETHODIMP nsMenuListenerAccessible::Destroy(nsIDOMEvent* aEvent)
{
mOpen = PR_FALSE;
/* TBD send state change event */
return NS_OK;
}
NS_IMETHODIMP nsMenuListenerAccessible::Close(nsIDOMEvent* aEvent)
{
mOpen = PR_FALSE;
/* TBD send state change event */
return NS_OK;
}
void
nsMenuListenerAccessible::SetupMenuListener()
{
// not not already one register ourselves as a popup listener
if (!mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (!eventReceiver) {
return;
}
nsresult rv = eventReceiver->AddEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
if (NS_FAILED(rv)) {
return;
}
mRegistered = PR_TRUE;
}
}
//-------- SelectButtonAccessible ------
nsHTMLSelectButtonAccessible::nsHTMLSelectButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsMenuListenerAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsHTMLSelectButtonAccessible::AccDoAction(PRUint8 index)
{
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return NS_ERROR_FAILURE;
frame->GetNextSibling(&frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::gfxButtonControlFrame) )
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(content));
if (element)
{
element->Click();
return NS_OK;
}
return NS_ERROR_FAILURE;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;
}
void nsHTMLSelectButtonAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
{
// get our second child's frame
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return;
frame->GetNextSibling(&frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::gfxButtonControlFrame) )
return;
frame->GetParent(aRelativeFrame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( *aRelativeFrame, nsLayoutAtoms::areaFrame) )
return;
frame->GetRect(aBounds);
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_PUSHBUTTON;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccName(nsAWritableString& _retval)
{
return GetAccActionName(0, _retval);
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
SetupMenuListener();
// get the current state open or closed
// set _retval to it.
// notice its supposed to be reversed. Close if opened
// and Open if closed.
if (mOpen)
_retval = NS_LITERAL_STRING("Close");
else
_retval = NS_LITERAL_STRING("Open");
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectWindowAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectTextFieldAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 0;
return NS_OK;
}
//---------------------
nsHTMLSelectWindowAccessible::nsHTMLSelectWindowAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell)
:nsMenuListenerAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccState(PRUint32 *_retval)
{
nsAccessible::GetAccState(_retval);
SetupMenuListener();
// if open we are visible if closed we are invisible
// set _retval to it.
if (mOpen)
*_retval |= STATE_DEFAULT;
else
*_retval |= STATE_INVISIBLE;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_WINDOW;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectButtonAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = new nsHTMLSelectListAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = new nsHTMLSelectListAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 1;
return NS_OK;
}
void nsHTMLSelectWindowAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
{
// get our first option
nsCOMPtr<nsIDOMNode> child;
mDOMNode->GetFirstChild(getter_AddRefs(child));
// now get its frame
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
*aRelativeFrame = nsnull;
return;
}
nsIFrame* frame = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(child));
shell->GetPrimaryFrameFor(content, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return;
frame->GetParent(&frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::areaFrame) )
return;
frame->GetParent(aRelativeFrame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( *aRelativeFrame, nsLayoutAtoms::listControlFrame) )
return;
frame->GetRect(aBounds);
}
//----------
nsHTMLSelectListAccessible::nsHTMLSelectListAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell)
:nsAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
{
return mParent->AccGetBounds(x,y,width,height);
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_LIST;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccLastChild(nsIAccessible **_retval)
{
nsCOMPtr<nsIDOMNode> last;
mDOMNode->GetLastChild(getter_AddRefs(last));
*_retval = new nsHTMLSelectOptionAccessible(this, last, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
nsCOMPtr<nsIDOMNode> first;
mDOMNode->GetFirstChild(getter_AddRefs(first));
*_retval = new nsHTMLSelectOptionAccessible(this, first, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
//--------
nsHTMLSelectOptionAccessible::nsHTMLSelectOptionAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsLeafAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_LISTITEM;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
nsCOMPtr<nsIDOMNode> next;
mDOMNode->GetNextSibling(getter_AddRefs(next));
if (next) {
*_retval = new nsHTMLSelectOptionAccessible(mParent, next, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
}
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
nsCOMPtr<nsIDOMNode> prev;
mDOMNode->GetPreviousSibling(getter_AddRefs(prev));
if (prev) {
*_retval = new nsHTMLSelectOptionAccessible(mParent, prev, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
}
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccName(nsAWritableString& _retval)
{
nsCOMPtr<nsIContent> content (do_QueryInterface(mDOMNode));
if (!content) {
return NS_ERROR_FAILURE;
}
nsAutoString option;
nsresult rv = AppendFlatStringFromSubtree(content, &option);
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAWritableString
option.CompressWhitespace();
_retval.Assign(option);
}
return rv;
}

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

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; 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.
*
* Original Author: Eric Vaughan (evaughan@netscape.com)
*
* Contributor(s):
*/
#ifndef __nsHTMLSelectAccessible_h__
#define __nsHTMLSelectAccessible_h__
#include "nsAccessible.h"
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIAccessibleSelectable.h"
class nsHTMLSelectAccessible : public nsAccessible,
public nsIAccessibleSelectable
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLESELECTABLE
nsHTMLSelectAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsHTMLSelectAccessible() {}
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
// helper method to verify frames
static PRBool IsCorrectFrame( nsIFrame* aFrame, nsIAtom* aAtom );
};
/*
* Each option in the Select. These are in the nsListAccessible
*/
class nsHTMLSelectOptionAccessible : public nsLeafAccessible
{
public:
nsHTMLSelectOptionAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
nsCOMPtr<nsIAccessible> mParent;
};
#endif

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

@ -25,8 +25,8 @@
#include "nsWeakReference.h"
#include "nsReadableUtils.h"
nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsDOMAccessible(aShell, aDomNode)
nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsHTMLBlockAccessible(aDomNode, aShell)
{
}
@ -37,8 +37,8 @@ NS_IMETHODIMP nsHTMLTableCellAccessible::GetAccRole(PRUint32 *_retval)
return NS_OK;
}
nsHTMLTableAccessible::nsHTMLTableAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsDOMAccessible(aShell, aDomNode)
nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsHTMLBlockAccessible(aDomNode, aShell)
{
}

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

@ -24,20 +24,20 @@
#ifndef _nsHTMLTableAccessible_H_
#define _nsHTMLTableAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsHTMLTableCellAccessible : public nsDOMAccessible
class nsHTMLTableCellAccessible : public nsHTMLBlockAccessible
{
public:
nsHTMLTableCellAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
};
class nsHTMLTableAccessible : public nsDOMAccessible
class nsHTMLTableAccessible : public nsHTMLBlockAccessible
{
public:
nsHTMLTableAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
};

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

@ -31,25 +31,16 @@
#include "nsIPresContext.h"
#include "nsReadableUtils.h"
nsHTMLTextAccessible::nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsLinkableAccessible(aShell, aDomNode)
nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsLinkableAccessible(aDomNode, aShell)
{
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(nsAWritableString& _retval)
{
nsAutoString nameString;
nsresult rv = NS_OK;
//if (IsALink()) {
// rv = AppendFlatStringFromSubtree(mLinkContent, &nameString);
//}
//else
mNode->GetNodeValue(nameString);
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
return rv;
return mDOMNode->GetNodeValue(_retval);
}
/* unsigned long getAccRole (); */

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

@ -23,7 +23,7 @@
#ifndef _nsHTMLTextAccessible_H_
#define _nsHTMLTextAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsIWeakReference;
class nsITextControlFrame;
@ -32,8 +32,8 @@ class nsHTMLTextAccessible : public nsLinkableAccessible
{
public:
nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);

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

@ -28,7 +28,7 @@ CPP_OBJS=\
.\$(OBJDIR)\nsRootAccessible.obj \
.\$(OBJDIR)\nsHTMLIFrameRootAccessible.obj \
.\$(OBJDIR)\nsAccessibilityService.obj \
.\$(OBJDIR)\nsSelectAccessible.obj \
.\$(OBJDIR)\nsHTMLSelectAccessible.obj \
.\$(OBJDIR)\nsGenericAccessible.obj \
.\$(OBJDIR)\nsHTMLFormControlAccessible.obj \
.\$(OBJDIR)\nsHTMLTextAccessible.obj \
@ -38,6 +38,10 @@ CPP_OBJS=\
.\$(OBJDIR)\nsHTMLLinkAccessible.obj \
$(NULL)
EXPORTS = \
.\nsRootAccessible.h \
$(NULL)
LINCS= \
-I..\..\layout\html\forms\public \
-I..\..\layout\html\forms\src \

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

@ -33,14 +33,18 @@
#include "nsIFrame.h"
#include "nsRootAccessible.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsLayoutAtoms.h"
#include "nsSelectAccessible.h"
#include "nsIDOMNode.h"
#include "nsHTMLTextAccessible.h"
#include "nsHTMLTableAccessible.h"
#include "nsHTMLImageAccessible.h"
#include "nsHTMLAreaAccessible.h"
#include "nsHTMLLinkAccessible.h"
#include "nsHTMLSelectAccessible.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsILink.h"
#include "nsIDocShellTreeItem.h"
// IFrame
#include "nsIDocShell.h"
@ -52,7 +56,6 @@
nsAccessibilityService::nsAccessibilityService()
{
NS_INIT_REFCNT();
//printf("################################## nsAccessibilityService\n");
}
nsAccessibilityService::~nsAccessibilityService()
@ -80,60 +83,76 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo
NS_ASSERTION(s,"Error not presshell!!");
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(s)));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(s);
//printf("################################## CreateRootAccessible\n");
*_retval = new nsRootAccessible(wr);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLSelectAccessible(nsIAtom* aPopupAtom, nsIDOMNode* node, nsISupports* aPresContext, nsIAccessible **_retval)
nsAccessibilityService::CreateHTMLSelectAccessible(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));
nsCOMPtr<nsIWeakReference> wr = getter_AddRefs(NS_GetWeakReference(s));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(s);
*_retval = new nsSelectAccessible(aPopupAtom, nsnull, node, wr);
*_retval = new nsHTMLSelectAccessible(node, wr);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
*/
return NS_ERROR_FAILURE;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLSelectOptionAccessible(nsIDOMNode* node, nsIAccessible *aAccParent, nsISupports* aPresContext, nsIAccessible **_retval)
{
nsCOMPtr<nsIPresContext> c(do_QueryInterface(aPresContext));
NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!");
nsCOMPtr<nsIPresShell> s;
c->GetShell(getter_AddRefs(s));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(s);
*_retval = new nsHTMLSelectOptionAccessible(aAccParent, node, wr);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLCheckboxAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
NS_IMETHODIMP nsAccessibilityService::CreateHTMLCheckboxAccessible(nsISupports *aFrame, nsIAccessible **_retval)
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLCheckboxAccessible(shell,node);
*_retval = new nsHTMLCheckboxAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMRadioButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -141,17 +160,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupport
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLRadioButtonAccessible(shell,node);
*_retval = new nsHTMLRadioButtonAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -159,17 +179,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLButtonAccessible(nsISupports *aF
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLButtonAccessible(shell,node);
*_retval = new nsHTMLButtonAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTML4ButtonAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -177,17 +198,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTML4ButtonAccessible(nsISupports *a
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTML4ButtonAccessible(shell,node);
*_retval = new nsHTML4ButtonAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLTextAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -195,18 +217,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextAccessible(nsISupports *aFra
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
//printf("################################## CreateHTMLTextAccessible\n");
*_retval = new nsHTMLTextAccessible(shell, node);
*_retval = new nsHTMLTextAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
@ -215,17 +237,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTableAccessible(nsISupports *aFr
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLTableAccessible(shell, node);
*_retval = new nsHTMLTableAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLTableCellAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -233,17 +256,18 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTableCellAccessible(nsISupports
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLTableCellAccessible(shell, node);
*_retval = new nsHTMLTableCellAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLImageAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
@ -251,35 +275,39 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFr
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIImageFrame> imageFrame(do_QueryInterface(aFrame));
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(shell, node, imageFrame);
*_retval = new nsHTMLImageAccessible(node, imageFrame, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
/* nsIAccessible createHTMLAreaAccessible (in nsISupports aPresShell, in nsISupports aFrame); */
NS_IMETHODIMP nsAccessibilityService::CreateHTMLAreaAccessible(nsISupports *aShell, nsIDOMNode *aDOMNode, nsIAccessible *aAccParent,
NS_IMETHODIMP nsAccessibilityService::CreateHTMLAreaAccessible(nsIWeakReference *aShell, nsIDOMNode *aDOMNode, nsIAccessible *aAccParent,
nsIAccessible **_retval)
{
nsCOMPtr<nsIPresShell> shell(do_QueryInterface(aShell));
*_retval = new nsHTMLAreaAccessible(shell, aDOMNode, aAccParent);
*_retval = new nsHTMLAreaAccessible(aDOMNode, aAccParent, aShell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
@ -288,20 +316,21 @@ NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports
{
nsIFrame* frame;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIWeakReference> shell;
nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node));
if (NS_FAILED(rv))
return rv;
*_retval = new nsHTMLTextFieldAccessible(shell, node);
*_retval = new nsHTMLTextFieldAccessible(node, shell);
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
} else
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aNode)
NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aNode)
{
*aRealFrame = NS_STATIC_CAST(nsIFrame*, aFrame);
nsCOMPtr<nsIContent> content;
@ -322,7 +351,66 @@ NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aR
NS_ASSERTION(shells > 0,"Error no shells!");
#endif
return document->GetShellAt(0, aShell);
// do_GetWR only works into a |nsCOMPtr| :-(
nsCOMPtr<nsIPresShell> tempShell;
nsCOMPtr<nsIWeakReference> weak;
document->GetShellAt(0, getter_AddRefs(tempShell));
weak = do_GetWeakReference(tempShell);
NS_IF_ADDREF(*aShell = weak);
return NS_OK;
}
NS_IMETHODIMP
nsAccessibilityService::CreateAccessible(nsIDOMNode* node, nsISupports* document, nsIAccessible **_retval)
{
nsCOMPtr<nsIContent> content (do_QueryInterface(node));
nsCOMPtr<nsIDocument> d (do_QueryInterface(document));
if (!d)
return NS_ERROR_FAILURE;
#ifdef DEBUG
PRInt32 shells = d->GetNumberOfShells();
NS_ASSERTION(shells > 0,"Error no shells!");
#endif
nsCOMPtr<nsIPresShell> tempShell;
d->GetShellAt(0, getter_AddRefs(tempShell));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(tempShell);
*_retval = new nsAccessible(node, wr);
if ( *_retval ) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsAccessibilityService::CreateHTMLBlockAccessible(nsIDOMNode* node, nsISupports* document, nsIAccessible **_retval)
{
nsCOMPtr<nsIContent> content (do_QueryInterface(node));
nsCOMPtr<nsIDocument> d (do_QueryInterface(document));
if (!d)
return NS_ERROR_FAILURE;
#ifdef DEBUG
PRInt32 shells = d->GetNumberOfShells();
NS_ASSERTION(shells > 0,"Error no shells!");
#endif
nsCOMPtr<nsIPresShell> tempShell;
d->GetShellAt(0, getter_AddRefs(tempShell));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(tempShell);
*_retval = new nsAccessible(node, wr);
if ( *_retval ) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
@ -340,7 +428,7 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports
presContext->GetShell(getter_AddRefs(presShell));
NS_ASSERTION(presShell,"Error non PresShell passed to accessible factory!!!");
nsCOMPtr<nsIWeakReference> weakRef (getter_AddRefs(NS_GetWeakReference(presShell)));
nsCOMPtr<nsIWeakReference> weakRef = do_GetWeakReference(presShell);
nsCOMPtr<nsIDocument> doc;
if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc))) && doc) {
@ -355,13 +443,22 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports
nsCOMPtr<nsIPresShell> ps;
docShell->GetPresShell(getter_AddRefs(ps));
if (ps) {
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(ps)));
//printf("################################## CreateHTMLIFrameAccessible\n");
nsCOMPtr<nsIAccessible> root = new nsHTMLIFrameRootAccessible(wr,node);
*_retval = new nsHTMLIFrameAccessible(presShell, node, root);
NS_ADDREF(*_retval);
return NS_OK;
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(ps);
nsCOMPtr<nsIDocument> innerDoc;
ps->GetDocument(getter_AddRefs(innerDoc));
if (innerDoc) {
nsCOMPtr<nsIAccessible> root = new nsHTMLIFrameRootAccessible(node, wr);
if ( root ) {
nsHTMLIFrameAccessible* frameAcc = new nsHTMLIFrameAccessible(node, root, weakRef, innerDoc);
if ( frameAcc != nsnull ) {
*_retval = NS_STATIC_CAST(nsIAccessible*, frameAcc);
if ( *_retval ) {
NS_ADDREF(*_retval);
return NS_OK;
}
}
}
}
}
}
}
@ -371,6 +468,155 @@ nsAccessibilityService::CreateHTMLIFrameAccessible(nsIDOMNode* node, nsISupports
}
//-----------------------------------------------------------------------
// This method finds the content node in the parent document
// corresponds to the docshell
// This code is copied and pasted from nsEventStateManager.cpp
// Is also inefficient - better solution should come along as part of
// Bug 85602: "FindContentForDocShell walks entire content tree"
// Hopefully there will be a better method soon, with a public interface
nsIContent*
nsAccessibilityService::FindContentForDocShell(nsIPresShell* aPresShell,
nsIContent* aContent,
nsIDocShell* aDocShell)
{
NS_ASSERTION(aPresShell, "Pointer is null!");
NS_ASSERTION(aDocShell, "Pointer is null!");
NS_ASSERTION(aContent, "Pointer is null!");
nsCOMPtr<nsISupports> supps;
aPresShell->GetSubShellFor(aContent, getter_AddRefs(supps));
if (supps) {
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(supps));
if (docShell.get() == aDocShell)
return aContent;
}
// walk children content
PRInt32 count;
aContent->ChildCount(count);
for (PRInt32 i=0;i<count;i++) {
nsCOMPtr<nsIContent> child;
aContent->ChildAt(i, *getter_AddRefs(child));
nsIContent* foundContent = FindContentForDocShell(aPresShell, child, aDocShell);
if (foundContent != nsnull) {
return foundContent;
}
}
return nsnull;
}
void nsAccessibilityService::GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent)
{
nsCOMPtr<nsIPresContext> presContext;
aPresShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext)
return;
nsCOMPtr<nsISupports> pcContainer;
presContext->GetContainer(getter_AddRefs(pcContainer));
if (!pcContainer)
return;
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(pcContainer));
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docShell));
if (!treeItem)
return;
// Get Parent Doc
nsCOMPtr<nsIDocShellTreeItem> treeItemParent;
treeItem->GetParent(getter_AddRefs(treeItemParent));
if (!treeItemParent)
return;
nsCOMPtr<nsIDocShell> parentDS(do_QueryInterface(treeItemParent));
if (!parentDS)
return;
nsCOMPtr<nsIPresShell> parentPresShell;
parentDS->GetPresShell(getter_AddRefs(parentPresShell));
if (!parentPresShell)
return;
nsCOMPtr<nsIDocument> parentDoc;
parentPresShell->GetDocument(getter_AddRefs(parentDoc));
if (!parentDoc)
return;
nsCOMPtr<nsIContent> rootContent;
parentDoc->GetRootContent(getter_AddRefs(rootContent));
nsIContent *tempContent;
tempContent = FindContentForDocShell(parentPresShell, rootContent, docShell);
if (tempContent) {
*aOwnerContent = tempContent;
*aOwnerShell = parentPresShell;
NS_ADDREF(*aOwnerShell);
NS_ADDREF(*aOwnerContent);
}
}
/* nsIAccessible GetAccessibleFor (in nsISupports aPresShell, in nsIDOMNode aNode); */
NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIWeakReference *aPresShell, nsIDOMNode *aNode,
nsIAccessible **_retval)
{
*_retval = nsnull;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aPresShell));
if (!shell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMHTMLAreaElement> areaContent(do_QueryInterface(aNode));
if (areaContent) // Area elements are implemented in nsHTMLImageAccessible as children of the image
return PR_FALSE; // Return, otherwise the image frame looks like an accessible object in the wrong place
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aNode));
if (!content && doc) {
// This happens when we're on the document node, which will not QI to an nsIContent,
// When that happens, we try to get the outer, parent document node that contains the document
// For example, a <browser> or <iframe> element
nsCOMPtr<nsIPresShell> ownerShell;
nsCOMPtr<nsIContent> ownerContent;
GetOwnerFor(shell, getter_AddRefs(ownerShell), getter_AddRefs(ownerContent));
shell = ownerShell;
content = ownerContent;
}
if (!content)
return PR_FALSE;
nsIFrame* frame = nsnull;
shell->GetPrimaryFrameFor(content, &frame);
if (!frame)
return PR_FALSE;
nsCOMPtr<nsIAccessible> newAcc;
frame->GetAccessible(getter_AddRefs(newAcc));
if (!newAcc)
newAcc = do_QueryInterface(aNode);
if (!newAcc) {
// is it a link?
nsCOMPtr<nsILink> link(do_QueryInterface(aNode));
if (link) {
newAcc = new nsHTMLLinkAccessible(aNode, aPresShell);
}
}
if (!newAcc)
return NS_ERROR_FAILURE;
*_retval = newAcc;
NS_ADDREF(*_retval);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

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

@ -27,8 +27,12 @@
#define __nsAccessibilityService_h__
#include "nsIAccessibilityService.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsIDocShell.h"
class nsIFrame;
class nsIPresShell;
class nsIWeakReference;
class nsIDOMNode;
class nsAccessibilityService : public nsIAccessibilityService
@ -46,7 +50,9 @@ public:
public:
private:
NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aContent);
NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aContent);
void GetOwnerFor(nsIPresShell *aPresShell, nsIPresShell **aOwnerShell, nsIContent **aOwnerContent);
nsIContent* FindContentForDocShell(nsIPresShell* aPresShell, nsIContent* aContent, nsIDocShell* aDocShell);
};

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

@ -21,6 +21,7 @@
*/
#include "nsAccessible.h"
#include "nsIAccessibilityService.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
@ -34,13 +35,30 @@
#include "nsIDOMElement.h"
#include "nsIEventStateManager.h"
#include "nsHTMLFormControlAccessible.h"
#include "nsILink.h"
#include "nsHTMLLinkAccessible.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsXPIDLString.h"
#include "nsIDOMComment.h"
#include "nsITextContent.h"
#include "nsIEventStateManager.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLBRElement.h"
#include "nsIAtom.h"
#include "nsHTMLAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsGUIEvent.h"
#include "nsILink.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsReadableUtils.h"
// IFrame Helpers
#include "nsIDocShell.h"
#include "nsIWebShell.h"
@ -398,6 +416,7 @@ public:
nsCOMPtr<nsIWeakReference> mPresShell;
nsCOMPtr<nsIAccessible> mAccessible;
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIAccessibilityService> mAccService;
};
nsDOMTreeWalker::nsDOMTreeWalker(nsIWeakReference* aPresShell, nsIDOMNode* aNode)
@ -405,6 +424,7 @@ nsDOMTreeWalker::nsDOMTreeWalker(nsIWeakReference* aPresShell, nsIDOMNode* aNode
mDOMNode = aNode;
mAccessible = nsnull;
mPresShell = aPresShell;
mAccService = do_GetService("@mozilla.org/accessibilityService;1");
}
nsRect nsDOMTreeWalker::GetBounds()
@ -420,6 +440,9 @@ nsRect nsDOMTreeWalker::GetBounds()
nsIFrame* nsDOMTreeWalker::GetPrimaryFrame()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return nsnull;
nsIFrame* frame = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
shell->GetPrimaryFrameFor(content, &frame);
@ -472,7 +495,7 @@ PRBool nsDOMTreeWalker::GetParent()
if (!accessible)
accessible = do_QueryInterface(content);
if (accessible) {
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(parentPresShell)));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(parentPresShell);
accessible->AccGetDOMNode(getter_AddRefs(mDOMNode));
mAccessible = accessible;
mPresShell = wr;
@ -721,37 +744,15 @@ PRBool nsDOMTreeWalker::GetAccessible()
{
mAccessible = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
if (!content)
if (!mAccService)
return PR_FALSE;
nsCOMPtr<nsIDOMHTMLAreaElement> areaContent(do_QueryInterface(mDOMNode));
if (areaContent) // Area elements are implemented in nsHTMLImageAccessible as children of the image
return PR_FALSE; // Return, otherwise the image frame looks like an accessible object in the wrong place
nsIFrame* frame = GetPrimaryFrame();
if (!frame)
return PR_FALSE;
frame->GetAccessible(getter_AddRefs(mAccessible));
if (!mAccessible)
mAccessible = do_QueryInterface(mDOMNode);
if (!mAccessible) {
// is it a link?
nsCOMPtr<nsILink> link(do_QueryInterface(mDOMNode));
if (link) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
mAccessible = new nsHTMLLinkAccessible(shell, mDOMNode);
}
}
mAccService->GetAccessibleFor(mPresShell, mDOMNode, getter_AddRefs(mAccessible));
if (mAccessible)
return PR_TRUE;
else
return PR_FALSE;
return PR_FALSE;
}
@ -759,22 +760,21 @@ PRBool nsDOMTreeWalker::GetAccessible()
* Class nsAccessible
*/
//-----------------------------------------------------
//-------------------------`----------------------------
// construction
//-----------------------------------------------------
nsAccessible::nsAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
nsAccessible::nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell)
{
NS_INIT_REFCNT();
// get frame and node
mDOMNode = aNode;
mAccessible = aAccessible;
mPresShell = aShell;
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (shell)
shell->GetDocument(getter_AddRefs(document));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
if (content)
content->GetDocument(*getter_AddRefs(document));
if (document) {
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
document->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
@ -815,24 +815,14 @@ nsAccessible::~nsAccessible()
#endif
}
NS_IMPL_ISUPPORTS1(nsAccessible, nsIAccessible);
nsresult nsAccessible::GetAccParent(nsIAccessible ** aAccParent)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccParent(aAccParent);
if (NS_SUCCEEDED(rv))
return rv;
}
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
nsDOMTreeWalker walker(mPresShell, mDOMNode);
if (walker.GetParent()) {
*aAccParent = CreateNewParentAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccParent = walker.mAccessible;
NS_ADDREF(*aAccParent);
return NS_OK;
}
@ -844,23 +834,13 @@ nsresult nsAccessible::GetAccParent(nsIAccessible ** aAccParent)
/* readonly attribute nsIAccessible accNextSibling; */
NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccNextSibling(aAccNextSibling);
if (NS_SUCCEEDED(rv))
return rv;
}
// failed? Lets do some default behavior
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetNextSibling();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccNextSibling = CreateNewNextAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccNextSibling = walker.mAccessible;
NS_ADDREF(*aAccNextSibling);
return NS_OK;
}
@ -872,22 +852,14 @@ NS_IMETHODIMP nsAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling)
/* readonly attribute nsIAccessible accPreviousSibling; */
NS_IMETHODIMP nsAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousSibling)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccPreviousSibling(aAccPreviousSibling);
if (NS_SUCCEEDED(rv))
return rv;
}
{
// failed? Lets do some default behavior
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetPreviousSibling();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccPreviousSibling = CreateNewPreviousAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccPreviousSibling = walker.mAccessible;
NS_ADDREF(*aAccPreviousSibling);
return NS_OK;
}
@ -900,19 +872,12 @@ NS_IMETHODIMP nsAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousS
/* readonly attribute nsIAccessible accFirstChild; */
NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccFirstChild(aAccFirstChild);
if (NS_SUCCEEDED(rv))
return rv;
}
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetFirstChild();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccFirstChild = CreateNewFirstAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccFirstChild = walker.mAccessible;
NS_ADDREF(*aAccFirstChild);
return NS_OK;
}
@ -925,19 +890,12 @@ NS_IMETHODIMP nsAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild)
/* readonly attribute nsIAccessible accFirstChild; */
NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccLastChild)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccLastChild(aAccLastChild);
if (NS_SUCCEEDED(rv))
return rv;
}
nsDOMTreeWalker walker(mPresShell, mDOMNode);
walker.GetLastChild();
if (walker.mAccessible && walker.mDOMNode)
{
*aAccLastChild = CreateNewLastAccessible(walker.mAccessible, walker.mDOMNode, walker.mPresShell);
*aAccLastChild = walker.mAccessible;
NS_ADDREF(*aAccLastChild);
return NS_OK;
}
@ -950,48 +908,12 @@ NS_IMETHODIMP nsAccessible::GetAccLastChild(nsIAccessible * *aAccLastChild)
/* readonly attribute long accChildCount; */
NS_IMETHODIMP nsAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccChildCount(aAccChildCount);
if (NS_SUCCEEDED(rv))
return rv;
}
// failed? Lets do some default behavior
nsDOMTreeWalker walker(mPresShell, mDOMNode);
*aAccChildCount = walker.GetCount();
return NS_OK;
}
/* attribute wstring accName; */
NS_IMETHODIMP nsAccessible::GetAccName(PRUnichar * *aAccName)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccName(aAccName);
if (NS_SUCCEEDED(rv) && *aAccName != nsnull)
return rv;
}
*aAccName = 0;
return NS_ERROR_NOT_IMPLEMENTED;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 0;
if (mAccessible)
mAccessible->GetAccNumActions(_retval);
return NS_OK;
}
nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *aStringOut)
{
static nsCOMPtr<nsIStringBundle> stringBundle;
@ -1018,101 +940,12 @@ nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *a
return NS_OK;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
{
PRUint8 numActions;
*_retval = 0;
if (mAccessible && NS_SUCCEEDED(GetAccNumActions(&numActions)) && index<numActions) {
nsresult rv = mAccessible->GetAccActionName(index, _retval);
if (*_retval && NS_SUCCEEDED(rv)) {
nsAutoString newString;
rv = GetTranslatedString(*_retval, &newString);
if (NS_SUCCEEDED(rv)) {
delete *_retval;
*_retval = newString.ToNewUnicode();
}
}
return NS_OK; // keep key for name if can't get translated version
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::AccDoAction(PRUint8 index)
{
PRUint8 numActions;
return (mAccessible && NS_SUCCEEDED(GetAccNumActions(&numActions)) && index<numActions)?
mAccessible->AccDoAction(index): NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsAccessible::SetAccName(const PRUnichar * aAccName)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->SetAccName(aAccName);
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute wstring accValue; */
NS_IMETHODIMP nsAccessible::GetAccValue(PRUnichar * *aAccValue)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccValue(aAccValue);
if (NS_SUCCEEDED(rv) && *aAccValue != nsnull)
return rv;
}
*aAccValue = 0;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsAccessible::SetAccValue(const PRUnichar * aAccValue) { return NS_ERROR_NOT_IMPLEMENTED; }
/* readonly attribute wstring accDescription; */
NS_IMETHODIMP nsAccessible::GetAccDescription(PRUnichar * *aAccDescription)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccDescription(aAccDescription);
if (NS_SUCCEEDED(rv) && *aAccDescription != nsnull)
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute unsigned long accRole; */
NS_IMETHODIMP nsAccessible::GetAccRole(PRUint32 *aAccRole)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccRole(aAccRole);
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute wstring accState; */
/* readonly attribute wstring accState; */
NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState)
{
nsresult rv = NS_OK;
*aAccState = 0;
// delegate
if (mAccessible)
rv = mAccessible->GetAccState(aAccState);
if (NS_SUCCEEDED(rv) && mFocusController) {
nsCOMPtr<nsIDOMElement> focusedElement, currElement(do_QueryInterface(mDOMNode));
mFocusController->GetFocusedElement(getter_AddRefs(focusedElement));
@ -1123,29 +956,6 @@ NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState)
return rv;
}
NS_IMETHODIMP nsAccessible::GetAccExtState(PRUint32 *aAccExtState)
{
// delegate
if (mAccessible)
return mAccessible->GetAccExtState(aAccExtState);
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute wstring accHelp; */
NS_IMETHODIMP nsAccessible::GetAccHelp(PRUnichar * *aAccHelp)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->GetAccHelp(aAccHelp);
if (NS_SUCCEEDED(rv) && *aAccHelp != nsnull)
return rv;
}
// failed? Lets do some default behavior
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute boolean accFocused; */
NS_IMETHODIMP nsAccessible::GetAccFocused(nsIAccessible * *aAccFocused)
{
@ -1157,6 +967,11 @@ NS_IMETHODIMP nsAccessible::GetAccFocused(nsIAccessible * *aAccFocused)
nsIFrame *frame = nsnull;
if (focusedElement) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
*aAccFocused = nsnull;
return NS_OK;
}
nsCOMPtr<nsIContent> content(do_QueryInterface(focusedElement));
if (shell && content)
shell->GetPrimaryFrameFor(content, &frame);
@ -1210,86 +1025,6 @@ NS_IMETHODIMP nsAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_re
return NS_OK;
}
/* void accNavigateRight (); */
NS_IMETHODIMP nsAccessible::AccNavigateRight(nsIAccessible **_retval) { return NS_OK; }
/* void navigateLeft (); */
NS_IMETHODIMP nsAccessible::AccNavigateLeft(nsIAccessible **_retval) { return NS_OK; }
/* void navigateUp (); */
NS_IMETHODIMP nsAccessible::AccNavigateUp(nsIAccessible **_retval) { return NS_OK; }
/* void navigateDown (); */
NS_IMETHODIMP nsAccessible::AccNavigateDown(nsIAccessible **_retval) { return NS_OK; }
/* void addSelection (); */
NS_IMETHODIMP nsAccessible::AccAddSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccAddSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void removeSelection (); */
NS_IMETHODIMP nsAccessible::AccRemoveSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccRemoveSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void extendSelection (); */
NS_IMETHODIMP nsAccessible::AccExtendSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccExtendSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void takeSelection (); */
NS_IMETHODIMP nsAccessible::AccTakeSelection(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccTakeSelection();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
/* void takeFocus (); */
NS_IMETHODIMP nsAccessible::AccTakeFocus(void)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccTakeFocus();
if (NS_SUCCEEDED(rv))
return rv;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsAccessible::AccGetDOMNode(nsIDOMNode **_retval)
{
*_retval = mDOMNode;
@ -1597,12 +1332,6 @@ void nsAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeParent)
/* 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)
{
// delegate
if (mAccessible) {
nsresult rv = mAccessible->AccGetBounds(x,y,width,height);
if (NS_SUCCEEDED(rv))
return rv;
}
// This routine will get the entire rectange for all the frames in this node
// -------------------------------------------------------------------------
@ -1661,6 +1390,9 @@ nsIFrame* nsAccessible::GetBoundsFrame()
nsIFrame* nsAccessible::GetFrame()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return nsnull;
nsIFrame* frame = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
shell->GetPrimaryFrameFor(content, &frame);
@ -1677,49 +1409,195 @@ void nsAccessible::GetPresContext(nsCOMPtr<nsIPresContext>& aContext)
aContext = nsnull;
}
nsIAccessible* nsAccessible::CreateNewNextAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
/* void accRemoveSelection (); */
NS_IMETHODIMP nsAccessible::AccRemoveSelection()
{
return CreateNewAccessible(aAccessible, aNode, aShell);
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
if (!control) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mDOMNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
rv = selection->Collapse(parent, 0);
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
nsIAccessible* nsAccessible::CreateNewPreviousAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
/* void accTakeSelection (); */
NS_IMETHODIMP nsAccessible::AccTakeSelection()
{
return CreateNewAccessible(aAccessible, aNode, aShell);
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
if (!control) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mDOMNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
PRInt32 offsetInParent = 0;
nsCOMPtr<nsIDOMNode> child;
rv = parent->GetFirstChild(getter_AddRefs(child));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> next;
while(child)
{
if (child == mDOMNode) {
// Collapse selection to just before desired element,
rv = selection->Collapse(parent, offsetInParent);
if (NS_FAILED(rv))
return rv;
// then extend it to just after
rv = selection->Extend(parent, offsetInParent+1);
return rv;
}
child->GetNextSibling(getter_AddRefs(next));
child = next;
offsetInParent++;
}
// didn't find a child
return NS_ERROR_FAILURE;
}
nsIAccessible* nsAccessible::CreateNewParentAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
return CreateNewAccessible(aAccessible, aNode, aShell);
/* void accTakeFocus (); */
NS_IMETHODIMP nsAccessible::AccTakeFocus()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
content->SetFocus(context);
return NS_OK;
}
nsIAccessible* nsAccessible::CreateNewFirstAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
NS_IMETHODIMP nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString)
{
return CreateNewAccessible(aAccessible, aNode, aShell);
nsCOMPtr<nsITextContent> textContent(do_QueryInterface(aContent));
if (textContent) {
nsCOMPtr<nsIDOMComment> commentNode(do_QueryInterface(aContent));
if (!commentNode) {
PRBool isHTMLBlock = PR_FALSE;
nsIFrame *frame;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIContent> parentContent;
aContent->GetParent(*getter_AddRefs(parentContent));
if (parentContent) {
nsresult rv = shell->GetPrimaryFrameFor(parentContent, &frame);
if (NS_SUCCEEDED(rv)) {
// If this text is inside a block level frame (as opposed to span level), we need to add spaces around that
// block's text, so we don't get words jammed together in final name
// Extra spaces will be trimmed out later
nsCOMPtr<nsIStyleContext> styleContext;
frame->GetStyleContext(getter_AddRefs(styleContext));
if (styleContext) {
const nsStyleDisplay* display = (const nsStyleDisplay*)styleContext->GetStyleData(eStyleStruct_Display);
if (display->IsBlockLevel() || display->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
isHTMLBlock = PR_TRUE;
aFlatString->Append(NS_LITERAL_STRING(" "));
}
}
}
}
nsAutoString text;
textContent->CopyText(text);
if (text.Length()>0)
aFlatString->Append(text);
if (isHTMLBlock)
aFlatString->Append(NS_LITERAL_STRING(" "));
}
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLBRElement> brElement(do_QueryInterface(aContent));
if (brElement) {
aFlatString->Append(NS_LITERAL_STRING(" "));
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLImageElement> imageContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent(do_QueryInterface(aContent));
if (imageContent || inputContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aContent));
nsAutoString textEquivalent;
elt->GetAttribute(NS_LITERAL_STRING("alt"), textEquivalent);
if (textEquivalent.IsEmpty())
elt->GetAttribute(NS_LITERAL_STRING("title"), textEquivalent);
if (textEquivalent.IsEmpty())
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 NS_OK;
}
nsIAccessible* nsAccessible::CreateNewLastAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
NS_IMETHODIMP nsAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString)
{
return CreateNewAccessible(aAccessible, aNode, aShell);
// Depth first search for all text nodes that are decendants of content node.
// Append all the text into one flat string
PRInt32 numChildren = 0;
aContent->ChildCount(numChildren);
if (numChildren == 0) {
AppendFlatStringFromContentNode(aContent, aFlatString);
return NS_OK;
}
nsIContent *contentWalker;
PRInt32 index;
for (index = 0; index < numChildren; index++) {
aContent->ChildAt(index, contentWalker);
AppendFlatStringFromSubtree(contentWalker, aFlatString);
}
return NS_OK;
}
nsIAccessible* nsAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
NS_ASSERTION(aAccessible && aNode,"Error not accessible or content");
return new nsAccessible(aAccessible, aNode, aShell);
}
// ------- nsHTMLBlockAccessible ------
nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aAccessible, aNode, aShell)
nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aNode, aShell)
{
}
nsIAccessible* nsHTMLBlockAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
NS_ASSERTION(aAccessible && aNode,"Error not accessible or content");
return new nsHTMLBlockAccessible(aAccessible, aNode, aShell);
}
/* nsIAccessible accGetAt (in long x, in long y); */
NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval)
{
@ -1775,7 +1653,170 @@ NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessi
return NS_OK;
}
//-------------
// nsLeafFrameAccessible
//-------------
nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsAccessible(aNode, aShell)
{
}
/* nsIAccessible getAccFirstChild (); */
NS_IMETHODIMP nsLeafAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* nsIAccessible getAccLastChild (); */
NS_IMETHODIMP nsLeafAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* long getAccChildCount (); */
NS_IMETHODIMP nsLeafAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 0;
return NS_OK;
}
//----------------
// nsLinkableAccessible
//----------------
nsLinkableAccessible::nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsAccessible(aNode, aShell), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE)
{
}
/* long GetAccState (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval)
{
nsAccessible::GetAccState(_retval);
*_retval |= STATE_READONLY | STATE_SELECTABLE;
if (IsALink()) {
*_retval |= STATE_FOCUSABLE | STATE_LINKED;
if (mIsLinkVisited)
*_retval |= STATE_TRAVERSED;
}
// Get current selection and find out if current node is in it
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsIFrame *frame;
if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) {
nsCOMPtr<nsISelectionController> selCon;
frame->GetSelectionController(context,getter_AddRefs(selCon));
if (selCon) {
nsCOMPtr<nsISelection> domSel;
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel));
if (domSel) {
PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE;
domSel->ContainsNode(mDOMNode, PR_TRUE, &isSelected);
domSel->GetIsCollapsed(&isCollapsed);
if (isSelected && !isCollapsed)
*_retval |=STATE_SELECTED;
}
}
}
// Focused? Do we implement that here or up the chain?
return NS_OK;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
// Action 0 (default action): Jump to link
if (index == 0) {
if (IsALink()) {
_retval = NS_LITERAL_STRING("jump");
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index)
{
// Action 0 (default action): Jump to link
if (index == 0) {
if (IsALink()) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsMouseEvent linkClickEvent;
linkClickEvent.eventStructType = NS_EVENT;
linkClickEvent.message = NS_MOUSE_LEFT_CLICK;
linkClickEvent.isShift = PR_FALSE;
linkClickEvent.isControl = PR_FALSE;
linkClickEvent.isAlt = PR_FALSE;
linkClickEvent.isMeta = PR_FALSE;
linkClickEvent.clickCount = 0;
linkClickEvent.widget = nsnull;
nsEventStatus eventStatus = nsEventStatus_eIgnore;
mLinkContent->HandleDOMEvent(presContext,
&linkClickEvent,
nsnull,
NS_EVENT_FLAG_INIT,
&eventStatus);
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
PRBool nsLinkableAccessible::IsALink()
{
if (mIsALinkCached) // Cached answer?
return mLinkContent? PR_TRUE: PR_FALSE;
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
if (walkUpContent) {
nsCOMPtr<nsIContent> tempContent = walkUpContent;
while (walkUpContent) {
nsCOMPtr<nsILink> link(do_QueryInterface(walkUpContent));
if (link) {
mLinkContent = tempContent;
mIsALinkCached = PR_TRUE;
nsLinkState linkState;
link->GetLinkState(linkState);
if (linkState == eLinkState_Visited)
mIsLinkVisited = PR_TRUE;
return PR_TRUE;
}
walkUpContent->GetParent(*getter_AddRefs(tempContent));
walkUpContent = tempContent;
}
}
mIsALinkCached = PR_TRUE; // Cached that there is no link
return PR_FALSE;
}

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

@ -24,7 +24,7 @@
#define _nsAccessible_H_
#include "nsISupports.h"
#include "nsIAccessible.h"
#include "nsGenericAccessible.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
@ -42,16 +42,26 @@ class nsIDocShell;
class nsIWebShell;
class nsIContent;
class nsAccessible : public nsIAccessible
// public nsIAccessibleWidgetAccess
class nsAccessible : public nsGenericAccessible
{
NS_DECL_ISUPPORTS
// nsIAccessibilityService methods:
NS_DECL_NSIACCESSIBLE
public:
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccFocused(nsIAccessible **_retval);
NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval);
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
NS_IMETHOD AccRemoveSelection(void);
NS_IMETHOD AccTakeSelection(void);
NS_IMETHOD AccTakeFocus(void);
NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval);
public:
nsAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual ~nsAccessible();
virtual void GetListAtomForFrame(nsIFrame* aFrame, nsIAtom*& aList) { aList = nsnull; }
@ -87,28 +97,53 @@ protected:
virtual nsIFrame* GetBoundsFrame();
virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual void GetPresContext(nsCOMPtr<nsIPresContext>& aContext);
virtual nsIAccessible* CreateNewNextAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewPreviousAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewParentAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewFirstAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewLastAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString);
NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString);
// Data Members
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIWeakReference> mPresShell;
nsCOMPtr<nsIAccessible> mAccessible;
nsCOMPtr<nsIFocusController> mFocusController;
};
/* Special Accessible that knows how to handle hit detection for flowing text */
class nsHTMLBlockAccessible : public nsAccessible
{
public:
nsHTMLBlockAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval);
protected:
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aFrame, nsIWeakReference* aShell);
};
/* Leaf version of DOM Accessible
* has no children
*/
class nsLeafAccessible : public nsAccessible
{
public:
nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
};
class nsLinkableAccessible : public nsAccessible
{
public:
nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccState(PRUint32 *_retval);
protected:
PRBool IsALink();
PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link
nsCOMPtr<nsIContent> mLinkContent;
PRBool mIsLinkVisited;
};
#endif

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

@ -22,25 +22,11 @@
*/
#include "nsGenericAccessible.h"
#include "nsIEventStateManager.h"
#include "nsIFrame.h"
#include "nsCOMPtr.h"
#include "nsIWeakReference.h"
#include "nsReadableUtils.h"
#include "nsILink.h"
#include "nsIContent.h"
#include "nsITextContent.h"
#include "nsIDOMComment.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLBRElement.h"
#include "nsIAtom.h"
#include "nsHTMLAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsGUIEvent.h"
/* Implementation file */
NS_IMPL_ISUPPORTS1(nsGenericAccessible, nsIAccessible)
@ -93,31 +79,25 @@ NS_IMETHODIMP nsGenericAccessible::GetAccChildCount(PRInt32 *_retval)
}
/* wstring getAccName (); */
NS_IMETHODIMP nsGenericAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccName(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* wstring getAccValue (); */
NS_IMETHODIMP nsGenericAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccValue(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void setAccName (in wstring name); */
NS_IMETHODIMP nsGenericAccessible::SetAccName(const PRUnichar *name)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void setAccValue (in wstring value); */
NS_IMETHODIMP nsGenericAccessible::SetAccValue(const PRUnichar *value)
NS_IMETHODIMP nsGenericAccessible::SetAccName(const nsAReadableString& name)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* wstring getAccDescription (); */
NS_IMETHODIMP nsGenericAccessible::GetAccDescription(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccDescription(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -141,7 +121,7 @@ NS_IMETHODIMP nsGenericAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsGenericAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -159,7 +139,7 @@ NS_IMETHODIMP nsGenericAccessible::GetAccFocused(nsIAccessible **_retval)
}
/* wstring getAccHelp (); */
NS_IMETHODIMP nsGenericAccessible::GetAccHelp(PRUnichar **_retval)
NS_IMETHODIMP nsGenericAccessible::GetAccHelp(nsAWritableString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -241,356 +221,4 @@ NS_IMETHODIMP nsGenericAccessible::AccGetDOMNode(nsIDOMNode **_retval)
return NS_ERROR_NOT_IMPLEMENTED;
}
//-------------
// nsDOMAccessible
//-------------
NS_IMETHODIMP
nsDOMAccessible::QueryInterface(REFNSIID aIID, void** aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(NS_GET_IID(nsIDOMNode))) {
nsIDOMNode* node = mNode;
*aResult = (void*) node;
NS_ADDREF(node);
return NS_OK;
}
return nsGenericAccessible::QueryInterface(aIID, aResult);
}
nsDOMAccessible::nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode)
{
mPresShell = do_GetWeakReference(aShell);
mNode = aNode;
}
NS_IMETHODIMP nsDOMAccessible::AccGetDOMNode(nsIDOMNode **_retval)
{
*_retval = mNode;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
/* void accRemoveSelection (); */
NS_IMETHODIMP nsDOMAccessible::AccRemoveSelection()
{
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
rv = selection->Collapse(parent, 0);
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
/* void accTakeSelection (); */
NS_IMETHODIMP nsDOMAccessible::AccTakeSelection()
{
nsCOMPtr<nsISelectionController> control(do_QueryReferent(mPresShell));
nsCOMPtr<nsISelection> selection;
nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> parent;
rv = mNode->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(rv))
return rv;
PRInt32 offsetInParent = 0;
nsCOMPtr<nsIDOMNode> child;
rv = parent->GetFirstChild(getter_AddRefs(child));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> next;
while(child)
{
if (child == mNode) {
// Collapse selection to just before desired element,
rv = selection->Collapse(parent, offsetInParent);
if (NS_FAILED(rv))
return rv;
// then extend it to just after
rv = selection->Extend(parent, offsetInParent+1);
return rv;
}
child->GetNextSibling(getter_AddRefs(next));
child = next;
offsetInParent++;
}
// didn't find a child
return NS_ERROR_FAILURE;
}
/* void accTakeFocus (); */
NS_IMETHODIMP nsDOMAccessible::AccTakeFocus()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
content->SetFocus(context);
return NS_OK;
}
NS_IMETHODIMP nsDOMAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString)
{
nsCOMPtr<nsITextContent> textContent(do_QueryInterface(aContent));
if (textContent) {
nsCOMPtr<nsIDOMComment> commentNode(do_QueryInterface(aContent));
if (!commentNode) {
PRBool isHTMLBlock = PR_FALSE;
nsIFrame *frame;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIContent> parentContent;
aContent->GetParent(*getter_AddRefs(parentContent));
if (parentContent) {
nsresult rv = shell->GetPrimaryFrameFor(parentContent, &frame);
if (NS_SUCCEEDED(rv)) {
// If this text is inside a block level frame (as opposed to span level), we need to add spaces around that
// block's text, so we don't get words jammed together in final name
// Extra spaces will be trimmed out later
nsCOMPtr<nsIStyleContext> styleContext;
frame->GetStyleContext(getter_AddRefs(styleContext));
if (styleContext) {
const nsStyleDisplay* display = (const nsStyleDisplay*)styleContext->GetStyleData(eStyleStruct_Display);
if (display->IsBlockLevel() || display->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
isHTMLBlock = PR_TRUE;
aFlatString->Append(NS_LITERAL_STRING(" "));
}
}
}
}
nsAutoString text;
textContent->CopyText(text);
if (text.Length()>0)
aFlatString->Append(text);
if (isHTMLBlock)
aFlatString->Append(NS_LITERAL_STRING(" "));
}
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLBRElement> brElement(do_QueryInterface(aContent));
if (brElement) {
aFlatString->Append(NS_LITERAL_STRING(" "));
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLImageElement> imageContent(do_QueryInterface(aContent));
nsCOMPtr<nsIDOMHTMLInputElement> inputContent(do_QueryInterface(aContent));
if (imageContent || inputContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aContent));
nsAutoString textEquivalent;
elt->GetAttribute(NS_LITERAL_STRING("alt"), textEquivalent);
if (textEquivalent.IsEmpty())
elt->GetAttribute(NS_LITERAL_STRING("title"), textEquivalent);
if (textEquivalent.IsEmpty())
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 NS_OK;
}
NS_IMETHODIMP nsDOMAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString)
{
// Depth first search for all text nodes that are decendants of content node.
// Append all the text into one flat string
PRInt32 numChildren = 0;
aContent->ChildCount(numChildren);
if (numChildren == 0) {
nsAutoString contentText;
AppendFlatStringFromContentNode(aContent, aFlatString);
return NS_OK;
}
nsIContent *contentWalker;
PRInt32 index;
for (index = 0; index < numChildren; index++) {
aContent->ChildAt(index, contentWalker);
AppendFlatStringFromSubtree(contentWalker, aFlatString);
}
return NS_OK;
}
//-------------
// nsLeafFrameAccessible
//-------------
nsLeafDOMAccessible::nsLeafDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsDOMAccessible(aShell, aNode)
{
}
/* nsIAccessible getAccFirstChild (); */
NS_IMETHODIMP nsLeafDOMAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* nsIAccessible getAccLastChild (); */
NS_IMETHODIMP nsLeafDOMAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
/* long getAccChildCount (); */
NS_IMETHODIMP nsLeafDOMAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 0;
return NS_OK;
}
//----------------
// nsLinkableAccessible
//----------------
nsLinkableAccessible::nsLinkableAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsDOMAccessible(aShell, aDomNode), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE)
{
}
/* long GetAccState (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval)
{
*_retval |= STATE_READONLY | STATE_SELECTABLE;
if (IsALink()) {
*_retval |= STATE_FOCUSABLE | STATE_LINKED;
if (mIsLinkVisited)
*_retval |= STATE_TRAVERSED;
}
// Get current selection and find out if current node is in it
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
nsIFrame *frame;
if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) {
nsCOMPtr<nsISelectionController> selCon;
frame->GetSelectionController(context,getter_AddRefs(selCon));
if (selCon) {
nsCOMPtr<nsISelection> domSel;
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel));
if (domSel) {
PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE;
domSel->ContainsNode(mNode, PR_TRUE, &isSelected);
domSel->GetIsCollapsed(&isCollapsed);
if (isSelected && !isCollapsed)
*_retval |=STATE_SELECTED;
}
}
}
// Focused? Do we implement that here or up the chain?
return NS_OK;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
{
if (index == 0) {
if (IsALink()) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("jump"));
return NS_OK;
}
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
if (IsALink()) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsMouseEvent linkClickEvent;
linkClickEvent.eventStructType = NS_EVENT;
linkClickEvent.message = NS_MOUSE_LEFT_CLICK;
linkClickEvent.isShift = PR_FALSE;
linkClickEvent.isControl = PR_FALSE;
linkClickEvent.isAlt = PR_FALSE;
linkClickEvent.isMeta = PR_FALSE;
linkClickEvent.clickCount = 0;
linkClickEvent.widget = nsnull;
nsEventStatus eventStatus = nsEventStatus_eIgnore;
mLinkContent->HandleDOMEvent(presContext, &linkClickEvent,
nsnull, NS_EVENT_FLAG_INIT, &eventStatus);
return NS_OK;
}
}
}
return NS_ERROR_NOT_IMPLEMENTED;
}
PRBool nsLinkableAccessible::IsALink()
{
if (mIsALinkCached) // Cached answer?
return mLinkContent? PR_TRUE: PR_FALSE;
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mNode));
if (walkUpContent) {
nsCOMPtr<nsIContent> tempContent = walkUpContent;
while (walkUpContent) {
nsCOMPtr<nsILink> link(do_QueryInterface(walkUpContent));
if (link) {
mLinkContent = tempContent;
mIsALinkCached = PR_TRUE;
nsLinkState linkState;
link->GetLinkState(linkState);
if (linkState == eLinkState_Visited)
mIsLinkVisited = PR_TRUE;
return PR_TRUE;
}
walkUpContent->GetParent(*getter_AddRefs(tempContent));
walkUpContent = tempContent;
}
}
mIsALinkCached = PR_TRUE; // Cached that there is no link
return PR_FALSE;
}

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

@ -47,61 +47,5 @@ class nsGenericAccessible : public nsIAccessible
virtual ~nsGenericAccessible();
};
/**
* And accessible that observes a dom node
* supports:
* - selection
* - focus
*/
class nsDOMAccessible : public nsGenericAccessible
{
public:
nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD AccTakeSelection(void);
NS_IMETHOD AccTakeFocus(void);
NS_IMETHOD AccRemoveSelection(void);
NS_IMETHOD AccGetDOMNode(nsIDOMNode **_retval);
protected:
NS_IMETHOD AppendFlatStringFromSubtree(nsIContent *aContent, nsAWritableString *aFlatString);
NS_IMETHOD AppendFlatStringFromContentNode(nsIContent *aContent, nsAWritableString *aFlatString);
nsCOMPtr<nsIWeakReference> mPresShell;
nsCOMPtr<nsIDOMNode> mNode;
};
/* Leaf version of DOM Accessible
* has no children
*/
class nsLeafDOMAccessible : public nsDOMAccessible
{
public:
nsLeafDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
};
class nsLinkableAccessible : public nsDOMAccessible
{
public:
nsLinkableAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccState(PRUint32 *_retval);
protected:
nsCOMPtr<nsIDOMNode> mDomNode;
PRBool IsALink();
PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link
nsCOMPtr<nsIContent> mLinkContent;
PRBool mIsLinkVisited;
};
#endif

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

@ -33,23 +33,18 @@
// --- area -----
nsHTMLAreaAccessible::nsHTMLAreaAccessible(nsIPresShell *aPresShell, nsIDOMNode *aDomNode, nsIAccessible *aAccParent):
nsGenericAccessible(), mPresShell(aPresShell), mDOMNode(aDomNode), mAccParent(aAccParent)
nsHTMLAreaAccessible::nsHTMLAreaAccessible(nsIDOMNode *aDomNode, nsIAccessible *aAccParent, nsIWeakReference* aShell):
nsLinkableAccessible(aDomNode, aShell), mAccParent(aAccParent)
{
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccName(nsAWritableString & _retval)
{
*_retval = 0;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
if (elt) {
nsAutoString hrefString;
elt->GetAttribute(NS_LITERAL_STRING("title"), hrefString);
if (!hrefString.IsEmpty()) {
*_retval = hrefString.ToNewUnicode();
return NS_OK;
}
elt->GetAttribute(NS_LITERAL_STRING("title"), _retval);
}
return NS_OK;
}
@ -62,85 +57,25 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetAccRole(PRUint32 *_retval)
}
/* wstring getAccValue (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccValue(nsAWritableString& _retval)
{
*_retval = 0;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
if (elt) {
nsAutoString hrefString;
elt->GetAttribute(NS_LITERAL_STRING("href"), hrefString);
*_retval = hrefString.ToNewUnicode();
}
if (elt)
elt->GetAttribute(NS_LITERAL_STRING("href"), _retval);
return NS_OK;
}
/* wstring getAccDescription (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccDescription(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccDescription(nsAWritableString& _retval)
{
// Still to do - follow IE's standard here
*_retval = 0;
nsAutoString shapeString;
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mDOMNode));
if (area) {
area->GetShape(shapeString);
if (!shapeString.IsEmpty())
*_retval = ToNewUnicode(shapeString);
}
if (area)
area->GetShape(_retval);
return NS_OK;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("jump"));
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsHTMLAreaAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIPresContext> presContext;
mPresShell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsMouseEvent linkClickEvent;
linkClickEvent.eventStructType = NS_EVENT;
linkClickEvent.message = NS_MOUSE_LEFT_CLICK;
linkClickEvent.isShift = PR_FALSE;
linkClickEvent.isControl = PR_FALSE;
linkClickEvent.isAlt = PR_FALSE;
linkClickEvent.isMeta = PR_FALSE;
linkClickEvent.clickCount = 0;
linkClickEvent.widget = nsnull;
nsEventStatus eventStatus = nsEventStatus_eIgnore;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
content->HandleDOMEvent(presContext, &linkClickEvent,
nsnull, NS_EVENT_FLAG_INIT, &eventStatus);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccState(PRUint32 *_retval)
{
*_retval = STATE_LINKED | STATE_FOCUSABLE | STATE_READONLY;
return NS_OK;
}
/* nsIAccessible getAccFirstChild (); */
NS_IMETHODIMP nsHTMLAreaAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
@ -172,8 +107,7 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetAccParent(nsIAccessible * *aAccParent)
nsIAccessible *nsHTMLAreaAccessible::CreateAreaAccessible(nsIDOMNode *aDOMNode)
{
nsresult rv;
NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv);
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (accService) {
nsIAccessible* acc = nsnull;
accService->CreateHTMLAreaAccessible(mPresShell, aDOMNode, mAccParent, &acc);

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

@ -25,37 +25,31 @@
#define _nsHTMLAreaAccessible_H_
#include "nsGenericAccessible.h"
#include "nsHTMLLinkAccessible.h"
#include "nsAccessible.h"
/* Accessible for image map areas - must be child of image
*/
class nsHTMLAreaAccessible : public nsGenericAccessible
class nsHTMLAreaAccessible : public nsLinkableAccessible
{
public:
nsHTMLAreaAccessible(nsIPresShell *presShell, nsIDOMNode *domNode, nsIAccessible *accParent);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLAreaAccessible(nsIDOMNode *domNode, nsIAccessible *accParent, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString & _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccValue(PRUnichar **_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent);
NS_IMETHOD GetAccNextSibling(nsIAccessible * *aAccNextSibling);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible * *aAccPreviousSibling);
NS_IMETHOD GetAccDescription(PRUnichar **_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccDescription(nsAWritableString& _retval);
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
protected:
nsIAccessible *CreateAreaAccessible(nsIDOMNode *aDOMNode);
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIAccessible> mAccParent;
nsCOMPtr<nsIPresShell> mPresShell;
};
#endif

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

@ -34,8 +34,8 @@
#include "nsIDOMHTMLLabelElement.h"
#include "nsIDOMHTMLFormElement.h"
nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsLeafDOMAccessible(aShell, aNode)
nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsLeafAccessible(aNode, aShell)
{
}
@ -69,20 +69,19 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::AppendLabelFor(nsIContent *aLookNode,
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(nsAWritableString& _retval)
{
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mNode));
nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLLabelElement> labelElement;
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
nsAutoString nameString;
nsresult rv = NS_OK;
nsAutoString label;
// go up tree get name of ancestor label if there is one. Don't go up farther than form element
while (walkUpContent && nameString.IsEmpty() && !formElement) {
while (walkUpContent && label.IsEmpty() && !formElement) {
labelElement = do_QueryInterface(walkUpContent);
if (labelElement)
rv = AppendFlatStringFromSubtree(walkUpContent, &nameString);
rv = AppendFlatStringFromSubtree(walkUpContent, &label);
formElement = do_QueryInterface(walkUpContent); // reached top ancestor in form
nsCOMPtr<nsIContent> nextParent;
walkUpContent->GetParent(*getter_AddRefs(nextParent));
@ -95,16 +94,16 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(PRUnichar **_retval)
walkUpContent = do_QueryInterface(formElement);
if (walkUpContent) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
nsAutoString forId;
elt->GetAttribute(NS_LITERAL_STRING("id"), forId);
// Actually we'll be walking down the content this time, with a depth first search
if (!forId.IsEmpty())
AppendLabelFor(walkUpContent,&forId,&nameString);
AppendLabelFor(walkUpContent,&forId,&label);
}
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
label.CompressWhitespace();
_retval.Assign(label);
return NS_OK;
}
@ -114,9 +113,10 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval)
{
// can be
// focusable, focused, checked, protected, unavailable
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
*_retval = STATE_FOCUSABLE;
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
PRBool checked = PR_FALSE;
element->GetChecked(&checked);
@ -137,8 +137,8 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval)
// --- checkbox -----
nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -157,20 +157,20 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
// check or uncheck
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
PRBool checked = PR_FALSE;
if (element)
element->GetChecked(&checked);
if (checked)
*_retval = ToNewUnicode(NS_LITERAL_STRING("uncheck"));
_retval = NS_LITERAL_STRING("uncheck");
else
*_retval = ToNewUnicode(NS_LITERAL_STRING("check"));
_retval = NS_LITERAL_STRING("check");
return NS_OK;
}
@ -180,8 +180,8 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, PRUnicha
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
if (index == 0) { // 0 is the magic value for default action
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
PRBool checked = PR_FALSE;
element->GetChecked(&checked);
element->SetChecked(checked ? PR_FALSE : PR_TRUE);
@ -193,8 +193,8 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index)
//------ Radio button -------
nsHTMLRadioButtonAccessible::nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLRadioButtonAccessible::nsHTMLRadioButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -206,10 +206,10 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("select"));
_retval = NS_LITERAL_STRING("select");
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
@ -219,7 +219,7 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccActionName(PRUint8 index, PRUni
NS_IMETHODIMP nsHTMLRadioButtonAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
element->Click();
return NS_OK;
}
@ -237,8 +237,8 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUint32 *_retval)
// ----- Button -----
nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -250,10 +250,10 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("press"));
_retval = NS_LITERAL_STRING("press");
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
@ -263,7 +263,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar
NS_IMETHODIMP nsHTMLButtonAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
element->Click();
return NS_OK;
}
@ -278,10 +278,9 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccRole(PRUint32 *_retval)
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(nsAWritableString& _retval)
{
*_retval = nsnull;
nsCOMPtr<nsIDOMHTMLInputElement> button(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> button(do_QueryInterface(mDOMNode));
if (!button)
return NS_ERROR_FAILURE;
@ -289,8 +288,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval)
nsAutoString name;
button->GetValue(name);
name.CompressWhitespace();
*_retval = name.ToNewUnicode();
_retval.Assign(name);
return NS_OK;
}
@ -298,8 +296,8 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval)
// ----- HTML 4 Button: can contain arbitrary HTML content -----
nsHTML4ButtonAccessible::nsHTML4ButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsDOMAccessible(aShell, aNode)
nsHTML4ButtonAccessible::nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLBlockAccessible(aNode, aShell)
{
}
@ -311,10 +309,10 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccNumActions(PRUint8 *_retval)
}
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar **_retval)
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
*_retval = ToNewUnicode(NS_LITERAL_STRING("press"));
_retval = NS_LITERAL_STRING("press");
return NS_OK;
}
return NS_ERROR_NOT_IMPLEMENTED;
@ -324,7 +322,7 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, PRUnichar
NS_IMETHODIMP nsHTML4ButtonAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
element->Click();
return NS_OK;
}
@ -341,25 +339,26 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccRole(PRUint32 *_retval)
/* long getAccState (); */
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccState(PRUint32 *_retval)
{
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
return NS_OK;
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(nsAWritableString& _retval)
{
*_retval = nsnull;
nsresult rv = NS_ERROR_FAILURE;
nsAutoString name;
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsAutoString name;
if (content)
rv = AppendFlatStringFromSubtree(content, &name);
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAWritableString
name.CompressWhitespace();
*_retval = name.ToNewUnicode();
_retval.Assign(name);
}
return rv;
@ -368,8 +367,8 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(PRUnichar **_retval)
// --- textfield -----
nsHTMLTextFieldAccessible::nsHTMLTextFieldAccessible(nsIPresShell* aShell, nsIDOMNode* aNode):
nsHTMLFormControlAccessible(aShell, aNode)
nsHTMLTextFieldAccessible::nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsHTMLFormControlAccessible(aNode, aShell)
{
}
@ -381,13 +380,11 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccRole(PRUint32 *_retval)
}
/* wstring getAccValue (); */
NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(nsAWritableString& _retval)
{
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mDOMNode));
if (textArea) {
nsAutoString valueString;
textArea->GetValue(valueString);
*_retval = ToNewUnicode(valueString);
textArea->GetValue(_retval);
return NS_OK;
}
@ -400,12 +397,13 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccState(PRUint32 *_retval)
// can be
// focusable, focused, protected. readonly, unavailable, selected
*_retval = STATE_FOCUSABLE;
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mNode));
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
PRBool isReadOnly = PR_FALSE;
elt->HasAttribute(NS_LITERAL_STRING("readonly"), &isReadOnly);
if (isReadOnly)
@ -413,9 +411,13 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccState(PRUint32 *_retval)
// Get current selection and find out if current node is in it
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsIFrame *frame;
if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) {
nsCOMPtr<nsISelectionController> selCon;

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

@ -24,7 +24,7 @@
#ifndef _nsHTMLFormControlAccessible_H_
#define _nsHTMLFormControlAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsICheckboxControlFrame;
@ -33,12 +33,12 @@ class nsICheckboxControlFrame;
* - walking up to get name from label
* - support basic state
*/
class nsHTMLFormControlAccessible : public nsLeafDOMAccessible
class nsHTMLFormControlAccessible : public nsLeafAccessible
{
public:
nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
protected:
@ -49,10 +49,10 @@ class nsHTMLCheckboxAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
@ -60,10 +60,10 @@ class nsHTMLRadioButtonAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLRadioButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
@ -71,24 +71,24 @@ class nsHTMLButtonAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccName(PRUnichar **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
class nsHTML4ButtonAccessible : public nsDOMAccessible
class nsHTML4ButtonAccessible : public nsHTMLBlockAccessible
{
public:
nsHTML4ButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccName(PRUnichar **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, PRUnichar **_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
@ -96,9 +96,9 @@ public:
class nsHTMLTextFieldAccessible : public nsHTMLFormControlAccessible
{
public:
nsHTMLTextFieldAccessible(nsIPresShell* aShell, nsIDOMNode* aNode);
nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(PRUnichar **_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
};

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

@ -30,19 +30,55 @@
#include "nsIDocShell.h"
#include "nsIWebShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIXULDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsReadableUtils.h"
NS_INTERFACE_MAP_BEGIN(nsHTMLIFrameRootAccessible)
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMFormListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFormListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMFormListener)
NS_INTERFACE_MAP_END_INHERITING(nsRootAccessible)
nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIPresShell* aShell, nsIDOMNode* aNode, nsIAccessible* aRoot):
nsDOMAccessible(aShell, aNode)
NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible);
NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible);
NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible);
NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible);
NS_IMETHODIMP
nsHTMLIFrameAccessible::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!");
if ( !aInstancePtr )
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(NS_GET_IID(nsIAccessibleDocument))) {
*aInstancePtr = (void*)(nsIAccessibleDocument*) this;
NS_IF_ADDREF(this);
return NS_OK;
}
return nsHTMLBlockAccessible::QueryInterface(aIID, aInstancePtr);
}
nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *aDoc):
nsHTMLBlockAccessible(aNode, aShell), mRootAccessible(aRoot), nsDocAccessibleMixin(aDoc)
{
mRootAccessible = aRoot;
}
/* attribute wstring accName; */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccName(PRUnichar * *aAccName)
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccName(nsAWritableString& aAccName)
{
return mRootAccessible->GetAccName(aAccName);
return GetTitle(aAccName);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccValue(nsAWritableString& aAccValue)
{
return GetURL(aAccValue);
}
/* nsIAccessible getAccFirstChild (); */
@ -66,13 +102,51 @@ NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccChildCount(PRInt32 *_retval)
/* unsigned long getAccRole (); */
NS_IMETHODIMP nsHTMLIFrameAccessible::GetAccRole(PRUint32 *_retval)
{
return mRootAccessible->GetAccRole(_retval);
*_retval = ROLE_PANE;
return NS_OK;
}
// ------- nsIAccessibleDocument Methods (5) ---------------
NS_IMETHODIMP nsHTMLIFrameAccessible::GetURL(nsAWritableString& aURL)
{
return nsDocAccessibleMixin::GetURL(aURL);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetTitle(nsAWritableString& aTitle)
{
return nsDocAccessibleMixin::GetTitle(aTitle);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetMimeType(nsAWritableString& aMimeType)
{
return nsDocAccessibleMixin::GetMimeType(aMimeType);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetDocType(nsAWritableString& aDocType)
{
return nsDocAccessibleMixin::GetDocType(aDocType);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetNameSpaceURIForID(PRInt16 aNameSpaceID, nsAWritableString& aNameSpaceURI)
{
return nsDocAccessibleMixin::GetNameSpaceURIForID(aNameSpaceID, aNameSpaceURI);
}
NS_IMETHODIMP nsHTMLIFrameAccessible::GetDocument(nsIDocument **doc)
{
return nsDocAccessibleMixin::GetDocument(doc);
}
//=============================//
// nsHTMLIFrameRootAccessible //
//=============================//
//-----------------------------------------------------
// construction
//-----------------------------------------------------
nsHTMLIFrameRootAccessible::nsHTMLIFrameRootAccessible(nsIWeakReference* aShell, nsIDOMNode* aNode):
nsHTMLIFrameRootAccessible::nsHTMLIFrameRootAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsRootAccessible(aShell)
{
mRealDOMNode = aNode;
@ -83,23 +157,6 @@ nsHTMLIFrameRootAccessible::nsHTMLIFrameRootAccessible(nsIWeakReference* aShell,
//-----------------------------------------------------
nsHTMLIFrameRootAccessible::~nsHTMLIFrameRootAccessible()
{
}
/* attribute wstring accName; */
NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetAccName(PRUnichar * *aAccName)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIDocument> document;
if (shell)
shell->GetDocument(getter_AddRefs(document));
if (document) {
const nsString* docTitle = document->GetDocumentTitle();
if (docTitle && !docTitle->IsEmpty()) {
*aAccName = docTitle->ToNewUnicode();
return NS_OK;
}
}
*aAccName = ToNewUnicode(NS_LITERAL_STRING("Frame"));
return NS_OK;
}
/* readonly attribute nsIAccessible accParent; */
@ -137,18 +194,16 @@ NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetAccPreviousSibling(nsIAccessible **
return NS_ERROR_NOT_IMPLEMENTED;
}
/* unsigned long getAccRole (); */
NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_PANE;
return NS_OK;
}
NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetHTMLIFrameAccessible(nsIAccessible** aAcc)
{
// Start by finding our PresShell and from that
// we get our nsIDocShell in order to walk the DocShell tree
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mPresShell));
if (!presShell) {
*aAcc = nsnull;
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
if (NS_SUCCEEDED(GetDocShellFromPS(presShell, getter_AddRefs(docShell)))) {
// Now that we have the DocShell QI
@ -183,7 +238,7 @@ NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetHTMLIFrameAccessible(nsIAccessible*
// OK, we found the content node in the parent doc
// that corresponds to this sub-doc
// Get the frame for that content
nsCOMPtr<nsIWeakReference> wr(getter_AddRefs(NS_GetWeakReference(parentPresShell)));
nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(parentPresShell);
nsIFrame* frame = nsnull;
parentPresShell->GetPrimaryFrameFor(content, &frame);
#ifdef NS_DEBUG_X
@ -200,7 +255,7 @@ NS_IMETHODIMP nsHTMLIFrameRootAccessible::GetHTMLIFrameAccessible(nsIAccessible*
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
nsCOMPtr<nsIAccessible> acc(do_QueryInterface(frame));
*aAcc = CreateNewAccessible(acc, node, wr);
*aAcc = acc;
NS_IF_ADDREF(*aAcc);
return NS_OK;

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

@ -24,19 +24,27 @@
#define _nsIFrameRootAccessible_H_
#include "nsRootAccessible.h"
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
#include "nsIAccessibleDocument.h"
class nsIWebShell;
class nsIWeakReference;
class nsHTMLIFrameAccessible : public nsDOMAccessible
class nsHTMLIFrameAccessible : public nsHTMLBlockAccessible,
public nsIAccessibleDocument,
public nsDocAccessibleMixin
{
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEDOCUMENT
public:
nsHTMLIFrameAccessible(nsIPresShell* aShell, nsIDOMNode* aNode, nsIAccessible* aRoot);
nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *doc);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
NS_IMETHOD GetAccName(nsAWritableString& aAccName);
NS_IMETHOD GetAccValue(nsAWritableString& AccValue);
NS_IMETHOD GetAccRole(PRUint32 *aAccRole);
protected:
@ -45,9 +53,10 @@ class nsHTMLIFrameAccessible : public nsDOMAccessible
class nsHTMLIFrameRootAccessible : public nsRootAccessible
{
NS_DECL_ISUPPORTS_INHERITED
public:
nsHTMLIFrameRootAccessible(nsIWeakReference* aShell, nsIDOMNode* aNode);
nsHTMLIFrameRootAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
virtual ~nsHTMLIFrameRootAccessible();
/* attribute wstring accName; */
@ -59,15 +68,9 @@ class nsHTMLIFrameRootAccessible : public nsRootAccessible
/* nsIAccessible getAccPreviousSibling (); */
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
NS_IMETHOD GetAccRole(PRUint32 *aAccRole);
protected:
NS_IMETHOD GetHTMLIFrameAccessible(nsIAccessible** aAcc);
nsCOMPtr<nsIDOMNode> mRealDOMNode;
NS_IMETHOD GetHTMLIFrameAccessible(nsIAccessible** aAcc);
nsCOMPtr<nsIDOMNode> mRealDOMNode;
};

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

@ -33,12 +33,15 @@
// --- image -----
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIPresShell* aShell, nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame):
nsLinkableAccessible(aShell, aDOMNode), mPresShell(aShell)
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIImageFrame *aImageFrame, nsIWeakReference* aShell):
nsLinkableAccessible(aDOMNode, aShell)
{
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));
nsCOMPtr<nsIDocument> doc;
aShell->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
NS_ASSERTION(shell,"Shell is gone!!! What are we doing here?");
shell->GetDocument(getter_AddRefs(doc));
nsAutoString mapElementName;
if (doc && element) {
@ -53,19 +56,21 @@ nsLinkableAccessible(aShell, aDOMNode), mPresShell(aShell)
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLImageAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLImageAccessible::GetAccName(nsAWritableString& _retval)
{
nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mNode));
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mDOMNode));
if (imageContent) {
nsAutoString nameString;
nsresult rv = AppendFlatStringFromContentNode(imageContent, &nameString);
nsAutoString name;
rv = AppendFlatStringFromContentNode(imageContent, &name);
if (NS_SUCCEEDED(rv)) {
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
// Temp var needed until CompressWhitespace built for nsAWritableString
name.CompressWhitespace();
_retval.Assign(name);
}
return rv;
}
return NS_ERROR_NOT_IMPLEMENTED;
return rv;
}
/* wstring getAccRole (); */
@ -99,12 +104,12 @@ nsIAccessible *nsHTMLImageAccessible::CreateAreaAccessible(PRUint32 areaNum)
if (!domNode)
return nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv);
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (!accService)
return nsnull;
if (accService) {
nsIAccessible* acc = nsnull;
nsCOMPtr<nsISupports> presShell(do_QueryInterface(mPresShell));
accService->CreateHTMLAreaAccessible(presShell, domNode, this, &acc);
accService->CreateHTMLAreaAccessible(mPresShell, domNode, this, &acc);
return acc;
}
return nsnull;

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

@ -24,7 +24,7 @@
#ifndef _nsHTMLImageAccessible_H_
#define _nsHTMLImageAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
#include "nsIFrame.h"
#include "nsIImageFrame.h"
#include "nsIDOMHTMLMapElement.h"
@ -38,8 +38,8 @@ class nsHTMLImageAccessible : public nsLinkableAccessible
{
public:
nsHTMLImageAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode, nsIImageFrame *imageFrame);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIImageFrame *imageFrame, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
@ -48,7 +48,6 @@ public:
protected:
nsIAccessible *CreateAreaAccessible(PRUint32 areaNum);
nsCOMPtr<nsIDOMHTMLMapElement> mMapElement;
nsCOMPtr<nsIPresShell> mPresShell;
};
#endif

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

@ -32,21 +32,24 @@
#include "nsReadableUtils.h"
#include "nsIDOMElement.h"
nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsLinkableAccessible(aShell, aDomNode)
nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsLinkableAccessible(aDomNode, aShell)
{
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccName(nsAWritableString& _retval)
{
if (!IsALink()) // Also initializes private data members
return NS_ERROR_FAILURE;
nsAutoString nameString;
nsresult rv = AppendFlatStringFromSubtree(mLinkContent, &nameString);
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
nsAutoString name;
nsresult rv = AppendFlatStringFromSubtree(mLinkContent, &name);
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAWritableString
name.CompressWhitespace();
_retval.Assign(name);
}
return rv;
}
@ -58,14 +61,10 @@ NS_IMETHODIMP nsHTMLLinkAccessible::GetAccRole(PRUint32 *_retval)
return NS_OK;
}
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccValue(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLLinkAccessible::GetAccValue(nsAWritableString& _retval)
{
*_retval = 0;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mNode));
if (elt) {
nsAutoString hrefString;
elt->GetAttribute(NS_LITERAL_STRING("href"), hrefString);
*_retval = hrefString.ToNewUnicode();
}
return NS_OK;
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
if (elt)
return elt->GetAttribute(NS_LITERAL_STRING("href"), _retval);
return NS_ERROR_FAILURE;;
}

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

@ -24,18 +24,16 @@
#ifndef _nsHTMLLinkAccessible_H_
#define _nsHTMLLinkAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsHTMLLinkAccessible : public nsLinkableAccessible
{
public:
nsHTMLLinkAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(PRUnichar **_retval);
private:
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
};
#endif

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

@ -0,0 +1,792 @@
/* -*- Mode: C++; tab-width: 4; 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.
*
* Original Author: Eric Vaughan (evaughan@netscape.com)
*
* Contributor(s):
*/
#include "nsHTMLSelectAccessible.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsRootAccessible.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsLayoutAtoms.h"
#include "nsIDOMMenuListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsReadableUtils.h"
#include "nsIDOMHTMLCollection.h"
#include "nsISelectElement.h"
#include "nsIDOMHTMLSelectElement.h"
#include "nsIAccessibilityService.h"
#include "nsIServiceManager.h"
#include "nsIDOMHTMLOptionElement.h"
/*
* A class the represents the text field in the Select to the left
* of the drop down button
*/
class nsHTMLSelectTextFieldAccessible : public nsLeafAccessible
{
public:
nsHTMLSelectTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame);
nsCOMPtr<nsIAccessible> mParent;
};
/*
* A base class that can listen to menu events. Its used so the
* button and the window accessibles can change there name and role
* depending on whether the drop down list is dropped down on not
*/
class nsMenuListenerAccessible : public nsAccessible,
public nsIDOMMenuListener
{
public:
NS_DECL_ISUPPORTS_INHERITED
nsMenuListenerAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsMenuListenerAccessible();
// popup listener
NS_IMETHOD Create(nsIDOMEvent* aEvent);
NS_IMETHOD Close(nsIDOMEvent* aEvent);
NS_IMETHOD Destroy(nsIDOMEvent* aEvent);
NS_IMETHOD Action(nsIDOMEvent* aEvent) { return NS_OK; }
NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; }
NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; }
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
virtual void SetupMenuListener();
PRBool mRegistered;
PRBool mOpen;
};
NS_IMPL_ISUPPORTS_INHERITED(nsMenuListenerAccessible, nsAccessible, nsIDOMMenuListener)
/**
* A class that represents the button inside the Select to the right of the text field
*/
class nsHTMLSelectButtonAccessible : public nsMenuListenerAccessible
{
public:
nsHTMLSelectButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval);
NS_IMETHOD AccDoAction(PRUint8 index);
virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame);
nsCOMPtr<nsIAccessible> mParent;
};
/*
* A class that represents the window that lives to the right
* of the drop down button inside the Select. This is the window
* that is made visible when the button is pressed.
*/
class nsHTMLSelectWindowAccessible : public nsMenuListenerAccessible
{
public:
nsHTMLSelectWindowAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
virtual void GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame);
nsCOMPtr<nsIAccessible> mParent;
};
/*
* The list that contains all the options in the select. It is inside the window.
*/
class nsHTMLSelectListAccessible : public nsAccessible
{
public:
nsHTMLSelectListAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsHTMLSelectListAccessible() {}
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
nsCOMPtr<nsIAccessible> mParent;
};
//--------- nsHTMLSelectAccessible -----
nsHTMLSelectAccessible::nsHTMLSelectAccessible(nsIDOMNode* aDOMNode,
nsIWeakReference* aShell)
:nsAccessible(aDOMNode, aShell)
{
}
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLSelectAccessible, nsAccessible, nsIAccessibleSelectable)
// ------------- Helper method for determination of proper Frame ------
//static
PRBool nsHTMLSelectAccessible::IsCorrectFrame( nsIFrame* aFrame, nsIAtom* aAtom ) {
if (!aFrame || !aAtom)
return PR_FALSE;
nsCOMPtr<nsIAtom> frameType;
aFrame->GetFrameType(getter_AddRefs(frameType));
if (frameType.get() != aAtom)
return PR_FALSE;
return PR_TRUE;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccValue(nsAWritableString& _retval)
{
nsCOMPtr<nsIAccessible> text;
GetAccFirstChild(getter_AddRefs(text));
if (text)
return text->GetAccValue(_retval);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_COMBOBOX;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccLastChild(nsIAccessible **_retval)
{
// create a window accessible
*_retval = new nsHTMLSelectWindowAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
// create a text field
*_retval = new nsHTMLSelectTextFieldAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetAccChildCount(PRInt32 *_retval)
{
// always have 3 children
*_retval = 3;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectAccessible::GetSelectedChildren(nsISupportsArray **_retval)
{
*_retval = nsnull;
return NS_OK;
}
//-------- SelectTextFieldAccessible ------
nsHTMLSelectTextFieldAccessible::nsHTMLSelectTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsLeafAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccValue(nsAWritableString& _retval)
{
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
if ( !frame )
return NS_ERROR_FAILURE;
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return NS_ERROR_FAILURE;
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::textFrame) )
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
if (!content)
return NS_ERROR_FAILURE;
AppendFlatStringFromSubtree(content, &_retval);
return NS_OK;
}
void nsHTMLSelectTextFieldAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
{
// get our first child's frame
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
if ( !frame )
return;
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return;
frame->GetParent(aRelativeFrame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( *aRelativeFrame, nsLayoutAtoms::areaFrame) )
return;
frame->GetRect(aBounds);
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectButtonAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectTextFieldAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_STATICTEXT;
return NS_OK;
}
// --------- nsMenuListenerAccessible -----------
nsMenuListenerAccessible::nsMenuListenerAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsAccessible(aDOMNode, aShell)
{
mRegistered = PR_FALSE;
mOpen = PR_FALSE;
}
nsMenuListenerAccessible::~nsMenuListenerAccessible()
{
if (mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (eventReceiver)
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
}
}
NS_IMETHODIMP nsMenuListenerAccessible::Create(nsIDOMEvent* aEvent)
{
mOpen = PR_TRUE;
/* TBD send state change event */
return NS_OK;
}
NS_IMETHODIMP nsMenuListenerAccessible::Destroy(nsIDOMEvent* aEvent)
{
mOpen = PR_FALSE;
/* TBD send state change event */
return NS_OK;
}
NS_IMETHODIMP nsMenuListenerAccessible::Close(nsIDOMEvent* aEvent)
{
mOpen = PR_FALSE;
/* TBD send state change event */
return NS_OK;
}
void
nsMenuListenerAccessible::SetupMenuListener()
{
// not not already one register ourselves as a popup listener
if (!mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (!eventReceiver) {
return;
}
nsresult rv = eventReceiver->AddEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
if (NS_FAILED(rv)) {
return;
}
mRegistered = PR_TRUE;
}
}
//-------- SelectButtonAccessible ------
nsHTMLSelectButtonAccessible::nsHTMLSelectButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsMenuListenerAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
/* void accDoAction (in PRUint8 index); */
NS_IMETHODIMP nsHTMLSelectButtonAccessible::AccDoAction(PRUint8 index)
{
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return NS_ERROR_FAILURE;
frame->GetNextSibling(&frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::gfxButtonControlFrame) )
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
if (index == 0) {
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(content));
if (element)
{
element->Click();
return NS_OK;
}
return NS_ERROR_FAILURE;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = 1;
return NS_OK;
}
void nsHTMLSelectButtonAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
{
// get our second child's frame
nsIFrame* frame = nsAccessible::GetBoundsFrame();
nsCOMPtr<nsIPresContext> context;
GetPresContext(context);
frame->FirstChild(context, nsnull, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return;
frame->GetNextSibling(&frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::gfxButtonControlFrame) )
return;
frame->GetParent(aRelativeFrame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( *aRelativeFrame, nsLayoutAtoms::areaFrame) )
return;
frame->GetRect(aBounds);
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_PUSHBUTTON;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccName(nsAWritableString& _retval)
{
return GetAccActionName(0, _retval);
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
SetupMenuListener();
// get the current state open or closed
// set _retval to it.
// notice its supposed to be reversed. Close if opened
// and Open if closed.
if (mOpen)
_retval = NS_LITERAL_STRING("Close");
else
_retval = NS_LITERAL_STRING("Open");
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectWindowAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectTextFieldAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectButtonAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 0;
return NS_OK;
}
//---------------------
nsHTMLSelectWindowAccessible::nsHTMLSelectWindowAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell)
:nsMenuListenerAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccState(PRUint32 *_retval)
{
nsAccessible::GetAccState(_retval);
SetupMenuListener();
// if open we are visible if closed we are invisible
// set _retval to it.
if (mOpen)
*_retval |= STATE_DEFAULT;
else
*_retval |= STATE_INVISIBLE;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_WINDOW;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
nsCOMPtr<nsIAccessible> parent;
GetAccParent(getter_AddRefs(parent));
*_retval = new nsHTMLSelectButtonAccessible(parent, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccLastChild(nsIAccessible **_retval)
{
*_retval = new nsHTMLSelectListAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
*_retval = new nsHTMLSelectListAccessible(this, mDOMNode, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectWindowAccessible::GetAccChildCount(PRInt32 *_retval)
{
*_retval = 1;
return NS_OK;
}
void nsHTMLSelectWindowAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
{
// get our first option
nsCOMPtr<nsIDOMNode> child;
mDOMNode->GetFirstChild(getter_AddRefs(child));
// now get its frame
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
*aRelativeFrame = nsnull;
return;
}
nsIFrame* frame = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(child));
shell->GetPrimaryFrameFor(content, &frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::blockFrame) )
return;
frame->GetParent(&frame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( frame, nsLayoutAtoms::areaFrame) )
return;
frame->GetParent(aRelativeFrame);
if ( ! nsHTMLSelectAccessible::IsCorrectFrame( *aRelativeFrame, nsLayoutAtoms::listControlFrame) )
return;
frame->GetRect(aBounds);
}
//----------
nsHTMLSelectListAccessible::nsHTMLSelectListAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell)
:nsAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
{
return mParent->AccGetBounds(x,y,width,height);
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_LIST;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccLastChild(nsIAccessible **_retval)
{
nsCOMPtr<nsIDOMNode> last;
mDOMNode->GetLastChild(getter_AddRefs(last));
*_retval = new nsHTMLSelectOptionAccessible(this, last, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectListAccessible::GetAccFirstChild(nsIAccessible **_retval)
{
nsCOMPtr<nsIDOMNode> first;
mDOMNode->GetFirstChild(getter_AddRefs(first));
*_retval = new nsHTMLSelectOptionAccessible(this, first, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
return NS_OK;
}
//--------
nsHTMLSelectOptionAccessible::nsHTMLSelectOptionAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
nsLeafAccessible(aDOMNode, aShell)
{
mParent = aParent;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccRole(PRUint32 *_retval)
{
*_retval = ROLE_LISTITEM;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccParent(nsIAccessible **_retval)
{
*_retval = mParent;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccNextSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
nsCOMPtr<nsIDOMNode> next;
mDOMNode->GetNextSibling(getter_AddRefs(next));
if (next) {
*_retval = new nsHTMLSelectOptionAccessible(mParent, next, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
}
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccPreviousSibling(nsIAccessible **_retval)
{
*_retval = nsnull;
nsCOMPtr<nsIDOMNode> prev;
mDOMNode->GetPreviousSibling(getter_AddRefs(prev));
if (prev) {
*_retval = new nsHTMLSelectOptionAccessible(mParent, prev, mPresShell);
if ( ! *_retval )
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval);
}
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccName(nsAWritableString& _retval)
{
nsCOMPtr<nsIContent> content (do_QueryInterface(mDOMNode));
if (!content) {
return NS_ERROR_FAILURE;
}
nsAutoString option;
nsresult rv = AppendFlatStringFromSubtree(content, &option);
if (NS_SUCCEEDED(rv)) {
// Temp var needed until CompressWhitespace built for nsAWritableString
option.CompressWhitespace();
_retval.Assign(option);
}
return rv;
}

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

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; 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.
*
* Original Author: Eric Vaughan (evaughan@netscape.com)
*
* Contributor(s):
*/
#ifndef __nsHTMLSelectAccessible_h__
#define __nsHTMLSelectAccessible_h__
#include "nsAccessible.h"
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIAccessibleSelectable.h"
class nsHTMLSelectAccessible : public nsAccessible,
public nsIAccessibleSelectable
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLESELECTABLE
nsHTMLSelectAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsHTMLSelectAccessible() {}
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccValue(nsAWritableString& _retval);
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
// helper method to verify frames
static PRBool IsCorrectFrame( nsIFrame* aFrame, nsIAtom* aAtom );
};
/*
* Each option in the Select. These are in the nsListAccessible
*/
class nsHTMLSelectOptionAccessible : public nsLeafAccessible
{
public:
nsHTMLSelectOptionAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
nsCOMPtr<nsIAccessible> mParent;
};
#endif

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

@ -25,8 +25,8 @@
#include "nsWeakReference.h"
#include "nsReadableUtils.h"
nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsDOMAccessible(aShell, aDomNode)
nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsHTMLBlockAccessible(aDomNode, aShell)
{
}
@ -37,8 +37,8 @@ NS_IMETHODIMP nsHTMLTableCellAccessible::GetAccRole(PRUint32 *_retval)
return NS_OK;
}
nsHTMLTableAccessible::nsHTMLTableAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsDOMAccessible(aShell, aDomNode)
nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsHTMLBlockAccessible(aDomNode, aShell)
{
}

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

@ -24,20 +24,20 @@
#ifndef _nsHTMLTableAccessible_H_
#define _nsHTMLTableAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsHTMLTableCellAccessible : public nsDOMAccessible
class nsHTMLTableCellAccessible : public nsHTMLBlockAccessible
{
public:
nsHTMLTableCellAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
};
class nsHTMLTableAccessible : public nsDOMAccessible
class nsHTMLTableAccessible : public nsHTMLBlockAccessible
{
public:
nsHTMLTableAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
};

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

@ -31,25 +31,16 @@
#include "nsIPresContext.h"
#include "nsReadableUtils.h"
nsHTMLTextAccessible::nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode):
nsLinkableAccessible(aShell, aDomNode)
nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
nsLinkableAccessible(aDomNode, aShell)
{
}
/* wstring getAccName (); */
NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(PRUnichar **_retval)
NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(nsAWritableString& _retval)
{
nsAutoString nameString;
nsresult rv = NS_OK;
//if (IsALink()) {
// rv = AppendFlatStringFromSubtree(mLinkContent, &nameString);
//}
//else
mNode->GetNodeValue(nameString);
nameString.CompressWhitespace();
*_retval = nameString.ToNewUnicode();
return rv;
return mDOMNode->GetNodeValue(_retval);
}
/* unsigned long getAccRole (); */

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

@ -23,7 +23,7 @@
#ifndef _nsHTMLTextAccessible_H_
#define _nsHTMLTextAccessible_H_
#include "nsGenericAccessible.h"
#include "nsAccessible.h"
class nsIWeakReference;
class nsITextControlFrame;
@ -32,8 +32,8 @@ class nsHTMLTextAccessible : public nsLinkableAccessible
{
public:
nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode);
NS_IMETHOD GetAccName(PRUnichar **_retval);
nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetAccName(nsAWritableString& _retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);

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

@ -36,8 +36,19 @@
#include "nsHTMLLinkAccessible.h"
#include "nsIURI.h"
#include "nsIDocShellTreeItem.h"
#include "nsIXULDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMNSHTMLSelectElement.h"
#include "nsIAccessibleSelectable.h"
#include "nsIDOMHTMLCollection.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsXPIDLString.h"
NS_INTERFACE_MAP_BEGIN(nsRootAccessible)
NS_INTERFACE_MAP_ENTRY(nsIAccessibleDocument)
NS_INTERFACE_MAP_ENTRY(nsIAccessibleEventReceiver)
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMFormListener)
@ -45,18 +56,23 @@ NS_INTERFACE_MAP_BEGIN(nsRootAccessible)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMFormListener)
NS_INTERFACE_MAP_END_INHERITING(nsAccessible)
NS_IMPL_ADDREF_INHERITED(nsRootAccessible, nsAccessible);
NS_IMPL_RELEASE_INHERITED(nsRootAccessible, nsAccessible);
//-----------------------------------------------------
// construction
//-----------------------------------------------------
nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell):nsAccessible(nsnull,nsnull,aShell)
nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell):nsAccessible(nsnull,aShell), nsDocAccessibleMixin(aShell)
{
mListener = nsnull;
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
NS_ASSERTION(shell,"Shell is gone!!! What are we doing here?");
shell->GetDocument(getter_AddRefs(mDocument));
mDOMNode = do_QueryInterface(mDocument);
nsLayoutAtoms::AddRefAtoms();
}
//-----------------------------------------------------
@ -64,24 +80,23 @@ nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell):nsAccessible(nsnull
//-----------------------------------------------------
nsRootAccessible::~nsRootAccessible()
{
nsLayoutAtoms::ReleaseAtoms();
RemoveAccessibleEventListener(mListener);
}
/* attribute wstring accName; */
NS_IMETHODIMP nsRootAccessible::GetAccName(PRUnichar * *aAccName)
NS_IMETHODIMP nsRootAccessible::GetAccName(nsAWritableString& aAccName)
{
const nsString* docTitle = mDocument->GetDocumentTitle();
if (docTitle && !docTitle->IsEmpty())
*aAccName = docTitle->ToNewUnicode();
else *aAccName = ToNewUnicode(NS_LITERAL_STRING("Document"));
return NS_OK;
return GetTitle(aAccName);
}
// helpers
nsIFrame* nsRootAccessible::GetFrame()
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return nsnull;
nsIFrame* root = nsnull;
if (shell)
shell->GetRootFrame(&root);
@ -95,11 +110,6 @@ void nsRootAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame)
(*aRelativeFrame)->GetRect(aBounds);
}
nsIAccessible* nsRootAccessible::CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell)
{
return new nsHTMLBlockAccessible(aAccessible, aNode, aShell);
}
/* readonly attribute nsIAccessible accParent; */
NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent)
{
@ -111,6 +121,11 @@ NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent)
NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUint32 *aAccRole)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell) {
*aAccRole = 0;
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresContext> context;
shell->GetPresContext(getter_AddRefs(context));
nsCOMPtr<nsISupports> container;
@ -131,14 +146,9 @@ NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUint32 *aAccRole)
return NS_OK;
}
NS_IMETHODIMP nsRootAccessible::GetAccValue(PRUnichar * *aAccValue)
NS_IMETHODIMP nsRootAccessible::GetAccValue(nsAWritableString& aAccValue)
{
nsCOMPtr<nsIURI> pURI;
mDocument->GetDocumentURL(getter_AddRefs(pURI));
char *path;
pURI->GetSpec(&path);
*aAccValue = ToNewUnicode(nsDependentCString(path));
return NS_OK;
return GetURL(aAccValue);
}
/* void addAccessibleEventListener (in nsIAccessibleEventListener aListener); */
@ -148,6 +158,9 @@ NS_IMETHODIMP nsRootAccessible::AddAccessibleEventListener(nsIAccessibleEventLis
{
// add an event listener to the document
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mPresShell));
if (!shell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> document;
shell->GetDocument(getter_AddRefs(document));
@ -248,34 +261,33 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
#endif
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
if (node)
a = new nsHTMLLinkAccessible(shell, node);
a = new nsHTMLLinkAccessible(node, mPresShell);
}
}
if (a) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
nsCOMPtr<nsIAccessible> na(CreateNewAccessible(a, node, mPresShell));
if ( !na )
return NS_OK;
if ( eventType.EqualsIgnoreCase("focus") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, na);
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, a);
}
else if ( eventType.EqualsIgnoreCase("change") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, na);
nsCOMPtr<nsIDOMNSHTMLSelectElement> select(do_QueryInterface(content));
if ( select ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_SELECTION, a);
}
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, a);
}
else if ( eventType.EqualsIgnoreCase("CheckboxStateChange") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, na);
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, a);
}
else if ( eventType.EqualsIgnoreCase("RadiobuttonStateChange") ) {
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, na);
mListener->HandleEvent(nsIAccessibleEventListener::EVENT_STATE_CHANGE, a);
}
}
}
return NS_OK;
}
// ------- nsIDOMFocusListener Methods (2) -------------
// ------- nsIDOMFocusListener Methods (1) -------------
NS_IMETHODIMP nsRootAccessible::Focus(nsIDOMEvent* aEvent)
{
@ -306,5 +318,115 @@ NS_IMETHODIMP nsRootAccessible::Select(nsIDOMEvent* aEvent) { return NS_OK; }
// gets Input events when text is entered or deleted in a textarea or input
NS_IMETHODIMP nsRootAccessible::Input(nsIDOMEvent* aEvent) { return NS_OK; }
// ------- nsIAccessibleDocument Methods (5) ---------------
NS_IMETHODIMP nsRootAccessible::GetURL(nsAWritableString& aURL)
{
return nsDocAccessibleMixin::GetURL(aURL);
}
NS_IMETHODIMP nsRootAccessible::GetTitle(nsAWritableString& aTitle)
{
return nsDocAccessibleMixin::GetTitle(aTitle);
}
NS_IMETHODIMP nsRootAccessible::GetMimeType(nsAWritableString& aMimeType)
{
return nsDocAccessibleMixin::GetMimeType(aMimeType);
}
NS_IMETHODIMP nsRootAccessible::GetDocType(nsAWritableString& aDocType)
{
return nsDocAccessibleMixin::GetDocType(aDocType);
}
NS_IMETHODIMP nsRootAccessible::GetNameSpaceURIForID(PRInt16 aNameSpaceID, nsAWritableString& aNameSpaceURI)
{
return nsDocAccessibleMixin::GetNameSpaceURIForID(aNameSpaceID, aNameSpaceURI);
}
NS_IMETHODIMP nsRootAccessible::GetDocument(nsIDocument **doc)
{
return nsDocAccessibleMixin::GetDocument(doc);
}
nsDocAccessibleMixin::nsDocAccessibleMixin(nsIDocument *aDoc):mDocument(aDoc)
{
}
nsDocAccessibleMixin::nsDocAccessibleMixin(nsIWeakReference *aPresShell)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aPresShell));
NS_ASSERTION(shell,"Shell is gone!!! What are we doing here?");
shell->GetDocument(getter_AddRefs(mDocument));
}
nsDocAccessibleMixin::~nsDocAccessibleMixin()
{
}
NS_IMETHODIMP nsDocAccessibleMixin::GetURL(nsAWritableString& aURL)
{
nsCOMPtr<nsIURI> pURI;
mDocument->GetDocumentURL(getter_AddRefs(pURI));
nsXPIDLCString path;
pURI->GetSpec(getter_Copies(path));
aURL.Assign(NS_ConvertUTF8toUCS2(path).get());
//XXXaaronl Need to use CopyUTF8toUCS2(nsDependentCString(path), aURL); when it's written
return NS_OK;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAWritableString& aTitle)
{
// This doesn't leak - we don't own the const pointer that's returned
aTitle = *(mDocument->GetDocumentTitle());
return NS_OK;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
{
if (mDocument)
return mDocument->GetContentType(aMimeType);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetDocType(nsAWritableString& aDocType)
{
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mDocument));
nsCOMPtr<nsIDOMDocumentType> docType;
if (xulDoc) {
aDocType = NS_LITERAL_STRING("window"); // doctype not implemented for XUL at time of writing - causes assertion
return NS_OK;
}
else if (domDoc && NS_SUCCEEDED(domDoc->GetDoctype(getter_AddRefs(docType))) && docType) {
return docType->GetName(aDocType);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetNameSpaceURIForID(PRInt16 aNameSpaceID, nsAWritableString& aNameSpaceURI)
{
if (mDocument) {
nsCOMPtr<nsINameSpaceManager> nameSpaceManager;
if (NS_SUCCEEDED(mDocument->GetNameSpaceManager(*getter_AddRefs(nameSpaceManager))))
return nameSpaceManager->GetNameSpaceURI(aNameSpaceID, aNameSpaceURI);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDocAccessibleMixin::GetDocument(nsIDocument **doc)
{
*doc = mDocument;
if (mDocument) {
NS_IF_ADDREF(*doc);
return NS_OK;
}
return NS_ERROR_FAILURE;
}

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

@ -26,17 +26,32 @@
#include "nsAccessible.h"
#include "nsIAccessibleEventReceiver.h"
#include "nsIAccessibleEventListener.h"
#include "nsIAccessibleDocument.h"
#include "nsIDOMFormListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDocument.h"
class nsDocAccessibleMixin
{
public:
nsDocAccessibleMixin(nsIDocument *doc);
nsDocAccessibleMixin(nsIWeakReference *aShell);
virtual ~nsDocAccessibleMixin();
NS_DECL_NSIACCESSIBLEDOCUMENT
protected:
nsCOMPtr<nsIDocument> mDocument;
};
class nsRootAccessible : public nsAccessible,
public nsDocAccessibleMixin,
public nsIAccessibleDocument,
public nsIAccessibleEventReceiver,
public nsIDOMFocusListener,
public nsIDOMFormListener
{
NS_DECL_ISUPPORTS_INHERITED
public:
@ -44,8 +59,8 @@ class nsRootAccessible : public nsAccessible,
virtual ~nsRootAccessible();
/* attribute wstring accName; */
NS_IMETHOD GetAccName(PRUnichar * *aAccName);
NS_IMETHOD GetAccValue(PRUnichar * *aAccValue);
NS_IMETHOD GetAccName(nsAWritableString& aAccName);
NS_IMETHOD GetAccValue(nsAWritableString& aAccValue);
NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent);
NS_IMETHOD GetAccRole(PRUint32 *aAccRole);
@ -68,17 +83,17 @@ class nsRootAccessible : public nsAccessible,
NS_IMETHOD Select(nsIDOMEvent* aEvent);
NS_IMETHOD Input(nsIDOMEvent* aEvent);
protected:
virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual nsIFrame* GetFrame();
virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIDOMNode* aNode, nsIWeakReference* aShell);
NS_DECL_NSIACCESSIBLEDOCUMENT
// not a com pointer. We don't own the listener
// it is the callers responsibility to remove the listener
// otherwise we will get into circular referencing problems
nsIAccessibleEventListener* mListener;
nsCOMPtr<nsIContent> mCurrentFocus;
nsCOMPtr<nsIDocument> mDocument;
protected:
virtual void GetBounds(nsRect& aRect, nsIFrame** aRelativeFrame);
virtual nsIFrame* GetFrame();
// not a com pointer. We don't own the listener
// it is the callers responsibility to remove the listener
// otherwise we will get into circular referencing problems
nsIAccessibleEventListener* mListener;
nsCOMPtr<nsIContent> mCurrentFocus;
};

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

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

@ -1584,6 +1584,9 @@ sub BuildLayoutProjects()
BuildOneProject(":mozilla:content:macbuild:contentshared.mcp", "contentshared$D.o", 0, 0, 0);
MakeAlias(":mozilla:content:macbuild:contentshared$D.o", ":mozilla:dist:content:");
# Get accessiblity which depends on gfx
BuildAccessiblityProjects();
BuildOneProject(":mozilla:content:macbuild:content.mcp", "content$D.shlb", 1, $main::ALIAS_SYM_FILES, 1);
if ($main::options{mathml})
{
@ -2059,8 +2062,8 @@ sub BuildProjects()
BuildSecurityProjects();
BuildBrowserUtilsProjects();
BuildInternationalProjects();
#BuildAccessiblityProjects();
BuildLayoutProjects();
BuildAccessiblityProjects();
BuildEditorProjects();
BuildEmbeddingProjects();
BuildViewerProjects();

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

@ -86,6 +86,7 @@ LAYOUT_ATOM(areaFrame, "AreaFrame")
LAYOUT_ATOM(blockFrame, "BlockFrame")
LAYOUT_ATOM(brFrame, "BRFrame")
LAYOUT_ATOM(bulletFrame, "BulletFrame")
LAYOUT_ATOM(gfxButtonControlFrame, "gfxButtonControlFrame")
LAYOUT_ATOM(hrFrame, "HRFrame")
LAYOUT_ATOM(htmlFrameInnerFrame, "htmlFrameInnerFrame")
LAYOUT_ATOM(htmlFrameOuterFrame, "htmlFrameOuterFrame")

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

@ -139,16 +139,17 @@ static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID);
nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY
#define NODE_SCRIPTABLE_FLAGS \
(DOM_DEFAULT_SCRIPTABLE_FLAGS | \
((DOM_DEFAULT_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_PRECREATE | \
nsIXPCScriptable::WANT_NEWRESOLVE | \
nsIXPCScriptable::WANT_ADDPROPERTY | \
nsIXPCScriptable::WANT_SETPROPERTY) & \
~nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
~nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY )
#define ELEMENT_SCRIPTABLE_FLAGS \
NODE_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_POSTCREATE
((NODE_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_POSTCREATE ) & \
~nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY ) /* to fix accessibility */
#define ARRAY_SCRIPTABLE_FLAGS \
DOM_DEFAULT_SCRIPTABLE_FLAGS | \

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

@ -1767,6 +1767,12 @@ NS_IMETHODIMP GlobalWindowImpl::Focus()
result = widget->SetFocus(PR_TRUE);
}
}
else {
nsCOMPtr<nsIFocusController> focusController;
GetRootFocusController(getter_AddRefs(focusController));
if (focusController)
focusController->SetFocusedWindow(this);
}
return result;
}

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

@ -86,6 +86,7 @@ LAYOUT_ATOM(areaFrame, "AreaFrame")
LAYOUT_ATOM(blockFrame, "BlockFrame")
LAYOUT_ATOM(brFrame, "BRFrame")
LAYOUT_ATOM(bulletFrame, "BulletFrame")
LAYOUT_ATOM(gfxButtonControlFrame, "gfxButtonControlFrame")
LAYOUT_ATOM(hrFrame, "HRFrame")
LAYOUT_ATOM(htmlFrameInnerFrame, "htmlFrameInnerFrame")
LAYOUT_ATOM(htmlFrameOuterFrame, "htmlFrameOuterFrame")

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

@ -22,6 +22,7 @@
*/
#include "nsCOMPtr.h"
#include "nsComboboxControlFrame.h"
#include "nsIDOMEventReceiver.h"
#include "nsIFrameManager.h"
#include "nsFormFrame.h"
#include "nsFormControlFrame.h"
@ -52,7 +53,6 @@
#include "nsISelectControlFrame.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
#include "nsIDOMMouseListener.h"
#include "nsITextContent.h"
#include "nsTextFragment.h"
#include "nsCSSFrameConstructor.h"
@ -67,7 +67,6 @@
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
@ -98,6 +97,44 @@ const char * kMozDropdownActive = "-moz-dropdown-active";
const PRInt32 kSizeNotSet = -1;
/**
* Helper class that listens to the combo boxes button. If the button is pressed the
* combo box is toggled to open or close. this is used by Accessibility which presses
* that button Programmatically.
*/
class nsComboButtonListener: public nsIDOMMouseListener
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent) { return PR_FALSE; }
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent)
{
PRBool isDroppedDown;
mComboBox->IsDroppedDown(&isDroppedDown);
mComboBox->ShowDropDown(!isDroppedDown);
return PR_FALSE;
}
nsComboButtonListener(nsComboboxControlFrame* aCombobox)
{
mComboBox = aCombobox;
NS_INIT_ISUPPORTS();
}
virtual ~nsComboButtonListener() {}
nsComboboxControlFrame* mComboBox;
};
NS_IMPL_ISUPPORTS1(nsComboButtonListener, nsIDOMMouseListener)
// static class data member for Bug 32920
nsComboboxControlFrame * nsComboboxControlFrame::mFocused = nsnull;
nscoord nsComboboxControlFrame::mCachedScrollbarWidth = kSizeNotSet;
@ -316,7 +353,7 @@ NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
if (accService) {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
return accService->CreateHTMLSelectAccessible(nsLayoutAtoms::popupList, node, mPresContext, aAccessible);
return accService->CreateHTMLSelectAccessible(node, mPresContext, aAccessible);
}
return NS_ERROR_FAILURE;
@ -2272,6 +2309,14 @@ nsComboboxControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
if (NS_SUCCEEDED(result)) {
nsCOMPtr<nsIHTMLContent> btnContent(do_QueryInterface(content));
if (btnContent) {
// make someone to listen to the button. If its pressed by someone like Accessibility
// then open or close the combo box.
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(content));
if (eventReceiver) {
mButtonListener = new nsComboButtonListener(this);
eventReceiver->AddEventListenerByIID(mButtonListener, NS_GET_IID(nsIDOMMouseListener));
}
btnContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, NS_ConvertASCIItoUCS2("button"), PR_FALSE);
aChildList.AppendElement(btnContent);
}

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

@ -35,6 +35,7 @@
//#define DO_NEW_REFLOW
#endif
#include "nsIDOMMouseListener.h"
#include "nsAreaFrame.h"
#include "nsIFormControlFrame.h"
#include "nsIComboboxControlFrame.h"
@ -276,6 +277,10 @@ protected:
PRPackedBool mGoodToGo;
// make someone to listen to the button. If its programmatically pressed by someone like Accessibility
// then open or close the combo box.
nsCOMPtr<nsIDOMMouseListener> mButtonListener;
// static class data member for Bug 32920
// only one control can be focused at a time
static nsComboboxControlFrame * mFocused;

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

@ -31,6 +31,7 @@
#include "nsIAccessibilityService.h"
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"
#include "nsLayoutAtoms.h"
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
@ -120,6 +121,14 @@ NS_NewGfxButtonControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
return NS_OK;
}
NS_IMETHODIMP
nsGfxButtonControlFrame::GetFrameType(nsIAtom** aType) const
{
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
*aType = nsLayoutAtoms::gfxButtonControlFrame;
NS_ADDREF(*aType);
return NS_OK;
}
PRBool
nsGfxButtonControlFrame::IsReset(PRInt32 type)

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

@ -61,6 +61,8 @@ public:
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
// nsFormControlFrame
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
#ifdef DEBUG

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

@ -58,7 +58,7 @@
#include "nsVoidArray.h"
#include "nsIScrollableFrame.h"
#include "nsIDOMEventTarget.h"
#include "nsIAccessibilityService.h"
#include "nsISelectElement.h"
#include "nsIPrivateDOMEvent.h"
@ -545,6 +545,18 @@ nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return nsScrollFrame::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP nsListControlFrame::GetAccessible(nsIAccessible** aAccessible)
{
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
if (accService) {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
return accService->CreateHTMLSelectAccessible(node, mPresContext, aAccessible);
}
return NS_ERROR_FAILURE;
}
//---------------------------------------------------------
// Reflow is overriden to constrain the listbox height to the number of rows and columns
// specified.
@ -2362,7 +2374,6 @@ nsListControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
return status;
}
//---------------------------------------------------------
void
nsListControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
@ -4116,6 +4127,7 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
SetContentSelected(mSelectedIndex, PR_TRUE);
SetContentSelected(mOldSelectedIndex, PR_FALSE);
}
UpdateSelection(PR_TRUE, PR_FALSE, GetOptionContent(mSelectedIndex)); // dispatch event
} else {
SingleSelection();
if (nsnull != mComboboxFrame && mIsAllFramesHere) {

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

@ -236,6 +236,9 @@ public:
nscoord aCharWidth) const;
virtual nsresult RequiresWidget(PRBool &aRequiresWidget);
// for accessibility purposes
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
// nsHTMLContainerFrame
virtual PRIntn GetSkipSides() const;

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

@ -22,6 +22,7 @@
*/
#include "nsCOMPtr.h"
#include "nsComboboxControlFrame.h"
#include "nsIDOMEventReceiver.h"
#include "nsIFrameManager.h"
#include "nsFormFrame.h"
#include "nsFormControlFrame.h"
@ -52,7 +53,6 @@
#include "nsISelectControlFrame.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
#include "nsIDOMMouseListener.h"
#include "nsITextContent.h"
#include "nsTextFragment.h"
#include "nsCSSFrameConstructor.h"
@ -67,7 +67,6 @@
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
@ -98,6 +97,44 @@ const char * kMozDropdownActive = "-moz-dropdown-active";
const PRInt32 kSizeNotSet = -1;
/**
* Helper class that listens to the combo boxes button. If the button is pressed the
* combo box is toggled to open or close. this is used by Accessibility which presses
* that button Programmatically.
*/
class nsComboButtonListener: public nsIDOMMouseListener
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent) { return PR_FALSE; }
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent)
{
PRBool isDroppedDown;
mComboBox->IsDroppedDown(&isDroppedDown);
mComboBox->ShowDropDown(!isDroppedDown);
return PR_FALSE;
}
nsComboButtonListener(nsComboboxControlFrame* aCombobox)
{
mComboBox = aCombobox;
NS_INIT_ISUPPORTS();
}
virtual ~nsComboButtonListener() {}
nsComboboxControlFrame* mComboBox;
};
NS_IMPL_ISUPPORTS1(nsComboButtonListener, nsIDOMMouseListener)
// static class data member for Bug 32920
nsComboboxControlFrame * nsComboboxControlFrame::mFocused = nsnull;
nscoord nsComboboxControlFrame::mCachedScrollbarWidth = kSizeNotSet;
@ -316,7 +353,7 @@ NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
if (accService) {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
return accService->CreateHTMLSelectAccessible(nsLayoutAtoms::popupList, node, mPresContext, aAccessible);
return accService->CreateHTMLSelectAccessible(node, mPresContext, aAccessible);
}
return NS_ERROR_FAILURE;
@ -2272,6 +2309,14 @@ nsComboboxControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
if (NS_SUCCEEDED(result)) {
nsCOMPtr<nsIHTMLContent> btnContent(do_QueryInterface(content));
if (btnContent) {
// make someone to listen to the button. If its pressed by someone like Accessibility
// then open or close the combo box.
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(content));
if (eventReceiver) {
mButtonListener = new nsComboButtonListener(this);
eventReceiver->AddEventListenerByIID(mButtonListener, NS_GET_IID(nsIDOMMouseListener));
}
btnContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, NS_ConvertASCIItoUCS2("button"), PR_FALSE);
aChildList.AppendElement(btnContent);
}

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

@ -35,6 +35,7 @@
//#define DO_NEW_REFLOW
#endif
#include "nsIDOMMouseListener.h"
#include "nsAreaFrame.h"
#include "nsIFormControlFrame.h"
#include "nsIComboboxControlFrame.h"
@ -276,6 +277,10 @@ protected:
PRPackedBool mGoodToGo;
// make someone to listen to the button. If its programmatically pressed by someone like Accessibility
// then open or close the combo box.
nsCOMPtr<nsIDOMMouseListener> mButtonListener;
// static class data member for Bug 32920
// only one control can be focused at a time
static nsComboboxControlFrame * mFocused;

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

@ -31,6 +31,7 @@
#include "nsIAccessibilityService.h"
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"
#include "nsLayoutAtoms.h"
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
@ -120,6 +121,14 @@ NS_NewGfxButtonControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
return NS_OK;
}
NS_IMETHODIMP
nsGfxButtonControlFrame::GetFrameType(nsIAtom** aType) const
{
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
*aType = nsLayoutAtoms::gfxButtonControlFrame;
NS_ADDREF(*aType);
return NS_OK;
}
PRBool
nsGfxButtonControlFrame::IsReset(PRInt32 type)

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

@ -61,6 +61,8 @@ public:
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
// nsFormControlFrame
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
#ifdef DEBUG

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

@ -58,7 +58,7 @@
#include "nsVoidArray.h"
#include "nsIScrollableFrame.h"
#include "nsIDOMEventTarget.h"
#include "nsIAccessibilityService.h"
#include "nsISelectElement.h"
#include "nsIPrivateDOMEvent.h"
@ -545,6 +545,18 @@ nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return nsScrollFrame::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP nsListControlFrame::GetAccessible(nsIAccessible** aAccessible)
{
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
if (accService) {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
return accService->CreateHTMLSelectAccessible(node, mPresContext, aAccessible);
}
return NS_ERROR_FAILURE;
}
//---------------------------------------------------------
// Reflow is overriden to constrain the listbox height to the number of rows and columns
// specified.
@ -2362,7 +2374,6 @@ nsListControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
return status;
}
//---------------------------------------------------------
void
nsListControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
@ -4116,6 +4127,7 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
SetContentSelected(mSelectedIndex, PR_TRUE);
SetContentSelected(mOldSelectedIndex, PR_FALSE);
}
UpdateSelection(PR_TRUE, PR_FALSE, GetOptionContent(mSelectedIndex)); // dispatch event
} else {
SingleSelection();
if (nsnull != mComboboxFrame && mIsAllFramesHere) {

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

@ -236,6 +236,9 @@ public:
nscoord aCharWidth) const;
virtual nsresult RequiresWidget(PRBool &aRequiresWidget);
// for accessibility purposes
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
// nsHTMLContainerFrame
virtual PRIntn GetSkipSides() const;

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

@ -20,6 +20,6 @@
# Contributor(s):
DEPTH=..\..
DIRS=xpwidgets windows support build
DIRS=xpwidgets windows\expose windows support build
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,5 @@
ISimpleDOMNode.h
ISimpleDOMNode_iid.h
ISimpleDOMDocument.h
ISimpleDOMDocument_iid.h

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

@ -19,17 +19,25 @@
*
* Contributor(s):
*/
#include "nsIAccessible.h"
#include "nsIAccessibleDocument.h"
#include "nsIAccessibleSelectable.h"
#include "nsIAccessibilityService.h"
#include "Accessible.h"
#include "nsIWidget.h"
#include "nsWindow.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIAccessibleEventReceiver.h"
#include "nsReadableUtils.h"
#include "nsITextContent.h"
#include "nsIDocument.h"
#include "nsIXULDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentType.h"
#include "nsINameSpaceManager.h"
#include "String.h"
/* For documentation of the accessibility architecture,
/* For documentation of the accessibility architecture,
* see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
*/
@ -51,7 +59,7 @@ EXTERN_C GUID CDECL CLSID_Accessible =
//-----------------------------------------------------
// construction
//-----------------------------------------------------
Accessible::Accessible(nsIAccessible* aAcc, HWND aWnd)
Accessible::Accessible(nsIAccessible* aAcc, nsIDOMNode* aNode, HWND aWnd): SimpleDOMNode(aAcc, aNode, aWnd)
{
mAccessible = aAcc; // The nsIAccessible we're proxying from
@ -66,9 +74,9 @@ Accessible::Accessible(nsIAccessible* aAcc, HWND aWnd)
#ifdef DEBUG_LEAKS
printf("Accessibles=%d\n", ++gAccessibles);
#endif
}
//-----------------------------------------------------
// destruction
//-----------------------------------------------------
@ -78,42 +86,37 @@ Accessible::~Accessible()
#ifdef DEBUG_LEAKS
printf("Accessibles=%d\n", --gAccessibles);
#endif
}
//-----------------------------------------------------
// IUnknown interface methods - see inknown.h for documentation
// IUnknown interface methods - see iunknown.h for documentation
//-----------------------------------------------------
STDMETHODIMP Accessible::QueryInterface(REFIID riid, void** ppv)
STDMETHODIMP Accessible::QueryInterface(REFIID iid, void** ppv)
{
*ppv=NULL;
*ppv = NULL;
if ( (IID_IUnknown == riid) || (IID_IAccessible == riid) || (IID_IDispatch == riid)) {
*ppv = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
if (IID_IUnknown == iid || IID_IDispatch == iid || IID_IAccessible == iid)
*ppv = NS_STATIC_CAST(IAccessible*, this);
if (NULL == *ppv)
return SimpleDOMNode::QueryInterface(iid,ppv);
(NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
return S_OK;
}
//-----------------------------------------------------
STDMETHODIMP_(ULONG) Accessible::AddRef()
{
return ++m_cRef;
return SimpleDOMNode::AddRef();
}
//-----------------------------------------------------
STDMETHODIMP_(ULONG) Accessible::Release()
{
if (0 != --m_cRef)
return m_cRef;
delete this;
return 0;
return SimpleDOMNode::Release();
}
HINSTANCE Accessible::gmAccLib = 0;
@ -124,10 +127,13 @@ LPFNLRESULTFROMOBJECT Accessible::gmLresultFromObject = 0;
LPFNNOTIFYWINEVENT Accessible::gmNotifyWinEvent = 0;
//-----------------------------------------------------
// IAccessible methods
//-----------------------------------------------------
STDMETHODIMP Accessible::AccessibleObjectFromWindow(
HWND hwnd,
DWORD dwObjectID,
@ -202,7 +208,7 @@ STDMETHODIMP Accessible::get_accParent( IDispatch __RPC_FAR *__RPC_FAR *ppdispPa
mAccessible->GetAccParent(getter_AddRefs(parent));
if (parent) {
IAccessible* a = new Accessible(parent, mWnd);
IAccessible* a = NewAccessible(parent, nsnull, mWnd);
a->AddRef();
*ppdispParent = a;
return S_OK;
@ -253,7 +259,7 @@ STDMETHODIMP Accessible::get_accChild(
}
// create a new one.
IAccessible* ia = new Accessible(a, mWnd);
IAccessible* ia = NewAccessible(a, nsnull, mWnd);
ia->AddRef();
*ppdispChild = ia;
return S_OK;
@ -265,23 +271,24 @@ STDMETHODIMP Accessible::get_accChild(
STDMETHODIMP Accessible::get_accName(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszValue)
/* [retval][out] */ BSTR __RPC_FAR *pszName)
{
*pszValue = NULL;
*pszName = NULL;
nsCOMPtr<nsIAccessible> a;
GetNSAccessibleFor(varChild,a);
if (a) {
nsXPIDLString name;
nsresult rv = a->GetAccName(getter_Copies(name));
nsAutoString name;
nsresult rv = a->GetAccName(name);
if (NS_FAILED(rv))
return S_FALSE;
*pszValue = ::SysAllocString(name.get());
*pszName = ::SysAllocString(name.GetUnicode());
}
return S_OK;
}
STDMETHODIMP Accessible::get_accValue(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszValue)
@ -290,12 +297,12 @@ STDMETHODIMP Accessible::get_accValue(
nsCOMPtr<nsIAccessible> a;
GetNSAccessibleFor(varChild,a);
if (a) {
nsXPIDLString name;
nsresult rv = a->GetAccValue(getter_Copies(name));
nsAutoString value;
nsresult rv = a->GetAccValue(value);
if (NS_FAILED(rv))
return S_FALSE;
*pszValue = ::SysAllocString(name.get());
*pszValue = ::SysAllocString(value.GetUnicode());
}
return S_OK;
@ -304,18 +311,18 @@ STDMETHODIMP Accessible::get_accValue(
STDMETHODIMP Accessible::get_accDescription(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszValue)
/* [retval][out] */ BSTR __RPC_FAR *pszDescription)
{
*pszValue = NULL;
*pszDescription = NULL;
nsCOMPtr<nsIAccessible> a;
GetNSAccessibleFor(varChild,a);
if (a) {
nsXPIDLString name;
nsresult rv = a->GetAccDescription(getter_Copies(name));
nsAutoString description;
nsresult rv = a->GetAccDescription(description);
if (NS_FAILED(rv))
return S_FALSE;
*pszValue = ::SysAllocString(name.get());
*pszDescription = ::SysAllocString(description.GetUnicode());
}
return S_OK;
@ -371,7 +378,8 @@ STDMETHODIMP Accessible::get_accHelp(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszHelp)
{
return NULL;
*pszHelp = NULL;
return S_FALSE;
}
STDMETHODIMP Accessible::get_accHelpTopic(
@ -379,6 +387,8 @@ STDMETHODIMP Accessible::get_accHelpTopic(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ long __RPC_FAR *pidTopic)
{
*pszHelpFile = NULL;
*pidTopic = 0;
return S_FALSE;
}
@ -386,6 +396,7 @@ STDMETHODIMP Accessible::get_accKeyboardShortcut(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszKeyboardShortcut)
{
*pszKeyboardShortcut = NULL;
return S_FALSE;
}
@ -398,7 +409,7 @@ STDMETHODIMP Accessible::get_accFocus(
nsCOMPtr<nsIAccessible> focusedAccessible;
if (NS_SUCCEEDED(mAccessible->GetAccFocused(getter_AddRefs(focusedAccessible)))) {
pvarChild->vt = VT_DISPATCH;
pvarChild->pdispVal = new Accessible(focusedAccessible, mWnd);
pvarChild->pdispVal = NewAccessible(focusedAccessible, nsnull, mWnd);
pvarChild->pdispVal->AddRef();
return S_OK;
}
@ -422,12 +433,12 @@ STDMETHODIMP Accessible::get_accDefaultAction(
nsCOMPtr<nsIAccessible> a;
GetNSAccessibleFor(varChild,a);
if (a) {
nsXPIDLString name;
nsresult rv = a->GetAccActionName(0,getter_Copies(name));
nsAutoString defaultAction;
nsresult rv = a->GetAccActionName(0,defaultAction);
if (NS_FAILED(rv))
return S_FALSE;
*pszDefaultAction = ::SysAllocString(name.get());
*pszDefaultAction = ::SysAllocString(defaultAction.GetUnicode());
}
return S_OK;
@ -521,7 +532,7 @@ STDMETHODIMP Accessible::accNavigate(
}
if (acc) {
IAccessible* a = new Accessible(acc,mWnd);
IAccessible* a = NewAccessible(acc, nsnull, mWnd);
a->AddRef();
pvarEndUpAt->vt = VT_DISPATCH;
pvarEndUpAt->pdispVal = a;
@ -556,7 +567,7 @@ STDMETHODIMP Accessible::accHitTest(
pvarChild->lVal = CHILDID_SELF;
} else { // its not create an Accessible for it.
pvarChild->vt = VT_DISPATCH;
pvarChild->pdispVal = new Accessible(a, mWnd);
pvarChild->pdispVal = NewAccessible(a, nsnull, mWnd);
pvarChild->pdispVal->AddRef();
}
} else {
@ -588,6 +599,7 @@ STDMETHODIMP Accessible::put_accValue(
return S_FALSE;
}
// For IDispatch support
STDMETHODIMP
Accessible::GetTypeInfoCount(UINT *p)
@ -619,8 +631,28 @@ STDMETHODIMP Accessible::Invoke(DISPID dispIdMember, REFIID riid,
return E_NOTIMPL;
}
//------- Helper methods ---------
IAccessible *Accessible::NewAccessible(nsIAccessible *aNSAcc, nsIDOMNode *aNode, HWND aWnd)
{
IAccessible *retval = nsnull;
if (aNSAcc) {
nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(aNSAcc));
if (accDoc) {
nsCOMPtr<nsIDocument> doc;
accDoc->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(doc));
retval = new DocAccessible(aNSAcc, node, aWnd);
}
else
retval = new Accessible(aNSAcc, aNode, aWnd);
}
return retval;
}
void Accessible::GetNSAccessibleFor(VARIANT varChild, nsCOMPtr<nsIAccessible>& aAcc)
{
// if its us real easy
@ -661,49 +693,181 @@ void Accessible::GetNSAccessibleFor(VARIANT varChild, nsCOMPtr<nsIAccessible>& a
}
}
//----- Root Accessible -----
NS_IMPL_QUERY_INTERFACE1(RootAccessible, nsIAccessibleEventListener)
//----- DocAccessible -----
// Microsoft COM QueryInterface
STDMETHODIMP DocAccessible::QueryInterface(REFIID iid, void** ppv)
{
*ppv = NULL;
if (IID_IUnknown == iid || IID_IDispatch == iid || IID_ISimpleDOMDocument == iid)
*ppv = NS_STATIC_CAST(ISimpleDOMDocument*, this);
if (NULL == *ppv)
return Accessible::QueryInterface(iid,ppv);
(NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
return S_OK;
}
NS_IMETHODIMP_(nsrefcnt)
RootAccessible::AddRef(void)
DocAccessible::AddRef(void)
{
return Accessible::AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
RootAccessible::Release(void)
DocAccessible::Release(void)
{
return Accessible::Release();
}
RootAccessible::RootAccessible(nsIAccessible* aAcc, HWND aWnd):Accessible(aAcc,aWnd)
DocAccessible::DocAccessible(nsIAccessible* aAcc, nsIDOMNode *aNode, HWND aWnd):Accessible(aAcc,aNode,aWnd)
{
mListCount = 0;
mNextId = -1;
mNextPos = 0;
}
nsCOMPtr<nsIAccessibleEventReceiver> r(do_QueryInterface(mAccessible));
if (r)
r->AddAccessibleEventListener(this);
DocAccessible::~DocAccessible()
{
}
STDMETHODIMP DocAccessible::get_URL(/* [out] */ BSTR __RPC_FAR *aURL)
{
nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(mAccessible));
if (accDoc) {
nsAutoString URL;
if (NS_SUCCEEDED(accDoc->GetURL(URL))) {
*aURL= ::SysAllocString(URL.GetUnicode());
return S_OK;
}
}
return S_FALSE;
}
STDMETHODIMP DocAccessible::get_title( /* [out] */ BSTR __RPC_FAR *aTitle)
{
nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(mAccessible));
if (accDoc) {
nsAutoString title;
if (NS_SUCCEEDED(accDoc->GetTitle(title))) { // getter_Copies(pszTitle)))) {
*aTitle= ::SysAllocString(title.GetUnicode());
return S_OK;
}
}
return S_FALSE;
}
STDMETHODIMP DocAccessible::get_mimeType(/* [out] */ BSTR __RPC_FAR *aMimeType)
{
nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(mAccessible));
if (accDoc) {
nsAutoString mimeType;
if (NS_SUCCEEDED(accDoc->GetMimeType(mimeType))) {
*aMimeType= ::SysAllocString(mimeType.GetUnicode());
return S_OK;
}
}
return S_FALSE;
}
STDMETHODIMP DocAccessible::get_docType(/* [out] */ BSTR __RPC_FAR *aDocType)
{
nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(mAccessible));
if (accDoc) {
nsAutoString docType;
if (NS_SUCCEEDED(accDoc->GetDocType(docType))) {
*aDocType= ::SysAllocString(docType.GetUnicode());
return S_OK;
}
}
return S_FALSE;
}
STDMETHODIMP DocAccessible::get_nameSpaceURIForID(/* [in] */ short aNameSpaceID,
/* [out] */ BSTR __RPC_FAR *aNameSpaceURI)
{
nsCOMPtr<nsIAccessibleDocument> accDoc(do_QueryInterface(mAccessible));
if (accDoc) {
*aNameSpaceURI = NULL;
nsAutoString nameSpaceURI;
if (NS_SUCCEEDED(accDoc->GetNameSpaceURIForID(aNameSpaceID, nameSpaceURI)))
*aNameSpaceURI = ::SysAllocString(nameSpaceURI.GetUnicode());
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP DocAccessible::put_alternateViewMediaTypes( /* [in] */ BSTR __RPC_FAR *commaSeparatedMediaTypes)
{
return S_FALSE;
}
//----- Root Accessible -----
// XPCOM QueryInterface
NS_IMPL_QUERY_INTERFACE1(RootAccessible, nsIAccessibleEventListener)
// Microsoft COM QueryInterface
STDMETHODIMP RootAccessible::QueryInterface(REFIID iid, void** ppv)
{
*ppv = NULL;
if (IID_IUnknown == iid || IID_IDispatch == iid || IID_ISimpleDOMDocument == iid)
*ppv = NS_STATIC_CAST(ISimpleDOMDocument*, this);
if (NULL == *ppv)
return DocAccessible::QueryInterface(iid, ppv);
(NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
return S_OK;
}
NS_IMETHODIMP_(nsrefcnt)
RootAccessible::AddRef(void)
{
return DocAccessible::AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
RootAccessible::Release(void)
{
return DocAccessible::Release();
}
RootAccessible::RootAccessible(nsIAccessible* aAcc, HWND aWnd):DocAccessible(aAcc,nsnull,aWnd)
{
mListCount = 0;
mNextId = -1;
mNextPos = 0;
nsCOMPtr<nsIAccessibleEventReceiver> r(do_QueryInterface(mAccessible));
if (r)
r->AddAccessibleEventListener(this);
}
RootAccessible::~RootAccessible()
{
nsCOMPtr<nsIAccessibleEventReceiver> r(do_QueryInterface(mAccessible));
if (r)
r->RemoveAccessibleEventListener(this);
nsCOMPtr<nsIAccessibleEventReceiver> r(do_QueryInterface(mAccessible));
if (r)
r->RemoveAccessibleEventListener(this);
// free up accessibles
for (int i=0; i < mListCount; i++)
mList[i].mAccessible = nsnull;
// free up accessibles
for (int i=0; i < mListCount; i++)
mList[i].mAccessible = nsnull;
}
void RootAccessible::GetNSAccessibleFor(VARIANT varChild, nsCOMPtr<nsIAccessible>& aAcc)
{
aAcc = nsnull;
Accessible::GetNSAccessibleFor(varChild, aAcc);
DocAccessible::GetNSAccessibleFor(varChild, aAcc);
if (aAcc)
return;

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

@ -37,15 +37,18 @@
#include "nsCOMPtr.h"
#include "nsIAccessible.h"
#include "nsIAccessibleEventListener.h"
#include "SimpleDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsString.h"
typedef LRESULT (STDAPICALLTYPE *LPFNNOTIFYWINEVENT)(DWORD event,HWND hwnd,LONG idObjectType,LONG idObject);
class Accessible : public IAccessible
class Accessible : public SimpleDOMNode, public IAccessible
{
public: // construction, destruction
Accessible(nsIAccessible*, HWND aWin = 0);
Accessible(nsIAccessible*, nsIDOMNode*, HWND aWin = 0);
virtual ~Accessible();
public: // IUnknown methods - see iunknown.h for documentation
@ -58,91 +61,92 @@ class Accessible : public IAccessible
public:
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accParent(
/* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispParent);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accParent(
/* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispParent);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accChildCount(
/* [retval][out] */ long __RPC_FAR *pcountChildren);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accChildCount(
/* [retval][out] */ long __RPC_FAR *pcountChildren);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accChild(
/* [in] */ VARIANT varChild,
/* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispChild);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accChild(
/* [in] */ VARIANT varChild,
/* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispChild);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accName(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszName);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accName(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszName);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accValue(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszValue);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accValue(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszValue);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accDescription(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszDescription);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accDescription(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszDescription);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accRole(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ VARIANT __RPC_FAR *pvarRole);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accRole(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ VARIANT __RPC_FAR *pvarRole);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accState(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ VARIANT __RPC_FAR *pvarState);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accState(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ VARIANT __RPC_FAR *pvarState);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accHelp(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszHelp);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accHelp(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszHelp);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accHelpTopic(
/* [out] */ BSTR __RPC_FAR *pszHelpFile,
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ long __RPC_FAR *pidTopic);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accHelpTopic(
/* [out] */ BSTR __RPC_FAR *pszHelpFile,
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ long __RPC_FAR *pidTopic);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accKeyboardShortcut(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszKeyboardShortcut);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accKeyboardShortcut(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszKeyboardShortcut);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accFocus(
/* [retval][out] */ VARIANT __RPC_FAR *pvarChild);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accFocus(
/* [retval][out] */ VARIANT __RPC_FAR *pvarChild);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accSelection(
/* [retval][out] */ VARIANT __RPC_FAR *pvarChildren);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accSelection(
/* [retval][out] */ VARIANT __RPC_FAR *pvarChildren);
virtual /* [id][propget][hidden] */ HRESULT STDMETHODCALLTYPE get_accDefaultAction(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszDefaultAction);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accDefaultAction(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR *pszDefaultAction);
virtual /* [id][hidden] */ HRESULT STDMETHODCALLTYPE accSelect(
/* [in] */ long flagsSelect,
/* [optional][in] */ VARIANT varChild);
virtual /* [id] */ HRESULT STDMETHODCALLTYPE accSelect(
/* [in] */ long flagsSelect,
/* [optional][in] */ VARIANT varChild);
virtual /* [id][hidden] */ HRESULT STDMETHODCALLTYPE accLocation(
/* [out] */ long __RPC_FAR *pxLeft,
/* [out] */ long __RPC_FAR *pyTop,
/* [out] */ long __RPC_FAR *pcxWidth,
/* [out] */ long __RPC_FAR *pcyHeight,
/* [optional][in] */ VARIANT varChild);
virtual /* [id] */ HRESULT STDMETHODCALLTYPE accLocation(
/* [out] */ long __RPC_FAR *pxLeft,
/* [out] */ long __RPC_FAR *pyTop,
/* [out] */ long __RPC_FAR *pcxWidth,
/* [out] */ long __RPC_FAR *pcyHeight,
/* [optional][in] */ VARIANT varChild);
virtual /* [id][hidden] */ HRESULT STDMETHODCALLTYPE accNavigate(
/* [in] */ long navDir,
/* [optional][in] */ VARIANT varStart,
/* [retval][out] */ VARIANT __RPC_FAR *pvarEndUpAt);
virtual /* [id] */ HRESULT STDMETHODCALLTYPE accNavigate(
/* [in] */ long navDir,
/* [optional][in] */ VARIANT varStart,
/* [retval][out] */ VARIANT __RPC_FAR *pvarEndUpAt);
virtual /* [id][hidden] */ HRESULT STDMETHODCALLTYPE accHitTest(
/* [in] */ long xLeft,
/* [in] */ long yTop,
/* [retval][out] */ VARIANT __RPC_FAR *pvarChild);
virtual /* [id] */ HRESULT STDMETHODCALLTYPE accHitTest(
/* [in] */ long xLeft,
/* [in] */ long yTop,
/* [retval][out] */ VARIANT __RPC_FAR *pvarChild);
virtual /* [id][hidden] */ HRESULT STDMETHODCALLTYPE accDoDefaultAction(
/* [optional][in] */ VARIANT varChild);
virtual /* [id] */ HRESULT STDMETHODCALLTYPE accDoDefaultAction(
/* [optional][in] */ VARIANT varChild);
virtual /* [id][propput][hidden] */ HRESULT STDMETHODCALLTYPE put_accName(
/* [optional][in] */ VARIANT varChild,
/* [in] */ BSTR szName);
virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_accName(
/* [optional][in] */ VARIANT varChild,
/* [in] */ BSTR szName);
virtual /* [id][propput][hidden] */ HRESULT STDMETHODCALLTYPE put_accValue(
/* [optional][in] */ VARIANT varChild,
/* [in] */ BSTR szValue);
virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_accValue(
/* [optional][in] */ VARIANT varChild,
/* [in] */ BSTR szValue);
// ====== Methods for IDispatch - for VisualBasic bindings (not implemented) ======
STDMETHODIMP GetTypeInfoCount(UINT *p);
STDMETHODIMP GetTypeInfo(UINT i, LCID lcid, ITypeInfo **ppti);
@ -158,47 +162,77 @@ class Accessible : public IAccessible
static STDMETHODIMP AccessibleObjectFromWindow(HWND hwnd,DWORD dwObjectID,REFIID riid,void **ppvObject);
static STDMETHODIMP_(LRESULT) LresultFromObject(REFIID riid,WPARAM wParam,LPUNKNOWN pAcc);
static STDMETHODIMP NotifyWinEvent(DWORD event,HWND hwnd,LONG idObjectType,LONG idObject);
static ULONG g_cRef; // the cum reference count of all instances
ULONG m_cRef; // the reference count
nsCOMPtr<nsIAccessible> mAccessible;
nsCOMPtr<nsIAccessible> mCachedChild;
HWND mWnd;
LONG mCachedIndex;
protected:
protected:
nsCOMPtr<nsIAccessible> mAccessible;
virtual void GetNSAccessibleFor(VARIANT varChild, nsCOMPtr<nsIAccessible>& aAcc);
PRBool InState(const nsString& aStates, const char* aState);
STDMETHODIMP GetAttribute(const char* aName, VARIANT varChild, BSTR __RPC_FAR *aString);
nsCOMPtr<nsIAccessible> mCachedChild;
LONG mCachedIndex;
virtual void GetNSAccessibleFor(VARIANT varChild, nsCOMPtr<nsIAccessible>& aAcc);
IAccessible *Accessible::NewAccessible(nsIAccessible *aNSAcc, nsIDOMNode *aNode, HWND aWnd);
private:
/// the accessible library and cached methods
static HINSTANCE gmAccLib;
static HINSTANCE gmUserLib;
static LPFNACCESSIBLEOBJECTFROMWINDOW gmAccessibleObjectFromWindow;
static LPFNLRESULTFROMOBJECT gmLresultFromObject;
static LPFNNOTIFYWINEVENT gmNotifyWinEvent;
/// the accessible library and cached methods
static HINSTANCE gmAccLib;
static HINSTANCE gmUserLib;
static LPFNACCESSIBLEOBJECTFROMWINDOW gmAccessibleObjectFromWindow;
static LPFNLRESULTFROMOBJECT gmLresultFromObject;
static LPFNNOTIFYWINEVENT gmNotifyWinEvent;
};
class nsAccessibleEventMap
{
public:
nsCOMPtr<nsIAccessible> mAccessible;
PRInt32 mId;
nsCOMPtr<nsIAccessible> mAccessible;
};
class DocAccessible: public Accessible, public ISimpleDOMDocument
{
public:
DocAccessible(nsIAccessible*, nsIDOMNode *, HWND aWin = 0);
virtual ~DocAccessible();
STDMETHODIMP_(ULONG) AddRef ();
STDMETHODIMP QueryInterface(REFIID, void**);
STDMETHODIMP_(ULONG) Release ();
// ISimpleDOMDocument
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_URL(
/* [out] */ BSTR __RPC_FAR *url);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_title(
/* [out] */ BSTR __RPC_FAR *title);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_mimeType(
/* [out] */ BSTR __RPC_FAR *mimeType);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_docType(
/* [out] */ BSTR __RPC_FAR *docType);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_nameSpaceURIForID(
/* [in] */ short nameSpaceID,
/* [out] */ BSTR __RPC_FAR *nameSpaceURI);
virtual /* [id] */ HRESULT STDMETHODCALLTYPE put_alternateViewMediaTypes(
/* [in] */ BSTR __RPC_FAR *commaSeparatedMediaTypes);
};
#define MAX_LIST_SIZE 100
class RootAccessible: public Accessible,
public nsIAccessibleEventListener
class RootAccessible: public DocAccessible, public nsIAccessibleEventListener
{
public:
RootAccessible(nsIAccessible*, HWND aWin = 0);
virtual ~RootAccessible();
STDMETHODIMP QueryInterface(REFIID, void**);
NS_DECL_ISUPPORTS
// nsIAccessibleEventListener
@ -214,7 +248,6 @@ private:
PRInt32 mListCount;
PRInt32 mNextId;
PRInt32 mNextPos;
};
#endif

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

@ -0,0 +1,436 @@
/* -*- 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.
*
* Original Author: Aaron Leventhal (aaronl@netscape.com)
*
* Contributor(s):
*/
#include "nsIAccessible.h"
#include "nsIAccessibleDocument.h"
#include "Accessible.h"
#include "SimpleDOMNode.h"
#include "ISimpleDOMNode_iid.h"
#include "ISimpleDOMDocument_iid.h"
#include "nsIWidget.h"
#include "nsWindow.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIAccessibleEventReceiver.h"
#include "nsReadableUtils.h"
#include "nsITextContent.h"
#include "nsIFrame.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMDocument.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMViewCSS.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsILink.h"
#include "nsIAccessibilityService.h"
#include "nsIServiceManager.h"
#include "nsIWeakReference.h"
#include "nsIDocShellTreeItem.h"
#include "nsIPresContext.h"
#include "nsPromiseFlatString.h"
/* For documentation of the accessibility architecture,
* see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
*/
//#define DEBUG_LEAKS
#ifdef DEBUG_LEAKS
static gSimpleDOMNodes = 0;
#endif
/*
* Class Accessible
*/
//-----------------------------------------------------
// construction
//-----------------------------------------------------
SimpleDOMNode::SimpleDOMNode(nsIAccessible* aNSAcc, nsIDOMNode *aNode, HWND aWnd): mWnd(aWnd), m_cRef(0)
{
MOZ_COUNT_CTOR(SimpleDOMNode); // For catching leaks on tinderbox
mDOMNode = aNode;
if (!aNode && aNSAcc)
aNSAcc->AccGetDOMNode(getter_AddRefs(mDOMNode));
#ifdef DEBUG_LEAKS
printf("SimpleDOMNodes=%d\n", ++gSimpleDOMNodes);
#endif
}
//-----------------------------------------------------
// destruction
//-----------------------------------------------------
SimpleDOMNode::~SimpleDOMNode()
{
MOZ_COUNT_DTOR(SimpleDOMNode); // For catching leaks on tinderbox
m_cRef = 0;
#ifdef DEBUG_LEAKS
printf("SimpleDOMNodes=%d\n", --gSimpleDOMNodes);
#endif
}
//-----------------------------------------------------
// IUnknown interface methods - see iunknown.h for documentation
//-----------------------------------------------------
STDMETHODIMP SimpleDOMNode::QueryInterface(REFIID iid, void** ppv)
{
*ppv = nsnull;
if (IID_IUnknown == iid || IID_ISimpleDOMNode == iid)
*ppv = NS_STATIC_CAST(ISimpleDOMNode*, this);
if (nsnull == *ppv)
return E_NOINTERFACE; //iid not supported.
(NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
return S_OK;
}
//-----------------------------------------------------
STDMETHODIMP_(ULONG) SimpleDOMNode::AddRef()
{
return ++m_cRef;
}
//-----------------------------------------------------
STDMETHODIMP_(ULONG) SimpleDOMNode::Release()
{
if (0 != --m_cRef)
return m_cRef;
delete this;
return 0;
}
//-----------------------------------------------------
// ISimpleDOMNode methods
//-----------------------------------------------------
STDMETHODIMP SimpleDOMNode::get_nodeInfo(
/* [out] */ BSTR __RPC_FAR *aNodeName,
/* [out] */ short __RPC_FAR *aNameSpaceID,
/* [out] */ BSTR __RPC_FAR *aNodeValue,
/* [out] */ unsigned int __RPC_FAR *aNumChildren,
/* [out] */ unsigned short __RPC_FAR *aNodeType)
{
*aNodeName = nsnull;
nsCOMPtr<nsIDOMElement> domElement;
nsCOMPtr<nsIContent> content;
GetElementAndContentFor(domElement, content);
PRUint16 nodeType = 0;
mDOMNode->GetNodeType(&nodeType);
*aNodeType=NS_STATIC_CAST(unsigned short, nodeType);
if (*aNodeType != NODETYPE_TEXT) {
nsAutoString nodeName;
mDOMNode->GetNodeName(nodeName);
*aNodeName = ::SysAllocString(nodeName.GetUnicode());
}
nsAutoString nodeValue;
mDOMNode->GetNodeValue(nodeValue);
*aNodeValue = ::SysAllocString(nodeValue.GetUnicode());
PRInt32 nameSpaceID = 0;
if (content)
content->GetNameSpaceID(nameSpaceID);
*aNameSpaceID = NS_STATIC_CAST(short, nameSpaceID);
*aNumChildren = 0;
PRUint32 numChildren = 0;
nsCOMPtr<nsIDOMNodeList> nodeList;
mDOMNode->GetChildNodes(getter_AddRefs(nodeList));
if (nodeList && NS_OK == nodeList->GetLength(&numChildren))
*aNumChildren = NS_STATIC_CAST(unsigned int, numChildren);
return S_OK;
}
STDMETHODIMP SimpleDOMNode::get_attributes(
/* [in] */ unsigned short aMaxAttribs,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *aAttribNames,
/* [length_is][size_is][out] */ short __RPC_FAR *aNameSpaceIDs,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *aAttribValues,
/* [out] */ unsigned short __RPC_FAR *aNumAttribs)
{
nsCOMPtr<nsIDOMElement> domElement;
nsCOMPtr<nsIContent> content;
GetElementAndContentFor(domElement, content);
*aNumAttribs = 0;
if (!content || !domElement)
return S_FALSE;
PRInt32 numAttribs;
content->GetAttributeCount(numAttribs);
if (numAttribs > aMaxAttribs)
numAttribs = aMaxAttribs;
*aNumAttribs = NS_STATIC_CAST(unsigned short, numAttribs);
PRInt32 index, nameSpaceID;
nsCOMPtr<nsIAtom> nameAtom, prefixAtom;
for (index = 0; index < numAttribs; index++) {
aNameSpaceIDs[index] = 0; aAttribValues[index] = aAttribNames[index] = nsnull;
nsAutoString attributeValue;
const PRUnichar *pszAttributeName;
if (NS_SUCCEEDED(content->GetAttributeNameAt(index, nameSpaceID, *getter_AddRefs(nameAtom), *getter_AddRefs(prefixAtom)))) {
aNameSpaceIDs[index] = NS_STATIC_CAST(short, nameSpaceID);
nameAtom->GetUnicode(&pszAttributeName);
aAttribNames[index] = ::SysAllocString(pszAttributeName);
if (NS_SUCCEEDED(content->GetAttribute(nameSpaceID, nameAtom, attributeValue)))
aAttribValues[index] = ::SysAllocString(attributeValue.GetUnicode());
}
}
return S_OK;
}
NS_IMETHODIMP SimpleDOMNode::GetComputedStyleDeclaration(nsIDOMCSSStyleDeclaration **aCssDecl, PRUint32 *aLength)
{
nsCOMPtr<nsIDOMElement> domElement;
nsCOMPtr<nsIContent> content;
GetElementAndContentFor(domElement, content);
if (!domElement || !content)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
if (content)
content->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIPresShell> shell;
if (doc)
doc->GetShellAt(0, getter_AddRefs(shell));
if (!shell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObject> global;
doc->GetScriptGlobalObject(getter_AddRefs(global));
nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(global));
if (!viewCSS)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
nsAutoString empty;
viewCSS->GetComputedStyle(domElement, empty, getter_AddRefs(cssDecl));
if (cssDecl) {
*aCssDecl = cssDecl;
NS_ADDREF(*aCssDecl);
cssDecl->GetLength(aLength);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
/* To do: use media type if not null */
STDMETHODIMP SimpleDOMNode::get_computedStyle(
/* [in] */ unsigned short aMaxStyleProperties,
/* [in] */ boolean aUseAlternateView,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *aStyleProperties,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *aStyleValues,
/* [out] */ unsigned short __RPC_FAR *aNumStyleProperties)
{
*aNumStyleProperties = 0;
PRUint32 length;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
if (NS_FAILED(GetComputedStyleDeclaration(getter_AddRefs(cssDecl), &length)))
return S_FALSE;
PRUint32 index, realIndex;
for (index = realIndex = 0; index < length && realIndex < aMaxStyleProperties; index ++) {
nsAutoString property, value;
if (NS_SUCCEEDED(cssDecl->Item(index, property)) && property.CharAt(0) != '-') // Ignore -moz-* properties
cssDecl->GetPropertyValue(property, value); // Get property value
if (!value.IsEmpty()) {
aStyleProperties[realIndex] = ::SysAllocString(property.GetUnicode());
aStyleValues[realIndex] = ::SysAllocString(value.GetUnicode());
++realIndex;
}
}
*aNumStyleProperties = NS_STATIC_CAST(unsigned short, realIndex);
return S_OK;
}
STDMETHODIMP SimpleDOMNode::get_computedStyleForProperties(
/* [in] */ unsigned short aNumStyleProperties,
/* [in] */ boolean aUseAlternateView,
/* [length_is][size_is][in] */ BSTR __RPC_FAR *aStyleProperties,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *aStyleValues)
{
PRUint32 length = 0;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
nsresult rv = GetComputedStyleDeclaration(getter_AddRefs(cssDecl), &length);
if (NS_FAILED(rv))
return S_FALSE;
PRUint32 index;
for (index = 0; index < aNumStyleProperties; index ++) {
nsAutoString value;
if (aStyleProperties[index])
cssDecl->GetPropertyValue(nsDependentString(NS_STATIC_CAST(PRUnichar*,aStyleProperties[index])), value); // Get property value
aStyleValues[index] = ::SysAllocString(value.GetUnicode());
}
return S_OK;
}
ISimpleDOMNode* SimpleDOMNode::MakeSimpleDOMNode(nsIDOMNode *node)
{
if (!node)
return NULL;
ISimpleDOMNode *newNode = NULL;
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
nsCOMPtr<nsIDocument> doc;
if (content)
content->GetDocument(*getter_AddRefs(doc));
else {
// Get the document via QueryInterface, since there is no content node
doc = do_QueryInterface(node);
}
if (!doc)
return NULL;
nsCOMPtr<nsIPresShell> shell;
doc->GetShellAt(0, getter_AddRefs(shell));
if (!shell)
return NULL;
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
if (!accService)
return NULL;
nsCOMPtr<nsIAccessible> nsAcc;
nsCOMPtr<nsIWeakReference> wr (getter_AddRefs(NS_GetWeakReference(shell)));
accService->GetAccessibleFor(wr, node, getter_AddRefs(nsAcc));
if (nsAcc) {
nsCOMPtr<nsIAccessibleDocument> nsAccDoc(do_QueryInterface(nsAcc));
if (nsAccDoc)
newNode = new DocAccessible(nsAcc, node, mWnd);
else
newNode = new Accessible(nsAcc, node, mWnd);
}
else if (!content) { // We're on a the root frame
IAccessible * pAcc = NULL;
HRESULT hr = Accessible::AccessibleObjectFromWindow( mWnd, OBJID_CLIENT, IID_IAccessible, (void **) &pAcc );
if (pAcc) {
ISimpleDOMNode *testNode;
pAcc->QueryInterface(IID_ISimpleDOMNode, (void**)&testNode);
newNode = testNode;
pAcc->Release();
}
}
else
newNode = new SimpleDOMNode(nsnull, node, mWnd);
if (newNode)
newNode->AddRef();
return newNode;
}
STDMETHODIMP SimpleDOMNode::get_parentNode(ISimpleDOMNode __RPC_FAR *__RPC_FAR *aNode)
{
nsCOMPtr<nsIDOMNode> node;
mDOMNode->GetParentNode(getter_AddRefs(node));
*aNode = MakeSimpleDOMNode(node);
return S_OK;
}
STDMETHODIMP SimpleDOMNode::get_firstChild(ISimpleDOMNode __RPC_FAR *__RPC_FAR *aNode)
{
nsCOMPtr<nsIDOMNode> node;
mDOMNode->GetFirstChild(getter_AddRefs(node));
*aNode = MakeSimpleDOMNode(node);
return S_OK;
}
STDMETHODIMP SimpleDOMNode::get_lastChild(ISimpleDOMNode __RPC_FAR *__RPC_FAR *aNode)
{
nsCOMPtr<nsIDOMNode> node;
mDOMNode->GetLastChild(getter_AddRefs(node));
*aNode = MakeSimpleDOMNode(node);
return S_OK;
}
STDMETHODIMP SimpleDOMNode::get_previousSibling(ISimpleDOMNode __RPC_FAR *__RPC_FAR *aNode)
{
nsCOMPtr<nsIDOMNode> node;
mDOMNode->GetPreviousSibling(getter_AddRefs(node));
*aNode = MakeSimpleDOMNode(node);
return S_OK;
}
STDMETHODIMP SimpleDOMNode::get_nextSibling(ISimpleDOMNode __RPC_FAR *__RPC_FAR *aNode)
{
nsCOMPtr<nsIDOMNode> node;
mDOMNode->GetNextSibling(getter_AddRefs(node));
*aNode = MakeSimpleDOMNode(node);
return S_OK;
}
//------- Helper methods ---------
void SimpleDOMNode::GetElementAndContentFor(nsCOMPtr<nsIDOMElement>& aElement, nsCOMPtr<nsIContent> &aContent)
{
aElement = do_QueryInterface(mDOMNode);
aContent = do_QueryInterface(mDOMNode);
}
nsIDOMNode* SimpleDOMNode::GetRealDOMNode()
{
return mDOMNode;
}

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

@ -0,0 +1,107 @@
/* -*- 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.
*
* Original Author: Aaron Leventhal
*
* Contributor(s):
*/
/* For documentation of the accessibility architecture,
* see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
*/
#ifndef _SimpleDOMNode_H_
#define _SimpleDOMNode_H_
#include "nsCOMPtr.h"
#include "nsIAccessible.h"
#include "Accessible.h"
#include "nsIAccessibleEventListener.h"
#include "ISimpleDOMNode.h"
#include "ISimpleDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsString.h"
class SimpleDOMNode : public ISimpleDOMNode
{
public: // construction, destruction
SimpleDOMNode(nsIAccessible *, HWND);
SimpleDOMNode(nsIAccessible *, nsIDOMNode *, HWND);
virtual ~SimpleDOMNode();
public: // IUnknown methods - see iunknown.h for documentation
STDMETHODIMP_(ULONG) AddRef ();
STDMETHODIMP QueryInterface(REFIID, void**);
STDMETHODIMP_(ULONG) Release ();
nsIDOMNode* GetRealDOMNode();
private:
void GetAccessibleFor(nsIDOMNode *node, nsIAccessible **newAcc);
ISimpleDOMNode* SimpleDOMNode::MakeSimpleDOMNode(nsIDOMNode *node);
NS_IMETHOD GetComputedStyleDeclaration(nsIDOMCSSStyleDeclaration **aCssDecl, PRUint32 *aLength);
public:
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_nodeInfo(
/* [out] */ BSTR __RPC_FAR *tagName,
/* [out] */ short __RPC_FAR *nameSpaceID,
/* [out] */ BSTR __RPC_FAR *nodeValue,
/* [out] */ unsigned int __RPC_FAR *numChildren,
/* [out][retval] */ unsigned short __RPC_FAR *nodeType);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_attributes(
/* [in] */ unsigned short maxAttribs,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *attribNames,
/* [length_is][size_is][out] */ short __RPC_FAR *nameSpaceID,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *attribValues,
/* [out][retval] */ unsigned short __RPC_FAR *numAttribs);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_computedStyle(
/* [in] */ unsigned short maxStyleProperties,
/* [in] */ boolean useAlternateView,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *styleProperties,
/* [length_is][size_is][out] */ BSTR __RPC_FAR *styleValues,
/* [out][retval] */ unsigned short __RPC_FAR *numStyleProperties);
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_computedStyleForProperties(
/* [in] */ unsigned short numStyleProperties,
/* [in] */ boolean useAlternateView,
/* [length_is][size_is][in] */ BSTR __RPC_FAR *styleProperties,
/* [length_is][size_is][out][retval] */ BSTR __RPC_FAR *styleValues);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_parentNode(ISimpleDOMNode __RPC_FAR *__RPC_FAR *node);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_firstChild(ISimpleDOMNode __RPC_FAR *__RPC_FAR *node);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_lastChild(ISimpleDOMNode __RPC_FAR *__RPC_FAR *node);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_previousSibling(ISimpleDOMNode __RPC_FAR *__RPC_FAR *node);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_nextSibling(ISimpleDOMNode __RPC_FAR *__RPC_FAR *node);
protected:
nsCOMPtr<nsIDOMNode> mDOMNode;
ULONG m_cRef; // the reference count
HWND mWnd;
void GetElementAndContentFor(nsCOMPtr<nsIDOMElement>& aElement, nsCOMPtr<nsIContent>& aContent);
};
#endif

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

@ -0,0 +1,8 @@
ISimpleDOMDocument_p.c
dlldata.c
ISimpleDOMDocument_i.c
ISimpleDOMDocument.h
dlldata.pdb
isimpledomDocument_p.pdb
isimpledomDocument_i.pdb

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

@ -0,0 +1,108 @@
/* -*- 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.
*
* Author: Aaron Leventhal (aaronl@netscape.com)
*/
cpp_quote("///////////////////////////////////////////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISimpleDOMDocument.h")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("//")
cpp_quote("// get_URL(out] BSTR *url)")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Get the internet URL associated with this document.")
cpp_quote("//")
cpp_quote("// get_title([out BSTR *title")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Get the document's title from the <TITLE> element")
cpp_quote("//")
cpp_quote("// get_mimeType([out BSTR *mimeType")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Get the registered mime type, such as text/html")
cpp_quote("//")
cpp_quote("// get_docType([out] BSTR *docType")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Get doctype associated with the <!DOCTYPE ..> element")
cpp_quote("//")
cpp_quote("// get_nameSpaceURIForID([in] short nameSpaceID, [out] BSTR *nameSpaceURI)")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Some of the methods for ISimpleDOMNode return a nameSpaceID (-1,0,1,2,3,....)")
cpp_quote("// This method returns the associated namespace URI for each ID.")
cpp_quote("//")
cpp_quote("// set_alternateViewMediaTypes([in] BSTR *commaSeparatedMediaType)")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// For style property retrieval on nsISimpleDOMNode elements, ")
cpp_quote("// set the additional alternate media types that properties are available for.")
cpp_quote("// [in] BSTR *commaSeparatedMediaTypes is a comma separate list, for example \"aural, braille\".")
cpp_quote("// The alternate media properties are requested with nsISimpleDOMNode::get_computedStyle.")
cpp_quote("// Note: setting this value on a document will increase memory overhead, and may create a small delay.")
cpp_quote("//")
cpp_quote("// W3C media Types:")
cpp_quote("// * all: Suitable for all devices. ")
cpp_quote("// * aural: Intended for speech synthesizers. See the section on aural style sheets for details. ")
cpp_quote("// * braille: Intended for braille tactile feedback devices. ")
cpp_quote("// * embossed: Intended for paged braille printers. ")
cpp_quote("// * handheld: Intended for handheld devices - typically small screen, monochrome, limited bandwidth. ")
cpp_quote("// * print: Intended for paged, opaque material and for documents viewed on screen in print preview mode. Please consult the section on paged media for information about formatting issues that are specific to paged media. ")
cpp_quote("// * projection: Intended for projected presentations, for example projectors or print to transparencies. Please consult the section on paged media for information about formatting issues that are specific to paged media. ")
cpp_quote("// * screen: Intended primarily for color computer screens. ")
cpp_quote("// * tty: intended for media using a fixed-pitch character grid, such as teletypes, terminals, or portable devices with limited display capabilities. Authors should not use pixel units with the tty media type. ")
cpp_quote("// * tv: Intended for television-type devices - low resolution, color, limited-scrollability screens, sound")
cpp_quote("// * See latest W3C CSS specs for complete list of media types")
cpp_quote("//")
cpp_quote("//")
cpp_quote("///////////////////////////////////////////////////////////////////////////////////////////////////////")
cpp_quote("")
cpp_quote("")
import "objidl.idl";
import "oaidl.idl";
const long DISPID_DOC_URL = -5904;
const long DISPID_DOC_TITLE = -5905;
const long DISPID_DOC_MIMETYPE = -5906;
const long DISPID_DOC_DOCTYPE = -5907;
const long DISPID_DOC_NAMESPACE = -5908;
const long DISPID_DOC_MEDIATYPES = -5909;
[object, uuid(0D68D6D0-D93D-4d08-A30D-F00DD1F45B24)]
interface ISimpleDOMDocument : IUnknown
{
[propget, id(DISPID_DOC_URL)] HRESULT URL(
[out, retval] BSTR * url
);
[propget, id(DISPID_DOC_TITLE)] HRESULT title(
[out, retval] BSTR * title
);
[propget, id(DISPID_DOC_MIMETYPE)] HRESULT mimeType(
[out, retval] BSTR * mimeType
);
[propget, id(DISPID_DOC_DOCTYPE)] HRESULT docType(
[out, retval] BSTR * docType
);
[propget, id(DISPID_DOC_NAMESPACE)] HRESULT nameSpaceURIForID(
[in] short nameSpaceID,
[out, retval] BSTR * nameSpaceURI
);
[propput, id(DISPID_DOC_MEDIATYPES)] HRESULT alternateViewMediaTypes(
[in] BSTR * commaSeparatedMediaTypes
);
}

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

@ -0,0 +1,72 @@
#!nmake
#
# 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):
# leaf@mozilla.org
DEPTH=..\..\..\..\..
MAKE_OBJ_TYPE = DLL
MODULE = ISimpleDOMDocumentMarshal
DLL = .\$(OBJDIR)\$(MODULE).dll
PROXYSTUBIDL = ISimpleDOMDocument.idl
LCFLAGS =-DWIN$(MOZ_BITS) -DREGISTER_PROXY_DLL -D_WIN$(MOZ_BITS)_WINNT=0x400
DEFFILE = ISimpleDOMDocument.def
OBJS = \
dlldata.obj \
ISimpleDOMDocument_p.obj \
ISimpleDOMDocument_i.obj \
$(NULL)
WIN_LIBS = \
kernel$(MOZ_BITS).lib \
rpcndr.lib \
rpcns4.lib \
rpcrt4.lib \
uuid.lib \
oleaut$(MOZ_BITS).lib \
$(NULL)
MIDL_GENERATED_FILES = \
..\..\ISimpleDOMDocument.h \
..\..\ISimpleDOMDocument_iid.h \
ISimpleDOMDocument_p.c \
ISimpleDOMDocument_i.c \
dlldata.c \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin
regsvr32 /s $(DIST)\bin\$(MODULE).dll
$(MIDL_GENERATED_FILES): ISimpleDOMDocument.idl
midl ISimpleDOMDocument.idl
copy ISimpleDOMDocument.h ..\..
copy ISimpleDOMDocument_i.c ..\..\ISimpleDOMDocument_iid.h
export:: $(MIDL_GENERATED_FILES)
clobber::
rm -rf $(MIDL_GENERATED_FILES)
rm -rf $(DLL)

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

@ -0,0 +1,8 @@
ISimpleDOMNode_p.c
dlldata.c
ISimpleDOMNode_i.c
ISimpleDOMNode.h
dlldata.pdb
isimpledomNode_p.pdb
isimpledomNode_i.pdb

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

@ -0,0 +1,145 @@
/* -*- 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.
*
* Author: Aaron Leventhal (aaronl@netscape.com)
*/
cpp_quote("///////////////////////////////////////////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISimpleDOMNode.h ")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("//")
cpp_quote("// get_nodeInfo(")
cpp_quote("// /* [out] */ BSTR *nodeName, // For elements, this is the tag name")
cpp_quote("// /* [out] */ short *nameSpaceID,")
cpp_quote("// /* [out] */ unsigned short *nodeType,")
cpp_quote("// /* [out] */ BSTR *nodeValue, ")
cpp_quote("// /* [out] */ unsigned int *numChildren); ")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Get the basic information about a node.")
cpp_quote("// The namespace ID can be mapped to an URI using nsISimpleDOMDocument::get_nameSpaceURIForID()")
cpp_quote("//")
cpp_quote("// get_attributes(")
cpp_quote("// /* [in] */ unsigned short maxAttribs,")
cpp_quote("// /* [out] */ unsigned short *numAttribs,")
cpp_quote("// /* [out] */ BSTR *attribNames,")
cpp_quote("// /* [out] */ short *nameSpaceID,")
cpp_quote("// /* [out] */ BSTR *attribValues);")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Returns 3 arrays - the attribute names and values, and a namespace ID for each")
cpp_quote("// If the namespace ID is 0, it's the same namespace as the node's namespace")
cpp_quote("//")
cpp_quote("// computedStyle( ")
cpp_quote("// /* [in] */ unsigned short maxStyleProperties,")
cpp_quote("// /* [out] */ unsigned short *numStyleProperties, ")
cpp_quote("// /* [in] */ boolean useAlternateView, // If TRUE, returns properites for media as set in nsIDOMDocument::set_alternateViewMediaTypes")
cpp_quote("// /* [out] */ BSTR *styleProperties, ")
cpp_quote("// /* [out] */ BSTR *styleValues);")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Returns 2 arrays -- the style properties and their values")
cpp_quote("// useAlternateView=FALSE: gets properties for the default media type (usually screen)")
cpp_quote("// useAlternateView=TRUE: properties for media types set w/ nsIDOMSimpleDocument::set_alternateViewMediaTypes()")
cpp_quote("//")
cpp_quote("// computedStyleForProperties( ")
cpp_quote("// /* [in] */ unsigned short numStyleProperties, ")
cpp_quote("// /* [in] */ boolean useAlternateView, // If TRUE, returns properites for media as set in nsIDOMDocument::set_alternateViewMediaTypes")
cpp_quote("// /* [in] */ BSTR *styleProperties, ")
cpp_quote("// /* [out] */ BSTR *styleValues);")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// Returns style property values for those properties in the styleProperties [in] array")
cpp_quote("// Returns 2 arrays -- the style properties and their values")
cpp_quote("// useAlternateView=FALSE: gets properties for the default media type (usually screen)")
cpp_quote("// useAlternateView=TRUE: properties for media types set w/ nsIDOMSimpleDocument::set_alternateViewMediaTypes()")
cpp_quote("//")
cpp_quote("// get_parentNode (/* [in] */ ISimpleDOMNode *newNodePtr);")
cpp_quote("// get_firstChild (/* [in] */ ISimpleDOMNode *newNodePtr);")
cpp_quote("// get_lastChild (/* [in] */ ISimpleDOMNode *newNodePtr);")
cpp_quote("// get_previousSibling(/* [in] */ ISimpleDOMNode *newNodePtr);")
cpp_quote("// get_nextSibling (/* [in] */ ISimpleDOMNode *newNodePtr);")
cpp_quote("// ---------------------------------------------------------------------------------------------------=")
cpp_quote("// DOM navigation - get a different node.")
cpp_quote("//")
cpp_quote("//")
cpp_quote("///////////////////////////////////////////////////////////////////////////////////////////////////////")
cpp_quote("")
cpp_quote("")
import "objidl.idl";
import "oaidl.idl";
const long DISPID_NODE_NODEINFO = -5900;
const long DISPID_NODE_ATTRIBUTES = -5901;
const long DISPID_NODE_COMPSTYLE = -5902;
const long DISPID_NODE_COMPSTYLEFORPROPS = -5903;
[object, uuid(96917748-8922-4fd9-8a73-d72e8aad671a)]
interface ISimpleDOMNode : IUnknown
{
const unsigned short NODETYPE_ELEMENT = 1;
const unsigned short NODETYPE_ATTRIBUTE = 2;
const unsigned short NODETYPE_TEXT = 3;
const unsigned short NODETYPE_CDATA_SECTION = 4;
const unsigned short NODETYPE_ENTITY_REFERENCE = 5;
const unsigned short NODETYPE_ENTITY = 6;
const unsigned short NODETYPE_PROCESSING_INSTRUCTION = 7;
const unsigned short NODETYPE_COMMENT = 8;
const unsigned short NODETYPE_DOCUMENT = 9;
const unsigned short NODETYPE_DOCUMENT_TYPE = 10;
const unsigned short NODETYPE_DOCUMENT_FRAGMENT = 11;
const unsigned short NODETYPE_NOTATION = 12;
[propget, id(DISPID_NODE_NODEINFO)] HRESULT nodeInfo(
[out] BSTR *nodeName, // for performance returns NULL for text nodes (true nodeName would be "#text")
[out] short *nameSpaceID,
[out] BSTR *nodeValue,
[out] unsigned int *numChildren,
[out, retval] unsigned short *nodeType
);
[propget, id(DISPID_NODE_ATTRIBUTES)] HRESULT attributes(
[in] unsigned short maxAttribs,
[out, size_is(maxAttribs), length_is(*numAttribs)] BSTR *attribNames,
[out, size_is(maxAttribs), length_is(*numAttribs)] short *nameSpaceID,
[out, size_is(maxAttribs), length_is(*numAttribs)] BSTR *attribValues,
[out, retval] unsigned short *numAttribs
);
[propget, id(DISPID_NODE_COMPSTYLE)] HRESULT computedStyle(
[in] unsigned short maxStyleProperties,
[in] boolean useAlternateView, // If TRUE, returns properites for media as set in nsIDOMDocument::set_alternateViewMediaTypes
[out, size_is(maxStyleProperties), length_is(*numStyleProperties)] BSTR *styleProperties,
[out, size_is(maxStyleProperties), length_is(*numStyleProperties)] BSTR *styleValues,
[out, retval] unsigned short *numStyleProperties
);
[propget, id(DISPID_NODE_COMPSTYLEFORPROPS)] HRESULT computedStyleForProperties(
[in] unsigned short numStyleProperties,
[in] boolean useAlternateView, // If TRUE, returns properites for media as set in nsIDOMDocument::set_alternateViewMediaTypes
[in, size_is(numStyleProperties), length_is(numStyleProperties)] BSTR *styleProperties,
[out, retval, size_is(numStyleProperties), length_is(numStyleProperties)] BSTR *styleValues
);
[propget] HRESULT parentNode([out, retval] ISimpleDOMNode **node);
[propget] HRESULT firstChild([out, retval] ISimpleDOMNode **node);
[propget] HRESULT lastChild([out, retval] ISimpleDOMNode **node);
[propget] HRESULT previousSibling([out, retval] ISimpleDOMNode **node);
[propget] HRESULT nextSibling([out, retval] ISimpleDOMNode **node);
}

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

@ -0,0 +1,72 @@
#!nmake
#
# 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):
# leaf@mozilla.org
DEPTH=..\..\..\..\..
MAKE_OBJ_TYPE = DLL
MODULE = ISimpleDOMNodeMarshal
DLL = .\$(OBJDIR)\$(MODULE).dll
PROXYSTUBIDL = ISimpleDOMNode.idl
LCFLAGS =-DWIN$(MOZ_BITS) -DREGISTER_PROXY_DLL -D_WIN$(MOZ_BITS)_WINNT=0x400
DEFFILE = ISimpleDOMNode.def
OBJS = \
dlldata.obj \
ISimpleDOMNode_p.obj \
ISimpleDOMNode_i.obj \
$(NULL)
WIN_LIBS = \
kernel$(MOZ_BITS).lib \
rpcndr.lib \
rpcns4.lib \
rpcrt4.lib \
uuid.lib \
oleaut$(MOZ_BITS).lib \
$(NULL)
MIDL_GENERATED_FILES = \
..\..\ISimpleDOMNode.h \
..\..\ISimpleDOMNode_iid.h \
ISimpleDOMNode_p.c \
ISimpleDOMNode_i.c \
dlldata.c \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin
regsvr32 /s $(DIST)\bin\$(MODULE).dll
$(MIDL_GENERATED_FILES): ISimpleDOMNode.idl
midl ISimpleDOMNode.idl
copy ISimpleDOMNode.h ..\..
copy ISimpleDOMNode_i.c ..\..\ISimpleDOMNode_iid.h
export:: $(MIDL_GENERATED_FILES)
clobber::
rm -rf $(MIDL_GENERATED_FILES)
rm -rf $(DLL)

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

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

@ -22,11 +22,13 @@
DEPTH=..\..\..
#
LIBRARY_NAME = raptorwidget_s
DEFINES =-D_IMPL_NS_WIDGET -DMOZ_AIMM
CPPSRCS = \
Accessible.cpp \
SimpleDOMNode.cpp \
nsFontRetrieverService.cpp \
nsFontSizeIterator.cpp \
nsNativeDragTarget.cpp \
@ -47,11 +49,12 @@ CPPSRCS = \
nsImageClipboard.cpp \
nsBidiKeyboard.cpp \
$(NULL)
MODULE=raptor
OBJS = \
.\$(OBJDIR)\Accessible.obj \
.\$(OBJDIR)\SimpleDOMNode.obj \
.\$(OBJDIR)\nsFontRetrieverService.obj \
.\$(OBJDIR)\nsFontSizeIterator.obj \
.\$(OBJDIR)\nsNativeDragTarget.obj \
@ -90,12 +93,11 @@ LCFLAGS = \
WIN_LIBS= \
ole32.lib
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
rm -f $(PDBFILE).pdb

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

@ -3566,28 +3566,31 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
case WM_GETOBJECT:
{
if (lParam == OBJID_CLIENT) {
nsCOMPtr<nsIAccessible> acc;
DispatchAccessibleEvent(NS_GETACCESSIBLE, getter_AddRefs(acc));
// create the COM accessible object
if (acc)
{
HWND wnd = GetWindowHandle();
if (!mRootAccessible) {
if (!mRootAccessible) {
nsCOMPtr<nsIAccessible> acc;
DispatchAccessibleEvent(NS_GETACCESSIBLE, getter_AddRefs(acc));
// create the COM accessible object
if (acc)
{
HWND wnd = GetWindowHandle();
mRootAccessible = new RootAccessible(acc, wnd); // ref is 0
mRootAccessible->AddRef();
CoInitialize(NULL);
}
}
if (mRootAccessible) {
// ask accessible to do this do it loads the library dynamically
LRESULT lAcc = Accessible::LresultFromObject(IID_IAccessible, wParam, mRootAccessible); // ref 1
if (lAcc == 0) {
*aRetValue = NULL;
return PR_FALSE;
}
*aRetValue = lAcc;
return PR_TRUE; // yes we handled it.
}
}
*aRetValue = NULL;
return PR_FALSE;
}
break;

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

@ -1318,6 +1318,13 @@ function URLBarBlurHandler(aEvent)
gURLBar.setSelectionRange(0, 0);
}
function URLBarKeyupHandler(aEvent)
{
if (aEvent.keyCode == aEvent.DOM_VK_TAB ) {
ShowAndSelectContentsOfURLBar();
}
}
// This function gets the "windows hooks" service and has it check its setting
// This will do nothing on platforms other than Windows.
function checkForDefaultBrowser()

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

@ -165,6 +165,7 @@ Contributor(s): ______________________________________. -->
ontextcommand="return handleURLBarCommand(userAction);"
ontextrevert="return handleURLBarRevert();"
onmouseup="URLBarMouseupHandler(event);"
onkeyup="URLBarKeyupHandler(event);"
onblur="URLBarBlurHandler(event);">
<image id="page-proxy-button" allowevents="true"
ondraggesture="PageProxyDragGesture(event);"/>

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

@ -8,54 +8,6 @@
<resources>
<stylesheet src="chrome://global/skin/button.css"/>
</resources>
<implementation implements="nsIAccessible">
<method name="getAccDefaultAction">
<body><![CDATA[
return 'Click';
]]></body>
</method>
<method name="getAccDescription">
<body><![CDATA[
return 'This is a button that can be clicked to perform an action';
]]></body>
</method>
<method name="getAccValue">
<body><![CDATA[
return this.getAttribute('value');
]]></body>
</method>
<method name="getAccName">
<body><![CDATA[
return 'Left Button';
]]></body>
</method>
<method name="getAccRole">
<body><![CDATA[
return 'push button';
]]></body>
</method>
<method name="accDoDefaultAction">
<body><![CDATA[
this.click();
]]></body>
</method>
<method name="getAccChildCount">
<body><![CDATA[
return 0;
]]></body>
</method>
<method name="getAccFirstChild">
<body><![CDATA[
return null;
]]></body>
</method>
<method name="getAccLastChild">
<body><![CDATA[
return null;
]]></body>
</method>
</implementation>
</binding>
<binding id="buttonleft" extends="chrome://global/content/bindings/button.xml#button-base">

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

@ -15,7 +15,7 @@
<xul:scrollbarbutton sbattr="scrollbar-down-bottom" type="increment" inherits="sborient=align"/>
</content>
<implementation implements="nsIAccessible">
<implementation>
<constructor>
this.initScrollbar();
</constructor>
@ -78,27 +78,6 @@
]]>
</body>
</method>
<method name="getAccDescription">
<body><![CDATA[
return 'This is a scrollbar';
]]></body>
</method>
<method name="getAccValue">
<body><![CDATA[
return this.getAttribute('curpos');
]]></body>
</method>
<method name="getAccName">
<body><![CDATA[
return 'Scroll Bar';
]]></body>
</method>
<method name="getAccRole">
<body><![CDATA[
return 'scrollbar';
]]></body>
</method>
</implementation>
<handlers>
<handler event="contextmenu" action="event.preventDefault();"/>
@ -117,44 +96,6 @@
<xul:image inherits="src"/>
<xul:spring flex="1"/>
</content>
<implementation implements="nsIAccessible">
<method name="getAccDescription">
<body><![CDATA[
return 'This is a scrollbars thumb';
]]></body>
</method>
<method name="getAccValue">
<body><![CDATA[
return this.getAttribute('curpos');
]]></body>
</method>
<method name="getAccName">
<body><![CDATA[
return 'Thumb';
]]></body>
</method>
<method name="getAccRole">
<body><![CDATA[
return 'indicator';
]]></body>
</method>
<method name="getAccChildCount">
<body><![CDATA[
return 0;
]]></body>
</method>
<method name="getAccFirstChild">
<body><![CDATA[
return null;
]]></body>
</method>
<method name="getAccLastChild">
<body><![CDATA[
return null;
]]></body>
</method>
</implementation>
</binding>
<binding id="scrollbarbutton">
@ -163,51 +104,6 @@
<xul:image class="scrollbarbutton-icon" inherits="src"/>
</xul:box>
</content>
<implementation implements="nsIAccessible">
<method name="getAccDefaultAction">
<body><![CDATA[
return 'Click';
]]></body>
</method>
<method name="getAccDescription">
<body><![CDATA[
return 'Adjusts scrollbar';
]]></body>
</method>
<method name="getAccName">
<body><![CDATA[
return 'scrollbar button';
]]></body>
</method>
<method name="getAccRole">
<body><![CDATA[
return 'push button';
]]></body>
</method>
<method name="accDoDefaultAction">
<body><![CDATA[
this.click();
dump("We just clicked!!!\n");
]]></body>
</method>
<method name="getAccChildCount">
<body><![CDATA[
return 0;
]]></body>
</method>
<method name="getAccFirstChild">
<body><![CDATA[
return null;
]]></body>
</method>
<method name="getAccLastChild">
<body><![CDATA[
return null;
]]></body>
</method>
</implementation>
</binding>
</bindings>

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше