Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / base / UserActivation.h
blob75181f1b7281398c126112be805b527f95f7eb86
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_dom_UserAcitvation_h
8 #define mozilla_dom_UserAcitvation_h
10 #include "mozilla/EventForwards.h"
11 #include "mozilla/TimeStamp.h"
13 namespace mozilla::dom {
15 class UserActivation final {
16 public:
17 enum class State : uint8_t {
18 // Not activated.
19 None,
20 // It is considered as has-been-activated, but not transient-activated given
21 // that it is being consumed.
22 HasBeenActivated,
23 // It is considered as has-been-activated, and also transient-activated if
24 // haven't timed out.
25 FullActivated,
26 EndGuard_
29 /**
30 * Returns true if the current code is being executed as a result of
31 * user input or keyboard input. The former includes anything that is
32 * initiated by user, with the exception of page load events or mouse
33 * over events. And the latter returns true when one of the user inputs
34 * is an input from keyboard. If these methods are called from asynchronously
35 * executed code, such as during layout reflows, it will return false.
37 static bool IsHandlingUserInput();
38 static bool IsHandlingKeyboardInput();
40 /**
41 * Returns true if the event is considered as user interaction event. I.e.,
42 * enough obvious input to allow to open popup, etc. Otherwise, returns false.
44 static bool IsUserInteractionEvent(const WidgetEvent* aEvent);
46 /**
47 * StartHandlingUserInput() is called when we start to handle a user input.
48 * StopHandlingUserInput() is called when we finish handling a user input.
49 * If the caller knows which input event caused that, it should set
50 * aMessage to the event message. Otherwise, set eVoidEvent.
51 * Note that StopHandlingUserInput() caller should call it with exactly same
52 * event message as its corresponding StartHandlingUserInput() call because
53 * these methods may count the number of specific event message.
55 static void StartHandlingUserInput(EventMessage aMessage);
56 static void StopHandlingUserInput(EventMessage aMessage);
58 static TimeStamp GetHandlingInputStart();
60 /**
61 * Get the timestamp at which the latest user input was handled.
63 * Guaranteed to be monotonic. Until the first user input, return
64 * the epoch.
66 static TimeStamp LatestUserInputStart();
69 /**
70 * This class is used while processing real user input. During this time, popups
71 * are allowed. For mousedown events, mouse capturing is also permitted.
73 class MOZ_RAII AutoHandlingUserInputStatePusher final {
74 public:
75 explicit AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
76 WidgetEvent* aEvent = nullptr);
77 ~AutoHandlingUserInputStatePusher();
79 protected:
80 EventMessage mMessage;
81 bool mIsHandlingUserInput;
84 } // namespace mozilla::dom
86 #endif // mozilla_dom_UserAcitvation_h