Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java |
| index 6543a19062599063a3ac9df68aae16da4a9ff796..4b4fa75df9d6cab20f33938c2b86d9667f5ba64e 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java |
| @@ -5,14 +5,16 @@ |
| package org.chromium.chrome.browser; |
| import android.content.Context; |
| +import android.view.ViewGroup; |
| import android.view.ViewGroup.LayoutParams; |
| import org.chromium.base.TraceEvent; |
| +import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.metrics.RecordUserAction; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.tab.Tab; |
| -import org.chromium.content.browser.ContentViewCore; |
| import org.chromium.content.browser.OverscrollRefreshHandler; |
| +import org.chromium.content_public.browser.WebContents; |
| import org.chromium.third_party.android.swiperefresh.SwipeRefreshLayout; |
| /** |
| @@ -35,10 +37,9 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| // The Tab where the swipe occurs. |
| private Tab mTab; |
| - // The ContentViewCore with which the handler is associated. The handler |
| - // will set/unset itself as the default OverscrollRefreshHandler as the |
| - // association changes. |
| - private ContentViewCore mContentViewCore; |
| + // The container view the SwipeRefreshHandler instance is currently |
| + // associated with. |
| + private ViewGroup mContainerView; |
| // Async runnable for ending the refresh animation after the page first |
| // loads a frame. This is used to provide a reasonable minimum animation time. |
| @@ -57,9 +58,9 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| * @param context The associated context. |
| * @param tab The Tab where the swipe occurs. |
| */ |
| - public SwipeRefreshHandler(Context context, Tab tab) { |
| + public SwipeRefreshHandler(final Context context, Tab tab, WebContents webContents) { |
|
Ted C
2016/12/01 00:53:56
no need to pass in WebContents, mTab.getWebContent
|
| mTab = tab; |
| - mContentViewCore = mTab.getContentViewCore(); |
| + mContainerView = mTab.getContentViewCore().getContainerView(); |
| mSwipeRefreshLayout = new SwipeRefreshLayout(context); |
| mSwipeRefreshLayout.setLayoutParams( |
| @@ -78,8 +79,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| getStopRefreshingRunnable(), MAX_REFRESH_ANIMATION_DURATION_MS); |
| if (mAccessibilityRefreshString == null) { |
| int resId = R.string.accessibility_swipe_refresh; |
| - mAccessibilityRefreshString = |
| - mContentViewCore.getContext().getResources().getString(resId); |
| + mAccessibilityRefreshString = context.getResources().getString(resId); |
| } |
| mSwipeRefreshLayout.announceForAccessibility(mAccessibilityRefreshString); |
| mTab.reload(); |
| @@ -100,8 +100,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| mSwipeRefreshLayout.post(mDetachLayoutRunnable); |
| } |
| }); |
| - |
| - mContentViewCore.setOverscrollRefreshHandler(this); |
| + webContents.setOverscrollRefreshHandler(this); |
| } |
| /** |
| @@ -111,7 +110,6 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| setEnabled(false); |
| cancelStopRefreshingRunnable(); |
| mSwipeRefreshLayout.setOnRefreshListener(null); |
| - mContentViewCore.setOverscrollRefreshHandler(null); |
| } |
| /** |
| @@ -127,12 +125,14 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| } |
| @Override |
| + @CalledByNative |
|
Ted C
2016/12/01 00:53:56
The @CalledByNative should be on the OverscrollRef
|
| public boolean start() { |
| attachSwipeRefreshLayoutIfNecessary(); |
| return mSwipeRefreshLayout.start(); |
| } |
| @Override |
| + @CalledByNative |
| public void pull(float delta) { |
| TraceEvent.begin("SwipeRefreshHandler.pull"); |
| mSwipeRefreshLayout.pull(delta); |
| @@ -140,6 +140,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| } |
| @Override |
| + @CalledByNative |
| public void release(boolean allowRefresh) { |
| TraceEvent.begin("SwipeRefreshHandler.release"); |
| mSwipeRefreshLayout.release(allowRefresh); |
| @@ -147,6 +148,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| } |
| @Override |
| + @CalledByNative |
| public void reset() { |
| cancelStopRefreshingRunnable(); |
| mSwipeRefreshLayout.reset(); |
| @@ -188,14 +190,14 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler { |
| private void attachSwipeRefreshLayoutIfNecessary() { |
| cancelDetachLayoutRunnable(); |
| if (mSwipeRefreshLayout.getParent() == null) { |
| - mContentViewCore.getContainerView().addView(mSwipeRefreshLayout); |
| + mContainerView.addView(mSwipeRefreshLayout); |
| } |
| } |
| private void detachSwipeRefreshLayoutIfNecessary() { |
| cancelDetachLayoutRunnable(); |
| if (mSwipeRefreshLayout.getParent() != null) { |
| - mContentViewCore.getContainerView().removeView(mSwipeRefreshLayout); |
| + mContainerView.removeView(mSwipeRefreshLayout); |
| } |
| } |
| } |