Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore window size/position if the app is exited while in fullscreen #1778

Merged
merged 4 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private ViewGroup mResizeModeContainer;
private WindowWidget mAttachedWindow;
private boolean mIsLoading;
private boolean mIsInFullScreenMode;
private boolean mIsResizing;
private boolean mIsInVRVideo;
private boolean mAutoEnteredVRVideo;
private WidgetPlacement mPlacementBeforeResize;
private WidgetPlacement mPlacementBeforeFullscreen;
private Runnable mResizeBackHandler;
private Runnable mFullScreenBackHandler;
private Runnable mVRVideoBackHandler;
Expand Down Expand Up @@ -131,9 +127,6 @@ private void initialize(@NonNull Context aContext) {
mBrightnessButton = findViewById(R.id.brightnessButton);
mFullScreenResizeButton = findViewById(R.id.fullScreenResizeEnterButton);
mProjectionButton = findViewById(R.id.projectionButton);
mPlacementBeforeResize = new WidgetPlacement(aContext);
mPlacementBeforeFullscreen = new WidgetPlacement(aContext);


mResizeBackHandler = () -> exitResizeMode(ResizeAction.RESTORE_SIZE);

Expand Down Expand Up @@ -365,10 +358,10 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {

@Override
public void detachFromWindow() {
if (mIsResizing) {
if (mAttachedWindow != null && mAttachedWindow.isResizing()) {
exitResizeMode(ResizeAction.RESTORE_SIZE);
}
if (mIsInFullScreenMode) {
if (mAttachedWindow != null && mAttachedWindow.isFullScreen()) {
exitFullScreenMode();
}

Expand Down Expand Up @@ -434,7 +427,6 @@ protected void onDraw(Canvas canvas) {
}

private void setFullScreenSize() {
mPlacementBeforeFullscreen.copyFrom(mAttachedWindow.getPlacement());
final float minScale = WidgetPlacement.floatDimension(getContext(), R.dimen.window_fullscreen_min_scale);
// Set browser fullscreen size
float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
Expand All @@ -451,13 +443,14 @@ private void setFullScreenSize() {
}

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

mAttachedWindow.saveBeforeFullscreenPlacement();
setFullScreenSize();
mWidgetManager.pushBackHandler(mFullScreenBackHandler);
mIsInFullScreenMode = true;
mAttachedWindow.setIsFullScreen(true);
AnimationHelper.fadeIn(mFullScreenModeContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);

AnimationHelper.fadeOut(mNavigationContainer, 0, null);
Expand Down Expand Up @@ -491,7 +484,7 @@ private void enterFullScreenMode() {
}

private void exitFullScreenMode() {
if (!mIsInFullScreenMode) {
if (!mAttachedWindow.isFullScreen()) {
mWidgetManager.setTrayVisible(true);
return;
}
Expand All @@ -504,10 +497,10 @@ private void exitFullScreenMode() {
}
}, 50);

mAttachedWindow.getPlacement().copyFrom(mPlacementBeforeFullscreen);
mAttachedWindow.restoreBeforeFullscreenPlacement();
mWidgetManager.updateWidget(mAttachedWindow);

mIsInFullScreenMode = false;
mAttachedWindow.setIsFullScreen(false);
mWidgetManager.popBackHandler(mFullScreenBackHandler);

AnimationHelper.fadeIn(mNavigationContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
Expand All @@ -521,14 +514,14 @@ private void exitFullScreenMode() {
}

private void enterResizeMode() {
if (mIsResizing) {
if (mAttachedWindow.isResizing()) {
return;
}
mIsResizing = true;
mPlacementBeforeResize.copyFrom(mAttachedWindow.getPlacement());
mAttachedWindow.setIsResizing(true);
mAttachedWindow.saveBeforeResizePlacement();
startWidgetResize();
AnimationHelper.fadeIn(mResizeModeContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
if (mIsInFullScreenMode) {
if (mAttachedWindow.isFullScreen()) {
AnimationHelper.fadeOut(mFullScreenModeContainer, 0, null);
} else {
AnimationHelper.fadeOut(mNavigationContainer, 0, null);
Expand Down Expand Up @@ -574,24 +567,24 @@ enum ResizeAction {
}

private void exitResizeMode(ResizeAction aResizeAction) {
if (!mIsResizing) {
if (!mAttachedWindow.isResizing()) {
return;
}
if (aResizeAction == ResizeAction.RESTORE_SIZE) {
mAttachedWindow.getPlacement().copyFrom(mPlacementBeforeResize);
mAttachedWindow.restoreBeforeResizePlacement();
mWidgetManager.updateWidget(mAttachedWindow);
mWidgetManager.updateVisibleWidgets();
}
mIsResizing = false;
mAttachedWindow.setIsResizing(false);
finishWidgetResize();
if (mIsInFullScreenMode) {
if (mAttachedWindow.isFullScreen()) {
AnimationHelper.fadeIn(mFullScreenModeContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
} else {
AnimationHelper.fadeIn(mNavigationContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
}
AnimationHelper.fadeOut(mResizeModeContainer, 0, () -> updateWidget());
mWidgetManager.popBackHandler(mResizeBackHandler);
mWidgetManager.setTrayVisible(!mIsInFullScreenMode);
mWidgetManager.setTrayVisible(!mAttachedWindow.isFullScreen());
closeFloatingMenus();

if (aResizeAction == ResizeAction.KEEP_SIZE) {
Expand Down Expand Up @@ -822,10 +815,10 @@ public void onSecurityChange(GeckoSession geckoSession, SecurityInformation secu
@Override
public void onFullScreen(GeckoSession session, boolean aFullScreen) {
if (aFullScreen) {
if (!mIsInFullScreenMode) {
if (!mAttachedWindow.isFullScreen()) {
enterFullScreenMode();
}
if (mIsResizing) {
if (mAttachedWindow.isResizing()) {
exitResizeMode(ResizeAction.KEEP_SIZE);
}
AtomicBoolean autoEnter = new AtomicBoolean(false);
Expand All @@ -847,7 +840,7 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
// WidgetManagerDelegate.UpdateListener
@Override
public void onWidgetUpdate(Widget aWidget) {
if (aWidget == mAttachedWindow && !mIsResizing) {
if (aWidget == mAttachedWindow && !mAttachedWindow.isResizing()) {
handleWindowResize();
}
}
Expand Down Expand Up @@ -875,9 +868,9 @@ public void onCurrentSessionChange(GeckoSession aSession, int aId) {
handleSessionState();

boolean isFullScreen = mSessionStack.isInFullScreen(aSession);
if (isFullScreen && !mIsInFullScreenMode) {
if (isFullScreen && !mAttachedWindow.isFullScreen()) {
enterFullScreenMode();
} else if (!isFullScreen && mIsInFullScreenMode) {
} else if (!isFullScreen && mAttachedWindow.isFullScreen()) {
exitVRVideo();
exitFullScreenMode();
}
Expand Down Expand Up @@ -1026,10 +1019,10 @@ public void onHistoryViewHidden(WindowWidget aWindow) {

@Override
public void onBookmarksClicked() {
if (mIsResizing) {
if (mAttachedWindow.isResizing()) {
exitResizeMode(ResizeAction.RESTORE_SIZE);

} else if (mIsInFullScreenMode) {
} else if (mAttachedWindow.isFullScreen()) {
exitFullScreenMode();

} else if (mIsInVRVideo) {
Expand All @@ -1044,10 +1037,10 @@ public void onPrivateBrowsingClicked() {

@Override
public void onHistoryClicked() {
if (mIsResizing) {
if (mAttachedWindow.isResizing()) {
exitResizeMode(ResizeAction.RESTORE_SIZE);

} else if (mIsInFullScreenMode) {
} else if (mAttachedWindow.isFullScreen()) {
exitFullScreenMode();

} else if (mIsInVRVideo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void onCurrentSessionChange(GeckoSession aSession, int aId) {

@Override
public void setVisible(boolean aIsVisible) {
if (mVisible == aIsVisible) {
if (mVisible == aIsVisible || mWidgetManager == null) {
return;
}
mVisible = aIsVisible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ default void onBookmarksHidden(WindowWidget aWindow) {}
boolean mClickedAfterFocus = false;
boolean mIsBookmarksVisible = false;
boolean mIsHistoryVisible = false;
private WidgetPlacement mPlacementBeforeFullscreen;
private WidgetPlacement mPlacementBeforeResize;
private boolean mIsResizing;
private boolean mIsFullScreen;

public interface WindowDelegate {
void onFocusRequest(@NonNull WindowWidget aWindow);
Expand Down Expand Up @@ -163,6 +167,10 @@ public WindowWidget(Context aContext, int windowId, boolean privateMode) {

mHandle = ((WidgetManagerDelegate)aContext).newWidgetHandle();
mWidgetPlacement = new WidgetPlacement(aContext);
mPlacementBeforeFullscreen = new WidgetPlacement(aContext);
mPlacementBeforeResize = new WidgetPlacement(aContext);
mIsResizing = false;
mIsFullScreen = false;
initializeWidgetPlacement(mWidgetPlacement);

mTopBar = new TopBarWidget(aContext);
Expand Down Expand Up @@ -781,6 +789,46 @@ protected void updateBorder() {
}
}

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

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

public WidgetPlacement getBeforeFullscreenPlacement() {
return mPlacementBeforeFullscreen;
}

public void saveBeforeResizePlacement() {
mPlacementBeforeResize.copyFrom(mWidgetPlacement);
}

public void restoreBeforeResizePlacement() {
mWidgetPlacement.copyFrom(mPlacementBeforeResize);
}

public WidgetPlacement getBeforeResizePlacement() {
return mPlacementBeforeResize;
}

public void setIsResizing(boolean isResizing) {
mIsResizing = isResizing;
}

public boolean isResizing() {
return mIsResizing;
}

public void setIsFullScreen(boolean isFullScreen) {
mIsFullScreen = isFullScreen;
}

public boolean isFullScreen() {
return mIsFullScreen;
}

public void setWindowDelegate(WindowDelegate aDelegate) {
mWindowDelegate = aDelegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,28 @@ class WindowState {
float worldWidth;

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

} else {
placement = aWindow.getWindowPlacement();
}
sessionStack = aWindow.getSessionStack();
currentSessionId = aWindow.getSessionStack().getCurrentSessionId();
textureWidth = aWindow.getPlacement().width;
textureHeight = aWindow.getPlacement().height;
worldWidth = aWindow.getPlacement().worldWidth;
WidgetPlacement placement;
if (aWindow.isFullScreen()) {
placement = aWindow.getBeforeFullscreenPlacement();

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

} else {
placement = aWindow.getPlacement();
}

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

Expand Down Expand Up @@ -802,15 +818,19 @@ private WindowWidget createWindow() {
}

public void enterResizeMode() {
for (WindowWidget window : getCurrentWindows()) {
window.getTopBar().setVisible(false);
if (mFullscreenWindow == null) {
for (WindowWidget window : getCurrentWindows()) {
window.getTopBar().setVisible(false);
}
}
}

public void exitResizeMode() {
for (WindowWidget window : getCurrentWindows()) {
if (getCurrentWindows().size() > 1 || isInPrivateMode()) {
window.getTopBar().setVisible(window != mFullscreenWindow);
if (mFullscreenWindow == null) {
for (WindowWidget window : getCurrentWindows()) {
if (getCurrentWindows().size() > 1 || isInPrivateMode()) {
window.getTopBar().setVisible(true);
}
}
}
}
Expand Down