Commit 3b0346f6 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Consolidate scroll status update in GestureListenerManager

The API |isScrollInProgress| is defined in ContentViewCore while
scroll-related state handling is spread across GestureListenerManager
and SelectionPopupController.

This CL tidies it up by moving the API to GestureListenerManager,
and making it the main class that takes care of all the scroll stuff.

Bug: 598880
Change-Id: Ib5abdddd361b93b823465b978aabfe9903d7cf68
Reviewed-on: https://chromium-review.googlesource.com/965863Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544872}
parent 080ebb1f
...@@ -447,8 +447,13 @@ public class Tab ...@@ -447,8 +447,13 @@ public class Tab
private void onScrollingStateChanged() { private void onScrollingStateChanged() {
FullscreenManager fullscreenManager = getFullscreenManager(); FullscreenManager fullscreenManager = getFullscreenManager();
if (fullscreenManager == null) return; if (fullscreenManager == null) return;
fullscreenManager.onContentViewScrollingStateChanged( fullscreenManager.onContentViewScrollingStateChanged(isScrollInProgress());
getContentViewCore() != null && getContentViewCore().isScrollInProgress()); }
private boolean isScrollInProgress() {
WebContents webContents = getWebContents();
if (webContents == null) return false;
return GestureListenerManager.fromWebContents(webContents).isScrollInProgress();
} }
}; };
} }
......
...@@ -92,7 +92,7 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser ...@@ -92,7 +92,7 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser
ContentViewCoreImpl contentViewCore = mWeakContentViewCore.get(); ContentViewCoreImpl contentViewCore = mWeakContentViewCore.get();
if (contentViewCore == null) return; if (contentViewCore == null) return;
contentViewCore.hidePopupsAndClearSelection(); contentViewCore.hidePopupsAndClearSelection();
contentViewCore.resetScrollInProgress(); contentViewCore.getGestureListenerManager().resetScrollInProgress();
} }
} }
...@@ -103,19 +103,19 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser ...@@ -103,19 +103,19 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser
private class ContentGestureStateListener implements GestureStateListener { private class ContentGestureStateListener implements GestureStateListener {
@Override @Override
public void onFlingStartGesture(int scrollOffsetY, int scrollExtentY) { public void onFlingStartGesture(int scrollOffsetY, int scrollExtentY) {
setTouchScrollInProgress(false); getGestureListenerManager().setTouchScrollInProgress(false);
} }
@Override @Override
public void onFlingEndGesture(int scrollOffsetY, int scrollExtentY) { public void onFlingEndGesture(int scrollOffsetY, int scrollExtentY) {
// Note that mTouchScrollInProgress should normally be false at this // Note that mTouchScrollInProgress should normally be false at this
// point, but we reset it anyway as another failsafe. // point, but we reset it anyway as another failsafe.
setTouchScrollInProgress(false); getGestureListenerManager().setTouchScrollInProgress(false);
} }
@Override @Override
public void onScrollStarted(int scrollOffsetY, int scrollExtentY) { public void onScrollStarted(int scrollOffsetY, int scrollExtentY) {
setTouchScrollInProgress(true); getGestureListenerManager().setTouchScrollInProgress(false);
} }
@Override @Override
...@@ -125,7 +125,7 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser ...@@ -125,7 +125,7 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser
@Override @Override
public void onScrollEnded(int scrollOffsetY, int scrollExtentY) { public void onScrollEnded(int scrollOffsetY, int scrollExtentY) {
setTouchScrollInProgress(false); getGestureListenerManager().setTouchScrollInProgress(false);
} }
@Override @Override
...@@ -434,18 +434,6 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser ...@@ -434,18 +434,6 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser
return nativeGetTopControlsShrinkBlinkHeightPixForTesting(mNativeContentViewCore); return nativeGetTopControlsShrinkBlinkHeightPixForTesting(mNativeContentViewCore);
} }
@Override
public boolean isScrollInProgress() {
return getSelectionPopupController().getScrollInProgress()
|| getGestureListenerManager().hasPotentiallyActiveFling();
}
private void setTouchScrollInProgress(boolean touchScrollInProgress) {
final boolean scrollInProgress =
touchScrollInProgress || getGestureListenerManager().hasPotentiallyActiveFling();
getSelectionPopupController().setScrollInProgress(touchScrollInProgress, scrollInProgress);
}
@Override @Override
public void onShow() { public void onShow() {
assert mWebContents != null; assert mWebContents != null;
...@@ -779,20 +767,6 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser ...@@ -779,20 +767,6 @@ public class ContentViewCoreImpl implements ContentViewCore, DisplayAndroidObser
settings.getTextTrackTextSize()); settings.getTextTrackTextSize());
} }
/**
* Reset scroll and fling accounting, notifying listeners as appropriate.
* This is useful as a failsafe when the input stream may have been interruped.
*/
private void resetScrollInProgress() {
if (!isScrollInProgress()) return;
final boolean touchScrollInProgress = getSelectionPopupController().getScrollInProgress();
setTouchScrollInProgress(false);
if (touchScrollInProgress) getGestureListenerManager().updateOnScrollEnd();
getGestureListenerManager().resetFlingGesture();
}
// DisplayAndroidObserver method. // DisplayAndroidObserver method.
@Override @Override
public void onRotationChanged(int rotation) { public void onRotationChanged(int rotation) {
......
...@@ -11,6 +11,7 @@ import org.chromium.base.ObserverList.RewindableIterator; ...@@ -11,6 +11,7 @@ import org.chromium.base.ObserverList.RewindableIterator;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.content.browser.selection.SelectionPopupControllerImpl;
import org.chromium.content.browser.webcontents.WebContentsImpl; import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content.browser.webcontents.WebContentsUserData; import org.chromium.content.browser.webcontents.WebContentsUserData;
import org.chromium.content.browser.webcontents.WebContentsUserData.UserDataFactory; import org.chromium.content.browser.webcontents.WebContentsUserData.UserDataFactory;
...@@ -46,6 +47,13 @@ public class GestureListenerManagerImpl implements GestureListenerManager, Windo ...@@ -46,6 +47,13 @@ public class GestureListenerManagerImpl implements GestureListenerManager, Windo
private long mNativeGestureListenerManager; private long mNativeGestureListenerManager;
/**
* Whether a touch scroll sequence is active, used to hide text selection
* handles. Note that a scroll sequence will *always* bound a pinch
* sequence, so this will also be true for the duration of a pinch gesture.
*/
private boolean mIsTouchScrollInProgress;
/** /**
* @param webContents {@link WebContents} object. * @param webContents {@link WebContents} object.
* @return {@link GestureListenerManager} object used for the give WebContents. * @return {@link GestureListenerManager} object used for the give WebContents.
...@@ -268,6 +276,36 @@ public class GestureListenerManagerImpl implements GestureListenerManager, Windo ...@@ -268,6 +276,36 @@ public class GestureListenerManagerImpl implements GestureListenerManager, Windo
TraceEvent.end("GestureListenerManagerImpl:updateScrollInfo"); TraceEvent.end("GestureListenerManagerImpl:updateScrollInfo");
} }
@Override
public boolean isScrollInProgress() {
return mIsTouchScrollInProgress || hasPotentiallyActiveFling();
}
void setTouchScrollInProgress(boolean touchScrollInProgress) {
mIsTouchScrollInProgress = touchScrollInProgress;
// Use the active touch scroll signal for hiding. The animation movement
// by fling will naturally hide the ActionMode by invalidating its content rect.
getSelectionPopupController().setScrollInProgress(touchScrollInProgress);
}
/**
* Reset scroll and fling accounting, notifying listeners as appropriate.
* This is useful as a failsafe when the input stream may have been interruped.
*/
void resetScrollInProgress() {
if (!isScrollInProgress()) return;
final boolean touchScrollInProgress = mIsTouchScrollInProgress;
setTouchScrollInProgress(false);
if (touchScrollInProgress) updateOnScrollEnd();
resetFlingGesture();
}
private SelectionPopupControllerImpl getSelectionPopupController() {
return SelectionPopupControllerImpl.fromWebContents(mWebContents);
}
/** /**
* Offer a long press gesture to the embedding View, primarily for WebView compatibility. * Offer a long press gesture to the embedding View, primarily for WebView compatibility.
* *
......
...@@ -41,6 +41,7 @@ import org.chromium.base.annotations.JNINamespace; ...@@ -41,6 +41,7 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.content.R; import org.chromium.content.R;
import org.chromium.content.browser.ContentClassFactory; import org.chromium.content.browser.ContentClassFactory;
import org.chromium.content.browser.GestureListenerManagerImpl;
import org.chromium.content.browser.PopupController; import org.chromium.content.browser.PopupController;
import org.chromium.content.browser.PopupController.HideablePopup; import org.chromium.content.browser.PopupController.HideablePopup;
import org.chromium.content.browser.WindowAndroidChangedObserver; import org.chromium.content.browser.WindowAndroidChangedObserver;
...@@ -162,9 +163,6 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper ...@@ -162,9 +163,6 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper
// SelectionClient was able to classify it, otherwise null. // SelectionClient was able to classify it, otherwise null.
private SelectionClient.Result mClassificationResult; private SelectionClient.Result mClassificationResult;
// Whether a scroll is in progress.
private boolean mScrollInProgress;
private boolean mPreserveSelectionOnNextLossOfFocus; private boolean mPreserveSelectionOnNextLossOfFocus;
private boolean mInitialized; private boolean mInitialized;
...@@ -604,22 +602,12 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper ...@@ -604,22 +602,12 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper
updateTextSelectionUI(false); updateTextSelectionUI(false);
} }
public void setScrollInProgress(boolean touchScrollInProgress, boolean scrollInProgress) {
mScrollInProgress = scrollInProgress;
// The active fling count reflected in |scrollInProgress| isn't reliable with WebView,
// so only use the active touch scroll signal for hiding. The fling animation
// movement will naturally hide the ActionMode by invalidating its content rect.
hideActionMode(touchScrollInProgress);
}
/** /**
* Whether a touch scroll sequence is active, used to hide text selection * Update scroll status.
* handles. Note that a scroll sequence will *always* bound a pinch * @param scrollInProgress {@code true} if scroll is in progress.
* sequence, so this will also be true for the duration of a pinch gesture.
*/ */
public boolean getScrollInProgress() { public void setScrollInProgress(boolean scrollInProgress) {
return mScrollInProgress; hideActionMode(scrollInProgress);
} }
/** /**
...@@ -1256,7 +1244,7 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper ...@@ -1256,7 +1244,7 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper
case SelectionEventType.INSERTION_HANDLE_MOVED: case SelectionEventType.INSERTION_HANDLE_MOVED:
mSelectionRect.set(left, top, right, bottom); mSelectionRect.set(left, top, right, bottom);
if (!mScrollInProgress && isPastePopupShowing()) { if (!getGestureListenerManager().isScrollInProgress() && isPastePopupShowing()) {
showPastePopup(); showPastePopup();
} else { } else {
destroyPastePopup(); destroyPastePopup();
...@@ -1307,6 +1295,10 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper ...@@ -1307,6 +1295,10 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper
} }
} }
private GestureListenerManagerImpl getGestureListenerManager() {
return GestureListenerManagerImpl.fromWebContents(mWebContents);
}
@VisibleForTesting @VisibleForTesting
@CalledByNative @CalledByNative
/* package */ void onDragUpdate(float x, float y) { /* package */ void onDragUpdate(float x, float y) {
......
...@@ -154,11 +154,6 @@ public interface ContentViewCore { ...@@ -154,11 +154,6 @@ public interface ContentViewCore {
*/ */
boolean isAlive(); boolean isAlive();
/**
* @return Whether a scroll targeting web content is in progress.
*/
boolean isScrollInProgress();
/** /**
* To be called when the ContentView is shown. * To be called when the ContentView is shown.
*/ */
......
...@@ -31,4 +31,9 @@ public interface GestureListenerManager { ...@@ -31,4 +31,9 @@ public interface GestureListenerManager {
* @param listener Listener to remove. * @param listener Listener to remove.
*/ */
void removeListener(GestureStateListener listener); void removeListener(GestureStateListener listener);
/**
* @return Whether a scroll targeting web content is in progress.
*/
boolean isScrollInProgress();
} }
...@@ -54,11 +54,6 @@ public class TestContentViewCore implements ContentViewCore { ...@@ -54,11 +54,6 @@ public class TestContentViewCore implements ContentViewCore {
return false; return false;
} }
@Override
public boolean isScrollInProgress() {
return false;
}
@Override @Override
public void onShow() {} public void onShow() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment