Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / dom / events / EventStateManager.h
blobee95b6e0fc54cb0af90b1224493c22988dc16ea0
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_EventStateManager_h_
8 #define mozilla_EventStateManager_h_
10 #include "mozilla/EventForwards.h"
12 #include "nsIObserver.h"
13 #include "nsWeakReference.h"
14 #include "nsCOMPtr.h"
15 #include "nsCOMArray.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsRefPtrHashtable.h"
18 #include "mozilla/Attributes.h"
19 #include "mozilla/TimeStamp.h"
20 #include "mozilla/layers/APZPublicUtils.h"
21 #include "mozilla/dom/Record.h"
22 #include "Units.h"
23 #include "WheelHandlingHelper.h" // for WheelDeltaAdjustmentStrategy
25 class nsFrameLoader;
26 class nsIContent;
27 class nsICookieJarSettings;
28 class nsIDocShell;
29 class nsIDocShellTreeItem;
30 class nsIFrame;
31 class imgIContainer;
32 class nsIContentViewer;
33 class nsIScrollableFrame;
34 class nsITimer;
35 class nsPresContext;
37 namespace mozilla {
39 class EditorBase;
40 class EnterLeaveDispatcher;
41 class EventStates;
42 class IMEContentObserver;
43 class ScrollbarsForWheel;
44 class TextControlElement;
45 class WheelTransaction;
47 namespace dom {
48 class DataTransfer;
49 class Document;
50 class Element;
51 class Selection;
52 class BrowserParent;
53 class RemoteDragStartData;
55 } // namespace dom
57 class OverOutElementsWrapper final : public nsISupports {
58 ~OverOutElementsWrapper();
60 public:
61 OverOutElementsWrapper();
63 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
64 NS_DECL_CYCLE_COLLECTION_CLASS(OverOutElementsWrapper)
66 WeakFrame mLastOverFrame;
68 nsCOMPtr<nsIContent> mLastOverElement;
70 // The last element on which we fired a over event, or null if
71 // the last over event we fired has finished processing.
72 nsCOMPtr<nsIContent> mFirstOverEventElement;
74 // The last element on which we fired a out event, or null if
75 // the last out event we fired has finished processing.
76 nsCOMPtr<nsIContent> mFirstOutEventElement;
79 class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
80 friend class mozilla::EnterLeaveDispatcher;
81 friend class mozilla::ScrollbarsForWheel;
82 friend class mozilla::WheelTransaction;
84 virtual ~EventStateManager();
86 public:
87 EventStateManager();
89 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
90 NS_DECL_NSIOBSERVER
92 nsresult Init();
93 nsresult Shutdown();
95 /* The PreHandleEvent method is called before event dispatch to either
96 * the DOM or frames. Any processing which must not be prevented or
97 * cancelled should occur here. Any processing which is intended to
98 * be conditional based on either DOM or frame processing should occur in
99 * PostHandleEvent. Any centralized event processing which must occur before
100 * DOM or frame event handling should occur here as well.
102 * aOverrideClickTarget can be used to indicate which element should be
103 * used as the *up target when deciding whether to send click event.
104 * This is used when releasing pointer capture. Otherwise null.
106 MOZ_CAN_RUN_SCRIPT
107 nsresult PreHandleEvent(nsPresContext* aPresContext, WidgetEvent* aEvent,
108 nsIFrame* aTargetFrame, nsIContent* aTargetContent,
109 nsEventStatus* aStatus,
110 nsIContent* aOverrideClickTarget);
112 /* The PostHandleEvent method should contain all system processing which
113 * should occur conditionally based on DOM or frame processing. It should
114 * also contain any centralized event processing which must occur after
115 * DOM and frame processing.
117 MOZ_CAN_RUN_SCRIPT
118 nsresult PostHandleEvent(nsPresContext* aPresContext, WidgetEvent* aEvent,
119 nsIFrame* aTargetFrame, nsEventStatus* aStatus,
120 nsIContent* aOverrideClickTarget);
122 void PostHandleKeyboardEvent(WidgetKeyboardEvent* aKeyboardEvent,
123 nsIFrame* aTargetFrame, nsEventStatus& aStatus);
126 * DispatchLegacyMouseScrollEvents() dispatches eLegacyMouseLineOrPageScroll
127 * event and eLegacyMousePixelScroll event for compatibility with old Gecko.
129 void DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
130 WidgetWheelEvent* aEvent,
131 nsEventStatus* aStatus);
133 void NotifyDestroyPresContext(nsPresContext* aPresContext);
134 void SetPresContext(nsPresContext* aPresContext);
135 void ClearFrameRefs(nsIFrame* aFrame);
137 nsIFrame* GetEventTarget();
138 already_AddRefed<nsIContent> GetEventTargetContent(WidgetEvent* aEvent);
140 // We manage 4 states here: ACTIVE, HOVER, DRAGOVER, URLTARGET
141 static bool ManagesState(EventStates aState) {
142 return aState == NS_EVENT_STATE_ACTIVE || aState == NS_EVENT_STATE_HOVER ||
143 aState == NS_EVENT_STATE_DRAGOVER ||
144 aState == NS_EVENT_STATE_URLTARGET;
148 * Notify that the given NS_EVENT_STATE_* bit has changed for this content.
149 * @param aContent Content which has changed states
150 * @param aState Corresponding state flags such as NS_EVENT_STATE_FOCUS
151 * @return Whether the content was able to change all states. Returns false
152 * if a resulting DOM event causes the content node passed in
153 * to not change states. Note, the frame for the content may
154 * change as a result of the content state change, because of
155 * frame reconstructions that may occur, but this does not
156 * affect the return value.
158 bool SetContentState(nsIContent* aContent, EventStates aState);
160 void NativeAnonymousContentRemoved(nsIContent* aAnonContent);
161 void ContentRemoved(dom::Document* aDocument, nsIContent* aContent);
164 * Called when a native anonymous <div> element which is root element of
165 * text editor will be removed.
167 void TextControlRootWillBeRemoved(TextControlElement& aTextControlElement);
170 * Called when a native anonymous <div> element which is root element of
171 * text editor is created.
173 void TextControlRootAdded(dom::Element& aAnonymousDivElement,
174 TextControlElement& aTextControlElement);
176 bool EventStatusOK(WidgetGUIEvent* aEvent);
179 * EventStateManager stores IMEContentObserver while it's observing contents.
180 * Following mehtods are called by IMEContentObserver when it starts to
181 * observe or stops observing the content.
183 void OnStartToObserveContent(IMEContentObserver* aIMEContentObserver);
184 void OnStopObservingContent(IMEContentObserver* aIMEContentObserver);
187 * TryToFlushPendingNotificationsToIME() suggests flushing pending
188 * notifications to IME to IMEContentObserver.
189 * Doesn't do anything in child processes where flushing happens
190 * asynchronously.
192 void TryToFlushPendingNotificationsToIME();
195 * Register accesskey on the given element. When accesskey is activated then
196 * the element will be notified via Element::PerformAccesskey() method.
198 * @param aElement the given element
199 * @param aKey accesskey
201 void RegisterAccessKey(dom::Element* aElement, uint32_t aKey);
204 * Unregister accesskey for the given element.
206 * @param aElement the given element
207 * @param aKey accesskey
209 void UnregisterAccessKey(dom::Element* aElement, uint32_t aKey);
212 * Get accesskey registered on the given element or 0 if there is none.
214 * @param aElement the given element (must not be null)
215 * @return registered accesskey
217 uint32_t GetRegisteredAccessKey(dom::Element* aContent);
219 static void GetAccessKeyLabelPrefix(dom::Element* aElement,
220 nsAString& aPrefix);
223 * HandleAccessKey() looks for access keys which matches with aEvent and
224 * execute when it matches with a chrome access key or some content access
225 * keys.
226 * If the event may match chrome access keys, this handles the access key
227 * synchronously (if there are nested ESMs, their HandleAccessKey() are
228 * also called recursively).
229 * If the event may match content access keys and focused target is a remote
230 * process, this does nothing for the content because when this is called,
231 * it should already have been handled in the remote process.
232 * If the event may match content access keys and focused target is not in
233 * remote process but there are some remote children, this will post
234 * HandleAccessKey messages to all remote children.
236 * @return true if there is accesskey which aEvent and
237 * aAccessCharCodes match with. Otherwise, false.
238 * I.e., when this returns true, a target is executed
239 * or focused.
240 * Note that even if this returns false, a target in
241 * remote process may be executed or focused
242 * asynchronously.
244 bool HandleAccessKey(WidgetKeyboardEvent* aEvent, nsPresContext* aPresContext,
245 nsTArray<uint32_t>& aAccessCharCodes) {
246 return WalkESMTreeToHandleAccessKey(aEvent, aPresContext, aAccessCharCodes,
247 nullptr, eAccessKeyProcessingNormal,
248 true);
252 * CheckIfEventMatchesAccessKey() looks for access key which matches with
253 * aEvent in the process but won't execute it.
255 * @return true if there is accesskey which aEvent matches with
256 * in this process. Otherwise, false.
258 bool CheckIfEventMatchesAccessKey(WidgetKeyboardEvent* aEvent,
259 nsPresContext* aPresContext);
261 nsresult SetCursor(StyleCursorKind, imgIContainer*, const ImageResolution&,
262 const Maybe<gfx::IntPoint>& aHotspot, nsIWidget* aWidget,
263 bool aLockCursor);
266 * Checks if the current mouse over element matches the given
267 * Element (which has a remote frame), and if so, notifies
268 * the BrowserParent of the mouse enter.
269 * Called when we reconstruct the BrowserParent and need to
270 * recompute state on the new object.
272 void RecomputeMouseEnterStateForRemoteFrame(dom::Element& aElement);
274 nsPresContext* GetPresContext() { return mPresContext; }
276 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EventStateManager, nsIObserver)
278 static dom::Document* sMouseOverDocument;
280 static EventStateManager* GetActiveEventStateManager() { return sActiveESM; }
282 // Sets aNewESM to be the active event state manager, and
283 // if aContent is non-null, marks the object as active.
284 static void SetActiveManager(EventStateManager* aNewESM,
285 nsIContent* aContent);
287 // Sets the fullscreen event state on aElement to aIsFullscreen.
288 static void SetFullscreenState(dom::Element* aElement, bool aIsFullscreen);
290 static bool IsRemoteTarget(nsIContent* target);
292 static bool IsTopLevelRemoteTarget(nsIContent* aTarget);
294 // Returns the kind of APZ action the given WidgetWheelEvent will perform.
295 static Maybe<layers::APZWheelAction> APZWheelActionFor(
296 const WidgetWheelEvent* aEvent);
298 // For some kinds of scrollings, the delta values of WidgetWheelEvent are
299 // possbile to be adjusted. This function is used to detect such scrollings
300 // and returns a wheel delta adjustment strategy to use, which is corresponded
301 // to the kind of the scrolling.
302 // It returns WheelDeltaAdjustmentStrategy::eAutoDir if the current default
303 // action is auto-dir scrolling which honours the scrolling target(The
304 // comments in WheelDeltaAdjustmentStrategy describes the concept in detail).
305 // It returns WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour if the
306 // current action is auto-dir scrolling which honours the root element in the
307 // document where the scrolling target is(The comments in
308 // WheelDeltaAdjustmentStrategy describes the concept in detail).
309 // It returns WheelDeltaAdjustmentStrategy::eHorizontalize if the current
310 // default action is horizontalized scrolling.
311 // It returns WheelDeltaAdjustmentStrategy::eNone to mean no delta adjustment
312 // strategy should be used if the scrolling is just a tranditional scrolling
313 // whose delta values are never possible to be adjusted.
314 static WheelDeltaAdjustmentStrategy GetWheelDeltaAdjustmentStrategy(
315 const WidgetWheelEvent& aEvent);
317 // Returns user-set multipliers for a wheel event.
318 static void GetUserPrefsForWheelEvent(const WidgetWheelEvent* aEvent,
319 double* aOutMultiplierX,
320 double* aOutMultiplierY);
322 // Holds the point in screen coords that a mouse event was dispatched to,
323 // before we went into pointer lock mode. This is constantly updated while
324 // the pointer is not locked, but we don't update it while the pointer is
325 // locked. This is used by dom::Event::GetScreenCoords() to make mouse
326 // events' screen coord appear frozen at the last mouse position while
327 // the pointer is locked.
328 static CSSIntPoint sLastScreenPoint;
330 // Holds the point in client coords of the last mouse event. Used by
331 // dom::Event::GetClientCoords() to make mouse events' client coords appear
332 // frozen at the last mouse position while the pointer is locked.
333 static CSSIntPoint sLastClientPoint;
336 * If the absolute values of mMultiplierX and/or mMultiplierY are equal or
337 * larger than this value, the computed scroll amount isn't rounded down to
338 * the page width or height.
340 enum { MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL = 1000 };
343 * HandleMiddleClickPaste() handles middle mouse button event as pasting
344 * clipboard text. Note that if aEditorBase is nullptr, this only
345 * dispatches ePaste event because it's necessary for some web apps which
346 * want to implement their own editor and supports middle click paste.
348 * @param aPresShell The PresShell for the ESM. This lifetime
349 * should be guaranteed by the caller.
350 * @param aMouseEvent The eMouseClick event which caused the
351 * paste.
352 * @param aStatus The event status of aMouseEvent.
353 * @param aEditorBase EditorBase which may be pasted the
354 * clipboard text by the middle click.
355 * If there is no editor for aMouseEvent,
356 * set nullptr.
358 MOZ_CAN_RUN_SCRIPT
359 nsresult HandleMiddleClickPaste(PresShell* aPresShell,
360 WidgetMouseEvent* aMouseEvent,
361 nsEventStatus* aStatus,
362 EditorBase* aEditorBase);
364 static void ConsumeInteractionData(
365 dom::Record<nsString, dom::InteractionData>& aInteractions);
367 // Stop tracking a possible drag. If aClearInChildProcesses is true, send
368 // a notification to any child processes that are in the drag service that
369 // tried to start a drag.
370 void StopTrackingDragGesture(bool aClearInChildProcesses);
372 protected:
374 * If aTargetFrame's widget has a cached cursor value, resets the cursor
375 * such that the next call to SetCursor on the widget will force an update
376 * of the native cursor. For use in getting puppet widget to update its
377 * cursor between mouse exit / enter transitions. This call basically wraps
378 * nsIWidget ClearCachedCursor.
380 void ClearCachedWidgetCursor(nsIFrame* aTargetFrame);
382 void UpdateCursor(nsPresContext* aPresContext, WidgetEvent* aEvent,
383 nsIFrame* aTargetFrame, nsEventStatus* aStatus);
385 * Turn a GUI mouse/pointer event into a mouse/pointer event targeted at the
386 * specified content. This returns the primary frame for the content (or null
387 * if it goes away during the event).
389 nsIFrame* DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent,
390 EventMessage aMessage,
391 nsIContent* aTargetContent,
392 nsIContent* aRelatedContent);
394 * Synthesize DOM pointerover and pointerout events
396 void GeneratePointerEnterExit(EventMessage aMessage,
397 WidgetMouseEvent* aEvent);
399 * Synthesize DOM and frame mouseover and mouseout events from this
400 * MOUSE_MOVE or MOUSE_EXIT event.
402 void GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent);
404 * Tell this ESM and ESMs in parent documents that the mouse is
405 * over some content in this document.
407 void NotifyMouseOver(WidgetMouseEvent* aMouseEvent, nsIContent* aContent);
409 * Tell this ESM and ESMs in affected child documents that the mouse
410 * has exited this document's currently hovered content.
411 * @param aMouseEvent the event that triggered the mouseout
412 * @param aMovingInto the content node we've moved into. This is used to set
413 * the relatedTarget for mouseout events. Also, if it's non-null
414 * NotifyMouseOut will NOT change the current hover content to null;
415 * in that case the caller is responsible for updating hover state.
417 void NotifyMouseOut(WidgetMouseEvent* aMouseEvent, nsIContent* aMovingInto);
418 MOZ_CAN_RUN_SCRIPT void GenerateDragDropEnterExit(
419 nsPresContext* aPresContext, WidgetDragEvent* aDragEvent);
422 * Return mMouseEnterLeaveHelper or relevant mPointersEnterLeaveHelper
423 * elements wrapper. If mPointersEnterLeaveHelper does not contain wrapper for
424 * pointerId it create new one
426 OverOutElementsWrapper* GetWrapperByEventID(WidgetMouseEvent* aMouseEvent);
429 * Fire the dragenter and dragexit/dragleave events when the mouse moves to a
430 * new target.
432 * @param aRelatedTarget relatedTarget to set for the event
433 * @param aTargetContent target to set for the event
434 * @param aTargetFrame target frame for the event
436 MOZ_CAN_RUN_SCRIPT void FireDragEnterOrExit(nsPresContext* aPresContext,
437 WidgetDragEvent* aDragEvent,
438 EventMessage aMessage,
439 nsIContent* aRelatedTarget,
440 nsIContent* aTargetContent,
441 AutoWeakFrame& aTargetFrame);
443 * Update the initial drag session data transfer with any changes that occur
444 * on cloned data transfer objects used for events.
446 void UpdateDragDataTransfer(WidgetDragEvent* dragEvent);
449 * InitAndDispatchClickEvent() dispatches a click event.
451 * @param aMouseUpEvent eMouseUp event which causes the click event.
452 * EventCausesClickEvents() must return true
453 * if this event is set to it.
454 * @param aStatus Returns the result of click event.
455 * If the status indicates consumed, the
456 * value won't be overwritten with
457 * nsEventStatus_eIgnore.
458 * @param aMessage Should be eMouseClick, eMouseDoubleClick or
459 * eMouseAuxClick.
460 * @param aPresShell The PresShell.
461 * @param aMouseUpContent The event target of aMouseUpEvent.
462 * @param aCurrentTarget Current target of the caller.
463 * @param aNoContentDispatch true if the event shouldn't be exposed to
464 * web contents (although will be fired on
465 * document and window).
466 * @param aOverrideClickTarget Preferred click event target. If this is
467 * not nullptr, aMouseUpContent and
468 * aCurrentTarget are ignored.
470 MOZ_CAN_RUN_SCRIPT
471 static nsresult InitAndDispatchClickEvent(
472 WidgetMouseEvent* aMouseUpEvent, nsEventStatus* aStatus,
473 EventMessage aMessage, PresShell* aPresShell, nsIContent* aMouseUpContent,
474 AutoWeakFrame aCurrentTarget, bool aNoContentDispatch,
475 nsIContent* aOverrideClickTarget);
477 nsresult SetClickCount(WidgetMouseEvent* aEvent, nsEventStatus* aStatus,
478 nsIContent* aOverrideClickTarget = nullptr);
481 * EventCausesClickEvents() returns true when aMouseEvent is an eMouseUp
482 * event and it should cause eMouseClick, eMouseDoubleClick and/or
483 * eMouseAuxClick events. Note that this method assumes that
484 * aMouseEvent.mClickCount has already been initialized with SetClickCount().
486 static bool EventCausesClickEvents(const WidgetMouseEvent& aMouseEvent);
489 * PostHandleMouseUp() handles default actions of eMouseUp event.
491 * @param aMouseUpEvent eMouseUp event which causes the click event.
492 * EventCausesClickEvents() must return true
493 * if this event is set to it.
494 * @param aStatus Returns the result of event status.
495 * If one of dispatching event is consumed or
496 * this does something as default action,
497 * returns nsEventStatus_eConsumeNoDefault.
498 * @param aOverrideClickTarget Preferred click event target. If nullptr,
499 * aMouseUpEvent target and current target
500 * are used.
502 MOZ_CAN_RUN_SCRIPT
503 nsresult PostHandleMouseUp(WidgetMouseEvent* aMouseUpEvent,
504 nsEventStatus* aStatus,
505 nsIContent* aOverrideClickTarget);
508 * DispatchClickEvents() dispatches eMouseClick, eMouseDoubleClick and
509 * eMouseAuxClick events for aMouseUpEvent. aMouseUpEvent should cause
510 * click event.
512 * @param aPresShell The PresShell.
513 * @param aMouseUpEvent eMouseUp event which causes the click event.
514 * EventCausesClickEvents() must return true
515 * if this event is set to it.
516 * @param aStatus Returns the result of event status.
517 * If one of dispatching click event is
518 * consumed, returns
519 * nsEventStatus_eConsumeNoDefault.
520 * @param aMouseUpContent The event target of aMouseUpEvent.
521 * @param aOverrideClickTarget Preferred click event target. If this is
522 * not nullptr, aMouseUpContent and
523 * current target frame of the ESM are ignored.
525 MOZ_CAN_RUN_SCRIPT
526 nsresult DispatchClickEvents(PresShell* aPresShell,
527 WidgetMouseEvent* aMouseUpEvent,
528 nsEventStatus* aStatus,
529 nsIContent* aMouseUpContent,
530 nsIContent* aOverrideClickTarget);
532 void EnsureDocument(nsPresContext* aPresContext);
533 MOZ_CAN_RUN_SCRIPT_BOUNDARY
534 void FlushLayout(nsPresContext* aPresContext);
537 * The phases of WalkESMTreeToHandleAccessKey processing. See below.
539 enum ProcessingAccessKeyState {
540 eAccessKeyProcessingNormal = 0,
541 eAccessKeyProcessingUp,
542 eAccessKeyProcessingDown
546 * Walk EMS to look for access key and execute found access key when aExecute
547 * is true.
548 * If there is registered element for the accesskey given by the key event
549 * and modifier mask then call element.PerformAccesskey(), otherwise call
550 * WalkESMTreeToHandleAccessKey() recursively, on descendant docshells first,
551 * then on the ancestor (with |aBubbledFrom| set to the docshell associated
552 * with |this|), until something matches.
554 * @param aEvent the keyboard event triggering the acccess key
555 * @param aPresContext the presentation context
556 * @param aAccessCharCodes list of charcode candidates
557 * @param aBubbledFrom is used by an ancestor to avoid calling
558 * WalkESMTreeToHandleAccessKey() on the child the call originally
559 * came from, i.e. this is the child that recursively called us in
560 * its Up phase. The initial caller passes |nullptr| here. This is to
561 * avoid an infinite loop.
562 * @param aAccessKeyState Normal, Down or Up processing phase (see enums
563 * above). The initial event receiver uses 'normal', then 'down' when
564 * processing children and Up when recursively calling its ancestor.
565 * @param aExecute is true, execute an accesskey if it's found. Otherwise,
566 * found accesskey won't be executed.
568 * @return true if there is a target which aEvent and
569 * aAccessCharCodes match with in this process.
570 * Otherwise, false. I.e., when this returns true and
571 * aExecute is true, a target is executed or focused.
572 * Note that even if this returns false, a target in
573 * remote process may be executed or focused
574 * asynchronously.
576 bool WalkESMTreeToHandleAccessKey(WidgetKeyboardEvent* aEvent,
577 nsPresContext* aPresContext,
578 nsTArray<uint32_t>& aAccessCharCodes,
579 nsIDocShellTreeItem* aBubbledFrom,
580 ProcessingAccessKeyState aAccessKeyState,
581 bool aExecute);
584 * Look for access key and execute found access key if aExecute is true in
585 * the instance.
587 * @return true if there is a target which matches with
588 * aAccessCharCodes and aIsTrustedEvent. Otherwise,
589 * false. I.e., when this returns true and aExecute
590 * is true, a target is executed or focused.
592 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool LookForAccessKeyAndExecute(
593 nsTArray<uint32_t>& aAccessCharCodes, bool aIsTrustedEvent,
594 bool aIsRepeat, bool aExecute);
596 //---------------------------------------------
597 // DocShell Focus Traversal Methods
598 //---------------------------------------------
600 dom::Element* GetFocusedElement();
601 bool IsShellVisible(nsIDocShell* aShell);
603 // These functions are for mousewheel and pixel scrolling
605 class WheelPrefs {
606 public:
607 static WheelPrefs* GetInstance();
608 static void Shutdown();
611 * ApplyUserPrefsToDelta() overrides the wheel event's delta values with
612 * user prefs.
614 void ApplyUserPrefsToDelta(WidgetWheelEvent* aEvent);
617 * Returns whether or not ApplyUserPrefsToDelta() would change the delta
618 * values of an event.
620 void GetUserPrefsForEvent(const WidgetWheelEvent* aEvent,
621 double* aOutMultiplierX, double* aOutMultiplierY);
624 * If ApplyUserPrefsToDelta() changed the delta values with customized
625 * prefs, the overflowDelta values would be inflated.
626 * CancelApplyingUserPrefsFromOverflowDelta() cancels the inflation.
628 void CancelApplyingUserPrefsFromOverflowDelta(WidgetWheelEvent* aEvent);
631 * Computes the default action for the aEvent with the prefs.
633 enum Action : uint8_t {
634 ACTION_NONE = 0,
635 ACTION_SCROLL,
636 ACTION_HISTORY,
637 ACTION_ZOOM,
638 // Horizontalized scrolling means treating vertical wheel scrolling as
639 // horizontal scrolling during the process of its default action and
640 // plugins handling scrolling. Note that delta values as the event object
641 // in a DOM event listener won't be affected, and will be still the
642 // original values. For more details, refer to
643 // mozilla::WheelDeltaAdjustmentStrategy::eHorizontalize
644 ACTION_HORIZONTALIZED_SCROLL,
645 ACTION_PINCH_ZOOM,
646 ACTION_LAST = ACTION_PINCH_ZOOM,
647 // Following actions are used only by internal processing. So, cannot
648 // specified by prefs.
649 ACTION_SEND_TO_PLUGIN,
651 Action ComputeActionFor(const WidgetWheelEvent* aEvent);
654 * NeedToComputeLineOrPageDelta() returns if the aEvent needs to be
655 * computed the lineOrPageDelta values.
657 bool NeedToComputeLineOrPageDelta(const WidgetWheelEvent* aEvent);
660 * IsOverOnePageScrollAllowed*() checks whether wheel scroll amount should
661 * be rounded down to the page width/height (false) or not (true).
663 bool IsOverOnePageScrollAllowedX(const WidgetWheelEvent* aEvent);
664 bool IsOverOnePageScrollAllowedY(const WidgetWheelEvent* aEvent);
666 private:
667 WheelPrefs();
668 ~WheelPrefs();
670 static void OnPrefChanged(const char* aPrefName, void* aClosure);
672 enum Index {
673 INDEX_DEFAULT = 0,
674 INDEX_ALT,
675 INDEX_CONTROL,
676 INDEX_META,
677 INDEX_SHIFT,
678 INDEX_OS,
679 COUNT_OF_MULTIPLIERS
683 * GetIndexFor() returns the index of the members which should be used for
684 * the aEvent. When only one modifier key of MODIFIER_ALT,
685 * MODIFIER_CONTROL, MODIFIER_META, MODIFIER_SHIFT or MODIFIER_OS is
686 * pressed, returns the index for the modifier. Otherwise, this return the
687 * default index which is used at either no modifier key is pressed or
688 * two or modifier keys are pressed.
690 Index GetIndexFor(const WidgetWheelEvent* aEvent);
693 * GetPrefNameBase() returns the base pref name for aEvent.
694 * It's decided by GetModifierForPref() which modifier should be used for
695 * the aEvent.
697 * @param aBasePrefName The result, must be "mousewheel.with_*." or
698 * "mousewheel.default.".
700 void GetBasePrefName(Index aIndex, nsACString& aBasePrefName);
702 void Init(Index aIndex);
704 void Reset();
707 * Retrieve multiplier for aEvent->mDeltaX and aEvent->mDeltaY.
709 * Note that if the default action is ACTION_HORIZONTALIZED_SCROLL and the
710 * delta values have been adjusted by WheelDeltaHorizontalizer() before this
711 * function is called, this function will swap the X and Y multipliers. By
712 * doing this, multipliers will still apply to the delta values they
713 * originally corresponded to.
715 * @param aEvent The event which is being handled.
716 * @param aIndex The index of mMultiplierX and mMultiplierY.
717 * Should be result of GetIndexFor(aEvent).
718 * @param aMultiplierForDeltaX Will be set to multiplier for
719 * aEvent->mDeltaX.
720 * @param aMultiplierForDeltaY Will be set to multiplier for
721 * aEvent->mDeltaY.
723 void GetMultiplierForDeltaXAndY(const WidgetWheelEvent* aEvent,
724 Index aIndex, double* aMultiplierForDeltaX,
725 double* aMultiplierForDeltaY);
727 bool mInit[COUNT_OF_MULTIPLIERS];
728 double mMultiplierX[COUNT_OF_MULTIPLIERS];
729 double mMultiplierY[COUNT_OF_MULTIPLIERS];
730 double mMultiplierZ[COUNT_OF_MULTIPLIERS];
731 Action mActions[COUNT_OF_MULTIPLIERS];
733 * action values overridden by .override_x pref.
734 * If an .override_x value is -1, same as the
735 * corresponding mActions value.
737 Action mOverriddenActionsX[COUNT_OF_MULTIPLIERS];
739 static WheelPrefs* sInstance;
743 * DeltaDirection is used for specifying whether the called method should
744 * handle vertical delta or horizontal delta.
745 * This is clearer than using bool.
747 enum DeltaDirection { DELTA_DIRECTION_X = 0, DELTA_DIRECTION_Y };
749 struct MOZ_STACK_CLASS EventState {
750 bool mDefaultPrevented;
751 bool mDefaultPreventedByContent;
753 EventState()
754 : mDefaultPrevented(false), mDefaultPreventedByContent(false) {}
758 * SendLineScrollEvent() dispatches a DOMMouseScroll event for the
759 * WidgetWheelEvent. This method shouldn't be called for non-trusted
760 * wheel event because it's not necessary for compatiblity.
762 * @param aTargetFrame The event target of wheel event.
763 * @param aEvent The original Wheel event.
764 * @param aState The event which should be set to the dispatching
765 * event. This also returns the dispatched event
766 * state.
767 * @param aDelta The delta value of the event.
768 * @param aDeltaDirection The X/Y direction of dispatching event.
770 void SendLineScrollEvent(nsIFrame* aTargetFrame, WidgetWheelEvent* aEvent,
771 EventState& aState, int32_t aDelta,
772 DeltaDirection aDeltaDirection);
775 * SendPixelScrollEvent() dispatches a MozMousePixelScroll event for the
776 * WidgetWheelEvent. This method shouldn't be called for non-trusted
777 * wheel event because it's not necessary for compatiblity.
779 * @param aTargetFrame The event target of wheel event.
780 * @param aEvent The original Wheel event.
781 * @param aState The event which should be set to the dispatching
782 * event. This also returns the dispatched event
783 * state.
784 * @param aPixelDelta The delta value of the event.
785 * @param aDeltaDirection The X/Y direction of dispatching event.
787 void SendPixelScrollEvent(nsIFrame* aTargetFrame, WidgetWheelEvent* aEvent,
788 EventState& aState, int32_t aPixelDelta,
789 DeltaDirection aDeltaDirection);
792 * ComputeScrollTargetAndMayAdjustWheelEvent() returns the scrollable frame
793 * which should be scrolled.
795 * @param aTargetFrame The event target of the wheel event.
796 * @param aEvent The handling mouse wheel event.
797 * @param aOptions The options for finding the scroll target.
798 * Callers should use COMPUTE_*.
799 * @return The scrollable frame which should be scrolled.
801 // These flags are used in ComputeScrollTargetAndMayAdjustWheelEvent().
802 // Callers should use COMPUTE_*.
803 enum {
804 PREFER_MOUSE_WHEEL_TRANSACTION = 0x00000001,
805 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS = 0x00000002,
806 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS = 0x00000004,
807 START_FROM_PARENT = 0x00000008,
808 INCLUDE_PLUGIN_AS_TARGET = 0x00000010,
809 // Indicates the wheel scroll event being computed is an auto-dir scroll, so
810 // its delta may be adjusted after being computed.
811 MAY_BE_ADJUSTED_BY_AUTO_DIR = 0x00000020,
813 enum ComputeScrollTargetOptions {
814 // At computing scroll target for legacy mouse events, we should return
815 // first scrollable element even when it's not scrollable to the direction.
816 COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET = 0,
817 // Default action prefers the scrolled element immediately before if it's
818 // still under the mouse cursor. Otherwise, it prefers the nearest
819 // scrollable ancestor which will be scrolled actually.
820 COMPUTE_DEFAULT_ACTION_TARGET =
821 (PREFER_MOUSE_WHEEL_TRANSACTION |
822 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS |
823 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS),
824 COMPUTE_DEFAULT_ACTION_TARGET_WITH_AUTO_DIR =
825 (COMPUTE_DEFAULT_ACTION_TARGET | MAY_BE_ADJUSTED_BY_AUTO_DIR),
826 // Look for the nearest scrollable ancestor which can be scrollable with
827 // aEvent.
828 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS =
829 (PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS | START_FROM_PARENT),
830 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS =
831 (PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS | START_FROM_PARENT),
832 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS_WITH_AUTO_DIR =
833 (COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS |
834 MAY_BE_ADJUSTED_BY_AUTO_DIR),
835 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS_WITH_AUTO_DIR =
836 (COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS |
837 MAY_BE_ADJUSTED_BY_AUTO_DIR),
840 // Compute the scroll target.
841 // The delta values in the wheel event may be changed if the event is for
842 // auto-dir scrolling. For information on auto-dir,
843 // @see mozilla::WheelDeltaAdjustmentStrategy
844 nsIFrame* ComputeScrollTargetAndMayAdjustWheelEvent(
845 nsIFrame* aTargetFrame, WidgetWheelEvent* aEvent,
846 ComputeScrollTargetOptions aOptions);
848 nsIFrame* ComputeScrollTargetAndMayAdjustWheelEvent(
849 nsIFrame* aTargetFrame, double aDirectionX, double aDirectionY,
850 WidgetWheelEvent* aEvent, ComputeScrollTargetOptions aOptions);
852 nsIFrame* ComputeScrollTarget(nsIFrame* aTargetFrame,
853 WidgetWheelEvent* aEvent,
854 ComputeScrollTargetOptions aOptions) {
855 MOZ_ASSERT(!(aOptions & MAY_BE_ADJUSTED_BY_AUTO_DIR),
856 "aEvent may be modified by auto-dir");
857 return ComputeScrollTargetAndMayAdjustWheelEvent(aTargetFrame, aEvent,
858 aOptions);
861 nsIFrame* ComputeScrollTarget(nsIFrame* aTargetFrame, double aDirectionX,
862 double aDirectionY, WidgetWheelEvent* aEvent,
863 ComputeScrollTargetOptions aOptions) {
864 MOZ_ASSERT(!(aOptions & MAY_BE_ADJUSTED_BY_AUTO_DIR),
865 "aEvent may be modified by auto-dir");
866 return ComputeScrollTargetAndMayAdjustWheelEvent(
867 aTargetFrame, aDirectionX, aDirectionY, aEvent, aOptions);
871 * GetScrollAmount() returns the scroll amount in app uints of one line or
872 * one page. If the wheel event scrolls a page, returns the page width and
873 * height. Otherwise, returns line height for both its width and height.
875 * @param aScrollableFrame A frame which will be scrolled by the event.
876 * The result of
877 * ComputeScrollTargetAndMayAdjustWheelEvent() is
878 * expected for this value.
879 * This can be nullptr if there is no scrollable
880 * frame. Then, this method uses root frame's
881 * line height or visible area's width and height.
883 nsSize GetScrollAmount(nsPresContext* aPresContext, WidgetWheelEvent* aEvent,
884 nsIScrollableFrame* aScrollableFrame);
887 * DoScrollText() scrolls the scrollable frame for aEvent.
889 void DoScrollText(nsIScrollableFrame* aScrollableFrame,
890 WidgetWheelEvent* aEvent);
892 void DoScrollHistory(int32_t direction);
893 void DoScrollZoom(nsIFrame* aTargetFrame, int32_t adjustment);
894 void ChangeZoom(bool aIncrease);
897 * DeltaAccumulator class manages delta values for dispatching DOMMouseScroll
898 * event. If wheel events are caused by pixel scroll only devices or
899 * the delta values are customized by prefs, this class stores the delta
900 * values and set lineOrPageDelta values.
902 class DeltaAccumulator {
903 public:
904 static DeltaAccumulator* GetInstance() {
905 if (!sInstance) {
906 sInstance = new DeltaAccumulator;
908 return sInstance;
911 static void Shutdown() {
912 delete sInstance;
913 sInstance = nullptr;
916 bool IsInTransaction() { return mHandlingDeltaMode != UINT32_MAX; }
919 * InitLineOrPageDelta() stores pixel delta values of WidgetWheelEvents
920 * which are caused if it's needed. And if the accumulated delta becomes a
921 * line height, sets lineOrPageDeltaX and lineOrPageDeltaY automatically.
923 void InitLineOrPageDelta(nsIFrame* aTargetFrame, EventStateManager* aESM,
924 WidgetWheelEvent* aEvent);
927 * Reset() resets all members.
929 void Reset();
932 * ComputeScrollAmountForDefaultAction() computes the default action's
933 * scroll amount in device pixels with mPendingScrollAmount*.
935 nsIntPoint ComputeScrollAmountForDefaultAction(
936 WidgetWheelEvent* aEvent, const nsIntSize& aScrollAmountInDevPixels);
938 private:
939 DeltaAccumulator()
940 : mX(0.0),
941 mY(0.0),
942 mPendingScrollAmountX(0.0),
943 mPendingScrollAmountY(0.0),
944 mHandlingDeltaMode(UINT32_MAX),
945 mIsNoLineOrPageDeltaDevice(false) {}
947 double mX;
948 double mY;
950 // When default action of a wheel event is scroll but some delta values
951 // are ignored because the computed amount values are not integer, the
952 // fractional values are saved by these members.
953 double mPendingScrollAmountX;
954 double mPendingScrollAmountY;
956 TimeStamp mLastTime;
958 uint32_t mHandlingDeltaMode;
959 bool mIsNoLineOrPageDeltaDevice;
961 static DeltaAccumulator* sInstance;
964 // end mousewheel functions
967 * When a touch gesture is about to start, this function determines what
968 * kind of gesture interaction we will want to use, based on what is
969 * underneath the initial touch point.
970 * Currently it decides between panning (finger scrolling) or dragging
971 * the target element, as well as the orientation to trigger panning and
972 * display visual boundary feedback. The decision is stored back in aEvent.
974 void DecideGestureEvent(WidgetGestureNotifyEvent* aEvent,
975 nsIFrame* targetFrame);
977 // routines for the d&d gesture tracking state machine
978 void BeginTrackingDragGesture(nsPresContext* aPresContext,
979 WidgetMouseEvent* aDownEvent,
980 nsIFrame* aDownFrame);
982 void SetGestureDownPoint(WidgetGUIEvent* aEvent);
984 LayoutDeviceIntPoint GetEventRefPoint(WidgetEvent* aEvent) const;
986 friend class mozilla::dom::BrowserParent;
987 void BeginTrackingRemoteDragGesture(nsIContent* aContent,
988 dom::RemoteDragStartData* aDragStartData);
990 MOZ_CAN_RUN_SCRIPT
991 void GenerateDragGesture(nsPresContext* aPresContext,
992 WidgetInputEvent* aEvent);
995 * When starting a dnd session, UA must fire a pointercancel event and stop
996 * firing the subsequent pointer events.
998 MOZ_CAN_RUN_SCRIPT
999 void MaybeFirePointerCancel(WidgetInputEvent* aEvent);
1002 * Determine which node the drag should be targeted at.
1003 * This is either the node clicked when there is a selection, or, for HTML,
1004 * the element with a draggable property set to true.
1006 * aSelectionTarget - target to check for selection
1007 * aDataTransfer - data transfer object that will contain the data to drag
1008 * aAllowEmptyDataTransfer - [out] set to true, if dnd operation can be
1009 * started even if DataTransfer is empty
1010 * aSelection - [out] set to the selection to be dragged
1011 * aTargetNode - [out] the draggable node, or null if there isn't one
1012 * aPrincipal - [out] set to the triggering principal of the drag, or null
1013 * if it's from browser chrome or OS
1014 * aCookieJarSettings - [out] set to the cookieJarSettings of the drag, or
1015 * null if it's from browser chrome or OS.
1017 void DetermineDragTargetAndDefaultData(
1018 nsPIDOMWindowOuter* aWindow, nsIContent* aSelectionTarget,
1019 dom::DataTransfer* aDataTransfer, bool* aAllowEmptyDataTransfer,
1020 dom::Selection** aSelection,
1021 dom::RemoteDragStartData** aRemoteDragStartData, nsIContent** aTargetNode,
1022 nsIPrincipal** aPrincipal, nsIContentSecurityPolicy** aCsp,
1023 nsICookieJarSettings** aCookieJarSettings);
1026 * Perform the default handling for the dragstart event and set up a
1027 * drag for aDataTransfer if it contains any data. Returns true if a drag has
1028 * started.
1030 * aDragEvent - the dragstart event
1031 * aDataTransfer - the data transfer that holds the data to be dragged
1032 * aAllowEmptyDataTransfer - if true, dnd can be started even if there is no
1033 * data to drag
1034 * aDragTarget - the target of the drag
1035 * aSelection - the selection to be dragged
1036 * aData - information pertaining to a drag started in a child process
1037 * aPrincipal - the triggering principal of the drag, or null if it's from
1038 * browser chrome or OS
1039 * aCookieJarSettings - the cookieJarSettings of the drag. or null if it's
1040 * from browser chrome or OS.
1042 MOZ_CAN_RUN_SCRIPT
1043 bool DoDefaultDragStart(
1044 nsPresContext* aPresContext, WidgetDragEvent* aDragEvent,
1045 dom::DataTransfer* aDataTransfer, bool aAllowEmptyDataTransfer,
1046 nsIContent* aDragTarget, dom::Selection* aSelection,
1047 dom::RemoteDragStartData* aDragStartData, nsIPrincipal* aPrincipal,
1048 nsIContentSecurityPolicy* aCsp, nsICookieJarSettings* aCookieJarSettings);
1050 bool IsTrackingDragGesture() const { return mGestureDownContent != nullptr; }
1052 * Set the fields of aEvent to reflect the mouse position and modifier keys
1053 * that were set when the user first pressed the mouse button (stored by
1054 * BeginTrackingDragGesture). aEvent->mWidget must be
1055 * mCurrentTarget->GetNearestWidget().
1057 void FillInEventFromGestureDown(WidgetMouseEvent* aEvent);
1059 MOZ_CAN_RUN_SCRIPT
1060 nsresult DoContentCommandEvent(WidgetContentCommandEvent* aEvent);
1061 MOZ_CAN_RUN_SCRIPT
1062 nsresult DoContentCommandInsertTextEvent(WidgetContentCommandEvent* aEvent);
1063 nsresult DoContentCommandScrollEvent(WidgetContentCommandEvent* aEvent);
1065 dom::BrowserParent* GetCrossProcessTarget();
1066 bool IsTargetCrossProcess(WidgetGUIEvent* aEvent);
1069 * DispatchCrossProcessEvent() try to post aEvent to target remote process.
1070 * If you need to check if the event is posted to a remote process, you
1071 * can use aEvent->HasBeenPostedToRemoteProcess().
1073 void DispatchCrossProcessEvent(WidgetEvent* aEvent,
1074 dom::BrowserParent* aRemoteTarget,
1075 nsEventStatus* aStatus);
1077 * HandleCrossProcessEvent() may post aEvent to target remote processes.
1078 * When it succeeded to post the event to at least one remote process,
1079 * returns true. Otherwise, including the case not tried to dispatch to
1080 * post the event, returns false.
1081 * If you need to check if the event is posted to at least one remote
1082 * process, you can use aEvent->HasBeenPostedToRemoteProcess().
1084 bool HandleCrossProcessEvent(WidgetEvent* aEvent, nsEventStatus* aStatus);
1086 void ReleaseCurrentIMEContentObserver();
1088 MOZ_CAN_RUN_SCRIPT void HandleQueryContentEvent(
1089 WidgetQueryContentEvent* aEvent);
1091 private:
1092 // Removes a node from the :hover / :active chain if needed, notifying if the
1093 // node is not a NAC subtree.
1095 // Only meant to be called from ContentRemoved and
1096 // NativeAnonymousContentRemoved.
1097 void RemoveNodeFromChainIfNeeded(EventStates aState,
1098 nsIContent* aContentRemoved, bool aNotify);
1100 bool IsEventOutsideDragThreshold(WidgetInputEvent* aEvent) const;
1102 static inline void DoStateChange(dom::Element* aElement, EventStates aState,
1103 bool aAddState);
1104 static inline void DoStateChange(nsIContent* aContent, EventStates aState,
1105 bool aAddState);
1106 static void UpdateAncestorState(nsIContent* aStartNode,
1107 nsIContent* aStopBefore, EventStates aState,
1108 bool aAddState);
1109 static void ResetLastOverForContent(
1110 const uint32_t& aIdx, const RefPtr<OverOutElementsWrapper>& aChunk,
1111 nsIContent* aClosure);
1114 * Update the attribute mLastRefPoint of the mouse event. It should be
1115 * the center of the window while the pointer is locked.
1116 * the same value as mRefPoint while there is no known last ref point.
1117 * the same value as the last known mRefPoint.
1119 static void UpdateLastRefPointOfMouseEvent(WidgetMouseEvent* aMouseEvent);
1121 static void ResetPointerToWindowCenterWhilePointerLocked(
1122 WidgetMouseEvent* aMouseEvent);
1124 // Update the last known ref point to the current event's mRefPoint.
1125 static void UpdateLastPointerPosition(WidgetMouseEvent* aMouseEvent);
1128 * Notify target when user has been interaction with some speicific user
1129 * gestures which are eKeyUp, eMouseUp, eTouchEnd.
1131 void NotifyTargetUserActivation(WidgetEvent* aEvent,
1132 nsIContent* aTargetContent);
1134 already_AddRefed<EventStateManager> ESMFromContentOrThis(
1135 nsIContent* aContent);
1137 StyleCursorKind mLockCursor;
1138 bool mLastFrameConsumedSetCursor;
1140 // Last mouse event mRefPoint (the offset from the widget's origin in
1141 // device pixels) when mouse was locked, used to restore mouse position
1142 // after unlocking.
1143 static LayoutDeviceIntPoint sPreLockPoint;
1145 // Stores the mRefPoint of the last synthetic mouse move we dispatched
1146 // to re-center the mouse when we were pointer locked. If this is (-1,-1) it
1147 // means we've not recently dispatched a centering event. We use this to
1148 // detect when we receive the synth event, so we can cancel and not send it
1149 // to content.
1150 static LayoutDeviceIntPoint sSynthCenteringPoint;
1152 WeakFrame mCurrentTarget;
1153 nsCOMPtr<nsIContent> mCurrentTargetContent;
1154 static AutoWeakFrame sLastDragOverFrame;
1156 // Stores the mRefPoint (the offset from the widget's origin in device
1157 // pixels) of the last mouse event.
1158 static LayoutDeviceIntPoint sLastRefPoint;
1160 // member variables for the d&d gesture state machine
1161 LayoutDeviceIntPoint mGestureDownPoint; // screen coordinates
1162 // The content to use as target if we start a d&d (what we drag).
1163 nsCOMPtr<nsIContent> mGestureDownContent;
1164 // The content of the frame where the mouse-down event occurred. It's the same
1165 // as the target in most cases but not always - for example when dragging
1166 // an <area> of an image map this is the image. (bug 289667)
1167 nsCOMPtr<nsIContent> mGestureDownFrameOwner;
1168 // Data associated with a drag started in a content process.
1169 RefPtr<dom::RemoteDragStartData> mGestureDownDragStartData;
1170 // State of keys when the original gesture-down happened
1171 Modifiers mGestureModifiers;
1172 uint16_t mGestureDownButtons;
1174 nsCOMPtr<nsIContent> mLastLeftMouseDownContent;
1175 nsCOMPtr<nsIContent> mLastMiddleMouseDownContent;
1176 nsCOMPtr<nsIContent> mLastRightMouseDownContent;
1178 nsCOMPtr<nsIContent> mActiveContent;
1179 nsCOMPtr<nsIContent> mHoverContent;
1180 static nsCOMPtr<nsIContent> sDragOverContent;
1181 nsCOMPtr<nsIContent> mURLTargetContent;
1183 nsPresContext* mPresContext; // Not refcnted
1184 RefPtr<dom::Document> mDocument; // Doesn't necessarily need to be owner
1186 RefPtr<IMEContentObserver> mIMEContentObserver;
1188 uint32_t mLClickCount;
1189 uint32_t mMClickCount;
1190 uint32_t mRClickCount;
1192 bool mShouldAlwaysUseLineDeltas : 1;
1193 bool mShouldAlwaysUseLineDeltasInitialized : 1;
1195 bool mGestureDownInTextControl : 1;
1197 bool mInTouchDrag;
1199 bool m_haveShutdown;
1201 RefPtr<OverOutElementsWrapper> mMouseEnterLeaveHelper;
1202 nsRefPtrHashtable<nsUint32HashKey, OverOutElementsWrapper>
1203 mPointersEnterLeaveHelper;
1205 // Array for accesskey support
1206 nsCOMArray<dom::Element> mAccessKeys;
1208 bool ShouldAlwaysUseLineDeltas();
1210 public:
1211 static nsresult UpdateUserActivityTimer(void);
1213 static bool sNormalLMouseEventInProcess;
1214 static int16_t sCurrentMouseBtn;
1216 static EventStateManager* sActiveESM;
1218 static void ClearGlobalActiveContent(EventStateManager* aClearer);
1220 // Functions used for click hold context menus
1221 nsCOMPtr<nsITimer> mClickHoldTimer;
1222 void CreateClickHoldTimer(nsPresContext* aPresContext, nsIFrame* aDownFrame,
1223 WidgetGUIEvent* aMouseDownEvent);
1224 void KillClickHoldTimer();
1225 MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireContextClick();
1227 MOZ_CAN_RUN_SCRIPT static void SetPointerLock(nsIWidget* aWidget,
1228 nsIContent* aElement);
1229 static void sClickHoldCallback(nsITimer* aTimer, void* aESM);
1232 } // namespace mozilla
1234 // Click and double-click events need to be handled even for content that
1235 // has no frame. This is required for Web compatibility.
1236 #define NS_EVENT_NEEDS_FRAME(event) \
1237 (!(event)->HasPluginActivationEventMessage() && \
1238 (event)->mMessage != eMouseClick && \
1239 (event)->mMessage != eMouseDoubleClick && \
1240 (event)->mMessage != eMouseAuxClick)
1242 #endif // mozilla_EventStateManager_h_