Bug 1757431 - Update orientation lock information in browsing context when exiting full screen. r=smaug

Orientation lock allows on full screen state only now. Then if exiting full
screen, orientation lock is unlocked without `screen.orientation.unlock` call.

Although we store orientation lock state in browsing context, we don't clear
when exiting full screen. So when current content is re-activated by switching
tab etc, we try to apply orientation lock state from browsing context
unfortunately.

So we should clear this state when exiting full screen even if `unlock` isn't
called.

Differential Revision: https://phabricator.services.mozilla.com/D142938
This commit is contained in:
Makoto Kato 2022-04-11 04:11:22 +00:00
parent 81292d59a9
commit cf9e71c1d9
5 changed files with 89 additions and 0 deletions

View File

@ -702,6 +702,12 @@ ScreenOrientation::FullscreenEventListener::HandleEvent(Event* aEvent) {
return NS_OK;
}
BrowsingContext* bc = doc->GetBrowsingContext();
bc = bc ? bc->Top() : nullptr;
if (bc) {
bc->SetOrientationLock(hal::ScreenOrientation::None, IgnoreErrors());
}
hal::UnlockScreenOrientation();
target->RemoveSystemEventListener(u"fullscreenchange"_ns, this, true);

View File

@ -4760,3 +4760,22 @@ nsDOMWindowUtils::GetHasScrollLinkedEffect(bool* aResult) {
*aResult = doc->HasScrollLinkedEffect();
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetOrientationLock(uint32_t* aOrientationLock) {
NS_WARNING("nsDOMWindowUtils::GetOrientationLock");
nsIDocShell* docShell = GetDocShell();
if (!docShell) {
return NS_ERROR_FAILURE;
}
BrowsingContext* bc = docShell->GetBrowsingContext();
bc = bc ? bc->Top() : nullptr;
if (!bc) {
return NS_ERROR_FAILURE;
}
*aOrientationLock = static_cast<uint32_t>(bc->GetOrientationLock());
return NS_OK;
}

View File

@ -704,6 +704,8 @@ skip-if = !e10s # Track Bug 1281415
[test_link_stylesheet.html]
[test_location_href_unknown_protocol.html]
support-files = file_location_href_unknown_protocol.html
[test_lock_orientation_after_fullscreen.html]
skip-if = toolkit != 'android' # Only run on Android.
[test_meta_refresh_referrer.html]
[test_mozMatchesSelector.html]
[test_mutationobserver_anonymous.html]

View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1757431
-->
<head>
<title>Test for Bug 1757431</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1757431">Mozilla Bug 1757431</a>
<div id="fullscreen">fullscreen</div>
<script>
add_task(async () => {
await SpecialPowers.pushPrefEnv({
set: [["dom.screenorientation.allow-lock", true]]
});
const element = document.getElementById("fullscreen");
await SpecialPowers.wrap(element).requestFullscreen();
let newOrientationLock = SpecialPowers.getDOMWindowUtils(window).orientationLock;
ok(document.fullscreen, "Document should be in fullscreen");
is(newOrientationLock, 0, "Orientation lock in browsing context should be none by enterFullscreen");
const originalOrientationType = window.screen.orientation.type;
const newOrientationType = originalOrientationType.startsWith("landscape") ? "portrait-primary" : "landscape-primary";
await window.screen.orientation.lock(newOrientationType);
newOrientationLock = SpecialPowers.getDOMWindowUtils(window).orientationLock;
if (newOrientationType == "portrait-primary") {
is(newOrientationLock, 1, "Orientation lock in browsing context should be portrait-primary");
} else {
is(newOrientationLock, 4, "Orientation lock in browsing context should be landscape-primary");
}
await window.screen.orientation.lock(originalOrientationType);
newOrientationLock = SpecialPowers.getDOMWindowUtils(window).orientationLock;
if (originalOrientationType == "portrait-primary") {
is(newOrientationLock, 1, "Orientation lock in browsing context should be portrait-primary");
} else {
is(newOrientationLock, 4, "Orientation lock in browsing context should be landscape-primary");
}
await document.exitFullscreen();
// Wait fullscreen change in ScreenOrientation
await new Promise(r =>
window.requestAnimationFrame(() => window.requestAnimationFrame(r))
);
newOrientationLock = SpecialPowers.getDOMWindowUtils(window).orientationLock;
is(newOrientationLock, 0, "Orientation lock in browsing context should be none by exitFullscreen");
});
</script>
</body>
</html>

View File

@ -2270,6 +2270,10 @@ interface nsIDOMWindowUtils : nsISupports {
// See https://firefox-source-docs.mozilla.org/performance/scroll-linked_effects.html
// about scroll-linked effects.
readonly attribute bool hasScrollLinkedEffect;
// Returns the current orientation lock value in browsing context.
// This value is defined in hal/HalScreenConfiguration.h
readonly attribute uint32_t orientationLock;
};
[scriptable, uuid(c694e359-7227-4392-a138-33c0cc1f15a6)]