Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
index e6f2003ecf5fc2304d299fb03663901130c0dc6e..f7ff60b8772160843bd67b7216fa4c17e19452c4 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java |
@@ -192,6 +192,18 @@ public class NewTabPageRecyclerView extends RecyclerView { |
} |
} |
+ public boolean isPeekingCardVisible() { |
+ return findFirstCard() != null; |
+ } |
+ |
+ public int getPeekingCardTop() { |
+ return findFirstCard().itemView.getTop(); |
+ } |
+ |
+ public int getPeekingCardHeight() { |
+ return findFirstCard().itemView.getHeight(); |
+ } |
+ |
/** |
* Finds the first card in this RecyclerView. |
* @return The viewholder for the first card or null if no card is available. |
@@ -244,4 +256,31 @@ public class NewTabPageRecyclerView extends RecyclerView { |
mCompensationHeight -= itemView.getHeight(); |
assert mCompensationHeight >= 0; |
} |
+ |
+ /** |
+ * If the RecyclerView is currently scrolled to between regionStart and regionEnd, smooth scroll |
+ * out of the region. flipPoint is the threshold used to decide which bound of the region to |
+ * scroll to. It returns whether the view was scrolled. |
+ */ |
+ public boolean scrollOutOfRegion(int regionStart, int flipPoint, int regionEnd) { |
+ // This function is only called when we are using the RecyclerView. |
+ final int currentScroll = computeVerticalScrollOffset(); |
+ |
+ if (currentScroll < regionStart || currentScroll > regionEnd) return false; |
+ |
+ if (currentScroll < flipPoint) { |
+ smoothScrollBy(0, regionStart - currentScroll); |
+ } else { |
+ smoothScrollBy(0, regionEnd - currentScroll); |
+ } |
+ return true; |
+ } |
+ |
+ /** |
+ * If the RecyclerView is currently scrolled to between regionStart and regionEnd, smooth scroll |
+ * out of the region to the nearest edge. |
+ */ |
+ public boolean scrollOutOfRegion(int regionStart, int regionEnd) { |
+ return scrollOutOfRegion(regionStart, (regionStart + regionEnd) / 2, regionEnd); |
+ } |
} |