From cfdc40191c522dd4756292a42fd4c5b586a99d91 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 31 Oct 2019 12:55:40 +0100 Subject: [PATCH] Register to Window OnFullscreen changes instead of using GeckoSession.addContextListener --- .../vrbrowser/ui/widgets/WindowWidget.java | 8 ++- .../mozilla/vrbrowser/ui/widgets/Windows.java | 61 ++++++++----------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java index 394f27682..53660da87 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java @@ -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) {} } public WindowWidget(Context aContext, int windowId, boolean privateMode) { @@ -885,7 +886,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() { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java index c1904e80c..a94623143 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java @@ -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); @@ -207,7 +206,7 @@ public WindowWidget addWindow() { if (mFullscreenWindow != null) { mFullscreenWindow.getSession().exitFullScreen(); - onFullScreen(mFullscreenWindow.getSession().getGeckoSession(), false); + onFullScreen(mFullscreenWindow, false); } WindowWidget frontWindow = getFrontWindow(); @@ -641,7 +640,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); @@ -840,7 +838,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); @@ -1029,36 +1026,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()) { @@ -1093,6 +1060,30 @@ public void onBorderChanged(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;