Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / base / nsScreen.h
blobeea44767760ed02cdeacf7125f41d12da2a81b22
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/. */
6 #ifndef nsScreen_h___
7 #define nsScreen_h___
9 #include "mozilla/Attributes.h"
10 #include "mozilla/dom/ScreenBinding.h"
11 #include "mozilla/dom/ScreenLuminance.h"
12 #include "mozilla/dom/ScreenOrientation.h"
13 #include "mozilla/DOMEventTargetHelper.h"
14 #include "mozilla/ErrorResult.h"
15 #include "mozilla/StaticPrefs_media.h"
16 #include "nsCOMPtr.h"
17 #include "mozilla/gfx/Rect.h"
18 #include "Units.h"
20 class nsDeviceContext;
22 namespace mozilla {
23 enum class RFPTarget : uint64_t;
26 // Script "screen" object
27 class nsScreen : public mozilla::DOMEventTargetHelper {
28 using ErrorResult = mozilla::ErrorResult;
30 public:
31 static already_AddRefed<nsScreen> Create(nsPIDOMWindowInner* aWindow);
33 NS_DECL_ISUPPORTS_INHERITED
34 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen,
35 mozilla::DOMEventTargetHelper)
37 nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
39 nsPIDOMWindowOuter* GetOuter() const;
41 int32_t GetTop(ErrorResult& aRv) {
42 mozilla::CSSIntRect rect;
43 aRv = GetRect(rect);
44 return rect.y;
47 int32_t GetLeft(ErrorResult& aRv) {
48 mozilla::CSSIntRect rect;
49 aRv = GetRect(rect);
50 return rect.x;
53 int32_t GetWidth(ErrorResult& aRv) {
54 mozilla::CSSIntRect rect;
55 aRv = GetRect(rect);
56 return rect.Width();
59 int32_t GetHeight(ErrorResult& aRv) {
60 mozilla::CSSIntRect rect;
61 aRv = GetRect(rect);
62 return rect.Height();
65 int32_t GetPixelDepth(ErrorResult& aRv);
66 int32_t GetColorDepth(ErrorResult& aRv) { return GetPixelDepth(aRv); }
68 int32_t GetAvailTop(ErrorResult& aRv) {
69 mozilla::CSSIntRect rect;
70 aRv = GetAvailRect(rect);
71 return rect.y;
74 int32_t GetAvailLeft(ErrorResult& aRv) {
75 mozilla::CSSIntRect rect;
76 aRv = GetAvailRect(rect);
77 return rect.x;
80 int32_t GetAvailWidth(ErrorResult& aRv) {
81 mozilla::CSSIntRect rect;
82 aRv = GetAvailRect(rect);
83 return rect.Width();
86 int32_t GetAvailHeight(ErrorResult& aRv) {
87 mozilla::CSSIntRect rect;
88 aRv = GetAvailRect(rect);
89 return rect.Height();
92 // Media Capabilities extension
93 mozilla::dom::ScreenColorGamut ColorGamut() const {
94 return mozilla::dom::ScreenColorGamut::Srgb;
97 already_AddRefed<mozilla::dom::ScreenLuminance> GetLuminance() const {
98 return nullptr;
101 static bool MediaCapabilitiesEnabled(JSContext* aCx, JSObject* aGlobal) {
102 return mozilla::StaticPrefs::media_media_capabilities_screen_enabled();
105 IMPL_EVENT_HANDLER(change);
107 uint16_t GetOrientationAngle() const;
108 mozilla::hal::ScreenOrientation GetOrientationType() const;
110 // Deprecated
111 void GetMozOrientation(nsString& aOrientation,
112 mozilla::dom::CallerType aCallerType) const;
114 IMPL_EVENT_HANDLER(mozorientationchange)
116 bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv);
117 bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations,
118 ErrorResult& aRv);
119 void MozUnlockOrientation();
121 virtual JSObject* WrapObject(JSContext* aCx,
122 JS::Handle<JSObject*> aGivenProto) override;
124 mozilla::dom::ScreenOrientation* Orientation() const;
125 mozilla::dom::ScreenOrientation* GetOrientationIfExists() const {
126 return mScreenOrientation.get();
129 protected:
130 nsDeviceContext* GetDeviceContext() const;
131 nsresult GetRect(mozilla::CSSIntRect& aRect);
132 nsresult GetAvailRect(mozilla::CSSIntRect& aRect);
133 nsresult GetWindowInnerRect(mozilla::CSSIntRect& aRect);
135 private:
136 explicit nsScreen(nsPIDOMWindowInner* aWindow);
137 virtual ~nsScreen();
139 bool ShouldResistFingerprinting(mozilla::RFPTarget aTarget) const;
141 mozilla::dom::Document* TopContentDocumentInRDMPane() const;
143 RefPtr<mozilla::dom::ScreenOrientation> mScreenOrientation;
146 #endif /* nsScreen_h___ */