Commit 4b0836bc authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Remove BottomSheet gatherTransparentRegion implementation

This patch removes the gatherTransparentRegion implementation from the
BottomSheet in favor of attaching and detaching the sheet view from
the hierarchy. Gathering the transparent region of a moving view is
difficult since that method is only called on layout. By taking the
view out of the hierarchy, the view is always "transparent" when it is
not visible.

Bug: 876097
Change-Id: I6073903d23b49b963bf2f4b570f6b51389430e42
Reviewed-on: https://chromium-review.googlesource.com/c/1252852
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596713}
parent 636c7ca5
......@@ -12,7 +12,6 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Build;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
......@@ -167,6 +166,9 @@ public class BottomSheet extends FrameLayout
/** The {@link BottomSheetMetrics} used to record user actions and histograms. */
private final BottomSheetMetrics mMetrics;
/** The view that contains the sheet. */
private ViewGroup mSheetContainer;
/** For detecting scroll and fling events on the bottom sheet. */
private BottomSheetSwipeDetector mGestureDetector;
......@@ -511,14 +513,6 @@ public class BottomSheet extends FrameLayout
return true;
}
@Override
public boolean gatherTransparentRegion(Region region) {
// TODO(mdjones): Figure out what this should actually be set to since the view animates
// without necessarily calling this method again.
region.setEmpty();
return true;
}
/**
* @return Whether or not the toolbar Android View is hidden due to being scrolled off-screen.
*/
......@@ -686,6 +680,9 @@ public class BottomSheet extends FrameLayout
@Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {}
});
mSheetContainer = (ViewGroup) this.getParent();
mSheetContainer.removeView(this);
}
@Override
......@@ -1099,6 +1096,13 @@ public class BottomSheet extends FrameLayout
setTranslationY(translationY);
float hiddenHeight = getHiddenRatio() * mContainerHeight;
if (mCurrentOffsetPx <= hiddenHeight && this.getParent() != null) {
mSheetContainer.removeView(this);
} else if (mCurrentOffsetPx > hiddenHeight && this.getParent() == null) {
mSheetContainer.addView(this);
}
float peekHeight = getSheetHeightForState(SheetState.PEEK);
boolean isAtPeekingHeight = MathUtils.areFloatsEqual(getCurrentOffsetPx(), peekHeight);
if (isSheetOpen() && (getCurrentOffsetPx() < peekHeight || isAtPeekingHeight)) {
......@@ -1341,8 +1345,6 @@ public class BottomSheet extends FrameLayout
if (getFocusedChild() == null) requestFocus();
}
setVisibility(mCurrentState == SheetState.HIDDEN ? GONE : VISIBLE);
for (BottomSheetObserver o : mObservers) {
o.onSheetStateChanged(mCurrentState);
}
......
......@@ -346,14 +346,10 @@ public class FullscreenManagerTest {
"Failed to reset scrolling state", gestureListenerManager.isScrollInProgress());
}
/**
* TODO(https://crbug.com/876097): Remove the DisableFeatures block turning off contextual
* suggestions.
*/
@Test
@LargeTest
@Feature({"Fullscreen"})
@Features.DisableFeatures({ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_BUTTON})
@Features.DisableFeatures({ChromeFeatureList.OFFLINE_INDICATOR})
public void testHidingBrowserControlsRemovesSurfaceFlingerOverlay()
throws InterruptedException {
FullscreenManagerTestUtils.disableBrowserOverrides();
......
......@@ -26,14 +26,12 @@ import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.net.test.EmbeddedTestServer;
......@@ -288,13 +286,10 @@ public class InfoBarContainerTest {
/**
* Tests that adding and removing correctly manages the transparent region, which allows for
* optimizations in SurfaceFlinger (less overlays).
* TODO(https://crbug.com/876097): Remove the DisableFeatures block turning off contextual
* suggestions.
*/
@Test
@MediumTest
@Feature({"Browser"})
@Features.DisableFeatures({ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_BUTTON})
public void testAddAndDismissSurfaceFlingerOverlays() throws Exception {
final ViewGroup decorView =
(ViewGroup) mActivityTestRule.getActivity().getWindow().getDecorView();
......
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