Skip to content

Commit

Permalink
Bug 1786119 - Set current size to EdgeEffect when reinitializing Over…
Browse files Browse the repository at this point in the history
…scrollEdgeEffect. r=geckoview-reviewers,owlish

When switching to previous tab, overscroll animation doesn't work since new
`EdgeEffect` doesn't have size. So we should set it from previous information.
If new size is available, `GeckoSession.onWindowBoundsChanged` will set new
size.

Also, this fix includes that `OverscrollEdgeEffect` doesn't use current
`GeckoSession` to draw edge effect. When switching to new `GeckoSession`,
we should set it to `OverscrollEdgeEffect`. `OverscrollEdgeEffect` is public
API, so I don't modify it for this.

Differential Revision: https://phabricator.services.mozilla.com/D155144
  • Loading branch information
makotokato committed Aug 26, 2022
1 parent dd21530 commit 236776e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5255,7 +5255,7 @@ default void onScrollChanged(
ThreadUtils.assertOnUiThread();

if (mOverscroll == null) {
mOverscroll = new OverscrollEdgeEffect(this);
mOverscroll = new OverscrollEdgeEffect();
}
return mOverscroll;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ private int defaultColor() {
final GeckoSession session = mSession;
mSession.releaseDisplay(mDisplay.release());
mSession.getOverscrollEdgeEffect().setInvalidationCallback(null);
mSession.getOverscrollEdgeEffect().setSession(null);
mSession.getCompositorController().setFirstPaintCallback(null);

if (mSession.getAccessibility().getView() == this) {
Expand Down Expand Up @@ -525,6 +526,7 @@ public void setSession(@NonNull final GeckoSession session) {

final Context context = getContext();
session.getOverscrollEdgeEffect().setTheme(context);
session.getOverscrollEdgeEffect().setSession(session);
session
.getOverscrollEdgeEffect()
.setInvalidationCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public final class OverscrollEdgeEffect {
// All four edges of the screen
private final EdgeEffect[] mEdges = new EdgeEffect[4];

private final GeckoSession mSession;
private GeckoSession mSession;
private Runnable mInvalidationCallback;
private int mWidth;
private int mHeight;

/* package */ OverscrollEdgeEffect(final GeckoSession session) {
mSession = session;
}
/* package */ OverscrollEdgeEffect() {}

private static Field sPaintField;

Expand All @@ -61,11 +59,18 @@ public void setTheme(final @NonNull Context context) {

for (int i = 0; i < mEdges.length; i++) {
final EdgeEffect edgeEffect = new EdgeEffect(context);
if (mWidth != 0 || mHeight != 0) {
edgeEffect.setSize(mWidth, mHeight);
}
setBlendMode(edgeEffect);
mEdges[i] = edgeEffect;
}
}

/* package */ void setSession(final @Nullable GeckoSession session) {
mSession = session;
}

/**
* Set a Runnable that acts as a callback to invalidate the overscroll effect (for example, as a
* response to user fling for example). The Runnbale should schedule a future call to {@link
Expand Down Expand Up @@ -154,6 +159,10 @@ private EdgeEffect getEdgeForAxisAndSide(final int axis, final float side) {
public void draw(final @NonNull Canvas canvas) {
ThreadUtils.assertOnUiThread();

if (mSession == null) {
return;
}

final Rect pageRect = new Rect();
mSession.getSurfaceBounds(pageRect);

Expand Down

0 comments on commit 236776e

Please sign in to comment.