summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraruslan <aruslan@chromium.org>2015-06-05 15:44:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-05 22:45:25 +0000
commit901a3e766236ed08252799f3a5737f65568c4a49 (patch)
tree8f55fc01630816b4fd7e459c4aaa340e1b631314
parent3e8d72a32a541dd323bd3d1bac6c84ca166c49c1 (diff)
downloadchromium_src-901a3e766236ed08252799f3a5737f65568c4a49.zip
chromium_src-901a3e766236ed08252799f3a5737f65568c4a49.tar.gz
chromium_src-901a3e766236ed08252799f3a5737f65568c4a49.tar.bz2
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}
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java55
-rw-r--r--chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java31
-rw-r--r--chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModePanel.java63
3 files changed, 132 insertions, 17 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java
index 45efdf3..3a7b977 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java
@@ -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);
}
}
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
index e6716e4..2a2f0ed 100644
--- a/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
@@ -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.
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModePanel.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModePanel.java
index 27a7ca5..63bbc06 100644
--- a/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModePanel.java
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/dom_distiller/ReaderModePanel.java
@@ -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();
}
@@ -757,6 +760,40 @@ public class ReaderModePanel implements ChromeAnimation.Animatable<ReaderModePan
}
/**
+ * 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.
*/