forked from mirrors/gecko-dev
Bug 1754858 - Simplify screen orientation API implementation. r=smaug,m_kato,geckoview-reviewers
Make the ScreenOrientation part of the screen struct, as it should. Stop using HAL to propagate just screen orientation updates, use the more general screen manager. Instead of HAL observers, add a simple observer service notification, and clean a bunch of the code. This will simplify bug 1754802 a bit, and is generally simpler. Shouldn't change behavior. I've tested the events and some common orientation locking use cases like Youtube, and they behave the same. Differential Revision: https://phabricator.services.mozilla.com/D138477
This commit is contained in:
parent
999c849e35
commit
28290f66db
33 changed files with 209 additions and 500 deletions
|
|
@ -71,12 +71,8 @@ ScreenOrientation::ScreenOrientation(nsPIDOMWindowInner* aWindow,
|
|||
MOZ_ASSERT(aWindow);
|
||||
MOZ_ASSERT(aScreen);
|
||||
|
||||
hal::RegisterScreenConfigurationObserver(this);
|
||||
|
||||
hal::ScreenConfiguration config;
|
||||
hal::GetCurrentScreenConfiguration(&config);
|
||||
mType = InternalOrientationToType(config.orientation());
|
||||
mAngle = config.angle();
|
||||
mAngle = aScreen->GetOrientationAngle();
|
||||
mType = InternalOrientationToType(aScreen->GetOrientationType());
|
||||
|
||||
Document* doc = GetResponsibleDocument();
|
||||
BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
|
||||
|
|
@ -87,7 +83,7 @@ ScreenOrientation::ScreenOrientation(nsPIDOMWindowInner* aWindow,
|
|||
|
||||
ScreenOrientation::~ScreenOrientation() {
|
||||
UnlockDeviceOrientation();
|
||||
hal::UnregisterScreenConfigurationObserver(this);
|
||||
|
||||
MOZ_ASSERT(!mFullscreenListener);
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +148,8 @@ ScreenOrientation::LockOrientationTask::LockOrientationTask(
|
|||
|
||||
ScreenOrientation::LockOrientationTask::~LockOrientationTask() = default;
|
||||
|
||||
using LockOrientationPromise = MozPromise<bool, bool, false>;
|
||||
|
||||
bool ScreenOrientation::LockOrientationTask::OrientationLockContains(
|
||||
OrientationType aOrientationType) {
|
||||
return bool(mOrientationLock & OrientationTypeToInternal(aOrientationType));
|
||||
|
|
@ -186,7 +184,7 @@ ScreenOrientation::LockOrientationTask::Run() {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<MozPromise<bool, bool, false>> lockOrientationPromise =
|
||||
RefPtr<LockOrientationPromise> lockOrientationPromise =
|
||||
mScreenOrientation->LockDeviceOrientation(mOrientationLock,
|
||||
mIsFullscreen);
|
||||
|
||||
|
|
@ -199,8 +197,7 @@ ScreenOrientation::LockOrientationTask::Run() {
|
|||
lockOrientationPromise->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
[self = RefPtr{this}](
|
||||
const mozilla::MozPromise<bool, bool, false>::ResolveOrRejectValue&
|
||||
aValue) {
|
||||
const LockOrientationPromise::ResolveOrRejectValue& aValue) {
|
||||
if (aValue.IsResolve()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -362,10 +359,10 @@ already_AddRefed<Promise> ScreenOrientation::LockInternal(
|
|||
#endif
|
||||
}
|
||||
|
||||
RefPtr<MozPromise<bool, bool, false>> ScreenOrientation::LockDeviceOrientation(
|
||||
RefPtr<LockOrientationPromise> ScreenOrientation::LockDeviceOrientation(
|
||||
hal::ScreenOrientation aOrientation, bool aIsFullscreen) {
|
||||
if (!GetOwner()) {
|
||||
return MozPromise<bool, bool, false>::CreateAndReject(false, __func__);
|
||||
return LockOrientationPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
|
||||
nsCOMPtr<EventTarget> target = GetOwner()->GetDoc();
|
||||
|
|
@ -374,7 +371,7 @@ RefPtr<MozPromise<bool, bool, false>> ScreenOrientation::LockDeviceOrientation(
|
|||
// This needs to be done before LockScreenOrientation call to make sure
|
||||
// the locking can be unlocked.
|
||||
if (aIsFullscreen && !target) {
|
||||
return MozPromise<bool, bool, false>::CreateAndReject(false, __func__);
|
||||
return LockOrientationPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
|
||||
// We are fullscreen and lock has been accepted.
|
||||
|
|
@ -387,16 +384,17 @@ RefPtr<MozPromise<bool, bool, false>> ScreenOrientation::LockDeviceOrientation(
|
|||
mFullscreenListener,
|
||||
/* aUseCapture = */ true);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return MozPromise<bool, bool, false>::CreateAndReject(false, __func__);
|
||||
return LockOrientationPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<MozPromise<bool, bool, false>> halPromise =
|
||||
RefPtr<LockOrientationPromise> halPromise =
|
||||
hal::LockScreenOrientation(aOrientation);
|
||||
if (halPromise == nullptr) {
|
||||
return MozPromise<bool, bool, false>::CreateAndReject(false, __func__);
|
||||
if (!halPromise) {
|
||||
return LockOrientationPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
|
||||
mTriedToLockDeviceOrientation = true;
|
||||
return halPromise;
|
||||
}
|
||||
|
||||
|
|
@ -405,7 +403,10 @@ void ScreenOrientation::Unlock(ErrorResult& aRv) {
|
|||
}
|
||||
|
||||
void ScreenOrientation::UnlockDeviceOrientation() {
|
||||
hal::UnlockScreenOrientation();
|
||||
if (mTriedToLockDeviceOrientation) {
|
||||
hal::UnlockScreenOrientation();
|
||||
mTriedToLockDeviceOrientation = false;
|
||||
}
|
||||
|
||||
if (!mFullscreenListener || !GetOwner()) {
|
||||
mFullscreenListener = nullptr;
|
||||
|
|
@ -413,8 +414,7 @@ void ScreenOrientation::UnlockDeviceOrientation() {
|
|||
}
|
||||
|
||||
// Remove event listener in case of fullscreen lock.
|
||||
nsCOMPtr<EventTarget> target = GetOwner()->GetDoc();
|
||||
if (target) {
|
||||
if (nsCOMPtr<EventTarget> target = GetOwner()->GetDoc()) {
|
||||
target->RemoveSystemEventListener(u"fullscreenchange"_ns,
|
||||
mFullscreenListener,
|
||||
/* useCapture */ true);
|
||||
|
|
@ -505,7 +505,7 @@ Document* ScreenOrientation::GetResponsibleDocument() const {
|
|||
return owner->GetDoc();
|
||||
}
|
||||
|
||||
void ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) {
|
||||
void ScreenOrientation::MaybeChanged() {
|
||||
if (ShouldResistFingerprinting()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -516,7 +516,7 @@ void ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) {
|
|||
return;
|
||||
}
|
||||
|
||||
hal::ScreenOrientation orientation = aConfiguration.orientation();
|
||||
hal::ScreenOrientation orientation = mScreen->GetOrientationType();
|
||||
if (orientation != hal::ScreenOrientation::PortraitPrimary &&
|
||||
orientation != hal::ScreenOrientation::PortraitSecondary &&
|
||||
orientation != hal::ScreenOrientation::LandscapePrimary &&
|
||||
|
|
@ -529,7 +529,7 @@ void ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) {
|
|||
}
|
||||
|
||||
OrientationType previousOrientation = mType;
|
||||
mAngle = aConfiguration.angle();
|
||||
mAngle = mScreen->GetOrientationAngle();
|
||||
mType = InternalOrientationToType(orientation);
|
||||
|
||||
DebugOnly<nsresult> rv;
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ namespace dom {
|
|||
|
||||
class Promise;
|
||||
|
||||
class ScreenOrientation final
|
||||
: public DOMEventTargetHelper,
|
||||
public mozilla::hal::ScreenConfigurationObserver {
|
||||
class ScreenOrientation final : public DOMEventTargetHelper {
|
||||
// nsScreen has deprecated API that shares implementation.
|
||||
friend class ::nsScreen;
|
||||
|
||||
|
|
@ -33,6 +31,9 @@ class ScreenOrientation final
|
|||
|
||||
IMPL_EVENT_HANDLER(change)
|
||||
|
||||
// Called when the orientation may have changed.
|
||||
void MaybeChanged();
|
||||
|
||||
ScreenOrientation(nsPIDOMWindowInner* aWindow, nsScreen* aScreen);
|
||||
|
||||
already_AddRefed<Promise> Lock(OrientationLockType aOrientation,
|
||||
|
|
@ -49,10 +50,8 @@ class ScreenOrientation final
|
|||
OrientationType GetType(CallerType aCallerType, ErrorResult& aRv) const;
|
||||
uint16_t GetAngle(CallerType aCallerType, ErrorResult& aRv) const;
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration) override;
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
static void UpdateActiveOrientationLock(hal::ScreenOrientation aOrientation);
|
||||
static void AbortInProcessOrientationPromises(
|
||||
|
|
@ -103,6 +102,12 @@ class ScreenOrientation final
|
|||
RefPtr<VisibleEventListener> mVisibleListener;
|
||||
OrientationType mType;
|
||||
uint16_t mAngle;
|
||||
// Whether we've tried to call into hal to lock the device orientation. This
|
||||
// is needed because you don't want calling UnlockDeviceOrientation() during
|
||||
// shutdown to initialize PHal if it hasn't been initialized earlier. Also,
|
||||
// makes sense (there's no reason destroying a ScreenOrientation object from a
|
||||
// different window should remove the orientation lock).
|
||||
bool mTriedToLockDeviceOrientation = false;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "WindowOrientationObserver.h"
|
||||
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "mozilla/Hal.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/**
|
||||
* This class is used by nsGlobalWindowInner to implement window.orientation
|
||||
* and window.onorientationchange. This class is defined in its own file
|
||||
* because Hal.h pulls in windows.h and can't be included from
|
||||
* nsGlobalWindow.cpp
|
||||
*/
|
||||
WindowOrientationObserver::WindowOrientationObserver(
|
||||
nsGlobalWindowInner* aGlobalWindow)
|
||||
: mWindow(aGlobalWindow) {
|
||||
MOZ_ASSERT(aGlobalWindow);
|
||||
hal::RegisterScreenConfigurationObserver(this);
|
||||
|
||||
hal::ScreenConfiguration config;
|
||||
hal::GetCurrentScreenConfiguration(&config);
|
||||
mAngle = config.angle();
|
||||
}
|
||||
|
||||
WindowOrientationObserver::~WindowOrientationObserver() {
|
||||
hal::UnregisterScreenConfigurationObserver(this);
|
||||
}
|
||||
|
||||
void WindowOrientationObserver::Notify(
|
||||
const mozilla::hal::ScreenConfiguration& aConfiguration) {
|
||||
uint16_t currentAngle = aConfiguration.angle();
|
||||
if (mAngle != currentAngle && mWindow->IsCurrentInnerWindow()) {
|
||||
mAngle = currentAngle;
|
||||
mWindow->GetOuterWindow()->DispatchCustomEvent(u"orientationchange"_ns);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
int16_t WindowOrientationObserver::OrientationAngle() {
|
||||
hal::ScreenConfiguration config;
|
||||
hal::GetCurrentScreenConfiguration(&config);
|
||||
int16_t angle = static_cast<int16_t>(config.angle());
|
||||
// config.angle() returns 0, 90, 180 or 270.
|
||||
// window.orientation returns -90, 0, 90 or 180.
|
||||
return angle <= 180 ? angle : angle - 360;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_WindowOrientationObserver_h
|
||||
#define mozilla_dom_WindowOrientationObserver_h
|
||||
|
||||
#include "mozilla/HalScreenConfiguration.h"
|
||||
|
||||
class nsGlobalWindowInner;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class WindowOrientationObserver final
|
||||
: public mozilla::hal::ScreenConfigurationObserver {
|
||||
public:
|
||||
explicit WindowOrientationObserver(nsGlobalWindowInner* aGlobalWindow);
|
||||
~WindowOrientationObserver();
|
||||
void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration) override;
|
||||
static int16_t OrientationAngle();
|
||||
|
||||
private:
|
||||
// Weak pointer, instance is owned by mWindow.
|
||||
nsGlobalWindowInner* MOZ_NON_OWNING_REF mWindow;
|
||||
uint16_t mAngle;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_WindowOrientationObserver_h
|
||||
|
|
@ -286,7 +286,6 @@ EXPORTS.mozilla.dom += [
|
|||
"ViewportMetaData.h",
|
||||
"VisualViewport.h",
|
||||
"WindowFeatures.h",
|
||||
"WindowOrientationObserver.h",
|
||||
"WindowProxyHolder.h",
|
||||
]
|
||||
|
||||
|
|
@ -464,7 +463,6 @@ UNIFIED_SOURCES += [
|
|||
"WindowDestroyedEvent.cpp",
|
||||
"WindowFeatures.cpp",
|
||||
"WindowNamedPropertiesHandler.cpp",
|
||||
"WindowOrientationObserver.cpp",
|
||||
"XPathGenerator.cpp",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -328,10 +328,6 @@
|
|||
# include <android/log.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
# include "mozilla/dom/WindowOrientationObserver.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
# include "mozilla/Debug.h"
|
||||
# include <process.h>
|
||||
|
|
@ -904,6 +900,7 @@ class PromiseDocumentFlushedResolver final {
|
|||
nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow,
|
||||
WindowGlobalChild* aActor)
|
||||
: nsPIDOMWindowInner(aOuterWindow, aActor),
|
||||
mHasOrientationChangeListeners(false),
|
||||
mWasOffline(false),
|
||||
mHasHadSlowScript(false),
|
||||
mIsChrome(false),
|
||||
|
|
@ -949,13 +946,13 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow,
|
|||
*this, StaticPrefs::dom_timeout_max_idle_defer_ms());
|
||||
|
||||
mObserver = new nsGlobalWindowObserver(this);
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
if (nsCOMPtr<nsIObserverService> os = services::GetObserverService()) {
|
||||
// Watch for online/offline status changes so we can fire events. Use
|
||||
// a strong reference.
|
||||
os->AddObserver(mObserver, NS_IOSERVICE_OFFLINE_STATUS_TOPIC, false);
|
||||
os->AddObserver(mObserver, MEMORY_PRESSURE_OBSERVER_TOPIC, false);
|
||||
os->AddObserver(mObserver, PERMISSION_CHANGED_TOPIC, false);
|
||||
os->AddObserver(mObserver, "screen-information-changed", false);
|
||||
}
|
||||
|
||||
Preferences::AddStrongObserver(mObserver, "intl.accept_languages");
|
||||
|
|
@ -1172,10 +1169,6 @@ void nsGlobalWindowInner::FreeInnerObjects() {
|
|||
|
||||
mScreen = nullptr;
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
mOrientationChangeObserver = nullptr;
|
||||
#endif
|
||||
|
||||
if (mDoc) {
|
||||
// Remember the document's principal, URI, and CSP.
|
||||
mDocumentPrincipal = mDoc->NodePrincipal();
|
||||
|
|
@ -1247,12 +1240,16 @@ void nsGlobalWindowInner::FreeInnerObjects() {
|
|||
|
||||
DisconnectEventTargetObjects();
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
DisableOrientationChangeListener();
|
||||
#endif
|
||||
|
||||
if (mObserver) {
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
if (nsCOMPtr<nsIObserverService> os = services::GetObserverService()) {
|
||||
os->RemoveObserver(mObserver, NS_IOSERVICE_OFFLINE_STATUS_TOPIC);
|
||||
os->RemoveObserver(mObserver, MEMORY_PRESSURE_OBSERVER_TOPIC);
|
||||
os->RemoveObserver(mObserver, PERMISSION_CHANGED_TOPIC);
|
||||
os->RemoveObserver(mObserver, "screen-information-changed");
|
||||
}
|
||||
|
||||
RefPtr<StorageNotifierService> sns = StorageNotifierService::GetOrCreate();
|
||||
|
|
@ -5346,6 +5343,24 @@ nsresult nsGlobalWindowInner::Observe(nsISupports* aSubject, const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, "screen-information-changed")) {
|
||||
if (mScreen) {
|
||||
if (RefPtr<ScreenOrientation> orientation =
|
||||
mScreen->GetOrientationIfExists()) {
|
||||
orientation->MaybeChanged();
|
||||
}
|
||||
}
|
||||
if (mHasOrientationChangeListeners) {
|
||||
int32_t oldAngle = mOrientationAngle;
|
||||
mOrientationAngle = Orientation(CallerType::System);
|
||||
if (mOrientationAngle != oldAngle && IsCurrentInnerWindow()) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> outer = GetOuterWindow();
|
||||
outer->DispatchCustomEvent(u"orientationchange"_ns);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
MOZ_ASSERT(!NS_strcmp(aData, u"intl.accept_languages"));
|
||||
|
||||
|
|
@ -6444,14 +6459,14 @@ void nsGlobalWindowInner::DisableDeviceSensor(uint32_t aType) {
|
|||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
void nsGlobalWindowInner::EnableOrientationChangeListener() {
|
||||
if (!nsContentUtils::ShouldResistFingerprinting(GetDocShell()) &&
|
||||
!mOrientationChangeObserver) {
|
||||
mOrientationChangeObserver = MakeUnique<WindowOrientationObserver>(this);
|
||||
if (!nsContentUtils::ShouldResistFingerprinting(GetDocShell())) {
|
||||
mHasOrientationChangeListeners = true;
|
||||
mOrientationAngle = Orientation(CallerType::System);
|
||||
}
|
||||
}
|
||||
|
||||
void nsGlobalWindowInner::DisableOrientationChangeListener() {
|
||||
mOrientationChangeObserver = nullptr;
|
||||
mHasOrientationChangeListeners = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -7289,13 +7304,19 @@ ChromeMessageBroadcaster* nsGlobalWindowInner::GetGroupMessageManager(
|
|||
|
||||
void nsGlobalWindowInner::InitWasOffline() { mWasOffline = NS_IsOffline(); }
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
int16_t nsGlobalWindowInner::Orientation(CallerType aCallerType) const {
|
||||
return nsContentUtils::ResistFingerprinting(aCallerType)
|
||||
? 0
|
||||
: WindowOrientationObserver::OrientationAngle();
|
||||
int16_t nsGlobalWindowInner::Orientation(CallerType aCallerType) {
|
||||
// GetOrientationAngle() returns 0, 90, 180 or 270.
|
||||
// window.orientation returns -90, 0, 90 or 180.
|
||||
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
||||
return 0;
|
||||
}
|
||||
nsScreen* s = GetScreen(IgnoreErrors());
|
||||
if (!s) {
|
||||
return 0;
|
||||
}
|
||||
int16_t angle = AssertedCast<int16_t>(s->GetOrientationAngle());
|
||||
return angle <= 180 ? angle : angle - 360;
|
||||
}
|
||||
#endif
|
||||
|
||||
already_AddRefed<Console> nsGlobalWindowInner::GetConsole(JSContext* aCx,
|
||||
ErrorResult& aRv) {
|
||||
|
|
|
|||
|
|
@ -99,6 +99,10 @@ namespace mozilla {
|
|||
class AbstractThread;
|
||||
class ErrorResult;
|
||||
|
||||
namespace hal {
|
||||
enum class ScreenOrientation : uint32_t;
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
class BarProp;
|
||||
class BrowsingContext;
|
||||
|
|
@ -134,9 +138,6 @@ class VRDisplay;
|
|||
enum class VRDisplayEventReason : uint8_t;
|
||||
class VREventObserver;
|
||||
class WakeLock;
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
class WindowOrientationObserver;
|
||||
#endif
|
||||
struct WindowPostMessageOptions;
|
||||
class Worklet;
|
||||
namespace cache {
|
||||
|
|
@ -646,9 +647,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
nsDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError);
|
||||
nsDOMOfflineResourceList* GetApplicationCache() override;
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
int16_t Orientation(mozilla::dom::CallerType aCallerType) const;
|
||||
#endif
|
||||
int16_t Orientation(mozilla::dom::CallerType aCallerType);
|
||||
|
||||
already_AddRefed<mozilla::dom::Console> GetConsole(JSContext* aCx,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
|
@ -1341,6 +1340,9 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
RefPtr<mozilla::dom::ContentMediaController> mContentMediaController;
|
||||
|
||||
protected:
|
||||
// Whether we need to care about orientation changes.
|
||||
bool mHasOrientationChangeListeners : 1;
|
||||
|
||||
// Window offline status. Checked to see if we need to fire offline event
|
||||
bool mWasOffline : 1;
|
||||
|
||||
|
|
@ -1472,6 +1474,9 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
// the method that was used to focus mFocusedElement
|
||||
uint32_t mFocusMethod;
|
||||
|
||||
// Only relevant if we're listening for orientation changes.
|
||||
int16_t mOrientationAngle = 0;
|
||||
|
||||
// The current idle request callback handle
|
||||
uint32_t mIdleRequestCallbackCounter;
|
||||
IdleRequests mIdleRequestCallbacks;
|
||||
|
|
@ -1495,11 +1500,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
|
||||
nsTArray<uint32_t> mEnabledSensors;
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
mozilla::UniquePtr<mozilla::dom::WindowOrientationObserver>
|
||||
mOrientationChangeObserver;
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WEBSPEECH
|
||||
RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -50,9 +50,6 @@
|
|||
#include "mozilla/dom/WindowFeatures.h" // WindowFeatures
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
# include "mozilla/dom/WindowOrientationObserver.h"
|
||||
#endif
|
||||
#include "nsBaseCommandController.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICookieService.h"
|
||||
|
|
@ -7475,14 +7472,6 @@ ChromeMessageBroadcaster* nsGlobalWindowOuter::GetGroupMessageManager(
|
|||
|
||||
void nsGlobalWindowOuter::InitWasOffline() { mWasOffline = NS_IsOffline(); }
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
int16_t nsGlobalWindowOuter::Orientation(CallerType aCallerType) const {
|
||||
return nsContentUtils::ResistFingerprinting(aCallerType)
|
||||
? 0
|
||||
: WindowOrientationObserver::OrientationAngle();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WINDOWS_) && !defined(MOZ_WRAPPED_WINDOWS_H)
|
||||
# pragma message( \
|
||||
"wrapper failure reason: " MOZ_WINDOWS_WRAPPER_DISABLED_REASON)
|
||||
|
|
|
|||
|
|
@ -116,9 +116,6 @@ class VRDisplay;
|
|||
enum class VRDisplayEventReason : uint8_t;
|
||||
class VREventObserver;
|
||||
class WakeLock;
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
class WindowOrientationObserver;
|
||||
#endif
|
||||
class Worklet;
|
||||
namespace cache {
|
||||
class CacheStorage;
|
||||
|
|
@ -571,10 +568,6 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||
mozilla::dom::BrowsingContext** _retval) override;
|
||||
mozilla::dom::Navigator* GetNavigator() override;
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
int16_t Orientation(mozilla::dom::CallerType aCallerType) const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool AlertOrConfirm(bool aAlert, const nsAString& aMessage,
|
||||
nsIPrincipal& aSubjectPrincipal,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsTPromiseFlatString.h"
|
||||
#include "nscore.h"
|
||||
#include "prenv.h"
|
||||
|
||||
#if !defined(DEBUG) && !defined(MOZ_ENABLE_JS_DUMP)
|
||||
# include "mozilla/StaticPrefs_browser.h"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "nsLayoutUtils.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include "mozilla/widget/ScreenManager.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
|
@ -122,6 +123,24 @@ nsresult nsScreen::GetRect(nsRect& aRect) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
uint16_t nsScreen::GetOrientationAngle() const {
|
||||
// NOTE(emilio): This could be made screen-dependent with some minor effort /
|
||||
// plumbing, but this will only ever differ on Android (where there's just one
|
||||
// screen anyways).
|
||||
RefPtr<widget::Screen> s =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
return s->GetOrientationAngle();
|
||||
}
|
||||
|
||||
hal::ScreenOrientation nsScreen::GetOrientationType() const {
|
||||
// NOTE(emilio): This could be made screen-dependent with some minor effort /
|
||||
// plumbing, but this will only ever differ on android where there's just one
|
||||
// screen anyways.
|
||||
RefPtr<widget::Screen> s =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
return s->GetOrientationType();
|
||||
}
|
||||
|
||||
nsresult nsScreen::GetAvailRect(nsRect& aRect) {
|
||||
// Return window inner rect to prevent fingerprinting.
|
||||
if (ShouldResistFingerprinting()) {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,9 @@ class nsScreen : public mozilla::DOMEventTargetHelper {
|
|||
|
||||
IMPL_EVENT_HANDLER(change);
|
||||
|
||||
uint16_t GetOrientationAngle() const;
|
||||
mozilla::hal::ScreenOrientation GetOrientationType() const;
|
||||
|
||||
// Deprecated
|
||||
void GetMozOrientation(nsString& aOrientation,
|
||||
mozilla::dom::CallerType aCallerType) const;
|
||||
|
|
@ -115,6 +118,9 @@ class nsScreen : public mozilla::DOMEventTargetHelper {
|
|||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
mozilla::dom::ScreenOrientation* Orientation() const;
|
||||
mozilla::dom::ScreenOrientation* GetOrientationIfExists() const {
|
||||
return mScreenOrientation.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
nsDeviceContext* GetDeviceContext();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ using struct mozilla::void_t from "mozilla/ipc/IPCCore.h";
|
|||
using struct mozilla::dom::LoadingSessionHistoryInfo
|
||||
from "mozilla/dom/SessionHistoryEntry.h";
|
||||
|
||||
using hal::ScreenOrientation from "mozilla/HalIPCUtils.h";
|
||||
using LayoutDeviceIntRect from "Units.h";
|
||||
using DesktopIntRect from "Units.h";
|
||||
using DesktopToLayoutDeviceScale from "Units.h";
|
||||
|
|
@ -133,6 +134,8 @@ struct ScreenDetails {
|
|||
DesktopToLayoutDeviceScale contentsScaleFactor;
|
||||
CSSToLayoutDeviceScale defaultCSSScaleFactor;
|
||||
float dpi;
|
||||
ScreenOrientation orientation;
|
||||
uint16_t orientationAngle;
|
||||
};
|
||||
|
||||
struct DimensionInfo
|
||||
|
|
|
|||
30
hal/Hal.cpp
30
hal/Hal.cpp
|
|
@ -258,22 +258,6 @@ class WakeLockObserversManager final
|
|||
}
|
||||
};
|
||||
|
||||
class ScreenConfigurationObserversManager final
|
||||
: public CachingObserversManager<ScreenConfiguration> {
|
||||
protected:
|
||||
void EnableNotifications() override {
|
||||
PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
|
||||
}
|
||||
|
||||
void DisableNotifications() override {
|
||||
PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
|
||||
}
|
||||
|
||||
void GetCurrentInformationInternal(ScreenConfiguration* aInfo) override {
|
||||
PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
|
||||
}
|
||||
};
|
||||
|
||||
typedef mozilla::ObserverList<SensorData> SensorObserverList;
|
||||
StaticAutoPtr<SensorObserverList> sSensorObservers[NUM_SENSOR_TYPE];
|
||||
|
||||
|
|
@ -394,19 +378,6 @@ void NotifyWakeLockChange(const WakeLockInformation& aInfo) {
|
|||
WakeLockObservers()->BroadcastInformation(aInfo);
|
||||
}
|
||||
|
||||
MOZ_IMPL_HAL_OBSERVER(ScreenConfiguration)
|
||||
|
||||
void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) {
|
||||
*aScreenConfiguration =
|
||||
ScreenConfigurationObservers()->GetCurrentInformation();
|
||||
}
|
||||
|
||||
void NotifyScreenConfigurationChange(
|
||||
const ScreenConfiguration& aScreenConfiguration) {
|
||||
ScreenConfigurationObservers()->CacheInformation(aScreenConfiguration);
|
||||
ScreenConfigurationObservers()->BroadcastCachedInformation();
|
||||
}
|
||||
|
||||
RefPtr<mozilla::MozPromise<bool, bool, false>> LockScreenOrientation(
|
||||
const ScreenOrientation& aOrientation) {
|
||||
AssertMainThread();
|
||||
|
|
@ -469,7 +440,6 @@ void Shutdown() {
|
|||
sBatteryObservers = nullptr;
|
||||
sNetworkObservers = nullptr;
|
||||
sWakeLockObservers = nullptr;
|
||||
sScreenConfigurationObservers = nullptr;
|
||||
|
||||
for (auto& sensorObserver : sSensorObservers) {
|
||||
sensorObserver = nullptr;
|
||||
|
|
|
|||
17
hal/Hal.h
17
hal/Hal.h
|
|
@ -11,9 +11,9 @@
|
|||
#include "base/platform_thread.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/hal_sandbox/PHal.h"
|
||||
#include "mozilla/HalScreenConfiguration.h"
|
||||
#include "mozilla/HalBatteryInformation.h"
|
||||
#include "mozilla/HalNetworkInformation.h"
|
||||
#include "mozilla/HalScreenConfiguration.h"
|
||||
#include "mozilla/HalWakeLockInformation.h"
|
||||
#include "mozilla/HalTypes.h"
|
||||
#include "mozilla/Types.h"
|
||||
|
|
@ -216,21 +216,6 @@ void GetWakeLockInfo(const nsAString& aTopic,
|
|||
*/
|
||||
void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
|
||||
|
||||
MOZ_DEFINE_HAL_OBSERVER(ScreenConfiguration);
|
||||
|
||||
/**
|
||||
* Returns the current screen configuration.
|
||||
*/
|
||||
void GetCurrentScreenConfiguration(
|
||||
hal::ScreenConfiguration* aScreenConfiguration);
|
||||
|
||||
/**
|
||||
* Notify of a change in the screen configuration.
|
||||
* @param aScreenConfiguration The new screen orientation.
|
||||
*/
|
||||
void NotifyScreenConfigurationChange(
|
||||
const hal::ScreenConfiguration& aScreenConfiguration);
|
||||
|
||||
/**
|
||||
* Lock the screen orientation to the specific orientation.
|
||||
* @return A promise indicating that the screen orientation has been locked.
|
||||
|
|
|
|||
|
|
@ -29,9 +29,6 @@ constexpr auto kAllScreenOrientationBits = ScreenOrientation((1 << 5) - 1);
|
|||
|
||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ScreenOrientation);
|
||||
|
||||
class ScreenConfiguration;
|
||||
using ScreenConfigurationObserver = Observer<ScreenConfiguration>;
|
||||
|
||||
} // namespace mozilla::hal
|
||||
|
||||
#endif // mozilla_HalScreenConfiguration_h
|
||||
|
|
|
|||
|
|
@ -77,28 +77,6 @@ void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo) {
|
|||
AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo);
|
||||
}
|
||||
|
||||
void EnableScreenConfigurationNotifications() {
|
||||
java::GeckoAppShell::EnableScreenOrientationNotifications();
|
||||
}
|
||||
|
||||
void DisableScreenConfigurationNotifications() {
|
||||
java::GeckoAppShell::DisableScreenOrientationNotifications();
|
||||
}
|
||||
|
||||
void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) {
|
||||
AndroidBridge* bridge = AndroidBridge::Bridge();
|
||||
if (!bridge) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<widget::Screen> screen =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
*aScreenConfiguration = screen->ToScreenConfiguration();
|
||||
aScreenConfiguration->orientation() =
|
||||
static_cast<hal::ScreenOrientation>(bridge->GetScreenOrientation());
|
||||
aScreenConfiguration->angle() = bridge->GetScreenAngle();
|
||||
}
|
||||
|
||||
static bool IsSupportedScreenOrientation(hal::ScreenOrientation aOrientation) {
|
||||
// The Android backend only supports these orientations.
|
||||
static constexpr ScreenOrientation kSupportedOrientations[] = {
|
||||
|
|
|
|||
|
|
@ -2,19 +2,9 @@
|
|||
* 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 "FallbackScreenConfiguration.h"
|
||||
#include "Hal.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
void EnableScreenConfigurationNotifications() {}
|
||||
|
||||
void DisableScreenConfigurationNotifications() {}
|
||||
|
||||
void GetCurrentScreenConfiguration(
|
||||
hal::ScreenConfiguration* aScreenConfiguration) {
|
||||
fallback::GetCurrentScreenConfiguration(aScreenConfiguration);
|
||||
}
|
||||
namespace mozilla::hal_impl {
|
||||
|
||||
RefPtr<mozilla::MozPromise<bool, bool, false>> LockScreenOrientation(
|
||||
const hal::ScreenOrientation& aOrientation) {
|
||||
|
|
@ -24,5 +14,4 @@ RefPtr<mozilla::MozPromise<bool, bool, false>> LockScreenOrientation(
|
|||
|
||||
void UnlockScreenOrientation() {}
|
||||
|
||||
} // namespace hal_impl
|
||||
} // namespace mozilla
|
||||
} // namespace mozilla::hal_impl
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
/* 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_fallback_FallbackScreenConfiguration_h
|
||||
#define mozilla_fallback_FallbackScreenConfiguration_h
|
||||
|
||||
#include "Hal.h"
|
||||
#include "mozilla/widget/ScreenManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace fallback {
|
||||
|
||||
inline void GetCurrentScreenConfiguration(
|
||||
hal::ScreenConfiguration* aScreenConfiguration) {
|
||||
RefPtr<widget::Screen> screen =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
|
||||
*aScreenConfiguration = screen->ToScreenConfiguration();
|
||||
aScreenConfiguration->orientation() =
|
||||
aScreenConfiguration->rect().Width() >=
|
||||
aScreenConfiguration->rect().Height()
|
||||
? hal::ScreenOrientation::LandscapePrimary
|
||||
: hal::ScreenOrientation::PortraitPrimary;
|
||||
}
|
||||
|
||||
} // namespace fallback
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_fallback_FallbackScreenConfiguration_h
|
||||
|
|
@ -21,10 +21,6 @@ EXPORTS.mozilla += [
|
|||
"HalWakeLockInformation.h",
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.fallback += [
|
||||
"fallback/FallbackScreenConfiguration.h",
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"HalWakeLock.cpp",
|
||||
"sandbox/SandboxHal.cpp",
|
||||
|
|
|
|||
|
|
@ -45,14 +45,6 @@ struct WakeLockInformation {
|
|||
uint64_t[] lockingProcesses;
|
||||
};
|
||||
|
||||
struct ScreenConfiguration {
|
||||
nsIntRect rect;
|
||||
ScreenOrientation orientation;
|
||||
uint16_t angle;
|
||||
uint32_t colorDepth;
|
||||
uint32_t pixelDepth;
|
||||
};
|
||||
|
||||
} // namespace hal
|
||||
|
||||
namespace hal_sandbox {
|
||||
|
|
@ -65,7 +57,6 @@ child:
|
|||
async NotifyBatteryChange(BatteryInformation aBatteryInfo);
|
||||
async NotifyNetworkChange(NetworkInformation aNetworkInfo);
|
||||
async NotifyWakeLockChange(WakeLockInformation aWakeLockInfo);
|
||||
async NotifyScreenConfigurationChange(ScreenConfiguration aScreenOrientation);
|
||||
|
||||
parent:
|
||||
async Vibrate(uint32_t[] pattern, uint64_t[] id, PBrowser browser);
|
||||
|
|
@ -90,8 +81,6 @@ parent:
|
|||
sync GetWakeLockInfo(nsString aTopic)
|
||||
returns (WakeLockInformation aWakeLockInfo);
|
||||
|
||||
async EnableScreenConfigurationNotifications();
|
||||
async DisableScreenConfigurationNotifications();
|
||||
async LockScreenOrientation(ScreenOrientation aOrientation)
|
||||
returns (bool allowed);
|
||||
async UnlockScreenOrientation();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include "mozilla/hal_sandbox/PHalParent.h"
|
||||
#include "mozilla/dom/BrowserParent.h"
|
||||
#include "mozilla/dom/BrowserChild.h"
|
||||
#include "mozilla/fallback/FallbackScreenConfiguration.h"
|
||||
#include "mozilla/EnumeratedRange.h"
|
||||
#include "mozilla/Observer.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
|
@ -70,18 +69,6 @@ void GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) {
|
|||
Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
|
||||
}
|
||||
|
||||
void EnableScreenConfigurationNotifications() {
|
||||
Hal()->SendEnableScreenConfigurationNotifications();
|
||||
}
|
||||
|
||||
void DisableScreenConfigurationNotifications() {
|
||||
Hal()->SendDisableScreenConfigurationNotifications();
|
||||
}
|
||||
|
||||
void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) {
|
||||
fallback::GetCurrentScreenConfiguration(aScreenConfiguration);
|
||||
}
|
||||
|
||||
RefPtr<mozilla::MozPromise<bool, bool, false>> LockScreenOrientation(
|
||||
const hal::ScreenOrientation& aOrientation) {
|
||||
return Hal()
|
||||
|
|
@ -147,15 +134,13 @@ class HalParent : public PHalParent,
|
|||
public BatteryObserver,
|
||||
public NetworkObserver,
|
||||
public ISensorObserver,
|
||||
public WakeLockObserver,
|
||||
public ScreenConfigurationObserver {
|
||||
public WakeLockObserver {
|
||||
public:
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override {
|
||||
// NB: you *must* unconditionally unregister your observer here,
|
||||
// if it *may* be registered below.
|
||||
hal::UnregisterBatteryObserver(this);
|
||||
hal::UnregisterNetworkObserver(this);
|
||||
hal::UnregisterScreenConfigurationObserver(this);
|
||||
for (auto sensor : MakeEnumeratedRange(NUM_SENSOR_TYPE)) {
|
||||
hal::UnregisterSensorObserver(sensor, this);
|
||||
}
|
||||
|
|
@ -229,20 +214,6 @@ class HalParent : public PHalParent,
|
|||
Unused << SendNotifyNetworkChange(aNetworkInfo);
|
||||
}
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvEnableScreenConfigurationNotifications()
|
||||
override {
|
||||
// Screen configuration is used to implement CSS and DOM
|
||||
// properties, so all content already has access to this.
|
||||
hal::RegisterScreenConfigurationObserver(this);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvDisableScreenConfigurationNotifications()
|
||||
override {
|
||||
hal::UnregisterScreenConfigurationObserver(this);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvLockScreenOrientation(
|
||||
const ScreenOrientation& aOrientation,
|
||||
LockScreenOrientationResolver&& aResolve) override {
|
||||
|
|
@ -269,10 +240,6 @@ class HalParent : public PHalParent,
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
void Notify(const ScreenConfiguration& aScreenConfiguration) override {
|
||||
Unused << SendNotifyScreenConfigurationChange(aScreenConfiguration);
|
||||
}
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvEnableSensorNotifications(
|
||||
const SensorType& aSensor) override {
|
||||
// We currently allow any content to register device-sensor
|
||||
|
|
@ -350,12 +317,6 @@ class HalChild : public PHalChild {
|
|||
hal::NotifyWakeLockChange(aWakeLockInfo);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvNotifyScreenConfigurationChange(
|
||||
const ScreenConfiguration& aScreenConfiguration) override {
|
||||
hal::NotifyScreenConfigurationChange(aScreenConfiguration);
|
||||
return IPC_OK();
|
||||
}
|
||||
};
|
||||
|
||||
mozilla::ipc::IPCResult HalChild::RecvNotifySensorChange(
|
||||
|
|
|
|||
|
|
@ -1205,16 +1205,6 @@ public class GeckoAppShell {
|
|||
return GeckoScreenOrientation.getInstance().getAngle();
|
||||
}
|
||||
|
||||
@WrapForJNI(calledFrom = "gecko")
|
||||
private static void enableScreenOrientationNotifications() {
|
||||
GeckoScreenOrientation.getInstance().enableNotifications();
|
||||
}
|
||||
|
||||
@WrapForJNI(calledFrom = "gecko")
|
||||
private static void disableScreenOrientationNotifications() {
|
||||
GeckoScreenOrientation.getInstance().disableNotifications();
|
||||
}
|
||||
|
||||
@WrapForJNI(calledFrom = "gecko")
|
||||
private static void notifyWakeLockChanged(final String topic, final String state) {
|
||||
final int intState;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import android.view.Surface;
|
|||
import android.view.WindowManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
/*
|
||||
|
|
@ -69,8 +68,6 @@ public class GeckoScreenOrientation {
|
|||
private static final int DEFAULT_ROTATION = Surface.ROTATION_0;
|
||||
// Last updated screen orientation with Gecko value space.
|
||||
private ScreenOrientation mScreenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
|
||||
// Whether the update should notify Gecko about screen orientation changes.
|
||||
private boolean mShouldNotify = true;
|
||||
|
||||
public interface OrientationChangeListener {
|
||||
void onScreenOrientationChanged(ScreenOrientation newOrientation);
|
||||
|
|
@ -102,23 +99,6 @@ public class GeckoScreenOrientation {
|
|||
mListeners.remove(aListener);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable Gecko screen orientation events on update.
|
||||
*/
|
||||
public void enableNotifications() {
|
||||
// We should notify Gecko of current orientation information at force.
|
||||
mScreenOrientation = ScreenOrientation.NONE;
|
||||
mShouldNotify = true;
|
||||
update();
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable Gecko screen orientation events on update.
|
||||
*/
|
||||
public void disableNotifications() {
|
||||
mShouldNotify = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update screen orientation.
|
||||
* Retrieve orientation and rotation via GeckoAppShell.
|
||||
|
|
@ -161,9 +141,6 @@ public class GeckoScreenOrientation {
|
|||
return update(getScreenOrientation(aAndroidOrientation, getRotation()));
|
||||
}
|
||||
|
||||
@WrapForJNI(dispatchTo = "gecko")
|
||||
private static native void onOrientationChange(short screenOrientation, short angle);
|
||||
|
||||
/*
|
||||
* Update screen orientation given the screen orientation.
|
||||
*
|
||||
|
|
@ -193,21 +170,6 @@ public class GeckoScreenOrientation {
|
|||
mScreenOrientation = screenOrientation;
|
||||
Log.d(LOGTAG, "updating to new orientation " + mScreenOrientation);
|
||||
notifyListeners(mScreenOrientation);
|
||||
if (mShouldNotify) {
|
||||
if (aScreenOrientation == ScreenOrientation.NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GeckoThread.isRunning()) {
|
||||
onOrientationChange(screenOrientation.value, getAngle());
|
||||
} else {
|
||||
GeckoThread.queueNativeCall(
|
||||
GeckoScreenOrientation.class,
|
||||
"onOrientationChange",
|
||||
screenOrientation.value,
|
||||
getAngle());
|
||||
}
|
||||
}
|
||||
ScreenManagerHelper.refreshScreenInfo();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,15 +10,26 @@
|
|||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/StaticPrefs_layout.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace widget {
|
||||
namespace mozilla::widget {
|
||||
|
||||
NS_IMPL_ISUPPORTS(Screen, nsIScreen)
|
||||
|
||||
static hal::ScreenOrientation EffectiveOrientation(
|
||||
hal::ScreenOrientation aOrientation, const LayoutDeviceIntRect& aRect) {
|
||||
if (aOrientation == hal::ScreenOrientation::None) {
|
||||
return aRect.Width() >= aRect.Height()
|
||||
? hal::ScreenOrientation::LandscapePrimary
|
||||
: hal::ScreenOrientation::PortraitPrimary;
|
||||
}
|
||||
return aOrientation;
|
||||
}
|
||||
|
||||
Screen::Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
|
||||
uint32_t aPixelDepth, uint32_t aColorDepth,
|
||||
DesktopToLayoutDeviceScale aContentsScale,
|
||||
CSSToLayoutDeviceScale aDefaultCssScale, float aDPI)
|
||||
CSSToLayoutDeviceScale aDefaultCssScale, float aDPI,
|
||||
hal::ScreenOrientation aOrientation,
|
||||
OrientationAngle aOrientationAngle)
|
||||
: mRect(aRect),
|
||||
mAvailRect(aAvailRect),
|
||||
mRectDisplayPix(RoundedToInt(aRect / aContentsScale)),
|
||||
|
|
@ -27,9 +38,11 @@ Screen::Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
|
|||
mColorDepth(aColorDepth),
|
||||
mContentsScale(aContentsScale),
|
||||
mDefaultCssScale(aDefaultCssScale),
|
||||
mDPI(aDPI) {}
|
||||
mDPI(aDPI),
|
||||
mScreenOrientation(EffectiveOrientation(aOrientation, aRect)),
|
||||
mOrientationAngle(aOrientationAngle) {}
|
||||
|
||||
Screen::Screen(const mozilla::dom::ScreenDetails& aScreen)
|
||||
Screen::Screen(const dom::ScreenDetails& aScreen)
|
||||
: mRect(aScreen.rect()),
|
||||
mAvailRect(aScreen.availRect()),
|
||||
mRectDisplayPix(aScreen.rectDisplayPix()),
|
||||
|
|
@ -38,7 +51,9 @@ Screen::Screen(const mozilla::dom::ScreenDetails& aScreen)
|
|||
mColorDepth(aScreen.colorDepth()),
|
||||
mContentsScale(aScreen.contentsScaleFactor()),
|
||||
mDefaultCssScale(aScreen.defaultCSSScaleFactor()),
|
||||
mDPI(aScreen.dpi()) {}
|
||||
mDPI(aScreen.dpi()),
|
||||
mScreenOrientation(aScreen.orientation()),
|
||||
mOrientationAngle(aScreen.orientationAngle()) {}
|
||||
|
||||
Screen::Screen(const Screen& aOther)
|
||||
: mRect(aOther.mRect),
|
||||
|
|
@ -49,18 +64,15 @@ Screen::Screen(const Screen& aOther)
|
|||
mColorDepth(aOther.mColorDepth),
|
||||
mContentsScale(aOther.mContentsScale),
|
||||
mDefaultCssScale(aOther.mDefaultCssScale),
|
||||
mDPI(aOther.mDPI) {}
|
||||
mDPI(aOther.mDPI),
|
||||
mScreenOrientation(aOther.mScreenOrientation),
|
||||
mOrientationAngle(aOther.mOrientationAngle) {}
|
||||
|
||||
mozilla::dom::ScreenDetails Screen::ToScreenDetails() {
|
||||
return mozilla::dom::ScreenDetails(
|
||||
mRect, mRectDisplayPix, mAvailRect, mAvailRectDisplayPix, mPixelDepth,
|
||||
mColorDepth, mContentsScale, mDefaultCssScale, mDPI);
|
||||
}
|
||||
|
||||
mozilla::hal::ScreenConfiguration Screen::ToScreenConfiguration() {
|
||||
return mozilla::hal::ScreenConfiguration(
|
||||
nsIntRect(mRect.x, mRect.y, mRect.width, mRect.height),
|
||||
hal::ScreenOrientation::None, 0, mColorDepth, mPixelDepth);
|
||||
dom::ScreenDetails Screen::ToScreenDetails() const {
|
||||
return dom::ScreenDetails(mRect, mRectDisplayPix, mAvailRect,
|
||||
mAvailRectDisplayPix, mPixelDepth, mColorDepth,
|
||||
mContentsScale, mDefaultCssScale, mDPI,
|
||||
mScreenOrientation, mOrientationAngle);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
@ -126,5 +138,4 @@ Screen::GetDpi(float* aDPI) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
} // namespace mozilla::widget
|
||||
|
|
|
|||
|
|
@ -10,17 +10,13 @@
|
|||
#include "nsIScreen.h"
|
||||
|
||||
#include "Units.h"
|
||||
#include "mozilla/HalScreenConfiguration.h" // For hal::ScreenOrientation
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class ScreenDetails;
|
||||
} // namespace dom
|
||||
namespace hal {
|
||||
class ScreenConfiguration;
|
||||
}
|
||||
} // namespace mozilla
|
||||
|
||||
namespace mozilla {
|
||||
namespace widget {
|
||||
|
||||
class Screen final : public nsIScreen {
|
||||
|
|
@ -28,32 +24,38 @@ class Screen final : public nsIScreen {
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
|
||||
using OrientationAngle = uint16_t;
|
||||
|
||||
Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
|
||||
uint32_t aPixelDepth, uint32_t aColorDepth,
|
||||
DesktopToLayoutDeviceScale aContentsScale,
|
||||
CSSToLayoutDeviceScale aDefaultCssScale, float dpi);
|
||||
explicit Screen(const mozilla::dom::ScreenDetails& aScreenDetails);
|
||||
CSSToLayoutDeviceScale aDefaultCssScale, float aDpi,
|
||||
hal::ScreenOrientation = hal::ScreenOrientation::None,
|
||||
OrientationAngle = 0);
|
||||
explicit Screen(const dom::ScreenDetails& aScreenDetails);
|
||||
Screen(const Screen& aOther);
|
||||
|
||||
mozilla::dom::ScreenDetails ToScreenDetails();
|
||||
dom::ScreenDetails ToScreenDetails() const;
|
||||
|
||||
// Convert to hal's ScreenConfiguration.
|
||||
// NOTE: Since Screen doesn't have orientation and angle information,
|
||||
// these can't be set.
|
||||
mozilla::hal::ScreenConfiguration ToScreenConfiguration();
|
||||
OrientationAngle GetOrientationAngle() const { return mOrientationAngle; }
|
||||
hal::ScreenOrientation GetOrientationType() const {
|
||||
return mScreenOrientation;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~Screen() = default;
|
||||
|
||||
LayoutDeviceIntRect mRect;
|
||||
LayoutDeviceIntRect mAvailRect;
|
||||
DesktopIntRect mRectDisplayPix;
|
||||
DesktopIntRect mAvailRectDisplayPix;
|
||||
uint32_t mPixelDepth;
|
||||
uint32_t mColorDepth;
|
||||
DesktopToLayoutDeviceScale mContentsScale;
|
||||
CSSToLayoutDeviceScale mDefaultCssScale;
|
||||
float mDPI;
|
||||
const LayoutDeviceIntRect mRect;
|
||||
const LayoutDeviceIntRect mAvailRect;
|
||||
const DesktopIntRect mRectDisplayPix;
|
||||
const DesktopIntRect mAvailRectDisplayPix;
|
||||
const uint32_t mPixelDepth;
|
||||
const uint32_t mColorDepth;
|
||||
const DesktopToLayoutDeviceScale mContentsScale;
|
||||
const CSSToLayoutDeviceScale mDefaultCssScale;
|
||||
const float mDPI;
|
||||
const hal::ScreenOrientation mScreenOrientation;
|
||||
const OrientationAngle mOrientationAngle;
|
||||
};
|
||||
|
||||
} // namespace widget
|
||||
|
|
|
|||
|
|
@ -51,26 +51,27 @@ void ScreenManager::Refresh(nsTArray<RefPtr<Screen>>&& aScreens) {
|
|||
// GetSingleton returns invalid data since it is freed.
|
||||
return;
|
||||
}
|
||||
GetSingleton().RefreshInternal(std::move(aScreens));
|
||||
}
|
||||
|
||||
void ScreenManager::RefreshInternal(nsTArray<RefPtr<Screen>>&& aScreens) {
|
||||
MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refresh screens"));
|
||||
|
||||
mScreenList = std::move(aScreens);
|
||||
|
||||
CopyScreensToAllRemotesIfIsParent();
|
||||
GetSingleton().RefreshInternal(std::move(aScreens));
|
||||
}
|
||||
|
||||
void ScreenManager::Refresh(nsTArray<mozilla::dom::ScreenDetails>&& aScreens) {
|
||||
MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refresh screens from IPC"));
|
||||
|
||||
mScreenList.Clear();
|
||||
AutoTArray<RefPtr<Screen>, 4> screens;
|
||||
for (auto& screen : aScreens) {
|
||||
mScreenList.AppendElement(new Screen(screen));
|
||||
screens.AppendElement(new Screen(screen));
|
||||
}
|
||||
RefreshInternal(std::move(screens));
|
||||
}
|
||||
|
||||
void ScreenManager::RefreshInternal(nsTArray<RefPtr<Screen>>&& aScreens) {
|
||||
mScreenList = std::move(aScreens);
|
||||
|
||||
CopyScreensToAllRemotesIfIsParent();
|
||||
if (nsCOMPtr<nsIObserverService> s = services::GetObserverService()) {
|
||||
s->NotifyObservers(nullptr, "screen-information-changed", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Range>
|
||||
|
|
@ -127,10 +128,11 @@ ScreenManager::ScreenForRect(int32_t aX, int32_t aY, int32_t aWidth,
|
|||
if (mScreenList.IsEmpty()) {
|
||||
MOZ_LOG(sScreenLog, LogLevel::Warning,
|
||||
("No screen available. This can happen in xpcshell."));
|
||||
RefPtr<Screen> ret = new Screen(
|
||||
auto screen = MakeRefPtr<Screen>(
|
||||
LayoutDeviceIntRect(), LayoutDeviceIntRect(), 0, 0,
|
||||
DesktopToLayoutDeviceScale(), CSSToLayoutDeviceScale(), 96 /* dpi */);
|
||||
ret.forget(aOutScreen);
|
||||
DesktopToLayoutDeviceScale(), CSSToLayoutDeviceScale(), 96 /* dpi */,
|
||||
hal::ScreenOrientation::None, 0);
|
||||
screen.forget(aOutScreen);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -213,14 +215,13 @@ already_AddRefed<Screen> ScreenManager::GetPrimaryScreen() {
|
|||
if (mScreenList.IsEmpty()) {
|
||||
MOZ_LOG(sScreenLog, LogLevel::Warning,
|
||||
("No screen available. This can happen in xpcshell."));
|
||||
RefPtr<Screen> ret = new Screen(
|
||||
LayoutDeviceIntRect(), LayoutDeviceIntRect(), 0, 0,
|
||||
DesktopToLayoutDeviceScale(), CSSToLayoutDeviceScale(), 96 /* dpi */);
|
||||
return ret.forget();
|
||||
return MakeAndAddRef<Screen>(LayoutDeviceIntRect(), LayoutDeviceIntRect(),
|
||||
0, 0, DesktopToLayoutDeviceScale(),
|
||||
CSSToLayoutDeviceScale(), 96 /* dpi */,
|
||||
hal::ScreenOrientation::None, 0);
|
||||
}
|
||||
|
||||
RefPtr<Screen> ret = mScreenList[0];
|
||||
return ret.forget();
|
||||
return do_AddRef(mScreenList[0]);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* 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 GeckoScreenOrientation_h
|
||||
#define GeckoScreenOrientation_h
|
||||
|
||||
#include "nsAppShell.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/java/GeckoScreenOrientationNatives.h"
|
||||
#include "mozilla/widget/ScreenManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class GeckoScreenOrientation final
|
||||
: public java::GeckoScreenOrientation::Natives<GeckoScreenOrientation> {
|
||||
GeckoScreenOrientation() = delete;
|
||||
|
||||
public:
|
||||
static void OnOrientationChange(int16_t aOrientation, int16_t aAngle) {
|
||||
RefPtr<widget::Screen> screen =
|
||||
widget::ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||
hal::ScreenConfiguration screenConfiguration =
|
||||
screen->ToScreenConfiguration();
|
||||
screenConfiguration.orientation() =
|
||||
static_cast<hal::ScreenOrientation>(aOrientation);
|
||||
screenConfiguration.angle() = aAngle;
|
||||
|
||||
hal::NotifyScreenConfigurationChange(screenConfiguration);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GeckoScreenOrientation_h
|
||||
|
|
@ -36,10 +36,12 @@ static already_AddRefed<Screen> MakePrimaryScreen() {
|
|||
uint32_t depth = java::GeckoAppShell::GetScreenDepth();
|
||||
float density = java::GeckoAppShell::GetDensity();
|
||||
float dpi = java::GeckoAppShell::GetDpi();
|
||||
RefPtr<Screen> screen = new Screen(bounds, bounds, depth, depth,
|
||||
DesktopToLayoutDeviceScale(density),
|
||||
CSSToLayoutDeviceScale(1.0f), dpi);
|
||||
return screen.forget();
|
||||
auto orientation =
|
||||
hal::ScreenOrientation(java::GeckoAppShell::GetScreenOrientation());
|
||||
uint16_t angle = java::GeckoAppShell::GetScreenAngle();
|
||||
return MakeAndAddRef<Screen>(
|
||||
bounds, bounds, depth, depth, DesktopToLayoutDeviceScale(density),
|
||||
CSSToLayoutDeviceScale(1.0f), dpi, orientation, angle);
|
||||
}
|
||||
|
||||
ScreenHelperAndroid::ScreenHelperAndroid() {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ classes_with_WrapForJNI = [
|
|||
"GeckoProcessType",
|
||||
"GeckoResult",
|
||||
"GeckoRuntime",
|
||||
"GeckoScreenOrientation",
|
||||
"GeckoServiceChildProcess",
|
||||
"GeckoServiceGpuProcess",
|
||||
"GeckoSession",
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@
|
|||
#include "GeckoEditableSupport.h"
|
||||
#include "GeckoNetworkManager.h"
|
||||
#include "GeckoProcessManager.h"
|
||||
#include "GeckoScreenOrientation.h"
|
||||
#include "GeckoSystemStateListener.h"
|
||||
#include "GeckoTelemetryDelegate.h"
|
||||
#include "GeckoVRManager.h"
|
||||
|
|
@ -428,7 +427,6 @@ nsAppShell::nsAppShell()
|
|||
mozilla::GeckoBatteryManager::Init();
|
||||
mozilla::GeckoNetworkManager::Init();
|
||||
mozilla::GeckoProcessManager::Init();
|
||||
mozilla::GeckoScreenOrientation::Init();
|
||||
mozilla::GeckoSystemStateListener::Init();
|
||||
mozilla::widget::Telemetry::Init();
|
||||
mozilla::widget::ImageDecoderSupport::Init();
|
||||
|
|
|
|||
|
|
@ -191,9 +191,8 @@ static already_AddRefed<Screen> MakeScreenGtk(GdkScreen* aScreen,
|
|||
"DPI %f ]",
|
||||
aMonitorNum, rect.x, rect.y, rect.width, rect.height, pixelDepth,
|
||||
contentsScale.scale, defaultCssScale.scale, dpi));
|
||||
RefPtr<Screen> screen = new Screen(rect, availRect, pixelDepth, pixelDepth,
|
||||
contentsScale, defaultCssScale, dpi);
|
||||
return screen.forget();
|
||||
return MakeAndAddRef<Screen>(rect, availRect, pixelDepth, pixelDepth,
|
||||
contentsScale, defaultCssScale, dpi);
|
||||
}
|
||||
|
||||
void ScreenGetterGtk::RefreshScreens() {
|
||||
|
|
@ -353,9 +352,8 @@ already_AddRefed<Screen> ScreenGetterWayland::MakeScreenWayland(gint aMonitor) {
|
|||
"DPI %f]",
|
||||
aMonitor, rect.x, rect.y, rect.width, rect.height, pixelDepth,
|
||||
contentsScale.scale, defaultCssScale.scale, dpi));
|
||||
RefPtr<Screen> screen = new Screen(rect, rect, pixelDepth, pixelDepth,
|
||||
contentsScale, defaultCssScale, dpi);
|
||||
return screen.forget();
|
||||
return MakeAndAddRef<Screen>(rect, rect, pixelDepth, pixelDepth,
|
||||
contentsScale, defaultCssScale, dpi);
|
||||
}
|
||||
|
||||
void ScreenGetterWayland::RefreshScreens() {
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ LayoutDeviceIntRect HeadlessScreenHelper::GetScreenRect() {
|
|||
HeadlessScreenHelper::HeadlessScreenHelper() {
|
||||
AutoTArray<RefPtr<Screen>, 1> screenList;
|
||||
LayoutDeviceIntRect rect = GetScreenRect();
|
||||
RefPtr<Screen> ret =
|
||||
new Screen(rect, rect, 24, 24, DesktopToLayoutDeviceScale(),
|
||||
CSSToLayoutDeviceScale(), 96.0f);
|
||||
auto ret =
|
||||
MakeRefPtr<Screen>(rect, rect, 24, 24, DesktopToLayoutDeviceScale(),
|
||||
CSSToLayoutDeviceScale(), 96.0f);
|
||||
screenList.AppendElement(ret.forget());
|
||||
ScreenManager::Refresh(std::move(screenList));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue