1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/Attributes.h"
9 #include "mozilla/dom/ScreenOrientation.h"
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/HalScreenConfiguration.h"
13 #include "nsIDOMScreen.h"
17 class nsDeviceContext
;
19 // Script "screen" object
20 class nsScreen
: public mozilla::DOMEventTargetHelper
22 , public mozilla::hal::ScreenConfigurationObserver
24 typedef mozilla::ErrorResult ErrorResult
;
26 static already_AddRefed
<nsScreen
> Create(nsPIDOMWindow
* aWindow
);
28 NS_DECL_ISUPPORTS_INHERITED
30 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper
)
32 nsPIDOMWindow
* GetParentObject() const
37 int32_t GetTop(ErrorResult
& aRv
)
44 int32_t GetLeft(ErrorResult
& aRv
)
51 int32_t GetWidth(ErrorResult
& aRv
)
54 if (IsDeviceSizePageSize()) {
55 nsCOMPtr
<nsPIDOMWindow
> owner
= GetOwner();
57 int32_t innerWidth
= 0;
58 aRv
= owner
->GetInnerWidth(&innerWidth
);
67 int32_t GetHeight(ErrorResult
& aRv
)
70 if (IsDeviceSizePageSize()) {
71 nsCOMPtr
<nsPIDOMWindow
> owner
= GetOwner();
73 int32_t innerHeight
= 0;
74 aRv
= owner
->GetInnerHeight(&innerHeight
);
83 int32_t GetPixelDepth(ErrorResult
& aRv
);
84 int32_t GetColorDepth(ErrorResult
& aRv
)
86 return GetPixelDepth(aRv
);
89 int32_t GetAvailTop(ErrorResult
& aRv
)
92 aRv
= GetAvailRect(rect
);
96 int32_t GetAvailLeft(ErrorResult
& aRv
)
99 aRv
= GetAvailRect(rect
);
103 int32_t GetAvailWidth(ErrorResult
& aRv
)
106 aRv
= GetAvailRect(rect
);
110 int32_t GetAvailHeight(ErrorResult
& aRv
)
113 aRv
= GetAvailRect(rect
);
117 void GetMozOrientation(nsString
& aOrientation
);
119 IMPL_EVENT_HANDLER(mozorientationchange
)
121 bool MozLockOrientation(const nsAString
& aOrientation
, ErrorResult
& aRv
);
122 bool MozLockOrientation(const mozilla::dom::Sequence
<nsString
>& aOrientations
, ErrorResult
& aRv
);
123 void MozUnlockOrientation();
125 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
127 void Notify(const mozilla::hal::ScreenConfiguration
& aConfiguration
);
130 nsDeviceContext
* GetDeviceContext();
131 nsresult
GetRect(nsRect
& aRect
);
132 nsresult
GetAvailRect(nsRect
& aRect
);
134 mozilla::dom::ScreenOrientation mOrientation
;
137 class FullScreenEventListener MOZ_FINAL
: public nsIDOMEventListener
139 ~FullScreenEventListener() {}
141 FullScreenEventListener() {}
144 NS_DECL_NSIDOMEVENTLISTENER
147 explicit nsScreen(nsPIDOMWindow
* aWindow
);
150 enum LockPermission
{
152 FULLSCREEN_LOCK_ALLOWED
,
156 LockPermission
GetLockOrientationPermission() const;
158 bool IsDeviceSizePageSize();
160 nsRefPtr
<FullScreenEventListener
> mEventListener
;
163 #endif /* nsScreen_h___ */