Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / ScreenOrientation.h
blob0d52ae49078c5df1d1cfb05fbac889ecd41fa122
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ScreenOrientation_h
8 #define mozilla_dom_ScreenOrientation_h
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/ScreenOrientationBinding.h"
13 #include "mozilla/HalScreenConfiguration.h"
14 #include "mozilla/MozPromise.h"
16 class nsScreen;
18 namespace mozilla::dom {
20 class Promise;
22 class ScreenOrientation final : public DOMEventTargetHelper {
23 // nsScreen has deprecated API that shares implementation.
24 friend class ::nsScreen;
26 public:
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ScreenOrientation,
29 mozilla::DOMEventTargetHelper)
31 IMPL_EVENT_HANDLER(change)
33 // Called when the orientation may have changed.
34 void MaybeChanged();
36 ScreenOrientation(nsPIDOMWindowInner* aWindow, nsScreen* aScreen);
38 already_AddRefed<Promise> Lock(OrientationLockType aOrientation,
39 ErrorResult& aRv);
41 void Unlock(ErrorResult& aRv);
43 // DeviceType and DeviceAngle gets the current type and angle of the device.
44 OrientationType DeviceType(CallerType aCallerType) const;
45 uint16_t DeviceAngle(CallerType aCallerType) const;
47 // GetType and GetAngle gets the type and angle of the responsible document
48 // (as defined in specification).
49 OrientationType GetType(CallerType aCallerType, ErrorResult& aRv) const;
50 uint16_t GetAngle(CallerType aCallerType, ErrorResult& aRv) const;
52 JSObject* WrapObject(JSContext* aCx,
53 JS::Handle<JSObject*> aGivenProto) override;
55 static void UpdateActiveOrientationLock(hal::ScreenOrientation aOrientation);
56 static void AbortInProcessOrientationPromises(
57 BrowsingContext* aBrowsingContext);
59 private:
60 virtual ~ScreenOrientation();
62 // Listener to unlock orientation if we leave fullscreen.
63 class FullscreenEventListener;
65 // Listener to update document's orienation lock when document becomes
66 // visible.
67 class VisibleEventListener;
69 // Task to run step to lock orientation as defined in specification.
70 class LockOrientationTask;
72 enum LockPermission { LOCK_DENIED, FULLSCREEN_LOCK_ALLOWED, LOCK_ALLOWED };
74 // This method calls into the HAL to lock the device and sets
75 // up listeners for full screen change.
76 RefPtr<GenericNonExclusivePromise> LockDeviceOrientation(
77 hal::ScreenOrientation aOrientation, bool aIsFullscreen);
79 // This method calls in to the HAL to unlock the device and removes
80 // full screen change listener.
81 void UnlockDeviceOrientation();
82 void CleanupFullscreenListener();
84 // This method performs the same function as |Lock| except it takes
85 // a hal::ScreenOrientation argument instead of an OrientationType.
86 // This method exists in order to share implementation with nsScreen that
87 // uses ScreenOrientation.
88 already_AddRefed<Promise> LockInternal(hal::ScreenOrientation aOrientation,
89 ErrorResult& aRv);
91 nsCOMPtr<nsIRunnable> DispatchChangeEventAndResolvePromise();
93 LockPermission GetLockOrientationPermission(bool aCheckSandbox) const;
95 // Gets the responsible document as defined in the spec.
96 Document* GetResponsibleDocument() const;
98 RefPtr<nsScreen> mScreen;
99 RefPtr<FullscreenEventListener> mFullscreenListener;
100 RefPtr<VisibleEventListener> mVisibleListener;
101 OrientationType mType;
102 uint16_t mAngle;
103 // Whether we've tried to call into hal to lock the device orientation. This
104 // is needed because you don't want calling UnlockDeviceOrientation() during
105 // shutdown to initialize PHal if it hasn't been initialized earlier. Also,
106 // makes sense (there's no reason destroying a ScreenOrientation object from a
107 // different window should remove the orientation lock).
108 bool mTriedToLockDeviceOrientation = false;
111 } // namespace mozilla::dom
113 #endif // mozilla_dom_ScreenOrientation_h