Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #ifndef nsScreen_h___ |
michael@0 | 6 | #define nsScreen_h___ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/Attributes.h" |
michael@0 | 9 | #include "mozilla/dom/ScreenOrientation.h" |
michael@0 | 10 | #include "mozilla/DOMEventTargetHelper.h" |
michael@0 | 11 | #include "mozilla/ErrorResult.h" |
michael@0 | 12 | #include "mozilla/HalScreenConfiguration.h" |
michael@0 | 13 | #include "nsIDOMScreen.h" |
michael@0 | 14 | #include "nsCOMPtr.h" |
michael@0 | 15 | #include "nsRect.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsDeviceContext; |
michael@0 | 18 | |
michael@0 | 19 | // Script "screen" object |
michael@0 | 20 | class nsScreen : public mozilla::DOMEventTargetHelper |
michael@0 | 21 | , public nsIDOMScreen |
michael@0 | 22 | , public mozilla::hal::ScreenConfigurationObserver |
michael@0 | 23 | { |
michael@0 | 24 | typedef mozilla::ErrorResult ErrorResult; |
michael@0 | 25 | public: |
michael@0 | 26 | static already_AddRefed<nsScreen> Create(nsPIDOMWindow* aWindow); |
michael@0 | 27 | |
michael@0 | 28 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 29 | NS_DECL_NSIDOMSCREEN |
michael@0 | 30 | NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper) |
michael@0 | 31 | |
michael@0 | 32 | nsPIDOMWindow* GetParentObject() const |
michael@0 | 33 | { |
michael@0 | 34 | return GetOwner(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | int32_t GetTop(ErrorResult& aRv) |
michael@0 | 38 | { |
michael@0 | 39 | nsRect rect; |
michael@0 | 40 | aRv = GetRect(rect); |
michael@0 | 41 | return rect.y; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | int32_t GetLeft(ErrorResult& aRv) |
michael@0 | 45 | { |
michael@0 | 46 | nsRect rect; |
michael@0 | 47 | aRv = GetRect(rect); |
michael@0 | 48 | return rect.x; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | int32_t GetWidth(ErrorResult& aRv) |
michael@0 | 52 | { |
michael@0 | 53 | nsRect rect; |
michael@0 | 54 | if (IsDeviceSizePageSize()) { |
michael@0 | 55 | nsCOMPtr<nsPIDOMWindow> owner = GetOwner(); |
michael@0 | 56 | if (owner) { |
michael@0 | 57 | int32_t innerWidth = 0; |
michael@0 | 58 | aRv = owner->GetInnerWidth(&innerWidth); |
michael@0 | 59 | return innerWidth; |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | aRv = GetRect(rect); |
michael@0 | 64 | return rect.width; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | int32_t GetHeight(ErrorResult& aRv) |
michael@0 | 68 | { |
michael@0 | 69 | nsRect rect; |
michael@0 | 70 | if (IsDeviceSizePageSize()) { |
michael@0 | 71 | nsCOMPtr<nsPIDOMWindow> owner = GetOwner(); |
michael@0 | 72 | if (owner) { |
michael@0 | 73 | int32_t innerHeight = 0; |
michael@0 | 74 | aRv = owner->GetInnerHeight(&innerHeight); |
michael@0 | 75 | return innerHeight; |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | aRv = GetRect(rect); |
michael@0 | 80 | return rect.height; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | int32_t GetPixelDepth(ErrorResult& aRv); |
michael@0 | 84 | int32_t GetColorDepth(ErrorResult& aRv) |
michael@0 | 85 | { |
michael@0 | 86 | return GetPixelDepth(aRv); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | int32_t GetAvailTop(ErrorResult& aRv) |
michael@0 | 90 | { |
michael@0 | 91 | nsRect rect; |
michael@0 | 92 | aRv = GetAvailRect(rect); |
michael@0 | 93 | return rect.y; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | int32_t GetAvailLeft(ErrorResult& aRv) |
michael@0 | 97 | { |
michael@0 | 98 | nsRect rect; |
michael@0 | 99 | aRv = GetAvailRect(rect); |
michael@0 | 100 | return rect.x; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | int32_t GetAvailWidth(ErrorResult& aRv) |
michael@0 | 104 | { |
michael@0 | 105 | nsRect rect; |
michael@0 | 106 | aRv = GetAvailRect(rect); |
michael@0 | 107 | return rect.width; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | int32_t GetAvailHeight(ErrorResult& aRv) |
michael@0 | 111 | { |
michael@0 | 112 | nsRect rect; |
michael@0 | 113 | aRv = GetAvailRect(rect); |
michael@0 | 114 | return rect.height; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | void GetMozOrientation(nsString& aOrientation); |
michael@0 | 118 | |
michael@0 | 119 | IMPL_EVENT_HANDLER(mozorientationchange) |
michael@0 | 120 | |
michael@0 | 121 | bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv); |
michael@0 | 122 | bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations, ErrorResult& aRv); |
michael@0 | 123 | void MozUnlockOrientation(); |
michael@0 | 124 | |
michael@0 | 125 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 126 | |
michael@0 | 127 | void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration); |
michael@0 | 128 | |
michael@0 | 129 | protected: |
michael@0 | 130 | nsDeviceContext* GetDeviceContext(); |
michael@0 | 131 | nsresult GetRect(nsRect& aRect); |
michael@0 | 132 | nsresult GetAvailRect(nsRect& aRect); |
michael@0 | 133 | bool IsChrome(); |
michael@0 | 134 | nsresult GetDOMWindow(nsIDOMWindow **aResult); |
michael@0 | 135 | nsresult GetWindowInnerRect(nsRect& aRect); |
michael@0 | 136 | |
michael@0 | 137 | mozilla::dom::ScreenOrientation mOrientation; |
michael@0 | 138 | |
michael@0 | 139 | private: |
michael@0 | 140 | class FullScreenEventListener MOZ_FINAL : public nsIDOMEventListener |
michael@0 | 141 | { |
michael@0 | 142 | public: |
michael@0 | 143 | FullScreenEventListener() {}; |
michael@0 | 144 | |
michael@0 | 145 | NS_DECL_ISUPPORTS |
michael@0 | 146 | NS_DECL_NSIDOMEVENTLISTENER |
michael@0 | 147 | }; |
michael@0 | 148 | |
michael@0 | 149 | nsScreen(nsPIDOMWindow* aWindow); |
michael@0 | 150 | virtual ~nsScreen(); |
michael@0 | 151 | |
michael@0 | 152 | enum LockPermission { |
michael@0 | 153 | LOCK_DENIED, |
michael@0 | 154 | FULLSCREEN_LOCK_ALLOWED, |
michael@0 | 155 | LOCK_ALLOWED |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | LockPermission GetLockOrientationPermission() const; |
michael@0 | 159 | |
michael@0 | 160 | bool IsDeviceSizePageSize(); |
michael@0 | 161 | |
michael@0 | 162 | nsRefPtr<FullScreenEventListener> mEventListener; |
michael@0 | 163 | }; |
michael@0 | 164 | |
michael@0 | 165 | #endif /* nsScreen_h___ */ |