2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-01-29 01:24:29 +03:00
|
|
|
#ifndef nsScreen_h___
|
|
|
|
#define nsScreen_h___
|
|
|
|
|
2012-10-14 11:39:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2018-05-31 17:01:31 +03:00
|
|
|
#include "mozilla/dom/ScreenBinding.h"
|
|
|
|
#include "mozilla/dom/ScreenLuminance.h"
|
2012-05-09 01:36:07 +04:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2012-10-14 11:39:34 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2018-08-10 00:05:55 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2003-07-03 06:49:06 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2012-10-14 11:40:11 +04:00
|
|
|
#include "nsRect.h"
|
2000-02-08 16:40:10 +03:00
|
|
|
|
2011-04-17 05:22:44 +04:00
|
|
|
class nsDeviceContext;
|
1999-01-29 01:24:29 +03:00
|
|
|
|
|
|
|
// Script "screen" object
|
2014-04-01 10:13:50 +04:00
|
|
|
class nsScreen : public mozilla::DOMEventTargetHelper {
|
2012-10-14 11:39:34 +04:00
|
|
|
typedef mozilla::ErrorResult ErrorResult;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
1999-01-29 01:24:29 +03:00
|
|
|
public:
|
2016-01-30 20:05:36 +03:00
|
|
|
static already_AddRefed<nsScreen> Create(nsPIDOMWindowInner* aWindow);
|
1999-01-29 01:24:29 +03:00
|
|
|
|
2012-10-14 11:40:11 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2015-08-19 00:55:21 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen,
|
|
|
|
mozilla::DOMEventTargetHelper)
|
2012-03-14 14:10:48 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
|
2012-10-14 11:40:11 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* GetOuter() const;
|
|
|
|
|
2012-10-14 11:40:11 +04:00
|
|
|
int32_t GetTop(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
|
|
|
aRv = GetRect(rect);
|
2018-02-19 23:15:23 +03:00
|
|
|
return rect.y;
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetLeft(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
|
|
|
aRv = GetRect(rect);
|
2018-02-19 23:15:23 +03:00
|
|
|
return rect.x;
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetWidth(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
2013-11-07 17:40:23 +04:00
|
|
|
if (IsDeviceSizePageSize()) {
|
2019-06-05 18:44:04 +03:00
|
|
|
if (IsInRDMPane()) {
|
|
|
|
GetRDMScreenSize(rect);
|
|
|
|
return rect.Width();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner()) {
|
2013-11-07 17:40:23 +04:00
|
|
|
int32_t innerWidth = 0;
|
|
|
|
aRv = owner->GetInnerWidth(&innerWidth);
|
|
|
|
return innerWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 11:40:11 +04:00
|
|
|
aRv = GetRect(rect);
|
2017-08-14 15:30:10 +03:00
|
|
|
return rect.Width();
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetHeight(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
2013-11-07 17:40:23 +04:00
|
|
|
if (IsDeviceSizePageSize()) {
|
2019-06-05 18:44:04 +03:00
|
|
|
if (IsInRDMPane()) {
|
|
|
|
GetRDMScreenSize(rect);
|
|
|
|
return rect.Height();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner()) {
|
2013-11-07 17:40:23 +04:00
|
|
|
int32_t innerHeight = 0;
|
|
|
|
aRv = owner->GetInnerHeight(&innerHeight);
|
|
|
|
return innerHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 11:40:11 +04:00
|
|
|
aRv = GetRect(rect);
|
2017-08-14 15:30:10 +03:00
|
|
|
return rect.Height();
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetPixelDepth(ErrorResult& aRv);
|
|
|
|
int32_t GetColorDepth(ErrorResult& aRv) { return GetPixelDepth(aRv); }
|
|
|
|
|
|
|
|
int32_t GetAvailTop(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
|
|
|
aRv = GetAvailRect(rect);
|
2018-02-19 23:15:23 +03:00
|
|
|
return rect.y;
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetAvailLeft(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
|
|
|
aRv = GetAvailRect(rect);
|
2018-02-19 23:15:23 +03:00
|
|
|
return rect.x;
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetAvailWidth(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
|
|
|
aRv = GetAvailRect(rect);
|
2017-08-14 15:30:10 +03:00
|
|
|
return rect.Width();
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetAvailHeight(ErrorResult& aRv) {
|
|
|
|
nsRect rect;
|
|
|
|
aRv = GetAvailRect(rect);
|
2017-08-14 15:30:10 +03:00
|
|
|
return rect.Height();
|
2012-10-14 11:40:11 +04:00
|
|
|
}
|
|
|
|
|
2018-05-31 17:01:31 +03:00
|
|
|
// Media Capabilities extension
|
|
|
|
mozilla::dom::ScreenColorGamut ColorGamut() const {
|
|
|
|
return mozilla::dom::ScreenColorGamut::Srgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<mozilla::dom::ScreenLuminance> GetLuminance() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-10 00:05:55 +03:00
|
|
|
static bool MediaCapabilitiesEnabled(JSContext* aCx, JSObject* aGlobal) {
|
2019-06-28 07:09:05 +03:00
|
|
|
return mozilla::StaticPrefs::media_media_capabilities_screen_enabled();
|
2018-08-10 00:05:55 +03:00
|
|
|
}
|
|
|
|
|
2018-05-31 17:01:31 +03:00
|
|
|
IMPL_EVENT_HANDLER(change);
|
|
|
|
|
2015-08-19 00:55:21 +03:00
|
|
|
// Deprecated
|
2016-12-22 22:05:54 +03:00
|
|
|
void GetMozOrientation(nsString& aOrientation,
|
|
|
|
mozilla::dom::CallerType aCallerType) const;
|
2012-10-14 11:40:11 +04:00
|
|
|
|
2012-11-09 20:00:25 +04:00
|
|
|
IMPL_EVENT_HANDLER(mozorientationchange)
|
2012-10-14 11:40:11 +04:00
|
|
|
|
2012-10-14 11:39:34 +04:00
|
|
|
bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv);
|
|
|
|
bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations,
|
|
|
|
ErrorResult& aRv);
|
2012-10-14 11:40:11 +04:00
|
|
|
void MozUnlockOrientation();
|
2012-10-14 11:39:34 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2012-10-14 11:40:11 +04:00
|
|
|
|
2015-08-19 00:55:21 +03:00
|
|
|
mozilla::dom::ScreenOrientation* Orientation() const;
|
2000-02-08 16:40:10 +03:00
|
|
|
|
1999-01-29 01:24:29 +03:00
|
|
|
protected:
|
2011-04-17 05:22:44 +04:00
|
|
|
nsDeviceContext* GetDeviceContext();
|
2003-09-20 01:06:52 +04:00
|
|
|
nsresult GetRect(nsRect& aRect);
|
|
|
|
nsresult GetAvailRect(nsRect& aRect);
|
2015-06-07 16:02:00 +03:00
|
|
|
nsresult GetWindowInnerRect(nsRect& aRect);
|
2019-06-05 18:44:04 +03:00
|
|
|
nsresult GetRDMScreenSize(nsRect& aRect);
|
2003-09-20 01:06:52 +04:00
|
|
|
|
2011-12-04 21:07:00 +04:00
|
|
|
private:
|
2016-01-30 20:05:36 +03:00
|
|
|
explicit nsScreen(nsPIDOMWindowInner* aWindow);
|
2012-03-14 14:10:48 +04:00
|
|
|
virtual ~nsScreen();
|
|
|
|
|
2013-11-07 17:40:23 +04:00
|
|
|
bool IsDeviceSizePageSize();
|
|
|
|
|
2015-06-07 16:02:00 +03:00
|
|
|
bool ShouldResistFingerprinting() const;
|
|
|
|
|
2019-06-05 18:44:04 +03:00
|
|
|
bool IsInRDMPane() const;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::ScreenOrientation> mScreenOrientation;
|
1999-01-29 01:24:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsScreen_h___ */
|