Bug 417561, disable tagging of Talkback now we have prebuilt packages, r=rhelmer
[mozilla-1.9.git] / content / events / src / nsEventStateManager.h
blob1200d43c8cf62732cfaf32d7a8677eb58196e1c7
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 * Mats Palmgren <mats.palmgren@bredband.net>
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 nsEventStateManager_h__
40 #define nsEventStateManager_h__
42 #include "nsIEventStateManager.h"
43 #include "nsGUIEvent.h"
44 #include "nsIContent.h"
45 #include "nsIObserver.h"
46 #include "nsWeakReference.h"
47 #include "nsHashtable.h"
48 #include "nsITimer.h"
49 #include "nsCOMPtr.h"
50 #include "nsIDocument.h"
51 #include "nsCOMArray.h"
52 #include "nsIFrame.h"
53 #include "nsCycleCollectionParticipant.h"
54 #include "nsIMarkupDocumentViewer.h"
56 class nsIScrollableView;
57 class nsIPresShell;
58 class nsIDocShell;
59 class nsIDocShellTreeNode;
60 class nsIDocShellTreeItem;
61 class nsIFocusController;
62 class imgIContainer;
64 // mac uses click-hold context menus, a holdover from 4.x
65 #ifdef XP_MACOSX
66 #define CLICK_HOLD_CONTEXT_MENUS 1
67 #endif
71 * Event listener manager
74 class nsEventStateManager : public nsSupportsWeakReference,
75 public nsIEventStateManager,
76 public nsIObserver
78 public:
79 nsEventStateManager();
80 virtual ~nsEventStateManager();
82 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
83 NS_DECL_NSIOBSERVER
85 NS_IMETHOD Init();
86 nsresult Shutdown();
88 /* The PreHandleEvent method is called before event dispatch to either
89 * the DOM or frames. Any processing which must not be prevented or
90 * cancelled should occur here. Any processing which is intended to
91 * be conditional based on either DOM or frame processing should occur in
92 * PostHandleEvent. Any centralized event processing which must occur before
93 * DOM or frame event handling should occur here as well.
95 NS_IMETHOD PreHandleEvent(nsPresContext* aPresContext,
96 nsEvent *aEvent,
97 nsIFrame* aTargetFrame,
98 nsEventStatus* aStatus,
99 nsIView* aView);
101 /* The PostHandleEvent method should contain all system processing which
102 * should occur conditionally based on DOM or frame processing. It should
103 * also contain any centralized event processing which must occur after
104 * DOM and frame processing.
106 NS_IMETHOD PostHandleEvent(nsPresContext* aPresContext,
107 nsEvent *aEvent,
108 nsIFrame* aTargetFrame,
109 nsEventStatus* aStatus,
110 nsIView* aView);
112 NS_IMETHOD NotifyDestroyPresContext(nsPresContext* aPresContext);
113 NS_IMETHOD SetPresContext(nsPresContext* aPresContext);
114 NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame);
116 NS_IMETHOD GetEventTarget(nsIFrame **aFrame);
117 NS_IMETHOD GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent);
119 NS_IMETHOD GetContentState(nsIContent *aContent, PRInt32& aState);
120 virtual PRBool SetContentState(nsIContent *aContent, PRInt32 aState);
121 NS_IMETHOD GetFocusedContent(nsIContent **aContent);
122 NS_IMETHOD SetFocusedContent(nsIContent* aContent);
123 NS_IMETHOD GetLastFocusedContent(nsIContent **aContent);
124 NS_IMETHOD GetFocusedFrame(nsIFrame **aFrame);
125 NS_IMETHOD ContentRemoved(nsIContent* aContent);
126 NS_IMETHOD EventStatusOK(nsGUIEvent* aEvent, PRBool *aOK);
128 // Access Key Registration
129 NS_IMETHOD RegisterAccessKey(nsIContent* aContent, PRUint32 aKey);
130 NS_IMETHOD UnregisterAccessKey(nsIContent* aContent, PRUint32 aKey);
131 NS_IMETHOD GetRegisteredAccessKey(nsIContent* aContent, PRUint32* aKey);
133 NS_IMETHOD SetCursor(PRInt32 aCursor, imgIContainer* aContainer,
134 PRBool aHaveHotspot, float aHotspotX, float aHotspotY,
135 nsIWidget* aWidget, PRBool aLockCursor);
137 NS_IMETHOD ShiftFocus(PRBool aForward, nsIContent* aStart=nsnull);
139 virtual PRBool GetBrowseWithCaret();
140 void ResetBrowseWithCaret();
142 NS_IMETHOD MoveFocusToCaret(PRBool aCanFocusDoc, PRBool *aIsSelectionWithFocus);
143 NS_IMETHOD MoveCaretToFocus();
144 NS_IMETHOD ChangeFocusWith(nsIContent* aFocus, EFocusedWithType aFocusedWith);
146 static void StartHandlingUserInput()
148 ++sUserInputEventDepth;
151 static void StopHandlingUserInput()
153 --sUserInputEventDepth;
156 static PRBool IsHandlingUserInput()
158 return sUserInputEventDepth > 0;
161 NS_IMETHOD_(PRBool) IsHandlingUserInputExternal() { return IsHandlingUserInput(); }
163 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventStateManager,
164 nsIEventStateManager)
166 protected:
168 * In certain situations the focus controller's concept of focus gets out of
169 * whack with mCurrentFocus. This is used in known cases to reset the focus
170 * controller's focus. At some point we should probably move to a single
171 * focus storage mechanism because tracking it in several places is error-prone.
173 void EnsureFocusSynchronization();
175 void UpdateCursor(nsPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus);
177 * Turn a GUI mouse event into a mouse event targeted at the specified
178 * content. This returns the primary frame for the content (or null
179 * if it goes away during the event).
181 nsIFrame* DispatchMouseEvent(nsGUIEvent* aEvent, PRUint32 aMessage,
182 nsIContent* aTargetContent,
183 nsIContent* aRelatedContent);
185 * Synthesize DOM and frame mouseover and mouseout events from this
186 * MOUSE_MOVE or MOUSE_EXIT event.
188 void GenerateMouseEnterExit(nsGUIEvent* aEvent);
190 * Tell this ESM and ESMs in parent documents that the mouse is
191 * over some content in this document.
193 void NotifyMouseOver(nsGUIEvent* aEvent, nsIContent* aContent);
195 * Tell this ESM and ESMs in affected child documents that the mouse
196 * has exited this document's currently hovered content.
197 * @param aEvent the event that triggered the mouseout
198 * @param aMovingInto the content node we've moved into. This is used to set
199 * the relatedTarget for mouseout events. Also, if it's non-null
200 * NotifyMouseOut will NOT change the current hover content to null;
201 * in that case the caller is responsible for updating hover state.
203 void NotifyMouseOut(nsGUIEvent* aEvent, nsIContent* aMovingInto);
204 void GenerateDragDropEnterExit(nsPresContext* aPresContext, nsGUIEvent* aEvent);
206 * Fire the dragenter and dragexit/dragleave events when the mouse moves to a
207 * new target.
209 * @param aRelatedTarget relatedTarget to set for the event
210 * @param aTargetContent target to set for the event
211 * @param aTargetFrame target frame for the event
213 void FireDragEnterOrExit(nsPresContext* aPresContext,
214 nsGUIEvent* aEvent,
215 PRUint32 aMsg,
216 nsIContent* aRelatedTarget,
217 nsIContent* aTargetContent,
218 nsWeakFrame& aTargetFrame);
219 nsresult SetClickCount(nsPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus);
220 nsresult CheckForAndDispatchClick(nsPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus);
221 nsresult GetNextTabbableContent(nsIContent* aRootContent,
222 nsIContent* aStartContent,
223 nsIFrame* aStartFrame,
224 PRBool forward, PRBool ignoreTabIndex,
225 nsIContent** aResultNode,
226 nsIFrame** aResultFrame);
227 nsIContent *GetNextTabbableMapArea(PRBool aForward, nsIContent *imageContent);
229 PRInt32 GetNextTabIndex(nsIContent* aParent, PRBool foward);
230 nsresult SendFocusBlur(nsPresContext* aPresContext, nsIContent *aContent, PRBool aEnsureWindowHasFocus);
231 void EnsureDocument(nsIPresShell* aPresShell);
232 void EnsureDocument(nsPresContext* aPresContext);
233 void FlushPendingEvents(nsPresContext* aPresContext);
234 nsIFocusController* GetFocusControllerForDocument(nsIDocument* aDocument);
237 * The phases of HandleAccessKey processing. See below.
239 typedef enum {
240 eAccessKeyProcessingNormal = 0,
241 eAccessKeyProcessingUp,
242 eAccessKeyProcessingDown
243 } ProcessingAccessKeyState;
246 * Access key handling. If there is registered content for the accesskey
247 * given by the key event and modifier mask then call
248 * content.PerformAccesskey(), otherwise call HandleAccessKey() recursively,
249 * on descendant docshells first, then on the ancestor (with |aBubbledFrom|
250 * set to the docshell associated with |this|), until something matches.
252 * @param aPresContext the presentation context
253 * @param aEvent the key event
254 * @param aStatus the event status
255 * @param aBubbledFrom is used by an ancestor to avoid calling HandleAccessKey()
256 * on the child the call originally came from, i.e. this is the child
257 * that recursively called us in it's Up phase. The initial caller
258 * passes |nsnull| here. This is to avoid an infinite loop.
259 * @param aAccessKeyState Normal, Down or Up processing phase (see enums
260 * above). The initial event reciever uses 'normal', then 'down' when
261 * processing children and Up when recursively calling its ancestor.
262 * @param aModifierMask modifier mask for the key event
264 void HandleAccessKey(nsPresContext* aPresContext,
265 nsKeyEvent* aEvent,
266 nsEventStatus* aStatus,
267 nsIDocShellTreeItem* aBubbledFrom,
268 ProcessingAccessKeyState aAccessKeyState,
269 PRInt32 aModifierMask);
271 //---------------------------------------------
272 // DocShell Focus Traversal Methods
273 //---------------------------------------------
275 nsresult ShiftFocusInternal(PRBool aForward, nsIContent* aStart = nsnull);
276 void TabIntoDocument(nsIDocShell* aDocShell, PRBool aForward);
277 void ShiftFocusByDoc(PRBool forward);
278 PRBool IsFrameSetDoc(nsIDocShell* aDocShell);
279 PRBool IsIFrameDoc(nsIDocShell* aDocShell);
280 PRBool IsShellVisible(nsIDocShell* aShell);
281 void GetLastChildDocShell(nsIDocShellTreeItem* aItem,
282 nsIDocShellTreeItem** aResult);
283 void GetNextDocShell(nsIDocShellTreeNode* aNode,
284 nsIDocShellTreeItem** aResult);
285 void GetPrevDocShell(nsIDocShellTreeNode* aNode,
286 nsIDocShellTreeItem** aResult);
288 // These functions are for mousewheel scrolling
289 nsresult GetParentScrollingView(nsInputEvent* aEvent,
290 nsPresContext* aPresContext,
291 nsIFrame* &targetOuterFrame,
292 nsPresContext* &presCtxOuter);
294 typedef enum {
295 eScrollByPixel,
296 eScrollByLine,
297 eScrollByPage
298 } ScrollQuantity;
299 nsresult DoScrollText(nsPresContext* aPresContext,
300 nsIFrame* aTargetFrame,
301 nsInputEvent* aEvent,
302 PRInt32 aNumLines,
303 PRBool aScrollHorizontal,
304 ScrollQuantity aScrollQuantity);
305 void ForceViewUpdate(nsIView* aView);
306 void DoScrollHistory(PRInt32 direction);
307 void DoScrollZoom(nsIFrame *aTargetFrame, PRInt32 adjustment);
308 nsresult GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv);
309 nsresult ChangeTextSize(PRInt32 change);
310 nsresult ChangeFullZoom(PRInt32 change);
311 // end mousewheel functions
313 // routines for the d&d gesture tracking state machine
314 void BeginTrackingDragGesture ( nsPresContext* aPresContext, nsMouseEvent* inDownEvent,
315 nsIFrame* inDownFrame ) ;
316 void StopTrackingDragGesture ( ) ;
317 void GenerateDragGesture ( nsPresContext* aPresContext, nsMouseEvent *aEvent ) ;
318 PRBool IsTrackingDragGesture ( ) const { return mGestureDownContent != nsnull; }
320 * Set the fields of aEvent to reflect the mouse position and modifier keys
321 * that were set when the user first pressed the mouse button (stored by
322 * BeginTrackingDragGesture). aEvent->widget must be
323 * mCurrentTarget->GetWindow().
325 void FillInEventFromGestureDown(nsMouseEvent* aEvent);
327 PRBool mSuppressFocusChange; // Used only for Ender text fields to suppress a focus firing on mouse down
329 nsresult SetCaretEnabled(nsIPresShell *aPresShell, PRBool aVisibility);
330 nsresult SetContentCaretVisible(nsIPresShell* aPresShell, nsIContent *aContent, PRBool aVisible);
331 void FocusElementButNotDocument(nsIContent *aElement);
333 // Return the location of the caret
334 nsresult GetDocSelectionLocation(nsIContent **start, nsIContent **end,
335 nsIFrame **startFrame, PRUint32 *startOffset);
337 PRInt32 mLockCursor;
339 nsWeakFrame mCurrentTarget;
340 nsCOMPtr<nsIContent> mCurrentTargetContent;
341 nsWeakFrame mLastMouseOverFrame;
342 nsCOMPtr<nsIContent> mLastMouseOverElement;
343 nsWeakFrame mLastDragOverFrame;
345 // member variables for the d&d gesture state machine
346 nsPoint mGestureDownPoint; // screen coordinates
347 // The content to use as target if we start a d&d (what we drag).
348 nsCOMPtr<nsIContent> mGestureDownContent;
349 // The content of the frame where the mouse-down event occurred. It's the same
350 // as the target in most cases but not always - for example when dragging
351 // an <area> of an image map this is the image. (bug 289667)
352 nsCOMPtr<nsIContent> mGestureDownFrameOwner;
353 // State of keys when the original gesture-down happened
354 PRPackedBool mGestureDownShift;
355 PRPackedBool mGestureDownControl;
356 PRPackedBool mGestureDownAlt;
357 PRPackedBool mGestureDownMeta;
359 nsCOMPtr<nsIContent> mLastLeftMouseDownContent;
360 nsCOMPtr<nsIContent> mLastMiddleMouseDownContent;
361 nsCOMPtr<nsIContent> mLastRightMouseDownContent;
363 nsCOMPtr<nsIContent> mActiveContent;
364 nsCOMPtr<nsIContent> mHoverContent;
365 nsCOMPtr<nsIContent> mDragOverContent;
366 nsCOMPtr<nsIContent> mURLTargetContent;
367 nsCOMPtr<nsIContent> mCurrentFocus;
368 nsCOMPtr<nsIContent> mLastFocus;
369 nsWeakFrame mCurrentFocusFrame;
370 PRInt32 mCurrentTabIndex;
371 EFocusedWithType mLastFocusedWith;
373 // DocShell Traversal Data Memebers
374 nsCOMPtr<nsIContent> mLastContentFocus;
376 //Anti-recursive stack controls
378 nsCOMPtr<nsIContent> mFirstBlurEvent;
379 nsCOMPtr<nsIContent> mFirstFocusEvent;
381 // The last element on which we fired a mouseover event, or null if
382 // the last mouseover event we fired has finished processing.
383 nsCOMPtr<nsIContent> mFirstMouseOverEventElement;
385 // The last element on which we fired a mouseout event, or null if
386 // the last mouseout event we fired has finished processing.
387 nsCOMPtr<nsIContent> mFirstMouseOutEventElement;
389 nsPresContext* mPresContext; // Not refcnted
390 nsCOMPtr<nsIDocument> mDocument; // Doesn't necessarily need to be owner
392 PRUint32 mLClickCount;
393 PRUint32 mMClickCount;
394 PRUint32 mRClickCount;
396 PRPackedBool mNormalLMouseEventInProcess;
398 PRPackedBool m_haveShutdown;
400 // So we don't have to keep checking accessibility.browsewithcaret pref
401 PRPackedBool mBrowseWithCaret;
403 // Recursion guard for tabbing
404 PRPackedBool mTabbedThroughDocument;
406 // Array for accesskey support
407 nsCOMArray<nsIContent> mAccessKeys;
409 nsCOMArray<nsIDocShell> mTabbingFromDocShells;
411 #ifdef CLICK_HOLD_CONTEXT_MENUS
412 enum { kClickHoldDelay = 500 } ; // 500ms == 1/2 second
414 void CreateClickHoldTimer ( nsPresContext* aPresContext, nsIFrame* inDownFrame,
415 nsGUIEvent* inMouseDownEvent ) ;
416 void KillClickHoldTimer ( ) ;
417 void FireContextClick ( ) ;
418 static void sClickHoldCallback ( nsITimer* aTimer, void* aESM ) ;
420 nsCOMPtr<nsITimer> mClickHoldTimer;
421 #endif
423 static PRInt32 sUserInputEventDepth;
427 class nsAutoHandlingUserInputStatePusher
429 public:
430 nsAutoHandlingUserInputStatePusher(PRBool aIsHandlingUserInput)
431 : mIsHandlingUserInput(aIsHandlingUserInput)
433 if (aIsHandlingUserInput) {
434 nsEventStateManager::StartHandlingUserInput();
438 ~nsAutoHandlingUserInputStatePusher()
440 if (mIsHandlingUserInput) {
441 nsEventStateManager::StopHandlingUserInput();
445 protected:
446 PRBool mIsHandlingUserInput;
448 private:
449 // Hide so that this class can only be stack-allocated
450 static void* operator new(size_t /*size*/) CPP_THROW_NEW { return nsnull; }
451 static void operator delete(void* /*memory*/) {}
454 #endif // nsEventStateManager_h__