Skip to content

Commit

Permalink
If resize is cancelled, resize back to the screen size it had before …
Browse files Browse the repository at this point in the history
…entering resize mode (#1411)
  • Loading branch information
MortimerGoro authored and bluemarvin committed Jul 19, 2019
1 parent ed251cf commit f08ecc4
Showing 1 changed file with 20 additions and 9 deletions.
Expand Up @@ -66,7 +66,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private boolean mIsResizing;
private boolean mIsInVRVideo;
private boolean mAutoEnteredVRVideo;
private WidgetPlacement mSizeBeforeFullScreen;
private WidgetPlacement mPlacementBeforeResize;
private Runnable mResizeBackHandler;
private Runnable mFullScreenBackHandler;
private Runnable mVRVideoBackHandler;
Expand Down Expand Up @@ -126,10 +126,10 @@ private void initialize(Context aContext) {
mBrightnessButton = findViewById(R.id.brightnessButton);
mFullScreenResizeButton = findViewById(R.id.fullScreenResizeEnterButton);
mProjectionButton = findViewById(R.id.projectionButton);
mSizeBeforeFullScreen = new WidgetPlacement(aContext);
mPlacementBeforeResize = new WidgetPlacement(aContext);


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

mFullScreenBackHandler = this::exitFullScreenMode;
mVRVideoBackHandler = new Runnable() {
Expand Down Expand Up @@ -207,7 +207,7 @@ else if (SessionStore.get().canUnstackSession())

mResizeExitButton.setOnClickListener(view -> {
view.requestFocusFromTouch();
exitResizeMode(true);
exitResizeMode(ResizeAction.KEEP_SIZE);
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
Expand Down Expand Up @@ -373,7 +373,7 @@ public void setBrowserWidget(WindowWidget aWidget) {
}

private void setFullScreenSize() {
mSizeBeforeFullScreen.copyFrom(mWindowWidget.getPlacement());
mPlacementBeforeResize.copyFrom(mWindowWidget.getPlacement());
// Set browser fullscreen size
float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
Media media = SessionStore.get().getFullScreenVideo();
Expand Down Expand Up @@ -437,7 +437,7 @@ private void exitFullScreenMode() {
}
}, 50);

mWindowWidget.getPlacement().copyFrom(mSizeBeforeFullScreen);
mWindowWidget.getPlacement().copyFrom(mPlacementBeforeResize);
mWidgetManager.updateWidget(mWindowWidget);
mWindowWidget.setSaveResizeChanges(true);

Expand All @@ -459,6 +459,7 @@ private void enterResizeMode() {
return;
}
mIsResizing = true;
mPlacementBeforeResize.copyFrom(mWindowWidget.getPlacement());
startWidgetResize();
AnimationHelper.fadeIn(mResizeModeContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
if (mIsInFullScreenMode) {
Expand All @@ -471,10 +472,20 @@ private void enterResizeMode() {
closeFloatingMenus();
}

private void exitResizeMode(boolean aCommitChanges) {

enum ResizeAction {
KEEP_SIZE,
RESTORE_SIZE
}

private void exitResizeMode(ResizeAction aResizeAction) {
if (!mIsResizing) {
return;
}
if (aResizeAction == ResizeAction.RESTORE_SIZE) {
mWindowWidget.getPlacement().copyFrom(mPlacementBeforeResize);
mWidgetManager.updateWidget(mWindowWidget);
}
mIsResizing = false;
finishWidgetResize();
if (mIsInFullScreenMode) {
Expand Down Expand Up @@ -735,7 +746,7 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
enterFullScreenMode();
}
if (mIsResizing) {
exitResizeMode(false);
exitResizeMode(ResizeAction.KEEP_SIZE);
}
AtomicBoolean autoEnter = new AtomicBoolean(false);
mAutoSelectedProjection = VideoProjectionMenuWidget.getAutomaticProjection(SessionStore.get().getUriFromSession(session), autoEnter);
Expand Down Expand Up @@ -982,7 +993,7 @@ public void onBookmarksHidden() {
@Override
public void onBookmarksClicked() {
if (mIsResizing) {
exitResizeMode(false);
exitResizeMode(ResizeAction.RESTORE_SIZE);

} else if (mIsInFullScreenMode) {
exitFullScreenMode();
Expand Down

0 comments on commit f08ecc4

Please sign in to comment.