Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLSelectAccessible.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; 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 #ifndef __nsHTMLSelectAccessible_h__
00040 #define __nsHTMLSelectAccessible_h__
00041 
00042 #include "nsIAccessibleSelectable.h"
00043 #include "nsAccessibilityAtoms.h"
00044 #include "nsFormControlAccessible.h"
00045 #include "nsIDOMHTMLOptionsCollection.h"
00046 #include "nsIDOMHTMLOptionElement.h"
00047 #include "nsIDOMNode.h"
00048 #include "nsIAccessibilityService.h"
00049 
00071 /*
00072  * The HTML implementation of nsIAccessibleSelectable.
00073  */
00074 class nsHTMLSelectableAccessible : public nsAccessibleWrap
00075 {
00076 public:
00077 
00078   NS_DECL_ISUPPORTS_INHERITED
00079   NS_DECL_NSIACCESSIBLESELECTABLE
00080 
00081   nsHTMLSelectableAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00082   virtual ~nsHTMLSelectableAccessible() {}
00083 
00084   NS_IMETHOD GetName(nsAString &aName) { return GetHTMLName(aName, PR_FALSE); }
00085 
00086 protected:
00087 
00088   NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState);
00089 
00090   class iterator 
00091   {
00092   protected:
00093     PRUint32 mLength;
00094     PRUint32 mIndex;
00095     PRInt32 mSelCount;
00096     nsCOMPtr<nsIDOMHTMLOptionsCollection> mOptions;
00097     nsCOMPtr<nsIDOMHTMLOptionElement> mOption;
00098     nsCOMPtr<nsIWeakReference> mWeakShell;
00099     nsHTMLSelectableAccessible *mParentSelect;
00100 
00101   public:
00102     void Shutdown();
00103     iterator(nsHTMLSelectableAccessible *aParent, nsIWeakReference *aWeakShell);
00104 
00105     void CalcSelectionCount(PRInt32 *aSelectionCount);
00106     void Select(PRBool aSelect);
00107     void AddAccessibleIfSelected(nsIAccessibilityService *aAccService, 
00108                                  nsIMutableArray *aSelectedAccessibles, 
00109                                  nsPresContext *aContext);
00110     PRBool GetAccessibleIfSelected(PRInt32 aIndex, nsIAccessibilityService *aAccService, nsPresContext *aContext, nsIAccessible **_retval);
00111 
00112     PRBool Advance();
00113   };
00114 
00115   friend class iterator;
00116 };
00117 
00118 /*
00119  * The list that contains all the options in the select.
00120  */
00121 class nsHTMLSelectListAccessible : public nsHTMLSelectableAccessible
00122 {
00123 public:
00124   
00125   nsHTMLSelectListAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00126   virtual ~nsHTMLSelectListAccessible() {}
00127 
00128   /* ----- nsIAccessible ----- */
00129   NS_IMETHOD GetRole(PRUint32 *aRole);
00130   NS_IMETHOD GetState(PRUint32 *_retval);
00131   void CacheChildren(PRBool aWalkAnonContent);
00132 
00133 protected:
00134   already_AddRefed<nsIAccessible>
00135     AccessibleForOption(nsIAccessibilityService *aAccService,
00136                         nsIContent *aContent,
00137                         nsIAccessible *aLastGoodAccessible);
00138   already_AddRefed<nsIAccessible>
00139     CacheOptSiblings(nsIAccessibilityService *aAccService,
00140                      nsIContent *aParentContent,
00141                      nsIAccessible *aLastGoodAccessible);
00142 };
00143 
00144 /*
00145  * Options inside the select, contained within the list
00146  */
00147 class nsHTMLSelectOptionAccessible : public nsLeafAccessible
00148 {
00149 public:
00150   
00151   nsHTMLSelectOptionAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00152   virtual ~nsHTMLSelectOptionAccessible() {}
00153 
00154   /* ----- nsIAccessible ----- */
00155   NS_IMETHOD DoAction(PRUint8 index);
00156   NS_IMETHOD GetActionName(PRUint8 index, nsAString& _retval);
00157   NS_IMETHOD GetNumActions(PRUint8 *_retval);
00158   NS_IMETHOD GetState(PRUint32 *_retval);
00159   NS_IMETHOD GetRole(PRUint32 *aRole);
00160   NS_IMETHOD GetName(nsAString& aName);
00161   nsIFrame*  GetBoundsFrame();
00162   static nsresult GetFocusedOptionNode(nsIDOMNode *aListNode, nsIDOMNode **aFocusedOptionNode);
00163   static void SelectionChangedIfOption(nsIContent *aPossibleOption);
00164 };
00165 
00166 /*
00167  * Opt Groups inside the select, contained within the list
00168  */
00169 class nsHTMLSelectOptGroupAccessible : public nsHTMLSelectOptionAccessible
00170 {
00171 public:
00172 
00173   nsHTMLSelectOptGroupAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00174   virtual ~nsHTMLSelectOptGroupAccessible() {}
00175 
00176   /* ----- nsIAccessible ----- */
00177   NS_IMETHOD GetState(PRUint32 *_retval);
00178   NS_IMETHOD DoAction(PRUint8 index);  
00179   NS_IMETHOD GetActionName(PRUint8 index, nsAString& _retval);
00180   NS_IMETHOD GetNumActions(PRUint8 *_retval);
00181 };
00182 
00187 /*
00188  * A class the represents the HTML Combobox widget.
00189  */
00190 class nsHTMLComboboxAccessible : public nsHTMLSelectableAccessible
00191 {
00192 public:
00193 
00194   nsHTMLComboboxAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00195   virtual ~nsHTMLComboboxAccessible() {}
00196 
00197   /* ----- nsIAccessible ----- */
00198   NS_IMETHOD GetRole(PRUint32 *_retval);
00199   NS_IMETHOD GetChildCount(PRInt32 *_retval);
00200   NS_IMETHOD GetState(PRUint32 *_retval);
00201 
00202   NS_IMETHOD GetLastChild(nsIAccessible **_retval);
00203   NS_IMETHOD GetFirstChild(nsIAccessible **_retval);
00204   NS_IMETHOD GetValue(nsAString& _retval);
00205   NS_IMETHOD GetDescription(nsAString& aDescription);
00206   NS_IMETHOD Shutdown();
00207   NS_IMETHOD Init();
00208   NS_IMETHOD InvalidateChildren();
00209 
00210 protected:
00211   already_AddRefed<nsIAccessible> GetFocusedOptionAccessible();
00212 
00213   // Hold references to our generated children
00214   // So that we can shut them down when we need to
00215   nsCOMPtr<nsIAccessible> mComboboxTextFieldAccessible;
00216   nsCOMPtr<nsIAccessible> mComboboxButtonAccessible;
00217   nsCOMPtr<nsIAccessible> mComboboxListAccessible;
00218 };
00219 
00220 /*
00221  * A class the represents the text field in the Select to the left
00222  *     of the drop down button
00223  */
00224 class nsHTMLComboboxTextFieldAccessible  : public nsLeafAccessible
00225 {
00226 public:
00227   
00228   nsHTMLComboboxTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00229   virtual ~nsHTMLComboboxTextFieldAccessible() {}
00230 
00231   /* ----- nsIAccessible ----- */
00232   NS_IMETHOD GetNextSibling(nsIAccessible **_retval);
00233   NS_IMETHOD GetPreviousSibling(nsIAccessible **_retval);
00234   NS_IMETHOD GetParent(nsIAccessible **_retval);
00235   NS_IMETHOD GetRole(PRUint32 *_retval);
00236   NS_IMETHOD GetValue(nsAString& _retval);
00237   NS_IMETHOD GetState(PRUint32 *_retval);
00238   NS_IMETHOD GetUniqueID(void **aUniqueID);
00239 
00240   virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
00241 };
00242 
00247 class nsHTMLComboboxButtonAccessible  : public nsLeafAccessible
00248 {
00249 public:
00250 
00251   nsHTMLComboboxButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
00252   virtual ~nsHTMLComboboxButtonAccessible() {}
00253 
00254   /* ----- nsIAccessible ----- */
00255   NS_IMETHOD DoAction(PRUint8 index);
00256   NS_IMETHOD GetNumActions(PRUint8 *_retval);
00257   NS_IMETHOD GetActionName(PRUint8 index, nsAString& _retval);
00258   NS_IMETHOD GetParent(nsIAccessible **_retval);
00259   NS_IMETHOD GetNextSibling(nsIAccessible **_retval);
00260   NS_IMETHOD GetPreviousSibling(nsIAccessible **_retval);
00261   NS_IMETHOD GetName(nsAString& _retval);
00262   NS_IMETHOD GetRole(PRUint32 *_retval);
00263   NS_IMETHOD GetState(PRUint32 *_retval);
00264   NS_IMETHOD GetUniqueID(void **aUniqueID);
00265 
00266   virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
00267 };
00268 
00269 /*
00270  * A class that represents the window that lives to the right
00271  * of the drop down button inside the Select. This is the window
00272  * that is made visible when the button is pressed.
00273  */
00274 class nsHTMLComboboxListAccessible : public nsHTMLSelectListAccessible
00275 {
00276 public:
00277 
00278   nsHTMLComboboxListAccessible(nsIAccessible *aParent, 
00279                                          nsIDOMNode* aDOMNode, 
00280                                                                                                           nsIWeakReference* aShell);
00281   virtual ~nsHTMLComboboxListAccessible() {}
00282 
00283   /* ----- nsIAccessible ----- */
00284   NS_IMETHOD GetState(PRUint32 *aState);
00285   NS_IMETHOD GetParent(nsIAccessible **aParent);
00286   NS_IMETHOD GetUniqueID(void **aUniqueID);
00287   NS_IMETHOD GetPreviousSibling(nsIAccessible **aAccPrevSibling);
00288 
00289   virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
00290 };
00291 
00292 #endif