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

There is a matching commit in external/webkit

Change-Id: I88d8c533eb821c564c453dfd7293616669b3bf37
diff --git a/core/java/android/webkit/PluginFullScreenHolder.java b/core/java/android/webkit/PluginFullScreenHolder.java
index b641803..6d9e108 100644
--- a/core/java/android/webkit/PluginFullScreenHolder.java
+++ b/core/java/android/webkit/PluginFullScreenHolder.java
@@ -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 @@
 
 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 @@
         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 @@
 
     @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;
     }
 
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index c5a4e9e..3b01b60 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -6508,80 +6508,21 @@
                     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.");
-                            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.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;
+                    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, npp);
+                    mFullScreenHolder.setContentView(view);
+                    mFullScreenHolder.setCancelable(false);
+                    mFullScreenHolder.setCanceledOnTouchOutside(false);
+                    mFullScreenHolder.show();
+
+                    break;
+                }
                 case HIDE_FULLSCREEN:
                     if (inFullScreenMode()) {
                         mFullScreenHolder.dismiss();
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index a274378..4073e37 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -716,14 +716,7 @@
         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 @@
 
     // 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 @@
                 .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,