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"
19 class nsDeviceContext
;
21 // Script "screen" object
22 class nsScreen
: public mozilla::DOMEventTargetHelper
{
23 typedef mozilla::ErrorResult ErrorResult
;
26 static already_AddRefed
<nsScreen
> Create(nsPIDOMWindowInner
* aWindow
);
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen
,
30 mozilla::DOMEventTargetHelper
)
32 nsPIDOMWindowInner
* GetParentObject() const { return GetOwner(); }
34 nsPIDOMWindowOuter
* GetOuter() const;
36 int32_t GetTop(ErrorResult
& aRv
) {
42 int32_t GetLeft(ErrorResult
& aRv
) {
48 int32_t GetWidth(ErrorResult
& aRv
) {
54 int32_t GetHeight(ErrorResult
& aRv
) {
60 int32_t GetPixelDepth(ErrorResult
& aRv
);
61 int32_t GetColorDepth(ErrorResult
& aRv
) { return GetPixelDepth(aRv
); }
63 int32_t GetAvailTop(ErrorResult
& aRv
) {
65 aRv
= GetAvailRect(rect
);
69 int32_t GetAvailLeft(ErrorResult
& aRv
) {
71 aRv
= GetAvailRect(rect
);
75 int32_t GetAvailWidth(ErrorResult
& aRv
) {
77 aRv
= GetAvailRect(rect
);
81 int32_t GetAvailHeight(ErrorResult
& aRv
) {
83 aRv
= GetAvailRect(rect
);
87 // Media Capabilities extension
88 mozilla::dom::ScreenColorGamut
ColorGamut() const {
89 return mozilla::dom::ScreenColorGamut::Srgb
;
92 already_AddRefed
<mozilla::dom::ScreenLuminance
> GetLuminance() const {
96 static bool MediaCapabilitiesEnabled(JSContext
* aCx
, JSObject
* aGlobal
) {
97 return mozilla::StaticPrefs::media_media_capabilities_screen_enabled();
100 IMPL_EVENT_HANDLER(change
);
103 void GetMozOrientation(nsString
& aOrientation
,
104 mozilla::dom::CallerType aCallerType
) const;
106 IMPL_EVENT_HANDLER(mozorientationchange
)
108 bool MozLockOrientation(const nsAString
& aOrientation
, ErrorResult
& aRv
);
109 bool MozLockOrientation(const mozilla::dom::Sequence
<nsString
>& aOrientations
,
111 void MozUnlockOrientation();
113 virtual JSObject
* WrapObject(JSContext
* aCx
,
114 JS::Handle
<JSObject
*> aGivenProto
) override
;
116 mozilla::dom::ScreenOrientation
* Orientation() const;
119 nsDeviceContext
* GetDeviceContext();
120 nsresult
GetRect(nsRect
& aRect
);
121 nsresult
GetAvailRect(nsRect
& aRect
);
122 nsresult
GetWindowInnerRect(nsRect
& aRect
);
125 explicit nsScreen(nsPIDOMWindowInner
* aWindow
);
128 bool ShouldResistFingerprinting() const;
130 mozilla::dom::Document
* TopContentDocumentInRDMPane() const;
132 RefPtr
<mozilla::dom::ScreenOrientation
> mScreenOrientation
;
135 #endif /* nsScreen_h___ */