Commit 901a3e76 authored by aruslan's avatar aruslan Committed by Commit bot

Disable Reader mode in fullscreen mode or when infobars are shown

BUG=495560,495808

Review URL: https://codereview.chromium.org/1152013007

Cr-Commit-Position: refs/heads/master@{#333164}
parent 3e8d72a3
......@@ -15,6 +15,7 @@ import android.widget.FrameLayout;
import android.widget.LinearLayout;
import org.chromium.base.CalledByNative;
import org.chromium.base.ObserverList;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.Tab;
......@@ -54,6 +55,27 @@ public class InfoBarContainer extends SwipableOverlayView {
void notifyAnimationFinished(int animationType);
}
/**
* An observer that is notified of changes to a {@link InfoBarContainer} object.
*/
public interface InfoBarContainerObserver {
/**
* Called when an {@link InfoBar} is about to be added (before the animation).
* @param container The notifying {@link InfoBarContainer}
* @param infoBar An {@link InfoBar} being added
* @param isFirst Whether the infobar container was empty
*/
void onAddInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isFirst);
/**
* Called when an {@link InfoBar} is about to be removed (before the animation).
* @param container The notifying {@link InfoBarContainer}
* @param infoBar An {@link InfoBar} being removed
* @param isLast Whether the infobar container is going to be empty
*/
void onRemoveInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isLast);
}
private static class InfoBarTransitionInfo {
// InfoBar being animated.
public InfoBar target;
......@@ -111,6 +133,9 @@ public class InfoBarContainer extends SwipableOverlayView {
private Paint mTopBorderPaint;
private final ObserverList<InfoBarContainerObserver> mObservers =
new ObserverList<InfoBarContainerObserver>();
public InfoBarContainer(Context context, int tabId, ViewGroup parentView, Tab tab) {
super(context, null);
tab.addObserver(getTabObserver());
......@@ -147,6 +172,22 @@ public class InfoBarContainer extends SwipableOverlayView {
mNativeInfoBarContainer = nativeInit();
}
/**
* Adds an {@link InfoBarContainerObserver}.
* @param observer The {@link InfoBarContainerObserver} to add.
*/
public void addObserver(InfoBarContainerObserver observer) {
mObservers.addObserver(observer);
}
/**
* Removes a {@link InfoBarContainerObserver}.
* @param observer The {@link InfoBarContainerObserver} to remove.
*/
public void removeObserver(InfoBarContainerObserver observer) {
mObservers.removeObserver(observer);
}
@Override
public void setContentViewCore(ContentViewCore contentViewCore) {
super.setContentViewCore(contentViewCore);
......@@ -254,6 +295,11 @@ public class InfoBarContainer extends SwipableOverlayView {
return;
}
// We notify observers immediately (before the animation starts).
for (InfoBarContainerObserver observer : mObservers) {
observer.onAddInfoBar(this, infoBar, mInfoBars.isEmpty());
}
// We add the infobar immediately to mInfoBars but we wait for the animation to end to
// notify it's been added, as tests rely on this notification but expects the infobar view
// to be available when they get the notification.
......@@ -312,6 +358,11 @@ public class InfoBarContainer extends SwipableOverlayView {
return;
}
// Notify observers immediately, before the animation begins.
for (InfoBarContainerObserver observer : mObservers) {
observer.onRemoveInfoBar(this, infoBar, mInfoBars.isEmpty());
}
// If an InfoBar is told to hide itself before it has a chance to be shown, don't bother
// with animating any of it.
boolean collapseAnimations = false;
......@@ -325,9 +376,7 @@ public class InfoBarContainer extends SwipableOverlayView {
assert !collapseAnimations;
collapseAnimations = true;
}
if (collapseAnimations) {
mInfoBarTransitions.remove(info);
}
if (collapseAnimations) mInfoBarTransitions.remove(info);
}
}
......
......@@ -22,6 +22,9 @@ import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver;
import org.chromium.chrome.browser.dom_distiller.ReaderModePanel.ReaderModePanelHost;
import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection;
import org.chromium.chrome.browser.infobar.InfoBar;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarContainerObserver;
import org.chromium.chrome.browser.tab.ChromeTab;
import org.chromium.components.dom_distiller.content.DistillablePageUtils;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
......@@ -35,7 +38,7 @@ import org.chromium.ui.base.DeviceFormFactor;
* top controls when a reader mode page has finished loading.
*/
public class ReaderModeManager extends EmptyTabObserver
implements ContextualSearchObserver, ReaderModePanelHost {
implements ContextualSearchObserver, InfoBarContainerObserver, ReaderModePanelHost {
/**
* Observer for changes to the current status of reader mode.
......@@ -124,6 +127,8 @@ public class ReaderModeManager extends EmptyTabObserver
ContextualSearchManager contextualSearchManager = getContextualSearchManager(tab);
if (contextualSearchManager != null) contextualSearchManager.removeObserver(this);
if (mTab.getInfoBarContainer() != null) mTab.getInfoBarContainer().removeObserver(this);
if (mReaderModePanel != null) mReaderModePanel.onDestroy();
if (mWebContentsObserver != null) {
......@@ -150,6 +155,19 @@ public class ReaderModeManager extends EmptyTabObserver
}
ContextualSearchManager contextualSearchManager = getContextualSearchManager(tab);
if (contextualSearchManager != null) contextualSearchManager.addObserver(this);
if (tab.getInfoBarContainer() != null) tab.getInfoBarContainer().addObserver(this);
}
@Override
public void onToggleFullscreenMode(Tab tab, boolean enable) {
if (mReaderModePanel == null) return;
if (enable) {
mReaderModePanel.onEnterFullscreen();
} else {
mReaderModePanel.onExitFullscreen();
}
}
// ContextualSearchObserver:
......@@ -163,6 +181,17 @@ public class ReaderModeManager extends EmptyTabObserver
if (mReaderModePanel != null) mReaderModePanel.unhideButtonBar();
}
// InfoBarContainerObserver:
@Override
public void onAddInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isFirst) {
if (isFirst && mReaderModePanel != null) mReaderModePanel.onShowInfobarContainer();
}
@Override
public void onRemoveInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isLast) {
if (isLast && mReaderModePanel != null) mReaderModePanel.onHideInfobarContainer();
}
// ReaderModePanelHost:
// TODO(aruslan): use the one in ChromeSwitches once it's rolled.
......
......@@ -145,6 +145,9 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
private boolean mIsReaderModePanelHidden;
private boolean mIsReaderModePanelDismissed;
private boolean mIsFullscreenModeEntered;
private boolean mIsInfobarContainerShown;
private ContentViewCore mDistilledContentViewCore;
private boolean mDidStartLoad;
private boolean mDidFinishLoad;
......@@ -191,7 +194,6 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
* Destroys the panel and associated resources.
*/
public void onDestroy() {
mLayoutAnimations = null;
hideButtonBar();
}
......@@ -538,20 +540,23 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
animateTo(mX, 1.0f, true);
}
private boolean isReaderModeCurrentlyAllowed() {
return !mIsReaderModePanelHidden && !mIsReaderModePanelDismissed
&& !mIsFullscreenModeEntered && !mIsInfobarContainerShown;
}
private void nonAnimatedUpdateButtomButtonBar() {
final int status = mReaderModeHost.getReaderModeStatus();
final Tab tab = mReaderModeHost.getTab();
if (mReaderModeButtonView != null
&& (status != ReaderModeManager.POSSIBLE || mIsReaderModePanelHidden
|| mIsReaderModePanelDismissed)) {
&& (status != ReaderModeManager.POSSIBLE || !isReaderModeCurrentlyAllowed())) {
mReaderModeButtonView.dismiss(true);
mReaderModeButtonView = null;
return;
}
if (mReaderModeButtonView == null
&& (status == ReaderModeManager.POSSIBLE && !mIsReaderModePanelHidden
&& !mIsReaderModePanelDismissed)) {
&& (status == ReaderModeManager.POSSIBLE && isReaderModeCurrentlyAllowed())) {
mReaderModeButtonView = ReaderModeButtonView.create(tab.getContentViewCore(),
new ReaderModeButtonViewDelegate() {
@Override
......@@ -583,8 +588,7 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
final int status = mReaderModeHost.getReaderModeStatus();
if (isPanelWithinScreenBounds()
&& (status != ReaderModeManager.POSSIBLE
|| mIsReaderModePanelHidden || mIsReaderModePanelDismissed)) {
&& (status != ReaderModeManager.POSSIBLE || !isReaderModeCurrentlyAllowed())) {
animateTo(0.0f, -1.0f, true);
mReaderModeHost.destroyReaderModeControl();
destroyDistilledContentViewCore();
......@@ -593,8 +597,7 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
}
if (!isPanelWithinScreenBounds()
&& (status == ReaderModeManager.POSSIBLE
&& !mIsReaderModePanelHidden && !mIsReaderModePanelDismissed)) {
&& (status == ReaderModeManager.POSSIBLE && isReaderModeCurrentlyAllowed())) {
animateTo(0.0f, 0.0f, true);
mReaderModeHost.createReaderModeControl();
requestUpdate();
......@@ -684,6 +687,8 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
}
private void enterDistilledMode() {
if (!isReaderModeCurrentlyAllowed()) return;
RecordUserAction.record("DomDistiller_DistilledPageOpened");
mSlidingT = -1.0f;
requestUpdate();
......@@ -732,9 +737,8 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
* Hides the reader mode button bar if shown.
*/
public void hideButtonBar() {
if (mIsReaderModePanelHidden) return;
mIsReaderModePanelHidden = true;
mLayoutAnimations = null;
updateBottomButtonBar();
}
......@@ -742,9 +746,8 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
* Dismisses the reader mode button bar if shown.
*/
public void dismissButtonBar() {
if (mIsReaderModePanelDismissed) return;
mIsReaderModePanelDismissed = true;
mLayoutAnimations = null;
updateBottomButtonBar();
}
......@@ -756,6 +759,40 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
updateBottomButtonBar();
}
/**
* Temporarily hides the reader mode button while the video is shown.
*/
public void onEnterFullscreen() {
mIsFullscreenModeEntered = true;
mLayoutAnimations = null;
updateBottomButtonBar();
}
/**
* Re-shows the reader mode button if necessary once the video is exited.
*/
public void onExitFullscreen() {
mIsFullscreenModeEntered = false;
updateBottomButtonBar();
}
/**
* Temporarily hides the reader mode button while the infobars are shown.
*/
public void onShowInfobarContainer() {
mIsInfobarContainerShown = true;
mLayoutAnimations = null;
updateBottomButtonBar();
}
/**
* Re-shows the reader mode button if necessary once the infobars are dismissed.
*/
public void onHideInfobarContainer() {
mIsInfobarContainerShown = false;
updateBottomButtonBar();
}
/**
* @param tab A {@link Tab}.
* @return The panel associated with a given Tab.
......
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