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/. */
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"
17 #include "mozilla/gfx/Rect.h"
20 class nsDeviceContext
;
23 enum class RFPTarget
: uint64_t;
26 // Script "screen" object
27 class nsScreen
: public mozilla::DOMEventTargetHelper
{
28 using ErrorResult
= mozilla::ErrorResult
;
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
;
47 int32_t GetLeft(ErrorResult
& aRv
) {
48 mozilla::CSSIntRect rect
;
53 int32_t GetWidth(ErrorResult
& aRv
) {
54 mozilla::CSSIntRect rect
;
59 int32_t GetHeight(ErrorResult
& aRv
) {
60 mozilla::CSSIntRect rect
;
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
);
74 int32_t GetAvailLeft(ErrorResult
& aRv
) {
75 mozilla::CSSIntRect rect
;
76 aRv
= GetAvailRect(rect
);
80 int32_t GetAvailWidth(ErrorResult
& aRv
) {
81 mozilla::CSSIntRect rect
;
82 aRv
= GetAvailRect(rect
);
86 int32_t GetAvailHeight(ErrorResult
& aRv
) {
87 mozilla::CSSIntRect rect
;
88 aRv
= GetAvailRect(rect
);
92 // Media Capabilities extension
93 mozilla::dom::ScreenColorGamut
ColorGamut() const {
94 return mozilla::dom::ScreenColorGamut::Srgb
;
97 already_AddRefed
<mozilla::dom::ScreenLuminance
> GetLuminance() const {
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;
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
,
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();
130 nsDeviceContext
* GetDeviceContext() const;
131 nsresult
GetRect(mozilla::CSSIntRect
& aRect
);
132 nsresult
GetAvailRect(mozilla::CSSIntRect
& aRect
);
133 nsresult
GetWindowInnerRect(mozilla::CSSIntRect
& aRect
);
136 explicit nsScreen(nsPIDOMWindowInner
* aWindow
);
139 bool ShouldResistFingerprinting(mozilla::RFPTarget aTarget
) const;
141 mozilla::dom::Document
* TopContentDocumentInRDMPane() const;
143 RefPtr
<mozilla::dom::ScreenOrientation
> mScreenOrientation
;
146 #endif /* nsScreen_h___ */