Backed out 9 changesets (bug 1846848) for causing multiple build bustages. CLOSED...
[gecko.git] / dom / base / UserActivation.h
blobc067bbc8c3f0093e22cb083d3c45e63dc6788820
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_UserActivation_h
8 #define mozilla_dom_UserActivation_h
10 #include "mozilla/EventForwards.h"
11 #include "mozilla/TimeStamp.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsWrapperCache.h"
14 #include "nsPIDOMWindow.h"
16 namespace mozilla::dom {
18 class UserActivation final : public nsISupports, public nsWrapperCache {
19 public:
20 // WebIDL UserActivation
22 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
23 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(UserActivation)
25 explicit UserActivation(nsPIDOMWindowInner* aWindow);
27 nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
28 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
30 bool HasBeenActive() const;
31 bool IsActive() const;
33 // End of WebIDL UserActivation
35 enum class State : uint8_t {
36 // Not activated.
37 None,
38 // It is considered as has-been-activated, but not transient-activated given
39 // that it is being consumed.
40 HasBeenActivated,
41 // It is considered as has-been-activated, and also transient-activated if
42 // haven't timed out.
43 FullActivated,
44 EndGuard_
47 /**
48 * Returns true if the current code is being executed as a result of
49 * user input or keyboard input. The former includes anything that is
50 * initiated by user, with the exception of page load events or mouse
51 * over events. And the latter returns true when one of the user inputs
52 * is an input from keyboard. If these methods are called from asynchronously
53 * executed code, such as during layout reflows, it will return false.
55 static bool IsHandlingUserInput();
56 static bool IsHandlingKeyboardInput();
58 /**
59 * Returns true if the event is considered as user interaction event. I.e.,
60 * enough obvious input to allow to open popup, etc. Otherwise, returns false.
62 static bool IsUserInteractionEvent(const WidgetEvent* aEvent);
64 /**
65 * StartHandlingUserInput() is called when we start to handle a user input.
66 * StopHandlingUserInput() is called when we finish handling a user input.
67 * If the caller knows which input event caused that, it should set
68 * aMessage to the event message. Otherwise, set eVoidEvent.
69 * Note that StopHandlingUserInput() caller should call it with exactly same
70 * event message as its corresponding StartHandlingUserInput() call because
71 * these methods may count the number of specific event message.
73 static void StartHandlingUserInput(EventMessage aMessage);
74 static void StopHandlingUserInput(EventMessage aMessage);
76 static TimeStamp GetHandlingInputStart();
78 /**
79 * Get the timestamp at which the latest user input was handled.
81 * Guaranteed to be monotonic. Until the first user input, return
82 * the epoch.
84 static TimeStamp LatestUserInputStart();
86 private:
87 ~UserActivation() = default;
89 nsCOMPtr<nsPIDOMWindowInner> mWindow;
92 /**
93 * This class is used while processing real user input. During this time, popups
94 * are allowed. For mousedown events, mouse capturing is also permitted.
96 class MOZ_RAII AutoHandlingUserInputStatePusher final {
97 public:
98 explicit AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
99 WidgetEvent* aEvent = nullptr);
100 ~AutoHandlingUserInputStatePusher();
102 protected:
103 EventMessage mMessage;
104 bool mIsHandlingUserInput;
107 } // namespace mozilla::dom
109 #endif // mozilla_dom_UserActivation_h