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

Commit 244e896c authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Allow plugin's surface to handle touch when in full-screen."

parents 4aa44192 c28ff44b
Loading
Loading
Loading
Loading
+8 −32
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@
package android.webkit;

import android.app.Dialog;
import android.graphics.Rect;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
@@ -34,15 +32,9 @@ import android.view.ViewGroup;

class PluginFullScreenHolder extends Dialog {

    private static final String LOGTAG = "FullScreenHolder";

    private final WebView mWebView;
    private final int mNpp;
    private View mContentView;
    private int mX;
    private int mY;
    private int mWidth;
    private int mHeight;

    PluginFullScreenHolder(WebView webView, int npp) {
        super(webView.getContext(), android.R.style.Theme_NoTitleBar_Fullscreen);
@@ -50,23 +42,15 @@ class PluginFullScreenHolder extends Dialog {
        mNpp = npp;
    }

    Rect getBound() {
        return new Rect(mX, mY, mWidth, mHeight);
    }

    /*
     * x, y, width, height are in the caller's view coordinate system. (x, y) is
     * relative to the top left corner of the caller's view.
     */
    void updateBound(int x, int y, int width, int height) {
        mX = x;
        mY = y;
        mWidth = width;
        mHeight = height;
    }

    @Override
    public void setContentView(View contentView) {
        // as we are sharing the View between full screen and
        // embedded mode, we have to remove the
        // AbsoluteLayout.LayoutParams set by embedded mode to
        // ViewGroup.LayoutParams before adding it to the dialog
        contentView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        super.setContentView(contentView);
        mContentView = contentView;
    }
@@ -99,15 +83,7 @@ class PluginFullScreenHolder extends Dialog {

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final float x = event.getX();
        final float y = event.getY();
        // TODO: find a way to know when the dialog size changed so that we can
        // cache the ratio
        final View decorView = getWindow().getDecorView();
        event.setLocation(mX + x * mWidth / decorView.getWidth(),
                mY + y * mHeight / decorView.getHeight());
        mWebView.onTouchEvent(event);
        // always return true as we are the handler
        // always return true as we don't want the event to propagate any further
        return true;
    }

+13 −72
Original line number Diff line number Diff line
@@ -6508,80 +6508,21 @@ public class WebView extends AbsoluteLayout
                    break;

                case SHOW_FULLSCREEN: {
                    WebViewCore.PluginFullScreenData data
                            = (WebViewCore.PluginFullScreenData) msg.obj;
                    if (data.mNpp != 0 && data.mView != null) {
                        if (inFullScreenMode()) {
                            Log.w(LOGTAG,
                                    "Should not have another full screen.");
                    View view = (View) msg.obj;
                    int npp = msg.arg1;

                    if (mFullScreenHolder != null) {
                        Log.w(LOGTAG, "Should not have another full screen.");
                        mFullScreenHolder.dismiss();
                    }
                        mFullScreenHolder = new PluginFullScreenHolder(
                                WebView.this, data.mNpp);
                        // as we are sharing the View between full screen and
                        // embedded mode, we have to remove the
                        // AbsoluteLayout.LayoutParams set by embedded mode to
                        // ViewGroup.LayoutParams before adding it to the dialog
                        data.mView.setLayoutParams(new FrameLayout.LayoutParams(
                                ViewGroup.LayoutParams.FILL_PARENT,
                                ViewGroup.LayoutParams.FILL_PARENT));
                        mFullScreenHolder.setContentView(data.mView);
                    mFullScreenHolder = new PluginFullScreenHolder(WebView.this, npp);
                    mFullScreenHolder.setContentView(view);
                    mFullScreenHolder.setCancelable(false);
                    mFullScreenHolder.setCanceledOnTouchOutside(false);
                    mFullScreenHolder.show();
                    } else if (!inFullScreenMode()) {
                        // this may happen if user dismisses the fullscreen and
                        // then the WebCore re-position message finally reached
                        // the UI thread.

                    break;
                }
                    // move the matching embedded view fully into the view so
                    // that touch will be valid instead of rejected due to out
                    // of the visible bounds
                    // TODO: do we need to preserve the original position and
                    // scale so that we can revert it when leaving the full
                    // screen mode?
                    int x = contentToViewX(data.mDocX);
                    int y = contentToViewY(data.mDocY);
                    int width = contentToViewDimension(data.mDocWidth);
                    int height = contentToViewDimension(data.mDocHeight);
                    int viewWidth = getViewWidth();
                    int viewHeight = getViewHeight();
                    int newX = mScrollX;
                    int newY = mScrollY;
                    if (x < mScrollX) {
                        newX = x + (width > viewWidth
                                ? (width - viewWidth) / 2 : 0);
                    } else if (x + width > mScrollX + viewWidth) {
                        newX = x + width - viewWidth - (width > viewWidth
                                ? (width - viewWidth) / 2 : 0);
                    }
                    if (y < mScrollY) {
                        newY = y + (height > viewHeight
                                ? (height - viewHeight) / 2 : 0);
                    } else if (y + height > mScrollY + viewHeight) {
                        newY = y + height - viewHeight - (height > viewHeight
                                ? (height - viewHeight) / 2 : 0);
                    }
                    scrollTo(newX, newY);
                    if (width > viewWidth || height > viewHeight) {
                        mZoomCenterX = viewWidth * .5f;
                        mZoomCenterY = viewHeight * .5f;
                        // do not change text wrap scale so that there is no
                        // reflow
                        setNewZoomScale(mActualScale
                                / Math.max((float) width / viewWidth,
                                        (float) height / viewHeight), false,
                                false);
                    }
                    // Now update the bound
                    mFullScreenHolder.updateBound(contentToViewX(data.mDocX)
                            - mScrollX, contentToViewY(data.mDocY) - mScrollY,
                            contentToViewDimension(data.mDocWidth),
                            contentToViewDimension(data.mDocHeight));
                    }
                    break;

                case HIDE_FULLSCREEN:
                    if (inFullScreenMode()) {
                        mFullScreenHolder.dismiss();
+6 −36
Original line number Diff line number Diff line
@@ -716,14 +716,7 @@ final class WebViewCore {
        boolean mRemember;
    }

    static class PluginFullScreenData {
        View mView;
        int mNpp;
        int mDocX;
        int mDocY;
        int mDocWidth;
        int mDocHeight;
    }


        static final String[] HandlerDebugString = {
            "REQUEST_LABEL", // 97
@@ -2351,22 +2344,15 @@ final class WebViewCore {

    // called by JNI. PluginWidget function to launch a full-screen view using a
    // View object provided by the plugin class.
    private void showFullScreenPlugin(ViewManager.ChildView childView,
            final int npp, int x, int y, int width, int height) {

    private void showFullScreenPlugin(ViewManager.ChildView childView, int npp) {
        if (mWebView == null) {
            return;
        }

        PluginFullScreenData data = new PluginFullScreenData();
        data.mView = childView.mView;
        data.mNpp = npp;
        data.mDocX = x;
        data.mDocY = y;
        data.mDocWidth = width;
        data.mDocHeight = height;
        mWebView.mPrivateHandler.obtainMessage(WebView.SHOW_FULLSCREEN, data)
                .sendToTarget();
        Message message = mWebView.mPrivateHandler.obtainMessage(WebView.SHOW_FULLSCREEN);
        message.obj = childView.mView;
        message.arg1 = npp;
        message.sendToTarget();
    }

    // called by JNI
@@ -2378,22 +2364,6 @@ final class WebViewCore {
                .sendToTarget();
    }

    // called by JNI
    private void updateFullScreenPlugin(int x, int y, int width, int height) {
        if (mWebView == null) {
            return;
        }

        PluginFullScreenData data = new PluginFullScreenData();
        data.mDocX = x;
        data.mDocY = y;
        data.mDocWidth = width;
        data.mDocHeight = height;
        // null mView and mNpp to indicate it is an update
        mWebView.mPrivateHandler.obtainMessage(WebView.SHOW_FULLSCREEN, data)
                .sendToTarget();
    }

    // called by JNI.  PluginWidget functions for creating an embedded View for
    // the surface drawing model.
    private ViewManager.ChildView addSurface(View pluginView, int x, int y,