Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / base / PointerLockManager.h
blob0b229bd42941da9b41425a2585072f4dee987483
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_PointerLockManager_h
8 #define mozilla_PointerLockManager_h
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "nsIWeakReferenceUtils.h"
12 #include "nsThreadUtils.h"
14 namespace mozilla {
15 enum class StyleCursorKind : uint8_t;
17 namespace dom {
18 class BrowsingContext;
19 class BrowserParent;
20 enum class CallerType : uint32_t;
21 class Document;
22 class Element;
23 } // namespace dom
25 class PointerLockManager final {
26 public:
27 static void RequestLock(dom::Element* aElement, dom::CallerType aCallerType);
29 MOZ_CAN_RUN_SCRIPT_BOUNDARY
30 static void Unlock(dom::Document* aDoc = nullptr);
32 static bool IsLocked() { return sIsLocked; }
34 static already_AddRefed<dom::Element> GetLockedElement();
36 static already_AddRefed<dom::Document> GetLockedDocument();
38 static dom::BrowserParent* GetLockedRemoteTarget();
40 /**
41 * Returns true if aContext and the current pointer locked document
42 * have common top BrowsingContext.
43 * Note that this method returns true only if caller is in the same process
44 * as pointer locked document.
46 static bool IsInLockContext(mozilla::dom::BrowsingContext* aContext);
48 // Set/release pointer lock remote target. Should only be called in parent
49 // process.
50 static bool SetLockedRemoteTarget(dom::BrowserParent* aBrowserParent);
51 static void ReleaseLockedRemoteTarget(dom::BrowserParent* aBrowserParent);
53 private:
54 class PointerLockRequest final : public Runnable {
55 public:
56 PointerLockRequest(dom::Element* aElement, bool aUserInputOrChromeCaller);
57 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD Run() final;
59 private:
60 nsWeakPtr mElement;
61 nsWeakPtr mDocument;
62 bool mUserInputOrChromeCaller;
65 static void ChangePointerLockedElement(dom::Element* aElement,
66 dom::Document* aDocument,
67 dom::Element* aPointerLockedElement);
69 MOZ_CAN_RUN_SCRIPT_BOUNDARY
70 static bool StartSetPointerLock(dom::Element* aElement,
71 dom::Document* aDocument);
73 MOZ_CAN_RUN_SCRIPT
74 static bool SetPointerLock(dom::Element* aElement, dom::Document* aDocument,
75 StyleCursorKind);
77 static bool sIsLocked;
80 } // namespace mozilla
82 #endif // mozilla_PointerLockManager_h