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/dom/ScreenBinding.h"
10 #include "mozilla/dom/ScreenLuminance.h"
11 #include "mozilla/dom/ScreenOrientation.h"
12 #include "mozilla/DOMEventTargetHelper.h"
13 #include "mozilla/StaticPrefs_media.h"
16 class nsDeviceContext
;
19 enum class RFPTarget
: uint64_t;
22 // Script "screen" object
23 class nsScreen
: public mozilla::DOMEventTargetHelper
{
25 explicit nsScreen(nsPIDOMWindowInner
* aWindow
);
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen
,
29 mozilla::DOMEventTargetHelper
)
31 nsIGlobalObject
* GetParentObject() const { return GetOwnerGlobal(); }
33 nsPIDOMWindowOuter
* GetOuter() const;
35 int32_t Top() { return GetRect().y
; }
36 int32_t Left() { return GetRect().x
; }
37 int32_t Width() { return GetRect().Width(); }
38 int32_t Height() { return GetRect().Height(); }
40 int32_t AvailTop() { return GetAvailRect().y
; }
41 int32_t AvailLeft() { return GetAvailRect().x
; }
42 int32_t AvailWidth() { return GetAvailRect().Width(); }
43 int32_t AvailHeight() { return GetAvailRect().Height(); }
46 int32_t ColorDepth() { return PixelDepth(); }
48 // Media Capabilities extension
49 mozilla::dom::ScreenColorGamut
ColorGamut() const {
50 return mozilla::dom::ScreenColorGamut::Srgb
;
53 already_AddRefed
<mozilla::dom::ScreenLuminance
> GetLuminance() const {
57 static bool MediaCapabilitiesEnabled(JSContext
* aCx
, JSObject
* aGlobal
) {
58 return mozilla::StaticPrefs::media_media_capabilities_screen_enabled();
61 IMPL_EVENT_HANDLER(change
);
63 uint16_t GetOrientationAngle() const;
64 mozilla::hal::ScreenOrientation
GetOrientationType() const;
67 void GetMozOrientation(nsString
& aOrientation
,
68 mozilla::dom::CallerType aCallerType
) const;
70 IMPL_EVENT_HANDLER(mozorientationchange
)
72 // This function is deprecated, use ScreenOrientation API instead.
73 bool MozLockOrientation(const nsAString
&) { return false; };
74 bool MozLockOrientation(const mozilla::dom::Sequence
<nsString
>&) {
77 void MozUnlockOrientation() {}
79 virtual JSObject
* WrapObject(JSContext
* aCx
,
80 JS::Handle
<JSObject
*> aGivenProto
) override
;
82 mozilla::dom::ScreenOrientation
* Orientation() const;
83 mozilla::dom::ScreenOrientation
* GetOrientationIfExists() const {
84 return mScreenOrientation
.get();
88 nsDeviceContext
* GetDeviceContext() const;
89 mozilla::CSSIntRect
GetRect();
90 mozilla::CSSIntRect
GetAvailRect();
91 mozilla::CSSIntRect
GetTopWindowInnerRectForRFP();
96 bool ShouldResistFingerprinting(mozilla::RFPTarget aTarget
) const;
98 mozilla::dom::Document
* TopContentDocumentInRDMPane() const;
100 RefPtr
<mozilla::dom::ScreenOrientation
> mScreenOrientation
;
103 #endif /* nsScreen_h___ */