Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / nsScreen.h
blob1386bd95aa8932c6a49c67576db49f58270195e1
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 "nsGlobalWindowOuter.h"
18 #include "nsRect.h"
20 class nsDeviceContext;
22 // Script "screen" object
23 class nsScreen : public mozilla::DOMEventTargetHelper {
24 typedef mozilla::ErrorResult ErrorResult;
26 public:
27 static already_AddRefed<nsScreen> Create(nsPIDOMWindowInner* aWindow);
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen,
31 mozilla::DOMEventTargetHelper)
33 nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
35 nsPIDOMWindowOuter* GetOuter() const;
37 int32_t GetTop(ErrorResult& aRv) {
38 nsRect rect;
39 aRv = GetRect(rect);
40 return rect.y;
43 int32_t GetLeft(ErrorResult& aRv) {
44 nsRect rect;
45 aRv = GetRect(rect);
46 return rect.x;
49 int32_t GetWidth(ErrorResult& aRv) {
50 nsRect rect;
51 aRv = GetRect(rect);
52 return rect.Width();
55 int32_t GetHeight(ErrorResult& aRv) {
56 nsRect rect;
57 aRv = GetRect(rect);
58 return rect.Height();
61 int32_t GetPixelDepth(ErrorResult& aRv);
62 int32_t GetColorDepth(ErrorResult& aRv) { return GetPixelDepth(aRv); }
64 int32_t GetAvailTop(ErrorResult& aRv) {
65 nsRect rect;
66 aRv = GetAvailRect(rect);
67 return rect.y;
70 int32_t GetAvailLeft(ErrorResult& aRv) {
71 nsRect rect;
72 aRv = GetAvailRect(rect);
73 return rect.x;
76 int32_t GetAvailWidth(ErrorResult& aRv) {
77 nsRect rect;
78 aRv = GetAvailRect(rect);
79 return rect.Width();
82 int32_t GetAvailHeight(ErrorResult& aRv) {
83 nsRect rect;
84 aRv = GetAvailRect(rect);
85 return rect.Height();
88 // Media Capabilities extension
89 mozilla::dom::ScreenColorGamut ColorGamut() const {
90 return mozilla::dom::ScreenColorGamut::Srgb;
93 already_AddRefed<mozilla::dom::ScreenLuminance> GetLuminance() const {
94 return nullptr;
97 static bool MediaCapabilitiesEnabled(JSContext* aCx, JSObject* aGlobal) {
98 return mozilla::StaticPrefs::media_media_capabilities_screen_enabled();
101 IMPL_EVENT_HANDLER(change);
103 // Deprecated
104 void GetMozOrientation(nsString& aOrientation,
105 mozilla::dom::CallerType aCallerType) const;
107 IMPL_EVENT_HANDLER(mozorientationchange)
109 bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv);
110 bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations,
111 ErrorResult& aRv);
112 void MozUnlockOrientation();
114 virtual JSObject* WrapObject(JSContext* aCx,
115 JS::Handle<JSObject*> aGivenProto) override;
117 mozilla::dom::ScreenOrientation* Orientation() const;
119 protected:
120 nsDeviceContext* GetDeviceContext();
121 nsresult GetRect(nsRect& aRect);
122 nsresult GetAvailRect(nsRect& aRect);
123 nsresult GetWindowInnerRect(nsRect& aRect);
125 private:
126 explicit nsScreen(nsPIDOMWindowInner* aWindow);
127 virtual ~nsScreen();
129 bool ShouldResistFingerprinting() const;
131 mozilla::dom::Document* TopContentDocumentInRDMPane() const;
133 RefPtr<mozilla::dom::ScreenOrientation> mScreenOrientation;
136 #endif /* nsScreen_h___ */