Commit 27272354 authored by mdjones's avatar mdjones Committed by Commit bot

Add attachToWindow event to infobar observer

When a user switches tabs while the infobar container is showing,
its state is not saved and it is possible for events in the currently
active tab to reset reader mode's knowledge of the infobars. This
change introduces an event "onInfobarContainerAttachedToWindow" that
notifies observers when the infobar container is attached and if
it needs to show any infobars.

BUG=579036

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

Cr-Commit-Position: refs/heads/master@{#371634}
parent df8e065b
......@@ -85,7 +85,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
private final int mHeaderBackgroundColor;
private boolean mIsFullscreenModeEntered;
private boolean mIsInfobarContainerShown;
private boolean mIsInfoBarContainerShown;
private boolean mIsFindToolbarShowing;
public ReaderModeManager(TabModelSelector selector, ChromeActivity activity) {
......@@ -258,7 +258,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
public void onAddInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isFirst) {
// Temporarily hides the reader mode button while the infobars are shown.
if (isFirst) {
mIsInfobarContainerShown = true;
mIsInfoBarContainerShown = true;
closeReaderPanel(StateChangeReason.INFOBAR_SHOWN, false);
}
}
......@@ -267,7 +267,17 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
public void onRemoveInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isLast) {
// Re-shows the reader mode button if necessary once the infobars are dismissed.
if (isLast) {
mIsInfobarContainerShown = false;
mIsInfoBarContainerShown = false;
requestReaderPanelShow(StateChangeReason.INFOBAR_HIDDEN);
}
}
@Override
public void onInfoBarContainerAttachedToWindow(boolean hasInfoBars) {
mIsInfoBarContainerShown = hasInfoBars;
if (mIsInfoBarContainerShown) {
closeReaderPanel(StateChangeReason.INFOBAR_SHOWN, false);
} else {
requestReaderPanelShow(StateChangeReason.INFOBAR_HIDDEN);
}
}
......@@ -394,7 +404,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
if (mReaderModePanel == null || !mTabStatusMap.containsKey(currentTabId)
|| mTabStatusMap.get(currentTabId).getStatus() != POSSIBLE
|| mTabStatusMap.get(currentTabId).isDismissed()
|| mIsInfobarContainerShown
|| mIsInfoBarContainerShown
|| mIsFindToolbarShowing
|| mIsFullscreenModeEntered
|| DeviceClassManager.isAccessibilityModeEnabled(mChromeActivity)) {
......
......@@ -78,6 +78,12 @@ public class InfoBarContainer extends SwipableOverlayView {
* @param isLast Whether the infobar container is going to be empty
*/
void onRemoveInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isLast);
/**
* Called when the InfobarContainer is attached to the window.
* @param hasInfobars True if infobar container has infobars to show.
*/
void onInfoBarContainerAttachedToWindow(boolean hasInfobars);
}
/** Toggles visibility of the InfoBarContainer when the keyboard appears. */
......@@ -354,6 +360,10 @@ public class InfoBarContainer extends SwipableOverlayView {
setAlpha(0f);
animate().alpha(1f).setDuration(REATTACH_FADE_IN_MS);
}
// Notify observers that the container has attached to the window.
for (InfoBarContainerObserver observer : mObservers) {
observer.onInfoBarContainerAttachedToWindow(!mInfoBars.isEmpty());
}
}
private native long nativeInit();
......
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