Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4516)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java

Issue 1613513004: Prevent Contextual Search from breaking InfoBarContainer visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Logs Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java
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 41e359be4bb4756a2a625c36e9b0a704a3c09122..9394b1fc1618c7ad6e881c1b13fa6d114a06a6de 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
@@ -6,16 +6,21 @@ package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.view.Gravity;
+import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import org.chromium.base.ObserverList;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.banners.SwipableOverlayView;
+import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.browser.WebContents;
+import org.chromium.ui.UiUtils;
import org.chromium.ui.base.DeviceFormFactor;
import java.util.ArrayList;
@@ -34,6 +39,9 @@ public class InfoBarContainer extends SwipableOverlayView {
private static final int TOP_MARGIN_PHONE_DP = 104;
private static final int TOP_MARGIN_TABLET_DP = 144;
+ /** Length of the animation to fade the InfoBarContainer back into View. */
+ private static final long REATTACH_FADE_IN_MS = 250;
+
/** Whether or not the InfoBarContainer is allowed to hide when the user scrolls. */
private static boolean sIsAllowedToAutoHide = true;
@@ -72,13 +80,39 @@ public class InfoBarContainer extends SwipableOverlayView {
void onRemoveInfoBar(InfoBarContainer container, InfoBar infoBar, boolean isLast);
}
+ /** Toggles visibility of the InfoBarContainer when the keyboard appears. */
+ private OnGlobalLayoutListener mGlobalLayoutListener = new OnGlobalLayoutListener() {
newt (away) 2016/01/22 21:43:46 Just realized a downside of using a global layout
gone 2016/01/22 22:11:41 Android doesn't like that: 01-22 14:10:17.992 290
+ @Override
+ public void onGlobalLayout() {
+ // Hide the View when the keyboard is showing.
+ boolean isShowing = (getVisibility() == View.VISIBLE);
+ if (UiUtils.isKeyboardShowing(getContext(), InfoBarContainer.this)) {
+ if (isShowing) {
+ setVisibility(View.GONE);
+ }
+ } else {
+ if (!isShowing && !mIsObscured) {
+ setVisibility(View.VISIBLE);
+ }
+ }
+ }
+ };
+
+ /** Resets the state of the InfoBarContainer when the user navigates. */
+ private final TabObserver mTabObserver = new EmptyTabObserver() {
+ @Override
+ public void onDidNavigateMainFrame(Tab tab, String url, String baseUrl,
+ boolean isNavigationToDifferentPage, boolean isFragmentNavigation,
+ int statusCode) {
+ setIsObscuredByOtherView(false);
+ }
+ };
+
private final InfoBarContainerLayout mLayout;
/** Native InfoBarContainer pointer which will be set by nativeInit(). */
private final long mNativeInfoBarContainer;
- private final Context mContext;
-
/** The list of all InfoBars in this container, regardless of whether they've been shown yet. */
private final ArrayList<InfoBar> mInfoBars = new ArrayList<InfoBar>();
@@ -91,12 +125,15 @@ public class InfoBarContainer extends SwipableOverlayView {
/** Parent view that contains the InfoBarContainerLayout. */
private ViewGroup mParentView;
+ /** Whether or not another View is occupying the same space as this one. */
+ private boolean mIsObscured;
+
private final ObserverList<InfoBarContainerObserver> mObservers =
new ObserverList<InfoBarContainerObserver>();
public InfoBarContainer(Context context, int tabId, ViewGroup parentView, Tab tab) {
super(context, null);
- tab.addObserver(getTabObserver());
+ tab.addObserver(mTabObserver);
// TODO(newt): move this workaround into the infobar views if/when they're scrollable.
// Workaround for http://crbug.com/407149. See explanation in onMeasure() below.
@@ -109,7 +146,6 @@ public class InfoBarContainer extends SwipableOverlayView {
lp.topMargin = Math.round(topMarginDp * getResources().getDisplayMetrics().density);
setLayoutParams(lp);
- mContext = context;
mTabId = tabId;
mParentView = parentView;
@@ -161,6 +197,9 @@ public class InfoBarContainer extends SwipableOverlayView {
private void addToParentView() {
super.addToParentView(mParentView);
+ if (mParentView != null) {
+ mParentView.getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
+ }
}
/**
@@ -175,6 +214,14 @@ public class InfoBarContainer extends SwipableOverlayView {
addToParentView();
}
+ @Override
+ public boolean removeFromParentView() {
+ if (mParentView != null) {
+ mParentView.getViewTreeObserver().removeOnGlobalLayoutListener(mGlobalLayoutListener);
+ }
+ return super.removeFromParentView();
+ }
+
/**
* Adds an InfoBar to the view hierarchy.
* @param infoBar InfoBar to add to the View hierarchy.
@@ -200,7 +247,7 @@ public class InfoBarContainer extends SwipableOverlayView {
// notify it's been added, as tests rely on this notification but expects the infobar view
// to be available when they get the notification.
mInfoBars.add(infoBar);
- infoBar.setContext(mContext);
+ infoBar.setContext(getContext());
infoBar.setInfoBarContainer(this);
infoBar.createView();
@@ -261,6 +308,22 @@ public class InfoBarContainer extends SwipableOverlayView {
}
/**
+ * Tells this class that a View with higher priority is occupying the same space.
+ *
+ * Causes this View to hide itself until the obscuring View goes away.
+ *
+ * @param isObscured Whether this View is obscured by another one.
+ */
+ public void setIsObscuredByOtherView(boolean isObscured) {
+ mIsObscured = isObscured;
+ if (isObscured) {
+ setVisibility(View.GONE);
+ } else {
+ setVisibility(View.VISIBLE);
+ }
+ }
+
+ /**
* Sets whether the InfoBarContainer is allowed to auto-hide when the user scrolls the page.
* Expected to be called when Touch Exploration is enabled.
* @param isAllowed Whether auto-hiding is allowed.
@@ -274,6 +337,16 @@ public class InfoBarContainer extends SwipableOverlayView {
return sIsAllowedToAutoHide;
}
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ if (!mIsObscured) {
+ setVisibility(VISIBLE);
+ setAlpha(0f);
+ animate().alpha(1f).setDuration(REATTACH_FADE_IN_MS);
+ }
+ }
+
private native long nativeInit();
private native void nativeSetWebContents(
long nativeInfoBarContainerAndroid, WebContents webContents);
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698