|
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___ |
|
7 |
|
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" |
|
16 |
|
17 class nsDeviceContext; |
|
18 |
|
19 // Script "screen" object |
|
20 class nsScreen : public mozilla::DOMEventTargetHelper |
|
21 , public nsIDOMScreen |
|
22 , public mozilla::hal::ScreenConfigurationObserver |
|
23 { |
|
24 typedef mozilla::ErrorResult ErrorResult; |
|
25 public: |
|
26 static already_AddRefed<nsScreen> Create(nsPIDOMWindow* aWindow); |
|
27 |
|
28 NS_DECL_ISUPPORTS_INHERITED |
|
29 NS_DECL_NSIDOMSCREEN |
|
30 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper) |
|
31 |
|
32 nsPIDOMWindow* GetParentObject() const |
|
33 { |
|
34 return GetOwner(); |
|
35 } |
|
36 |
|
37 int32_t GetTop(ErrorResult& aRv) |
|
38 { |
|
39 nsRect rect; |
|
40 aRv = GetRect(rect); |
|
41 return rect.y; |
|
42 } |
|
43 |
|
44 int32_t GetLeft(ErrorResult& aRv) |
|
45 { |
|
46 nsRect rect; |
|
47 aRv = GetRect(rect); |
|
48 return rect.x; |
|
49 } |
|
50 |
|
51 int32_t GetWidth(ErrorResult& aRv) |
|
52 { |
|
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; |
|
60 } |
|
61 } |
|
62 |
|
63 aRv = GetRect(rect); |
|
64 return rect.width; |
|
65 } |
|
66 |
|
67 int32_t GetHeight(ErrorResult& aRv) |
|
68 { |
|
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; |
|
76 } |
|
77 } |
|
78 |
|
79 aRv = GetRect(rect); |
|
80 return rect.height; |
|
81 } |
|
82 |
|
83 int32_t GetPixelDepth(ErrorResult& aRv); |
|
84 int32_t GetColorDepth(ErrorResult& aRv) |
|
85 { |
|
86 return GetPixelDepth(aRv); |
|
87 } |
|
88 |
|
89 int32_t GetAvailTop(ErrorResult& aRv) |
|
90 { |
|
91 nsRect rect; |
|
92 aRv = GetAvailRect(rect); |
|
93 return rect.y; |
|
94 } |
|
95 |
|
96 int32_t GetAvailLeft(ErrorResult& aRv) |
|
97 { |
|
98 nsRect rect; |
|
99 aRv = GetAvailRect(rect); |
|
100 return rect.x; |
|
101 } |
|
102 |
|
103 int32_t GetAvailWidth(ErrorResult& aRv) |
|
104 { |
|
105 nsRect rect; |
|
106 aRv = GetAvailRect(rect); |
|
107 return rect.width; |
|
108 } |
|
109 |
|
110 int32_t GetAvailHeight(ErrorResult& aRv) |
|
111 { |
|
112 nsRect rect; |
|
113 aRv = GetAvailRect(rect); |
|
114 return rect.height; |
|
115 } |
|
116 |
|
117 void GetMozOrientation(nsString& aOrientation); |
|
118 |
|
119 IMPL_EVENT_HANDLER(mozorientationchange) |
|
120 |
|
121 bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv); |
|
122 bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations, ErrorResult& aRv); |
|
123 void MozUnlockOrientation(); |
|
124 |
|
125 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
126 |
|
127 void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration); |
|
128 |
|
129 protected: |
|
130 nsDeviceContext* GetDeviceContext(); |
|
131 nsresult GetRect(nsRect& aRect); |
|
132 nsresult GetAvailRect(nsRect& aRect); |
|
133 bool IsChrome(); |
|
134 nsresult GetDOMWindow(nsIDOMWindow **aResult); |
|
135 nsresult GetWindowInnerRect(nsRect& aRect); |
|
136 |
|
137 mozilla::dom::ScreenOrientation mOrientation; |
|
138 |
|
139 private: |
|
140 class FullScreenEventListener MOZ_FINAL : public nsIDOMEventListener |
|
141 { |
|
142 public: |
|
143 FullScreenEventListener() {}; |
|
144 |
|
145 NS_DECL_ISUPPORTS |
|
146 NS_DECL_NSIDOMEVENTLISTENER |
|
147 }; |
|
148 |
|
149 nsScreen(nsPIDOMWindow* aWindow); |
|
150 virtual ~nsScreen(); |
|
151 |
|
152 enum LockPermission { |
|
153 LOCK_DENIED, |
|
154 FULLSCREEN_LOCK_ALLOWED, |
|
155 LOCK_ALLOWED |
|
156 }; |
|
157 |
|
158 LockPermission GetLockOrientationPermission() const; |
|
159 |
|
160 bool IsDeviceSizePageSize(); |
|
161 |
|
162 nsRefPtr<FullScreenEventListener> mEventListener; |
|
163 }; |
|
164 |
|
165 #endif /* nsScreen_h___ */ |