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

Commit 7ab3d673 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Add API to allow plugins to lock their orientation in full-screen mode.

This CL has companion changes in the browser and webkit.

bug: 3398386
Change-Id: I09eee11e3a22ba3ce0af67e2a068dc7331dc49c2
parent 279ad356
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23391,6 +23391,7 @@ package android.webkit {
    method public void onReceivedTouchIconUrl(android.webkit.WebView, java.lang.String, boolean);
    method public void onRequestFocus(android.webkit.WebView);
    method public void onShowCustomView(android.view.View, android.webkit.WebChromeClient.CustomViewCallback);
    method public void onShowCustomView(android.view.View, int, android.webkit.WebChromeClient.CustomViewCallback);
  }
  public static abstract interface WebChromeClient.CustomViewCallback {
+83 −53
Original line number Diff line number Diff line
@@ -24,34 +24,44 @@
 */
package android.webkit;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

class PluginFullScreenHolder extends Dialog {
class PluginFullScreenHolder {

    private final WebView mWebView;
    private final int mNpp;
    private final int mOrientation;

    // The container for the plugin view
    private static CustomFrameLayout mLayout;

    private View mContentView;

    PluginFullScreenHolder(WebView webView, int npp) {
        super(webView.getContext(), android.R.style.Theme_NoTitleBar_Fullscreen);
    PluginFullScreenHolder(WebView webView, int orientation, int npp) {
        mWebView = webView;
        mNpp = npp;
        mOrientation = orientation;
    }

    @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(

        // Create a FrameLayout that will contain the plugin's view
        mLayout = new CustomFrameLayout(mWebView.getContext());
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            Gravity.CENTER);

        mLayout.addView(contentView, layoutParams);
        mLayout.setVisibility(View.VISIBLE);

        // fixed size is only used either during pinch zoom or surface is too
        // big. Make sure it is not fixed size before setting it to the full
        // screen content view. The SurfaceView will be set to the correct mode
@@ -62,14 +72,28 @@ class PluginFullScreenHolder extends Dialog {
                sView.getHolder().setSizeFromLayout();
            }
        }
        super.setContentView(contentView);

        mContentView = contentView;
    }

    @Override
    public void onBackPressed() {
        mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN)
                .sendToTarget();
    public void show() {
        // Other plugins may attempt to draw so hide them while we're active.
        if (mWebView.getViewManager() != null)
            mWebView.getViewManager().hideAll();

        WebChromeClient client = mWebView.getWebChromeClient();
        client.onShowCustomView(mLayout, mOrientation, mCallback);
    }

    public void hide() {
        WebChromeClient client = mWebView.getWebChromeClient();
        client.onHideCustomView();
    }

    private class CustomFrameLayout extends FrameLayout {

        CustomFrameLayout(Context context) {
            super(context);
        }

        @Override
@@ -104,17 +128,23 @@ class PluginFullScreenHolder extends Dialog {
            // always return true as we are the handler
            return true;
        }

    @Override
    protected void onStop() {
        super.onStop();
        // manually remove the contentView's parent since the dialog does not
        if (mContentView != null && mContentView.getParent() != null) {
            ViewGroup vg = (ViewGroup) mContentView.getParent();
            vg.removeView(mContentView);
    }
    
    private final WebChromeClient.CustomViewCallback mCallback =
        new WebChromeClient.CustomViewCallback() {
            public void onCustomViewHidden() {

                mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN)
                    .sendToTarget();

                mWebView.getWebViewCore().sendMessage(
                        WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
    }

                mLayout.removeView(mContentView);
                mLayout = null;

                // Re enable plugin views.
                mWebView.getViewManager().showAll();
            }
        };
}
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.webkit;

import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Message;
@@ -75,6 +76,18 @@ public class WebChromeClient {
     */
    public void onShowCustomView(View view, CustomViewCallback callback) {};

    /**
     * Notify the host application that the current page would
     * like to show a custom View in a particular orientation.
     * @param view is the View object to be shown.
     * @param requestedOrientation An orientation constant as used in
     * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
     * @param callback is the callback to be invoked if and when the view
     * is dismissed.
     */
    public void onShowCustomView(View view, int requestedOrientation,
            CustomViewCallback callback) {};
    
    /**
     * Notify the host application that the current page would
     * like to hide its custom view.
+4 −5
Original line number Diff line number Diff line
@@ -5543,7 +5543,7 @@ public class WebView extends AbsoluteLayout

    private void dismissFullScreenMode() {
        if (inFullScreenMode()) {
            mFullScreenHolder.dismiss();
            mFullScreenHolder.hide();
            mFullScreenHolder = null;
        }
    }
@@ -8198,16 +8198,15 @@ public class WebView extends AbsoluteLayout

                case SHOW_FULLSCREEN: {
                    View view = (View) msg.obj;
                    int npp = msg.arg1;
                    int orientation = msg.arg1;
                    int npp = msg.arg2;

                    if (inFullScreenMode()) {
                        Log.w(LOGTAG, "Should not have another full screen.");
                        dismissFullScreenMode();
                    }
                    mFullScreenHolder = new PluginFullScreenHolder(WebView.this, npp);
                    mFullScreenHolder = new PluginFullScreenHolder(WebView.this, orientation, npp);
                    mFullScreenHolder.setContentView(view);
                    mFullScreenHolder.setCancelable(false);
                    mFullScreenHolder.setCanceledOnTouchOutside(false);
                    mFullScreenHolder.show();

                    break;
+3 −2
Original line number Diff line number Diff line
@@ -2623,14 +2623,15 @@ public 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, int npp) {
    private void showFullScreenPlugin(ViewManager.ChildView childView, int orientation, int npp) {
        if (mWebView == null) {
            return;
        }

        Message message = mWebView.mPrivateHandler.obtainMessage(WebView.SHOW_FULLSCREEN);
        message.obj = childView.mView;
        message.arg1 = npp;
        message.arg1 = orientation;
        message.arg2 = npp;
        message.sendToTarget();
    }