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"
15 enum class StyleCursorKind
: uint8_t;
18 class BrowsingContext
;
20 enum class CallerType
: uint32_t;
25 class PointerLockManager final
{
27 static void RequestLock(dom::Element
* aElement
, dom::CallerType aCallerType
);
29 MOZ_CAN_RUN_SCRIPT_BOUNDARY
30 static void Unlock(const char* aReason
, 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();
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
50 static void SetLockedRemoteTarget(dom::BrowserParent
* aBrowserParent
,
52 static void ReleaseLockedRemoteTarget(dom::BrowserParent
* aBrowserParent
);
55 class PointerLockRequest final
: public Runnable
{
57 PointerLockRequest(dom::Element
* aElement
, bool aUserInputOrChromeCaller
);
58 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
Run() final
;
63 bool mUserInputOrChromeCaller
;
66 static void ChangePointerLockedElement(dom::Element
* aElement
,
67 dom::Document
* aDocument
,
68 dom::Element
* aPointerLockedElement
);
70 MOZ_CAN_RUN_SCRIPT_BOUNDARY
71 static bool StartSetPointerLock(dom::Element
* aElement
,
72 dom::Document
* aDocument
);
75 static bool SetPointerLock(dom::Element
* aElement
, dom::Document
* aDocument
,
78 static bool sIsLocked
;
81 } // namespace mozilla
83 #endif // mozilla_PointerLockManager_h