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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java

Issue 1944783002: Add a third point to snap the scroll to. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | no next file » | 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/ntp/NewTabPageView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
index 5cdc7454ca1192aec1011447890834b5e3ef4bf1..58b58b1ecf6771307c3912d3827895a7bb237942 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java
@@ -449,23 +449,37 @@ public class NewTabPageView extends FrameLayout
// computeVerticalScrollOffset only takes into account visible items).
// Luckily, we only need to perform the calculations if the first item is visible.
if (!mRecyclerView.isFirstItemVisible()) return;
- int currentScroll = mRecyclerView.computeVerticalScrollOffset();
-
- // Scroll to hide all of content view off the top of the page.
- // We subtract mContentView.getPaddingTop() to offset the contents below the
- // search box.
- int targetScroll = mContentView.getHeight() - mContentView.getPaddingTop();
-
- if (currentScroll > 0 && currentScroll < targetScroll) {
- if (currentScroll < mSearchBoxView.getTop()) {
- // Scroll to the top.
- mRecyclerView.smoothScrollBy(0, -currentScroll);
- } else {
- // Scroll to the articles.
- mRecyclerView.smoothScrollBy(0, targetScroll - currentScroll);
- }
+ final int currentScroll = mRecyclerView.computeVerticalScrollOffset();
+
+ // If snapping to Most Likely or to Articles, the omnibox will be at the top of the
+ // page, so offset the scroll so the scroll targets appear below it.
+ final int omniBoxHeight = mContentView.getPaddingTop();
+ final int topOfMostLikelyScroll = mMostVisitedLayout.getTop() - omniBoxHeight;
+ final int topOfSnippetsScroll = mContentView.getHeight() - omniBoxHeight;
+
+ assert currentScroll >= 0;
+ // Do not do any scrolling if the user is currently viewing articles.
+ if (currentScroll > topOfSnippetsScroll) return;
+
+ // If Most Likely is fully visible when we are scrolled to the top, we have two
mcwilliams 2016/05/04 16:07:16 If Most Likely is NOT :) visibile
PEConn 2016/05/04 16:12:02 Nope, I think you misread the comment...
+ // snap points: the Top and Articles.
+ // If not, we have three snap points, the Top, Most Likely and Articles.
+ boolean snapToMostLikely =
+ mRecyclerView.getHeight() < mMostVisitedLayout.getBottom();
May 2016/05/04 15:45:19 Is it possible to have a case where the screen is
PEConn 2016/05/04 15:53:08 The Most Visited is contained within the mContentV
+
+ int targetScroll;
+ if (currentScroll < mContentView.getHeight() / 3) {
+ // In either case, if in the top 1/3 of the original NTP, snap to the top.
+ targetScroll = 0;
+ } else if (snapToMostLikely && currentScroll < mContentView.getHeight() * 2 / 3) {
+ // If in the middle 1/3 and we are snapping to Most Likely, snap to it.
+ targetScroll = topOfMostLikelyScroll;
+ } else {
+ // Otherwise, snap to the Articles.
+ targetScroll = topOfSnippetsScroll;
}
+ mRecyclerView.smoothScrollBy(0, targetScroll - currentScroll);
mPendingSnapScroll = false;
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698