Commit c3b5aad8 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

android: separates GestureStateListener into two interfaces

To fully support onScrollOffsetOrExtentChanged() comes at a performance
cost. As very few places actually need this, this creates a new interface
with onScrollOffsetOrExtentChanged() and converts the places that need it
to the new interface.

BUG=1087480
TEST=none

Change-Id: I1f54bdf74ee0b6006fc92284bc761ed6992a0d55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225548
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774422}
parent 75401d49
...@@ -801,11 +801,6 @@ public class AwContents implements SmartClipProvider { ...@@ -801,11 +801,6 @@ public class AwContents implements SmartClipProvider {
public void onScaleLimitsChanged(float minPageScaleFactor, float maxPageScaleFactor) { public void onScaleLimitsChanged(float minPageScaleFactor, float maxPageScaleFactor) {
mZoomControls.updateZoomControls(); mZoomControls.updateZoomControls();
} }
@Override
public void onScrollOffsetOrExtentChanged(int scrollOffsetY, int scrollExtentY) {
mZoomControls.updateZoomControls();
}
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
......
...@@ -25,7 +25,7 @@ import org.chromium.base.annotations.CalledByNative; ...@@ -25,7 +25,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.content_public.browser.GestureListenerManager; import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.GestureStateListener; import org.chromium.content_public.browser.GestureStateListenerWithScroll;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver; import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
...@@ -90,7 +90,7 @@ public class PopupTouchHandleDrawable extends View implements DisplayAndroidObse ...@@ -90,7 +90,7 @@ public class PopupTouchHandleDrawable extends View implements DisplayAndroidObse
private boolean mRotationChanged; private boolean mRotationChanged;
// Gesture accounting for handle hiding while scrolling. // Gesture accounting for handle hiding while scrolling.
private final GestureStateListener mGestureStateListener; private final GestureStateListenerWithScroll mGestureStateListener;
// There are no guarantees that the side effects of setting the position of // There are no guarantees that the side effects of setting the position of
// the PopupWindow and the visibility of its content View will be realized // the PopupWindow and the visibility of its content View will be realized
...@@ -143,7 +143,7 @@ public class PopupTouchHandleDrawable extends View implements DisplayAndroidObse ...@@ -143,7 +143,7 @@ public class PopupTouchHandleDrawable extends View implements DisplayAndroidObse
mParentPositionObserver = new ViewPositionObserver(containerView); mParentPositionObserver = new ViewPositionObserver(containerView);
mParentPositionListener = (x, y) -> updateParentPosition(x, y); mParentPositionListener = (x, y) -> updateParentPosition(x, y);
mGestureStateListener = new GestureStateListener() { mGestureStateListener = new GestureStateListenerWithScroll() {
@Override @Override
public void onScrollStarted(int scrollOffsetX, int scrollOffsetY) { public void onScrollStarted(int scrollOffsetX, int scrollOffsetY) {
setIsScrolling(true); setIsScrolling(true);
......
...@@ -21,7 +21,7 @@ import androidx.annotation.IntDef; ...@@ -21,7 +21,7 @@ import androidx.annotation.IntDef;
import org.chromium.base.MathUtils; import org.chromium.base.MathUtils;
import org.chromium.content_public.browser.GestureListenerManager; import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.GestureStateListener; import org.chromium.content_public.browser.GestureStateListenerWithScroll;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -58,7 +58,7 @@ public abstract class SwipableOverlayView extends FrameLayout { ...@@ -58,7 +58,7 @@ public abstract class SwipableOverlayView extends FrameLayout {
private static final long ANIMATION_DURATION_MS = 250; private static final long ANIMATION_DURATION_MS = 250;
/** Detects when the user is dragging the WebContents. */ /** Detects when the user is dragging the WebContents. */
private final GestureStateListener mGestureStateListener; private final GestureStateListenerWithScroll mGestureStateListener;
/** Listens for changes in the layout. */ /** Listens for changes in the layout. */
private final View.OnLayoutChangeListener mLayoutChangeListener; private final View.OnLayoutChangeListener mLayoutChangeListener;
...@@ -202,10 +202,10 @@ public abstract class SwipableOverlayView extends FrameLayout { ...@@ -202,10 +202,10 @@ public abstract class SwipableOverlayView extends FrameLayout {
/** /**
* Creates a listener than monitors the WebContents for scrolls and flings. * Creates a listener than monitors the WebContents for scrolls and flings.
* The listener updates the location of this View to account for the user's gestures. * The listener updates the location of this View to account for the user's gestures.
* @return GestureStateListener to send to the WebContents. * @return GestureStateListenerWithScroll to send to the WebContents.
*/ */
private GestureStateListener createGestureStateListener() { private GestureStateListenerWithScroll createGestureStateListener() {
return new GestureStateListener() { return new GestureStateListenerWithScroll() {
/** Tracks the previous event's scroll offset to determine if a scroll is up or down. */ /** Tracks the previous event's scroll offset to determine if a scroll is up or down. */
private int mLastScrollOffsetY; private int mLastScrollOffsetY;
......
...@@ -282,6 +282,7 @@ android_library("content_java") { ...@@ -282,6 +282,7 @@ android_library("content_java") {
"java/src/org/chromium/content_public/browser/DeviceUtils.java", "java/src/org/chromium/content_public/browser/DeviceUtils.java",
"java/src/org/chromium/content_public/browser/GestureListenerManager.java", "java/src/org/chromium/content_public/browser/GestureListenerManager.java",
"java/src/org/chromium/content_public/browser/GestureStateListener.java", "java/src/org/chromium/content_public/browser/GestureStateListener.java",
"java/src/org/chromium/content_public/browser/GestureStateListenerWithScroll.java",
"java/src/org/chromium/content_public/browser/ImageDownloadCallback.java", "java/src/org/chromium/content_public/browser/ImageDownloadCallback.java",
"java/src/org/chromium/content_public/browser/ImeAdapter.java", "java/src/org/chromium/content_public/browser/ImeAdapter.java",
"java/src/org/chromium/content_public/browser/ImeEventObserver.java", "java/src/org/chromium/content_public/browser/ImeEventObserver.java",
......
...@@ -21,6 +21,7 @@ import org.chromium.content.browser.webcontents.WebContentsImpl; ...@@ -21,6 +21,7 @@ import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content.browser.webcontents.WebContentsImpl.UserDataFactory; import org.chromium.content.browser.webcontents.WebContentsImpl.UserDataFactory;
import org.chromium.content_public.browser.GestureListenerManager; import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.GestureStateListener; import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.GestureStateListenerWithScroll;
import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate; import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.GestureEventType; import org.chromium.ui.base.GestureEventType;
...@@ -147,7 +148,11 @@ public class GestureListenerManagerImpl ...@@ -147,7 +148,11 @@ public class GestureListenerManagerImpl
*/ */
public void updateOnScrollChanged(int offset, int extent) { public void updateOnScrollChanged(int offset, int extent) {
for (mIterator.rewind(); mIterator.hasNext();) { for (mIterator.rewind(); mIterator.hasNext();) {
mIterator.next().onScrollOffsetOrExtentChanged(offset, extent); GestureStateListener listener = mIterator.next();
if (listener instanceof GestureStateListenerWithScroll) {
((GestureStateListenerWithScroll) listener)
.onScrollOffsetOrExtentChanged(offset, extent);
}
} }
} }
......
...@@ -12,22 +12,22 @@ public interface GestureStateListener { ...@@ -12,22 +12,22 @@ public interface GestureStateListener {
/** /**
* Called when the pinch gesture starts. * Called when the pinch gesture starts.
*/ */
default public void onPinchStarted() {} public default void onPinchStarted() {}
/** /**
* Called when the pinch gesture ends. * Called when the pinch gesture ends.
*/ */
default public void onPinchEnded() {} public default void onPinchEnded() {}
/** /**
* Called when a fling starts. * Called when a fling starts.
*/ */
default public void onFlingStartGesture(int scrollOffsetY, int scrollExtentY) {} public default void onFlingStartGesture(int scrollOffsetY, int scrollExtentY) {}
/** /**
* Called when a fling has ended. * Called when a fling has ended.
*/ */
default public void onFlingEndGesture(int scrollOffsetY, int scrollExtentY) {} public default void onFlingEndGesture(int scrollOffsetY, int scrollExtentY) {}
/** /**
* Called to indicate that a scroll update gesture had been consumed by the page. * Called to indicate that a scroll update gesture had been consumed by the page.
...@@ -35,58 +35,53 @@ public interface GestureStateListener { ...@@ -35,58 +35,53 @@ public interface GestureStateListener {
* not called when a JS touch handler consumes the event (preventDefault), it is not called * not called when a JS touch handler consumes the event (preventDefault), it is not called
* for JS-initiated scrolling. * for JS-initiated scrolling.
*/ */
default public void onScrollUpdateGestureConsumed() {} public default void onScrollUpdateGestureConsumed() {}
/** /**
* Called when a scroll gesture has started. * Called when a scroll gesture has started.
*/ */
default public void onScrollStarted(int scrollOffsetY, int scrollExtentY) {} public default void onScrollStarted(int scrollOffsetY, int scrollExtentY) {}
/** /**
* Called when a scroll gesture has stopped. * Called when a scroll gesture has stopped.
*/ */
default public void onScrollEnded(int scrollOffsetY, int scrollExtentY) {} public default void onScrollEnded(int scrollOffsetY, int scrollExtentY) {}
/** /**
* Called when the min or max scale factor may have been changed. * Called when the min or max scale factor may have been changed.
*/ */
default public void onScaleLimitsChanged(float minPageScaleFactor, float maxPageScaleFactor) {} public default void onScaleLimitsChanged(float minPageScaleFactor, float maxPageScaleFactor) {}
/**
* Called when the scroll offsets or extents may have changed.
*/
default public void onScrollOffsetOrExtentChanged(int scrollOffsetY, int scrollExtentY) {}
/** /**
* Called at the beginning of any kind of touch event when the user's finger first touches down * Called at the beginning of any kind of touch event when the user's finger first touches down
* onto the screen. The resulting gesture may be a single tap, long-press, or scroll. * onto the screen. The resulting gesture may be a single tap, long-press, or scroll.
*/ */
default public void onTouchDown() {} public default void onTouchDown() {}
/** /**
* Called after a single-tap gesture event was dispatched to the renderer, * Called after a single-tap gesture event was dispatched to the renderer,
* indicating whether or not the gesture was consumed. * indicating whether or not the gesture was consumed.
*/ */
default public void onSingleTap(boolean consumed) {} public default void onSingleTap(boolean consumed) {}
/** /**
* Called after a single-tap gesture event was processed by the renderer, * Called after a single-tap gesture event was processed by the renderer,
* but was not handled. * but was not handled.
*/ */
default public void onShowUnhandledTapUIIfNeeded(int x, int y) {} public default void onShowUnhandledTapUIIfNeeded(int x, int y) {}
/** /**
* Called when the gesture source loses window focus. * Called when the gesture source loses window focus.
*/ */
default public void onWindowFocusChanged(boolean hasWindowFocus) {} public default void onWindowFocusChanged(boolean hasWindowFocus) {}
/** /**
* Called when a long press gesture event was processed by the rendereer. * Called when a long press gesture event was processed by the rendereer.
*/ */
default public void onLongPress() {} public default void onLongPress() {}
/** /**
* Called when the gesture source is being destroyed. * Called when the gesture source is being destroyed.
*/ */
default public void onDestroyed() {} public default void onDestroyed() {}
} }
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content_public.browser;
/**
* Adds notification of changes in scroll offset/extent to GestureStateListener. Tracking changes to
* scroll offset/extent impacts performance, which is why it's separated in its own interface.
*/
public interface GestureStateListenerWithScroll extends GestureStateListener {
/**
* Called when the scroll offsets or extents may have changed.
*/
public default void onScrollOffsetOrExtentChanged(int scrollOffsetY, int scrollExtentY) {}
}
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