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
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) 2003
20 * the Initial Developer. All Rights Reserved.
23 * Original Author: Aaron Leventhal (aaronl@netscape.com)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef _nsDocAccessible_H_
40 #define _nsDocAccessible_H_
42 #include "nsHyperTextAccessibleWrap.h"
43 #include "nsIAccessibleDocument.h"
44 #include "nsPIAccessibleDocument.h"
45 #include "nsIDocument.h"
46 #include "nsIDocumentObserver.h"
47 #include "nsIEditor.h"
48 #include "nsIObserver.h"
49 #include "nsIScrollPositionListener.h"
51 #include "nsIWeakReference.h"
52 #include "nsCOMArray.h"
53 #include "nsIDocShellTreeNode.h"
55 class nsIScrollableView
;
57 const PRUint32 kDefaultCacheSize
= 256;
59 class nsDocAccessible
: public nsHyperTextAccessibleWrap
,
60 public nsIAccessibleDocument
,
61 public nsPIAccessibleDocument
,
62 public nsIDocumentObserver
,
64 public nsIScrollPositionListener
,
65 public nsSupportsWeakReference
67 NS_DECL_ISUPPORTS_INHERITED
68 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocAccessible
, nsAccessible
)
70 NS_DECL_NSIACCESSIBLEDOCUMENT
71 NS_DECL_NSPIACCESSIBLEDOCUMENT
75 nsDocAccessible(nsIDOMNode
*aNode
, nsIWeakReference
* aShell
);
76 virtual ~nsDocAccessible();
78 NS_IMETHOD
GetRole(PRUint32
*aRole
);
79 NS_IMETHOD
SetRoleMapEntry(nsRoleMapEntry
* aRoleMapEntry
);
80 NS_IMETHOD
GetName(nsAString
& aName
);
81 NS_IMETHOD
GetDescription(nsAString
& aDescription
);
82 NS_IMETHOD
GetARIAState(PRUint32
*aState
);
83 NS_IMETHOD
GetState(PRUint32
*aState
, PRUint32
*aExtraState
);
84 NS_IMETHOD
GetAttributes(nsIPersistentProperties
**aAttributes
);
85 NS_IMETHOD
GetFocusedChild(nsIAccessible
**aFocusedChild
);
86 NS_IMETHOD
GetParent(nsIAccessible
**aParent
);
87 NS_IMETHOD
TakeFocus(void);
89 // ----- nsIScrollPositionListener ---------------------------
90 NS_IMETHOD
ScrollPositionWillChange(nsIScrollableView
*aView
, nscoord aX
, nscoord aY
);
91 virtual void ViewPositionDidChange(nsIScrollableView
* aScrollable
) {}
92 NS_IMETHOD
ScrollPositionDidChange(nsIScrollableView
*aView
, nscoord aX
, nscoord aY
);
94 // nsIDocumentObserver
95 NS_DECL_NSIDOCUMENTOBSERVER
97 static void FlushEventsCallback(nsITimer
*aTimer
, void *aClosure
);
100 NS_IMETHOD
Shutdown();
104 NS_IMETHOD_(nsIFrame
*) GetFrame(void);
107 NS_IMETHOD
GetAssociatedEditor(nsIEditor
**aEditor
);
110 * Non-virtual method to fire a delayed event after a 0 length timeout
112 * @param aEvent - the nsIAccessibleEvent event type
113 * @param aDOMNode - DOM node the accesible event should be fired for
114 * @param aAllowDupes - eAllowDupes: more than one event of the same type is allowed.
115 * eCoalesceFromSameSubtree: if two events are in the same subtree,
116 * only the event on ancestor is used
117 * eRemoveDupes (default): events of the same type are discarded
118 * (the last one is used)
120 * @param aIsAsynch - set to PR_TRUE if this is not being called from code
121 * synchronous with a DOM event
123 nsresult
FireDelayedToolkitEvent(PRUint32 aEvent
, nsIDOMNode
*aDOMNode
,
124 nsAccEvent::EEventRule aAllowDupes
= nsAccEvent::eRemoveDupes
,
125 PRBool aIsAsynch
= PR_FALSE
);
128 * Fire accessible event in timeout.
130 * @param aEvent - the event to fire
132 nsresult
FireDelayedAccessibleEvent(nsIAccessibleEvent
*aEvent
);
134 void ShutdownChildDocuments(nsIDocShellTreeItem
*aStart
);
137 virtual void GetBoundsRect(nsRect
& aRect
, nsIFrame
** aRelativeFrame
);
138 virtual nsresult
AddEventListeners();
139 virtual nsresult
RemoveEventListeners();
140 void AddScrollListener();
141 void RemoveScrollListener();
144 * For any accessibles in this subtree, invalidate their knowledge of
145 * their children. Only weak refrences are destroyed, not accessibles.
146 * @param aStartNode The root of the subrtee to invalidate accessible child refs in
148 void InvalidateChildrenInSubtree(nsIDOMNode
*aStartNode
);
149 void RefreshNodes(nsIDOMNode
*aStartNode
);
150 static void ScrollTimerCallback(nsITimer
*aTimer
, void *aClosure
);
153 * Fires accessible events when attribute is changed.
155 * @param aContent - node that attribute is changed for
156 * @param aNameSpaceID - namespace of changed attribute
157 * @param aAttribute - changed attribute
159 void AttributeChangedImpl(nsIContent
* aContent
, PRInt32 aNameSpaceID
, nsIAtom
* aAttribute
);
162 * Fires accessible events when ARIA attribute is changed.
164 * @param aContent - node that attribute is changed for
165 * @param aAttribute - changed attribute
167 void ARIAAttributeChanged(nsIContent
* aContent
, nsIAtom
* aAttribute
);
170 * Fire text changed event for character data changed. The method is used
171 * from nsIMutationObserver methods.
173 * @param aContent the text node holding changed data
174 * @param aInfo info structure describing how the data was changed
175 * @param aIsInserted the flag pointed whether removed or inserted
176 * characters should be cause of event
178 void FireTextChangeEventForText(nsIContent
*aContent
,
179 CharacterDataChangeInfo
* aInfo
,
183 * Create a text change event for a changed node
184 * @param aContainerAccessible, the first accessible in the container
185 * @param aChangeNode, the node that is being inserted or removed, or shown/hidden
186 * @param aAccessibleForChangeNode, the accessible for that node, or nsnull if none exists
187 * @param aIsInserting, is aChangeNode being created or shown (vs. removed or hidden)
189 already_AddRefed
<nsIAccessibleTextChangeEvent
>
190 CreateTextChangeEventForNode(nsIAccessible
*aContainerAccessible
,
191 nsIDOMNode
*aChangeNode
,
192 nsIAccessible
*aAccessibleForNode
,
197 * Fire show/hide events for either the current node if it has an accessible,
198 * or the first-line accessible descendants of the given node.
200 * @param aDOMNode the given node
201 * @param aEventType event type to fire an event
202 * @param aAvoidOnThisNode Call with PR_TRUE the first time to prevent event firing on root node for change
203 * @param aDelay whether to fire the event on a delay
204 * @param aForceIsFromUserInput the event is known to be from user input
206 nsresult
FireShowHideEvents(nsIDOMNode
*aDOMNode
, PRBool aAvoidOnThisNode
, PRUint32 aEventType
,
207 PRBool aDelay
, PRBool aForceIsFromUserInput
);
210 * If the given accessible object is a ROLE_ENTRY, fire a value change event for it
212 void FireValueChangeForTextFields(nsIAccessible
*aPossibleTextFieldAccessible
);
214 nsAccessNodeHashtable mAccessNodeCache
;
216 nsCOMPtr
<nsIDocument
> mDocument
;
217 nsCOMPtr
<nsITimer
> mScrollWatchTimer
;
218 nsCOMPtr
<nsITimer
> mFireEventTimer
;
219 PRUint16 mScrollPositionChangedTicks
; // Used for tracking scroll events
220 PRPackedBool mIsContentLoaded
;
221 PRPackedBool mIsLoadCompleteFired
;
222 nsCOMArray
<nsIAccessibleEvent
> mEventsToFire
;
226 PRBool mIsAnchorJumped
;
227 PRBool mInFlushPendingEvents
;
228 static PRUint32 gLastFocusedAccessiblesState
;
229 static nsIAtom
*gLastFocusedFrameType
;