Commit 9f52f0c2 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Merge FullscreenManager into ChromeFullscreenManager

The distinction between FullscreenManager and ChromeFullscreenManager
got fuzzy over time, and there has not been any other concrete
implementation. This CL merges the two classes into one. This is a
part of the fullscreen manager clean up task that will split the role
of browser controls positioning and HTML5 fullscreen API processing.

Bug: 966272
Change-Id: Ie5cf76d6f1caf14b02b390bf6d3b40f52fe4183b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217679
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774561}
parent 7d9ed458
...@@ -738,7 +738,6 @@ chrome_java_sources = [ ...@@ -738,7 +738,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/fullscreen/BrowserStateBrowserControlsVisibilityDelegate.java", "java/src/org/chromium/chrome/browser/fullscreen/BrowserStateBrowserControlsVisibilityDelegate.java",
"java/src/org/chromium/chrome/browser/fullscreen/ChromeFullscreenManager.java", "java/src/org/chromium/chrome/browser/fullscreen/ChromeFullscreenManager.java",
"java/src/org/chromium/chrome/browser/fullscreen/FullscreenHtmlApiHandler.java", "java/src/org/chromium/chrome/browser/fullscreen/FullscreenHtmlApiHandler.java",
"java/src/org/chromium/chrome/browser/fullscreen/FullscreenManager.java",
"java/src/org/chromium/chrome/browser/fullscreen/FullscreenOptions.java", "java/src/org/chromium/chrome/browser/fullscreen/FullscreenOptions.java",
"java/src/org/chromium/chrome/browser/fullscreen/TabGestureStateListener.java", "java/src/org/chromium/chrome/browser/fullscreen/TabGestureStateListener.java",
"java/src/org/chromium/chrome/browser/gcore/ChromeGoogleApiClient.java", "java/src/org/chromium/chrome/browser/gcore/ChromeGoogleApiClient.java",
......
...@@ -30,7 +30,6 @@ import org.chromium.chrome.browser.document.ChromeIntentUtil; ...@@ -30,7 +30,6 @@ import org.chromium.chrome.browser.document.ChromeIntentUtil;
import org.chromium.chrome.browser.document.DocumentWebContentsDelegate; import org.chromium.chrome.browser.document.DocumentWebContentsDelegate;
import org.chromium.chrome.browser.fullscreen.BrowserControlsStateProvider; import org.chromium.chrome.browser.fullscreen.BrowserControlsStateProvider;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.FullscreenManager;
import org.chromium.chrome.browser.fullscreen.FullscreenOptions; import org.chromium.chrome.browser.fullscreen.FullscreenOptions;
import org.chromium.chrome.browser.media.PictureInPicture; import org.chromium.chrome.browser.media.PictureInPicture;
import org.chromium.chrome.browser.policy.PolicyAuditor; import org.chromium.chrome.browser.policy.PolicyAuditor;
...@@ -127,7 +126,7 @@ public class ActivityTabWebContentsDelegateAndroid extends TabWebContentsDelegat ...@@ -127,7 +126,7 @@ public class ActivityTabWebContentsDelegateAndroid extends TabWebContentsDelegat
@Override @Override
public boolean isFullscreenForTabOrPending() { public boolean isFullscreenForTabOrPending() {
FullscreenManager manager = getFullscreenManager(); ChromeFullscreenManager manager = getFullscreenManager();
return manager != null ? manager.getPersistentFullscreenMode() : false; return manager != null ? manager.getPersistentFullscreenMode() : false;
} }
......
...@@ -25,7 +25,7 @@ import org.chromium.chrome.browser.compositor.overlays.SceneOverlay; ...@@ -25,7 +25,7 @@ import org.chromium.chrome.browser.compositor.overlays.SceneOverlay;
import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutHelperManager; import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutHelperManager;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManagementDelegate; import org.chromium.chrome.browser.contextualsearch.ContextualSearchManagementDelegate;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.fullscreen.FullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabLaunchType; import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
...@@ -524,7 +524,7 @@ public class LayoutManagerChrome ...@@ -524,7 +524,7 @@ public class LayoutManagerChrome
@Override @Override
public boolean isSwipeEnabled(@ScrollDirection int direction) { public boolean isSwipeEnabled(@ScrollDirection int direction) {
FullscreenManager manager = mHost.getFullscreenManager(); ChromeFullscreenManager manager = mHost.getFullscreenManager();
if (getActiveLayout() != mStaticLayout if (getActiveLayout() != mStaticLayout
|| !DeviceClassManager.enableToolbarSwipe() || !DeviceClassManager.enableToolbarSwipe()
|| (manager != null && manager.getPersistentFullscreenMode())) { || (manager != null && manager.getPersistentFullscreenMode())) {
......
...@@ -33,7 +33,6 @@ import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabContro ...@@ -33,7 +33,6 @@ import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabContro
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider;
import org.chromium.chrome.browser.dependency_injection.ActivityScope; import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.FullscreenManager;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.ToolbarManager; import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.content_public.common.BrowserControlsState; import org.chromium.content_public.common.BrowserControlsState;
...@@ -46,7 +45,7 @@ import dagger.Lazy; ...@@ -46,7 +45,7 @@ import dagger.Lazy;
/** /**
* Works with the toolbar in a Custom Tab. Encapsulates interactions with Chrome's toolbar-related * Works with the toolbar in a Custom Tab. Encapsulates interactions with Chrome's toolbar-related
* classes such as {@link ToolbarManager} and {@link FullscreenManager}. * classes such as {@link ToolbarManager} and {@link ChromeFullscreenManager}.
* *
* TODO(pshmakov): * TODO(pshmakov):
* 1. Reduce the coupling between Custom Tab toolbar and Chrome's common code. In particular, * 1. Reduce the coupling between Custom Tab toolbar and Chrome's common code. In particular,
......
...@@ -45,6 +45,7 @@ import org.chromium.chrome.browser.toolbar.ControlContainer; ...@@ -45,6 +45,7 @@ import org.chromium.chrome.browser.toolbar.ControlContainer;
import org.chromium.chrome.browser.vr.VrModuleProvider; import org.chromium.chrome.browser.vr.VrModuleProvider;
import org.chromium.components.browser_ui.util.BrowserControlsVisibilityDelegate; import org.chromium.components.browser_ui.util.BrowserControlsVisibilityDelegate;
import org.chromium.components.embedder_support.view.ContentView; import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.NavigationHandle; import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.SelectionPopupController; import org.chromium.content_public.browser.SelectionPopupController;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
...@@ -60,9 +61,9 @@ import java.util.ArrayList; ...@@ -60,9 +61,9 @@ import java.util.ArrayList;
/** /**
* A class that manages control and content views to create the fullscreen mode. * A class that manages control and content views to create the fullscreen mode.
*/ */
public class ChromeFullscreenManager extends FullscreenManager public class ChromeFullscreenManager implements ActivityStateListener, WindowFocusChangedListener,
implements ActivityStateListener, WindowFocusChangedListener, ViewGroup.OnHierarchyChangeListener,
ViewGroup.OnHierarchyChangeListener, View.OnSystemUiVisibilityChangeListener, View.OnSystemUiVisibilityChangeListener,
VrModeObserver, BrowserControlsStateProvider { VrModeObserver, BrowserControlsStateProvider {
// The amount of time to delay the control show request after returning to a once visible // The amount of time to delay the control show request after returning to a once visible
// activity. This delay is meant to allow Android to run its Activity focusing animation and // activity. This delay is meant to allow Android to run its Activity focusing animation and
...@@ -113,6 +114,9 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -113,6 +114,9 @@ public class ChromeFullscreenManager extends FullscreenManager
private final ObserverList<BrowserControlsStateProvider.Observer> mControlsObservers = private final ObserverList<BrowserControlsStateProvider.Observer> mControlsObservers =
new ObserverList<>(); new ObserverList<>();
private Runnable mViewportSizeDelegate; private Runnable mViewportSizeDelegate;
private FullscreenHtmlApiHandler mHtmlApiHandler;
@Nullable
private Tab mTab;
/** The animator for slide-in animation on the Android controls. */ /** The animator for slide-in animation on the Android controls. */
private ValueAnimator mControlsAnimator; private ValueAnimator mControlsAnimator;
...@@ -185,13 +189,12 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -185,13 +189,12 @@ public class ChromeFullscreenManager extends FullscreenManager
*/ */
public ChromeFullscreenManager(Activity activity, public ChromeFullscreenManager(Activity activity,
@ControlsPosition int controlsPosition, boolean exitFullscreenOnStop) { @ControlsPosition int controlsPosition, boolean exitFullscreenOnStop) {
super(activity.getWindow());
mActivity = activity; mActivity = activity;
mControlsPosition = controlsPosition; mControlsPosition = controlsPosition;
mExitFullscreenOnStop = exitFullscreenOnStop; mExitFullscreenOnStop = exitFullscreenOnStop;
mHtmlApiHandler = new FullscreenHtmlApiHandler(activity.getWindow(), createApiDelegate());
mBrowserVisibilityDelegate = new BrowserStateBrowserControlsVisibilityDelegate( mBrowserVisibilityDelegate = new BrowserStateBrowserControlsVisibilityDelegate(
getHtmlApiHandler().getPersistentFullscreenModeSupplier()); mHtmlApiHandler.getPersistentFullscreenModeSupplier());
mBrowserVisibilityDelegate.addObserver((constraints) -> { mBrowserVisibilityDelegate.addObserver((constraints) -> {
if (constraints == BrowserControlsState.SHOWN) setPositionsForTabToNonFullscreen(); if (constraints == BrowserControlsState.SHOWN) setPositionsForTabToNonFullscreen();
}); });
...@@ -323,10 +326,17 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -323,10 +326,17 @@ public class ChromeFullscreenManager extends FullscreenManager
return mBrowserVisibilityDelegate; return mBrowserVisibilityDelegate;
} }
@Override /**
public void setTab(@Nullable Tab tab) { * @return The currently selected tab for fullscreen.
*/
@Nullable
public Tab getTab() {
return mTab;
}
private void setTab(@Nullable Tab tab) {
Tab previousTab = getTab(); Tab previousTab = getTab();
super.setTab(tab); mTab = tab;
if (previousTab != tab) { if (previousTab != tab) {
if (previousTab != null) { if (previousTab != null) {
TabGestureStateListener.from(previousTab).setFullscreenManager(null); TabGestureStateListener.from(previousTab).setFullscreenManager(null);
...@@ -345,29 +355,87 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -345,29 +355,87 @@ public class ChromeFullscreenManager extends FullscreenManager
} }
} }
/**
* Enter fullscreen.
* @param tab {@link Tab} that goes into fullscreen.
* @param options Fullscreen options.
*/
public void onEnterFullscreen(Tab tab, FullscreenOptions options) { public void onEnterFullscreen(Tab tab, FullscreenOptions options) {
// If enabling fullscreen while the tab is not interactable, fullscreen // If enabling fullscreen while the tab is not interactable, fullscreen
// will be delayed until the tab is interactable. // will be delayed until the tab is interactable.
if (tab.isUserInteractable()) { Runnable r = () -> {
enterPersistentFullscreenMode(options);
destroySelectActionMode(tab);
} else {
setEnterFullscreenRunnable(tab, () -> {
enterPersistentFullscreenMode(options); enterPersistentFullscreenMode(options);
destroySelectActionMode(tab); destroySelectActionMode(tab);
setEnterFullscreenRunnable(tab, null); setEnterFullscreenRunnable(tab, null);
}); };
if (tab.isUserInteractable()) {
r.run();
} else {
setEnterFullscreenRunnable(tab, r);
} }
for (FullscreenListener listener : mListeners) listener.onEnterFullscreen(tab, options); for (FullscreenListener listener : mListeners) listener.onEnterFullscreen(tab, options);
} }
/**
* Exit fullscreen.
* @param tab {@link Tab} that goes out of fullscreen.
*/
public void onExitFullscreen(Tab tab) { public void onExitFullscreen(Tab tab) {
setEnterFullscreenRunnable(tab, null); setEnterFullscreenRunnable(tab, null);
if (tab == getTab()) exitPersistentFullscreenMode(); if (tab == getTab()) exitPersistentFullscreenMode();
for (FullscreenListener listener : mListeners) listener.onExitFullscreen(tab); for (FullscreenListener listener : mListeners) listener.onExitFullscreen(tab);
} }
/**
* Enters persistent fullscreen mode. In this mode, the browser controls will be
* permanently hidden until this mode is exited.
*/
private void enterPersistentFullscreenMode(FullscreenOptions options) {
mHtmlApiHandler.enterPersistentFullscreenMode(options);
updateMultiTouchZoomSupport(false);
}
/**
* Exits persistent fullscreen mode. In this mode, the browser controls will be
* permanently hidden until this mode is exited.
*/
public void exitPersistentFullscreenMode() {
mHtmlApiHandler.exitPersistentFullscreenMode();
updateMultiTouchZoomSupport(true);
}
/**
* @see GestureListenerManager#updateMultiTouchZoomSupport(boolean).
*/
private void updateMultiTouchZoomSupport(boolean enable) {
Tab tab = getTab();
if (tab == null || tab.isHidden()) return;
WebContents webContents = tab.getWebContents();
if (webContents != null) {
GestureListenerManager manager = GestureListenerManager.fromWebContents(webContents);
if (manager != null) manager.updateMultiTouchZoomSupport(enable);
}
}
/**
* @return Whether the application is in persistent fullscreen mode.
* @see #setPersistentFullscreenMode(boolean)
*/
public boolean getPersistentFullscreenMode() {
return mHtmlApiHandler.getPersistentFullscreenMode();
}
/**
* Notified when the system UI visibility for the current ContentView has changed.
* @param visibility The updated UI visibility.
* @see View#getSystemUiVisibility()
*/
public void onContentViewSystemUiVisibilityChange(int visibility) {
mHtmlApiHandler.onContentViewSystemUiVisibilityChange(visibility);
}
private void destroySelectActionMode(Tab tab) { private void destroySelectActionMode(Tab tab) {
WebContents webContents = tab.getWebContents(); WebContents webContents = tab.getWebContents();
if (webContents != null) { if (webContents != null) {
...@@ -423,20 +491,23 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -423,20 +491,23 @@ public class ChromeFullscreenManager extends FullscreenManager
@Override @Override
public void onWindowFocusChanged(Activity activity, boolean hasFocus) { public void onWindowFocusChanged(Activity activity, boolean hasFocus) {
if (mActivity != activity) return; if (mActivity != activity) return;
onWindowFocusChanged(hasFocus); mHtmlApiHandler.onWindowFocusChanged(hasFocus);
// {@link ContentVideoView#getContentVideoView} requires native to have been initialized. // {@link ContentVideoView#getContentVideoView} requires native to have been initialized.
if (!LibraryLoader.getInstance().isInitialized()) return; if (!LibraryLoader.getInstance().isInitialized()) return;
} }
@Override /**
protected FullscreenHtmlApiDelegate createApiDelegate() { * @return The delegate that will handle the embedder specific requirements of the
* fullscreen API handler.
*/
private FullscreenHtmlApiDelegate createApiDelegate() {
return new FullscreenHtmlApiDelegate() { return new FullscreenHtmlApiDelegate() {
@Override @Override
public void onEnterFullscreen(FullscreenOptions options) { public void onEnterFullscreen(FullscreenOptions options) {
Tab tab = getTab(); Tab tab = getTab();
if (areBrowserControlsAtMinHeight()) { if (areBrowserControlsAtMinHeight()) {
// The browser controls are currently hidden. // The browser controls are currently hidden.
getHtmlApiHandler().enterFullscreen(tab, options); mHtmlApiHandler.enterFullscreen(tab, options);
} else { } else {
// We should hide browser controls first. // We should hide browser controls first.
mPendingFullscreenOptions = options; mPendingFullscreenOptions = options;
...@@ -485,7 +556,8 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -485,7 +556,8 @@ public class ChromeFullscreenManager extends FullscreenManager
* @return True if the browser controls are showing as much as the min height. Note that this is * @return True if the browser controls are showing as much as the min height. Note that this is
* the same as {@link #areBrowserControlsOffScreen()} when both min-heights are 0. * the same as {@link #areBrowserControlsOffScreen()} when both min-heights are 0.
*/ */
public boolean areBrowserControlsAtMinHeight() { @VisibleForTesting
boolean areBrowserControlsAtMinHeight() {
return getContentOffset() == getTopControlsMinHeight() return getContentOffset() == getTopControlsMinHeight()
&& getBottomContentOffset() == getBottomControlsMinHeight(); && getBottomContentOffset() == getBottomControlsMinHeight();
} }
...@@ -703,7 +775,10 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -703,7 +775,10 @@ public class ChromeFullscreenManager extends FullscreenManager
updateContentViewChildrenState(); updateContentViewChildrenState();
} }
@Override /**
* Updates the current ContentView's children and any popups with the correct offsets based on
* the current fullscreen state.
*/
public void updateContentViewChildrenState() { public void updateContentViewChildrenState() {
ViewGroup view = getContentView(); ViewGroup view = getContentView();
if (view == null) return; if (view == null) return;
...@@ -757,7 +832,7 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -757,7 +832,7 @@ public class ChromeFullscreenManager extends FullscreenManager
final Tab tab = getTab(); final Tab tab = getTab();
if (tab != null && areBrowserControlsAtMinHeight() && mIsEnteringPersistentModeState) { if (tab != null && areBrowserControlsAtMinHeight() && mIsEnteringPersistentModeState) {
getHtmlApiHandler().enterFullscreen(tab, mPendingFullscreenOptions); mHtmlApiHandler.enterFullscreen(tab, mPendingFullscreenOptions);
mIsEnteringPersistentModeState = false; mIsEnteringPersistentModeState = false;
mPendingFullscreenOptions = null; mPendingFullscreenOptions = null;
} }
...@@ -870,7 +945,10 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -870,7 +945,10 @@ public class ChromeFullscreenManager extends FullscreenManager
return tab != null ? (ContentView) tab.getContentView() : null; return tab != null ? (ContentView) tab.getContentView() : null;
} }
@Override /**
* Updates the positions of the browser controls and content to the default non fullscreen
* values.
*/
public void setPositionsForTabToNonFullscreen() { public void setPositionsForTabToNonFullscreen() {
Tab tab = getTab(); Tab tab = getTab();
if (tab == null if (tab == null
...@@ -888,7 +966,15 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -888,7 +966,15 @@ public class ChromeFullscreenManager extends FullscreenManager
} }
} }
@Override /**
* Updates the positions of the browser controls and content based on the desired position of
* the current tab.
* @param topControlsOffset The Y offset of the top controls in px.
* @param bottomControlsOffset The Y offset of the bottom controls in px.
* @param topContentOffset The Y offset for the content in px.
* @param topControlsMinHeightOffset The Y offset for the top controls min-height in px.
* @param bottomControlsMinHeightOffset The Y offset for the bottom controls min-height in px.
*/
public void setPositionsForTab(int topControlsOffset, int bottomControlsOffset, public void setPositionsForTab(int topControlsOffset, int bottomControlsOffset,
int topContentOffset, int topControlsMinHeightOffset, int topContentOffset, int topControlsMinHeightOffset,
int bottomControlsMinHeightOffset) { int bottomControlsMinHeightOffset) {
...@@ -931,7 +1017,7 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -931,7 +1017,7 @@ public class ChromeFullscreenManager extends FullscreenManager
mInGesture = true; mInGesture = true;
// TODO(qinmin): Probably there is no need to hide the toast as it will go away // TODO(qinmin): Probably there is no need to hide the toast as it will go away
// by itself. // by itself.
getHtmlApiHandler().hideNotificationToast(); mHtmlApiHandler.hideNotificationToast();
} else if (eventAction == MotionEvent.ACTION_CANCEL } else if (eventAction == MotionEvent.ACTION_CANCEL
|| eventAction == MotionEvent.ACTION_UP) { || eventAction == MotionEvent.ACTION_UP) {
mInGesture = false; mInGesture = false;
...@@ -939,7 +1025,9 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -939,7 +1025,9 @@ public class ChromeFullscreenManager extends FullscreenManager
} }
} }
@Override /**
* Called when scrolling state of the ContentView changed.
*/
public void onContentViewScrollingStateChanged(boolean scrolling) { public void onContentViewScrollingStateChanged(boolean scrolling) {
mContentViewScrolling = scrolling; mContentViewScrolling = scrolling;
if (!scrolling) updateVisuals(); if (!scrolling) updateVisuals();
...@@ -1006,8 +1094,7 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -1006,8 +1094,7 @@ public class ChromeFullscreenManager extends FullscreenManager
} }
/** /**
* Helper method to update offsets in {@link FullscreenManager} and notify offset changes to * Helper method to update offsets and notify offset changes to observers if necessary.
* observers if necessary.
*/ */
private void updateFullscreenManagerOffsets(boolean toNonFullscreen, int topControlsOffset, private void updateFullscreenManagerOffsets(boolean toNonFullscreen, int topControlsOffset,
int bottomControlsOffset, int topContentOffset, int topControlsMinHeightOffset, int bottomControlsOffset, int topContentOffset, int topControlsMinHeightOffset,
...@@ -1126,9 +1213,11 @@ public class ChromeFullscreenManager extends FullscreenManager ...@@ -1126,9 +1213,11 @@ public class ChromeFullscreenManager extends FullscreenManager
showAndroidControls(false); showAndroidControls(false);
} }
@Override /**
* Destroys the FullscreenManager
*/
public void destroy() { public void destroy() {
super.destroy(); mTab = null;
mBrowserVisibilityDelegate.destroy(); mBrowserVisibilityDelegate.destroy();
if (mTabFullscreenObserver != null) mTabFullscreenObserver.destroy(); if (mTabFullscreenObserver != null) mTabFullscreenObserver.destroy();
if (mContentView != null) { if (mContentView != null) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.fullscreen;
import android.view.View;
import android.view.Window;
import androidx.annotation.Nullable;
import org.chromium.chrome.browser.fullscreen.FullscreenHtmlApiHandler.FullscreenHtmlApiDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.WebContents;
/**
* Manages the basic fullscreen functionality required by a Tab.
*/
// TODO(tedchoc): Remove Tab's requirement on the fullscreen tokens to slim down the API of this
// class.
public abstract class FullscreenManager {
private final FullscreenHtmlApiHandler mHtmlApiHandler;
@Nullable private Tab mTab;
/**
* Constructs the basic ChromeTab oriented FullscreenManager.
*
* @param window Top-level window to turn to fullscreen.
*/
public FullscreenManager(Window window) {
mHtmlApiHandler = new FullscreenHtmlApiHandler(window, createApiDelegate());
}
/**
* @return The delegate that will handle the embedder specific requirements of the
* fullscreen API handler.
*/
protected abstract FullscreenHtmlApiDelegate createApiDelegate();
/**
* @return The handler for managing interactions with the HTML fullscreen API.
*/
protected FullscreenHtmlApiHandler getHtmlApiHandler() {
return mHtmlApiHandler;
}
/**
* Updates the positions of the browser controls and content to the default non fullscreen
* values.
*/
public abstract void setPositionsForTabToNonFullscreen();
/**
* Updates the positions of the browser controls and content based on the desired position of
* the current tab.
* @param topControlsOffset The Y offset of the top controls in px.
* @param bottomControlsOffset The Y offset of the bottom controls in px.
* @param topContentOffset The Y offset for the content in px.
* @param topControlsMinHeightOffset The Y offset for the top controls min-height in px.
* @param bottomControlsMinHeightOffset The Y offset for the bottom controls min-height in px.
*/
public abstract void setPositionsForTab(int topControlsOffset, int bottomControlsOffset,
int topContentOffset, int topControlsMinHeightOffset,
int bottomControlsMinHeightOffset);
/**
* Updates the current ContentView's children and any popups with the correct offsets based on
* the current fullscreen state.
*/
public abstract void updateContentViewChildrenState();
/**
* Sets the currently selected tab for fullscreen.
*/
public void setTab(@Nullable Tab tab) {
if (mTab == tab) return;
mTab = tab;
}
/**
* @return The currently selected tab for fullscreen.
*/
@Nullable public Tab getTab() {
return mTab;
}
/**
* Enters persistent fullscreen mode. In this mode, the browser controls will be
* permanently hidden until this mode is exited.
*/
protected void enterPersistentFullscreenMode(FullscreenOptions options) {
mHtmlApiHandler.enterPersistentFullscreenMode(options);
updateMultiTouchZoomSupport(false);
}
/**
* Exits persistent fullscreen mode. In this mode, the browser controls will be
* permanently hidden until this mode is exited.
*/
public void exitPersistentFullscreenMode() {
mHtmlApiHandler.exitPersistentFullscreenMode();
updateMultiTouchZoomSupport(true);
}
/**
* @see GestureListenerManager#updateMultiTouchZoomSupport(boolean).
*/
protected void updateMultiTouchZoomSupport(boolean enable) {
Tab tab = getTab();
if (tab == null || tab.isHidden()) return;
WebContents webContents = tab.getWebContents();
if (webContents != null) {
GestureListenerManager manager = GestureListenerManager.fromWebContents(webContents);
if (manager != null) manager.updateMultiTouchZoomSupport(enable);
}
}
/**
* @return Whether the application is in persistent fullscreen mode.
* @see #setPersistentFullscreenMode(boolean)
*/
public boolean getPersistentFullscreenMode() {
return mHtmlApiHandler.getPersistentFullscreenMode();
}
/**
* Notified when the system UI visibility for the current ContentView has changed.
* @param visibility The updated UI visibility.
* @see View#getSystemUiVisibility()
*/
public void onContentViewSystemUiVisibilityChange(int visibility) {
mHtmlApiHandler.onContentViewSystemUiVisibilityChange(visibility);
}
/**
* Ensure the proper system UI flags are set after the window regains focus.
* @see android.app.Activity#onWindowFocusChanged(boolean)
*/
public void onWindowFocusChanged(boolean hasWindowFocus) {
mHtmlApiHandler.onWindowFocusChanged(hasWindowFocus);
}
/**
* Called when scrolling state of the ContentView changed.
*/
public void onContentViewScrollingStateChanged(boolean scrolling) {}
/**
* Destroys the FullscreenManager
*/
public void destroy() {
setTab(null);
}
}
...@@ -21,7 +21,7 @@ public final class TabGestureStateListener extends TabWebContentsUserData { ...@@ -21,7 +21,7 @@ public final class TabGestureStateListener extends TabWebContentsUserData {
private final Tab mTab; private final Tab mTab;
private GestureStateListener mGestureListener; private GestureStateListener mGestureListener;
private FullscreenManager mFullscreenManager; private ChromeFullscreenManager mFullscreenManager;
/** /**
* Creates TabGestureStateListener and lets the WebContentsUserData of the Tab manage it. * Creates TabGestureStateListener and lets the WebContentsUserData of the Tab manage it.
...@@ -45,7 +45,7 @@ public final class TabGestureStateListener extends TabWebContentsUserData { ...@@ -45,7 +45,7 @@ public final class TabGestureStateListener extends TabWebContentsUserData {
* Set {@link FullscreenManager} instance. This is non-null for active tab. * Set {@link FullscreenManager} instance. This is non-null for active tab.
* @param manager FullscreenManager instance. * @param manager FullscreenManager instance.
*/ */
void setFullscreenManager(FullscreenManager manager) { void setFullscreenManager(ChromeFullscreenManager manager) {
mFullscreenManager = manager; mFullscreenManager = manager;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment