| 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..8a3d1878cdef855166d1d250afbec91673436890 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.
|
| @@ -51,15 +52,18 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
|
| // Accessibility utterance used to indicate refresh activation.
|
| private String mAccessibilityRefreshString;
|
|
|
| + // Pointer to the C++ SwipeRefreshHandler
|
| + private long mNativeSwipeRefreshHandler;
|
| +
|
| /**
|
| * Simple constructor to use when creating an OverscrollRefresh instance from code.
|
| *
|
| * @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) {
|
| mTab = tab;
|
| - mContentViewCore = mTab.getContentViewCore();
|
| + mContainerView = mTab.getContentViewCore().getContainerView();
|
|
|
| mSwipeRefreshLayout = new SwipeRefreshLayout(context);
|
| mSwipeRefreshLayout.setLayoutParams(
|
| @@ -78,8 +82,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 +103,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
|
| mSwipeRefreshLayout.post(mDetachLayoutRunnable);
|
| }
|
| });
|
| -
|
| - mContentViewCore.setOverscrollRefreshHandler(this);
|
| + webContents.setOverscrollRefreshHandler(this);
|
| }
|
|
|
| /**
|
| @@ -111,7 +113,6 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
|
| setEnabled(false);
|
| cancelStopRefreshingRunnable();
|
| mSwipeRefreshLayout.setOnRefreshListener(null);
|
| - mContentViewCore.setOverscrollRefreshHandler(null);
|
| }
|
|
|
| /**
|
| @@ -127,12 +128,14 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
|
| }
|
|
|
| @Override
|
| + @CalledByNative
|
| public boolean start() {
|
| attachSwipeRefreshLayoutIfNecessary();
|
| return mSwipeRefreshLayout.start();
|
| }
|
|
|
| @Override
|
| + @CalledByNative
|
| public void pull(float delta) {
|
| TraceEvent.begin("SwipeRefreshHandler.pull");
|
| mSwipeRefreshLayout.pull(delta);
|
| @@ -140,6 +143,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
|
| }
|
|
|
| @Override
|
| + @CalledByNative
|
| public void release(boolean allowRefresh) {
|
| TraceEvent.begin("SwipeRefreshHandler.release");
|
| mSwipeRefreshLayout.release(allowRefresh);
|
| @@ -147,6 +151,7 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
|
| }
|
|
|
| @Override
|
| + @CalledByNative
|
| public void reset() {
|
| cancelStopRefreshingRunnable();
|
| mSwipeRefreshLayout.reset();
|
| @@ -188,14 +193,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);
|
| }
|
| }
|
| }
|
|
|