Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47c0a480 authored by Changwan Ryu's avatar Changwan Ryu
Browse files

[WebView] Listen to window insets change

Overriding these methods in preparation for notch and safe area implementation
for WebView.

A corresponding implementation for Chrome app does this:
https://source.chromium.org/chromium/chromium/src/+/master:components/browser_ui/widget/android/java/src/org/chromium/components/browser_ui/widget/InsetObserverView.java;l=179;drc=b17e62321db0f69a9131d3bb87ab9cef502a0eaf?originalUrl=https:%2F%2Fcs.chromium.org%2F

An alternative would be to call View#setOnApplyWindowInsetsListener(),
but that might not be as straightforward and might conflict with app's own
usage around windowinsets.

Returning null from a default implementation and use super method until
we can actually implement it in the chromium repo.

(Note: I would like to merge this to R if possible.)

Bug: 159610496
Test: CL does not break build/test.
Change-Id: Ic0421d7347e8091e02af6c9d5a24fdb334f37c47
parent a6846ed0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -12805,6 +12805,7 @@ package android.webkit {
    method public void super_computeScroll();
    method public boolean super_dispatchKeyEvent(android.view.KeyEvent);
    method public int super_getScrollBarStyle();
    method @Nullable public android.view.WindowInsets super_onApplyWindowInsets(@Nullable android.view.WindowInsets);
    method public void super_onDrawVerticalScrollBar(android.graphics.Canvas, android.graphics.drawable.Drawable, int, int, int, int);
    method public boolean super_onGenericMotionEvent(android.view.MotionEvent);
    method public boolean super_onHoverEvent(android.view.MotionEvent);
@@ -13007,6 +13008,7 @@ package android.webkit {
    method public android.os.Handler getHandler(android.os.Handler);
    method public default boolean isVisibleToUserForAutofill(int);
    method public void onActivityResult(int, int, android.content.Intent);
    method @Nullable public default android.view.WindowInsets onApplyWindowInsets(@Nullable android.view.WindowInsets);
    method public void onAttachedToWindow();
    method public default boolean onCheckIsTextEditor();
    method public void onConfigurationChanged(android.content.res.Configuration);
+16 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.view.ViewGroup;
import android.view.ViewHierarchyEncoder;
import android.view.ViewStructure;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeProvider;
@@ -2449,6 +2450,14 @@ public class WebView extends AbsoluteLayout
            WebView.super.startActivityForResult(intent, requestCode);
        }

        /**
         * @see View#onApplyWindowInsets(WindowInsets)
         */
        @Nullable
        public WindowInsets super_onApplyWindowInsets(@Nullable WindowInsets insets) {
            return WebView.super.onApplyWindowInsets(insets);
        }

        // ---- Access to non-public methods ----
        public void overScrollBy(int deltaX, int deltaY,
                int scrollX, int scrollY,
@@ -3078,4 +3087,11 @@ public class WebView extends AbsoluteLayout
        encoder.addProperty("webview:url", mProvider.getUrl());
        encoder.addProperty("webview:originalUrl", mProvider.getOriginalUrl());
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        WindowInsets result = mProvider.getViewDelegate().onApplyWindowInsets(insets);
        if (result == null) return super.onApplyWindowInsets(insets);
        return result;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeProvider;
@@ -448,6 +449,12 @@ public interface WebViewProvider {
        default boolean onCheckIsTextEditor() {
            return false;
        }

        @SuppressWarnings("unused")
        @Nullable
        default WindowInsets onApplyWindowInsets(@Nullable WindowInsets insets) {
            return null;
        }
    }

    interface ScrollDelegate {
+2 −0
Original line number Diff line number Diff line
@@ -11649,6 +11649,7 @@ package android.webkit {
    method public void super_computeScroll();
    method public boolean super_dispatchKeyEvent(android.view.KeyEvent);
    method public int super_getScrollBarStyle();
    method @Nullable public android.view.WindowInsets super_onApplyWindowInsets(@Nullable android.view.WindowInsets);
    method public void super_onDrawVerticalScrollBar(android.graphics.Canvas, android.graphics.drawable.Drawable, int, int, int, int);
    method public boolean super_onGenericMotionEvent(android.view.MotionEvent);
    method public boolean super_onHoverEvent(android.view.MotionEvent);
@@ -11851,6 +11852,7 @@ package android.webkit {
    method public android.os.Handler getHandler(android.os.Handler);
    method public default boolean isVisibleToUserForAutofill(int);
    method public void onActivityResult(int, int, android.content.Intent);
    method @Nullable public default android.view.WindowInsets onApplyWindowInsets(@Nullable android.view.WindowInsets);
    method public void onAttachedToWindow();
    method public default boolean onCheckIsTextEditor();
    method public void onConfigurationChanged(android.content.res.Configuration);