Commit 9fb660c3 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer] Reuse //components-level SwipableOverlayView

//chrome's SwipableOverlayView.java has now been componentized, and
hence //weblayer can reuse it rather than having its own custom copy.
The only change made to this code in //weblayer was to support the fact
that //weblayer needs to add the SwipableOverlayView to its parent at a
specific index. This CL adds that API to the //components-level
SwipableOverlayView.java and eliminates //weblayer's copy in favor of
its using the //components-level class.

Note: I didn't have the existing SwipableOverlayView#addToParentView()
call through to the newly-added
SwipableOverlayView#addToParentViewAtIndex() because the default value
used for the index in the ViewGroup#addView() variant that doesn't take
in an index doesn't seem to be documented publicly anywhere. In
practice it looks like -1 from looking at the ViewGroup.java source, but
I don't want to hardcode that without public documentation.

Bug: 1099169
Change-Id: If159701d611b7eee1a600911ff0b2aa1bda10154
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274390
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784351}
parent 575fcb93
...@@ -133,6 +133,16 @@ public abstract class SwipableOverlayView extends FrameLayout { ...@@ -133,6 +133,16 @@ public abstract class SwipableOverlayView extends FrameLayout {
} }
} }
protected void addToParentViewAtIndex(ViewGroup parentView, int index) {
if (parentView == null) return;
if (getParent() == null) {
parentView.addView(this, index, createLayoutParams());
// Listen for the layout to know when to animate the View coming onto the screen.
addOnLayoutChangeListener(mLayoutChangeListener);
}
}
/** /**
* Removes the SwipableOverlayView from its parent and stops monitoring the WebContents. * Removes the SwipableOverlayView from its parent and stops monitoring the WebContents.
* @return Whether the View was removed from its parent. * @return Whether the View was removed from its parent.
......
...@@ -109,7 +109,6 @@ android_library("java") { ...@@ -109,7 +109,6 @@ android_library("java") {
"org/chromium/weblayer_private/ProfileManager.java", "org/chromium/weblayer_private/ProfileManager.java",
"org/chromium/weblayer_private/RemoteFragmentImpl.java", "org/chromium/weblayer_private/RemoteFragmentImpl.java",
"org/chromium/weblayer_private/SiteSettingsFragmentImpl.java", "org/chromium/weblayer_private/SiteSettingsFragmentImpl.java",
"org/chromium/weblayer_private/SwipableOverlayView.java",
"org/chromium/weblayer_private/TabCallbackProxy.java", "org/chromium/weblayer_private/TabCallbackProxy.java",
"org/chromium/weblayer_private/TabImpl.java", "org/chromium/weblayer_private/TabImpl.java",
"org/chromium/weblayer_private/TranslateCompactInfoBar.java", "org/chromium/weblayer_private/TranslateCompactInfoBar.java",
...@@ -144,6 +143,7 @@ android_library("java") { ...@@ -144,6 +143,7 @@ android_library("java") {
"//base:base_java", "//base:base_java",
"//base:jni_java", "//base:jni_java",
"//components/autofill/android/provider:java", "//components/autofill/android/provider:java",
"//components/browser_ui/banners/android:java",
"//components/browser_ui/client_certificate/android:java", "//components/browser_ui/client_certificate/android:java",
"//components/browser_ui/http_auth/android:java", "//components/browser_ui/http_auth/android:java",
"//components/browser_ui/media/android:java", "//components/browser_ui/media/android:java",
......
...@@ -17,6 +17,7 @@ import androidx.annotation.NonNull; ...@@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.MathUtils; import org.chromium.base.MathUtils;
import org.chromium.components.browser_ui.banners.SwipableOverlayView;
import org.chromium.components.infobars.InfoBar; import org.chromium.components.infobars.InfoBar;
import org.chromium.components.infobars.InfoBarUiItem; import org.chromium.components.infobars.InfoBarUiItem;
import org.chromium.ui.display.DisplayAndroid; import org.chromium.ui.display.DisplayAndroid;
...@@ -185,7 +186,7 @@ public class InfoBarContainerView extends SwipableOverlayView { ...@@ -185,7 +186,7 @@ public class InfoBarContainerView extends SwipableOverlayView {
* Adds this class to the parent view {@link #mParentView}. * Adds this class to the parent view {@link #mParentView}.
*/ */
void addToParentView() { void addToParentView() {
super.addToParentView(mParentView, super.addToParentViewAtIndex(mParentView,
mTab.getBrowser().getViewController().getDesiredInfoBarContainerViewIndex()); mTab.getBrowser().getViewController().getDesiredInfoBarContainerViewIndex());
} }
......
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