Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / accessible / src / base / nsAccessibleEventData.h
blob32aadac44ea854bab5ba54e9e90186a785263db1
1 /* -*- Mode: C++; tab-width: 2; 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 * Kyle Yuan (kyle.yuan@sun.com)
24 * John Sun (john.sun@sun.com)
25 * Alexander Surkov <surkov.alexander@gmail.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef _nsAccessibleEventData_H_
42 #define _nsAccessibleEventData_H_
44 #include "nsAutoPtr.h"
45 #include "nsCOMPtr.h"
46 #include "nsCOMArray.h"
47 #include "nsIAccessibleEvent.h"
48 #include "nsIAccessible.h"
49 #include "nsIAccessibleDocument.h"
50 #include "nsIDOMNode.h"
51 #include "nsString.h"
52 #include "nsCycleCollectionParticipant.h"
54 class nsIPresShell;
56 #define NS_ACCEVENT_IMPL_CID \
57 { /* 55b89892-a83d-4252-ba78-cbdf53a86936 */ \
58 0x55b89892, \
59 0xa83d, \
60 0x4252, \
61 { 0xba, 0x78, 0xcb, 0xdf, 0x53, 0xa8, 0x69, 0x36 } \
64 class nsAccEvent: public nsIAccessibleEvent
66 public:
68 // Rule for accessible events.
69 // The rule will be applied when flushing pending events.
70 enum EEventRule {
71 // eAllowDupes : More than one event of the same type is allowed.
72 // This event will always be emitted.
73 eAllowDupes,
74 // eCoalesceFromSameSubtree : For events of the same type from the same
75 // subtree or the same node, only the umbrelle event on the ancestor
76 // will be emitted.
77 eCoalesceFromSameSubtree,
78 // eRemoveDupes : For repeat events, only the newest event in queue
79 // will be emitted.
80 eRemoveDupes,
81 // eDoNotEmit : This event is confirmed as a duplicate, do not emit it.
82 eDoNotEmit
85 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCEVENT_IMPL_CID)
87 // Initialize with an nsIAccessible
88 nsAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible,
89 PRBool aIsAsynch = PR_FALSE,
90 EEventRule aEventRule = eRemoveDupes);
91 // Initialize with an nsIDOMNode
92 nsAccEvent(PRUint32 aEventType, nsIDOMNode *aDOMNode,
93 PRBool aIsAsynch = PR_FALSE,
94 EEventRule aEventRule = eRemoveDupes);
95 virtual ~nsAccEvent() {}
97 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
98 NS_DECL_CYCLE_COLLECTION_CLASS(nsAccEvent)
100 NS_DECL_NSIACCESSIBLEEVENT
102 static void GetLastEventAttributes(nsIDOMNode *aNode,
103 nsIPersistentProperties *aAttributes);
105 protected:
106 already_AddRefed<nsIAccessible> GetAccessibleByNode();
108 void CaptureIsFromUserInput(PRBool aIsAsynch);
109 PRBool mIsFromUserInput;
111 PRUint32 mEventType;
112 EEventRule mEventRule;
113 nsCOMPtr<nsIAccessible> mAccessible;
114 nsCOMPtr<nsIDOMNode> mDOMNode;
115 nsCOMPtr<nsIAccessibleDocument> mDocAccessible;
117 private:
118 static PRBool gLastEventFromUserInput;
119 static nsIDOMNode* gLastEventNodeWeak;
121 public:
122 static PRUint32 EventType(nsIAccessibleEvent *aAccEvent) {
123 PRUint32 eventType;
124 aAccEvent->GetEventType(&eventType);
125 return eventType;
127 static EEventRule EventRule(nsIAccessibleEvent *aAccEvent) {
128 nsRefPtr<nsAccEvent> accEvent = GetAccEventPtr(aAccEvent);
129 return accEvent->mEventRule;
131 static PRBool IsFromUserInput(nsIAccessibleEvent *aAccEvent) {
132 PRBool isFromUserInput;
133 aAccEvent->GetIsFromUserInput(&isFromUserInput);
134 return isFromUserInput;
137 static void ResetLastInputState()
138 {gLastEventFromUserInput = PR_FALSE; gLastEventNodeWeak = nsnull; }
141 * Find and cache the last input state. This will be called automatically
142 * for synchronous events. For asynchronous events it should be
143 * called from the synchronous code which is the true source of the event,
144 * before the event is fired.
145 * @param aChangeNode that event will be on
146 * @param aForceIsFromUserInput PR_TRUE if the caller knows that this event was
147 * caused by user input
149 static void PrepareForEvent(nsIDOMNode *aChangeNode,
150 PRBool aForceIsFromUserInput = PR_FALSE);
153 * The input state was previously stored with the nsIAccessibleEvent,
154 * so use that state now -- call this when about to flush an event that
155 * was waiting in an event queue
157 static void PrepareForEvent(nsIAccessibleEvent *aEvent,
158 PRBool aForceIsFromUserInput = PR_FALSE);
161 * Apply event rules to pending events, this method is called in
162 * FlushingPendingEvents().
163 * Result of this method:
164 * Event rule of filtered events will be set to eDoNotEmit.
165 * Events with other event rule are good to emit.
167 static void ApplyEventRules(nsCOMArray<nsIAccessibleEvent> &aEventsToFire);
169 private:
170 static already_AddRefed<nsAccEvent> GetAccEventPtr(nsIAccessibleEvent *aAccEvent) {
171 nsAccEvent* accEvent = nsnull;
172 aAccEvent->QueryInterface(NS_GET_IID(nsAccEvent), (void**)&accEvent);
173 return accEvent;
177 * Apply aEventRule to same type event that from sibling nodes of aDOMNode.
178 * @param aEventsToFire array of pending events
179 * @param aStart start index of pending events to be scanned
180 * @param aEnd end index to be scanned (not included)
181 * @param aEventType target event type
182 * @param aDOMNode target are siblings of this node
183 * @param aEventRule the event rule to be applied
184 * (should be eDoNotEmit or eAllowDupes)
186 static void ApplyToSiblings(nsCOMArray<nsIAccessibleEvent> &aEventsToFire,
187 PRUint32 aStart, PRUint32 aEnd,
188 PRUint32 aEventType, nsIDOMNode* aDOMNode,
189 EEventRule aEventRule);
192 NS_DEFINE_STATIC_IID_ACCESSOR(nsAccEvent, NS_ACCEVENT_IMPL_CID)
194 class nsAccStateChangeEvent: public nsAccEvent,
195 public nsIAccessibleStateChangeEvent
197 public:
198 nsAccStateChangeEvent(nsIAccessible *aAccessible,
199 PRUint32 aState, PRBool aIsExtraState,
200 PRBool aIsEnabled);
202 nsAccStateChangeEvent(nsIDOMNode *aNode,
203 PRUint32 aState, PRBool aIsExtraState,
204 PRBool aIsEnabled);
206 nsAccStateChangeEvent(nsIDOMNode *aNode,
207 PRUint32 aState, PRBool aIsExtraState);
209 NS_DECL_ISUPPORTS_INHERITED
210 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
211 NS_DECL_NSIACCESSIBLESTATECHANGEEVENT
213 private:
214 PRUint32 mState;
215 PRBool mIsExtraState;
216 PRBool mIsEnabled;
219 class nsAccTextChangeEvent: public nsAccEvent,
220 public nsIAccessibleTextChangeEvent
222 public:
223 nsAccTextChangeEvent(nsIAccessible *aAccessible, PRInt32 aStart, PRUint32 aLength,
224 PRBool aIsInserted, PRBool aIsAsynch = PR_FALSE);
226 NS_DECL_ISUPPORTS_INHERITED
227 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
228 NS_DECL_NSIACCESSIBLETEXTCHANGEEVENT
230 private:
231 PRInt32 mStart;
232 PRUint32 mLength;
233 PRBool mIsInserted;
234 nsString mModifiedText;
237 class nsAccCaretMoveEvent: public nsAccEvent,
238 public nsIAccessibleCaretMoveEvent
240 public:
241 nsAccCaretMoveEvent(nsIAccessible *aAccessible, PRInt32 aCaretOffset);
242 nsAccCaretMoveEvent(nsIDOMNode *aNode);
244 NS_DECL_ISUPPORTS_INHERITED
245 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
246 NS_DECL_NSIACCESSIBLECARETMOVEEVENT
248 private:
249 PRInt32 mCaretOffset;
252 class nsAccTableChangeEvent : public nsAccEvent,
253 public nsIAccessibleTableChangeEvent {
254 public:
255 nsAccTableChangeEvent(nsIAccessible *aAccessible, PRUint32 aEventType,
256 PRInt32 aRowOrColIndex, PRInt32 aNumRowsOrCols,
257 PRBool aIsAsynch);
259 NS_DECL_ISUPPORTS
260 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
261 NS_DECL_NSIACCESSIBLETABLECHANGEEVENT
263 private:
264 PRUint32 mRowOrColIndex; // the start row/column after which the rows are inserted/deleted.
265 PRUint32 mNumRowsOrCols; // the number of inserted/deleted rows/columns
268 #endif