From b28fc76be2e677a04c1fb4507faa999e61b08c0f Mon Sep 17 00:00:00 2001 From: "evaughan%netscape.com" Date: Tue, 17 Apr 2001 23:06:38 +0000 Subject: [PATCH] Accessibility work. bug #12952 -r aaronl -sr brendan git-svn-id: svn://10.0.0.236/trunk@92582 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/accessible/build/makefile.win | 4 - mozilla/accessible/macbuild/accessible.mcp | Bin 145036 -> 145036 bytes mozilla/accessible/macbuild/accessibleIDL.mcp | Bin 71370 -> 71370 bytes mozilla/accessible/public/Makefile.in | 2 + mozilla/accessible/public/makefile.win | 2 + .../public/nsIAccessibilityService.idl | 6 +- .../public/nsIAccessibleEventListener.idl | 34 ++ .../public/nsIAccessibleEventReceiver.idl | 32 ++ mozilla/accessible/src/Makefile.in | 3 + .../src/base/nsAccessibilityService.cpp | 129 ++++++- .../src/base/nsAccessibilityService.h | 6 + mozilla/accessible/src/base/nsAccessible.cpp | 65 +++- .../src/base/nsGenericAccessible.cpp | 335 ++++++++++++++++++ .../accessible/src/base/nsGenericAccessible.h | 84 +++++ .../accessible/src/base/nsRootAccessible.cpp | 123 ++++++- .../accessible/src/base/nsRootAccessible.h | 35 +- .../src/base/nsSelectAccessible.cpp | 28 +- .../src/html/nsHTMLFormControlAccessible.cpp | 172 +++++++++ .../src/html/nsHTMLFormControlAccessible.h | 77 ++++ .../src/html/nsHTMLTextAccessible.cpp | 51 +++ .../src/html/nsHTMLTextAccessible.h | 43 +++ mozilla/accessible/src/makefile.win | 5 + .../accessible/src/nsAccessibilityService.cpp | 129 ++++++- .../accessible/src/nsAccessibilityService.h | 6 + mozilla/accessible/src/nsAccessible.cpp | 65 +++- .../accessible/src/nsGenericAccessible.cpp | 335 ++++++++++++++++++ mozilla/accessible/src/nsGenericAccessible.h | 84 +++++ .../src/nsHTMLFormControlAccessible.cpp | 172 +++++++++ .../src/nsHTMLFormControlAccessible.h | 77 ++++ .../accessible/src/nsHTMLTextAccessible.cpp | 51 +++ mozilla/accessible/src/nsHTMLTextAccessible.h | 43 +++ .../accessible/src/nsMutableAccessible.cpp | 6 +- mozilla/accessible/src/nsRootAccessible.cpp | 123 ++++++- mozilla/accessible/src/nsRootAccessible.h | 35 +- mozilla/accessible/src/nsSelectAccessible.cpp | 28 +- .../layout/forms/nsGfxButtonControlFrame.cpp | 9 +- .../forms/nsGfxCheckboxControlFrame.cpp | 8 +- .../layout/forms/nsGfxCheckboxControlFrame.h | 9 +- .../layout/forms/nsGfxRadioControlFrame.cpp | 9 +- mozilla/layout/generic/nsFrame.cpp | 2 +- mozilla/layout/generic/nsTextFrame.cpp | 9 +- mozilla/layout/html/base/src/nsFrame.cpp | 2 +- mozilla/layout/html/base/src/nsTextFrame.cpp | 9 +- .../forms/src/nsGfxButtonControlFrame.cpp | 9 +- .../forms/src/nsGfxCheckboxControlFrame.cpp | 8 +- .../forms/src/nsGfxCheckboxControlFrame.h | 9 +- .../html/forms/src/nsGfxRadioControlFrame.cpp | 9 +- mozilla/widget/src/windows/Accessible.cpp | 168 ++++++++- mozilla/widget/src/windows/Accessible.h | 51 ++- mozilla/widget/src/windows/nsWindow.cpp | 14 +- mozilla/widget/src/windows/nsWindow.h | 6 + 51 files changed, 2542 insertions(+), 179 deletions(-) create mode 100644 mozilla/accessible/public/nsIAccessibleEventListener.idl create mode 100644 mozilla/accessible/public/nsIAccessibleEventReceiver.idl create mode 100644 mozilla/accessible/src/base/nsGenericAccessible.cpp create mode 100644 mozilla/accessible/src/base/nsGenericAccessible.h create mode 100644 mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp create mode 100644 mozilla/accessible/src/html/nsHTMLFormControlAccessible.h create mode 100644 mozilla/accessible/src/html/nsHTMLTextAccessible.cpp create mode 100644 mozilla/accessible/src/html/nsHTMLTextAccessible.h create mode 100644 mozilla/accessible/src/nsGenericAccessible.cpp create mode 100644 mozilla/accessible/src/nsGenericAccessible.h create mode 100644 mozilla/accessible/src/nsHTMLFormControlAccessible.cpp create mode 100644 mozilla/accessible/src/nsHTMLFormControlAccessible.h create mode 100644 mozilla/accessible/src/nsHTMLTextAccessible.cpp create mode 100644 mozilla/accessible/src/nsHTMLTextAccessible.h diff --git a/mozilla/accessible/build/makefile.win b/mozilla/accessible/build/makefile.win index 2bbbf58d922..4f5b867926b 100644 --- a/mozilla/accessible/build/makefile.win +++ b/mozilla/accessible/build/makefile.win @@ -32,10 +32,6 @@ CPP_OBJS=\ LINCS = $(LINCS) -I..\src # for implementation headers -# XXX linking in raptor is a heinous crime that will go away once we -# have a more DOM-based mechanism for constructing elements and -# hooking in to their changes. - LLIBS=\ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\accessibility_s.lib \ diff --git a/mozilla/accessible/macbuild/accessible.mcp b/mozilla/accessible/macbuild/accessible.mcp index c953571a5fe58cf5b03ff1d81b8646dbddb94c79..4c5e2d66e8df456c73c942bbe335844be97202e5 100644 GIT binary patch delta 594 zcmeBq%hB_eV}mg>=QaighV4MSW3vIXIHT@PAoBnN1CJF0g8-1pu#>@&L8PIcfy1JK zfze_C17l+|NSJ|%fssLGqNDWY*({=ryuv^c1r8tq#KD{QvOb0iaRP;aICS$`b}KD8 z?w3F=$Sxq@VFVI8z)S`nMIgO%qGR;r1S3B7-%Zi~|1W&MxztFO705CA|9^49=0=C# zjFYEWia`Xv-vSE!WZd2$t>`IOyd0Un^mfj}Gta=_%d{ti4qYlDF}1Z@3Re`!@u zZZ}UKSD?H%l=gwrzEIi^O8Z0U04N;@rGub!@MO!1vj%~@4Q2&{JPl$^=hI=F zJN>pMqsI2tI*bmC+pipBG-jIoWkvuiNDWZm3}x03h&~`I6ryj2^5#7=*_b8rX6emc>S&a delta 417 zcmeBq%hB_eV}mjCW_xB4#)$zuy4x5S7!EKnaKB_=5CAe6wlR3R#K#+2<`sMTCFZ6E z7bGU9`U1t77#JC3COS%Qp3Nf4$O}@czyTzHIAHT$*2hpGPM{DF2W?)fDb z5g+?UzTW@;ck4~QI8%6YhY=Sm`$yiR|NmdOy}8lhH{;|fmSPZr-#tKqpN!iZdys5xxEqR+I04FF8lgE9aB diff --git a/mozilla/accessible/macbuild/accessibleIDL.mcp b/mozilla/accessible/macbuild/accessibleIDL.mcp index a9c386343375d90240995e714dec59e2356bbd25..6799e1dae749c0c2d254688bdd4fb10ac7226979 100644 GIT binary patch delta 564 zcmZXQKS;ws6vlIDPOD9JtL0fQCv1SO=T5Ku)=`8A?)I&Py z;-DZx;RdNo9YoMc7Y7G%bQ2UDbf{k?MZpKZ`@X!py!Y;I&!pQksr2FW&`m)QVgNyp zvBV4EBX-)fLZ|Q%<7%^m^iWupU;zdg02AW67DKFv=5aNfjNA$uCfdCi=K@ehBE&GjMYmsX8 zB*o|4eo?0rk?1)357?^Ns@v+f)!;o!6Ddq8{KivhU=?kh`q3`NUbQ}I)JCm2zO9c) ztlB~OPItL+ER~6b6A3euvF4NJc+N~^qgEzsrp)DlwU8A4Z^z7pY30mi7W`ECv#(cV zX}837yV^1IAnx+W?|ol{9sBHrv4upH{Jut%Uk*jWG-!{eI%~JKr&Ia#(#C<t&o7IRn9jQ^575$--|PCq`h0- U!NGbVbgf5A3C?@I*G5L^H)8CJX#fBK delta 471 zcmX@LmgUr1mJQ!HCc1B(yqdFOu{Iau!~hP(Kn4be1O^7y4h9AeAd>;a*Jfe_F&P*c z88{gx`*6prG6Q)EAVDD31Y&g{)&Q}Y7#MVcSPzKxCtu*!oEX41`9cNDJuNZzlUpEftxwJ}cakgR4^1)A+X zd4i-es~V8yz1cu2l4bJ&T~9|=ZK#X_2heFcAW5Jyh0S64ZF8A4_D{dZ!zj-9WBNB9 zMt#E-Kv{v@l7dVi4Gbd~;NAgb@#L1| diff --git a/mozilla/accessible/public/nsIAccessibilityService.idl b/mozilla/accessible/public/nsIAccessibilityService.idl index 66f87beb5b2..ccdca117c3d 100644 --- a/mozilla/accessible/public/nsIAccessibilityService.idl +++ b/mozilla/accessible/public/nsIAccessibilityService.idl @@ -31,9 +31,13 @@ interface nsIAccessibilityService : nsISupports { nsIAccessible createRootAccessible(in nsISupports aPresShell, in nsISupports aFrame); + nsIMutableAccessible createMutableAccessible(in nsISupports aNode); nsIAccessible createHTMLBlockAccessible(in nsIAccessible aAccessible, in nsIDOMNode aNode, in nsISupports aPresShell); nsIAccessible createHTMLSelectAccessible(in nsIAtom aAccessible, in nsIDOMNode aNode, in nsISupports aPresShell); - nsIMutableAccessible createMutableAccessible(in nsISupports aNode); + nsIAccessible createHTMLCheckboxAccessible(in nsISupports aFrame); + nsIAccessible createHTMLRadioButtonAccessible(in nsISupports aFrame); + nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame); + nsIAccessible createHTMLTextAccessible(in nsISupports aFrame); }; diff --git a/mozilla/accessible/public/nsIAccessibleEventListener.idl b/mozilla/accessible/public/nsIAccessibleEventListener.idl new file mode 100644 index 00000000000..24a00c20378 --- /dev/null +++ b/mozilla/accessible/public/nsIAccessibleEventListener.idl @@ -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: Eric D Vaughan (evaughan@netscape.com) + * + * Contributor(s): + */ + +#include "nsISupports.idl" +#include "nsIAccessible.idl" + +[scriptable, uuid(BEE49E7D-9D06-49bf-8984-1694C697D74F)] +interface nsIAccessibleEventListener : nsISupports +{ + const unsigned long EVENT_FOCUS = 0x8005; + + void handleEvent(in unsigned long aEvent, in nsIAccessible aTarget); +}; diff --git a/mozilla/accessible/public/nsIAccessibleEventReceiver.idl b/mozilla/accessible/public/nsIAccessibleEventReceiver.idl new file mode 100644 index 00000000000..252a1f6638a --- /dev/null +++ b/mozilla/accessible/public/nsIAccessibleEventReceiver.idl @@ -0,0 +1,32 @@ +/* -*- 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: Eric D Vaughan (evaughan@netscape.com) + * + * Contributor(s): + */ + +#include "nsIAccessibleEventListener.idl" + +[scriptable, uuid(AB331E47-4FAA-4a12-9480-9B480DD78B39)] +interface nsIAccessibleEventReceiver : nsISupports +{ + void addAccessibleEventListener(in nsIAccessibleEventListener aListener); + void removeAccessibleEventListener(in nsIAccessibleEventListener aListener); +}; diff --git a/mozilla/accessible/src/Makefile.in b/mozilla/accessible/src/Makefile.in index 7f2acdffb4b..ed47e2026cc 100644 --- a/mozilla/accessible/src/Makefile.in +++ b/mozilla/accessible/src/Makefile.in @@ -35,7 +35,10 @@ CPPSRCS = \ nsAccessibilityService.cpp \ nsMutableAccessible.cpp \ nsRootAccessible.cpp \ + nsHTMLFormControlAccessible.cpp \ + nsHTMLTextAccessible.cpp \ nsSelectAccessible.cpp \ + nsGenericAccessible.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a static lib. diff --git a/mozilla/accessible/src/base/nsAccessibilityService.cpp b/mozilla/accessible/src/base/nsAccessibilityService.cpp index 3ae83fa0b2b..b4bf50278a3 100644 --- a/mozilla/accessible/src/base/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/base/nsAccessibilityService.cpp @@ -34,8 +34,10 @@ #include "nsRootAccessible.h" #include "nsINameSpaceManager.h" #include "nsMutableAccessible.h" +#include "nsHTMLFormControlAccessible.h" #include "nsLayoutAtoms.h" #include "nsSelectAccessible.h" +#include "nsHTMLTextAccessible.h" //-------------------- @@ -60,7 +62,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsAccessibilityService, nsIAccessibilityService); NS_IMETHODIMP nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISupports* aFrame, nsIAccessible **_retval) { - nsIFrame* f = (nsIFrame*)aFrame; + nsIFrame* f = NS_STATIC_CAST(nsIFrame*, aFrame); nsCOMPtr c = do_QueryInterface(aPresContext); NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!"); @@ -73,17 +75,22 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); *_retval = new nsRootAccessible(wr,f); - NS_ADDREF(*_retval); - - return NS_OK; + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsAccessibilityService::CreateMutableAccessible(nsISupports* aNode, nsIMutableAccessible **_retval) { *_retval = new nsMutableAccessible(aNode); - NS_ADDREF(*_retval); - return NS_OK; + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP @@ -103,9 +110,11 @@ nsAccessibilityService::CreateHTMLBlockAccessible(nsIAccessible* aAccessible, ns nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); *_retval = new nsHTMLBlockAccessible(aAccessible, n,wr); - NS_ADDREF(*_retval); - - return NS_OK; + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP @@ -123,11 +132,107 @@ nsAccessibilityService::CreateHTMLSelectAccessible(nsIAtom* aPopupAtom, nsIDOMNo nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); *_retval = new nsSelectAccessible(aPopupAtom, nsnull, n, wr); - NS_ADDREF(*_retval); - return NS_OK; - + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + 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 node; + nsCOMPtr shell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + + *_retval = new nsHTMLCheckboxAccessible(shell,node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +/* nsIAccessible createHTMLCheckboxAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ +NS_IMETHODIMP nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr shell; + GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + + *_retval = new nsHTMLRadioButtonAccessible(shell,node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +/* nsIAccessible createHTMLCheckboxAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ +NS_IMETHODIMP nsAccessibilityService::CreateHTMLButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr shell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + + *_retval = new nsHTMLButtonAccessible(shell,node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +/* nsIAccessible createHTMLTextAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ +NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextAccessible(nsISupports *aFrame, nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr shell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + + *_retval = new nsHTMLTextAccessible(shell, node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aNode) +{ + *aRealFrame = NS_STATIC_CAST(nsIFrame*, aFrame); + nsCOMPtr content; + (*aRealFrame)->GetContent(getter_AddRefs(content)); + nsCOMPtr node = do_QueryInterface(content); + *aNode = node; + NS_ADDREF(*aNode); + + nsCOMPtr document; + content->GetDocument(*getter_AddRefs(document)); + +#ifdef DEBUG + PRInt32 shells = document->GetNumberOfShells(); + NS_ASSERTION(shells > 0,"Error no shells!"); +#endif + + *aShell = document->GetShellAt(0); + NS_IF_ADDREF(*aShell); + + return NS_OK; +} + + ////////////////////////////////////////////////////////////////////// nsresult diff --git a/mozilla/accessible/src/base/nsAccessibilityService.h b/mozilla/accessible/src/base/nsAccessibilityService.h index c8267cf6566..6f1848a75d8 100644 --- a/mozilla/accessible/src/base/nsAccessibilityService.h +++ b/mozilla/accessible/src/base/nsAccessibilityService.h @@ -27,6 +27,9 @@ #define __nsAccessibilityService_h__ #include "nsIAccessibilityService.h" +class nsIFrame; +class nsIPresShell; +class nsIDOMNode; class nsAccessibilityService : public nsIAccessibilityService { @@ -42,6 +45,9 @@ public: public: +private: + NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aContent); + }; #endif /* __nsIccessibilityService_h__ */ diff --git a/mozilla/accessible/src/base/nsAccessible.cpp b/mozilla/accessible/src/base/nsAccessible.cpp index 48e473c02e9..e09a989f563 100644 --- a/mozilla/accessible/src/base/nsAccessible.cpp +++ b/mozilla/accessible/src/base/nsAccessible.cpp @@ -287,8 +287,8 @@ void nsFrameTreeWalker::GetAccessible(nsIFrame* aFrame, nsCOMPtr& if (!aAccessible) aAccessible = do_QueryInterface(aContent); - // if (aAccessible) - // printf("Found accessible!\n"); + if (aAccessible) + printf("Found accessible!\n"); } PRBool nsFrameTreeWalker::IsSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2) @@ -700,21 +700,70 @@ NS_IMETHODIMP nsAccessible::AccNavigateUp(nsIAccessible **_retval) { return NS_O NS_IMETHODIMP nsAccessible::AccNavigateDown(nsIAccessible **_retval) { return NS_OK; } - /* void addSelection (); */ -NS_IMETHODIMP nsAccessible::AccAddSelection(void) { return NS_OK; } +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) { return NS_OK; } +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) { return NS_OK; } +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) { return NS_OK; } +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) { return NS_OK; } +NS_IMETHODIMP nsAccessible::AccTakeFocus(void) +{ + // delegate + if (mAccessible) { + nsresult rv = mAccessible->AccTakeFocus(); + if (NS_SUCCEEDED(rv)) + return rv; + } + + return NS_ERROR_FAILURE; +} /* void doDefaultAction (); */ NS_IMETHODIMP nsAccessible::AccDoDefaultAction(void) diff --git a/mozilla/accessible/src/base/nsGenericAccessible.cpp b/mozilla/accessible/src/base/nsGenericAccessible.cpp new file mode 100644 index 00000000000..a1d778870d5 --- /dev/null +++ b/mozilla/accessible/src/base/nsGenericAccessible.cpp @@ -0,0 +1,335 @@ +/* -*- 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: Eric Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#include "nsGenericAccessible.h" +#include "nsIEventStateManager.h" +#include "nsIFrame.h" +#include "nsCOMPtr.h" +#include "nsIWeakReference.h" + +/* Implementation file */ +NS_IMPL_ISUPPORTS1(nsGenericAccessible, nsIAccessible) + +nsGenericAccessible::nsGenericAccessible() +{ + NS_INIT_ISUPPORTS(); + /* member initializers and constructor code */ +} + +nsGenericAccessible::~nsGenericAccessible() +{ + /* destructor code */ +} + +/* nsIAccessible getAccParent (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccParent(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccNextSibling (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccNextSibling(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccPreviousSibling (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccPreviousSibling(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccFirstChild (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccFirstChild(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccLastChild (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccLastChild(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* long getAccChildCount (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccChildCount(PRInt32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccName(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccValue (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccValue(PRUnichar **_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) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccDescription (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccDescription(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccRole(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccState (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccState(PRUint32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccHelp (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccHelp(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* boolean getAccFocused (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccFocused(PRBool *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accGetAt (in long x, in long y); */ +NS_IMETHODIMP nsGenericAccessible::AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateRight (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateRight(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateLeft (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateLeft(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateUp (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateUp(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateDown (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateDown(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accGetBounds (out long x, out long y, out long width, out long height); */ +NS_IMETHODIMP nsGenericAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accAddSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccAddSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accRemoveSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccRemoveSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accExtendSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccExtendSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accTakeSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccTakeSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accTakeFocus (); */ +NS_IMETHODIMP nsGenericAccessible::AccTakeFocus() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accDoDefaultAction (); */ +NS_IMETHODIMP nsGenericAccessible::AccDoDefaultAction() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* unsigned long getAccExtState (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccExtState(PRUint32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +//------------- +// nsDOMAccessible +//------------- + +nsDOMAccessible::nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode) +{ + mPresShell = getter_AddRefs(NS_GetWeakReference(aShell)); + mNode = aNode; +} + + +/* void accRemoveSelection (); */ +NS_IMETHODIMP nsDOMAccessible::AccRemoveSelection() +{ + nsCOMPtr control = do_QueryReferent(mPresShell); + nsCOMPtr selection; + nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr 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 control = do_QueryReferent(mPresShell); + nsCOMPtr selection; + nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr parent; + rv = mNode->GetParentNode(getter_AddRefs(parent)); + if (NS_FAILED(rv)) + return rv; + + PRInt32 offsetInParent = 0; + nsCOMPtr child; + rv = parent->GetFirstChild(getter_AddRefs(child)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr 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 shell = do_QueryReferent(mPresShell); + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context)); + nsCOMPtr content = do_QueryInterface(mNode); + content->SetFocus(context); + + 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; +} + diff --git a/mozilla/accessible/src/base/nsGenericAccessible.h b/mozilla/accessible/src/base/nsGenericAccessible.h new file mode 100644 index 00000000000..ac247f4860a --- /dev/null +++ b/mozilla/accessible/src/base/nsGenericAccessible.h @@ -0,0 +1,84 @@ +/* -*- 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: Eric D Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#ifndef _nsGenericAccessible_H_ +#define _nsGenericAccessible_H_ + +#include "nsISupports.h" +#include "nsIAccessible.h" +#include "nsIContent.h" +#include "nsIDOMNode.h" +#include "nsIPresShell.h" +#include "nsIPresContext.h" +#include "nsCOMPtr.h" + +class nsIWeakReference; + +/** + * Basic implementation + * supports nothing + */ +class nsGenericAccessible : public nsIAccessible +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIACCESSIBLE + + public: + nsGenericAccessible(); + virtual ~nsGenericAccessible(); +}; + +/** + * And accessible that observes a dom node + * supports: + * - selection + * - focus + */ +class nsDOMAccessible : public nsGenericAccessible +{ + public: + nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + + NS_IMETHOD AccTakeSelection(void); + NS_IMETHOD AccTakeFocus(void); + NS_IMETHOD AccRemoveSelection(void); + + protected: + nsIWeakReference* mPresShell; + nsCOMPtr 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); +}; + +#endif diff --git a/mozilla/accessible/src/base/nsRootAccessible.cpp b/mozilla/accessible/src/base/nsRootAccessible.cpp index 0b4776c2409..5589421dc09 100644 --- a/mozilla/accessible/src/base/nsRootAccessible.cpp +++ b/mozilla/accessible/src/base/nsRootAccessible.cpp @@ -27,6 +27,18 @@ #include "nsIPresContext.h" #include "nsIContent.h" #include "nsIFrame.h" +#include "nsIDOMEventTarget.h" +#include "nsIDOMElement.h" +#include "nsIDOMEventReceiver.h" +#include "nsReadableUtils.h" + +NS_INTERFACE_MAP_BEGIN(nsRootAccessible) + NS_INTERFACE_MAP_ENTRY(nsIAccessibleEventReceiver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAccessibleEventReceiver) +NS_INTERFACE_MAP_END_INHERITING(nsAccessible) + +NS_IMPL_ADDREF_INHERITED(nsRootAccessible, nsAccessible); +NS_IMPL_RELEASE_INHERITED(nsRootAccessible, nsAccessible); //----------------------------------------------------- // construction @@ -34,6 +46,7 @@ nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame):nsAccessible(nsnull,nsnull,aShell) { // mFrame = aFrame; + mListener = nsnull; } //----------------------------------------------------- @@ -41,14 +54,13 @@ nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame):n //----------------------------------------------------- nsRootAccessible::~nsRootAccessible() { + RemoveAccessibleEventListener(mListener); } /* attribute wstring accName; */ NS_IMETHODIMP nsRootAccessible::GetAccName(PRUnichar * *aAccName) { - nsAutoString name; - name.AssignWithConversion("Mozilla Document"); - *aAccName = name.ToNewUnicode() ; + *aAccName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document")); return NS_OK; } @@ -82,9 +94,106 @@ NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent) /* readonly attribute wstring accRole; */ NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUnichar * *aAccRole) { - // failed? Lets do some default behavior - nsAutoString a; - a.AssignWithConversion("client"); - *aAccRole = a.ToNewUnicode(); + *aAccRole = ToNewUnicode(NS_LITERAL_STRING("client")); return NS_OK; } + +/* void addAccessibleEventListener (in nsIAccessibleEventListener aListener); */ +NS_IMETHODIMP nsRootAccessible::AddAccessibleEventListener(nsIAccessibleEventListener *aListener) +{ + if (!mListener) + { + // add an event listener to the document + nsCOMPtr shell = do_QueryReferent(mPresShell); + nsCOMPtr document; + shell->GetDocument(getter_AddRefs(document)); + + nsCOMPtr receiver; + if (NS_SUCCEEDED(document->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(receiver))) && receiver) + { + nsresult rv = receiver->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *, this), NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register listener"); + } + } + + // create a weak reference to the listener + mListener = aListener; + + return NS_OK; +} + +/* void removeAccessibleEventListener (in nsIAccessibleEventListener aListener); */ +NS_IMETHODIMP nsRootAccessible::RemoveAccessibleEventListener(nsIAccessibleEventListener *aListener) +{ + if (mListener) + { + nsCOMPtr shell = do_QueryReferent(mPresShell); + nsCOMPtr document; + if (!shell) + return NS_OK; + + shell->GetDocument(getter_AddRefs(document)); + + nsCOMPtr erP; + if (NS_SUCCEEDED(document->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP))) && erP) + { + nsresult rv = erP->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *, this), NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register listener"); + } + } + + mListener = nsnull; + + return NS_OK; +} + + +nsresult nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) +{ + if (mListener) { + nsCOMPtr t; + aEvent->GetOriginalTarget(getter_AddRefs(t)); + + // create and accessible for the target + nsCOMPtr content = do_QueryInterface(t); + + if (!content) + return NS_OK; + + if (mCurrentFocus == content) + return NS_OK; + + mCurrentFocus = content; + + nsIFrame* frame = nsnull; + nsCOMPtr shell = do_QueryReferent(mPresShell); + shell->GetPrimaryFrameFor(content, &frame); + + if (!frame) + return NS_OK; + + nsCOMPtr a = do_QueryInterface(frame); + + if (!a) + a = do_QueryInterface(content); + + nsCOMPtr na = CreateNewAccessible(a, content, mPresShell); + + mListener->HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, na); + } + + return NS_OK; +} + +nsresult nsRootAccessible::Focus(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +nsresult nsRootAccessible::Blur(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + + + diff --git a/mozilla/accessible/src/base/nsRootAccessible.h b/mozilla/accessible/src/base/nsRootAccessible.h index 552ede9ea5e..f881d7028e7 100644 --- a/mozilla/accessible/src/base/nsRootAccessible.h +++ b/mozilla/accessible/src/base/nsRootAccessible.h @@ -24,23 +24,46 @@ #define _nsRootAccessible_H_ #include "nsAccessible.h" +#include "nsIAccessibleEventReceiver.h" +#include "nsIAccessibleEventListener.h" +#include "nsIDOMFocusListener.h" + +class nsRootAccessible : public nsAccessible, + public nsIAccessibleEventReceiver, + public nsIDOMFocusListener -class nsRootAccessible : public nsAccessible { - public: - nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame = nsnull); - virtual ~nsRootAccessible(); + NS_DECL_ISUPPORTS_INHERITED + + public: + nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame = nsnull); + virtual ~nsRootAccessible(); /* attribute wstring accName; */ NS_IMETHOD GetAccName(PRUnichar * *aAccName); NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent); NS_IMETHOD GetAccRole(PRUnichar * *aAccRole); + // ----- nsIAccessibleEventReceiver ------ + + NS_IMETHOD AddAccessibleEventListener(nsIAccessibleEventListener *aListener); + NS_IMETHOD RemoveAccessibleEventListener(nsIAccessibleEventListener *aListener); + + // ----- nsIDOMEventListener -------- + virtual nsresult HandleEvent(nsIDOMEvent* anEvent); + virtual nsresult Focus(nsIDOMEvent* aEvent); + virtual nsresult Blur(nsIDOMEvent* aEvent); + protected: virtual nsIFrame* GetFrame(); - virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aFrame, nsIWeakReference* aShell); - /// nsIFrame* mFrame; + virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIWeakReference* aShell); + + // 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 mCurrentFocus; }; diff --git a/mozilla/accessible/src/base/nsSelectAccessible.cpp b/mozilla/accessible/src/base/nsSelectAccessible.cpp index 68aef4d09f3..ea846137bf8 100644 --- a/mozilla/accessible/src/base/nsSelectAccessible.cpp +++ b/mozilla/accessible/src/base/nsSelectAccessible.cpp @@ -35,6 +35,7 @@ #include "nsLayoutAtoms.h" #include "nsIDOMMenuListener.h" #include "nsIDOMEventReceiver.h" +#include "nsReadableUtils.h" class nsSelectChildAccessible : public nsAccessible, public nsIDOMMenuListener @@ -190,9 +191,7 @@ NS_IMETHODIMP nsSelectAccessible::GetAccName(PRUnichar **_retval) NS_IMETHODIMP nsSelectAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("combo box"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("combo box")); return NS_OK; } @@ -311,9 +310,7 @@ NS_IMETHODIMP nsSelectChildAccessible::GetAccRole(PRUnichar **_retval) // any text in the combo box is static if (role.EqualsIgnoreCase("text")) { // if it the comboboxes text. Make it static - nsAutoString name; - name.AssignWithConversion("static text"); - *_retval = name.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("static text")); } else { rv = nsAccessible::GetAccRole(_retval); } @@ -353,13 +350,8 @@ NS_IMETHODIMP nsSelectChildAccessible::GetAccName(PRUnichar **_retval) // set _retval to it. // notice its supposed to be reversed. Close if opened // and Open if closed. - nsAutoString name; - if (mOpen) - name.AssignWithConversion("Close"); - else - name.AssignWithConversion("Open"); - *_retval = name.ToNewUnicode(); + *_retval = ToNewUnicode(mOpen ? NS_LITERAL_STRING("Close") : NS_LITERAL_STRING("Open")); } else { /*rv = nsAccessible::GetAccName(_retval);*/ @@ -545,9 +537,7 @@ NS_IMETHODIMP nsSelectWindowAccessible::GetAccName(PRUnichar **_retval) NS_IMETHODIMP nsSelectWindowAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("window"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("window")); return NS_OK; } @@ -654,9 +644,7 @@ NS_IMETHODIMP nsSelectListAccessible::GetAccName(PRUnichar **_retval) NS_IMETHODIMP nsSelectListAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("list"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("list")); return NS_OK; } @@ -713,9 +701,7 @@ void nsListChildAccessible::GetListAtomForFrame(nsIFrame* aFrame, nsIAtom*& aLis NS_IMETHODIMP nsListChildAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("list item"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("list item")); return NS_OK; } diff --git a/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp new file mode 100644 index 00000000000..71bee732853 --- /dev/null +++ b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -0,0 +1,172 @@ +/* -*- 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: Eric Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#include "nsHTMLFormControlAccessible.h" +#include "nsWeakReference.h" +#include "nsIFrame.h" +#include "nsIDOMHTMLInputElement.h" +#include "nsINameSpaceManager.h" +#include "nsHTMLAtoms.h" +#include "nsIDOMHTMLButtonElement.h" +#include "nsReadableUtils.h" + +nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsLeafDOMAccessible(aShell, aNode) +{ +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(PRUnichar **_retval) +{ + // go up tree get name of label if there is one. + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccState (); */ +NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval) +{ + // can be + // focusable, focused, checked + nsCOMPtr element = do_QueryInterface(mNode); + + PRBool checked = PR_FALSE; + element->GetChecked(&checked); + *_retval = (checked ? STATE_CHECKED : 0); + return NS_OK; +} + +// --- checkbox ----- + +nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsHTMLFormControlAccessible(aShell, aNode) +{ +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccRole(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("check box")); + return NS_OK; +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + // check or uncheck + nsCOMPtr element = do_QueryInterface(mNode); + + PRBool checked = PR_FALSE; + element->GetChecked(&checked); + *_retval = ToNewUnicode(checked ? NS_LITERAL_STRING("Check") : NS_LITERAL_STRING("UnCheck")); + + return NS_OK; +} + +/* void accDoDefaultAction (); */ +NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoDefaultAction() +{ + nsCOMPtr element = do_QueryInterface(mNode); + PRBool checked = PR_FALSE; + element->GetChecked(&checked); + element->SetChecked(checked ? PR_FALSE : PR_TRUE); + + return NS_OK; +} + + +//------ Radio button ------- + +nsHTMLRadioButtonAccessible::nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsHTMLFormControlAccessible(aShell, aNode) +{ +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("Select")); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("radio button")); + + return NS_OK; +} + +NS_IMETHODIMP nsHTMLRadioButtonAccessible::AccDoDefaultAction() +{ + nsCOMPtr element = do_QueryInterface(mNode); + element->Click(); + + return NS_OK; +} + +// ----- Button ----- + +nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsHTMLFormControlAccessible(aShell, aNode) +{ +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsHTMLButtonAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("Press")); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLButtonAccessible::GetAccRole(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("push button")); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval) +{ + *_retval = nsnull; + nsCOMPtr button = do_QueryInterface(mNode); + + if (!button) + return NS_ERROR_FAILURE; + + nsAutoString name; + button->GetValue(name); + name.CompressWhitespace(); + + *_retval = name.ToNewUnicode(); + + return NS_OK; +} + +NS_IMETHODIMP nsHTMLButtonAccessible::AccDoDefaultAction() +{ + nsCOMPtr element = do_QueryInterface(mNode); + element->Click(); + + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h new file mode 100644 index 00000000000..ae3840443b0 --- /dev/null +++ b/mozilla/accessible/src/html/nsHTMLFormControlAccessible.h @@ -0,0 +1,77 @@ +/* -*- 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: Eric D Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#ifndef _nsHTMLFormControlAccessible_H_ +#define _nsHTMLFormControlAccessible_H_ + +#include "nsGenericAccessible.h" + +class nsICheckboxControlFrame; + +/* Accessible for supporting for controls + * supports: + * - walking up to get name from label + * - support basic state + */ +class nsHTMLFormControlAccessible : public nsLeafDOMAccessible +{ + +public: + nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccName(PRUnichar **_retval); + NS_IMETHOD GetAccState(PRUint32 *_retval); +}; + +class nsHTMLCheckboxAccessible : public nsHTMLFormControlAccessible +{ + +public: + nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + NS_IMETHOD GetAccDefaultAction(PRUnichar **_retval); + NS_IMETHOD AccDoDefaultAction(void); +}; + +class nsHTMLRadioButtonAccessible : public nsHTMLFormControlAccessible +{ + +public: + nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + NS_IMETHOD GetAccDefaultAction(PRUnichar **_retval); + NS_IMETHOD AccDoDefaultAction(void); +}; + +class nsHTMLButtonAccessible : public nsHTMLFormControlAccessible +{ + +public: + nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + NS_IMETHOD GetAccName(PRUnichar **_retval); + NS_IMETHOD GetAccDefaultAction(PRUnichar **_retval); + NS_IMETHOD AccDoDefaultAction(void); + +}; + +#endif diff --git a/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp b/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp new file mode 100644 index 00000000000..98eeec93ace --- /dev/null +++ b/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Author: Eric Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#include "nsHTMLTextAccessible.h" +#include "nsICheckboxControlFrame.h" +#include "nsWeakReference.h" +#include "nsIFrame.h" + +nsHTMLTextAccessible::nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode): +nsLeafDOMAccessible(aShell, aDomNode) +{ +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(PRUnichar **_retval) +{ + nsAutoString value; + mNode->GetNodeValue(value); + value.CompressWhitespace(); + *_retval = value.ToNewUnicode(); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLTextAccessible::GetAccRole(PRUnichar **_retval) +{ + nsAutoString role(NS_LITERAL_STRING("text")); + *_retval = role.ToNewUnicode(); + + return NS_OK; +} diff --git a/mozilla/accessible/src/html/nsHTMLTextAccessible.h b/mozilla/accessible/src/html/nsHTMLTextAccessible.h new file mode 100644 index 00000000000..089017ea7dd --- /dev/null +++ b/mozilla/accessible/src/html/nsHTMLTextAccessible.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef _nsHTMLTextAccessible_H_ +#define _nsHTMLTextAccessible_H_ + +#include "nsGenericAccessible.h" + +class nsIWeakReference; +class nsITextControlFrame; + +class nsHTMLTextAccessible : public nsLeafDOMAccessible +{ + +public: + nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode); + NS_IMETHOD GetAccName(PRUnichar **_retval); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + +private: + nsCOMPtr mDomNode; +}; + +#endif diff --git a/mozilla/accessible/src/makefile.win b/mozilla/accessible/src/makefile.win index 6a37e8cf741..b44e645f7f4 100644 --- a/mozilla/accessible/src/makefile.win +++ b/mozilla/accessible/src/makefile.win @@ -29,10 +29,15 @@ CPP_OBJS=\ .\$(OBJDIR)\nsMutableAccessible.obj \ .\$(OBJDIR)\nsAccessibilityService.obj \ .\$(OBJDIR)\nsSelectAccessible.obj \ + .\$(OBJDIR)\nsGenericAccessible.obj \ + .\$(OBJDIR)\nsHTMLFormControlAccessible.obj \ + .\$(OBJDIR)\nsHTMLTextAccessible.obj \ $(NULL) LINCS= \ -I..\..\layout\html\forms\public \ + -I..\..\layout\html\forms\src \ + -I..\..\layout\html\base\src \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/accessible/src/nsAccessibilityService.cpp b/mozilla/accessible/src/nsAccessibilityService.cpp index 3ae83fa0b2b..b4bf50278a3 100644 --- a/mozilla/accessible/src/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/nsAccessibilityService.cpp @@ -34,8 +34,10 @@ #include "nsRootAccessible.h" #include "nsINameSpaceManager.h" #include "nsMutableAccessible.h" +#include "nsHTMLFormControlAccessible.h" #include "nsLayoutAtoms.h" #include "nsSelectAccessible.h" +#include "nsHTMLTextAccessible.h" //-------------------- @@ -60,7 +62,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsAccessibilityService, nsIAccessibilityService); NS_IMETHODIMP nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISupports* aFrame, nsIAccessible **_retval) { - nsIFrame* f = (nsIFrame*)aFrame; + nsIFrame* f = NS_STATIC_CAST(nsIFrame*, aFrame); nsCOMPtr c = do_QueryInterface(aPresContext); NS_ASSERTION(c,"Error non prescontext passed to accessible factory!!!"); @@ -73,17 +75,22 @@ nsAccessibilityService::CreateRootAccessible(nsISupports* aPresContext, nsISuppo nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); *_retval = new nsRootAccessible(wr,f); - NS_ADDREF(*_retval); - - return NS_OK; + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsAccessibilityService::CreateMutableAccessible(nsISupports* aNode, nsIMutableAccessible **_retval) { *_retval = new nsMutableAccessible(aNode); - NS_ADDREF(*_retval); - return NS_OK; + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP @@ -103,9 +110,11 @@ nsAccessibilityService::CreateHTMLBlockAccessible(nsIAccessible* aAccessible, ns nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); *_retval = new nsHTMLBlockAccessible(aAccessible, n,wr); - NS_ADDREF(*_retval); - - return NS_OK; + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP @@ -123,11 +132,107 @@ nsAccessibilityService::CreateHTMLSelectAccessible(nsIAtom* aPopupAtom, nsIDOMNo nsCOMPtr wr = getter_AddRefs(NS_GetWeakReference(s)); *_retval = new nsSelectAccessible(aPopupAtom, nsnull, n, wr); - NS_ADDREF(*_retval); - return NS_OK; - + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + 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 node; + nsCOMPtr shell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + + *_retval = new nsHTMLCheckboxAccessible(shell,node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +/* nsIAccessible createHTMLCheckboxAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ +NS_IMETHODIMP nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr shell; + GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + + *_retval = new nsHTMLRadioButtonAccessible(shell,node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +/* nsIAccessible createHTMLCheckboxAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ +NS_IMETHODIMP nsAccessibilityService::CreateHTMLButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr shell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + + *_retval = new nsHTMLButtonAccessible(shell,node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +/* nsIAccessible createHTMLTextAccessible (in nsISupports aPresShell, in nsISupports aFrame); */ +NS_IMETHODIMP nsAccessibilityService::CreateHTMLTextAccessible(nsISupports *aFrame, nsIAccessible **_retval) +{ + nsIFrame* frame; + nsCOMPtr node; + nsCOMPtr shell; + nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(shell), getter_AddRefs(node)); + if (NS_FAILED(rv)) + return rv; + + *_retval = new nsHTMLTextAccessible(shell, node); + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } else + return NS_ERROR_OUT_OF_MEMORY; +} + +NS_IMETHODIMP nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aNode) +{ + *aRealFrame = NS_STATIC_CAST(nsIFrame*, aFrame); + nsCOMPtr content; + (*aRealFrame)->GetContent(getter_AddRefs(content)); + nsCOMPtr node = do_QueryInterface(content); + *aNode = node; + NS_ADDREF(*aNode); + + nsCOMPtr document; + content->GetDocument(*getter_AddRefs(document)); + +#ifdef DEBUG + PRInt32 shells = document->GetNumberOfShells(); + NS_ASSERTION(shells > 0,"Error no shells!"); +#endif + + *aShell = document->GetShellAt(0); + NS_IF_ADDREF(*aShell); + + return NS_OK; +} + + ////////////////////////////////////////////////////////////////////// nsresult diff --git a/mozilla/accessible/src/nsAccessibilityService.h b/mozilla/accessible/src/nsAccessibilityService.h index c8267cf6566..6f1848a75d8 100644 --- a/mozilla/accessible/src/nsAccessibilityService.h +++ b/mozilla/accessible/src/nsAccessibilityService.h @@ -27,6 +27,9 @@ #define __nsAccessibilityService_h__ #include "nsIAccessibilityService.h" +class nsIFrame; +class nsIPresShell; +class nsIDOMNode; class nsAccessibilityService : public nsIAccessibilityService { @@ -42,6 +45,9 @@ public: public: +private: + NS_IMETHOD GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIPresShell** aShell, nsIDOMNode** aContent); + }; #endif /* __nsIccessibilityService_h__ */ diff --git a/mozilla/accessible/src/nsAccessible.cpp b/mozilla/accessible/src/nsAccessible.cpp index 48e473c02e9..e09a989f563 100644 --- a/mozilla/accessible/src/nsAccessible.cpp +++ b/mozilla/accessible/src/nsAccessible.cpp @@ -287,8 +287,8 @@ void nsFrameTreeWalker::GetAccessible(nsIFrame* aFrame, nsCOMPtr& if (!aAccessible) aAccessible = do_QueryInterface(aContent); - // if (aAccessible) - // printf("Found accessible!\n"); + if (aAccessible) + printf("Found accessible!\n"); } PRBool nsFrameTreeWalker::IsSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2) @@ -700,21 +700,70 @@ NS_IMETHODIMP nsAccessible::AccNavigateUp(nsIAccessible **_retval) { return NS_O NS_IMETHODIMP nsAccessible::AccNavigateDown(nsIAccessible **_retval) { return NS_OK; } - /* void addSelection (); */ -NS_IMETHODIMP nsAccessible::AccAddSelection(void) { return NS_OK; } +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) { return NS_OK; } +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) { return NS_OK; } +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) { return NS_OK; } +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) { return NS_OK; } +NS_IMETHODIMP nsAccessible::AccTakeFocus(void) +{ + // delegate + if (mAccessible) { + nsresult rv = mAccessible->AccTakeFocus(); + if (NS_SUCCEEDED(rv)) + return rv; + } + + return NS_ERROR_FAILURE; +} /* void doDefaultAction (); */ NS_IMETHODIMP nsAccessible::AccDoDefaultAction(void) diff --git a/mozilla/accessible/src/nsGenericAccessible.cpp b/mozilla/accessible/src/nsGenericAccessible.cpp new file mode 100644 index 00000000000..a1d778870d5 --- /dev/null +++ b/mozilla/accessible/src/nsGenericAccessible.cpp @@ -0,0 +1,335 @@ +/* -*- 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: Eric Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#include "nsGenericAccessible.h" +#include "nsIEventStateManager.h" +#include "nsIFrame.h" +#include "nsCOMPtr.h" +#include "nsIWeakReference.h" + +/* Implementation file */ +NS_IMPL_ISUPPORTS1(nsGenericAccessible, nsIAccessible) + +nsGenericAccessible::nsGenericAccessible() +{ + NS_INIT_ISUPPORTS(); + /* member initializers and constructor code */ +} + +nsGenericAccessible::~nsGenericAccessible() +{ + /* destructor code */ +} + +/* nsIAccessible getAccParent (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccParent(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccNextSibling (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccNextSibling(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccPreviousSibling (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccPreviousSibling(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccFirstChild (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccFirstChild(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible getAccLastChild (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccLastChild(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* long getAccChildCount (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccChildCount(PRInt32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccName(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccValue (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccValue(PRUnichar **_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) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccDescription (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccDescription(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccRole(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccState (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccState(PRUint32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccHelp (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccHelp(PRUnichar **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* boolean getAccFocused (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccFocused(PRBool *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accGetAt (in long x, in long y); */ +NS_IMETHODIMP nsGenericAccessible::AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateRight (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateRight(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateLeft (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateLeft(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateUp (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateUp(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* nsIAccessible accNavigateDown (); */ +NS_IMETHODIMP nsGenericAccessible::AccNavigateDown(nsIAccessible **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accGetBounds (out long x, out long y, out long width, out long height); */ +NS_IMETHODIMP nsGenericAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accAddSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccAddSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accRemoveSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccRemoveSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accExtendSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccExtendSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accTakeSelection (); */ +NS_IMETHODIMP nsGenericAccessible::AccTakeSelection() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accTakeFocus (); */ +NS_IMETHODIMP nsGenericAccessible::AccTakeFocus() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void accDoDefaultAction (); */ +NS_IMETHODIMP nsGenericAccessible::AccDoDefaultAction() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* unsigned long getAccExtState (); */ +NS_IMETHODIMP nsGenericAccessible::GetAccExtState(PRUint32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +//------------- +// nsDOMAccessible +//------------- + +nsDOMAccessible::nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode) +{ + mPresShell = getter_AddRefs(NS_GetWeakReference(aShell)); + mNode = aNode; +} + + +/* void accRemoveSelection (); */ +NS_IMETHODIMP nsDOMAccessible::AccRemoveSelection() +{ + nsCOMPtr control = do_QueryReferent(mPresShell); + nsCOMPtr selection; + nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr 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 control = do_QueryReferent(mPresShell); + nsCOMPtr selection; + nsresult rv = control->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr parent; + rv = mNode->GetParentNode(getter_AddRefs(parent)); + if (NS_FAILED(rv)) + return rv; + + PRInt32 offsetInParent = 0; + nsCOMPtr child; + rv = parent->GetFirstChild(getter_AddRefs(child)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr 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 shell = do_QueryReferent(mPresShell); + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context)); + nsCOMPtr content = do_QueryInterface(mNode); + content->SetFocus(context); + + 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; +} + diff --git a/mozilla/accessible/src/nsGenericAccessible.h b/mozilla/accessible/src/nsGenericAccessible.h new file mode 100644 index 00000000000..ac247f4860a --- /dev/null +++ b/mozilla/accessible/src/nsGenericAccessible.h @@ -0,0 +1,84 @@ +/* -*- 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: Eric D Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#ifndef _nsGenericAccessible_H_ +#define _nsGenericAccessible_H_ + +#include "nsISupports.h" +#include "nsIAccessible.h" +#include "nsIContent.h" +#include "nsIDOMNode.h" +#include "nsIPresShell.h" +#include "nsIPresContext.h" +#include "nsCOMPtr.h" + +class nsIWeakReference; + +/** + * Basic implementation + * supports nothing + */ +class nsGenericAccessible : public nsIAccessible +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIACCESSIBLE + + public: + nsGenericAccessible(); + virtual ~nsGenericAccessible(); +}; + +/** + * And accessible that observes a dom node + * supports: + * - selection + * - focus + */ +class nsDOMAccessible : public nsGenericAccessible +{ + public: + nsDOMAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + + NS_IMETHOD AccTakeSelection(void); + NS_IMETHOD AccTakeFocus(void); + NS_IMETHOD AccRemoveSelection(void); + + protected: + nsIWeakReference* mPresShell; + nsCOMPtr 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); +}; + +#endif diff --git a/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp b/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp new file mode 100644 index 00000000000..71bee732853 --- /dev/null +++ b/mozilla/accessible/src/nsHTMLFormControlAccessible.cpp @@ -0,0 +1,172 @@ +/* -*- 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: Eric Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#include "nsHTMLFormControlAccessible.h" +#include "nsWeakReference.h" +#include "nsIFrame.h" +#include "nsIDOMHTMLInputElement.h" +#include "nsINameSpaceManager.h" +#include "nsHTMLAtoms.h" +#include "nsIDOMHTMLButtonElement.h" +#include "nsReadableUtils.h" + +nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsLeafDOMAccessible(aShell, aNode) +{ +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(PRUnichar **_retval) +{ + // go up tree get name of label if there is one. + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* wstring getAccState (); */ +NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval) +{ + // can be + // focusable, focused, checked + nsCOMPtr element = do_QueryInterface(mNode); + + PRBool checked = PR_FALSE; + element->GetChecked(&checked); + *_retval = (checked ? STATE_CHECKED : 0); + return NS_OK; +} + +// --- checkbox ----- + +nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsHTMLFormControlAccessible(aShell, aNode) +{ +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccRole(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("check box")); + return NS_OK; +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + // check or uncheck + nsCOMPtr element = do_QueryInterface(mNode); + + PRBool checked = PR_FALSE; + element->GetChecked(&checked); + *_retval = ToNewUnicode(checked ? NS_LITERAL_STRING("Check") : NS_LITERAL_STRING("UnCheck")); + + return NS_OK; +} + +/* void accDoDefaultAction (); */ +NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoDefaultAction() +{ + nsCOMPtr element = do_QueryInterface(mNode); + PRBool checked = PR_FALSE; + element->GetChecked(&checked); + element->SetChecked(checked ? PR_FALSE : PR_TRUE); + + return NS_OK; +} + + +//------ Radio button ------- + +nsHTMLRadioButtonAccessible::nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsHTMLFormControlAccessible(aShell, aNode) +{ +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("Select")); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("radio button")); + + return NS_OK; +} + +NS_IMETHODIMP nsHTMLRadioButtonAccessible::AccDoDefaultAction() +{ + nsCOMPtr element = do_QueryInterface(mNode); + element->Click(); + + return NS_OK; +} + +// ----- Button ----- + +nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode): +nsHTMLFormControlAccessible(aShell, aNode) +{ +} + +/* wstring getAccDefaultAction (); */ +NS_IMETHODIMP nsHTMLButtonAccessible::GetAccDefaultAction(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("Press")); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLButtonAccessible::GetAccRole(PRUnichar **_retval) +{ + *_retval = ToNewUnicode(NS_LITERAL_STRING("push button")); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(PRUnichar **_retval) +{ + *_retval = nsnull; + nsCOMPtr button = do_QueryInterface(mNode); + + if (!button) + return NS_ERROR_FAILURE; + + nsAutoString name; + button->GetValue(name); + name.CompressWhitespace(); + + *_retval = name.ToNewUnicode(); + + return NS_OK; +} + +NS_IMETHODIMP nsHTMLButtonAccessible::AccDoDefaultAction() +{ + nsCOMPtr element = do_QueryInterface(mNode); + element->Click(); + + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/accessible/src/nsHTMLFormControlAccessible.h b/mozilla/accessible/src/nsHTMLFormControlAccessible.h new file mode 100644 index 00000000000..ae3840443b0 --- /dev/null +++ b/mozilla/accessible/src/nsHTMLFormControlAccessible.h @@ -0,0 +1,77 @@ +/* -*- 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: Eric D Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#ifndef _nsHTMLFormControlAccessible_H_ +#define _nsHTMLFormControlAccessible_H_ + +#include "nsGenericAccessible.h" + +class nsICheckboxControlFrame; + +/* Accessible for supporting for controls + * supports: + * - walking up to get name from label + * - support basic state + */ +class nsHTMLFormControlAccessible : public nsLeafDOMAccessible +{ + +public: + nsHTMLFormControlAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccName(PRUnichar **_retval); + NS_IMETHOD GetAccState(PRUint32 *_retval); +}; + +class nsHTMLCheckboxAccessible : public nsHTMLFormControlAccessible +{ + +public: + nsHTMLCheckboxAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + NS_IMETHOD GetAccDefaultAction(PRUnichar **_retval); + NS_IMETHOD AccDoDefaultAction(void); +}; + +class nsHTMLRadioButtonAccessible : public nsHTMLFormControlAccessible +{ + +public: + nsHTMLRadioButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + NS_IMETHOD GetAccDefaultAction(PRUnichar **_retval); + NS_IMETHOD AccDoDefaultAction(void); +}; + +class nsHTMLButtonAccessible : public nsHTMLFormControlAccessible +{ + +public: + nsHTMLButtonAccessible(nsIPresShell* aShell, nsIDOMNode* aNode); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + NS_IMETHOD GetAccName(PRUnichar **_retval); + NS_IMETHOD GetAccDefaultAction(PRUnichar **_retval); + NS_IMETHOD AccDoDefaultAction(void); + +}; + +#endif diff --git a/mozilla/accessible/src/nsHTMLTextAccessible.cpp b/mozilla/accessible/src/nsHTMLTextAccessible.cpp new file mode 100644 index 00000000000..98eeec93ace --- /dev/null +++ b/mozilla/accessible/src/nsHTMLTextAccessible.cpp @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Author: Eric Vaughan (evaughan@netscape.com) + * Contributor(s): + */ + +#include "nsHTMLTextAccessible.h" +#include "nsICheckboxControlFrame.h" +#include "nsWeakReference.h" +#include "nsIFrame.h" + +nsHTMLTextAccessible::nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode): +nsLeafDOMAccessible(aShell, aDomNode) +{ +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(PRUnichar **_retval) +{ + nsAutoString value; + mNode->GetNodeValue(value); + value.CompressWhitespace(); + *_retval = value.ToNewUnicode(); + return NS_OK; +} + +/* wstring getAccRole (); */ +NS_IMETHODIMP nsHTMLTextAccessible::GetAccRole(PRUnichar **_retval) +{ + nsAutoString role(NS_LITERAL_STRING("text")); + *_retval = role.ToNewUnicode(); + + return NS_OK; +} diff --git a/mozilla/accessible/src/nsHTMLTextAccessible.h b/mozilla/accessible/src/nsHTMLTextAccessible.h new file mode 100644 index 00000000000..089017ea7dd --- /dev/null +++ b/mozilla/accessible/src/nsHTMLTextAccessible.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef _nsHTMLTextAccessible_H_ +#define _nsHTMLTextAccessible_H_ + +#include "nsGenericAccessible.h" + +class nsIWeakReference; +class nsITextControlFrame; + +class nsHTMLTextAccessible : public nsLeafDOMAccessible +{ + +public: + nsHTMLTextAccessible(nsIPresShell* aShell, nsIDOMNode* aDomNode); + NS_IMETHOD GetAccName(PRUnichar **_retval); + NS_IMETHOD GetAccRole(PRUnichar **_retval); + +private: + nsCOMPtr mDomNode; +}; + +#endif diff --git a/mozilla/accessible/src/nsMutableAccessible.cpp b/mozilla/accessible/src/nsMutableAccessible.cpp index ebee0f21d98..09975cf2a5c 100644 --- a/mozilla/accessible/src/nsMutableAccessible.cpp +++ b/mozilla/accessible/src/nsMutableAccessible.cpp @@ -32,7 +32,7 @@ nsMutableAccessible::nsMutableAccessible(nsISupports* aNode) mNode = aNode; mNameNodeValue = PR_FALSE; mNameStringSet = PR_FALSE; - mRole.AssignWithConversion("unknown"); + mRole = NS_LITERAL_STRING("unknown"); mIsLeaf = PR_FALSE; } @@ -129,7 +129,7 @@ NS_IMETHODIMP nsMutableAccessible::GetAccName(PRUnichar **_retval) nsCOMPtr node = do_QueryInterface(mNode); if (node) { node->GetNodeValue(value); - value.StripWhitespace(); + value.CompressWhitespace(); } else { *_retval = nsnull; return NS_ERROR_NOT_IMPLEMENTED; @@ -139,7 +139,7 @@ NS_IMETHODIMP nsMutableAccessible::GetAccName(PRUnichar **_retval) } else if (mNameAttribute) { nsCOMPtr content = do_QueryInterface(mNode); content->GetAttribute(kNameSpaceID_None, mNameAttribute, value); - value.StripWhitespace(); + value.CompressWhitespace(); } else { *_retval = nsnull; return NS_ERROR_NOT_IMPLEMENTED; diff --git a/mozilla/accessible/src/nsRootAccessible.cpp b/mozilla/accessible/src/nsRootAccessible.cpp index 0b4776c2409..5589421dc09 100644 --- a/mozilla/accessible/src/nsRootAccessible.cpp +++ b/mozilla/accessible/src/nsRootAccessible.cpp @@ -27,6 +27,18 @@ #include "nsIPresContext.h" #include "nsIContent.h" #include "nsIFrame.h" +#include "nsIDOMEventTarget.h" +#include "nsIDOMElement.h" +#include "nsIDOMEventReceiver.h" +#include "nsReadableUtils.h" + +NS_INTERFACE_MAP_BEGIN(nsRootAccessible) + NS_INTERFACE_MAP_ENTRY(nsIAccessibleEventReceiver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAccessibleEventReceiver) +NS_INTERFACE_MAP_END_INHERITING(nsAccessible) + +NS_IMPL_ADDREF_INHERITED(nsRootAccessible, nsAccessible); +NS_IMPL_RELEASE_INHERITED(nsRootAccessible, nsAccessible); //----------------------------------------------------- // construction @@ -34,6 +46,7 @@ nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame):nsAccessible(nsnull,nsnull,aShell) { // mFrame = aFrame; + mListener = nsnull; } //----------------------------------------------------- @@ -41,14 +54,13 @@ nsRootAccessible::nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame):n //----------------------------------------------------- nsRootAccessible::~nsRootAccessible() { + RemoveAccessibleEventListener(mListener); } /* attribute wstring accName; */ NS_IMETHODIMP nsRootAccessible::GetAccName(PRUnichar * *aAccName) { - nsAutoString name; - name.AssignWithConversion("Mozilla Document"); - *aAccName = name.ToNewUnicode() ; + *aAccName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document")); return NS_OK; } @@ -82,9 +94,106 @@ NS_IMETHODIMP nsRootAccessible::GetAccParent(nsIAccessible * *aAccParent) /* readonly attribute wstring accRole; */ NS_IMETHODIMP nsRootAccessible::GetAccRole(PRUnichar * *aAccRole) { - // failed? Lets do some default behavior - nsAutoString a; - a.AssignWithConversion("client"); - *aAccRole = a.ToNewUnicode(); + *aAccRole = ToNewUnicode(NS_LITERAL_STRING("client")); return NS_OK; } + +/* void addAccessibleEventListener (in nsIAccessibleEventListener aListener); */ +NS_IMETHODIMP nsRootAccessible::AddAccessibleEventListener(nsIAccessibleEventListener *aListener) +{ + if (!mListener) + { + // add an event listener to the document + nsCOMPtr shell = do_QueryReferent(mPresShell); + nsCOMPtr document; + shell->GetDocument(getter_AddRefs(document)); + + nsCOMPtr receiver; + if (NS_SUCCEEDED(document->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(receiver))) && receiver) + { + nsresult rv = receiver->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *, this), NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register listener"); + } + } + + // create a weak reference to the listener + mListener = aListener; + + return NS_OK; +} + +/* void removeAccessibleEventListener (in nsIAccessibleEventListener aListener); */ +NS_IMETHODIMP nsRootAccessible::RemoveAccessibleEventListener(nsIAccessibleEventListener *aListener) +{ + if (mListener) + { + nsCOMPtr shell = do_QueryReferent(mPresShell); + nsCOMPtr document; + if (!shell) + return NS_OK; + + shell->GetDocument(getter_AddRefs(document)); + + nsCOMPtr erP; + if (NS_SUCCEEDED(document->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP))) && erP) + { + nsresult rv = erP->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMFocusListener *, this), NS_GET_IID(nsIDOMFocusListener)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register listener"); + } + } + + mListener = nsnull; + + return NS_OK; +} + + +nsresult nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) +{ + if (mListener) { + nsCOMPtr t; + aEvent->GetOriginalTarget(getter_AddRefs(t)); + + // create and accessible for the target + nsCOMPtr content = do_QueryInterface(t); + + if (!content) + return NS_OK; + + if (mCurrentFocus == content) + return NS_OK; + + mCurrentFocus = content; + + nsIFrame* frame = nsnull; + nsCOMPtr shell = do_QueryReferent(mPresShell); + shell->GetPrimaryFrameFor(content, &frame); + + if (!frame) + return NS_OK; + + nsCOMPtr a = do_QueryInterface(frame); + + if (!a) + a = do_QueryInterface(content); + + nsCOMPtr na = CreateNewAccessible(a, content, mPresShell); + + mListener->HandleEvent(nsIAccessibleEventListener::EVENT_FOCUS, na); + } + + return NS_OK; +} + +nsresult nsRootAccessible::Focus(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +nsresult nsRootAccessible::Blur(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + + + diff --git a/mozilla/accessible/src/nsRootAccessible.h b/mozilla/accessible/src/nsRootAccessible.h index 552ede9ea5e..f881d7028e7 100644 --- a/mozilla/accessible/src/nsRootAccessible.h +++ b/mozilla/accessible/src/nsRootAccessible.h @@ -24,23 +24,46 @@ #define _nsRootAccessible_H_ #include "nsAccessible.h" +#include "nsIAccessibleEventReceiver.h" +#include "nsIAccessibleEventListener.h" +#include "nsIDOMFocusListener.h" + +class nsRootAccessible : public nsAccessible, + public nsIAccessibleEventReceiver, + public nsIDOMFocusListener -class nsRootAccessible : public nsAccessible { - public: - nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame = nsnull); - virtual ~nsRootAccessible(); + NS_DECL_ISUPPORTS_INHERITED + + public: + nsRootAccessible(nsIWeakReference* aShell, nsIFrame* aFrame = nsnull); + virtual ~nsRootAccessible(); /* attribute wstring accName; */ NS_IMETHOD GetAccName(PRUnichar * *aAccName); NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent); NS_IMETHOD GetAccRole(PRUnichar * *aAccRole); + // ----- nsIAccessibleEventReceiver ------ + + NS_IMETHOD AddAccessibleEventListener(nsIAccessibleEventListener *aListener); + NS_IMETHOD RemoveAccessibleEventListener(nsIAccessibleEventListener *aListener); + + // ----- nsIDOMEventListener -------- + virtual nsresult HandleEvent(nsIDOMEvent* anEvent); + virtual nsresult Focus(nsIDOMEvent* aEvent); + virtual nsresult Blur(nsIDOMEvent* aEvent); + protected: virtual nsIFrame* GetFrame(); - virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aFrame, nsIWeakReference* aShell); - /// nsIFrame* mFrame; + virtual nsIAccessible* CreateNewAccessible(nsIAccessible* aAccessible, nsIContent* aContent, nsIWeakReference* aShell); + + // 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 mCurrentFocus; }; diff --git a/mozilla/accessible/src/nsSelectAccessible.cpp b/mozilla/accessible/src/nsSelectAccessible.cpp index 68aef4d09f3..ea846137bf8 100644 --- a/mozilla/accessible/src/nsSelectAccessible.cpp +++ b/mozilla/accessible/src/nsSelectAccessible.cpp @@ -35,6 +35,7 @@ #include "nsLayoutAtoms.h" #include "nsIDOMMenuListener.h" #include "nsIDOMEventReceiver.h" +#include "nsReadableUtils.h" class nsSelectChildAccessible : public nsAccessible, public nsIDOMMenuListener @@ -190,9 +191,7 @@ NS_IMETHODIMP nsSelectAccessible::GetAccName(PRUnichar **_retval) NS_IMETHODIMP nsSelectAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("combo box"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("combo box")); return NS_OK; } @@ -311,9 +310,7 @@ NS_IMETHODIMP nsSelectChildAccessible::GetAccRole(PRUnichar **_retval) // any text in the combo box is static if (role.EqualsIgnoreCase("text")) { // if it the comboboxes text. Make it static - nsAutoString name; - name.AssignWithConversion("static text"); - *_retval = name.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("static text")); } else { rv = nsAccessible::GetAccRole(_retval); } @@ -353,13 +350,8 @@ NS_IMETHODIMP nsSelectChildAccessible::GetAccName(PRUnichar **_retval) // set _retval to it. // notice its supposed to be reversed. Close if opened // and Open if closed. - nsAutoString name; - if (mOpen) - name.AssignWithConversion("Close"); - else - name.AssignWithConversion("Open"); - *_retval = name.ToNewUnicode(); + *_retval = ToNewUnicode(mOpen ? NS_LITERAL_STRING("Close") : NS_LITERAL_STRING("Open")); } else { /*rv = nsAccessible::GetAccName(_retval);*/ @@ -545,9 +537,7 @@ NS_IMETHODIMP nsSelectWindowAccessible::GetAccName(PRUnichar **_retval) NS_IMETHODIMP nsSelectWindowAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("window"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("window")); return NS_OK; } @@ -654,9 +644,7 @@ NS_IMETHODIMP nsSelectListAccessible::GetAccName(PRUnichar **_retval) NS_IMETHODIMP nsSelectListAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("list"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("list")); return NS_OK; } @@ -713,9 +701,7 @@ void nsListChildAccessible::GetListAtomForFrame(nsIFrame* aFrame, nsIAtom*& aLis NS_IMETHODIMP nsListChildAccessible::GetAccRole(PRUnichar **_retval) { - nsAutoString a; - a.AssignWithConversion("list item"); - *_retval = a.ToNewUnicode(); + *_retval = ToNewUnicode(NS_LITERAL_STRING("list item")); return NS_OK; } diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 0cb56507b1d..5bf055fc857 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -477,16 +477,13 @@ nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIMutableAccessible* acc = nsnull; - accService->CreateMutableAccessible(node,&acc); - acc->SetName(NS_LITERAL_STRING("Push Button").get()); - acc->SetRole(NS_LITERAL_STRING("push button").get()); - acc->SetIsLeaf(PR_TRUE); + nsIAccessible* acc = nsnull; + accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); *aInstancePtr = acc; return NS_OK; } return NS_ERROR_FAILURE; + } else { return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr); diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index fb80a143237..00338960e6a 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -92,12 +92,8 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIMutableAccessible* acc = nsnull; - accService->CreateMutableAccessible(node,&acc); - acc->SetName(NS_LITERAL_STRING("Check Box").get()); - acc->SetRole(NS_LITERAL_STRING("check box").get()); - acc->SetIsLeaf(PR_TRUE); + nsIAccessible* acc = nsnull; + accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); *aInstancePtr = acc; return NS_OK; } diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.h b/mozilla/layout/forms/nsGfxCheckboxControlFrame.h index cecb2616aac..96b58d3ad56 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.h +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.h @@ -32,9 +32,13 @@ class nsGfxCheckboxControlFrame : public nsFormControlFrame, public nsIStatefulFrame, - public nsICheckboxControlFrame + public nsICheckboxControlFrame//, + //public nsIAccessible { public: + + //NS_DECL_NSIACCESSIBLE + nsGfxCheckboxControlFrame(); virtual ~nsGfxCheckboxControlFrame(); @@ -95,6 +99,9 @@ public: nsReflowStatus& aStatus); #endif + NS_IMETHOD GetChecked(PRBool* aIsChecked) { *aIsChecked = (GetCheckboxState() == eOn); return NS_OK; } + NS_IMETHOD SetChecked(nsIPresContext* aPresContext, PRBool aIsChecked) { SetCheckboxState(aPresContext, aIsChecked ? eOn : eOff); return NS_OK; } + protected: // native/gfx implementations need to implement needs. diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index 0f406e57328..99d09cd02a5 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -87,15 +87,12 @@ nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { nsCOMPtr node = do_QueryInterface(mContent); - nsIMutableAccessible* acc = nsnull; - accService->CreateMutableAccessible(node,&acc); - acc->SetName(NS_LITERAL_STRING("Radio Button").get()); - acc->SetRole(NS_LITERAL_STRING("radio button").get()); - acc->SetIsLeaf(PR_TRUE); + nsIAccessible* acc = nsnull; + accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); *aInstancePtr = acc; return NS_OK; } - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 88504b9f0cd..39473fea05c 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -807,7 +807,7 @@ nsFrame::HandleEvent(nsIPresContext* aPresContext, nsISupports* f = (nsISupports*)(nsIFrame*)this; nsIAccessible* acc; accService->CreateRootAccessible(aPresContext,mParent ? f : nsnull,&acc); - ((nsAccessibleEvent*)aEvent)->accessible = acc; + NS_STATIC_CAST(nsAccessibleEvent*, aEvent)->accessible = acc; } //} } diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 24999106c27..f066957fc26 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -68,7 +68,7 @@ #include "nsIAccessible.h" #include "nsINameSpaceManager.h" #include "nsIAccessibilityService.h" -#include "nsIMutableAccessible.h" +//#include "nsIMutableAccessible.h" #ifdef IBMBIDI #include "nsBidiFrames.h" @@ -776,6 +776,11 @@ NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { + nsIAccessible* acc = nsnull; + accService->CreateHTMLTextAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); + *aInstancePtrResult = acc; + + /* nsIMutableAccessible* acc = nsnull; nsCOMPtr node = do_QueryInterface(mContent); @@ -802,6 +807,8 @@ NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, acc->SetRole(NS_LITERAL_STRING("text").get()); acc->SetIsLeaf(PR_TRUE); *aInstancePtrResult = acc; + */ + return NS_OK; } return NS_ERROR_FAILURE; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 88504b9f0cd..39473fea05c 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -807,7 +807,7 @@ nsFrame::HandleEvent(nsIPresContext* aPresContext, nsISupports* f = (nsISupports*)(nsIFrame*)this; nsIAccessible* acc; accService->CreateRootAccessible(aPresContext,mParent ? f : nsnull,&acc); - ((nsAccessibleEvent*)aEvent)->accessible = acc; + NS_STATIC_CAST(nsAccessibleEvent*, aEvent)->accessible = acc; } //} } diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 24999106c27..f066957fc26 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -68,7 +68,7 @@ #include "nsIAccessible.h" #include "nsINameSpaceManager.h" #include "nsIAccessibilityService.h" -#include "nsIMutableAccessible.h" +//#include "nsIMutableAccessible.h" #ifdef IBMBIDI #include "nsBidiFrames.h" @@ -776,6 +776,11 @@ NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { + nsIAccessible* acc = nsnull; + accService->CreateHTMLTextAccessible(NS_STATIC_CAST(nsIFrame*, this),&acc); + *aInstancePtrResult = acc; + + /* nsIMutableAccessible* acc = nsnull; nsCOMPtr node = do_QueryInterface(mContent); @@ -802,6 +807,8 @@ NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID, acc->SetRole(NS_LITERAL_STRING("text").get()); acc->SetIsLeaf(PR_TRUE); *aInstancePtrResult = acc; + */ + return NS_OK; } return NS_ERROR_FAILURE; diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 0cb56507b1d..5bf055fc857 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -477,16 +477,13 @@ nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIMutableAccessible* acc = nsnull; - accService->CreateMutableAccessible(node,&acc); - acc->SetName(NS_LITERAL_STRING("Push Button").get()); - acc->SetRole(NS_LITERAL_STRING("push button").get()); - acc->SetIsLeaf(PR_TRUE); + nsIAccessible* acc = nsnull; + accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); *aInstancePtr = acc; return NS_OK; } return NS_ERROR_FAILURE; + } else { return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr); diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index fb80a143237..00338960e6a 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -92,12 +92,8 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr nsresult rv = NS_OK; NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { - nsCOMPtr node = do_QueryInterface(mContent); - nsIMutableAccessible* acc = nsnull; - accService->CreateMutableAccessible(node,&acc); - acc->SetName(NS_LITERAL_STRING("Check Box").get()); - acc->SetRole(NS_LITERAL_STRING("check box").get()); - acc->SetIsLeaf(PR_TRUE); + nsIAccessible* acc = nsnull; + accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); *aInstancePtr = acc; return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h index cecb2616aac..96b58d3ad56 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.h @@ -32,9 +32,13 @@ class nsGfxCheckboxControlFrame : public nsFormControlFrame, public nsIStatefulFrame, - public nsICheckboxControlFrame + public nsICheckboxControlFrame//, + //public nsIAccessible { public: + + //NS_DECL_NSIACCESSIBLE + nsGfxCheckboxControlFrame(); virtual ~nsGfxCheckboxControlFrame(); @@ -95,6 +99,9 @@ public: nsReflowStatus& aStatus); #endif + NS_IMETHOD GetChecked(PRBool* aIsChecked) { *aIsChecked = (GetCheckboxState() == eOn); return NS_OK; } + NS_IMETHOD SetChecked(nsIPresContext* aPresContext, PRBool aIsChecked) { SetCheckboxState(aPresContext, aIsChecked ? eOn : eOff); return NS_OK; } + protected: // native/gfx implementations need to implement needs. diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index 0f406e57328..99d09cd02a5 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -87,15 +87,12 @@ nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) NS_WITH_SERVICE(nsIAccessibilityService, accService, "@mozilla.org/accessibilityService;1", &rv); if (accService) { nsCOMPtr node = do_QueryInterface(mContent); - nsIMutableAccessible* acc = nsnull; - accService->CreateMutableAccessible(node,&acc); - acc->SetName(NS_LITERAL_STRING("Radio Button").get()); - acc->SetRole(NS_LITERAL_STRING("radio button").get()); - acc->SetIsLeaf(PR_TRUE); + nsIAccessible* acc = nsnull; + accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), &acc); *aInstancePtr = acc; return NS_OK; } - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; } return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); diff --git a/mozilla/widget/src/windows/Accessible.cpp b/mozilla/widget/src/windows/Accessible.cpp index c5968ccd82d..efe3322c635 100644 --- a/mozilla/widget/src/windows/Accessible.cpp +++ b/mozilla/widget/src/windows/Accessible.cpp @@ -27,6 +27,7 @@ #include "nsWindow.h" #include "nsCOMPtr.h" #include "nsXPIDLString.h" +#include "nsIAccessibleEventReceiver.h" //#define DEBUG_LEAKS @@ -56,6 +57,8 @@ Accessible::Accessible(nsIAccessible* aAcc, HWND aWnd) mAccessible = aAcc; mWnd = aWnd; m_cRef = 0; + mCachedIndex = 0; + mCachedChild = NULL; #ifdef DEBUG_LEAKS printf("Accessibles=%d\n", ++gAccessibles); @@ -284,7 +287,13 @@ STDMETHODIMP Accessible::get_accRole( else if (role.EqualsIgnoreCase("push button")) pvarRole->lVal = ROLE_SYSTEM_PUSHBUTTON; else if (role.EqualsIgnoreCase("radio button")) - pvarRole->lVal = ROLE_SYSTEM_RADIOBUTTON; + pvarRole->lVal = ROLE_SYSTEM_PUSHBUTTON; + else if (role.EqualsIgnoreCase("indicator")) + pvarRole->lVal = ROLE_SYSTEM_INDICATOR; + else if (role.EqualsIgnoreCase("check box")) + pvarRole->lVal = ROLE_SYSTEM_CHECKBUTTON; + else if (role.EqualsIgnoreCase("scrollbar")) + pvarRole->lVal = ROLE_SYSTEM_SCROLLBAR; else if (role.EqualsIgnoreCase("slider")) pvarRole->lVal = ROLE_SYSTEM_SLIDER; else if (role.EqualsIgnoreCase("client")) @@ -315,6 +324,7 @@ STDMETHODIMP Accessible::get_accState( nsresult rv = a->GetAccState(&state); if (NS_FAILED(rv)) return S_FALSE; + pvarState->lVal = state; return S_OK; @@ -366,13 +376,41 @@ STDMETHODIMP Accessible::get_accDefaultAction( /* [optional][in] */ VARIANT varChild, /* [retval][out] */ BSTR __RPC_FAR *pszDefaultAction) { - return NULL; + *pszDefaultAction = NULL; + nsCOMPtr a; + GetNSAccessibleFor(varChild,a); + if (a) { + nsXPIDLString name; + nsresult rv = a->GetAccDefaultAction(getter_Copies(name)); + if (NS_FAILED(rv)) + return S_FALSE; + + *pszDefaultAction = ::SysAllocString(name.get()); + } + + return S_OK; } STDMETHODIMP Accessible::accSelect( /* [in] */ long flagsSelect, /* [optional][in] */ VARIANT varChild) { + // currently only handle focus and selection + if (flagsSelect & (SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION|SELFLAG_REMOVESELECTION)) + { + if (flagsSelect & SELFLAG_TAKEFOCUS) + mAccessible->AccTakeFocus(); + + if (flagsSelect & SELFLAG_TAKESELECTION) + mAccessible->AccTakeSelection(); + + if (flagsSelect & SELFLAG_REMOVESELECTION) + mAccessible->AccRemoveSelection(); + + + return S_OK; + } + return S_FALSE; } @@ -543,28 +581,132 @@ STDMETHODIMP Accessible::Invoke(DISPID dispIdMember, REFIID riid, void Accessible::GetNSAccessibleFor(VARIANT varChild, nsCOMPtr& aAcc) { - if (varChild.lVal == CHILDID_SELF) + // if its us real easy + if (varChild.lVal == CHILDID_SELF) { aAcc = mAccessible; - else { - long count = 1; - nsCOMPtr a; + } else if (mCachedChild && varChild.lVal == mCachedIndex+1) { + // if the cachedIndex is not self and the if its the one right + // before the one we want to get. Then just ask it for its next. nsCOMPtr next; - mAccessible->GetAccFirstChild(getter_AddRefs(a)); - while(a) + mCachedChild->GetAccNextSibling(getter_AddRefs(next)); + if (next) { + mCachedIndex++; + mCachedChild = next; + } + + aAcc = next; + return; + + } else { + // if the cachedindex is not the one right before we have to start at the begining + nsCOMPtr a; + mAccessible->GetAccFirstChild(getter_AddRefs(mCachedChild)); + mCachedIndex = 1; + while(mCachedChild) { - if (varChild.lVal == count) + if (varChild.lVal == mCachedIndex) { - aAcc = a; + aAcc = mCachedChild; return; } - a->GetAccNextSibling(getter_AddRefs(next)); - a = next; - count++; + mCachedChild->GetAccNextSibling(getter_AddRefs(a)); + mCachedChild = a; + mCachedIndex++; } aAcc = nsnull; } } + +//----- Root Accessible ----- + +NS_IMPL_QUERY_INTERFACE1(RootAccessible, nsIAccessibleEventListener) + +NS_IMETHODIMP_(nsrefcnt) +RootAccessible::AddRef(void) +{ + return Accessible::AddRef(); +} + +NS_IMETHODIMP_(nsrefcnt) +RootAccessible::Release(void) +{ + return Accessible::Release(); +} + +RootAccessible::RootAccessible(nsIAccessible* aAcc, HWND aWnd):Accessible(aAcc,aWnd) + +{ + mListCount = 0; + mNextId = -1; + mNextPos = 0; + + nsCOMPtr r = do_QueryInterface(mAccessible); + if (r) + r->AddAccessibleEventListener(this); +} + +RootAccessible::~RootAccessible() +{ + nsCOMPtr r = do_QueryInterface(mAccessible); + if (r) + r->RemoveAccessibleEventListener(this); + + // free up accessibles + for (int i=0; i < mListCount; i++) + mList[i].mAccessible = nsnull; +} + +void RootAccessible::GetNSAccessibleFor(VARIANT varChild, nsCOMPtr& aAcc) +{ + aAcc = nsnull; + Accessible::GetNSAccessibleFor(varChild, aAcc); + + if (aAcc) + return; + + for (int i=0; i < mListCount; i++) + { + if (varChild.lVal == mList[i].mId) { + aAcc = mList[i].mAccessible; + return; + } + } +} + +NS_IMETHODIMP RootAccessible::HandleEvent(PRUint32 aEvent, nsIAccessible* aAccessible) +{ + // print focus event!! + printf("Focus Changed!!!\n"); + + // get the id for the accessible + PRInt32 id = GetIdFor(aAccessible); + + // notify the window system + NotifyWinEvent(aEvent, mWnd, OBJID_CLIENT, id); + + + return NS_OK; +} + +PRInt32 RootAccessible::GetIdFor(nsIAccessible* aAccessible) +{ + // max of 99999 ids can be generated + if (mNextId < -99999) + mNextId = -1; + + // Lets make one and add it to the list + mList[mNextPos].mId = mNextId; + mList[mNextPos].mAccessible = aAccessible; + + mNextId--; + mNextPos++; + if (mListCount < MAX_LIST_SIZE) + mListCount++; + + return mNextId+1; +} + #endif #endif \ No newline at end of file diff --git a/mozilla/widget/src/windows/Accessible.h b/mozilla/widget/src/windows/Accessible.h index 1dd50a348f8..07e1d74a6fc 100644 --- a/mozilla/widget/src/windows/Accessible.h +++ b/mozilla/widget/src/windows/Accessible.h @@ -28,9 +28,10 @@ #include "nsCOMPtr.h" #include "nsIAccessible.h" +#include "nsIAccessibleEventListener.h" #include "nsString.h" -//#define IS_ACCESSIBLE +#define IS_ACCESSIBLE class Accessible : public IAccessible { @@ -41,7 +42,7 @@ class Accessible : public IAccessible public: // construction, destruction Accessible(nsIAccessible*, HWND aWin = 0); - ~Accessible(); + virtual ~Accessible(); public: // IUnknown methods - see iunknown.h for documentation STDMETHODIMP_(ULONG) AddRef (); @@ -152,11 +153,13 @@ class Accessible : public IAccessible static ULONG g_cRef; // the cum reference count of all instances ULONG m_cRef; // the reference count nsCOMPtr mAccessible; + nsCOMPtr mCachedChild; HWND mWnd; + LONG mCachedIndex; protected: - void GetNSAccessibleFor(VARIANT varChild, nsCOMPtr& aAcc); + virtual void GetNSAccessibleFor(VARIANT varChild, nsCOMPtr& aAcc); PRBool InState(const nsString& aStates, const char* aState); STDMETHODIMP GetAttribute(const char* aName, VARIANT varChild, BSTR __RPC_FAR *aString); @@ -164,5 +167,47 @@ class Accessible : public IAccessible #endif }; +class nsAccessibleEventMap +{ +public: + nsCOMPtr mAccessible; + PRInt32 mId; +}; + +#define MAX_LIST_SIZE 100 + +class RootAccessible: public Accessible, + public nsIAccessibleEventListener +{ +#ifdef IS_ACCESSIBLE + +// accessibility only on Windows2000 and Windows98 +#ifdef OBJID_WINDOW + +public: + RootAccessible(nsIAccessible*, HWND aWin = 0); + virtual ~RootAccessible(); + + NS_DECL_ISUPPORTS + + // nsIAccessibleEventListener + NS_DECL_NSIACCESSIBLEEVENTLISTENER + + virtual PRInt32 GetIdFor(nsIAccessible* aAccessible); + virtual void GetNSAccessibleFor(VARIANT varChild, nsCOMPtr& aAcc); + +private: + // list of accessible that may have had + // events fire. + nsAccessibleEventMap mList[MAX_LIST_SIZE]; + PRInt32 mListCount; + PRInt32 mNextId; + PRInt32 mNextPos; + +#endif +#endif +}; + + #endif diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 63f6364c68f..b765db50dfa 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -427,7 +427,7 @@ NS_IMETHODIMP nsWindow::QueryInterface(const nsIID& aIID, void** aInstancePtr) // nsWindow constructor // //------------------------------------------------------------------------- -nsWindow::nsWindow() : nsBaseWidget() +nsWindow::nsWindow() : nsBaseWidget(), mRootAccessible(NULL) { NS_INIT_REFCNT(); mWnd = 0; @@ -507,6 +507,9 @@ UINT nsWindow::gCurrentKeyboardCP = 0; //------------------------------------------------------------------------- nsWindow::~nsWindow() { + if (mRootAccessible) + mRootAccessible->Release(); + mIsDestroying = PR_TRUE; if (gCurrentWindow == this) { gCurrentWindow = nsnull; @@ -3364,8 +3367,11 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT if (acc) { HWND wnd = GetWindowHandle(); - IAccessible* pAcc = new Accessible(acc, wnd); // ref is 0 - LRESULT lAcc = LresultFromObject(IID_IAccessible, wParam, pAcc); // ref 1 + if (!mRootAccessible) { + mRootAccessible = new RootAccessible(acc, wnd); // ref is 0 + mRootAccessible->AddRef(); + } + LRESULT lAcc = LresultFromObject(IID_IAccessible, wParam, mRootAccessible); // ref 1 *aRetValue = lAcc; return PR_TRUE; // yes we handled it. } @@ -3526,8 +3532,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT } } - - //------------------------------------------------------------------------- // // return the window class name and initialize the class if needed diff --git a/mozilla/widget/src/windows/nsWindow.h b/mozilla/widget/src/windows/nsWindow.h index 4d5d781c7ae..fc60518de9d 100644 --- a/mozilla/widget/src/windows/nsWindow.h +++ b/mozilla/widget/src/windows/nsWindow.h @@ -46,6 +46,9 @@ class nsIRollupListener; class nsIMenuBar; struct IAccessible; +#include "nsIAccessible.h" +#include "nsIAccessibleEventListener.h" + #define NSRGB_2_COLOREF(color) \ RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color)) @@ -176,6 +179,7 @@ private: class nsWindow : public nsSwitchToUIThread, public nsBaseWidget, public nsIKBStateControl + { public: @@ -448,6 +452,8 @@ protected: static UINT uWM_MSIME_RECONVERT; // reconvert messge for MSIME static UINT uWM_MSIME_MOUSE; // mouse messge for MSIME static UINT uWM_ATOK_RECONVERT; // reconvert messge for ATOK + + IAccessible* mRootAccessible; }; //