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
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.
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
;
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.
59 * - nsHTMLSelectListAccessible
60 * - nsHTMLSelectOptionAccessible
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
81 NS_DECL_ISUPPORTS_INHERITED
82 NS_DECL_NSIACCESSIBLESELECTABLE
84 nsHTMLSelectableAccessible(nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
85 virtual ~nsHTMLSelectableAccessible() {}
87 NS_IMETHOD
GetName(nsAString
&aName
) { return GetHTMLName(aName
, PR_FALSE
); }
91 NS_IMETHOD
ChangeSelection(PRInt32 aIndex
, PRUint8 aMethod
, PRBool
*aSelState
);
99 nsCOMPtr
<nsIDOMHTMLOptionsCollection
> mOptions
;
100 nsCOMPtr
<nsIDOMHTMLOptionElement
> mOption
;
101 nsCOMPtr
<nsIWeakReference
> mWeakShell
;
102 nsHTMLSelectableAccessible
*mParentSelect
;
105 iterator(nsHTMLSelectableAccessible
*aParent
, nsIWeakReference
*aWeakShell
);
107 void CalcSelectionCount(PRInt32
*aSelectionCount
);
108 void Select(PRBool aSelect
);
109 void AddAccessibleIfSelected(nsIAccessibilityService
*aAccService
,
110 nsIMutableArray
*aSelectedAccessibles
,
111 nsPresContext
*aContext
);
112 PRBool
GetAccessibleIfSelected(PRInt32 aIndex
, nsIAccessibilityService
*aAccService
, nsPresContext
*aContext
, nsIAccessible
**_retval
);
117 friend class iterator
;
121 * The list that contains all the options in the select.
123 class nsHTMLSelectListAccessible
: public nsHTMLSelectableAccessible
127 nsHTMLSelectListAccessible(nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
128 virtual ~nsHTMLSelectListAccessible() {}
130 /* ----- nsIAccessible ----- */
131 NS_IMETHOD
GetRole(PRUint32
*aRole
);
132 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
133 void CacheChildren();
136 already_AddRefed
<nsIAccessible
>
137 AccessibleForOption(nsIAccessibilityService
*aAccService
,
138 nsIContent
*aContent
,
139 nsIAccessible
*aLastGoodAccessible
,
140 PRInt32
*aChildCount
);
141 already_AddRefed
<nsIAccessible
>
142 CacheOptSiblings(nsIAccessibilityService
*aAccService
,
143 nsIContent
*aParentContent
,
144 nsIAccessible
*aLastGoodAccessible
,
145 PRInt32
*aChildCount
);
149 * Options inside the select, contained within the list
151 class nsHTMLSelectOptionAccessible
: public nsHyperTextAccessibleWrap
154 enum { eAction_Select
= 0 };
156 nsHTMLSelectOptionAccessible(nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
157 virtual ~nsHTMLSelectOptionAccessible() {}
159 /* ----- nsIAccessible ----- */
160 NS_IMETHOD
DoAction(PRUint8 index
);
161 NS_IMETHOD
GetActionName(PRUint8 aIndex
, nsAString
& aName
);
162 NS_IMETHOD
GetNumActions(PRUint8
*_retval
);
163 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
164 NS_IMETHOD
GetRole(PRUint32
*aRole
);
165 NS_IMETHOD
GetName(nsAString
& aName
);
166 virtual nsresult
GetAttributesInternal(nsIPersistentProperties
*aAttributes
);
168 nsIFrame
* GetBoundsFrame();
169 static nsresult
GetFocusedOptionNode(nsIDOMNode
*aListNode
, nsIDOMNode
**aFocusedOptionNode
);
170 static void SelectionChangedIfOption(nsIContent
*aPossibleOption
);
175 * Get Select element's accessible state
176 * @param aState, Select element state
177 * @param aExtraState, Select element extra state
178 * @return Select element content, returns null if not avaliable
180 nsIContent
* GetSelectState(PRUint32
* aState
, PRUint32
* aExtraState
= nsnull
);
184 * Opt Groups inside the select, contained within the list
186 class nsHTMLSelectOptGroupAccessible
: public nsHTMLSelectOptionAccessible
190 nsHTMLSelectOptGroupAccessible(nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
191 virtual ~nsHTMLSelectOptGroupAccessible() {}
193 /* ----- nsIAccessible ----- */
194 NS_IMETHOD
GetRole(PRUint32
*aRole
);
195 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
196 NS_IMETHOD
DoAction(PRUint8 index
);
197 NS_IMETHOD
GetActionName(PRUint8 aIndex
, nsAString
& aName
);
198 NS_IMETHOD
GetNumActions(PRUint8
*_retval
);
199 void CacheChildren();
202 /** ------------------------------------------------------ */
203 /** Finally, the Combobox widgets */
204 /** ------------------------------------------------------ */
206 class nsHTMLComboboxListAccessible
;
209 * A class the represents the HTML Combobox widget.
211 class nsHTMLComboboxAccessible
: public nsAccessibleWrap
214 enum { eAction_Click
= 0 };
216 nsHTMLComboboxAccessible(nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
217 virtual ~nsHTMLComboboxAccessible() {}
219 /* ----- nsIAccessible ----- */
220 NS_IMETHOD
GetRole(PRUint32
*_retval
);
221 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
222 NS_IMETHOD
GetValue(nsAString
& _retval
);
223 NS_IMETHOD
GetDescription(nsAString
& aDescription
);
224 NS_IMETHOD
DoAction(PRUint8 index
);
225 NS_IMETHOD
GetNumActions(PRUint8
*aNumActions
);
226 NS_IMETHOD
GetActionName(PRUint8 aIndex
, nsAString
& aName
);
228 void CacheChildren();
229 NS_IMETHOD
Shutdown();
232 already_AddRefed
<nsIAccessible
> GetFocusedOptionAccessible();
235 nsRefPtr
<nsHTMLComboboxListAccessible
> mListAccessible
;
238 #ifdef COMBO_BOX_WITH_THREE_CHILDREN
240 * A class the represents the text field in the Select to the left
241 * of the drop down button
243 class nsHTMLComboboxTextFieldAccessible
: public nsHTMLTextFieldAccessible
247 nsHTMLComboboxTextFieldAccessible(nsIAccessible
* aParent
, nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
248 virtual ~nsHTMLComboboxTextFieldAccessible() {}
250 /* ----- nsIAccessible ----- */
251 NS_IMETHOD
GetUniqueID(void **aUniqueID
);
253 virtual void GetBoundsRect(nsRect
& aBounds
, nsIFrame
** aBoundingFrame
);
256 void CacheChildren();
260 * A class that represents the button inside the Select to the
261 * right of the text field
263 class nsHTMLComboboxButtonAccessible
: public nsLeafAccessible
266 enum { eAction_Click
= 0 };
268 nsHTMLComboboxButtonAccessible(nsIAccessible
* aParent
, nsIDOMNode
* aDOMNode
, nsIWeakReference
* aShell
);
269 virtual ~nsHTMLComboboxButtonAccessible() {}
271 /* ----- nsIAccessible ----- */
272 NS_IMETHOD
DoAction(PRUint8 index
);
273 NS_IMETHOD
GetNumActions(PRUint8
*_retval
);
274 NS_IMETHOD
GetActionName(PRUint8 aIndex
, nsAString
& aName
);
275 NS_IMETHOD
GetParent(nsIAccessible
**_retval
);
276 NS_IMETHOD
GetName(nsAString
& _retval
);
277 NS_IMETHOD
GetRole(PRUint32
*_retval
);
278 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
279 NS_IMETHOD
GetUniqueID(void **aUniqueID
);
281 virtual void GetBoundsRect(nsRect
& aBounds
, nsIFrame
** aBoundingFrame
);
286 * A class that represents the window that lives to the right
287 * of the drop down button inside the Select. This is the window
288 * that is made visible when the button is pressed.
290 class nsHTMLComboboxListAccessible
: public nsHTMLSelectListAccessible
294 nsHTMLComboboxListAccessible(nsIAccessible
*aParent
,
295 nsIDOMNode
* aDOMNode
,
296 nsIWeakReference
* aShell
);
297 virtual ~nsHTMLComboboxListAccessible() {}
299 /* ----- nsIAccessible ----- */
300 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
301 NS_IMETHOD
GetParent(nsIAccessible
**aParent
);
302 NS_IMETHOD
GetUniqueID(void **aUniqueID
);
305 NS_IMETHOD_(nsIFrame
*) GetFrame(void);
307 virtual void GetBoundsRect(nsRect
& aBounds
, nsIFrame
** aBoundingFrame
);