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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheet.java

Issue 2698613006: [Home] Add lifecycle events and some tests (Closed)
Patch Set: fix previous patch Created 3 years, 10 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 | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheetObserver.java » ('j') | 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/widget/BottomSheet.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheet.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheet.java
index e2799f6627bb792ebea71037f4ff1e01f929b7c2..99beafd449779541062384d37a93a26eaa878cf4 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheet.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheet.java
@@ -337,7 +337,6 @@ public class BottomSheet
* Adds layout change listeners to the views that the bottom sheet depends on. Namely the
* heights of the root view and control container are important as they are used in many of the
* calculations in this class.
- * @param activity An activity for loading native pages.
* @param root The container of the bottom sheet.
* @param controlContainer The container for the toolbar.
*/
@@ -394,6 +393,8 @@ public class BottomSheet
@Override
public int loadUrl(LoadUrlParams params) {
+ for (BottomSheetObserver o : mObservers) o.onLoadUrl(params.getUrl());
+
// Native page URLs in this context do not need to communicate with the tab.
if (NativePageFactory.isNativePageUrl(params.getUrl(), isIncognito())) {
return TabLoadStatus.PAGE_LOAD_FAILED;
@@ -448,13 +449,22 @@ public class BottomSheet
/**
* A notification that the sheet is exiting the peek state into one that shows content.
*/
- private void onExitPeekState() {
+ private void onSheetOpened() {
if (mSuggestionsContent == null) {
mSuggestionsContent = new SuggestionsBottomSheetContent(
mTabModelSelector.getCurrentTab().getActivity(), this, mTabModelSelector);
}
showContent(mSuggestionsContent);
+
+ for (BottomSheetObserver o : mObservers) o.onSheetOpened();
+ }
+
+ /**
+ * A notification that the sheet has returned to the peeking state.
+ */
+ private void onSheetClosed() {
+ for (BottomSheetObserver o : mObservers) o.onSheetClosed();
}
/**
@@ -599,7 +609,10 @@ public class BottomSheet
private void setSheetOffsetFromBottom(float offset) {
if (MathUtils.areFloatsEqual(getSheetOffsetFromBottom(), getMinOffset())
&& offset > getMinOffset()) {
- onExitPeekState();
+ onSheetOpened();
+ } else if (MathUtils.areFloatsEqual(offset, getMinOffset())
+ && getSheetOffsetFromBottom() > getMinOffset()) {
+ onSheetClosed();
}
setTranslationY(mContainerHeight - offset);
@@ -607,27 +620,47 @@ public class BottomSheet
}
/**
+ * This is the same as {@link #setSheetOffsetFromBottom(float)} but exclusively for testing.
+ * @param offset The offset to set the sheet to.
+ */
+ @VisibleForTesting
+ public void setSheetOffsetFromBottomForTesting(float offset) {
+ setSheetOffsetFromBottom(offset);
+ }
+
+ /**
* @return The ratio of the height of the screen that the peeking state is.
*/
- private float getPeekRatio() {
+ @VisibleForTesting
+ public float getPeekRatio() {
return mStateRatios[0];
}
/**
* @return The ratio of the height of the screen that the half expanded state is.
*/
- private float getHalfRatio() {
+ @VisibleForTesting
+ public float getHalfRatio() {
return mStateRatios[1];
}
/**
* @return The ratio of the height of the screen that the fully expanded state is.
*/
- private float getFullRatio() {
+ @VisibleForTesting
+ public float getFullRatio() {
return mStateRatios[2];
}
/**
+ * @return The height of the container that the bottom sheet exists in.
+ */
+ @VisibleForTesting
+ public float getSheetContainerHeight() {
+ return mContainerHeight;
+ }
+
+ /**
* Sends a notification if the sheet is transitioning from the peeking to half expanded state.
* This method only sends events when the sheet is between the peeking and half states.
*/
@@ -643,9 +676,9 @@ public class BottomSheet
// If the ratio is close enough to zero, just set it to zero.
if (MathUtils.areFloatsEqual(peekHalfRatio, 0f)) peekHalfRatio = 0f;
- for (BottomSheetObserver o : mObservers) {
- if (mLastPeekToHalfRatioSent < 1f || peekHalfRatio < 1f) {
- mLastPeekToHalfRatioSent = peekHalfRatio;
+ if (mLastPeekToHalfRatioSent < 1f || peekHalfRatio < 1f) {
+ mLastPeekToHalfRatioSent = peekHalfRatio;
+ for (BottomSheetObserver o : mObservers) {
o.onTransitionPeekToHalf(peekHalfRatio);
}
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheetObserver.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698