Bug 1409664 - P2. Add ScreenLuminance objects and friends to Screen. r=bz

Summary:
As per https://wicg.github.io/media-capabilities/#idl-index

Depends on D1613

Tags: #secure-revision

Bug #: 1409664

Differential Revision: https://phabricator.services.mozilla.com/D1614
This commit is contained in:
Jean-Yves Avenard 2018-05-31 16:01:31 +02:00
parent 83a8e7725c
commit c55b6749ae
6 changed files with 123 additions and 1 deletions

View File

@ -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<JSObject*> aGivenProto)
{
return ScreenLuminance_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla

View File

@ -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<JSObject*> aGivenProto) override;
private:
virtual ~ScreenLuminance() {}
RefPtr<nsScreen> mScreen;
double mMin;
double mMax;
double mMaxAverage;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_ScreenLuminance_h

View File

@ -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',

View File

@ -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"

View File

@ -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<mozilla::dom::ScreenLuminance> GetLuminance() const
{
return nullptr;
}
IMPL_EVENT_HANDLER(change);
// Deprecated
void GetMozOrientation(nsString& aOrientation,
mozilla::dom::CallerType aCallerType) const;

View File

@ -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;
};