Backed out changeset 4d64571ef929 (bug 1821732) for popovers related unexpected passe...
[gecko.git] / dom / events / EventStateManager.h
blob336694fcf092e28f97ed532f45ef49438bf34103
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 enum class FormControlType : uint8_t;
39 namespace mozilla {
41 class EditorBase;
42 class EnterLeaveDispatcher;
43 class IMEContentObserver;
44 class ScrollbarsForWheel;
45 class TextControlElement;
46 class WheelTransaction;
48 namespace dom {
49 class DataTransfer;
50 class Document;
51 class Element;
52 class Selection;
53 class BrowserParent;
54 class RemoteDragStartData;
56 } // namespace dom
58 class OverOutElementsWrapper final : public nsISupports {
59 ~OverOutElementsWrapper();
61 public:
62 OverOutElementsWrapper();
64 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
65 NS_DECL_CYCLE_COLLECTION_CLASS(OverOutElementsWrapper)
67 WeakFrame mLastOverFrame;
69 nsCOMPtr<nsIContent> mLastOverElement;
71 // The last element on which we fired a over event, or null if
72 // the last over event we fired has finished processing.
73 nsCOMPtr<nsIContent> mFirstOverEventElement;
75 // The last element on which we fired a out event, or null if
76 // the last out event we fired has finished processing.
77 nsCOMPtr<nsIContent> mFirstOutEventElement;
80 class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
81 friend class mozilla::EnterLeaveDispatcher;
82 friend class mozilla::ScrollbarsForWheel;
83 friend class mozilla::WheelTransaction;
85 using ElementState = dom::ElementState;
87 virtual ~EventStateManager();
89 public:
90 EventStateManager();
92 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
93 NS_DECL_NSIOBSERVER
95 nsresult Init();
96 nsresult Shutdown();
98 /* The PreHandleEvent method is called before event dispatch to either
99 * the DOM or frames. Any processing which must not be prevented or
100 * cancelled should occur here. Any processing which is intended to
101 * be conditional based on either DOM or frame processing should occur in
102 * PostHandleEvent. Any centralized event processing which must occur before
103 * DOM or frame event handling should occur here as well.
105 * aOverrideClickTarget can be used to indicate which element should be
106 * used as the *up target when deciding whether to send click event.
107 * This is used when releasing pointer capture. Otherwise null.
109 MOZ_CAN_RUN_SCRIPT
110 nsresult PreHandleEvent(nsPresContext* aPresContext, WidgetEvent* aEvent,
111 nsIFrame* aTargetFrame, nsIContent* aTargetContent,
112 nsEventStatus* aStatus,
113 nsIContent* aOverrideClickTarget);
115 /* The PostHandleEvent method should contain all system processing which
116 * should occur conditionally based on DOM or frame processing. It should
117 * also contain any centralized event processing which must occur after
118 * DOM and frame processing.
120 MOZ_CAN_RUN_SCRIPT
121 nsresult PostHandleEvent(nsPresContext* aPresContext, WidgetEvent* aEvent,
122 nsIFrame* aTargetFrame, nsEventStatus* aStatus,
123 nsIContent* aOverrideClickTarget);
125 MOZ_CAN_RUN_SCRIPT void PostHandleKeyboardEvent(
126 WidgetKeyboardEvent* aKeyboardEvent, nsIFrame* aTargetFrame,
127 nsEventStatus& aStatus);
130 * DispatchLegacyMouseScrollEvents() dispatches eLegacyMouseLineOrPageScroll
131 * event and eLegacyMousePixelScroll event for compatibility with old Gecko.
133 MOZ_CAN_RUN_SCRIPT_BOUNDARY void DispatchLegacyMouseScrollEvents(
134 nsIFrame* aTargetFrame, WidgetWheelEvent* aEvent, nsEventStatus* aStatus);
136 MOZ_CAN_RUN_SCRIPT_BOUNDARY void NotifyDestroyPresContext(
137 nsPresContext* aPresContext);
139 void ResetHoverState();
141 void SetPresContext(nsPresContext* aPresContext);
142 void ClearFrameRefs(nsIFrame* aFrame);
144 nsIFrame* GetEventTarget();
145 already_AddRefed<nsIContent> GetEventTargetContent(WidgetEvent* aEvent);
147 // We manage 4 states here: ACTIVE, HOVER, DRAGOVER, URLTARGET
148 static bool ManagesState(ElementState aState) {
149 return aState == ElementState::ACTIVE || aState == ElementState::HOVER ||
150 aState == ElementState::DRAGOVER ||
151 aState == ElementState::URLTARGET;
155 * Notify that the given ElementState::* bit has changed for this content.
156 * @param aContent Content which has changed states
157 * @param aState Corresponding state flags such as ElementState::FOCUS
158 * @return Whether the content was able to change all states. Returns false
159 * if a resulting DOM event causes the content node passed in
160 * to not change states. Note, the frame for the content may
161 * change as a result of the content state change, because of
162 * frame reconstructions that may occur, but this does not
163 * affect the return value.
165 bool SetContentState(nsIContent* aContent, ElementState aState);
167 nsIContent* GetActiveContent() const { return mActiveContent; }
169 void NativeAnonymousContentRemoved(nsIContent* aAnonContent);
170 MOZ_CAN_RUN_SCRIPT_BOUNDARY void ContentRemoved(dom::Document* aDocument,
171 nsIContent* aContent);
174 * Called when a native anonymous <div> element which is root element of
175 * text editor will be removed.
177 void TextControlRootWillBeRemoved(TextControlElement& aTextControlElement);
180 * Called when a native anonymous <div> element which is root element of
181 * text editor is created.
183 void TextControlRootAdded(dom::Element& aAnonymousDivElement,
184 TextControlElement& aTextControlElement);
186 bool EventStatusOK(WidgetGUIEvent* aEvent);
189 * EventStateManager stores IMEContentObserver while it's observing contents.
190 * Following mehtods are called by IMEContentObserver when it starts to
191 * observe or stops observing the content.
193 void OnStartToObserveContent(IMEContentObserver* aIMEContentObserver);
194 void OnStopObservingContent(IMEContentObserver* aIMEContentObserver);
197 * TryToFlushPendingNotificationsToIME() suggests flushing pending
198 * notifications to IME to IMEContentObserver.
199 * Doesn't do anything in child processes where flushing happens
200 * asynchronously.
202 void TryToFlushPendingNotificationsToIME();
204 static bool IsKeyboardEventUserActivity(WidgetEvent* aEvent);
207 * Register accesskey on the given element. When accesskey is activated then
208 * the element will be notified via Element::PerformAccesskey() method.
210 * @param aElement the given element
211 * @param aKey accesskey
213 void RegisterAccessKey(dom::Element* aElement, uint32_t aKey);
216 * Unregister accesskey for the given element.
218 * @param aElement the given element
219 * @param aKey accesskey
221 void UnregisterAccessKey(dom::Element* aElement, uint32_t aKey);
224 * Get accesskey registered on the given element or 0 if there is none.
226 * @param aElement the given element (must not be null)
227 * @return registered accesskey
229 uint32_t GetRegisteredAccessKey(dom::Element* aContent);
231 static void GetAccessKeyLabelPrefix(dom::Element* aElement,
232 nsAString& aPrefix);
235 * HandleAccessKey() looks for access keys which matches with aEvent and
236 * execute when it matches with a chrome access key or some content access
237 * keys.
238 * If the event may match chrome access keys, this handles the access key
239 * synchronously (if there are nested ESMs, their HandleAccessKey() are
240 * also called recursively).
241 * If the event may match content access keys and focused target is a remote
242 * process, this does nothing for the content because when this is called,
243 * it should already have been handled in the remote process.
244 * If the event may match content access keys and focused target is not in
245 * remote process but there are some remote children, this will post
246 * HandleAccessKey messages to all remote children.
248 * @return true if there is accesskey which aEvent and
249 * aAccessCharCodes match with. Otherwise, false.
250 * I.e., when this returns true, a target is executed
251 * or focused.
252 * Note that even if this returns false, a target in
253 * remote process may be executed or focused
254 * asynchronously.
256 bool HandleAccessKey(WidgetKeyboardEvent* aEvent, nsPresContext* aPresContext,
257 nsTArray<uint32_t>& aAccessCharCodes) {
258 return WalkESMTreeToHandleAccessKey(aEvent, aPresContext, aAccessCharCodes,
259 nullptr, eAccessKeyProcessingNormal,
260 true);
264 * CheckIfEventMatchesAccessKey() looks for access key which matches with
265 * aEvent in the process but won't execute it.
267 * @return true if there is accesskey which aEvent matches with
268 * in this process. Otherwise, false.
270 bool CheckIfEventMatchesAccessKey(WidgetKeyboardEvent* aEvent,
271 nsPresContext* aPresContext);
273 nsresult SetCursor(StyleCursorKind, imgIContainer*, const ImageResolution&,
274 const Maybe<gfx::IntPoint>& aHotspot, nsIWidget* aWidget,
275 bool aLockCursor);
277 void StartHidingCursorWhileTyping(nsIWidget*);
280 * Checks if the current mouse over element matches the given
281 * Element (which has a remote frame), and if so, notifies
282 * the BrowserParent of the mouse enter.
283 * Called when we reconstruct the BrowserParent and need to
284 * recompute state on the new object.
286 void RecomputeMouseEnterStateForRemoteFrame(dom::Element& aElement);
288 nsPresContext* GetPresContext() { return mPresContext; }
290 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EventStateManager, nsIObserver)
292 // The manager in this process that is setting the cursor. In the parent
293 // process it might be null if a remote process is setting the cursor.
294 static EventStateManager* sCursorSettingManager;
295 static void ClearCursorSettingManager() { sCursorSettingManager = nullptr; }
297 static EventStateManager* GetActiveEventStateManager() { return sActiveESM; }
299 // Sets aNewESM to be the active event state manager, and
300 // if aContent is non-null, marks the object as active.
301 static void SetActiveManager(EventStateManager* aNewESM,
302 nsIContent* aContent);
304 static bool IsRemoteTarget(nsIContent* target);
306 static bool IsTopLevelRemoteTarget(nsIContent* aTarget);
308 // Returns the kind of APZ action the given WidgetWheelEvent will perform.
309 static Maybe<layers::APZWheelAction> APZWheelActionFor(
310 const WidgetWheelEvent* aEvent);
312 // For some kinds of scrollings, the delta values of WidgetWheelEvent are
313 // possbile to be adjusted. This function is used to detect such scrollings
314 // and returns a wheel delta adjustment strategy to use, which is corresponded
315 // to the kind of the scrolling.
316 // It returns WheelDeltaAdjustmentStrategy::eAutoDir if the current default
317 // action is auto-dir scrolling which honours the scrolling target(The
318 // comments in WheelDeltaAdjustmentStrategy describes the concept in detail).
319 // It returns WheelDeltaAdjustmentStrategy::eAutoDirWithRootHonour if the
320 // current action is auto-dir scrolling which honours the root element in the
321 // document where the scrolling target is(The comments in
322 // WheelDeltaAdjustmentStrategy describes the concept in detail).
323 // It returns WheelDeltaAdjustmentStrategy::eHorizontalize if the current
324 // default action is horizontalized scrolling.
325 // It returns WheelDeltaAdjustmentStrategy::eNone to mean no delta adjustment
326 // strategy should be used if the scrolling is just a tranditional scrolling
327 // whose delta values are never possible to be adjusted.
328 static WheelDeltaAdjustmentStrategy GetWheelDeltaAdjustmentStrategy(
329 const WidgetWheelEvent& aEvent);
331 // Returns user-set multipliers for a wheel event.
332 static void GetUserPrefsForWheelEvent(const WidgetWheelEvent* aEvent,
333 double* aOutMultiplierX,
334 double* aOutMultiplierY);
336 // Holds the point in screen coords that a mouse event was dispatched to,
337 // before we went into pointer lock mode. This is constantly updated while
338 // the pointer is not locked, but we don't update it while the pointer is
339 // locked. This is used by dom::Event::GetScreenCoords() to make mouse
340 // events' screen coord appear frozen at the last mouse position while
341 // the pointer is locked.
342 static CSSIntPoint sLastScreenPoint;
344 // Holds the point in client coords of the last mouse event. Used by
345 // dom::Event::GetClientCoords() to make mouse events' client coords appear
346 // frozen at the last mouse position while the pointer is locked.
347 static CSSIntPoint sLastClientPoint;
350 * If the absolute values of mMultiplierX and/or mMultiplierY are equal or
351 * larger than this value, the computed scroll amount isn't rounded down to
352 * the page width or height.
354 static constexpr double MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL =
355 1000.0;
358 * HandleMiddleClickPaste() handles middle mouse button event as pasting
359 * clipboard text. Note that if aEditorBase is nullptr, this only
360 * dispatches ePaste event because it's necessary for some web apps which
361 * want to implement their own editor and supports middle click paste.
363 * @param aPresShell The PresShell for the ESM. This lifetime
364 * should be guaranteed by the caller.
365 * @param aMouseEvent The eMouseClick event which caused the
366 * paste.
367 * @param aStatus The event status of aMouseEvent.
368 * @param aEditorBase EditorBase which may be pasted the
369 * clipboard text by the middle click.
370 * If there is no editor for aMouseEvent,
371 * set nullptr.
373 MOZ_CAN_RUN_SCRIPT
374 nsresult HandleMiddleClickPaste(PresShell* aPresShell,
375 WidgetMouseEvent* aMouseEvent,
376 nsEventStatus* aStatus,
377 EditorBase* aEditorBase);
379 static void ConsumeInteractionData(
380 dom::Record<nsString, dom::InteractionData>& aInteractions);
382 // Stop tracking a possible drag. If aClearInChildProcesses is true, send
383 // a notification to any child processes that are in the drag service that
384 // tried to start a drag.
385 void StopTrackingDragGesture(bool aClearInChildProcesses);
387 protected:
389 * If aTargetFrame's widget has a cached cursor value, resets the cursor
390 * such that the next call to SetCursor on the widget will force an update
391 * of the native cursor. For use in getting puppet widget to update its
392 * cursor between mouse exit / enter transitions. This call basically wraps
393 * nsIWidget ClearCachedCursor.
395 void ClearCachedWidgetCursor(nsIFrame* aTargetFrame);
397 void UpdateCursor(nsPresContext*, WidgetMouseEvent*, nsIFrame* aTargetFrame,
398 nsEventStatus* aStatus);
400 * Turn a GUI mouse/pointer event into a mouse/pointer event targeted at the
401 * specified content. This returns the primary frame for the content (or null
402 * if it goes away during the event).
404 MOZ_CAN_RUN_SCRIPT nsIFrame* DispatchMouseOrPointerEvent(
405 WidgetMouseEvent* aMouseEvent, EventMessage aMessage,
406 nsIContent* aTargetContent, nsIContent* aRelatedContent);
408 * Synthesize DOM pointerover and pointerout events
410 void GeneratePointerEnterExit(EventMessage aMessage,
411 WidgetMouseEvent* aEvent);
413 * Synthesize DOM and frame mouseover and mouseout events from this
414 * MOUSE_MOVE or MOUSE_EXIT event.
416 void GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent);
418 * Tell this ESM and ESMs in parent documents that the mouse is
419 * over some content in this document.
421 MOZ_CAN_RUN_SCRIPT_BOUNDARY void NotifyMouseOver(
422 WidgetMouseEvent* aMouseEvent, nsIContent* aContent);
424 * Tell this ESM and ESMs in affected child documents that the mouse
425 * has exited this document's currently hovered content.
426 * TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
428 * @param aMouseEvent the event that triggered the mouseout
429 * @param aMovingInto the content node we've moved into. This is used to set
430 * the relatedTarget for mouseout events. Also, if it's non-null
431 * NotifyMouseOut will NOT change the current hover content to null;
432 * in that case the caller is responsible for updating hover state.
434 MOZ_CAN_RUN_SCRIPT_BOUNDARY void NotifyMouseOut(WidgetMouseEvent* aMouseEvent,
435 nsIContent* aMovingInto);
436 MOZ_CAN_RUN_SCRIPT void GenerateDragDropEnterExit(
437 nsPresContext* aPresContext, WidgetDragEvent* aDragEvent);
440 * Return mMouseEnterLeaveHelper or relevant mPointersEnterLeaveHelper
441 * elements wrapper. If mPointersEnterLeaveHelper does not contain wrapper for
442 * pointerId it create new one
444 OverOutElementsWrapper* GetWrapperByEventID(WidgetMouseEvent* aMouseEvent);
447 * Fire the dragenter and dragexit/dragleave events when the mouse moves to a
448 * new target.
450 * @param aRelatedTarget relatedTarget to set for the event
451 * @param aTargetContent target to set for the event
452 * @param aTargetFrame target frame for the event
454 MOZ_CAN_RUN_SCRIPT void FireDragEnterOrExit(nsPresContext* aPresContext,
455 WidgetDragEvent* aDragEvent,
456 EventMessage aMessage,
457 nsIContent* aRelatedTarget,
458 nsIContent* aTargetContent,
459 AutoWeakFrame& aTargetFrame);
461 * Update the initial drag session data transfer with any changes that occur
462 * on cloned data transfer objects used for events.
464 void UpdateDragDataTransfer(WidgetDragEvent* dragEvent);
467 * InitAndDispatchClickEvent() dispatches a click event.
469 * @param aMouseUpEvent eMouseUp event which causes the click event.
470 * EventCausesClickEvents() must return true
471 * if this event is set to it.
472 * @param aStatus Returns the result of click event.
473 * If the status indicates consumed, the
474 * value won't be overwritten with
475 * nsEventStatus_eIgnore.
476 * @param aMessage Should be eMouseClick, eMouseDoubleClick or
477 * eMouseAuxClick.
478 * @param aPresShell The PresShell.
479 * @param aMouseUpContent The event target of aMouseUpEvent.
480 * @param aCurrentTarget Current target of the caller.
481 * @param aNoContentDispatch true if the event shouldn't be exposed to
482 * web contents (although will be fired on
483 * document and window).
484 * @param aOverrideClickTarget Preferred click event target. If this is
485 * not nullptr, aMouseUpContent and
486 * aCurrentTarget are ignored.
488 MOZ_CAN_RUN_SCRIPT
489 static nsresult InitAndDispatchClickEvent(
490 WidgetMouseEvent* aMouseUpEvent, nsEventStatus* aStatus,
491 EventMessage aMessage, PresShell* aPresShell, nsIContent* aMouseUpContent,
492 AutoWeakFrame aCurrentTarget, bool aNoContentDispatch,
493 nsIContent* aOverrideClickTarget);
495 nsresult SetClickCount(WidgetMouseEvent* aEvent, nsEventStatus* aStatus,
496 nsIContent* aOverrideClickTarget = nullptr);
499 * EventCausesClickEvents() returns true when aMouseEvent is an eMouseUp
500 * event and it should cause eMouseClick, eMouseDoubleClick and/or
501 * eMouseAuxClick events. Note that this method assumes that
502 * aMouseEvent.mClickCount has already been initialized with SetClickCount().
504 static bool EventCausesClickEvents(const WidgetMouseEvent& aMouseEvent);
507 * PostHandleMouseUp() handles default actions of eMouseUp event.
509 * @param aMouseUpEvent eMouseUp event which causes the click event.
510 * EventCausesClickEvents() must return true
511 * if this event is set to it.
512 * @param aStatus Returns the result of event status.
513 * If one of dispatching event is consumed or
514 * this does something as default action,
515 * returns nsEventStatus_eConsumeNoDefault.
516 * @param aOverrideClickTarget Preferred click event target. If nullptr,
517 * aMouseUpEvent target and current target
518 * are used.
520 MOZ_CAN_RUN_SCRIPT
521 nsresult PostHandleMouseUp(WidgetMouseEvent* aMouseUpEvent,
522 nsEventStatus* aStatus,
523 nsIContent* aOverrideClickTarget);
526 * DispatchClickEvents() dispatches eMouseClick, eMouseDoubleClick and
527 * eMouseAuxClick events for aMouseUpEvent. aMouseUpEvent should cause
528 * click event.
530 * @param aPresShell The PresShell.
531 * @param aMouseUpEvent eMouseUp event which causes the click event.
532 * EventCausesClickEvents() must return true
533 * if this event is set to it.
534 * @param aStatus Returns the result of event status.
535 * If one of dispatching click event is
536 * consumed, returns
537 * nsEventStatus_eConsumeNoDefault.
538 * @param aMouseUpContent The event target of aMouseUpEvent.
539 * @param aOverrideClickTarget Preferred click event target. If this is
540 * not nullptr, aMouseUpContent and
541 * current target frame of the ESM are ignored.
543 MOZ_CAN_RUN_SCRIPT
544 nsresult DispatchClickEvents(PresShell* aPresShell,
545 WidgetMouseEvent* aMouseUpEvent,
546 nsEventStatus* aStatus,
547 nsIContent* aMouseUpContent,
548 nsIContent* aOverrideClickTarget);
550 void EnsureDocument(nsPresContext* aPresContext);
551 MOZ_CAN_RUN_SCRIPT_BOUNDARY
552 void FlushLayout(nsPresContext* aPresContext);
555 * The phases of WalkESMTreeToHandleAccessKey processing. See below.
557 enum ProcessingAccessKeyState {
558 eAccessKeyProcessingNormal = 0,
559 eAccessKeyProcessingUp,
560 eAccessKeyProcessingDown
564 * Walk EMS to look for access key and execute found access key when aExecute
565 * is true.
566 * If there is registered element for the accesskey given by the key event
567 * and modifier mask then call element.PerformAccesskey(), otherwise call
568 * WalkESMTreeToHandleAccessKey() recursively, on descendant docshells first,
569 * then on the ancestor (with |aBubbledFrom| set to the docshell associated
570 * with |this|), until something matches.
572 * @param aEvent the keyboard event triggering the acccess key
573 * @param aPresContext the presentation context
574 * @param aAccessCharCodes list of charcode candidates
575 * @param aBubbledFrom is used by an ancestor to avoid calling
576 * WalkESMTreeToHandleAccessKey() on the child the call originally
577 * came from, i.e. this is the child that recursively called us in
578 * its Up phase. The initial caller passes |nullptr| here. This is to
579 * avoid an infinite loop.
580 * @param aAccessKeyState Normal, Down or Up processing phase (see enums
581 * above). The initial event receiver uses 'normal', then 'down' when
582 * processing children and Up when recursively calling its ancestor.
583 * @param aExecute is true, execute an accesskey if it's found. Otherwise,
584 * found accesskey won't be executed.
586 * @return true if there is a target which aEvent and
587 * aAccessCharCodes match with in this process.
588 * Otherwise, false. I.e., when this returns true and
589 * aExecute is true, a target is executed or focused.
590 * Note that even if this returns false, a target in
591 * remote process may be executed or focused
592 * asynchronously.
594 bool WalkESMTreeToHandleAccessKey(WidgetKeyboardEvent* aEvent,
595 nsPresContext* aPresContext,
596 nsTArray<uint32_t>& aAccessCharCodes,
597 nsIDocShellTreeItem* aBubbledFrom,
598 ProcessingAccessKeyState aAccessKeyState,
599 bool aExecute);
602 * Look for access key and execute found access key if aExecute is true in
603 * the instance.
605 * @return true if there is a target which matches with
606 * aAccessCharCodes and aIsTrustedEvent. Otherwise,
607 * false. I.e., when this returns true and aExecute
608 * is true, a target is executed or focused.
610 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool LookForAccessKeyAndExecute(
611 nsTArray<uint32_t>& aAccessCharCodes, bool aIsTrustedEvent,
612 bool aIsRepeat, bool aExecute);
614 //---------------------------------------------
615 // DocShell Focus Traversal Methods
616 //---------------------------------------------
618 dom::Element* GetFocusedElement();
619 bool IsShellVisible(nsIDocShell* aShell);
621 // These functions are for mousewheel and pixel scrolling
623 class WheelPrefs {
624 public:
625 static WheelPrefs* GetInstance();
626 static void Shutdown();
629 * ApplyUserPrefsToDelta() overrides the wheel event's delta values with
630 * user prefs.
632 void ApplyUserPrefsToDelta(WidgetWheelEvent* aEvent);
635 * Returns whether or not ApplyUserPrefsToDelta() would change the delta
636 * values of an event.
638 void GetUserPrefsForEvent(const WidgetWheelEvent* aEvent,
639 double* aOutMultiplierX, double* aOutMultiplierY);
642 * If ApplyUserPrefsToDelta() changed the delta values with customized
643 * prefs, the overflowDelta values would be inflated.
644 * CancelApplyingUserPrefsFromOverflowDelta() cancels the inflation.
646 void CancelApplyingUserPrefsFromOverflowDelta(WidgetWheelEvent* aEvent);
649 * Computes the default action for the aEvent with the prefs.
651 enum Action : uint8_t {
652 ACTION_NONE = 0,
653 ACTION_SCROLL,
654 ACTION_HISTORY,
655 ACTION_ZOOM,
656 // Horizontalized scrolling means treating vertical wheel scrolling as
657 // horizontal scrolling during the process of its default action and
658 // plugins handling scrolling. Note that delta values as the event object
659 // in a DOM event listener won't be affected, and will be still the
660 // original values. For more details, refer to
661 // mozilla::WheelDeltaAdjustmentStrategy::eHorizontalize
662 ACTION_HORIZONTALIZED_SCROLL,
663 ACTION_PINCH_ZOOM,
664 ACTION_LAST = ACTION_PINCH_ZOOM,
665 // Following actions are used only by internal processing. So, cannot
666 // specified by prefs.
667 ACTION_SEND_TO_PLUGIN,
669 Action ComputeActionFor(const WidgetWheelEvent* aEvent);
672 * NeedToComputeLineOrPageDelta() returns if the aEvent needs to be
673 * computed the lineOrPageDelta values.
675 bool NeedToComputeLineOrPageDelta(const WidgetWheelEvent* aEvent);
678 * IsOverOnePageScrollAllowed*() checks whether wheel scroll amount should
679 * be rounded down to the page width/height (false) or not (true).
681 bool IsOverOnePageScrollAllowedX(const WidgetWheelEvent* aEvent);
682 bool IsOverOnePageScrollAllowedY(const WidgetWheelEvent* aEvent);
684 private:
685 WheelPrefs();
686 ~WheelPrefs();
688 static void OnPrefChanged(const char* aPrefName, void* aClosure);
690 enum Index {
691 INDEX_DEFAULT = 0,
692 INDEX_ALT,
693 INDEX_CONTROL,
694 INDEX_META,
695 INDEX_SHIFT,
696 COUNT_OF_MULTIPLIERS
700 * GetIndexFor() returns the index of the members which should be used for
701 * the aEvent. When only one modifier key of MODIFIER_ALT,
702 * MODIFIER_CONTROL, MODIFIER_META or MODIFIER_SHIFT is pressed, returns the
703 * index for the modifier. Otherwise, this return the default index which
704 * is used at either no modifier key is pressed or two or modifier keys are
705 * pressed.
707 Index GetIndexFor(const WidgetWheelEvent* aEvent);
710 * GetPrefNameBase() returns the base pref name for aEvent.
711 * It's decided by GetModifierForPref() which modifier should be used for
712 * the aEvent.
714 * @param aBasePrefName The result, must be "mousewheel.with_*." or
715 * "mousewheel.default.".
717 void GetBasePrefName(Index aIndex, nsACString& aBasePrefName);
719 void Init(Index aIndex);
721 void Reset();
724 * Retrieve multiplier for aEvent->mDeltaX and aEvent->mDeltaY.
726 * Note that if the default action is ACTION_HORIZONTALIZED_SCROLL and the
727 * delta values have been adjusted by WheelDeltaHorizontalizer() before this
728 * function is called, this function will swap the X and Y multipliers. By
729 * doing this, multipliers will still apply to the delta values they
730 * originally corresponded to.
732 * @param aEvent The event which is being handled.
733 * @param aIndex The index of mMultiplierX and mMultiplierY.
734 * Should be result of GetIndexFor(aEvent).
735 * @param aMultiplierForDeltaX Will be set to multiplier for
736 * aEvent->mDeltaX.
737 * @param aMultiplierForDeltaY Will be set to multiplier for
738 * aEvent->mDeltaY.
740 void GetMultiplierForDeltaXAndY(const WidgetWheelEvent* aEvent,
741 Index aIndex, double* aMultiplierForDeltaX,
742 double* aMultiplierForDeltaY);
744 bool mInit[COUNT_OF_MULTIPLIERS];
745 double mMultiplierX[COUNT_OF_MULTIPLIERS];
746 double mMultiplierY[COUNT_OF_MULTIPLIERS];
747 double mMultiplierZ[COUNT_OF_MULTIPLIERS];
748 Action mActions[COUNT_OF_MULTIPLIERS];
750 * action values overridden by .override_x pref.
751 * If an .override_x value is -1, same as the
752 * corresponding mActions value.
754 Action mOverriddenActionsX[COUNT_OF_MULTIPLIERS];
756 static WheelPrefs* sInstance;
760 * DeltaDirection is used for specifying whether the called method should
761 * handle vertical delta or horizontal delta.
762 * This is clearer than using bool.
764 enum DeltaDirection { DELTA_DIRECTION_X = 0, DELTA_DIRECTION_Y };
766 struct MOZ_STACK_CLASS EventState {
767 bool mDefaultPrevented;
768 bool mDefaultPreventedByContent;
770 EventState()
771 : mDefaultPrevented(false), mDefaultPreventedByContent(false) {}
775 * SendLineScrollEvent() dispatches a DOMMouseScroll 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 aDelta The delta value of the event.
785 * @param aDeltaDirection The X/Y direction of dispatching event.
787 MOZ_CAN_RUN_SCRIPT void SendLineScrollEvent(nsIFrame* aTargetFrame,
788 WidgetWheelEvent* aEvent,
789 EventState& aState,
790 int32_t aDelta,
791 DeltaDirection aDeltaDirection);
794 * SendPixelScrollEvent() dispatches a MozMousePixelScroll event for the
795 * WidgetWheelEvent. This method shouldn't be called for non-trusted
796 * wheel event because it's not necessary for compatiblity.
798 * @param aTargetFrame The event target of wheel event.
799 * @param aEvent The original Wheel event.
800 * @param aState The event which should be set to the dispatching
801 * event. This also returns the dispatched event
802 * state.
803 * @param aPixelDelta The delta value of the event.
804 * @param aDeltaDirection The X/Y direction of dispatching event.
806 MOZ_CAN_RUN_SCRIPT void SendPixelScrollEvent(nsIFrame* aTargetFrame,
807 WidgetWheelEvent* aEvent,
808 EventState& aState,
809 int32_t aPixelDelta,
810 DeltaDirection aDeltaDirection);
813 * ComputeScrollTargetAndMayAdjustWheelEvent() returns the scrollable frame
814 * which should be scrolled.
816 * @param aTargetFrame The event target of the wheel event.
817 * @param aEvent The handling mouse wheel event.
818 * @param aOptions The options for finding the scroll target.
819 * Callers should use COMPUTE_*.
820 * @return The scrollable frame which should be scrolled.
822 // These flags are used in ComputeScrollTargetAndMayAdjustWheelEvent().
823 // Callers should use COMPUTE_*.
824 enum {
825 PREFER_MOUSE_WHEEL_TRANSACTION = 0x00000001,
826 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS = 0x00000002,
827 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS = 0x00000004,
828 START_FROM_PARENT = 0x00000008,
829 INCLUDE_PLUGIN_AS_TARGET = 0x00000010,
830 // Indicates the wheel scroll event being computed is an auto-dir scroll, so
831 // its delta may be adjusted after being computed.
832 MAY_BE_ADJUSTED_BY_AUTO_DIR = 0x00000020,
834 enum ComputeScrollTargetOptions {
835 // At computing scroll target for legacy mouse events, we should return
836 // first scrollable element even when it's not scrollable to the direction.
837 COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET = 0,
838 // Default action prefers the scrolled element immediately before if it's
839 // still under the mouse cursor. Otherwise, it prefers the nearest
840 // scrollable ancestor which will be scrolled actually.
841 COMPUTE_DEFAULT_ACTION_TARGET =
842 (PREFER_MOUSE_WHEEL_TRANSACTION |
843 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS |
844 PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS),
845 COMPUTE_DEFAULT_ACTION_TARGET_WITH_AUTO_DIR =
846 (COMPUTE_DEFAULT_ACTION_TARGET | MAY_BE_ADJUSTED_BY_AUTO_DIR),
847 // Look for the nearest scrollable ancestor which can be scrollable with
848 // aEvent.
849 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS =
850 (PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS | START_FROM_PARENT),
851 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS =
852 (PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS | START_FROM_PARENT),
853 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS_WITH_AUTO_DIR =
854 (COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS |
855 MAY_BE_ADJUSTED_BY_AUTO_DIR),
856 COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS_WITH_AUTO_DIR =
857 (COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS |
858 MAY_BE_ADJUSTED_BY_AUTO_DIR),
861 // Compute the scroll target.
862 // The delta values in the wheel event may be changed if the event is for
863 // auto-dir scrolling. For information on auto-dir,
864 // @see mozilla::WheelDeltaAdjustmentStrategy
865 nsIFrame* ComputeScrollTargetAndMayAdjustWheelEvent(
866 nsIFrame* aTargetFrame, WidgetWheelEvent* aEvent,
867 ComputeScrollTargetOptions aOptions);
869 nsIFrame* ComputeScrollTargetAndMayAdjustWheelEvent(
870 nsIFrame* aTargetFrame, double aDirectionX, double aDirectionY,
871 WidgetWheelEvent* aEvent, ComputeScrollTargetOptions aOptions);
873 nsIFrame* ComputeScrollTarget(nsIFrame* aTargetFrame,
874 WidgetWheelEvent* aEvent,
875 ComputeScrollTargetOptions aOptions) {
876 MOZ_ASSERT(!(aOptions & MAY_BE_ADJUSTED_BY_AUTO_DIR),
877 "aEvent may be modified by auto-dir");
878 return ComputeScrollTargetAndMayAdjustWheelEvent(aTargetFrame, aEvent,
879 aOptions);
882 nsIFrame* ComputeScrollTarget(nsIFrame* aTargetFrame, double aDirectionX,
883 double aDirectionY, WidgetWheelEvent* aEvent,
884 ComputeScrollTargetOptions aOptions) {
885 MOZ_ASSERT(!(aOptions & MAY_BE_ADJUSTED_BY_AUTO_DIR),
886 "aEvent may be modified by auto-dir");
887 return ComputeScrollTargetAndMayAdjustWheelEvent(
888 aTargetFrame, aDirectionX, aDirectionY, aEvent, aOptions);
892 * GetScrollAmount() returns the scroll amount in app uints of one line or
893 * one page. If the wheel event scrolls a page, returns the page width and
894 * height. Otherwise, returns line height for both its width and height.
896 * @param aScrollableFrame A frame which will be scrolled by the event.
897 * The result of
898 * ComputeScrollTargetAndMayAdjustWheelEvent() is
899 * expected for this value.
900 * This can be nullptr if there is no scrollable
901 * frame. Then, this method uses root frame's
902 * line height or visible area's width and height.
904 nsSize GetScrollAmount(nsPresContext* aPresContext, WidgetWheelEvent* aEvent,
905 nsIScrollableFrame* aScrollableFrame);
908 * DoScrollText() scrolls the scrollable frame for aEvent.
910 void DoScrollText(nsIScrollableFrame* aScrollableFrame,
911 WidgetWheelEvent* aEvent);
913 void DoScrollHistory(int32_t direction);
914 void DoScrollZoom(nsIFrame* aTargetFrame, int32_t adjustment);
915 void ChangeZoom(bool aIncrease);
918 * DeltaAccumulator class manages delta values for dispatching DOMMouseScroll
919 * event. If wheel events are caused by pixel scroll only devices or
920 * the delta values are customized by prefs, this class stores the delta
921 * values and set lineOrPageDelta values.
923 class DeltaAccumulator {
924 public:
925 static DeltaAccumulator* GetInstance() {
926 if (!sInstance) {
927 sInstance = new DeltaAccumulator;
929 return sInstance;
932 static void Shutdown() {
933 delete sInstance;
934 sInstance = nullptr;
937 bool IsInTransaction() { return mHandlingDeltaMode != UINT32_MAX; }
940 * InitLineOrPageDelta() stores pixel delta values of WidgetWheelEvents
941 * which are caused if it's needed. And if the accumulated delta becomes a
942 * line height, sets lineOrPageDeltaX and lineOrPageDeltaY automatically.
944 void InitLineOrPageDelta(nsIFrame* aTargetFrame, EventStateManager* aESM,
945 WidgetWheelEvent* aEvent);
948 * Reset() resets all members.
950 void Reset();
953 * ComputeScrollAmountForDefaultAction() computes the default action's
954 * scroll amount in device pixels with mPendingScrollAmount*.
956 nsIntPoint ComputeScrollAmountForDefaultAction(
957 WidgetWheelEvent* aEvent, const nsIntSize& aScrollAmountInDevPixels);
959 private:
960 DeltaAccumulator()
961 : mX(0.0),
962 mY(0.0),
963 mPendingScrollAmountX(0.0),
964 mPendingScrollAmountY(0.0),
965 mHandlingDeltaMode(UINT32_MAX),
966 mIsNoLineOrPageDeltaDevice(false) {}
968 double mX;
969 double mY;
971 // When default action of a wheel event is scroll but some delta values
972 // are ignored because the computed amount values are not integer, the
973 // fractional values are saved by these members.
974 double mPendingScrollAmountX;
975 double mPendingScrollAmountY;
977 TimeStamp mLastTime;
979 uint32_t mHandlingDeltaMode;
980 bool mIsNoLineOrPageDeltaDevice;
982 static DeltaAccumulator* sInstance;
985 // end mousewheel functions
988 * When a touch gesture is about to start, this function determines what
989 * kind of gesture interaction we will want to use, based on what is
990 * underneath the initial touch point.
991 * Currently it decides between panning (finger scrolling) or dragging
992 * the target element, as well as the orientation to trigger panning and
993 * display visual boundary feedback. The decision is stored back in aEvent.
995 void DecideGestureEvent(WidgetGestureNotifyEvent* aEvent,
996 nsIFrame* targetFrame);
998 // routines for the d&d gesture tracking state machine
999 void BeginTrackingDragGesture(nsPresContext* aPresContext,
1000 WidgetMouseEvent* aDownEvent,
1001 nsIFrame* aDownFrame);
1003 void SetGestureDownPoint(WidgetGUIEvent* aEvent);
1005 LayoutDeviceIntPoint GetEventRefPoint(WidgetEvent* aEvent) const;
1007 friend class mozilla::dom::BrowserParent;
1008 void BeginTrackingRemoteDragGesture(nsIContent* aContent,
1009 dom::RemoteDragStartData* aDragStartData);
1011 MOZ_CAN_RUN_SCRIPT
1012 void GenerateDragGesture(nsPresContext* aPresContext,
1013 WidgetInputEvent* aEvent);
1016 * When starting a dnd session, UA must fire a pointercancel event and stop
1017 * firing the subsequent pointer events.
1019 MOZ_CAN_RUN_SCRIPT
1020 void MaybeFirePointerCancel(WidgetInputEvent* aEvent);
1023 * Determine which node the drag should be targeted at.
1024 * This is either the node clicked when there is a selection, or, for HTML,
1025 * the element with a draggable property set to true.
1027 * aSelectionTarget - target to check for selection
1028 * aDataTransfer - data transfer object that will contain the data to drag
1029 * aAllowEmptyDataTransfer - [out] set to true, if dnd operation can be
1030 * started even if DataTransfer is empty
1031 * aSelection - [out] set to the selection to be dragged
1032 * aTargetNode - [out] the draggable node, or null if there isn't one
1033 * aPrincipal - [out] set to the triggering principal of the drag, or null
1034 * if it's from browser chrome or OS
1035 * aCookieJarSettings - [out] set to the cookieJarSettings of the drag, or
1036 * null if it's from browser chrome or OS.
1038 void DetermineDragTargetAndDefaultData(
1039 nsPIDOMWindowOuter* aWindow, nsIContent* aSelectionTarget,
1040 dom::DataTransfer* aDataTransfer, bool* aAllowEmptyDataTransfer,
1041 dom::Selection** aSelection,
1042 dom::RemoteDragStartData** aRemoteDragStartData, nsIContent** aTargetNode,
1043 nsIPrincipal** aPrincipal, nsIContentSecurityPolicy** aCsp,
1044 nsICookieJarSettings** aCookieJarSettings);
1047 * Perform the default handling for the dragstart event and set up a
1048 * drag for aDataTransfer if it contains any data. Returns true if a drag has
1049 * started.
1051 * aDragEvent - the dragstart event
1052 * aDataTransfer - the data transfer that holds the data to be dragged
1053 * aAllowEmptyDataTransfer - if true, dnd can be started even if there is no
1054 * data to drag
1055 * aDragTarget - the target of the drag
1056 * aSelection - the selection to be dragged
1057 * aData - information pertaining to a drag started in a child process
1058 * aPrincipal - the triggering principal of the drag, or null if it's from
1059 * browser chrome or OS
1060 * aCookieJarSettings - the cookieJarSettings of the drag. or null if it's
1061 * from browser chrome or OS.
1063 MOZ_CAN_RUN_SCRIPT
1064 bool DoDefaultDragStart(
1065 nsPresContext* aPresContext, WidgetDragEvent* aDragEvent,
1066 dom::DataTransfer* aDataTransfer, bool aAllowEmptyDataTransfer,
1067 nsIContent* aDragTarget, dom::Selection* aSelection,
1068 dom::RemoteDragStartData* aDragStartData, nsIPrincipal* aPrincipal,
1069 nsIContentSecurityPolicy* aCsp, nsICookieJarSettings* aCookieJarSettings);
1071 bool IsTrackingDragGesture() const { return mGestureDownContent != nullptr; }
1073 * Set the fields of aEvent to reflect the mouse position and modifier keys
1074 * that were set when the user first pressed the mouse button (stored by
1075 * BeginTrackingDragGesture). aEvent->mWidget must be
1076 * mCurrentTarget->GetNearestWidget().
1078 void FillInEventFromGestureDown(WidgetMouseEvent* aEvent);
1080 MOZ_CAN_RUN_SCRIPT
1081 nsresult DoContentCommandEvent(WidgetContentCommandEvent* aEvent);
1082 MOZ_CAN_RUN_SCRIPT
1083 nsresult DoContentCommandInsertTextEvent(WidgetContentCommandEvent* aEvent);
1084 nsresult DoContentCommandScrollEvent(WidgetContentCommandEvent* aEvent);
1086 dom::BrowserParent* GetCrossProcessTarget();
1087 bool IsTargetCrossProcess(WidgetGUIEvent* aEvent);
1090 * DispatchCrossProcessEvent() try to post aEvent to target remote process.
1091 * If you need to check if the event is posted to a remote process, you
1092 * can use aEvent->HasBeenPostedToRemoteProcess().
1094 void DispatchCrossProcessEvent(WidgetEvent* aEvent,
1095 dom::BrowserParent* aRemoteTarget,
1096 nsEventStatus* aStatus);
1098 * HandleCrossProcessEvent() may post aEvent to target remote processes.
1099 * When it succeeded to post the event to at least one remote process,
1100 * returns true. Otherwise, including the case not tried to dispatch to
1101 * post the event, returns false.
1102 * If you need to check if the event is posted to at least one remote
1103 * process, you can use aEvent->HasBeenPostedToRemoteProcess().
1105 bool HandleCrossProcessEvent(WidgetEvent* aEvent, nsEventStatus* aStatus);
1107 void ReleaseCurrentIMEContentObserver();
1109 MOZ_CAN_RUN_SCRIPT void HandleQueryContentEvent(
1110 WidgetQueryContentEvent* aEvent);
1112 private:
1113 // Removes a node from the :hover / :active chain if needed, notifying if the
1114 // node is not a NAC subtree.
1116 // Only meant to be called from ContentRemoved and
1117 // NativeAnonymousContentRemoved.
1118 void RemoveNodeFromChainIfNeeded(ElementState aState,
1119 nsIContent* aContentRemoved, bool aNotify);
1121 bool IsEventOutsideDragThreshold(WidgetInputEvent* aEvent) const;
1123 static inline void DoStateChange(dom::Element* aElement, ElementState aState,
1124 bool aAddState);
1125 static inline void DoStateChange(nsIContent* aContent, ElementState aState,
1126 bool aAddState);
1127 static void UpdateAncestorState(nsIContent* aStartNode,
1128 nsIContent* aStopBefore, ElementState aState,
1129 bool aAddState);
1130 static void ResetLastOverForContent(
1131 const uint32_t& aIdx, const RefPtr<OverOutElementsWrapper>& aChunk,
1132 nsIContent* aClosure);
1135 * Update the attribute mLastRefPoint of the mouse event. It should be
1136 * the center of the window while the pointer is locked.
1137 * the same value as mRefPoint while there is no known last ref point.
1138 * the same value as the last known mRefPoint.
1140 static void UpdateLastRefPointOfMouseEvent(WidgetMouseEvent* aMouseEvent);
1142 static void ResetPointerToWindowCenterWhilePointerLocked(
1143 WidgetMouseEvent* aMouseEvent);
1145 // Update the last known ref point to the current event's mRefPoint.
1146 static void UpdateLastPointerPosition(WidgetMouseEvent* aMouseEvent);
1149 * Notify target when user has been interaction with some speicific user
1150 * gestures which are eKeyUp, eMouseUp, eTouchEnd.
1152 void NotifyTargetUserActivation(WidgetEvent* aEvent,
1153 nsIContent* aTargetContent);
1155 already_AddRefed<EventStateManager> ESMFromContentOrThis(
1156 nsIContent* aContent);
1158 struct LastMouseDownInfo {
1159 nsCOMPtr<nsIContent> mLastMouseDownContent;
1160 Maybe<FormControlType> mLastMouseDownInputControlType;
1161 uint32_t mClickCount = 0;
1164 LastMouseDownInfo& GetLastMouseDownInfo(int16_t aButton);
1166 // These variables are only relevant if we're the cursor-setting manager.
1167 StyleCursorKind mLockCursor;
1168 bool mLastFrameConsumedSetCursor = false;
1169 bool mHidingCursorWhileTyping = false;
1171 // Last mouse event mRefPoint (the offset from the widget's origin in
1172 // device pixels) when mouse was locked, used to restore mouse position
1173 // after unlocking.
1174 static LayoutDeviceIntPoint sPreLockPoint;
1176 // Stores the mRefPoint of the last synthetic mouse move we dispatched
1177 // to re-center the mouse when we were pointer locked. If this is (-1,-1) it
1178 // means we've not recently dispatched a centering event. We use this to
1179 // detect when we receive the synth event, so we can cancel and not send it
1180 // to content.
1181 static LayoutDeviceIntPoint sSynthCenteringPoint;
1183 WeakFrame mCurrentTarget;
1184 nsCOMPtr<nsIContent> mCurrentTargetContent;
1185 static AutoWeakFrame sLastDragOverFrame;
1187 // Stores the mRefPoint (the offset from the widget's origin in device
1188 // pixels) of the last mouse event.
1189 static LayoutDeviceIntPoint sLastRefPoint;
1191 // member variables for the d&d gesture state machine
1192 LayoutDeviceIntPoint mGestureDownPoint; // screen coordinates
1193 // The content to use as target if we start a d&d (what we drag).
1194 RefPtr<nsIContent> mGestureDownContent;
1195 // The content of the frame where the mouse-down event occurred. It's the same
1196 // as the target in most cases but not always - for example when dragging
1197 // an <area> of an image map this is the image. (bug 289667)
1198 nsCOMPtr<nsIContent> mGestureDownFrameOwner;
1199 // Data associated with a drag started in a content process.
1200 RefPtr<dom::RemoteDragStartData> mGestureDownDragStartData;
1201 // State of keys when the original gesture-down happened
1202 Modifiers mGestureModifiers;
1203 uint16_t mGestureDownButtons;
1205 LastMouseDownInfo mLastLeftMouseDownInfo;
1206 LastMouseDownInfo mLastMiddleMouseDownInfo;
1207 LastMouseDownInfo mLastRightMouseDownInfo;
1209 nsCOMPtr<nsIContent> mActiveContent;
1210 nsCOMPtr<nsIContent> mHoverContent;
1211 static nsCOMPtr<nsIContent> sDragOverContent;
1212 nsCOMPtr<nsIContent> mURLTargetContent;
1214 nsPresContext* mPresContext; // Not refcnted
1215 RefPtr<dom::Document> mDocument; // Doesn't necessarily need to be owner
1217 RefPtr<IMEContentObserver> mIMEContentObserver;
1219 bool mShouldAlwaysUseLineDeltas : 1;
1220 bool mShouldAlwaysUseLineDeltasInitialized : 1;
1222 bool mGestureDownInTextControl : 1;
1224 bool mInTouchDrag;
1226 bool m_haveShutdown;
1228 RefPtr<OverOutElementsWrapper> mMouseEnterLeaveHelper;
1229 nsRefPtrHashtable<nsUint32HashKey, OverOutElementsWrapper>
1230 mPointersEnterLeaveHelper;
1232 // Array for accesskey support
1233 nsCOMArray<dom::Element> mAccessKeys;
1235 bool ShouldAlwaysUseLineDeltas();
1237 public:
1238 static nsresult UpdateUserActivityTimer(void);
1240 static bool sNormalLMouseEventInProcess;
1241 static int16_t sCurrentMouseBtn;
1243 static EventStateManager* sActiveESM;
1245 static void ClearGlobalActiveContent(EventStateManager* aClearer);
1247 // Functions used for click hold context menus
1248 nsCOMPtr<nsITimer> mClickHoldTimer;
1249 void CreateClickHoldTimer(nsPresContext* aPresContext, nsIFrame* aDownFrame,
1250 WidgetGUIEvent* aMouseDownEvent);
1251 void KillClickHoldTimer();
1252 MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireContextClick();
1254 MOZ_CAN_RUN_SCRIPT static void SetPointerLock(nsIWidget* aWidget,
1255 nsIContent* aElement);
1256 static void sClickHoldCallback(nsITimer* aTimer, void* aESM);
1259 } // namespace mozilla
1261 // Click and double-click events need to be handled even for content that
1262 // has no frame. This is required for Web compatibility.
1263 #define NS_EVENT_NEEDS_FRAME(event) \
1264 ((event)->mMessage != eMouseClick && \
1265 (event)->mMessage != eMouseDoubleClick && \
1266 (event)->mMessage != eMouseAuxClick)
1268 #endif // mozilla_EventStateManager_h_