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

Commit

Permalink
Register to Window OnFullscreen changes instead of using GeckoSession…
Browse files Browse the repository at this point in the history
….addContextListener (#2109)
  • Loading branch information
MortimerGoro authored and keianhzo committed Nov 1, 2019
1 parent 29cbd25 commit b88d869
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public interface WindowListener {
default void onFocusRequest(@NonNull WindowWidget aWindow) {}
default void onBorderChanged(@NonNull WindowWidget aWindow) {}
default void onSessionChanged(@NonNull Session aOldSession, @NonNull Session aSession) {}
default void onFullScreen(@NonNull WindowWidget aWindow, boolean aFullScreen) {}
default void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {}
}

Expand Down Expand Up @@ -886,7 +887,12 @@ public boolean isResizing() {
}

public void setIsFullScreen(boolean isFullScreen) {
mIsFullScreen = isFullScreen;
if (isFullScreen != mIsFullScreen) {
mIsFullScreen = isFullScreen;
for (WindowListener listener: mListeners) {
listener.onFullScreen(this, isFullScreen);
}
}
}

public boolean isFullScreen() {
Expand Down
61 changes: 26 additions & 35 deletions app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
import mozilla.components.concept.sync.TabData;

public class Windows implements TrayListener, TopBarWidget.Delegate, TitleBarWidget.Delegate,
GeckoSession.ContentDelegate, WindowWidget.WindowListener, TabsWidget.TabDelegate,
Services.TabReceivedDelegate {
WindowWidget.WindowListener, TabsWidget.TabDelegate, Services.TabReceivedDelegate {

private static final String LOGTAG = SystemUtils.createLogtag(Windows.class);

Expand Down Expand Up @@ -208,7 +207,7 @@ public WindowWidget addWindow() {

if (mFullscreenWindow != null) {
mFullscreenWindow.getSession().exitFullScreen();
onFullScreen(mFullscreenWindow.getSession().getGeckoSession(), false);
onFullScreen(mFullscreenWindow, false);
}

WindowWidget frontWindow = getFrontWindow();
Expand Down Expand Up @@ -652,7 +651,6 @@ private void removeWindow(@NonNull WindowWidget aWindow) {
aWindow.removeWindowListener(this);
aWindow.getTitleBar().setVisible(false);
aWindow.getTitleBar().setDelegate((TitleBarWidget.Delegate) null);
aWindow.getSession().removeContentListener(this);
aWindow.close();
updateMaxWindowScales();
updateCurvedMode(true);
Expand Down Expand Up @@ -851,7 +849,6 @@ private WindowWidget createWindow(@Nullable Session aSession) {
getCurrentWindows().add(window);
window.getTopBar().setDelegate(this);
window.getTitleBar().setDelegate(this);
window.getSession().addContentListener(this);

if (mPrivateMode) {
TelemetryWrapper.openWindowsEvent(mPrivateWindows.size() - 1, mPrivateWindows.size(), true);
Expand Down Expand Up @@ -1040,36 +1037,6 @@ private void setFullScreenSize(WindowWidget aWindow) {
}
}

// Content delegate
@Override
public void onFullScreen(GeckoSession session, boolean aFullScreen) {
WindowWidget window = getWindowWithSession(session);
if (window == null) {
return;
}

if (aFullScreen) {
mFullscreenWindow = window;
window.saveBeforeFullscreenPlacement();
setFullScreenSize(window);
placeWindow(window, WindowPlacement.FRONT);
focusWindow(window);
for (WindowWidget win: getCurrentWindows()) {
setWindowVisible(win, win == mFullscreenWindow);
}
updateMaxWindowScales();
updateViews();
} else if (mFullscreenWindow != null) {
window.restoreBeforeFullscreenPlacement();
mFullscreenWindow = null;
for (WindowWidget win : getCurrentWindows()) {
setWindowVisible(win, true);
}
updateMaxWindowScales();
updateViews();
}
}

@Nullable
private WindowWidget getWindowWithSession(GeckoSession aSession) {
for (WindowWidget window: getCurrentWindows()) {
Expand Down Expand Up @@ -1110,6 +1077,30 @@ public void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
}
}

@Override
public void onFullScreen(@NonNull WindowWidget aWindow, boolean aFullScreen) {
if (aFullScreen) {
mFullscreenWindow = aWindow;
aWindow.saveBeforeFullscreenPlacement();
setFullScreenSize(aWindow);
placeWindow(aWindow, WindowPlacement.FRONT);
focusWindow(aWindow);
for (WindowWidget win: getCurrentWindows()) {
setWindowVisible(win, win == mFullscreenWindow);
}
updateMaxWindowScales();
updateViews();
} else if (mFullscreenWindow != null) {
aWindow.restoreBeforeFullscreenPlacement();
mFullscreenWindow = null;
for (WindowWidget win : getCurrentWindows()) {
setWindowVisible(win, true);
}
updateMaxWindowScales();
updateViews();
}
}

@Override
public void onTabSelect(Session aTab) {
WindowWidget targetWindow = mFocusedWindow;
Expand Down

0 comments on commit b88d869

Please sign in to comment.