Bug 702341 - Add a hack to make plugins (mostly) positioned correctly [r=blassey]
authorJames Willcox <snorp@snorp.net>
Mon, 14 Nov 2011 20:22:12 -0500
changeset 83469 b2957d1980e6688e87f6ecf9f9de912d839d4049
parent 83468 fd9a9c599157f8bb899d83c7d1f499fab1886bf5
child 83470 151de04e6bd6a6f27eebe0307691b09081257eb6
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs702341
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 702341 - Add a hack to make plugins (mostly) positioned correctly [r=blassey]
embedding/android/GeckoApp.java
embedding/android/gfx/LayerController.java
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -36,16 +36,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
+import org.mozilla.gecko.gfx.FloatRect;
 import org.mozilla.gecko.gfx.IntRect;
 import org.mozilla.gecko.gfx.IntSize;
 import org.mozilla.gecko.gfx.LayerController;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.gfx.PlaceholderLayerClient;
 import org.mozilla.gecko.Tab.HistoryEntry;
 
 import java.io.*;
@@ -112,16 +113,18 @@ abstract public class GeckoApp
     private IntentFilter mBatteryFilter;
     private BroadcastReceiver mBatteryReceiver;
     private Geocoder mGeocoder;
     private Address  mLastGeoAddress;
     private static LayerController mLayerController;
     private static GeckoSoftwareLayerClient mSoftwareLayerClient;
     boolean mUserDefinedProfile = false;
 
+    private Vector<View> mPluginViews = new Vector<View>();
+
     public interface OnTabsChangedListener {
         public void onTabsChanged();
     }
     
     private static ArrayList<OnTabsChangedListener> mTabsChangedListeners;
 
     static class ExtraMenuItem implements MenuItem.OnMenuItemClickListener {
         String label;
@@ -942,27 +945,29 @@ abstract public class GeckoApp
         }
     }
 
     void addPluginView(final View view,
                        final double x, final double y,
                        final double w, final double h) {
         mMainHandler.post(new Runnable() { 
             public void run() {
-                AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams((int) w, (int) h, (int)x, (int)y);
+                PluginLayoutParams lp = new PluginLayoutParams((int) w, (int) h, (int)x, (int)y);
+                lp.repositionFromVisibleRect(mLayerController.getVisibleRect());
                 if (mGeckoLayout.indexOfChild(view) == -1) {
                     view.setWillNotDraw(false);
                     if (view instanceof SurfaceView) {
                         SurfaceView sview = (SurfaceView)view;
 
                         sview.setZOrderOnTop(false);
                         sview.setZOrderMediaOverlay(true);
                     }
 
                     mGeckoLayout.addView(view, lp);
+                    mPluginViews.add(view);
                 } else {
                     try {
                         mGeckoLayout.updateViewLayout(view, lp);
                     } catch (IllegalArgumentException e) {
                         Log.i("updateViewLayout - IllegalArgumentException", "e:" + e);
                         // it can be the case where we
                         // get an update before the view
                         // is actually attached.
@@ -972,21 +977,30 @@ abstract public class GeckoApp
         });
     }
 
     void removePluginView(final View view) {
         mMainHandler.post(new Runnable() { 
             public void run() {
                 try {
                     mGeckoLayout.removeView(view);
+                    mPluginViews.remove(view);
                 } catch (Exception e) {}
             }
         });
     }
 
+    public void repositionPluginViews() {
+        for (View view : mPluginViews) {
+            PluginLayoutParams lp = (PluginLayoutParams) view.getLayoutParams();
+            lp.repositionFromVisibleRect(mLayerController.getVisibleRect());
+            mGeckoLayout.updateViewLayout(view, lp);
+        }
+    }
+
     public void setFullScreen(final boolean fullscreen) {
         mFullScreen = fullscreen;
         mMainHandler.post(new Runnable() { 
             public void run() {
                 // Hide/show the system notification bar
                 getWindow().setFlags(fullscreen ?
                                      WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
                                      WindowManager.LayoutParams.FLAG_FULLSCREEN);
@@ -1710,9 +1724,27 @@ abstract public class GeckoApp
     }
 
 
     private void connectGeckoLayerClient() {
         LayerController layerController = getLayerController();
         layerController.setLayerClient(mSoftwareLayerClient);
         GeckoAppShell.scheduleRedraw();
     }
+
+    private class PluginLayoutParams extends AbsoluteLayout.LayoutParams
+    {
+        public int originalX;
+        public int originalY;
+
+        public PluginLayoutParams(int width, int height, int aX, int aY) {
+            super(width, height, aX, aY);
+
+            originalX = aX;
+            originalY = aY;
+        }
+
+        public void repositionFromVisibleRect(FloatRect rect) {
+            x = originalX - (int)rect.x;
+            y = originalY - (int)rect.y;
+        }
+    }
 }
--- a/embedding/android/gfx/LayerController.java
+++ b/embedding/android/gfx/LayerController.java
@@ -40,16 +40,17 @@ package org.mozilla.gecko.gfx;
 import org.mozilla.gecko.gfx.FloatPoint;
 import org.mozilla.gecko.gfx.FloatRect;
 import org.mozilla.gecko.gfx.IntRect;
 import org.mozilla.gecko.gfx.IntSize;
 import org.mozilla.gecko.gfx.Layer;
 import org.mozilla.gecko.gfx.LayerClient;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.ui.PanZoomController;
+import org.mozilla.gecko.GeckoApp;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.GestureDetector;
 import android.view.ScaleGestureDetector;
@@ -158,16 +159,17 @@ public class LayerController {
 
     public void scrollTo(float x, float y) {
         setVisibleRect(x, y, mVisibleRect.width, mVisibleRect.height);
     }
 
     public void setVisibleRect(float x, float y, float width, float height) {
         mVisibleRect = new FloatRect(x, y, width, height);
         setNeedsDisplay();
+        GeckoApp.mAppContext.repositionPluginViews();
     }
 
     /**
      * Sets the zoom factor to 1, adjusting the visible rect accordingly. The Gecko layer client
      * calls this function after a zoom has completed and Gecko is done rendering the new visible
      * region.
      */
     public void unzoom() {