Skip to content

Commit

Permalink
Bug 1757031 - Don't restore previous viewport when window size isn't …
Browse files Browse the repository at this point in the history
…same. r=emilio

Fenix's Picture-In-Picture uses full screen mode. So it isn't same as Firefox
Desktop. When exiting full screen, Fenix's window may not same as before
entering full screen.

When this occurs,

1. When device is portrait orientation, user changes to full screen by content
   script.
2. Fenix enters to full screen then orientation is changed to landscape.
3. User changes that device is changed to landscape by hand.
4. Fenix enters PiP mode. Android (Home screen) change to portrait orientation.
   Then PiP window keeps landscape orientation.
5. When exiting PiP, full screen will be exited.
6. Device is landscape (by Step 3.), so Fenix window is landscape. But Gecko
   restores 1.'s viewport by `nsIDOMWindowUtils.exitFullScreen`. So viewport
   becomes portrait orientation size even if window is landscape orientation.

For PiP mode, although nsIDOMWindowUtils.exitFullScreen is used, it doesn't
consider this situation. So I would like to add non-restore option for it.

Differential Revision: https://phabricator.services.mozilla.com/D143992
  • Loading branch information
makotokato committed May 2, 2022
1 parent 8b63af6 commit cb0d1c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3611,7 +3611,7 @@ nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal) {
return NS_OK;
}

nsresult nsDOMWindowUtils::ExitFullscreen() {
nsresult nsDOMWindowUtils::ExitFullscreen(bool aDontRestoreViewSize) {
PROFILER_MARKER_UNTYPED("Exit fullscreen", DOM);
nsCOMPtr<Document> doc = GetDocument();
NS_ENSURE_STATE(doc);
Expand All @@ -3627,7 +3627,8 @@ nsresult nsDOMWindowUtils::ExitFullscreen() {
// set the window dimensions in advance. Since the resize message
// comes after the fullscreen change call, doing so could avoid an
// extra resize reflow after this point.
PrepareForFullscreenChange(GetDocShell(), oldSize);
PrepareForFullscreenChange(GetDocShell(),
aDontRestoreViewSize ? nsSize() : oldSize);
Document::ExitFullscreenInDocTree(doc);
return NS_OK;
}
Expand Down
6 changes: 5 additions & 1 deletion dom/interfaces/base/nsIDOMWindowUtils.idl
Original file line number Diff line number Diff line change
Expand Up @@ -1393,8 +1393,12 @@ interface nsIDOMWindowUtils : nsISupports {
/**
* Called when the child frame has fully exit fullscreen, so that the parent
* process can also fully exit.
*
* @param aDontResoreViewSize false if content view size is restored by
* original view size that is on entering full
* screen.
*/
void exitFullscreen();
void exitFullscreen([optional] in boolean aDontRestoreViewSize);

/**
* If sendQueryContentEvent()'s aAdditionalFlags argument is
Expand Down
26 changes: 25 additions & 1 deletion mobile/android/actors/GeckoViewContentChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const SCREEN_LENGTH_DOCUMENT_HEIGHT = 4;
const SCROLL_BEHAVIOR_SMOOTH = 0;
const SCROLL_BEHAVIOR_AUTO = 1;

const SCREEN_ORIENTATION_PORTRAIT = 0;
const SCREEN_ORIENTATION_LANDSCAPE = 1;

XPCOMUtils.defineLazyModuleGetters(this, {
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
PrivacyFilter: "resource://gre/modules/sessionstore/PrivacyFilter.jsm",
Expand All @@ -33,6 +36,11 @@ XPCOMUtils.defineLazyModuleGetters(this, {
var EXPORTED_SYMBOLS = ["GeckoViewContentChild"];

class GeckoViewContentChild extends GeckoViewActorChild {
constructor() {
super();
this.lastOrientation = SCREEN_ORIENTATION_PORTRAIT;
}

actorCreated() {
super.actorCreated();

Expand Down Expand Up @@ -103,16 +111,32 @@ class GeckoViewContentChild extends GeckoViewActorChild {
return { history, formdata, scrolldata };
}

orientation() {
const currentOrientationType = this.contentWindow?.screen.orientation.type;
if (!currentOrientationType) {
// Unfortunately, we don't know current screen orientation.
// Return portrait as default.
return SCREEN_ORIENTATION_PORTRAIT;
}
if (currentOrientationType.startsWith("landscape")) {
return SCREEN_ORIENTATION_LANDSCAPE;
}
return SCREEN_ORIENTATION_PORTRAIT;
}

receiveMessage(message) {
const { name } = message;
debug`receiveMessage: ${name}`;

switch (name) {
case "GeckoView:DOMFullscreenEntered":
this.lastOrientation = this.orientation();
this.contentWindow?.windowUtils.handleFullscreenRequests();
break;
case "GeckoView:DOMFullscreenExited":
this.contentWindow?.windowUtils.exitFullscreen();
// During fullscreen, window size is changed. So don't restore viewport size.
const restoreViewSize = this.orientation() == this.lastOrientation;
this.contentWindow?.windowUtils.exitFullscreen(!restoreViewSize);
break;
case "GeckoView:ZoomToInput": {
const { contentWindow } = this;
Expand Down

0 comments on commit cb0d1c0

Please sign in to comment.