Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / accessible / src / html / nsHTMLSelectAccessible.h
blob0d2dfd6ff5dd5338c3080295aa4b7f758bb7c849
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Aaron Leventhal (aaronl@netscape.com)
24 * Kyle Yuan (kyle.yuan@sun.com)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
39 #ifndef __nsHTMLSelectAccessible_h__
40 #define __nsHTMLSelectAccessible_h__
42 #include "nsIAccessibleSelectable.h"
43 #include "nsAccessibilityAtoms.h"
44 #include "nsHTMLFormControlAccessible.h"
45 #include "nsIDOMHTMLOptionsCollection.h"
46 #include "nsIDOMHTMLOptionElement.h"
47 #include "nsIDOMNode.h"
48 #include "nsIAccessibilityService.h"
49 #include "nsAccessibleTreeWalker.h"
51 class nsIMutableArray;
53 /**
54 * Selects, Listboxes and Comboboxes, are made up of a number of different
55 * widgets, some of which are shared between the two. This file contains
56 * all of the widgets for both of the Selects, for HTML only.
58 * Listbox:
59 * - nsHTMLSelectListAccessible
60 * - nsHTMLSelectOptionAccessible
62 * Comboboxes:
63 * - nsHTMLComboboxAccessible
64 * - nsHTMLComboboxTextFieldAccessible
65 * - nsHTMLComboboxButtonAccessible
66 * - nsHTMLComboboxListAccessible [ inserted in accessible tree ]
67 * - nsHTMLSelectOptionAccessible(s)
70 /** ------------------------------------------------------ */
71 /** First, the common widgets */
72 /** ------------------------------------------------------ */
75 * The HTML implementation of nsIAccessibleSelectable.
77 class nsHTMLSelectableAccessible : public nsAccessibleWrap
79 public:
81 NS_DECL_ISUPPORTS_INHERITED
82 NS_DECL_NSIACCESSIBLESELECTABLE
84 nsHTMLSelectableAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
85 virtual ~nsHTMLSelectableAccessible() {}
87 protected:
89 NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState);
91 class iterator
93 protected:
94 PRUint32 mLength;
95 PRUint32 mIndex;
96 PRInt32 mSelCount;
97 nsCOMPtr<nsIDOMHTMLOptionsCollection> mOptions;
98 nsCOMPtr<nsIDOMHTMLOptionElement> mOption;
99 nsCOMPtr<nsIWeakReference> mWeakShell;
100 nsHTMLSelectableAccessible *mParentSelect;
102 public:
103 iterator(nsHTMLSelectableAccessible *aParent, nsIWeakReference *aWeakShell);
105 void CalcSelectionCount(PRInt32 *aSelectionCount);
106 void Select(PRBool aSelect);
107 void AddAccessibleIfSelected(nsIAccessibilityService *aAccService,
108 nsIMutableArray *aSelectedAccessibles,
109 nsPresContext *aContext);
110 PRBool GetAccessibleIfSelected(PRInt32 aIndex, nsIAccessibilityService *aAccService, nsPresContext *aContext, nsIAccessible **_retval);
112 PRBool Advance();
115 friend class iterator;
119 * The list that contains all the options in the select.
121 class nsHTMLSelectListAccessible : public nsHTMLSelectableAccessible
123 public:
125 nsHTMLSelectListAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
126 virtual ~nsHTMLSelectListAccessible() {}
128 // nsIAccessible
129 NS_IMETHOD GetRole(PRUint32 *aRole);
131 // nsAccessible
132 virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
134 protected:
135 void CacheChildren();
137 already_AddRefed<nsIAccessible>
138 AccessibleForOption(nsIAccessibilityService *aAccService,
139 nsIContent *aContent,
140 nsIAccessible *aLastGoodAccessible,
141 PRInt32 *aChildCount);
142 already_AddRefed<nsIAccessible>
143 CacheOptSiblings(nsIAccessibilityService *aAccService,
144 nsIContent *aParentContent,
145 nsIAccessible *aLastGoodAccessible,
146 PRInt32 *aChildCount);
150 * Options inside the select, contained within the list
152 class nsHTMLSelectOptionAccessible : public nsHyperTextAccessibleWrap
154 public:
155 enum { eAction_Select = 0 };
157 nsHTMLSelectOptionAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
158 virtual ~nsHTMLSelectOptionAccessible() {}
160 // nsIAccessible
161 NS_IMETHOD DoAction(PRUint8 index);
162 NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
163 NS_IMETHOD GetNumActions(PRUint8 *_retval);
164 NS_IMETHOD GetRole(PRUint32 *aRole);
166 // nsAccessible
167 virtual nsresult GetNameInternal(nsAString& aName);
168 virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
169 virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
171 nsIFrame* GetBoundsFrame();
172 static nsresult GetFocusedOptionNode(nsIDOMNode *aListNode, nsIDOMNode **aFocusedOptionNode);
173 static void SelectionChangedIfOption(nsIContent *aPossibleOption);
175 private:
178 * Get Select element's accessible state
179 * @param aState, Select element state
180 * @param aExtraState, Select element extra state
181 * @return Select element content, returns null if not avaliable
183 nsIContent* GetSelectState(PRUint32* aState, PRUint32* aExtraState = nsnull);
187 * Opt Groups inside the select, contained within the list
189 class nsHTMLSelectOptGroupAccessible : public nsHTMLSelectOptionAccessible
191 public:
193 nsHTMLSelectOptGroupAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
194 virtual ~nsHTMLSelectOptGroupAccessible() {}
196 // nsIAccessible
197 NS_IMETHOD GetRole(PRUint32 *aRole);
198 NS_IMETHOD DoAction(PRUint8 index);
199 NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
200 NS_IMETHOD GetNumActions(PRUint8 *_retval);
202 // nsAccessible
203 virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
205 protected:
206 void CacheChildren();
209 /** ------------------------------------------------------ */
210 /** Finally, the Combobox widgets */
211 /** ------------------------------------------------------ */
213 class nsHTMLComboboxListAccessible;
216 * A class the represents the HTML Combobox widget.
218 class nsHTMLComboboxAccessible : public nsAccessibleWrap
220 public:
221 enum { eAction_Click = 0 };
223 nsHTMLComboboxAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
224 virtual ~nsHTMLComboboxAccessible() {}
226 // nsIAccessible
227 NS_IMETHOD GetRole(PRUint32 *_retval);
228 NS_IMETHOD GetValue(nsAString& _retval);
229 NS_IMETHOD GetDescription(nsAString& aDescription);
230 NS_IMETHOD DoAction(PRUint8 index);
231 NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
232 NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
234 // nsAccessNode
235 virtual nsresult Shutdown();
237 // nsAccessible
238 virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
240 protected:
241 void CacheChildren();
243 already_AddRefed<nsIAccessible> GetFocusedOptionAccessible();
245 private:
246 nsRefPtr<nsHTMLComboboxListAccessible> mListAccessible;
249 #ifdef COMBO_BOX_WITH_THREE_CHILDREN
251 * A class the represents the text field in the Select to the left
252 * of the drop down button
254 class nsHTMLComboboxTextFieldAccessible : public nsHTMLTextFieldAccessible
256 public:
258 nsHTMLComboboxTextFieldAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
259 virtual ~nsHTMLComboboxTextFieldAccessible() {}
261 /* ----- nsIAccessible ----- */
262 NS_IMETHOD GetUniqueID(void **aUniqueID);
264 virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
266 protected:
267 void CacheChildren();
271 * A class that represents the button inside the Select to the
272 * right of the text field
274 class nsHTMLComboboxButtonAccessible : public nsLeafAccessible
276 public:
277 enum { eAction_Click = 0 };
279 nsHTMLComboboxButtonAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
280 virtual ~nsHTMLComboboxButtonAccessible() {}
282 // nsIAccessible
283 NS_IMETHOD DoAction(PRUint8 index);
284 NS_IMETHOD GetNumActions(PRUint8 *_retval);
285 NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
286 NS_IMETHOD GetParent(nsIAccessible **_retval);
287 NS_IMETHOD GetRole(PRUint32 *_retval);
288 NS_IMETHOD GetName(nsAString& aName);
290 // nsIAccessNode
291 NS_IMETHOD GetUniqueID(void **aUniqueID);
293 // nsAccessible
294 virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
296 protected:
297 virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
300 #endif
303 * A class that represents the window that lives to the right
304 * of the drop down button inside the Select. This is the window
305 * that is made visible when the button is pressed.
307 class nsHTMLComboboxListAccessible : public nsHTMLSelectListAccessible
309 public:
311 nsHTMLComboboxListAccessible(nsIAccessible *aParent,
312 nsIDOMNode* aDOMNode,
313 nsIWeakReference* aShell);
314 virtual ~nsHTMLComboboxListAccessible() {}
316 // nsIAccessible
317 NS_IMETHOD GetParent(nsIAccessible **aParent);
318 NS_IMETHOD GetUniqueID(void **aUniqueID);
320 // nsAccessNode
321 virtual nsIFrame* GetFrame();
323 // nsAccessible
324 virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
325 virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
328 #endif