Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.ntp; | 5 package org.chromium.chrome.browser.ntp; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 private void initializeSearchBoxRecyclerViewScrollHandling() { | 442 private void initializeSearchBoxRecyclerViewScrollHandling() { |
| 443 final Runnable mSnapScrollRunnable = new Runnable() { | 443 final Runnable mSnapScrollRunnable = new Runnable() { |
| 444 @Override | 444 @Override |
| 445 public void run() { | 445 public void run() { |
| 446 assert mPendingSnapScroll; | 446 assert mPendingSnapScroll; |
| 447 | 447 |
| 448 // These calculations only work if the first item is visible (si nce | 448 // These calculations only work if the first item is visible (si nce |
| 449 // computeVerticalScrollOffset only takes into account visible i tems). | 449 // computeVerticalScrollOffset only takes into account visible i tems). |
| 450 // Luckily, we only need to perform the calculations if the firs t item is visible. | 450 // Luckily, we only need to perform the calculations if the firs t item is visible. |
| 451 if (!mRecyclerView.isFirstItemVisible()) return; | 451 if (!mRecyclerView.isFirstItemVisible()) return; |
| 452 int currentScroll = mRecyclerView.computeVerticalScrollOffset(); | 452 final int currentScroll = mRecyclerView.computeVerticalScrollOff set(); |
| 453 | 453 |
| 454 // Scroll to hide all of content view off the top of the page. | 454 // If snapping to Most Likely or to Articles, the omnibox will b e at the top of the |
| 455 // We subtract mContentView.getPaddingTop() to offset the conten ts below the | 455 // page, so offset the scroll so the scroll targets appear below it. |
| 456 // search box. | 456 final int omniBoxHeight = mContentView.getPaddingTop(); |
| 457 int targetScroll = mContentView.getHeight() - mContentView.getPa ddingTop(); | 457 final int topOfMostLikelyScroll = mMostVisitedLayout.getTop() - omniBoxHeight; |
| 458 final int topOfSnippetsScroll = mContentView.getHeight() - omniB oxHeight; | |
| 458 | 459 |
| 459 if (currentScroll > 0 && currentScroll < targetScroll) { | 460 assert currentScroll >= 0; |
| 460 if (currentScroll < mSearchBoxView.getTop()) { | 461 // Do not do any scrolling if the user is currently viewing arti cles. |
| 461 // Scroll to the top. | 462 if (currentScroll > topOfSnippetsScroll) return; |
| 462 mRecyclerView.smoothScrollBy(0, -currentScroll); | 463 |
| 463 } else { | 464 // If Most Likely is fully visible when we are scrolled to the t op, 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...
| |
| 464 // Scroll to the articles. | 465 // snap points: the Top and Articles. |
| 465 mRecyclerView.smoothScrollBy(0, targetScroll - currentSc roll); | 466 // If not, we have three snap points, the Top, Most Likely and A rticles. |
| 466 } | 467 boolean snapToMostLikely = |
| 468 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
| |
| 469 | |
| 470 int targetScroll; | |
| 471 if (currentScroll < mContentView.getHeight() / 3) { | |
| 472 // In either case, if in the top 1/3 of the original NTP, sn ap to the top. | |
| 473 targetScroll = 0; | |
| 474 } else if (snapToMostLikely && currentScroll < mContentView.getH eight() * 2 / 3) { | |
| 475 // If in the middle 1/3 and we are snapping to Most Likely, snap to it. | |
| 476 targetScroll = topOfMostLikelyScroll; | |
| 477 } else { | |
| 478 // Otherwise, snap to the Articles. | |
| 479 targetScroll = topOfSnippetsScroll; | |
| 467 } | 480 } |
| 468 | 481 |
| 482 mRecyclerView.smoothScrollBy(0, targetScroll - currentScroll); | |
| 469 mPendingSnapScroll = false; | 483 mPendingSnapScroll = false; |
| 470 } | 484 } |
| 471 }; | 485 }; |
| 472 | 486 |
| 473 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | 487 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| 474 @Override | 488 @Override |
| 475 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | 489 public void onScrolled(RecyclerView recyclerView, int dx, int dy) { |
| 476 if (mPendingSnapScroll) { | 490 if (mPendingSnapScroll) { |
| 477 mRecyclerView.removeCallbacks(mSnapScrollRunnable); | 491 mRecyclerView.removeCallbacks(mSnapScrollRunnable); |
| 478 mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_D ELAY_MS); | 492 mRecyclerView.postDelayed(mSnapScrollRunnable, SNAP_SCROLL_D ELAY_MS); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 } | 1075 } |
| 1062 | 1076 |
| 1063 private int getVerticalScroll() { | 1077 private int getVerticalScroll() { |
| 1064 if (mUseCardsUi) { | 1078 if (mUseCardsUi) { |
| 1065 return mRecyclerView.computeVerticalScrollOffset(); | 1079 return mRecyclerView.computeVerticalScrollOffset(); |
| 1066 } else { | 1080 } else { |
| 1067 return mScrollView.getScrollY(); | 1081 return mScrollView.getScrollY(); |
| 1068 } | 1082 } |
| 1069 } | 1083 } |
| 1070 } | 1084 } |
| OLD | NEW |