Bug 496271, automation config for Tb2.0.0.22 build1, p=joduinn, r=me
[mozilla-1.9.git] / accessible / src / base / nsAccessibleEventData.h
blobef11872c589b8677036e4ffe45198842b47c1771
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"
53 class nsIPresShell;
55 #define NS_ACCEVENT_IMPL_CID \
56 { /* 55b89892-a83d-4252-ba78-cbdf53a86936 */ \
57 0x55b89892, \
58 0xa83d, \
59 0x4252, \
60 { 0xba, 0x78, 0xcb, 0xdf, 0x53, 0xa8, 0x69, 0x36 } \
63 class nsAccEvent: public nsIAccessibleEvent
65 public:
67 // Rule for accessible events.
68 // The rule will be applied when flushing pending events.
69 enum EEventRule {
70 // eAllowDupes : More than one event of the same type is allowed.
71 // This event will always be emitted.
72 eAllowDupes,
73 // eCoalesceFromSameSubtree : For events of the same type from the same
74 // subtree or the same node, only the umbrelle event on the ancestor
75 // will be emitted.
76 eCoalesceFromSameSubtree,
77 // eRemoveDupes : For repeat events, only the newest event in queue
78 // will be emitted.
79 eRemoveDupes,
80 // eDoNotEmit : This event is confirmed as a duplicate, do not emit it.
81 eDoNotEmit
84 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCEVENT_IMPL_CID)
86 // Initialize with an nsIAccessible
87 nsAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible,
88 PRBool aIsAsynch = PR_FALSE,
89 EEventRule aEventRule = eRemoveDupes);
90 // Initialize with an nsIDOMNode
91 nsAccEvent(PRUint32 aEventType, nsIDOMNode *aDOMNode,
92 PRBool aIsAsynch = PR_FALSE,
93 EEventRule aEventRule = eRemoveDupes);
94 virtual ~nsAccEvent() {}
96 NS_DECL_ISUPPORTS
97 NS_DECL_NSIACCESSIBLEEVENT
99 static void GetLastEventAttributes(nsIDOMNode *aNode,
100 nsIPersistentProperties *aAttributes);
102 protected:
103 already_AddRefed<nsIAccessible> GetAccessibleByNode();
105 void CaptureIsFromUserInput(PRBool aIsAsynch);
106 PRBool mIsFromUserInput;
108 private:
109 PRUint32 mEventType;
110 EEventRule mEventRule;
111 nsCOMPtr<nsIAccessible> mAccessible;
112 nsCOMPtr<nsIDOMNode> mDOMNode;
113 nsCOMPtr<nsIAccessibleDocument> mDocAccessible;
115 static PRBool gLastEventFromUserInput;
116 static nsIDOMNode* gLastEventNodeWeak;
118 public:
119 static PRUint32 EventType(nsIAccessibleEvent *aAccEvent) {
120 PRUint32 eventType;
121 aAccEvent->GetEventType(&eventType);
122 return eventType;
124 static EEventRule EventRule(nsIAccessibleEvent *aAccEvent) {
125 nsRefPtr<nsAccEvent> accEvent = GetAccEventPtr(aAccEvent);
126 return accEvent->mEventRule;
128 static PRBool IsFromUserInput(nsIAccessibleEvent *aAccEvent) {
129 PRBool isFromUserInput;
130 aAccEvent->GetIsFromUserInput(&isFromUserInput);
131 return isFromUserInput;
134 static void ResetLastInputState()
135 {gLastEventFromUserInput = PR_FALSE; gLastEventNodeWeak = nsnull; }
138 * Find and cache the last input state. This will be called automatically
139 * for synchronous events. For asynchronous events it should be
140 * called from the synchronous code which is the true source of the event,
141 * before the event is fired.
142 * @param aChangeNode that event will be on
143 * @param aForceIsFromUserInput PR_TRUE if the caller knows that this event was
144 * caused by user input
146 static void PrepareForEvent(nsIDOMNode *aChangeNode,
147 PRBool aForceIsFromUserInput = PR_FALSE);
150 * The input state was previously stored with the nsIAccessibleEvent,
151 * so use that state now -- call this when about to flush an event that
152 * was waiting in an event queue
154 static void PrepareForEvent(nsIAccessibleEvent *aEvent,
155 PRBool aForceIsFromUserInput = PR_FALSE);
158 * Apply event rules to pending events, this method is called in
159 * FlushingPendingEvents().
160 * Result of this method:
161 * Event rule of filtered events will be set to eDoNotEmit.
162 * Events with other event rule are good to emit.
164 static void ApplyEventRules(nsCOMArray<nsIAccessibleEvent> &aEventsToFire);
166 private:
167 static already_AddRefed<nsAccEvent> GetAccEventPtr(nsIAccessibleEvent *aAccEvent) {
168 nsAccEvent* accEvent = nsnull;
169 aAccEvent->QueryInterface(NS_GET_IID(nsAccEvent), (void**)&accEvent);
170 return accEvent;
174 * Apply aEventRule to same type event that from sibling nodes of aDOMNode.
175 * @param aEventsToFire array of pending events
176 * @param aStart start index of pending events to be scanned
177 * @param aEnd end index to be scanned (not included)
178 * @param aEventType target event type
179 * @param aDOMNode target are siblings of this node
180 * @param aEventRule the event rule to be applied
181 * (should be eDoNotEmit or eAllowDupes)
183 static void ApplyToSiblings(nsCOMArray<nsIAccessibleEvent> &aEventsToFire,
184 PRUint32 aStart, PRUint32 aEnd,
185 PRUint32 aEventType, nsIDOMNode* aDOMNode,
186 EEventRule aEventRule);
189 NS_DEFINE_STATIC_IID_ACCESSOR(nsAccEvent, NS_ACCEVENT_IMPL_CID)
191 class nsAccStateChangeEvent: public nsAccEvent,
192 public nsIAccessibleStateChangeEvent
194 public:
195 nsAccStateChangeEvent(nsIAccessible *aAccessible,
196 PRUint32 aState, PRBool aIsExtraState,
197 PRBool aIsEnabled);
199 nsAccStateChangeEvent(nsIDOMNode *aNode,
200 PRUint32 aState, PRBool aIsExtraState,
201 PRBool aIsEnabled);
203 nsAccStateChangeEvent(nsIDOMNode *aNode,
204 PRUint32 aState, PRBool aIsExtraState);
206 NS_DECL_ISUPPORTS_INHERITED
207 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
208 NS_DECL_NSIACCESSIBLESTATECHANGEEVENT
210 private:
211 PRUint32 mState;
212 PRBool mIsExtraState;
213 PRBool mIsEnabled;
216 class nsAccTextChangeEvent: public nsAccEvent,
217 public nsIAccessibleTextChangeEvent
219 public:
220 nsAccTextChangeEvent(nsIAccessible *aAccessible, PRInt32 aStart, PRUint32 aLength,
221 PRBool aIsInserted, PRBool aIsAsynch = PR_FALSE);
223 NS_DECL_ISUPPORTS_INHERITED
224 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
225 NS_DECL_NSIACCESSIBLETEXTCHANGEEVENT
227 private:
228 PRInt32 mStart;
229 PRUint32 mLength;
230 PRBool mIsInserted;
231 nsString mModifiedText;
234 class nsAccCaretMoveEvent: public nsAccEvent,
235 public nsIAccessibleCaretMoveEvent
237 public:
238 nsAccCaretMoveEvent(nsIAccessible *aAccessible, PRInt32 aCaretOffset);
239 nsAccCaretMoveEvent(nsIDOMNode *aNode);
241 NS_DECL_ISUPPORTS_INHERITED
242 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
243 NS_DECL_NSIACCESSIBLECARETMOVEEVENT
245 private:
246 PRInt32 mCaretOffset;
249 class nsAccTableChangeEvent : public nsAccEvent,
250 public nsIAccessibleTableChangeEvent {
251 public:
252 nsAccTableChangeEvent(nsIAccessible *aAccessible, PRUint32 aEventType,
253 PRInt32 aRowOrColIndex, PRInt32 aNumRowsOrCols,
254 PRBool aIsAsynch);
256 NS_DECL_ISUPPORTS
257 NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
258 NS_DECL_NSIACCESSIBLETABLECHANGEEVENT
260 private:
261 PRUint32 mRowOrColIndex; // the start row/column after which the rows are inserted/deleted.
262 PRUint32 mNumRowsOrCols; // the number of inserted/deleted rows/columns
265 #endif