Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLTextAccessible.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Aaron Leventhal (aaronl@netscape.com)
00024  *   Kyle Yuan (kyle.yuan@sun.com)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef _nsHTMLTextAccessible_H_
00041 #define _nsHTMLTextAccessible_H_
00042 
00043 #include "nsTextAccessibleWrap.h"
00044 #include "nsAutoPtr.h"
00045 
00046 class nsIWeakReference;
00047 
00048 class nsHTMLTextAccessible : public nsTextAccessibleWrap
00049 {
00050 public:
00051   nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell, nsIFrame *aFrame);
00052   
00053   // nsIAccessible
00054   NS_IMETHOD GetName(nsAString& _retval);
00055   NS_IMETHOD GetState(PRUint32 *aState);
00056 };
00057 
00058 class nsHTMLHRAccessible : public nsLeafAccessible
00059 {
00060 public:
00061   nsHTMLHRAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
00062   NS_IMETHOD GetRole(PRUint32 *aRole); 
00063   NS_IMETHOD GetState(PRUint32 *aState); 
00064 };
00065 
00066 class nsHTMLLabelAccessible : public nsTextAccessible 
00067 {
00068 public:
00069   nsHTMLLabelAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
00070   NS_IMETHOD GetName(nsAString& _retval);
00071   NS_IMETHOD GetRole(PRUint32 *_retval); 
00072   NS_IMETHOD GetState(PRUint32 *_retval); 
00073   NS_IMETHOD GetFirstChild(nsIAccessible **aFirstChild);
00074   NS_IMETHOD GetLastChild(nsIAccessible **aLastChild);
00075   NS_IMETHOD GetChildCount(PRInt32 *aAccChildCount);
00076 };
00077 
00078 class nsHTMLListBulletAccessible : public nsHTMLTextAccessible
00079 {
00080 public:
00081   nsHTMLListBulletAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell,
00082                              nsIFrame *aFrame, const nsAString& aBulletText);
00083   NS_IMETHOD GetUniqueID(void **aUniqueID);
00084   NS_IMETHOD Shutdown();
00085   NS_IMETHOD GetName(nsAString& aName);
00086   NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = ROLE_STATICTEXT; return NS_OK; }
00087   NS_IMETHOD GetState(PRUint32 *aState) { nsHTMLTextAccessible::GetState(aState); *aState &= ~STATE_FOCUSABLE; *aState |= STATE_READONLY; return NS_OK; }
00088   // Don't cache via unique ID -- bullet accessible shares the same dom node as this LI accessible.
00089   // Also, don't cache via mParent/SetParent(), prevent circular reference since li holds onto us.
00090   NS_IMETHOD SetParent(nsIAccessible *aParentAccessible) { mParent = nsnull; mWeakParent = aParentAccessible; return NS_OK; }
00091   NS_IMETHOD GetParent(nsIAccessible **aParentAccessible) { NS_IF_ADDREF(*aParentAccessible = mWeakParent); return NS_OK; }
00092 protected:
00093   // XXX Ideally we'd get the bullet text directly from the bullet frame via
00094   // nsBulletFrame::GetListItemText(), but we'd need an interface
00095   // for getting text from contentless anonymous frames.
00096   // Perhaps something like nsIAnonymousFrame::GetText() ?
00097   // However, in practice storing the bullet text here should not be a
00098   // problem if we invalidate the right parts of the accessibility cache
00099   // when mutation events occur.
00100   nsIAccessible *mWeakParent;
00101   nsString mBulletText;
00102 };
00103 
00104 class nsHTMLListAccessible : public nsAccessibleWrap
00105 {
00106 public:
00107   nsHTMLListAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell):
00108     nsAccessibleWrap(aDOMNode, aShell) { }
00109   NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = ROLE_LIST; return NS_OK; }
00110   NS_IMETHOD GetState(PRUint32 *aState) { nsAccessibleWrap::GetState(aState); *aState &= ~STATE_FOCUSABLE; *aState |= STATE_READONLY; return NS_OK; }
00111 };
00112 
00113 class nsHTMLLIAccessible : public nsBlockAccessible
00114 {
00115 public:
00116   nsHTMLLIAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell, 
00117                      nsIFrame *aBulletFrame, const nsAString& aBulletText);
00118   NS_IMETHOD Shutdown();
00119   NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = ROLE_LISTITEM; return NS_OK; }
00120   NS_IMETHOD GetState(PRUint32 *aState) { nsAccessibleWrap::GetState(aState); *aState |= STATE_READONLY; return NS_OK; }
00121   NS_IMETHOD GetName(nsAString& aName) { aName.SetIsVoid(PR_TRUE); return mRoleMapEntry ? nsAccessible::GetName(aName) : NS_OK; }
00122   NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
00123   void CacheChildren(PRBool aWalkAnonContent);  // Include bullet accessible
00124 protected:
00125   nsRefPtr<nsHTMLListBulletAccessible> mBulletAccessible;
00126 };
00127 
00128 #endif