diff --git a/accessible/public/nsIAccessibilityService.idl b/accessible/public/nsIAccessibilityService.idl index 0c3f717f788..1c6c91952d6 100644 --- a/accessible/public/nsIAccessibilityService.idl +++ b/accessible/public/nsIAccessibilityService.idl @@ -38,14 +38,10 @@ interface nsIAccessibilityService : nsISupports nsIAccessible createHTMLListboxAccessible(in nsIDOMNode aNode, in nsISupports aPresShell); nsIAccessible createHTMLSelectOptionAccessible(in nsIDOMNode aNode, in nsIAccessible aAccParent, in nsISupports aPresShell); nsIAccessible createHTMLCheckboxAccessible(in nsISupports aFrame); - nsIAccessible createXULCheckboxAccessible(in nsIDOMNode aNode); nsIAccessible createHTMLRadioButtonAccessible(in nsISupports aFrame); nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame); nsIAccessible createHTML4ButtonAccessible(in nsISupports aFrame); - nsIAccessible createXULButtonAccessible(in nsIDOMNode aNode); nsIAccessible createHTMLTextAccessible(in nsISupports aFrame); - nsIAccessible createXULTextAccessible(in nsIDOMNode aNode); - nsIAccessible createXULImageAccessible(in nsIDOMNode aNode); nsIAccessible createHTMLImageAccessible(in nsISupports aFrame); nsIAccessible createHTMLAreaAccessible(in nsIWeakReference aPresShell, in nsIDOMNode aDOMNode, in nsIAccessible aAccParent); nsIAccessible createHTMLTableAccessible(in nsISupports aFrame); @@ -53,6 +49,10 @@ interface nsIAccessibilityService : nsISupports nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame); nsIAccessible createHTMLIFrameAccessible(in nsIDOMNode aNode, in nsISupports aPresContext); nsIAccessible createHTMLBlockAccessible(in nsIDOMNode aNode, in nsISupports aDocument); + nsIAccessible createXULButtonAccessible(in nsIDOMNode aNode); + nsIAccessible createXULCheckboxAccessible(in nsIDOMNode aNode); + nsIAccessible createXULImageAccessible(in nsIDOMNode aNode); + nsIAccessible createXULTextAccessible(in nsIDOMNode aNode); nsIAccessible createAccessible(in nsIDOMNode aNode, in nsISupports aDocument); nsIAccessible getAccessibleFor(in nsIDOMNode aNode); }; diff --git a/accessible/src/Makefile.in b/accessible/src/Makefile.in index 9bc117e2276..bf7cac8c03f 100644 --- a/accessible/src/Makefile.in +++ b/accessible/src/Makefile.in @@ -64,6 +64,9 @@ CPPSRCS = \ nsHTMLComboboxAccessible.cpp \ nsHTMLListboxAccessible.cpp \ nsGenericAccessible.cpp \ + nsXULFormControlAccessible.cpp \ + nsXULTextAccessible.cpp \ + nsBaseWidgetAccessible.obj \ $(NULL) EXPORTS = \ diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index ffbbceb6fb8..a7bf43919dd 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -66,6 +66,8 @@ #include "nsIDOMDocument.h" #include "nsIDOMHTMLOptionElement.h" #include "nsIDOMXULCheckboxElement.h" +#include "nsXULFormControlAccessible.h" +#include "nsXULTextAccessible.h" // IFrame #include "nsIDocShell.h" @@ -199,7 +201,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULCheckboxAccessible(nsIDOMNode *aN GetShellFromNode(aNode, getter_AddRefs(weakShell)); // reusing the HTML accessible widget and enhancing for XUL - *_retval = new nsHTMLCheckboxAccessible(aNode, weakShell); + *_retval = new nsXULCheckboxAccessible(aNode, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -267,7 +269,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULButtonAccessible(nsIDOMNode *aNod GetShellFromNode(aNode, getter_AddRefs(weakShell)); // reusing the HTML accessible widget and enhancing for XUL - *_retval = new nsHTML4ButtonAccessible(aNode, weakShell); + *_retval = new nsXULButtonAccessible(aNode, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -299,7 +301,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULTextAccessible(nsIDOMNode *aNode, GetShellFromNode(aNode, getter_AddRefs(weakShell)); // reusing the HTML accessible widget and enhancing for XUL - *_retval = new nsHTMLTextAccessible(aNode, weakShell); + *_retval = new nsXULTextAccessible(aNode, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -661,6 +663,18 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode, if (!aNode) return NS_ERROR_NULL_POINTER; + // ---- Is it a XUL element? -- they impl nsIAccessibleProvider via XBL + nsCOMPtr newAcc; + nsCOMPtr accProv(do_QueryInterface(aNode)); + if (accProv) { + accProv->GetAccessible(getter_AddRefs(newAcc)); + if (newAcc) { + *_retval = newAcc; + NS_ADDREF(*_retval); + return NS_OK; + } + } + // ---- Get the document for this node ---- nsCOMPtr doc; nsCOMPtr nodeIsDoc(do_QueryInterface(aNode)); @@ -710,16 +724,8 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode, if (!frame) return NS_ERROR_FAILURE; - nsCOMPtr newAcc; frame->GetAccessible(getter_AddRefs(newAcc)); - // ---- Is it a XUL element? -- they impl nsIAccessibleProvider via XBL - if (!newAcc) { - nsCOMPtr accProv(do_QueryInterface(aNode)); - if (accProv) - accProv->GetAccessible(getter_AddRefs(newAcc)); - } - // ---- If link, create link accessible ---- if (!newAcc) { // is it a link? diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 908ea84ca70..11138a72c05 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * John Gaunt (jgaunt@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -48,7 +49,6 @@ #include "nsIViewManager.h" #include "nsIWidget.h" #include "nsRootAccessible.h" -#include "nsIScriptGlobalObject.h" #include "nsPIDOMWindow.h" #include "nsIDOMElement.h" #include "nsIEventStateManager.h" @@ -79,8 +79,6 @@ #include "nsStyleConsts.h" #include "nsReadableUtils.h" - - // IFrame Helpers #include "nsIDocShell.h" #include "nsIWebShell.h" @@ -1463,244 +1461,3 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, ns } return NS_OK; } - - -// ------- nsHTMLBlockAccessible ------ - -nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aNode, aShell) -{ -} - -/* nsIAccessible accGetAt (in long x, in long y); */ -NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval) -{ - // We're going to find the child that contains coordinates (tx,ty) - PRInt32 x,y,w,h; - AccGetBounds(&x,&y,&w,&h); // Get bounds for this accessible - if (tx > x && tx < x + w && ty > y && ty < y + h) - { - // It's within this nsIAccessible, let's drill down - nsCOMPtr child; - nsCOMPtr smallestChild; - PRInt32 smallestArea = -1; - nsCOMPtr next; - GetAccFirstChild(getter_AddRefs(child)); - PRInt32 cx,cy,cw,ch; // Child bounds - - while(child) { - child->AccGetBounds(&cx,&cy,&cw,&ch); - - // ok if there are multiple frames the contain the point - // and they overlap then pick the smallest. We need to do this - // for text frames. - - // For example, A point that's in block #2 is also in block #1, but we want to return #2: - // - // [[block #1 is long wrapped text that continues to - // another line]] [[here is a shorter block #2]] - - if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch) - { - if (smallestArea == -1 || cw*ch < smallestArea) { - smallestArea = cw*ch; - smallestChild = child; - } - } - child->GetAccNextSibling(getter_AddRefs(next)); - child = next; - } - - if (smallestChild != nsnull) - { - *_retval = smallestChild; - NS_ADDREF(*_retval); - return NS_OK; - } - - *_retval = this; - NS_ADDREF(this); - return NS_OK; - } - - *_retval = nsnull; - return NS_OK; -} - -//------------- -// nsLeafFrameAccessible -//------------- - -nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): -nsAccessible(aNode, aShell) -{ -} - -/* nsIAccessible getAccFirstChild (); */ -NS_IMETHODIMP nsLeafAccessible::GetAccFirstChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* nsIAccessible getAccLastChild (); */ -NS_IMETHODIMP nsLeafAccessible::GetAccLastChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* long getAccChildCount (); */ -NS_IMETHODIMP nsLeafAccessible::GetAccChildCount(PRInt32 *_retval) -{ - *_retval = 0; - return NS_OK; -} - - -//---------------- -// nsLinkableAccessible -//---------------- - -nsLinkableAccessible::nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): -nsAccessible(aNode, aShell), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE) -{ -} - -/* long GetAccState (); */ -NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval) -{ - nsAccessible::GetAccState(_retval); - *_retval |= STATE_READONLY | STATE_SELECTABLE; - if (IsALink()) { - *_retval |= STATE_LINKED; - if (mIsLinkVisited) - *_retval |= STATE_TRAVERSED; - } - - // Get current selection and find out if current node is in it - nsCOMPtr shell(do_QueryReferent(mPresShell)); - if (!shell) { - return NS_ERROR_FAILURE; - } - - nsCOMPtr context; - shell->GetPresContext(getter_AddRefs(context)); - nsCOMPtr content(do_QueryInterface(mDOMNode)); - nsIFrame *frame; - if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) { - nsCOMPtr selCon; - frame->GetSelectionController(context,getter_AddRefs(selCon)); - if (selCon) { - nsCOMPtr domSel; - selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)); - if (domSel) { - PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE; - domSel->ContainsNode(mDOMNode, PR_TRUE, &isSelected); - domSel->GetIsCollapsed(&isCollapsed); - if (isSelected && !isCollapsed) - *_retval |=STATE_SELECTED; - } - } - } - - // Focused? Do we implement that here or up the chain? - return NS_OK; -} - - -NS_IMETHODIMP nsLinkableAccessible::GetAccValue(nsAWritableString& _retval) -{ - if (IsALink()) { - nsCOMPtr elt(do_QueryInterface(mLinkContent)); - if (elt) - return elt->GetAttribute(NS_LITERAL_STRING("href"), _retval); - } - return NS_ERROR_FAILURE; -} - - -/* PRUint8 getAccNumActions (); */ -NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval) -{ - *_retval = 1; - return NS_OK; -} - -/* wstring getAccActionName (in PRUint8 index); */ -NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) -{ - // Action 0 (default action): Jump to link - if (index == 0) { - if (IsALink()) { - _retval = NS_LITERAL_STRING("jump"); - return NS_OK; - } - } - return NS_ERROR_FAILURE; -} - -/* void accDoAction (in PRUint8 index); */ -NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index) -{ - // Action 0 (default action): Jump to link - if (index == 0) { - if (IsALink()) { - nsCOMPtr shell(do_QueryReferent(mPresShell)); - if (!shell) { - return NS_ERROR_FAILURE; - } - - nsCOMPtr presContext; - shell->GetPresContext(getter_AddRefs(presContext)); - if (presContext) { - nsMouseEvent linkClickEvent; - linkClickEvent.eventStructType = NS_EVENT; - linkClickEvent.message = NS_MOUSE_LEFT_CLICK; - linkClickEvent.isShift = PR_FALSE; - linkClickEvent.isControl = PR_FALSE; - linkClickEvent.isAlt = PR_FALSE; - linkClickEvent.isMeta = PR_FALSE; - linkClickEvent.clickCount = 0; - linkClickEvent.widget = nsnull; - - nsEventStatus eventStatus = nsEventStatus_eIgnore; - mLinkContent->HandleDOMEvent(presContext, - &linkClickEvent, - nsnull, - NS_EVENT_FLAG_INIT, - &eventStatus); - return NS_OK; - } - } - } - return NS_ERROR_FAILURE; -} - - -PRBool nsLinkableAccessible::IsALink() -{ - if (mIsALinkCached) // Cached answer? - return mLinkContent? PR_TRUE: PR_FALSE; - - nsCOMPtr walkUpContent(do_QueryInterface(mDOMNode)); - if (walkUpContent) { - nsCOMPtr tempContent = walkUpContent; - while (walkUpContent) { - nsCOMPtr link(do_QueryInterface(walkUpContent)); - if (link) { - mLinkContent = tempContent; - mIsALinkCached = PR_TRUE; - nsLinkState linkState; - link->GetLinkState(linkState); - if (linkState == eLinkState_Visited) - mIsLinkVisited = PR_TRUE; - return PR_TRUE; - } - walkUpContent->GetParent(*getter_AddRefs(tempContent)); - walkUpContent = tempContent; - } - } - mIsALinkCached = PR_TRUE; // Cached that there is no link - return PR_FALSE; -} - diff --git a/accessible/src/base/nsAccessible.h b/accessible/src/base/nsAccessible.h index 2f6a6fa9055..41a3cdf5835 100644 --- a/accessible/src/base/nsAccessible.h +++ b/accessible/src/base/nsAccessible.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * John Gaunt (jgaunt@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -39,25 +40,23 @@ #ifndef _nsAccessible_H_ #define _nsAccessible_H_ -#include "nsISupports.h" -#include "nsGenericAccessible.h" #include "nsCOMPtr.h" -#include "nsIContent.h" +#include "nsGenericAccessible.h" +#include "nsIAccessible.h" #include "nsIDOMNode.h" -#include "nsIPresShell.h" -#include "nsIPresContext.h" -#include "nsWeakReference.h" #include "nsIFocusController.h" -#include "nsIViewManager.h" -#include "nsRect.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" #include "nsPoint.h" +#include "nsRect.h" +#include "nsWeakReference.h" #define ACCESSIBLE_BUNDLE_URL "chrome://global/locale/accessible.properties" -class nsIFrame; -class nsIDocShell; -class nsIWebShell; class nsIContent; +class nsIDocShell; +class nsIFrame; +class nsIWebShell; class nsAccessible : public nsGenericAccessible { @@ -130,44 +129,4 @@ protected: nsCOMPtr mFocusController; }; -/* Special Accessible that knows how to handle hit detection for flowing text */ -class nsHTMLBlockAccessible : public nsAccessible -{ -public: - nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval); -}; - -/* Leaf version of DOM Accessible - * has no children - */ -class nsLeafAccessible : public nsAccessible -{ - public: - nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); -}; - - -class nsLinkableAccessible : public nsAccessible -{ - public: - nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - NS_IMETHOD GetAccNumActions(PRUint8 *_retval); - NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); - NS_IMETHOD AccDoAction(PRUint8 index); - NS_IMETHOD GetAccState(PRUint32 *_retval); - NS_IMETHOD GetAccValue(nsAWritableString& _retval); - - protected: - PRBool IsALink(); - PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link - nsCOMPtr mLinkContent; - PRBool mIsLinkVisited; -}; - - #endif diff --git a/accessible/src/base/nsBaseWidgetAccessible.cpp b/accessible/src/base/nsBaseWidgetAccessible.cpp new file mode 100644 index 00000000000..df55a527ba9 --- /dev/null +++ b/accessible/src/base/nsBaseWidgetAccessible.cpp @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" +#include "nsCOMPtr.h" +#include "nsGUIEvent.h" +#include "nsIContent.h" +#include "nsIDOMElement.h" +#include "nsIFrame.h" +#include "nsILink.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsISelection.h" +#include "nsISelectionController.h" + +// ------------ +// nsBlockAccessible +// ------------ + +nsBlockAccessible::nsBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aNode, aShell) +{ +} + +/* nsIAccessible accGetAt (in long x, in long y); */ +NS_IMETHODIMP nsBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval) +{ + // We're going to find the child that contains coordinates (tx,ty) + PRInt32 x,y,w,h; + AccGetBounds(&x,&y,&w,&h); // Get bounds for this accessible + if (tx > x && tx < x + w && ty > y && ty < y + h) + { + // It's within this nsIAccessible, let's drill down + nsCOMPtr child; + nsCOMPtr smallestChild; + PRInt32 smallestArea = -1; + nsCOMPtr next; + GetAccFirstChild(getter_AddRefs(child)); + PRInt32 cx,cy,cw,ch; // Child bounds + + while(child) { + child->AccGetBounds(&cx,&cy,&cw,&ch); + + // ok if there are multiple frames the contain the point + // and they overlap then pick the smallest. We need to do this + // for text frames. + + // For example, A point that's in block #2 is also in block #1, but we want to return #2: + // + // [[block #1 is long wrapped text that continues to + // another line]] [[here is a shorter block #2]] + + if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch) + { + if (smallestArea == -1 || cw*ch < smallestArea) { + smallestArea = cw*ch; + smallestChild = child; + } + } + child->GetAccNextSibling(getter_AddRefs(next)); + child = next; + } + + if (smallestChild != nsnull) + { + *_retval = smallestChild; + NS_ADDREF(*_retval); + return NS_OK; + } + + *_retval = this; + NS_ADDREF(this); + return NS_OK; + } + + *_retval = nsnull; + return NS_OK; +} + +//------------- +// nsLeafFrameAccessible +//------------- + +nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsAccessible(aNode, aShell) +{ +} + +/* nsIAccessible getAccFirstChild (); */ +NS_IMETHODIMP nsLeafAccessible::GetAccFirstChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* nsIAccessible getAccLastChild (); */ +NS_IMETHODIMP nsLeafAccessible::GetAccLastChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* long getAccChildCount (); */ +NS_IMETHODIMP nsLeafAccessible::GetAccChildCount(PRInt32 *_retval) +{ + *_retval = 0; + return NS_OK; +} + + +//---------------- +// nsLinkableAccessible +//---------------- + +nsLinkableAccessible::nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsAccessible(aNode, aShell), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE) +{ +} + +/* long GetAccState (); */ +NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval) +{ + nsAccessible::GetAccState(_retval); + *_retval |= STATE_READONLY | STATE_SELECTABLE; + if (IsALink()) { + *_retval |= STATE_LINKED; + if (mIsLinkVisited) + *_retval |= STATE_TRAVERSED; + } + + // Get current selection and find out if current node is in it + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (!shell) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context)); + nsCOMPtr content(do_QueryInterface(mDOMNode)); + nsIFrame *frame; + if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) { + nsCOMPtr selCon; + frame->GetSelectionController(context,getter_AddRefs(selCon)); + if (selCon) { + nsCOMPtr domSel; + selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)); + if (domSel) { + PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE; + domSel->ContainsNode(mDOMNode, PR_TRUE, &isSelected); + domSel->GetIsCollapsed(&isCollapsed); + if (isSelected && !isCollapsed) + *_retval |=STATE_SELECTED; + } + } + } + + // Focused? Do we implement that here or up the chain? + return NS_OK; +} + + +NS_IMETHODIMP nsLinkableAccessible::GetAccValue(nsAWritableString& _retval) +{ + if (IsALink()) { + nsCOMPtr elt(do_QueryInterface(mLinkContent)); + if (elt) + return elt->GetAttribute(NS_LITERAL_STRING("href"), _retval); + } + return NS_ERROR_FAILURE; +} + + +/* PRUint8 getAccNumActions (); */ +NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval) +{ + *_retval = 1; + return NS_OK; +} + +/* wstring getAccActionName (in PRUint8 index); */ +NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) +{ + // Action 0 (default action): Jump to link + if (index == 0) { + if (IsALink()) { + _retval = NS_LITERAL_STRING("jump"); + return NS_OK; + } + } + return NS_ERROR_FAILURE; +} + +/* void accDoAction (in PRUint8 index); */ +NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index) +{ + // Action 0 (default action): Jump to link + if (index == 0) { + if (IsALink()) { + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (!shell) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + if (presContext) { + nsMouseEvent linkClickEvent; + linkClickEvent.eventStructType = NS_EVENT; + linkClickEvent.message = NS_MOUSE_LEFT_CLICK; + linkClickEvent.isShift = PR_FALSE; + linkClickEvent.isControl = PR_FALSE; + linkClickEvent.isAlt = PR_FALSE; + linkClickEvent.isMeta = PR_FALSE; + linkClickEvent.clickCount = 0; + linkClickEvent.widget = nsnull; + + nsEventStatus eventStatus = nsEventStatus_eIgnore; + mLinkContent->HandleDOMEvent(presContext, + &linkClickEvent, + nsnull, + NS_EVENT_FLAG_INIT, + &eventStatus); + return NS_OK; + } + } + } + return NS_ERROR_FAILURE; +} + + +PRBool nsLinkableAccessible::IsALink() +{ + if (mIsALinkCached) // Cached answer? + return mLinkContent? PR_TRUE: PR_FALSE; + + nsCOMPtr walkUpContent(do_QueryInterface(mDOMNode)); + if (walkUpContent) { + nsCOMPtr tempContent = walkUpContent; + while (walkUpContent) { + nsCOMPtr link(do_QueryInterface(walkUpContent)); + if (link) { + mLinkContent = tempContent; + mIsALinkCached = PR_TRUE; + nsLinkState linkState; + link->GetLinkState(linkState); + if (linkState == eLinkState_Visited) + mIsLinkVisited = PR_TRUE; + return PR_TRUE; + } + walkUpContent->GetParent(*getter_AddRefs(tempContent)); + walkUpContent = tempContent; + } + } + mIsALinkCached = PR_TRUE; // Cached that there is no link + return PR_FALSE; +} + +// ------------ +// Text Accessibles +// ------------ + +nsTextAccessible::nsTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): +nsLinkableAccessible(aDomNode, aShell) +{ +} + +/* unsigned long getAccRole (); */ +NS_IMETHODIMP nsTextAccessible::GetAccRole(PRUint32 *_retval) +{ + *_retval = ROLE_TEXT; + + return NS_OK; +} + +/* nsIAccessible getAccFirstChild (); */ +NS_IMETHODIMP nsTextAccessible::GetAccFirstChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* nsIAccessible getAccLastChild (); */ +NS_IMETHODIMP nsTextAccessible::GetAccLastChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* long getAccChildCount (); */ +NS_IMETHODIMP nsTextAccessible::GetAccChildCount(PRInt32 *_retval) +{ + *_retval = 0; + return NS_OK; +} diff --git a/accessible/src/base/nsBaseWidgetAccessible.h b/accessible/src/base/nsBaseWidgetAccessible.h new file mode 100644 index 00000000000..106ce5d2a0e --- /dev/null +++ b/accessible/src/base/nsBaseWidgetAccessible.h @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsBaseWidgetAccessible_H_ +#define _nsBaseWidgetAccessible_H_ + +#include "nsAccessible.h" +#include "nsIDOMNode.h" +#include "nsCOMPtr.h" +#include "nsIContent.h" + +/** + * This file contains a number of classes that are used as base + * classes for the different accessibility implementations of + * the HTML and XUL widget sets. --jgaunt + */ + +/** + * Special Accessible that knows how to handle hit detection for flowing text + */ +class nsBlockAccessible : public nsAccessible +{ +public: + nsBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval); +}; + +/** + * Leaf version of DOM Accessible -- has no children + */ +class nsLeafAccessible : public nsAccessible +{ + public: + nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); + NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); + NS_IMETHOD GetAccChildCount(PRInt32 *_retval); +}; + +/** + * A type of accessible for DOM nodes containing an href="" attribute. + * It knows how to report the state of the link ( traveled or not ) + * and can activate ( click ) the link programmatically. + */ +class nsLinkableAccessible : public nsAccessible +{ + public: + nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccNumActions(PRUint8 *_retval); + NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); + NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); + NS_IMETHOD GetAccValue(nsAWritableString& _retval); + + protected: + PRBool IsALink(); + PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link + nsCOMPtr mLinkContent; + PRBool mIsLinkVisited; +}; + +/** + * Text nodes have no children, but since double inheritance + * no-worky we have to re-impl the LeafAccessiblity blocks + * this way. + */ +class nsTextAccessible : public nsLinkableAccessible +{ + +public: + nsTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccRole(PRUint32 *_retval); + NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); + NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); + NS_IMETHOD GetAccChildCount(PRInt32 *_retval); +}; + + +#endif diff --git a/accessible/src/html/nsHTMLAreaAccessible.h b/accessible/src/html/nsHTMLAreaAccessible.h index 439c9187cc1..58c30029b9a 100644 --- a/accessible/src/html/nsHTMLAreaAccessible.h +++ b/accessible/src/html/nsHTMLAreaAccessible.h @@ -40,7 +40,7 @@ #ifndef _nsHTMLAreaAccessible_H_ #define _nsHTMLAreaAccessible_H_ -#include "nsGenericAccessible.h" +#include "nsBaseWidgetAccessible.h" #include "nsAccessible.h" /* Accessible for image map areas - must be child of image diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index 7703155efe2..164eea15c29 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -146,11 +146,6 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval) htmlFormElement->GetType(typeString); if (typeString.EqualsIgnoreCase("password")) *_retval |= STATE_PROTECTED; - } - else { - nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode)); - if (xulFormElement) - xulFormElement->GetDisabled(&disabled); } if (disabled) @@ -209,15 +204,9 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index) if (htmlCheckboxElement) { htmlCheckboxElement->GetChecked(&checked); htmlCheckboxElement->SetChecked(!checked); + return NS_OK; } - else { - nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); - if (xulCheckboxElement) { - xulCheckboxElement->GetChecked(&checked); - xulCheckboxElement->SetChecked(!checked); - } - } - return NS_OK; + return NS_ERROR_FAILURE; } return NS_ERROR_INVALID_ARG; } @@ -230,11 +219,6 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccState(PRUint32 *_retval) nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); if (htmlCheckboxElement) htmlCheckboxElement->GetChecked(&checked); - else { - nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); - if (xulCheckboxElement) - xulCheckboxElement->GetChecked(&checked); - } if (checked) *_retval |= STATE_CHECKED; @@ -370,7 +354,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(nsAWritableString& _retval) // ----- HTML 4 Button: can contain arbitrary HTML content ----- nsHTML4ButtonAccessible::nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): -nsHTMLBlockAccessible(aNode, aShell) +nsBlockAccessible(aNode, aShell) { } @@ -401,15 +385,6 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::AccDoAction(PRUint8 index) inputElement->Click(); return NS_OK; } - else - { - nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); - if ( buttonElement ) - { - buttonElement->DoCommand(); - return NS_OK; - } - } return NS_ERROR_FAILURE; } return NS_ERROR_INVALID_ARG; @@ -434,11 +409,6 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccState(PRUint32 *_retval) /* wstring getAccName (); */ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(nsAWritableString& _retval) { - nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); - if ( buttonElement ) { - return buttonElement->GetLabel(_retval); - } - nsresult rv = NS_ERROR_FAILURE; nsCOMPtr content(do_QueryInterface(mDOMNode)); diff --git a/accessible/src/html/nsHTMLFormControlAccessible.h b/accessible/src/html/nsHTMLFormControlAccessible.h index d2a4f7b785e..13ab8ceb00a 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/accessible/src/html/nsHTMLFormControlAccessible.h @@ -41,6 +41,7 @@ #define _nsHTMLFormControlAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" class nsICheckboxControlFrame; @@ -97,7 +98,7 @@ public: NS_IMETHOD AccDoAction(PRUint8 index); }; -class nsHTML4ButtonAccessible : public nsHTMLBlockAccessible +class nsHTML4ButtonAccessible : public nsBlockAccessible { public: diff --git a/accessible/src/html/nsHTMLIFrameRootAccessible.cpp b/accessible/src/html/nsHTMLIFrameRootAccessible.cpp index 037a2949527..bc3ce7c96eb 100644 --- a/accessible/src/html/nsHTMLIFrameRootAccessible.cpp +++ b/accessible/src/html/nsHTMLIFrameRootAccessible.cpp @@ -58,8 +58,8 @@ NS_INTERFACE_MAP_END_INHERITING(nsRootAccessible) NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible); NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible); -NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible); -NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible); +NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameAccessible, nsBlockAccessible); +NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameAccessible, nsBlockAccessible); NS_IMETHODIMP @@ -73,12 +73,12 @@ nsHTMLIFrameAccessible::QueryInterface(const nsIID& aIID, void** aInstancePtr) NS_IF_ADDREF(this); return NS_OK; } - return nsHTMLBlockAccessible::QueryInterface(aIID, aInstancePtr); + return nsBlockAccessible::QueryInterface(aIID, aInstancePtr); } nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *aDoc): - nsHTMLBlockAccessible(aNode, aShell), mRootAccessible(aRoot), nsDocAccessibleMixin(aDoc) + nsBlockAccessible(aNode, aShell), mRootAccessible(aRoot), nsDocAccessibleMixin(aDoc) { } diff --git a/accessible/src/html/nsHTMLIFrameRootAccessible.h b/accessible/src/html/nsHTMLIFrameRootAccessible.h index ad28a231cb3..44978c5ab5b 100644 --- a/accessible/src/html/nsHTMLIFrameRootAccessible.h +++ b/accessible/src/html/nsHTMLIFrameRootAccessible.h @@ -39,6 +39,7 @@ #ifndef _nsIFrameRootAccessible_H_ #define _nsIFrameRootAccessible_H_ +#include "nsBaseWidgetAccessible.h" #include "nsRootAccessible.h" #include "nsAccessible.h" #include "nsIAccessibleDocument.h" @@ -46,7 +47,7 @@ class nsIWebShell; class nsIWeakReference; -class nsHTMLIFrameAccessible : public nsHTMLBlockAccessible, +class nsHTMLIFrameAccessible : public nsBlockAccessible, public nsIAccessibleDocument, public nsDocAccessibleMixin { diff --git a/accessible/src/html/nsHTMLImageAccessible.h b/accessible/src/html/nsHTMLImageAccessible.h index b00ce5032c9..c55e650a00d 100644 --- a/accessible/src/html/nsHTMLImageAccessible.h +++ b/accessible/src/html/nsHTMLImageAccessible.h @@ -41,6 +41,7 @@ #define _nsHTMLImageAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" #include "nsIFrame.h" #include "nsIImageFrame.h" #include "nsIDOMHTMLMapElement.h" diff --git a/accessible/src/html/nsHTMLLinkAccessible.h b/accessible/src/html/nsHTMLLinkAccessible.h index ebfdeda4edd..05a28c87b6d 100644 --- a/accessible/src/html/nsHTMLLinkAccessible.h +++ b/accessible/src/html/nsHTMLLinkAccessible.h @@ -41,6 +41,7 @@ #define _nsHTMLLinkAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" class nsHTMLLinkAccessible : public nsLinkableAccessible { diff --git a/accessible/src/html/nsHTMLTableAccessible.cpp b/accessible/src/html/nsHTMLTableAccessible.cpp index 847561ed6bf..1aee9328d1b 100644 --- a/accessible/src/html/nsHTMLTableAccessible.cpp +++ b/accessible/src/html/nsHTMLTableAccessible.cpp @@ -42,7 +42,7 @@ #include "nsReadableUtils.h" nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsHTMLBlockAccessible(aDomNode, aShell) +nsBlockAccessible(aDomNode, aShell) { } @@ -54,7 +54,7 @@ NS_IMETHODIMP nsHTMLTableCellAccessible::GetAccRole(PRUint32 *_retval) } nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsHTMLBlockAccessible(aDomNode, aShell) +nsBlockAccessible(aDomNode, aShell) { } diff --git a/accessible/src/html/nsHTMLTableAccessible.h b/accessible/src/html/nsHTMLTableAccessible.h index 21c7ffa8a46..35eb0fb933e 100644 --- a/accessible/src/html/nsHTMLTableAccessible.h +++ b/accessible/src/html/nsHTMLTableAccessible.h @@ -41,8 +41,9 @@ #define _nsHTMLTableAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" -class nsHTMLTableCellAccessible : public nsHTMLBlockAccessible +class nsHTMLTableCellAccessible : public nsBlockAccessible { public: nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); @@ -50,7 +51,7 @@ public: }; -class nsHTMLTableAccessible : public nsHTMLBlockAccessible +class nsHTMLTableAccessible : public nsBlockAccessible { public: nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); diff --git a/accessible/src/html/nsHTMLTextAccessible.cpp b/accessible/src/html/nsHTMLTextAccessible.cpp index 8d9acc7d17f..b13dddb2960 100644 --- a/accessible/src/html/nsHTMLTextAccessible.cpp +++ b/accessible/src/html/nsHTMLTextAccessible.cpp @@ -50,51 +50,12 @@ #include "nsIDOMXULLabelElement.h" nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsLinkableAccessible(aDomNode, aShell) +nsTextAccessible(aDomNode, aShell) { } /* wstring getAccName (); */ NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(nsAWritableString& _retval) { - // handles descriptions and label XUL elements - nsCOMPtr descriptionElement(do_QueryInterface(mDOMNode)); - if (descriptionElement) { - nsCOMPtr content(do_QueryInterface(mDOMNode)); - return AppendFlatStringFromSubtree(content, &_retval); - } - // HTML elements - else { - return mDOMNode->GetNodeValue(_retval); - } - return NS_ERROR_FAILURE; -} - -/* unsigned long getAccRole (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccRole(PRUint32 *_retval) -{ - *_retval = ROLE_TEXT; - - return NS_OK; -} - -/* nsIAccessible getAccFirstChild (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccFirstChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* nsIAccessible getAccLastChild (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccLastChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* long getAccChildCount (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccChildCount(PRInt32 *_retval) -{ - *_retval = 0; - return NS_OK; + return mDOMNode->GetNodeValue(_retval); } diff --git a/accessible/src/html/nsHTMLTextAccessible.h b/accessible/src/html/nsHTMLTextAccessible.h index f5fdd847d5e..391689df547 100644 --- a/accessible/src/html/nsHTMLTextAccessible.h +++ b/accessible/src/html/nsHTMLTextAccessible.h @@ -40,20 +40,16 @@ #define _nsHTMLTextAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" class nsIWeakReference; -class nsITextControlFrame; -class nsHTMLTextAccessible : public nsLinkableAccessible +class nsHTMLTextAccessible : public nsTextAccessible { public: nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); NS_IMETHOD GetAccName(nsAWritableString& _retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); }; #endif diff --git a/accessible/src/makefile.win b/accessible/src/makefile.win index b99acdceb0e..b2c41b9fdb7 100644 --- a/accessible/src/makefile.win +++ b/accessible/src/makefile.win @@ -59,6 +59,9 @@ CPP_OBJS=\ .\$(OBJDIR)\nsHTMLLinkAccessible.obj \ .\$(OBJDIR)\nsHTMLComboboxAccessible.obj \ .\$(OBJDIR)\nsHTMLListboxAccessible.obj \ + .\$(OBJDIR)\nsXULFormControlAccessible.obj \ + .\$(OBJDIR)\nsXULTextAccessible.obj \ + .\$(OBJDIR)\nsBaseWidgetAccessible.obj \ $(NULL) EXPORTS = \ diff --git a/accessible/src/nsAccessibilityService.cpp b/accessible/src/nsAccessibilityService.cpp index ffbbceb6fb8..a7bf43919dd 100644 --- a/accessible/src/nsAccessibilityService.cpp +++ b/accessible/src/nsAccessibilityService.cpp @@ -66,6 +66,8 @@ #include "nsIDOMDocument.h" #include "nsIDOMHTMLOptionElement.h" #include "nsIDOMXULCheckboxElement.h" +#include "nsXULFormControlAccessible.h" +#include "nsXULTextAccessible.h" // IFrame #include "nsIDocShell.h" @@ -199,7 +201,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULCheckboxAccessible(nsIDOMNode *aN GetShellFromNode(aNode, getter_AddRefs(weakShell)); // reusing the HTML accessible widget and enhancing for XUL - *_retval = new nsHTMLCheckboxAccessible(aNode, weakShell); + *_retval = new nsXULCheckboxAccessible(aNode, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -267,7 +269,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULButtonAccessible(nsIDOMNode *aNod GetShellFromNode(aNode, getter_AddRefs(weakShell)); // reusing the HTML accessible widget and enhancing for XUL - *_retval = new nsHTML4ButtonAccessible(aNode, weakShell); + *_retval = new nsXULButtonAccessible(aNode, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -299,7 +301,7 @@ NS_IMETHODIMP nsAccessibilityService::CreateXULTextAccessible(nsIDOMNode *aNode, GetShellFromNode(aNode, getter_AddRefs(weakShell)); // reusing the HTML accessible widget and enhancing for XUL - *_retval = new nsHTMLTextAccessible(aNode, weakShell); + *_retval = new nsXULTextAccessible(aNode, weakShell); if (! *_retval) return NS_ERROR_OUT_OF_MEMORY; @@ -661,6 +663,18 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode, if (!aNode) return NS_ERROR_NULL_POINTER; + // ---- Is it a XUL element? -- they impl nsIAccessibleProvider via XBL + nsCOMPtr newAcc; + nsCOMPtr accProv(do_QueryInterface(aNode)); + if (accProv) { + accProv->GetAccessible(getter_AddRefs(newAcc)); + if (newAcc) { + *_retval = newAcc; + NS_ADDREF(*_retval); + return NS_OK; + } + } + // ---- Get the document for this node ---- nsCOMPtr doc; nsCOMPtr nodeIsDoc(do_QueryInterface(aNode)); @@ -710,16 +724,8 @@ NS_IMETHODIMP nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode, if (!frame) return NS_ERROR_FAILURE; - nsCOMPtr newAcc; frame->GetAccessible(getter_AddRefs(newAcc)); - // ---- Is it a XUL element? -- they impl nsIAccessibleProvider via XBL - if (!newAcc) { - nsCOMPtr accProv(do_QueryInterface(aNode)); - if (accProv) - accProv->GetAccessible(getter_AddRefs(newAcc)); - } - // ---- If link, create link accessible ---- if (!newAcc) { // is it a link? diff --git a/accessible/src/nsAccessible.cpp b/accessible/src/nsAccessible.cpp index 908ea84ca70..11138a72c05 100644 --- a/accessible/src/nsAccessible.cpp +++ b/accessible/src/nsAccessible.cpp @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * John Gaunt (jgaunt@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -48,7 +49,6 @@ #include "nsIViewManager.h" #include "nsIWidget.h" #include "nsRootAccessible.h" -#include "nsIScriptGlobalObject.h" #include "nsPIDOMWindow.h" #include "nsIDOMElement.h" #include "nsIEventStateManager.h" @@ -79,8 +79,6 @@ #include "nsStyleConsts.h" #include "nsReadableUtils.h" - - // IFrame Helpers #include "nsIDocShell.h" #include "nsIWebShell.h" @@ -1463,244 +1461,3 @@ NS_IMETHODIMP nsAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, ns } return NS_OK; } - - -// ------- nsHTMLBlockAccessible ------ - -nsHTMLBlockAccessible::nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aNode, aShell) -{ -} - -/* nsIAccessible accGetAt (in long x, in long y); */ -NS_IMETHODIMP nsHTMLBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval) -{ - // We're going to find the child that contains coordinates (tx,ty) - PRInt32 x,y,w,h; - AccGetBounds(&x,&y,&w,&h); // Get bounds for this accessible - if (tx > x && tx < x + w && ty > y && ty < y + h) - { - // It's within this nsIAccessible, let's drill down - nsCOMPtr child; - nsCOMPtr smallestChild; - PRInt32 smallestArea = -1; - nsCOMPtr next; - GetAccFirstChild(getter_AddRefs(child)); - PRInt32 cx,cy,cw,ch; // Child bounds - - while(child) { - child->AccGetBounds(&cx,&cy,&cw,&ch); - - // ok if there are multiple frames the contain the point - // and they overlap then pick the smallest. We need to do this - // for text frames. - - // For example, A point that's in block #2 is also in block #1, but we want to return #2: - // - // [[block #1 is long wrapped text that continues to - // another line]] [[here is a shorter block #2]] - - if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch) - { - if (smallestArea == -1 || cw*ch < smallestArea) { - smallestArea = cw*ch; - smallestChild = child; - } - } - child->GetAccNextSibling(getter_AddRefs(next)); - child = next; - } - - if (smallestChild != nsnull) - { - *_retval = smallestChild; - NS_ADDREF(*_retval); - return NS_OK; - } - - *_retval = this; - NS_ADDREF(this); - return NS_OK; - } - - *_retval = nsnull; - return NS_OK; -} - -//------------- -// nsLeafFrameAccessible -//------------- - -nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): -nsAccessible(aNode, aShell) -{ -} - -/* nsIAccessible getAccFirstChild (); */ -NS_IMETHODIMP nsLeafAccessible::GetAccFirstChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* nsIAccessible getAccLastChild (); */ -NS_IMETHODIMP nsLeafAccessible::GetAccLastChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* long getAccChildCount (); */ -NS_IMETHODIMP nsLeafAccessible::GetAccChildCount(PRInt32 *_retval) -{ - *_retval = 0; - return NS_OK; -} - - -//---------------- -// nsLinkableAccessible -//---------------- - -nsLinkableAccessible::nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): -nsAccessible(aNode, aShell), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE) -{ -} - -/* long GetAccState (); */ -NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval) -{ - nsAccessible::GetAccState(_retval); - *_retval |= STATE_READONLY | STATE_SELECTABLE; - if (IsALink()) { - *_retval |= STATE_LINKED; - if (mIsLinkVisited) - *_retval |= STATE_TRAVERSED; - } - - // Get current selection and find out if current node is in it - nsCOMPtr shell(do_QueryReferent(mPresShell)); - if (!shell) { - return NS_ERROR_FAILURE; - } - - nsCOMPtr context; - shell->GetPresContext(getter_AddRefs(context)); - nsCOMPtr content(do_QueryInterface(mDOMNode)); - nsIFrame *frame; - if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) { - nsCOMPtr selCon; - frame->GetSelectionController(context,getter_AddRefs(selCon)); - if (selCon) { - nsCOMPtr domSel; - selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)); - if (domSel) { - PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE; - domSel->ContainsNode(mDOMNode, PR_TRUE, &isSelected); - domSel->GetIsCollapsed(&isCollapsed); - if (isSelected && !isCollapsed) - *_retval |=STATE_SELECTED; - } - } - } - - // Focused? Do we implement that here or up the chain? - return NS_OK; -} - - -NS_IMETHODIMP nsLinkableAccessible::GetAccValue(nsAWritableString& _retval) -{ - if (IsALink()) { - nsCOMPtr elt(do_QueryInterface(mLinkContent)); - if (elt) - return elt->GetAttribute(NS_LITERAL_STRING("href"), _retval); - } - return NS_ERROR_FAILURE; -} - - -/* PRUint8 getAccNumActions (); */ -NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval) -{ - *_retval = 1; - return NS_OK; -} - -/* wstring getAccActionName (in PRUint8 index); */ -NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) -{ - // Action 0 (default action): Jump to link - if (index == 0) { - if (IsALink()) { - _retval = NS_LITERAL_STRING("jump"); - return NS_OK; - } - } - return NS_ERROR_FAILURE; -} - -/* void accDoAction (in PRUint8 index); */ -NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index) -{ - // Action 0 (default action): Jump to link - if (index == 0) { - if (IsALink()) { - nsCOMPtr shell(do_QueryReferent(mPresShell)); - if (!shell) { - return NS_ERROR_FAILURE; - } - - nsCOMPtr presContext; - shell->GetPresContext(getter_AddRefs(presContext)); - if (presContext) { - nsMouseEvent linkClickEvent; - linkClickEvent.eventStructType = NS_EVENT; - linkClickEvent.message = NS_MOUSE_LEFT_CLICK; - linkClickEvent.isShift = PR_FALSE; - linkClickEvent.isControl = PR_FALSE; - linkClickEvent.isAlt = PR_FALSE; - linkClickEvent.isMeta = PR_FALSE; - linkClickEvent.clickCount = 0; - linkClickEvent.widget = nsnull; - - nsEventStatus eventStatus = nsEventStatus_eIgnore; - mLinkContent->HandleDOMEvent(presContext, - &linkClickEvent, - nsnull, - NS_EVENT_FLAG_INIT, - &eventStatus); - return NS_OK; - } - } - } - return NS_ERROR_FAILURE; -} - - -PRBool nsLinkableAccessible::IsALink() -{ - if (mIsALinkCached) // Cached answer? - return mLinkContent? PR_TRUE: PR_FALSE; - - nsCOMPtr walkUpContent(do_QueryInterface(mDOMNode)); - if (walkUpContent) { - nsCOMPtr tempContent = walkUpContent; - while (walkUpContent) { - nsCOMPtr link(do_QueryInterface(walkUpContent)); - if (link) { - mLinkContent = tempContent; - mIsALinkCached = PR_TRUE; - nsLinkState linkState; - link->GetLinkState(linkState); - if (linkState == eLinkState_Visited) - mIsLinkVisited = PR_TRUE; - return PR_TRUE; - } - walkUpContent->GetParent(*getter_AddRefs(tempContent)); - walkUpContent = tempContent; - } - } - mIsALinkCached = PR_TRUE; // Cached that there is no link - return PR_FALSE; -} - diff --git a/accessible/src/nsAccessible.h b/accessible/src/nsAccessible.h index 2f6a6fa9055..41a3cdf5835 100644 --- a/accessible/src/nsAccessible.h +++ b/accessible/src/nsAccessible.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * John Gaunt (jgaunt@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -39,25 +40,23 @@ #ifndef _nsAccessible_H_ #define _nsAccessible_H_ -#include "nsISupports.h" -#include "nsGenericAccessible.h" #include "nsCOMPtr.h" -#include "nsIContent.h" +#include "nsGenericAccessible.h" +#include "nsIAccessible.h" #include "nsIDOMNode.h" -#include "nsIPresShell.h" -#include "nsIPresContext.h" -#include "nsWeakReference.h" #include "nsIFocusController.h" -#include "nsIViewManager.h" -#include "nsRect.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" #include "nsPoint.h" +#include "nsRect.h" +#include "nsWeakReference.h" #define ACCESSIBLE_BUNDLE_URL "chrome://global/locale/accessible.properties" -class nsIFrame; -class nsIDocShell; -class nsIWebShell; class nsIContent; +class nsIDocShell; +class nsIFrame; +class nsIWebShell; class nsAccessible : public nsGenericAccessible { @@ -130,44 +129,4 @@ protected: nsCOMPtr mFocusController; }; -/* Special Accessible that knows how to handle hit detection for flowing text */ -class nsHTMLBlockAccessible : public nsAccessible -{ -public: - nsHTMLBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval); -}; - -/* Leaf version of DOM Accessible - * has no children - */ -class nsLeafAccessible : public nsAccessible -{ - public: - nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); -}; - - -class nsLinkableAccessible : public nsAccessible -{ - public: - nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - NS_IMETHOD GetAccNumActions(PRUint8 *_retval); - NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); - NS_IMETHOD AccDoAction(PRUint8 index); - NS_IMETHOD GetAccState(PRUint32 *_retval); - NS_IMETHOD GetAccValue(nsAWritableString& _retval); - - protected: - PRBool IsALink(); - PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link - nsCOMPtr mLinkContent; - PRBool mIsLinkVisited; -}; - - #endif diff --git a/accessible/src/nsBaseWidgetAccessible.cpp b/accessible/src/nsBaseWidgetAccessible.cpp new file mode 100644 index 00000000000..df55a527ba9 --- /dev/null +++ b/accessible/src/nsBaseWidgetAccessible.cpp @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" +#include "nsCOMPtr.h" +#include "nsGUIEvent.h" +#include "nsIContent.h" +#include "nsIDOMElement.h" +#include "nsIFrame.h" +#include "nsILink.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsISelection.h" +#include "nsISelectionController.h" + +// ------------ +// nsBlockAccessible +// ------------ + +nsBlockAccessible::nsBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):nsAccessible(aNode, aShell) +{ +} + +/* nsIAccessible accGetAt (in long x, in long y); */ +NS_IMETHODIMP nsBlockAccessible::AccGetAt(PRInt32 tx, PRInt32 ty, nsIAccessible **_retval) +{ + // We're going to find the child that contains coordinates (tx,ty) + PRInt32 x,y,w,h; + AccGetBounds(&x,&y,&w,&h); // Get bounds for this accessible + if (tx > x && tx < x + w && ty > y && ty < y + h) + { + // It's within this nsIAccessible, let's drill down + nsCOMPtr child; + nsCOMPtr smallestChild; + PRInt32 smallestArea = -1; + nsCOMPtr next; + GetAccFirstChild(getter_AddRefs(child)); + PRInt32 cx,cy,cw,ch; // Child bounds + + while(child) { + child->AccGetBounds(&cx,&cy,&cw,&ch); + + // ok if there are multiple frames the contain the point + // and they overlap then pick the smallest. We need to do this + // for text frames. + + // For example, A point that's in block #2 is also in block #1, but we want to return #2: + // + // [[block #1 is long wrapped text that continues to + // another line]] [[here is a shorter block #2]] + + if (tx > cx && tx < cx + cw && ty > cy && ty < cy + ch) + { + if (smallestArea == -1 || cw*ch < smallestArea) { + smallestArea = cw*ch; + smallestChild = child; + } + } + child->GetAccNextSibling(getter_AddRefs(next)); + child = next; + } + + if (smallestChild != nsnull) + { + *_retval = smallestChild; + NS_ADDREF(*_retval); + return NS_OK; + } + + *_retval = this; + NS_ADDREF(this); + return NS_OK; + } + + *_retval = nsnull; + return NS_OK; +} + +//------------- +// nsLeafFrameAccessible +//------------- + +nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsAccessible(aNode, aShell) +{ +} + +/* nsIAccessible getAccFirstChild (); */ +NS_IMETHODIMP nsLeafAccessible::GetAccFirstChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* nsIAccessible getAccLastChild (); */ +NS_IMETHODIMP nsLeafAccessible::GetAccLastChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* long getAccChildCount (); */ +NS_IMETHODIMP nsLeafAccessible::GetAccChildCount(PRInt32 *_retval) +{ + *_retval = 0; + return NS_OK; +} + + +//---------------- +// nsLinkableAccessible +//---------------- + +nsLinkableAccessible::nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsAccessible(aNode, aShell), mIsALinkCached(PR_FALSE), mLinkContent(nsnull), mIsLinkVisited(PR_FALSE) +{ +} + +/* long GetAccState (); */ +NS_IMETHODIMP nsLinkableAccessible::GetAccState(PRUint32 *_retval) +{ + nsAccessible::GetAccState(_retval); + *_retval |= STATE_READONLY | STATE_SELECTABLE; + if (IsALink()) { + *_retval |= STATE_LINKED; + if (mIsLinkVisited) + *_retval |= STATE_TRAVERSED; + } + + // Get current selection and find out if current node is in it + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (!shell) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context)); + nsCOMPtr content(do_QueryInterface(mDOMNode)); + nsIFrame *frame; + if (content && NS_SUCCEEDED(shell->GetPrimaryFrameFor(content, &frame))) { + nsCOMPtr selCon; + frame->GetSelectionController(context,getter_AddRefs(selCon)); + if (selCon) { + nsCOMPtr domSel; + selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)); + if (domSel) { + PRBool isSelected = PR_FALSE, isCollapsed = PR_TRUE; + domSel->ContainsNode(mDOMNode, PR_TRUE, &isSelected); + domSel->GetIsCollapsed(&isCollapsed); + if (isSelected && !isCollapsed) + *_retval |=STATE_SELECTED; + } + } + } + + // Focused? Do we implement that here or up the chain? + return NS_OK; +} + + +NS_IMETHODIMP nsLinkableAccessible::GetAccValue(nsAWritableString& _retval) +{ + if (IsALink()) { + nsCOMPtr elt(do_QueryInterface(mLinkContent)); + if (elt) + return elt->GetAttribute(NS_LITERAL_STRING("href"), _retval); + } + return NS_ERROR_FAILURE; +} + + +/* PRUint8 getAccNumActions (); */ +NS_IMETHODIMP nsLinkableAccessible::GetAccNumActions(PRUint8 *_retval) +{ + *_retval = 1; + return NS_OK; +} + +/* wstring getAccActionName (in PRUint8 index); */ +NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) +{ + // Action 0 (default action): Jump to link + if (index == 0) { + if (IsALink()) { + _retval = NS_LITERAL_STRING("jump"); + return NS_OK; + } + } + return NS_ERROR_FAILURE; +} + +/* void accDoAction (in PRUint8 index); */ +NS_IMETHODIMP nsLinkableAccessible::AccDoAction(PRUint8 index) +{ + // Action 0 (default action): Jump to link + if (index == 0) { + if (IsALink()) { + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (!shell) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + if (presContext) { + nsMouseEvent linkClickEvent; + linkClickEvent.eventStructType = NS_EVENT; + linkClickEvent.message = NS_MOUSE_LEFT_CLICK; + linkClickEvent.isShift = PR_FALSE; + linkClickEvent.isControl = PR_FALSE; + linkClickEvent.isAlt = PR_FALSE; + linkClickEvent.isMeta = PR_FALSE; + linkClickEvent.clickCount = 0; + linkClickEvent.widget = nsnull; + + nsEventStatus eventStatus = nsEventStatus_eIgnore; + mLinkContent->HandleDOMEvent(presContext, + &linkClickEvent, + nsnull, + NS_EVENT_FLAG_INIT, + &eventStatus); + return NS_OK; + } + } + } + return NS_ERROR_FAILURE; +} + + +PRBool nsLinkableAccessible::IsALink() +{ + if (mIsALinkCached) // Cached answer? + return mLinkContent? PR_TRUE: PR_FALSE; + + nsCOMPtr walkUpContent(do_QueryInterface(mDOMNode)); + if (walkUpContent) { + nsCOMPtr tempContent = walkUpContent; + while (walkUpContent) { + nsCOMPtr link(do_QueryInterface(walkUpContent)); + if (link) { + mLinkContent = tempContent; + mIsALinkCached = PR_TRUE; + nsLinkState linkState; + link->GetLinkState(linkState); + if (linkState == eLinkState_Visited) + mIsLinkVisited = PR_TRUE; + return PR_TRUE; + } + walkUpContent->GetParent(*getter_AddRefs(tempContent)); + walkUpContent = tempContent; + } + } + mIsALinkCached = PR_TRUE; // Cached that there is no link + return PR_FALSE; +} + +// ------------ +// Text Accessibles +// ------------ + +nsTextAccessible::nsTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): +nsLinkableAccessible(aDomNode, aShell) +{ +} + +/* unsigned long getAccRole (); */ +NS_IMETHODIMP nsTextAccessible::GetAccRole(PRUint32 *_retval) +{ + *_retval = ROLE_TEXT; + + return NS_OK; +} + +/* nsIAccessible getAccFirstChild (); */ +NS_IMETHODIMP nsTextAccessible::GetAccFirstChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* nsIAccessible getAccLastChild (); */ +NS_IMETHODIMP nsTextAccessible::GetAccLastChild(nsIAccessible **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* long getAccChildCount (); */ +NS_IMETHODIMP nsTextAccessible::GetAccChildCount(PRInt32 *_retval) +{ + *_retval = 0; + return NS_OK; +} diff --git a/accessible/src/nsBaseWidgetAccessible.h b/accessible/src/nsBaseWidgetAccessible.h new file mode 100644 index 00000000000..106ce5d2a0e --- /dev/null +++ b/accessible/src/nsBaseWidgetAccessible.h @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsBaseWidgetAccessible_H_ +#define _nsBaseWidgetAccessible_H_ + +#include "nsAccessible.h" +#include "nsIDOMNode.h" +#include "nsCOMPtr.h" +#include "nsIContent.h" + +/** + * This file contains a number of classes that are used as base + * classes for the different accessibility implementations of + * the HTML and XUL widget sets. --jgaunt + */ + +/** + * Special Accessible that knows how to handle hit detection for flowing text + */ +class nsBlockAccessible : public nsAccessible +{ +public: + nsBlockAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD AccGetAt(PRInt32 x, PRInt32 y, nsIAccessible **_retval); +}; + +/** + * Leaf version of DOM Accessible -- has no children + */ +class nsLeafAccessible : public nsAccessible +{ + public: + nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + + NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); + NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); + NS_IMETHOD GetAccChildCount(PRInt32 *_retval); +}; + +/** + * A type of accessible for DOM nodes containing an href="" attribute. + * It knows how to report the state of the link ( traveled or not ) + * and can activate ( click ) the link programmatically. + */ +class nsLinkableAccessible : public nsAccessible +{ + public: + nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccNumActions(PRUint8 *_retval); + NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); + NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); + NS_IMETHOD GetAccValue(nsAWritableString& _retval); + + protected: + PRBool IsALink(); + PRBool mIsALinkCached; // -1 = unknown, 0 = not a link, 1 = is a link + nsCOMPtr mLinkContent; + PRBool mIsLinkVisited; +}; + +/** + * Text nodes have no children, but since double inheritance + * no-worky we have to re-impl the LeafAccessiblity blocks + * this way. + */ +class nsTextAccessible : public nsLinkableAccessible +{ + +public: + nsTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccRole(PRUint32 *_retval); + NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); + NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); + NS_IMETHOD GetAccChildCount(PRInt32 *_retval); +}; + + +#endif diff --git a/accessible/src/nsHTMLAreaAccessible.h b/accessible/src/nsHTMLAreaAccessible.h index 439c9187cc1..e69de29bb2d 100644 --- a/accessible/src/nsHTMLAreaAccessible.h +++ b/accessible/src/nsHTMLAreaAccessible.h @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Author: Aaron Leventhal (aaronl@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef _nsHTMLAreaAccessible_H_ -#define _nsHTMLAreaAccessible_H_ - -#include "nsGenericAccessible.h" -#include "nsAccessible.h" - -/* Accessible for image map areas - must be child of image - */ - -class nsHTMLAreaAccessible : public nsLinkableAccessible -{ - -public: - nsHTMLAreaAccessible(nsIDOMNode *domNode, nsIAccessible *accParent, nsIWeakReference* aShell); - NS_IMETHOD GetAccName(nsAWritableString & _retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccValue(nsAWritableString& _retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); - NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent); - NS_IMETHOD GetAccNextSibling(nsIAccessible * *aAccNextSibling); - NS_IMETHOD GetAccPreviousSibling(nsIAccessible * *aAccPreviousSibling); - NS_IMETHOD GetAccDescription(nsAWritableString& _retval); - NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height); - -protected: - nsIAccessible *CreateAreaAccessible(nsIDOMNode *aDOMNode); - nsCOMPtr mAccParent; -}; - -#endif diff --git a/accessible/src/nsHTMLComboboxAccessible.h b/accessible/src/nsHTMLComboboxAccessible.h index 39df04c471d..e69de29bb2d 100644 --- a/accessible/src/nsHTMLComboboxAccessible.h +++ b/accessible/src/nsHTMLComboboxAccessible.h @@ -1,179 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Original Author: John Gaunt (jgaunt@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef __nsHTMLComboboxAccessible_h__ -#define __nsHTMLComboboxAccessible_h__ - -#include "nsAccessible.h" -#include "nsIAccessibleSelectable.h" - -#include "nsCOMPtr.h" -#include "nsHTMLSelectListAccessible.h" -#include "nsIDOMXULListener.h" - -/* - * A class the represents the HTML Combobox widget. - */ -class nsHTMLComboboxAccessible : public nsAccessible, - public nsIAccessibleSelectable, - public nsIDOMXULListener -{ -public: - - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIACCESSIBLESELECTABLE - - nsHTMLComboboxAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell); - virtual ~nsHTMLComboboxAccessible(); - - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); - NS_IMETHOD GetAccValue(nsAWritableString& _retval); - NS_IMETHOD GetAccState(PRUint32 *_retval); - - // popup listener - NS_IMETHOD PopupShowing(nsIDOMEvent* aEvent); - NS_IMETHOD PopupShown(nsIDOMEvent* aEvent) { return NS_OK; } - NS_IMETHOD PopupHiding(nsIDOMEvent* aEvent); - NS_IMETHOD PopupHidden(nsIDOMEvent* aEvent) { return NS_OK; } - - NS_IMETHOD Close(nsIDOMEvent* aEvent); - NS_IMETHOD Command(nsIDOMEvent* aEvent) { return NS_OK; } - NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; } - NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; } - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } - - virtual void SetupMenuListener(); - -protected: - - PRBool mRegistered; - PRBool mOpen; - -}; - -/* - * A class the represents the text field in the Select to the left - * of the drop down button - */ -class nsHTMLComboboxTextFieldAccessible : public nsLeafAccessible -{ -public: - - nsHTMLComboboxTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell); - - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccParent(nsIAccessible **_retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccValue(nsAWritableString& _retval); - NS_IMETHOD GetAccState(PRUint32 *_retval); - - virtual void GetBounds(nsRect& aBounds, nsIFrame** aBoundingFrame); - -protected: - - nsCOMPtr mParent; -}; - -/** - * A class that represents the button inside the Select to the - * right of the text field - */ -class nsHTMLComboboxButtonAccessible : public nsAccessible -{ -public: - - enum { eAction_Click=0 }; - - nsHTMLComboboxButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell); - - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccParent(nsIAccessible **_retval); - NS_IMETHOD GetAccName(nsAWritableString& _retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); - NS_IMETHOD GetAccNumActions(PRUint8 *_retval); - NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); - NS_IMETHOD AccDoAction(PRUint8 index); - NS_IMETHOD GetAccState(PRUint32 *_retval); - - virtual void GetBounds(nsRect& aBounds, nsIFrame** aBoundingFrame); - -protected: - - nsCOMPtr mParent; -}; - -/* - * A class that represents the window that lives to the right - * of the drop down button inside the Select. This is the window - * that is made visible when the button is pressed. - */ -class nsHTMLComboboxWindowAccessible : public nsAccessible -{ -public: - - nsHTMLComboboxWindowAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell); - - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetAccParent(nsIAccessible **_retval); - NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccState(PRUint32 *_retval); - - virtual void GetBounds(nsRect& aBounds, nsIFrame** aBoundingFrame); - -protected: - - nsCOMPtr mParent; -}; - -#endif diff --git a/accessible/src/nsHTMLFormControlAccessible.cpp b/accessible/src/nsHTMLFormControlAccessible.cpp index 7703155efe2..164eea15c29 100644 --- a/accessible/src/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/nsHTMLFormControlAccessible.cpp @@ -146,11 +146,6 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval) htmlFormElement->GetType(typeString); if (typeString.EqualsIgnoreCase("password")) *_retval |= STATE_PROTECTED; - } - else { - nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode)); - if (xulFormElement) - xulFormElement->GetDisabled(&disabled); } if (disabled) @@ -209,15 +204,9 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index) if (htmlCheckboxElement) { htmlCheckboxElement->GetChecked(&checked); htmlCheckboxElement->SetChecked(!checked); + return NS_OK; } - else { - nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); - if (xulCheckboxElement) { - xulCheckboxElement->GetChecked(&checked); - xulCheckboxElement->SetChecked(!checked); - } - } - return NS_OK; + return NS_ERROR_FAILURE; } return NS_ERROR_INVALID_ARG; } @@ -230,11 +219,6 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccState(PRUint32 *_retval) nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); if (htmlCheckboxElement) htmlCheckboxElement->GetChecked(&checked); - else { - nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); - if (xulCheckboxElement) - xulCheckboxElement->GetChecked(&checked); - } if (checked) *_retval |= STATE_CHECKED; @@ -370,7 +354,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccName(nsAWritableString& _retval) // ----- HTML 4 Button: can contain arbitrary HTML content ----- nsHTML4ButtonAccessible::nsHTML4ButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): -nsHTMLBlockAccessible(aNode, aShell) +nsBlockAccessible(aNode, aShell) { } @@ -401,15 +385,6 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::AccDoAction(PRUint8 index) inputElement->Click(); return NS_OK; } - else - { - nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); - if ( buttonElement ) - { - buttonElement->DoCommand(); - return NS_OK; - } - } return NS_ERROR_FAILURE; } return NS_ERROR_INVALID_ARG; @@ -434,11 +409,6 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccState(PRUint32 *_retval) /* wstring getAccName (); */ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccName(nsAWritableString& _retval) { - nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); - if ( buttonElement ) { - return buttonElement->GetLabel(_retval); - } - nsresult rv = NS_ERROR_FAILURE; nsCOMPtr content(do_QueryInterface(mDOMNode)); diff --git a/accessible/src/nsHTMLFormControlAccessible.h b/accessible/src/nsHTMLFormControlAccessible.h index d2a4f7b785e..13ab8ceb00a 100644 --- a/accessible/src/nsHTMLFormControlAccessible.h +++ b/accessible/src/nsHTMLFormControlAccessible.h @@ -41,6 +41,7 @@ #define _nsHTMLFormControlAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" class nsICheckboxControlFrame; @@ -97,7 +98,7 @@ public: NS_IMETHOD AccDoAction(PRUint8 index); }; -class nsHTML4ButtonAccessible : public nsHTMLBlockAccessible +class nsHTML4ButtonAccessible : public nsBlockAccessible { public: diff --git a/accessible/src/nsHTMLIFrameRootAccessible.cpp b/accessible/src/nsHTMLIFrameRootAccessible.cpp index 037a2949527..bc3ce7c96eb 100644 --- a/accessible/src/nsHTMLIFrameRootAccessible.cpp +++ b/accessible/src/nsHTMLIFrameRootAccessible.cpp @@ -58,8 +58,8 @@ NS_INTERFACE_MAP_END_INHERITING(nsRootAccessible) NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible); NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameRootAccessible, nsRootAccessible); -NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible); -NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameAccessible, nsHTMLBlockAccessible); +NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameAccessible, nsBlockAccessible); +NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameAccessible, nsBlockAccessible); NS_IMETHODIMP @@ -73,12 +73,12 @@ nsHTMLIFrameAccessible::QueryInterface(const nsIID& aIID, void** aInstancePtr) NS_IF_ADDREF(this); return NS_OK; } - return nsHTMLBlockAccessible::QueryInterface(aIID, aInstancePtr); + return nsBlockAccessible::QueryInterface(aIID, aInstancePtr); } nsHTMLIFrameAccessible::nsHTMLIFrameAccessible(nsIDOMNode* aNode, nsIAccessible* aRoot, nsIWeakReference* aShell, nsIDocument *aDoc): - nsHTMLBlockAccessible(aNode, aShell), mRootAccessible(aRoot), nsDocAccessibleMixin(aDoc) + nsBlockAccessible(aNode, aShell), mRootAccessible(aRoot), nsDocAccessibleMixin(aDoc) { } diff --git a/accessible/src/nsHTMLIFrameRootAccessible.h b/accessible/src/nsHTMLIFrameRootAccessible.h index ad28a231cb3..44978c5ab5b 100644 --- a/accessible/src/nsHTMLIFrameRootAccessible.h +++ b/accessible/src/nsHTMLIFrameRootAccessible.h @@ -39,6 +39,7 @@ #ifndef _nsIFrameRootAccessible_H_ #define _nsIFrameRootAccessible_H_ +#include "nsBaseWidgetAccessible.h" #include "nsRootAccessible.h" #include "nsAccessible.h" #include "nsIAccessibleDocument.h" @@ -46,7 +47,7 @@ class nsIWebShell; class nsIWeakReference; -class nsHTMLIFrameAccessible : public nsHTMLBlockAccessible, +class nsHTMLIFrameAccessible : public nsBlockAccessible, public nsIAccessibleDocument, public nsDocAccessibleMixin { diff --git a/accessible/src/nsHTMLImageAccessible.h b/accessible/src/nsHTMLImageAccessible.h index b00ce5032c9..e69de29bb2d 100644 --- a/accessible/src/nsHTMLImageAccessible.h +++ b/accessible/src/nsHTMLImageAccessible.h @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Author: Aaron Leventhal (aaronl@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef _nsHTMLImageAccessible_H_ -#define _nsHTMLImageAccessible_H_ - -#include "nsAccessible.h" -#include "nsIFrame.h" -#include "nsIImageFrame.h" -#include "nsIDOMHTMLMapElement.h" - -/* Accessible for supporting images - * supports: - * - gets name, role - * - support basic state - */ -class nsHTMLImageAccessible : public nsLinkableAccessible -{ - -public: - nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetAccName(nsAWritableString& _retval); - NS_IMETHOD GetAccState(PRUint32 *_retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); - -protected: - nsIAccessible *CreateAreaAccessible(PRUint32 areaNum); - nsCOMPtr mMapElement; -}; - -#endif diff --git a/accessible/src/nsHTMLLinkAccessible.h b/accessible/src/nsHTMLLinkAccessible.h index ebfdeda4edd..e69de29bb2d 100644 --- a/accessible/src/nsHTMLLinkAccessible.h +++ b/accessible/src/nsHTMLLinkAccessible.h @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Author: Aaron Leventhal (aaronl@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef _nsHTMLLinkAccessible_H_ -#define _nsHTMLLinkAccessible_H_ - -#include "nsAccessible.h" - -class nsHTMLLinkAccessible : public nsLinkableAccessible -{ - -public: - nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetAccName(nsAWritableString& _retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); -}; - -#endif diff --git a/accessible/src/nsHTMLSelectListAccessible.h b/accessible/src/nsHTMLSelectListAccessible.h index 93911a9cf4f..e69de29bb2d 100644 --- a/accessible/src/nsHTMLSelectListAccessible.h +++ b/accessible/src/nsHTMLSelectListAccessible.h @@ -1,94 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Original Author: Eric Vaughan (evaughan@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef __nsHTMLSelectListAccessible_h__ -#define __nsHTMLSelectListAccessible_h__ - -#include "nsAccessible.h" - -#include "nsCOMPtr.h" - -/* - * The list that contains all the options in the select. - */ -class nsHTMLSelectListAccessible : public nsAccessible -{ -public: - - nsHTMLSelectListAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell); - virtual ~nsHTMLSelectListAccessible() {} - - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetAccParent(nsIAccessible **_retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval); - NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccState(PRUint32 *_retval); - -protected: - - nsCOMPtr mParent; -}; - -/* - * Options inside the select, contained within the list - */ -class nsHTMLSelectOptionAccessible : public nsLeafAccessible -{ -public: - - nsHTMLSelectOptionAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell); - - /* ----- nsIAccessible ----- */ - NS_IMETHOD GetAccParent(nsIAccessible **_retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval); - NS_IMETHOD GetAccName(nsAWritableString& _retval); - NS_IMETHOD GetAccState(PRUint32 *_retval); - static nsresult GetFocusedOptionNode(nsIWeakReference *aPresShell, nsIDOMNode *aListNode, nsCOMPtr& aFocusedOptionNode); - -protected: - - nsCOMPtr mParent; -}; - -#endif diff --git a/accessible/src/nsHTMLTableAccessible.cpp b/accessible/src/nsHTMLTableAccessible.cpp index 847561ed6bf..e69de29bb2d 100644 --- a/accessible/src/nsHTMLTableAccessible.cpp +++ b/accessible/src/nsHTMLTableAccessible.cpp @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Author: Aaron Leventhal (aaronl@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsHTMLTableAccessible.h" -#include "nsWeakReference.h" -#include "nsReadableUtils.h" - -nsHTMLTableCellAccessible::nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsHTMLBlockAccessible(aDomNode, aShell) -{ -} - -/* unsigned long getAccRole (); */ -NS_IMETHODIMP nsHTMLTableCellAccessible::GetAccRole(PRUint32 *_retval) -{ - *_retval = ROLE_CELL; - return NS_OK; -} - -nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsHTMLBlockAccessible(aDomNode, aShell) -{ -} - -/* unsigned long getAccRole (); */ -NS_IMETHODIMP nsHTMLTableAccessible::GetAccRole(PRUint32 *_retval) -{ - *_retval = ROLE_TABLE; - return NS_OK; -} - diff --git a/accessible/src/nsHTMLTableAccessible.h b/accessible/src/nsHTMLTableAccessible.h index 21c7ffa8a46..e69de29bb2d 100644 --- a/accessible/src/nsHTMLTableAccessible.h +++ b/accessible/src/nsHTMLTableAccessible.h @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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 the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Author: Aaron Leventhal (aaronl@netscape.com) - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef _nsHTMLTableAccessible_H_ -#define _nsHTMLTableAccessible_H_ - -#include "nsAccessible.h" - -class nsHTMLTableCellAccessible : public nsHTMLBlockAccessible -{ -public: - nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetAccRole(PRUint32 *_retval); -}; - - -class nsHTMLTableAccessible : public nsHTMLBlockAccessible -{ -public: - nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); - NS_IMETHOD GetAccRole(PRUint32 *_retval); -}; - -#endif diff --git a/accessible/src/nsHTMLTextAccessible.cpp b/accessible/src/nsHTMLTextAccessible.cpp index 8d9acc7d17f..b13dddb2960 100644 --- a/accessible/src/nsHTMLTextAccessible.cpp +++ b/accessible/src/nsHTMLTextAccessible.cpp @@ -50,51 +50,12 @@ #include "nsIDOMXULLabelElement.h" nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsLinkableAccessible(aDomNode, aShell) +nsTextAccessible(aDomNode, aShell) { } /* wstring getAccName (); */ NS_IMETHODIMP nsHTMLTextAccessible::GetAccName(nsAWritableString& _retval) { - // handles descriptions and label XUL elements - nsCOMPtr descriptionElement(do_QueryInterface(mDOMNode)); - if (descriptionElement) { - nsCOMPtr content(do_QueryInterface(mDOMNode)); - return AppendFlatStringFromSubtree(content, &_retval); - } - // HTML elements - else { - return mDOMNode->GetNodeValue(_retval); - } - return NS_ERROR_FAILURE; -} - -/* unsigned long getAccRole (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccRole(PRUint32 *_retval) -{ - *_retval = ROLE_TEXT; - - return NS_OK; -} - -/* nsIAccessible getAccFirstChild (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccFirstChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* nsIAccessible getAccLastChild (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccLastChild(nsIAccessible **_retval) -{ - *_retval = nsnull; - return NS_OK; -} - -/* long getAccChildCount (); */ -NS_IMETHODIMP nsHTMLTextAccessible::GetAccChildCount(PRInt32 *_retval) -{ - *_retval = 0; - return NS_OK; + return mDOMNode->GetNodeValue(_retval); } diff --git a/accessible/src/nsHTMLTextAccessible.h b/accessible/src/nsHTMLTextAccessible.h index f5fdd847d5e..391689df547 100644 --- a/accessible/src/nsHTMLTextAccessible.h +++ b/accessible/src/nsHTMLTextAccessible.h @@ -40,20 +40,16 @@ #define _nsHTMLTextAccessible_H_ #include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" class nsIWeakReference; -class nsITextControlFrame; -class nsHTMLTextAccessible : public nsLinkableAccessible +class nsHTMLTextAccessible : public nsTextAccessible { public: nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); NS_IMETHOD GetAccName(nsAWritableString& _retval); - NS_IMETHOD GetAccRole(PRUint32 *_retval); - NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval); - NS_IMETHOD GetAccLastChild(nsIAccessible **_retval); - NS_IMETHOD GetAccChildCount(PRInt32 *_retval); }; #endif diff --git a/accessible/src/nsXULFormControlAccessible.cpp b/accessible/src/nsXULFormControlAccessible.cpp new file mode 100644 index 00000000000..41427df2119 --- /dev/null +++ b/accessible/src/nsXULFormControlAccessible.cpp @@ -0,0 +1,326 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// NOTE: alphabetically ordered +#include "nsIDocument.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMXULButtonElement.h" +#include "nsIDOMXULCheckboxElement.h" +#include "nsIDOMXULDocument.h" +#include "nsReadableUtils.h" +#include "nsString.h" +#include "nsXULFormControlAccessible.h" + +// ----- XUL Form Control accessible -------- + +nsXULFormControlAccessible::nsXULFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsLeafAccessible(aNode, aShell) +{ +} + +/** + * Checks the label's value first then makes a call to get the + * text from the children if the value is not set. + */ +NS_IMETHODIMP nsXULFormControlAccessible::AppendLabelText(nsIDOMNode *aLabelNode, nsAWritableString& _retval) +{ + NS_ASSERTION(aLabelNode, "Label Node passed in is null"); + nsCOMPtr labelNode(do_QueryInterface(aLabelNode)); + // label's value="foo" is set + if ( labelNode && NS_SUCCEEDED(labelNode->GetValue(_retval))) { + if (_retval.IsEmpty()) { + // label contains children who define it's text -- possibly HTML + nsCOMPtr content(do_QueryInterface(labelNode)); + if (content) + return AppendFlatStringFromSubtree(content, &_retval); + } + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +/** + * 3 main cases for Xul Controls to be labeled + * 1 - control contains label="foo" + * 2 - control has, as a child, a label element + * - label has either value="foo" or children + * 3 - non-child label contains control="controlID" + * - label has either value="foo" or children + * Once a label is found, the search is discontinued, so a control + * that has a label child as well as having a label external to + * the control that uses the control="controlID" syntax will use + * the child label for its Name. + */ +/* wstring getAccName (); */ +NS_IMETHODIMP nsXULFormControlAccessible::GetAccName(nsAWritableString& _retval) +{ + nsresult rv; + nsAutoString label; + + // CASE #1 -- great majority of the cases + nsCOMPtr domElement(do_QueryInterface(mDOMNode)); + NS_ASSERTION(domElement, "No domElement for accessible DOM node!"); + rv = domElement->GetAttribute(NS_LITERAL_STRING("label"), label) ; + + if (NS_FAILED(rv) || label.IsEmpty() ) { + + // CASE #2 ------ label as a child + nsCOMPtrlabelChildren; + NS_ASSERTION(domElement, "No domElement for accessible DOM node!"); + if (NS_SUCCEEDED(rv = domElement->GetElementsByTagName(NS_LITERAL_STRING("label"), getter_AddRefs(labelChildren)))) { + PRUint32 length = 0; + if (NS_SUCCEEDED(rv = labelChildren->GetLength(&length)) && length > 0) { + for (PRUint32 i = 0; i < length; ++i) { + nsCOMPtr child; + if (NS_SUCCEEDED(rv = labelChildren->Item(i, getter_AddRefs(child) ))) { + rv = AppendLabelText(child, label); + } + } + } + } + + if (NS_FAILED(rv) || label.IsEmpty()) { + + // CASE #3 ----- non-child label pointing to control + // XXX jgaunt + // decided to search the parent's children for labels linked to + // this control via the control="controlID" syntax, instead of searching + // the entire document with: + // + // nsCOMPtr doc; + // nsCOMPtr content(do_QueryInterface(mDOMNode)); + // content->GetDocument(*getter_AddRefs(doc)); + // nsCOMPtr xulDoc(do_QueryInterface(doc)); + // if (xulDoc) { + // nsCOMPtrlabelList; + // if (NS_SUCCEEDED(rv = xulDoc->GetElementsByAttribute(NS_LITERAL_STRING("control"), controlID, getter_AddRefs(labelList)))) + // + // This should keep search times down and still get the relevant + // labels. + nsCOMPtr parent; + if (NS_SUCCEEDED(rv = mDOMNode->GetParentNode(getter_AddRefs(parent)))) { + nsCOMPtr xulElement(do_QueryInterface(parent)); + NS_ASSERTION(xulElement, "No xulElement for parent DOM Node!"); + if (xulElement) { + nsAutoString controlID; + nsCOMPtrlabelList; + if (NS_SUCCEEDED(rv = xulElement->GetElementsByAttribute(NS_LITERAL_STRING("control"), controlID, getter_AddRefs(labelList)))) + { + PRUint32 length = 0; + if (NS_SUCCEEDED(rv = labelList->GetLength(&length)) && length > 0) { + for (PRUint32 i = 0; i < length; ++i) { + nsCOMPtr child; + if (NS_SUCCEEDED(rv = labelList->Item(i, getter_AddRefs(child) ))) { + rv = AppendLabelText(child, label); + } + } + } + } + } + } // End of CASE #3 + } // END of CASE #2 + } // END of CASE #1 + + label.CompressWhitespace(); + if (label.IsEmpty()) + return nsAccessible::GetAccName(_retval); + + _retval.Assign(label); + return NS_OK; +} + +/** + * XUL Form controls can be focusable, focused, unavailable, ?protected? + **/ +NS_IMETHODIMP nsXULFormControlAccessible::GetAccState(PRUint32 *_retval) +{ + // Get the focused state from the nsAccessible + nsAccessible::GetAccState(_retval); + + PRBool disabled = PR_FALSE; + nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode)); + if (xulFormElement) + xulFormElement->GetDisabled(&disabled); + + if (disabled) + *_retval |= STATE_UNAVAILABLE; + else + *_retval |= STATE_FOCUSABLE; + + return NS_OK; +} + +// ----- XUL Button: can contain arbitrary HTML content ----- + +nsXULButtonAccessible::nsXULButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsBlockAccessible(aNode, aShell) +{ +} + +/* PRUint8 getAccNumActions (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccNumActions(PRUint8 *_retval) +{ + *_retval = 1; + return NS_OK;; +} + +/* wstring getAccActionName (in PRUint8 index); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) +{ + if (index == 0) { + _retval = NS_LITERAL_STRING("press"); + return NS_OK; + } + return NS_ERROR_INVALID_ARG; +} + +/* void accDoAction (in PRUint8 index); */ +NS_IMETHODIMP nsXULButtonAccessible::AccDoAction(PRUint8 index) +{ + if (index == 0) { + nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); + if ( buttonElement ) + { + buttonElement->DoCommand(); + return NS_OK; + } + return NS_ERROR_FAILURE; + } + return NS_ERROR_INVALID_ARG; +} + +/* unsigned long getAccRole (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccRole(PRUint32 *_retval) +{ + *_retval = ROLE_PUSHBUTTON; + return NS_OK; +} + +/* long getAccState (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccState(PRUint32 *_retval) +{ + nsAccessible::GetAccState(_retval); + *_retval |= STATE_FOCUSABLE; + return NS_OK; +} + + +/* wstring getAccName (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccName(nsAWritableString& _retval) +{ + nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); + if ( buttonElement ) { + return buttonElement->GetLabel(_retval); + } + return NS_ERROR_FAILURE; +} + +// --- XUL checkbox ----- + +nsXULCheckboxAccessible::nsXULCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsXULFormControlAccessible(aNode, aShell) +{ +} + +/* unsigned long getAccRole (); */ +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccRole(PRUint32 *_retval) +{ + *_retval = ROLE_CHECKBUTTON; + return NS_OK; +} + +/* PRUint8 getAccNumActions (); */ +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccNumActions(PRUint8 *_retval) +{ + *_retval = 1; + return NS_OK; +} + +/* wstring getAccActionName (in PRUint8 index); */ +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) +{ + if (index == 0) { // 0 is the magic value for default action + // check or uncheck + PRUint32 state; + GetAccState(&state); + + if (state & STATE_CHECKED) + _retval = NS_LITERAL_STRING("uncheck"); + else + _retval = NS_LITERAL_STRING("check"); + + return NS_OK; + } + return NS_ERROR_INVALID_ARG; +} + +/* void accDoAction (in PRUint8 index); */ +NS_IMETHODIMP nsXULCheckboxAccessible::AccDoAction(PRUint8 index) +{ + if (index == 0) { // 0 is the magic value for default action + PRBool checked = PR_FALSE; + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) { + xulCheckboxElement->GetChecked(&checked); + xulCheckboxElement->SetChecked(!checked); + return NS_OK; + } + return NS_ERROR_FAILURE; + } + return NS_ERROR_INVALID_ARG; +} + +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccState(PRUint32 *_retval) +{ + // Get focus state from parent + nsXULFormControlAccessible::GetAccState(_retval); + + // Determine Checked state + PRBool checked = PR_FALSE; + + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) + xulCheckboxElement->GetChecked(&checked); + + if (checked) + *_retval |= STATE_CHECKED; + + return NS_OK; +} + diff --git a/accessible/src/nsXULFormControlAccessible.h b/accessible/src/nsXULFormControlAccessible.h new file mode 100644 index 00000000000..8e722e29ddb --- /dev/null +++ b/accessible/src/nsXULFormControlAccessible.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsXULFormControlAccessible_H_ +#define _nsXULFormControlAccessible_H_ + +// NOTE: alphabetically ordered +#include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" +#include "nsHTMLFormControlAccessible.h" +#include "nsIDOMXULLabelElement.h" + +/* Accessible for supporting for controls + * supports: + * - walking up to get name from label + * - support basic state + */ +class nsXULFormControlAccessible : public nsLeafAccessible +{ +public: + nsXULFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccName(nsAWritableString& _retval); + NS_IMETHOD GetAccState(PRUint32 *_retval); + +protected: + NS_IMETHODIMP AppendLabelText(nsIDOMNode *aLabelNode, nsAWritableString& _retval); +}; + +class nsXULButtonAccessible : public nsBlockAccessible +{ +public: + nsXULButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccRole(PRUint32 *_retval); + NS_IMETHOD GetAccName(nsAWritableString& _retval); + NS_IMETHOD GetAccState(PRUint32 *_retval); + NS_IMETHOD GetAccNumActions(PRUint8 *_retval); + NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); + NS_IMETHOD AccDoAction(PRUint8 index); +}; + +class nsXULCheckboxAccessible : public nsXULFormControlAccessible +{ +public: + nsXULCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccRole(PRUint32 *_retval); + NS_IMETHOD GetAccNumActions(PRUint8 *_retval); + NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); + NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); +}; + +#endif diff --git a/accessible/src/nsXULTextAccessible.cpp b/accessible/src/nsXULTextAccessible.cpp new file mode 100644 index 00000000000..90de5609af1 --- /dev/null +++ b/accessible/src/nsXULTextAccessible.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// NOTE: alphabetically ordered +#include "nsIDOMXULDescriptionElement.h" +#include "nsIDOMXULLabelElement.h" +#include "nsWeakReference.h" +#include "nsXULTextAccessible.h" + +/** + * For XUL descriptions and labels + */ +nsXULTextAccessible::nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): +nsTextAccessible(aDomNode, aShell) +{ +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsXULTextAccessible::GetAccName(nsAWritableString& _retval) +{ + nsCOMPtr descriptionElement(do_QueryInterface(mDOMNode)); + if (descriptionElement) { + nsCOMPtr content(do_QueryInterface(mDOMNode)); + return AppendFlatStringFromSubtree(content, &_retval); + } + return NS_ERROR_FAILURE; +} diff --git a/accessible/src/nsXULTextAccessible.h b/accessible/src/nsXULTextAccessible.h new file mode 100644 index 00000000000..fad3d2f796e --- /dev/null +++ b/accessible/src/nsXULTextAccessible.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsXULTextAccessible_H_ +#define _nsXULTextAccessible_H_ + +#include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" + +class nsIWeakReference; + +class nsXULTextAccessible : public nsTextAccessible +{ + +public: + nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccName(nsAWritableString& _retval); +}; + +#endif diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp new file mode 100644 index 00000000000..41427df2119 --- /dev/null +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -0,0 +1,326 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// NOTE: alphabetically ordered +#include "nsIDocument.h" +#include "nsIDOMNodeList.h" +#include "nsIDOMXULButtonElement.h" +#include "nsIDOMXULCheckboxElement.h" +#include "nsIDOMXULDocument.h" +#include "nsReadableUtils.h" +#include "nsString.h" +#include "nsXULFormControlAccessible.h" + +// ----- XUL Form Control accessible -------- + +nsXULFormControlAccessible::nsXULFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsLeafAccessible(aNode, aShell) +{ +} + +/** + * Checks the label's value first then makes a call to get the + * text from the children if the value is not set. + */ +NS_IMETHODIMP nsXULFormControlAccessible::AppendLabelText(nsIDOMNode *aLabelNode, nsAWritableString& _retval) +{ + NS_ASSERTION(aLabelNode, "Label Node passed in is null"); + nsCOMPtr labelNode(do_QueryInterface(aLabelNode)); + // label's value="foo" is set + if ( labelNode && NS_SUCCEEDED(labelNode->GetValue(_retval))) { + if (_retval.IsEmpty()) { + // label contains children who define it's text -- possibly HTML + nsCOMPtr content(do_QueryInterface(labelNode)); + if (content) + return AppendFlatStringFromSubtree(content, &_retval); + } + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +/** + * 3 main cases for Xul Controls to be labeled + * 1 - control contains label="foo" + * 2 - control has, as a child, a label element + * - label has either value="foo" or children + * 3 - non-child label contains control="controlID" + * - label has either value="foo" or children + * Once a label is found, the search is discontinued, so a control + * that has a label child as well as having a label external to + * the control that uses the control="controlID" syntax will use + * the child label for its Name. + */ +/* wstring getAccName (); */ +NS_IMETHODIMP nsXULFormControlAccessible::GetAccName(nsAWritableString& _retval) +{ + nsresult rv; + nsAutoString label; + + // CASE #1 -- great majority of the cases + nsCOMPtr domElement(do_QueryInterface(mDOMNode)); + NS_ASSERTION(domElement, "No domElement for accessible DOM node!"); + rv = domElement->GetAttribute(NS_LITERAL_STRING("label"), label) ; + + if (NS_FAILED(rv) || label.IsEmpty() ) { + + // CASE #2 ------ label as a child + nsCOMPtrlabelChildren; + NS_ASSERTION(domElement, "No domElement for accessible DOM node!"); + if (NS_SUCCEEDED(rv = domElement->GetElementsByTagName(NS_LITERAL_STRING("label"), getter_AddRefs(labelChildren)))) { + PRUint32 length = 0; + if (NS_SUCCEEDED(rv = labelChildren->GetLength(&length)) && length > 0) { + for (PRUint32 i = 0; i < length; ++i) { + nsCOMPtr child; + if (NS_SUCCEEDED(rv = labelChildren->Item(i, getter_AddRefs(child) ))) { + rv = AppendLabelText(child, label); + } + } + } + } + + if (NS_FAILED(rv) || label.IsEmpty()) { + + // CASE #3 ----- non-child label pointing to control + // XXX jgaunt + // decided to search the parent's children for labels linked to + // this control via the control="controlID" syntax, instead of searching + // the entire document with: + // + // nsCOMPtr doc; + // nsCOMPtr content(do_QueryInterface(mDOMNode)); + // content->GetDocument(*getter_AddRefs(doc)); + // nsCOMPtr xulDoc(do_QueryInterface(doc)); + // if (xulDoc) { + // nsCOMPtrlabelList; + // if (NS_SUCCEEDED(rv = xulDoc->GetElementsByAttribute(NS_LITERAL_STRING("control"), controlID, getter_AddRefs(labelList)))) + // + // This should keep search times down and still get the relevant + // labels. + nsCOMPtr parent; + if (NS_SUCCEEDED(rv = mDOMNode->GetParentNode(getter_AddRefs(parent)))) { + nsCOMPtr xulElement(do_QueryInterface(parent)); + NS_ASSERTION(xulElement, "No xulElement for parent DOM Node!"); + if (xulElement) { + nsAutoString controlID; + nsCOMPtrlabelList; + if (NS_SUCCEEDED(rv = xulElement->GetElementsByAttribute(NS_LITERAL_STRING("control"), controlID, getter_AddRefs(labelList)))) + { + PRUint32 length = 0; + if (NS_SUCCEEDED(rv = labelList->GetLength(&length)) && length > 0) { + for (PRUint32 i = 0; i < length; ++i) { + nsCOMPtr child; + if (NS_SUCCEEDED(rv = labelList->Item(i, getter_AddRefs(child) ))) { + rv = AppendLabelText(child, label); + } + } + } + } + } + } // End of CASE #3 + } // END of CASE #2 + } // END of CASE #1 + + label.CompressWhitespace(); + if (label.IsEmpty()) + return nsAccessible::GetAccName(_retval); + + _retval.Assign(label); + return NS_OK; +} + +/** + * XUL Form controls can be focusable, focused, unavailable, ?protected? + **/ +NS_IMETHODIMP nsXULFormControlAccessible::GetAccState(PRUint32 *_retval) +{ + // Get the focused state from the nsAccessible + nsAccessible::GetAccState(_retval); + + PRBool disabled = PR_FALSE; + nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode)); + if (xulFormElement) + xulFormElement->GetDisabled(&disabled); + + if (disabled) + *_retval |= STATE_UNAVAILABLE; + else + *_retval |= STATE_FOCUSABLE; + + return NS_OK; +} + +// ----- XUL Button: can contain arbitrary HTML content ----- + +nsXULButtonAccessible::nsXULButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsBlockAccessible(aNode, aShell) +{ +} + +/* PRUint8 getAccNumActions (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccNumActions(PRUint8 *_retval) +{ + *_retval = 1; + return NS_OK;; +} + +/* wstring getAccActionName (in PRUint8 index); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) +{ + if (index == 0) { + _retval = NS_LITERAL_STRING("press"); + return NS_OK; + } + return NS_ERROR_INVALID_ARG; +} + +/* void accDoAction (in PRUint8 index); */ +NS_IMETHODIMP nsXULButtonAccessible::AccDoAction(PRUint8 index) +{ + if (index == 0) { + nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); + if ( buttonElement ) + { + buttonElement->DoCommand(); + return NS_OK; + } + return NS_ERROR_FAILURE; + } + return NS_ERROR_INVALID_ARG; +} + +/* unsigned long getAccRole (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccRole(PRUint32 *_retval) +{ + *_retval = ROLE_PUSHBUTTON; + return NS_OK; +} + +/* long getAccState (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccState(PRUint32 *_retval) +{ + nsAccessible::GetAccState(_retval); + *_retval |= STATE_FOCUSABLE; + return NS_OK; +} + + +/* wstring getAccName (); */ +NS_IMETHODIMP nsXULButtonAccessible::GetAccName(nsAWritableString& _retval) +{ + nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); + if ( buttonElement ) { + return buttonElement->GetLabel(_retval); + } + return NS_ERROR_FAILURE; +} + +// --- XUL checkbox ----- + +nsXULCheckboxAccessible::nsXULCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): +nsXULFormControlAccessible(aNode, aShell) +{ +} + +/* unsigned long getAccRole (); */ +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccRole(PRUint32 *_retval) +{ + *_retval = ROLE_CHECKBUTTON; + return NS_OK; +} + +/* PRUint8 getAccNumActions (); */ +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccNumActions(PRUint8 *_retval) +{ + *_retval = 1; + return NS_OK; +} + +/* wstring getAccActionName (in PRUint8 index); */ +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) +{ + if (index == 0) { // 0 is the magic value for default action + // check or uncheck + PRUint32 state; + GetAccState(&state); + + if (state & STATE_CHECKED) + _retval = NS_LITERAL_STRING("uncheck"); + else + _retval = NS_LITERAL_STRING("check"); + + return NS_OK; + } + return NS_ERROR_INVALID_ARG; +} + +/* void accDoAction (in PRUint8 index); */ +NS_IMETHODIMP nsXULCheckboxAccessible::AccDoAction(PRUint8 index) +{ + if (index == 0) { // 0 is the magic value for default action + PRBool checked = PR_FALSE; + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) { + xulCheckboxElement->GetChecked(&checked); + xulCheckboxElement->SetChecked(!checked); + return NS_OK; + } + return NS_ERROR_FAILURE; + } + return NS_ERROR_INVALID_ARG; +} + +NS_IMETHODIMP nsXULCheckboxAccessible::GetAccState(PRUint32 *_retval) +{ + // Get focus state from parent + nsXULFormControlAccessible::GetAccState(_retval); + + // Determine Checked state + PRBool checked = PR_FALSE; + + nsCOMPtr xulCheckboxElement(do_QueryInterface(mDOMNode)); + if (xulCheckboxElement) + xulCheckboxElement->GetChecked(&checked); + + if (checked) + *_retval |= STATE_CHECKED; + + return NS_OK; +} + diff --git a/accessible/src/xul/nsXULFormControlAccessible.h b/accessible/src/xul/nsXULFormControlAccessible.h new file mode 100644 index 00000000000..8e722e29ddb --- /dev/null +++ b/accessible/src/xul/nsXULFormControlAccessible.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsXULFormControlAccessible_H_ +#define _nsXULFormControlAccessible_H_ + +// NOTE: alphabetically ordered +#include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" +#include "nsHTMLFormControlAccessible.h" +#include "nsIDOMXULLabelElement.h" + +/* Accessible for supporting for controls + * supports: + * - walking up to get name from label + * - support basic state + */ +class nsXULFormControlAccessible : public nsLeafAccessible +{ +public: + nsXULFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccName(nsAWritableString& _retval); + NS_IMETHOD GetAccState(PRUint32 *_retval); + +protected: + NS_IMETHODIMP AppendLabelText(nsIDOMNode *aLabelNode, nsAWritableString& _retval); +}; + +class nsXULButtonAccessible : public nsBlockAccessible +{ +public: + nsXULButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccRole(PRUint32 *_retval); + NS_IMETHOD GetAccName(nsAWritableString& _retval); + NS_IMETHOD GetAccState(PRUint32 *_retval); + NS_IMETHOD GetAccNumActions(PRUint8 *_retval); + NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); + NS_IMETHOD AccDoAction(PRUint8 index); +}; + +class nsXULCheckboxAccessible : public nsXULFormControlAccessible +{ +public: + nsXULCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccRole(PRUint32 *_retval); + NS_IMETHOD GetAccNumActions(PRUint8 *_retval); + NS_IMETHOD GetAccActionName(PRUint8 index, nsAWritableString& _retval); + NS_IMETHOD AccDoAction(PRUint8 index); + NS_IMETHOD GetAccState(PRUint32 *_retval); +}; + +#endif diff --git a/accessible/src/xul/nsXULTextAccessible.cpp b/accessible/src/xul/nsXULTextAccessible.cpp new file mode 100644 index 00000000000..90de5609af1 --- /dev/null +++ b/accessible/src/xul/nsXULTextAccessible.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// NOTE: alphabetically ordered +#include "nsIDOMXULDescriptionElement.h" +#include "nsIDOMXULLabelElement.h" +#include "nsWeakReference.h" +#include "nsXULTextAccessible.h" + +/** + * For XUL descriptions and labels + */ +nsXULTextAccessible::nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): +nsTextAccessible(aDomNode, aShell) +{ +} + +/* wstring getAccName (); */ +NS_IMETHODIMP nsXULTextAccessible::GetAccName(nsAWritableString& _retval) +{ + nsCOMPtr descriptionElement(do_QueryInterface(mDOMNode)); + if (descriptionElement) { + nsCOMPtr content(do_QueryInterface(mDOMNode)); + return AppendFlatStringFromSubtree(content, &_retval); + } + return NS_ERROR_FAILURE; +} diff --git a/accessible/src/xul/nsXULTextAccessible.h b/accessible/src/xul/nsXULTextAccessible.h new file mode 100644 index 00000000000..fad3d2f796e --- /dev/null +++ b/accessible/src/xul/nsXULTextAccessible.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Author: John Gaunt (jgaunt@netscape.com) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsXULTextAccessible_H_ +#define _nsXULTextAccessible_H_ + +#include "nsAccessible.h" +#include "nsBaseWidgetAccessible.h" + +class nsIWeakReference; + +class nsXULTextAccessible : public nsTextAccessible +{ + +public: + nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); + NS_IMETHOD GetAccName(nsAWritableString& _retval); +}; + +#endif