Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Prevent NavigationBarWidget from restoring the incorrect window posit…
Browse files Browse the repository at this point in the history
…ion when dropping out of fullscreen. Fixes #1798 (#1810)
  • Loading branch information
bluemarvin authored Sep 12, 2019
1 parent 2c2a69e commit 7265441
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ public void write(JsonWriter out, T value) throws IOException {
out.name("mTitle").value(session.mTitle);
out.name("mFullScreen").value(session.mFullScreen);
out.name("mSettings").jsonValue(gson.toJson(session.mSettings));
if (session.mSession.getSettings().getUsePrivateMode()) {
out.name("mSessionState").jsonValue(null);

} else {
if (session.mSessionState != null) {
out.name("mSessionState").jsonValue(gsDelegate.toJson(session.mSessionState));
if (session.mSession != null) {
if (session.mSession.getSettings().getUsePrivateMode()) {
out.name("mSessionState").jsonValue(null);

} else {
out.name("mSessionState").jsonValue(null);
if (session.mSessionState != null) {
out.name("mSessionState").jsonValue(gsDelegate.toJson(session.mSessionState));

} else {
out.name("mSessionState").jsonValue(null);
}
}
}
out.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,29 +437,11 @@ protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

private void setFullScreenSize() {
final float minScale = WidgetPlacement.floatDimension(getContext(), R.dimen.window_fullscreen_min_scale);
// Set browser fullscreen size
float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
Media media = mSessionStack.getFullScreenVideo();
if (media != null && media.getWidth() > 0 && media.getHeight() > 0) {
aspect = (float)media.getWidth() / (float)media.getHeight();
}
float scale = mAttachedWindow.getCurrentScale();
// Enforce min fullscreen size.
// If current window area is larger only resize if the aspect changes (e.g. media).
if (scale < minScale || aspect != mAttachedWindow.getCurrentAspect()) {
mAttachedWindow.resizeByMultiplier(aspect, Math.max(scale, minScale));
}
}

private void enterFullScreenMode() {
if (mAttachedWindow.isFullScreen()) {
return;
}

mAttachedWindow.saveBeforeFullscreenPlacement();
setFullScreenSize();
mWidgetManager.pushBackHandler(mFullScreenBackHandler);
mAttachedWindow.setIsFullScreen(true);
AnimationHelper.fadeIn(mFullScreenModeContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
Expand All @@ -475,7 +457,7 @@ private void enterFullScreenMode() {
mProjectionMenu.setParentWidget(this);
mProjectionMenuPlacement = new WidgetPlacement(getContext());
mWidgetManager.addWidget(mProjectionMenu);
mProjectionMenu.setDelegate((projection )-> {
mProjectionMenu.setDelegate((projection)-> {
if (mIsInVRVideo) {
// Reproject while reproducing VRVideo
mWidgetManager.showVRVideo(mAttachedWindow.getHandle(), projection);
Expand Down Expand Up @@ -508,7 +490,6 @@ private void exitFullScreenMode() {
}
}, 50);

mAttachedWindow.restoreBeforeFullscreenPlacement();
mWidgetManager.updateWidget(mAttachedWindow);

mAttachedWindow.setIsFullScreen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ default void onBookmarksHidden(WindowWidget aWindow) {}
private ArrayList<BookmarksViewDelegate> mBookmarksViewListeners;
private ArrayList<HistoryViewDelegate> mHistoryViewListeners;
private Windows.WindowPlacement mWindowPlacement = Windows.WindowPlacement.FRONT;
private Windows.WindowPlacement mWindowPlacementBeforeFullscreen = Windows.WindowPlacement.FRONT;
private float mMaxWindowScale = 3;
private boolean mIsRestored = false;
private WindowDelegate mWindowDelegate;
Expand Down Expand Up @@ -517,6 +518,10 @@ public void setWindowPlacement(@NonNull Windows.WindowPlacement aPlacement) {
}
}

public @NonNull Windows.WindowPlacement getmWindowPlacementBeforeFullscreen() {
return mWindowPlacementBeforeFullscreen;
}

public @NonNull Windows.WindowPlacement getWindowPlacement() {
return mWindowPlacement;
}
Expand Down Expand Up @@ -789,10 +794,12 @@ protected void updateBorder() {
}

public void saveBeforeFullscreenPlacement() {
mWindowPlacementBeforeFullscreen = mWindowPlacement;
mPlacementBeforeFullscreen.copyFrom(mWidgetPlacement);
}

public void restoreBeforeFullscreenPlacement() {
mWindowPlacement = mWindowPlacementBeforeFullscreen;
mWidgetPlacement.copyFrom(mPlacementBeforeFullscreen);
}

Expand Down
55 changes: 35 additions & 20 deletions app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.Media;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.SessionStack;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
Expand Down Expand Up @@ -42,28 +43,23 @@ class WindowState {
float worldWidth;

public void load(WindowWidget aWindow) {
if (aWindow == mFullscreenWindow) {
placement = mPrevWindowPlacement;

} else {
placement = aWindow.getWindowPlacement();
}
sessionStack = aWindow.getSessionStack();
currentSessionId = aWindow.getSessionStack().getCurrentSessionId();
WidgetPlacement placement;
WidgetPlacement widgetPlacement;
if (aWindow.isFullScreen()) {
placement = aWindow.getBeforeFullscreenPlacement();

widgetPlacement = aWindow.getBeforeFullscreenPlacement();
placement = aWindow.getmWindowPlacementBeforeFullscreen();
} else if (aWindow.isResizing()) {
placement = aWindow.getBeforeResizePlacement();

widgetPlacement = aWindow.getBeforeResizePlacement();
placement = aWindow.getWindowPlacement();
} else {
placement = aWindow.getPlacement();
widgetPlacement = aWindow.getPlacement();
placement = aWindow.getWindowPlacement();
}

textureWidth = placement.width;
textureHeight = placement.height;
worldWidth = placement.worldWidth;
textureWidth = widgetPlacement.width;
textureHeight = widgetPlacement.height;
worldWidth = widgetPlacement.worldWidth;
}
}

Expand All @@ -84,7 +80,6 @@ class WindowsState {
private boolean mPrivateMode = false;
public static final int MAX_WINDOWS = 3;
private WindowWidget mFullscreenWindow;
private WindowPlacement mPrevWindowPlacement;
private WindowPlacement mRegularWindowPlacement;
private WindowPlacement mPrivateWindowPlacement;
private boolean mStoredCurvedMode = false;
Expand Down Expand Up @@ -131,8 +126,7 @@ private void saveState() {
try (Writer writer = new FileWriter(file)) {
WindowsState state = new WindowsState();
state.privateMode = mPrivateMode;
state.focusedWindowPlacement = mFocusedWindow.getWindowPlacement();
state.regularWindowsState = new ArrayList<>();
state.focusedWindowPlacement = mFocusedWindow.isFullScreen() ? mFocusedWindow.getmWindowPlacementBeforeFullscreen() : mFocusedWindow.getWindowPlacement();
for (WindowWidget window : mRegularWindows) {
WindowState windowState = new WindowState();
windowState.load(window);
Expand Down Expand Up @@ -917,6 +911,26 @@ public void onMediaPauseClicked(@NonNull TitleBarWidget titleBar) {
}
}

private void setFullScreenSize(WindowWidget aWindow) {
final float minScale = WidgetPlacement.floatDimension(mContext, R.dimen.window_fullscreen_min_scale);
// Set browser fullscreen size
float aspect = SettingsStore.getInstance(mContext).getWindowAspect();
SessionStack sessionStack = mFocusedWindow.getSessionStack();
if (sessionStack == null) {
return;
}
Media media = sessionStack.getFullScreenVideo();
if (media != null && media.getWidth() > 0 && media.getHeight() > 0) {
aspect = (float)media.getWidth() / (float)media.getHeight();
}
float scale = aWindow.getCurrentScale();
// Enforce min fullscreen size.
// If current window area is larger only resize if the aspect changes (e.g. media).
if (scale < minScale || aspect != aWindow.getCurrentAspect()) {
aWindow.resizeByMultiplier(aspect, Math.max(scale, minScale));
}
}

// Content delegate
@Override
public void onFullScreen(GeckoSession session, boolean aFullScreen) {
Expand All @@ -927,7 +941,8 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {

if (aFullScreen) {
mFullscreenWindow = window;
mPrevWindowPlacement = window.getWindowPlacement();
window.saveBeforeFullscreenPlacement();
setFullScreenSize(window);
placeWindow(window, WindowPlacement.FRONT);
focusWindow(window);
for (WindowWidget win: getCurrentWindows()) {
Expand All @@ -936,7 +951,7 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
updateMaxWindowScales();
updateViews();
} else if (mFullscreenWindow != null) {
placeWindow(mFullscreenWindow, mPrevWindowPlacement);
window.restoreBeforeFullscreenPlacement();
mFullscreenWindow = null;
for (WindowWidget win : getCurrentWindows()) {
setWindowVisible(win, true);
Expand Down

0 comments on commit 7265441

Please sign in to comment.