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

Register to Window OnFullscreen changes instead of using GeckoSession.addContextListener #2109

Merged
merged 2 commits into from
Nov 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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