diff --git a/dom/base/ScreenLuminance.cpp b/dom/base/ScreenLuminance.cpp new file mode 100644 index 000000000000..d8192b61aa41 --- /dev/null +++ b/dom/base/ScreenLuminance.cpp @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 et tw=78: */ +/* 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/. */ + +#include "ScreenLuminance.h" +#include "nsScreen.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ScreenLuminance, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ScreenLuminance, Release) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ScreenLuminance, mScreen) + +JSObject* +ScreenLuminance::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return ScreenLuminance_Binding::Wrap(aCx, this, aGivenProto); +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/base/ScreenLuminance.h b/dom/base/ScreenLuminance.h new file mode 100644 index 000000000000..4ece9ee42340 --- /dev/null +++ b/dom/base/ScreenLuminance.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 et tw=78: */ +/* 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/. */ + +#ifndef mozilla_dom_ScreenLuminance_h +#define mozilla_dom_ScreenLuminance_h + +#include "nsCycleCollectionParticipant.h" +#include "nsISupportsImpl.h" + +class nsScreen; + +namespace mozilla { +namespace dom { + +class ScreenLuminance final : public nsWrapperCache +{ +public: + // Ref counting and cycle collection + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ScreenLuminance) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(ScreenLuminance) + + // WebIDL methods + double Min() const { return mMin; } + double Max() const { return mMax; } + double MaxAverage() const { return mMaxAverage; } + // End WebIDL methods + + ScreenLuminance(nsScreen* aScreen, + double aMin, + double aMax, + double aMaxAverage) + : mScreen(aScreen) + , mMin(aMin) + , mMax(aMax) + , mMaxAverage(aMaxAverage) + { + } + + nsScreen* GetParentObject() const { return mScreen; } + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + +private: + virtual ~ScreenLuminance() {} + + RefPtr mScreen; + double mMin; + double mMax; + double mMaxAverage; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_ScreenLuminance_h diff --git a/dom/base/moz.build b/dom/base/moz.build index 1ba685ca7bbb..2ada52e99e0c 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -210,6 +210,7 @@ EXPORTS.mozilla.dom += [ 'ProcessMessageManager.h', 'ResponsiveImageSelector.h', 'SameProcessMessageQueue.h', + 'ScreenLuminance.h', 'ScreenOrientation.h', 'Selection.h', 'ShadowRoot.h', @@ -359,6 +360,7 @@ UNIFIED_SOURCES += [ 'ProcessMessageManager.cpp', 'ResponsiveImageSelector.cpp', 'SameProcessMessageQueue.cpp', + 'ScreenLuminance.cpp', 'ScreenOrientation.cpp', 'Selection.cpp', 'SelectionChangeListener.cpp', diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index f287a64a0562..b5c36b516c91 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -4,7 +4,6 @@ * 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/. */ -#include "mozilla/dom/ScreenBinding.h" #include "nsContentUtils.h" #include "nsScreen.h" #include "nsIDocument.h" diff --git a/dom/base/nsScreen.h b/dom/base/nsScreen.h index 829c3dcc7eda..ed52a9e702c2 100644 --- a/dom/base/nsScreen.h +++ b/dom/base/nsScreen.h @@ -7,6 +7,8 @@ #define nsScreen_h___ #include "mozilla/Attributes.h" +#include "mozilla/dom/ScreenBinding.h" +#include "mozilla/dom/ScreenLuminance.h" #include "mozilla/dom/ScreenOrientation.h" #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/ErrorResult.h" @@ -110,6 +112,19 @@ public: return rect.Height(); } + // Media Capabilities extension + mozilla::dom::ScreenColorGamut ColorGamut() const + { + return mozilla::dom::ScreenColorGamut::Srgb; + } + + already_AddRefed GetLuminance() const + { + return nullptr; + } + + IMPL_EVENT_HANDLER(change); + // Deprecated void GetMozOrientation(nsString& aOrientation, mozilla::dom::CallerType aCallerType) const; diff --git a/dom/webidl/Screen.webidl b/dom/webidl/Screen.webidl index 225389dae379..723728424560 100644 --- a/dom/webidl/Screen.webidl +++ b/dom/webidl/Screen.webidl @@ -59,3 +59,27 @@ interface Screen : EventTarget { partial interface Screen { readonly attribute ScreenOrientation orientation; }; + +// https://wicg.github.io/media-capabilities/#idl-index +enum ScreenColorGamut { + "srgb", + "p3", + "rec2020", +}; + +[Func="mozilla::dom::MediaCapabilities::Enabled"] +interface ScreenLuminance { + readonly attribute double min; + readonly attribute double max; + readonly attribute double maxAverage; +}; + +partial interface Screen { + [Func="mozilla::dom::MediaCapabilities::Enabled"] + readonly attribute ScreenColorGamut colorGamut; + [Func="mozilla::dom::MediaCapabilities::Enabled"] + readonly attribute ScreenLuminance? luminance; + + [Func="mozilla::dom::MediaCapabilities::Enabled"] + attribute EventHandler onchange; +};