michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsScreen_h___ michael@0: #define nsScreen_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/ScreenOrientation.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "mozilla/HalScreenConfiguration.h" michael@0: #include "nsIDOMScreen.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsRect.h" michael@0: michael@0: class nsDeviceContext; michael@0: michael@0: // Script "screen" object michael@0: class nsScreen : public mozilla::DOMEventTargetHelper michael@0: , public nsIDOMScreen michael@0: , public mozilla::hal::ScreenConfigurationObserver michael@0: { michael@0: typedef mozilla::ErrorResult ErrorResult; michael@0: public: michael@0: static already_AddRefed Create(nsPIDOMWindow* aWindow); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSIDOMSCREEN michael@0: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper) michael@0: michael@0: nsPIDOMWindow* GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: int32_t GetTop(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: aRv = GetRect(rect); michael@0: return rect.y; michael@0: } michael@0: michael@0: int32_t GetLeft(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: aRv = GetRect(rect); michael@0: return rect.x; michael@0: } michael@0: michael@0: int32_t GetWidth(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: if (IsDeviceSizePageSize()) { michael@0: nsCOMPtr owner = GetOwner(); michael@0: if (owner) { michael@0: int32_t innerWidth = 0; michael@0: aRv = owner->GetInnerWidth(&innerWidth); michael@0: return innerWidth; michael@0: } michael@0: } michael@0: michael@0: aRv = GetRect(rect); michael@0: return rect.width; michael@0: } michael@0: michael@0: int32_t GetHeight(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: if (IsDeviceSizePageSize()) { michael@0: nsCOMPtr owner = GetOwner(); michael@0: if (owner) { michael@0: int32_t innerHeight = 0; michael@0: aRv = owner->GetInnerHeight(&innerHeight); michael@0: return innerHeight; michael@0: } michael@0: } michael@0: michael@0: aRv = GetRect(rect); michael@0: return rect.height; michael@0: } michael@0: michael@0: int32_t GetPixelDepth(ErrorResult& aRv); michael@0: int32_t GetColorDepth(ErrorResult& aRv) michael@0: { michael@0: return GetPixelDepth(aRv); michael@0: } michael@0: michael@0: int32_t GetAvailTop(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: aRv = GetAvailRect(rect); michael@0: return rect.y; michael@0: } michael@0: michael@0: int32_t GetAvailLeft(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: aRv = GetAvailRect(rect); michael@0: return rect.x; michael@0: } michael@0: michael@0: int32_t GetAvailWidth(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: aRv = GetAvailRect(rect); michael@0: return rect.width; michael@0: } michael@0: michael@0: int32_t GetAvailHeight(ErrorResult& aRv) michael@0: { michael@0: nsRect rect; michael@0: aRv = GetAvailRect(rect); michael@0: return rect.height; michael@0: } michael@0: michael@0: void GetMozOrientation(nsString& aOrientation); michael@0: michael@0: IMPL_EVENT_HANDLER(mozorientationchange) michael@0: michael@0: bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv); michael@0: bool MozLockOrientation(const mozilla::dom::Sequence& aOrientations, ErrorResult& aRv); michael@0: void MozUnlockOrientation(); michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration); michael@0: michael@0: protected: michael@0: nsDeviceContext* GetDeviceContext(); michael@0: nsresult GetRect(nsRect& aRect); michael@0: nsresult GetAvailRect(nsRect& aRect); michael@0: bool IsChrome(); michael@0: nsresult GetDOMWindow(nsIDOMWindow **aResult); michael@0: nsresult GetWindowInnerRect(nsRect& aRect); michael@0: michael@0: mozilla::dom::ScreenOrientation mOrientation; michael@0: michael@0: private: michael@0: class FullScreenEventListener MOZ_FINAL : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: FullScreenEventListener() {}; michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: }; michael@0: michael@0: nsScreen(nsPIDOMWindow* aWindow); michael@0: virtual ~nsScreen(); michael@0: michael@0: enum LockPermission { michael@0: LOCK_DENIED, michael@0: FULLSCREEN_LOCK_ALLOWED, michael@0: LOCK_ALLOWED michael@0: }; michael@0: michael@0: LockPermission GetLockOrientationPermission() const; michael@0: michael@0: bool IsDeviceSizePageSize(); michael@0: michael@0: nsRefPtr mEventListener; michael@0: }; michael@0: michael@0: #endif /* nsScreen_h___ */