Bumping manifests a=b2g-bump
[gecko.git] / dom / base / nsScreen.h
blob47067092527861e618a91d6430304a66b885cfcd
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/. */
5 #ifndef nsScreen_h___
6 #define nsScreen_h___
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"
14 #include "nsCOMPtr.h"
15 #include "nsRect.h"
17 class nsDeviceContext;
19 // Script "screen" object
20 class nsScreen : public mozilla::DOMEventTargetHelper
21 , public nsIDOMScreen
22 , public mozilla::hal::ScreenConfigurationObserver
24 typedef mozilla::ErrorResult ErrorResult;
25 public:
26 static already_AddRefed<nsScreen> Create(nsPIDOMWindow* aWindow);
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_NSIDOMSCREEN
30 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper)
32 nsPIDOMWindow* GetParentObject() const
34 return GetOwner();
37 int32_t GetTop(ErrorResult& aRv)
39 nsRect rect;
40 aRv = GetRect(rect);
41 return rect.y;
44 int32_t GetLeft(ErrorResult& aRv)
46 nsRect rect;
47 aRv = GetRect(rect);
48 return rect.x;
51 int32_t GetWidth(ErrorResult& aRv)
53 nsRect rect;
54 if (IsDeviceSizePageSize()) {
55 nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
56 if (owner) {
57 int32_t innerWidth = 0;
58 aRv = owner->GetInnerWidth(&innerWidth);
59 return innerWidth;
63 aRv = GetRect(rect);
64 return rect.width;
67 int32_t GetHeight(ErrorResult& aRv)
69 nsRect rect;
70 if (IsDeviceSizePageSize()) {
71 nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
72 if (owner) {
73 int32_t innerHeight = 0;
74 aRv = owner->GetInnerHeight(&innerHeight);
75 return innerHeight;
79 aRv = GetRect(rect);
80 return rect.height;
83 int32_t GetPixelDepth(ErrorResult& aRv);
84 int32_t GetColorDepth(ErrorResult& aRv)
86 return GetPixelDepth(aRv);
89 int32_t GetAvailTop(ErrorResult& aRv)
91 nsRect rect;
92 aRv = GetAvailRect(rect);
93 return rect.y;
96 int32_t GetAvailLeft(ErrorResult& aRv)
98 nsRect rect;
99 aRv = GetAvailRect(rect);
100 return rect.x;
103 int32_t GetAvailWidth(ErrorResult& aRv)
105 nsRect rect;
106 aRv = GetAvailRect(rect);
107 return rect.width;
110 int32_t GetAvailHeight(ErrorResult& aRv)
112 nsRect rect;
113 aRv = GetAvailRect(rect);
114 return rect.height;
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);
129 protected:
130 nsDeviceContext* GetDeviceContext();
131 nsresult GetRect(nsRect& aRect);
132 nsresult GetAvailRect(nsRect& aRect);
134 mozilla::dom::ScreenOrientation mOrientation;
136 private:
137 class FullScreenEventListener MOZ_FINAL : public nsIDOMEventListener
139 ~FullScreenEventListener() {}
140 public:
141 FullScreenEventListener() {}
143 NS_DECL_ISUPPORTS
144 NS_DECL_NSIDOMEVENTLISTENER
147 explicit nsScreen(nsPIDOMWindow* aWindow);
148 virtual ~nsScreen();
150 enum LockPermission {
151 LOCK_DENIED,
152 FULLSCREEN_LOCK_ALLOWED,
153 LOCK_ALLOWED
156 LockPermission GetLockOrientationPermission() const;
158 bool IsDeviceSizePageSize();
160 nsRefPtr<FullScreenEventListener> mEventListener;
163 #endif /* nsScreen_h___ */