| 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.Configuration; | 9 import android.content.res.Configuration; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 int searchBoxX = (int) mSearchBoxView.getX(); | 717 int searchBoxX = (int) mSearchBoxView.getX(); |
| 718 int searchBoxY = (int) mSearchBoxView.getY(); | 718 int searchBoxY = (int) mSearchBoxView.getY(); |
| 719 | 719 |
| 720 bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(), | 720 bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(), |
| 721 searchBoxY + mSearchBoxView.getPaddingTop(), | 721 searchBoxY + mSearchBoxView.getPaddingTop(), |
| 722 searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddi
ngRight(), | 722 searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddi
ngRight(), |
| 723 searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPadd
ingBottom()); | 723 searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPadd
ingBottom()); |
| 724 | 724 |
| 725 translation.set(0, 0); | 725 translation.set(0, 0); |
| 726 | 726 |
| 727 View view = (View) mSearchBoxView.getParent(); | 727 View view = mSearchBoxView; |
| 728 while (view != null) { | 728 while (true) { |
| 729 view = (View) view.getParent(); |
| 730 if (view == null) { |
| 731 // The |mSearchBoxView| is not a child of this view. This can ha
ppen if the |
| 732 // RecyclerView detaches the NewTabPageLayout after it has been
scrolled out of |
| 733 // view. Set the translation to the minimum Y value as an approx
imation. |
| 734 translation.y = Integer.MIN_VALUE; |
| 735 break; |
| 736 } |
| 729 translation.offset(-view.getScrollX(), -view.getScrollY()); | 737 translation.offset(-view.getScrollX(), -view.getScrollY()); |
| 730 if (view == this) break; | 738 if (view == this) break; |
| 731 translation.offset((int) view.getX(), (int) view.getY()); | 739 translation.offset((int) view.getX(), (int) view.getY()); |
| 732 view = (View) view.getParent(); | |
| 733 } | 740 } |
| 734 bounds.offset(translation.x, translation.y); | 741 bounds.offset(translation.x, translation.y); |
| 735 } | 742 } |
| 736 | 743 |
| 737 /** | 744 /** |
| 738 * Sets the listener for search box scroll changes. | 745 * Sets the listener for search box scroll changes. |
| 739 * @param listener The listener to be notified on changes. | 746 * @param listener The listener to be notified on changes. |
| 740 */ | 747 */ |
| 741 void setSearchBoxScrollListener(OnSearchBoxScrollListener listener) { | 748 void setSearchBoxScrollListener(OnSearchBoxScrollListener listener) { |
| 742 mSearchBoxScrollListener = listener; | 749 mSearchBoxScrollListener = listener; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 } | 1124 } |
| 1118 | 1125 |
| 1119 private int getVerticalScroll() { | 1126 private int getVerticalScroll() { |
| 1120 if (mUseCardsUi) { | 1127 if (mUseCardsUi) { |
| 1121 return mRecyclerView.computeVerticalScrollOffset(); | 1128 return mRecyclerView.computeVerticalScrollOffset(); |
| 1122 } else { | 1129 } else { |
| 1123 return mScrollView.getScrollY(); | 1130 return mScrollView.getScrollY(); |
| 1124 } | 1131 } |
| 1125 } | 1132 } |
| 1126 } | 1133 } |
| OLD | NEW |