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

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: address comments 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
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 274e9f1627fd457b5a9932a9264a36713e876abe..a8407b4596e29a9e488539d373923bc63a2007d0 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
@@ -336,7 +336,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.
*/
@@ -393,6 +392,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;
@@ -447,13 +448,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();
}
/**
@@ -598,7 +608,12 @@ public class BottomSheet
private void setSheetOffsetFromBottom(float offset) {
if (MathUtils.areFloatsEqual(getSheetOffsetFromBottom(), getMinOffset())
&& offset > getMinOffset()) {
- onExitPeekState();
+ onSheetOpened();
+ }
+
+ if (MathUtils.areFloatsEqual(offset, getMinOffset())
dgn 2017/02/20 11:37:14 nit: else if to make it more easily spottable that
mdjones 2017/02/21 17:19:10 Done. One option to make this more clear is settin
+ && getSheetOffsetFromBottom() > getMinOffset()) {
+ onSheetClosed();
}
setTranslationY(mContainerHeight - offset);
@@ -606,27 +621,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.
*/
@@ -642,9 +677,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);
}
}

Powered by Google App Engine
This is Rietveld 408576698