Bug 1243070 - Remove obsolete size-change code; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 01 Feb 2016 17:38:14 -0500
changeset 282634 9d7a310cb701aff7072c1ec8aae853fb125ce319
parent 282633 9f0bf58364c731d8c6cec765703fddb9cadf674c
child 282635 28e722408379ed0ee10c8ed73e75914598cb0e4e
push id17362
push usercbook@mozilla.com
push dateTue, 02 Feb 2016 10:54:53 +0000
treeherderfx-team@e5f1b4782e38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1243070
milestone47.0a1
Bug 1243070 - Remove obsolete size-change code; r=snorp Remove obsolete SIZE_CHANGED event and its handler in nsWindow. Also remove some other supporting code (such as gAndroidBounds and the FORCED_RESIZE event) that should be unnecessary by now.
mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java
widget/android/AndroidJavaWrappers.cpp
widget/android/AndroidJavaWrappers.h
widget/android/nsAppShell.cpp
widget/android/nsAppShell.h
widget/android/nsWindow.cpp
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoEvent.java
@@ -63,22 +63,21 @@ public class GeckoEvent {
 
             events.offer(this);
         }
     }
 
     // Make sure to keep these values in sync with the enum in
     // AndroidGeckoEvent in widget/android/AndroidJavaWrappers.h
     @JNITarget
-    private enum NativeGeckoEvent {
+    public enum NativeGeckoEvent {
         NATIVE_POKE(0),
         MOTION_EVENT(2),
         SENSOR_EVENT(3),
         LOCATION_EVENT(5),
-        SIZE_CHANGED(8),
         APP_BACKGROUNDING(9),
         APP_FOREGROUNDING(10),
         LOAD_URI(12),
         NOOP(15),
         BROADCAST(19),
         VIEWPORT(20),
         VISITED(21),
         NETWORK_CHANGED(22),
@@ -465,24 +464,16 @@ public class GeckoEvent {
     }
 
     public static GeckoEvent createLocationEvent(Location l) {
         GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOCATION_EVENT);
         event.mLocation = l;
         return event;
     }
 
-    public static GeckoEvent createSizeChangedEvent(int w, int h, int screenw, int screenh) {
-        GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.SIZE_CHANGED);
-        event.mPoints = new Point[2];
-        event.mPoints[0] = new Point(w, h);
-        event.mPoints[1] = new Point(screenw, screenh);
-        return event;
-    }
-
     @RobocopTarget
     public static GeckoEvent createBroadcastEvent(String subject, String data) {
         GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.BROADCAST);
         event.mCharacters = subject;
         event.mCharactersExtra = data;
         return event;
     }
 
--- a/widget/android/AndroidJavaWrappers.cpp
+++ b/widget/android/AndroidJavaWrappers.cpp
@@ -339,20 +339,16 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jo
     if (!jobj)
         return;
 
     mAction = jenv->GetIntField(jobj, jActionField);
     mType = jenv->GetIntField(jobj, jTypeField);
     mAckNeeded = jenv->GetBooleanField(jobj, jAckNeededField);
 
     switch (mType) {
-        case SIZE_CHANGED:
-            ReadPointArray(mPoints, jenv, jPoints, 2);
-            break;
-
         case NATIVE_GESTURE_EVENT:
             mTime = jenv->GetLongField(jobj, jTimeField);
             mMetaState = jenv->GetIntField(jobj, jMetaStateField);
             mCount = jenv->GetIntField(jobj, jCountField);
             ReadPointArray(mPoints, jenv, jPoints, mCount);
             mX = jenv->GetDoubleField(jobj, jXField);
 
             break;
@@ -515,27 +511,16 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jo
 
 void
 AndroidGeckoEvent::Init(int aType)
 {
     mType = aType;
     mAckNeeded = false;
 }
 
-void
-AndroidGeckoEvent::Init(AndroidGeckoEvent *aResizeEvent)
-{
-    NS_ASSERTION(aResizeEvent->Type() == SIZE_CHANGED, "Init called on non-SIZE_CHANGED event");
-
-    mType = FORCED_RESIZE;
-    mAckNeeded = false;
-    mTime = aResizeEvent->mTime;
-    mPoints = aResizeEvent->mPoints; // x,y coordinates
-}
-
 bool
 AndroidGeckoEvent::CanCoalesceWith(AndroidGeckoEvent* ae)
 {
     if (Type() == MOTION_EVENT && ae->Type() == MOTION_EVENT) {
         return Action() == AndroidMotionEvent::ACTION_MOVE
             && ae->Action() == AndroidMotionEvent::ACTION_MOVE;
     } else if (Type() == APZ_INPUT_EVENT && ae->Type() == APZ_INPUT_EVENT) {
         return mApzInput.mType == MultiTouchInput::MULTITOUCH_MOVE
--- a/widget/android/AndroidJavaWrappers.h
+++ b/widget/android/AndroidJavaWrappers.h
@@ -423,39 +423,32 @@ public:
 class AndroidGeckoEvent : public WrappedJavaObject
 {
 private:
     AndroidGeckoEvent() {
     }
 
     void Init(JNIEnv *jenv, jobject jobj);
     void Init(int aType);
-    void Init(AndroidGeckoEvent *aResizeEvent);
 
 public:
     static void InitGeckoEventClass(JNIEnv *jEnv);
 
     static AndroidGeckoEvent* MakeNativePoke() {
         AndroidGeckoEvent *event = new AndroidGeckoEvent();
         event->Init(NATIVE_POKE);
         return event;
     }
 
     static AndroidGeckoEvent* MakeFromJavaObject(JNIEnv *jenv, jobject jobj) {
         AndroidGeckoEvent *event = new AndroidGeckoEvent();
         event->Init(jenv, jobj);
         return event;
     }
 
-    static AndroidGeckoEvent* CopyResizeEvent(AndroidGeckoEvent *aResizeEvent) {
-        AndroidGeckoEvent *event = new AndroidGeckoEvent();
-        event->Init(aResizeEvent);
-        return event;
-    }
-
     static AndroidGeckoEvent* MakeBroadcastEvent(const nsCString& topic, const nsCString& data) {
         AndroidGeckoEvent* event = new AndroidGeckoEvent();
         event->Init(BROADCAST);
         CopyUTF8toUTF16(topic, event->mCharacters);
         CopyUTF8toUTF16(data, event->mCharactersExtra);
         return event;
     }
 
@@ -638,22 +631,20 @@ protected:
     static jfieldID jGamepadValuesField;
 
 public:
     enum {
         NATIVE_POKE = 0,
         MOTION_EVENT = 2,
         SENSOR_EVENT = 3,
         LOCATION_EVENT = 5,
-        SIZE_CHANGED = 8,
         APP_BACKGROUNDING = 9,
         APP_FOREGROUNDING = 10,
         LOAD_URI = 12,
         NOOP = 15,
-        FORCED_RESIZE = 16, // used internally in nsAppShell/nsWindow
         APZ_INPUT_EVENT = 17, // used internally in AndroidJNI/nsAppShell/nsWindow
         BROADCAST = 19,
         VIEWPORT = 20,
         VISITED = 21,
         NETWORK_CHANGED = 22,
         THUMBNAIL = 25,
         SCREENORIENTATION_CHANGED = 27,
         NATIVE_GESTURE_EVENT = 31,
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -730,25 +730,16 @@ nsAppShell::LegacyGeckoEvent::Run()
         if (NS_SUCCEEDED(rv))
             cmdline->Run();
         free(uri);
         if (flag)
             free(flag);
         break;
     }
 
-    case AndroidGeckoEvent::SIZE_CHANGED: {
-        // store the last resize event to dispatch it to new windows with a FORCED_RESIZE event
-        if (curEvent.get() != gLastSizeChange) {
-            gLastSizeChange = AndroidGeckoEvent::CopyResizeEvent(curEvent.get());
-        }
-        nsWindow::OnGlobalAndroidEvent(curEvent.get());
-        break;
-    }
-
     case AndroidGeckoEvent::VISITED: {
 #ifdef MOZ_ANDROID_HISTORY
         nsCOMPtr<IHistory> history = services::GetHistoryService();
         nsCOMPtr<nsIURI> visitedURI;
         if (history &&
             NS_SUCCEEDED(NS_NewURI(getter_AddRefs(visitedURI),
                                    nsString(curEvent->Characters())))) {
             history->NotifyVisited(visitedURI);
@@ -948,23 +939,16 @@ nsAppShell::LegacyGeckoEvent::PostTo(moz
 
         default:
             queue.insertBack(this);
             break;
         }
     }
 }
 
-void
-nsAppShell::ResendLastResizeEvent(nsWindow* aDest) {
-    if (gLastSizeChange) {
-        nsWindow::OnGlobalAndroidEvent(gLastSizeChange);
-    }
-}
-
 nsresult
 nsAppShell::AddObserver(const nsAString &aObserverKey, nsIObserver *aObserver)
 {
     NS_ASSERTION(aObserver != nullptr, "nsAppShell::AddObserver: aObserver is null!");
     mObserversHash.Put(aObserverKey, aObserver);
     return NS_OK;
 }
 
--- a/widget/android/nsAppShell.h
+++ b/widget/android/nsAppShell.h
@@ -134,18 +134,16 @@ public:
 
     static void PostEvent(mozilla::AndroidGeckoEvent* event);
 
     // Post a event and wait for it to finish running on the Gecko thread.
     static void SyncRunEvent(Event&& event,
                              mozilla::UniquePtr<Event>(*eventFactory)(
                                     mozilla::UniquePtr<Event>&&) = nullptr);
 
-    void ResendLastResizeEvent(nsWindow* aDest);
-
     void SetBrowserApp(nsIAndroidBrowserApp* aBrowserApp) {
         mBrowserApp = aBrowserApp;
     }
 
     void GetBrowserApp(nsIAndroidBrowserApp* *aBrowserApp) {
         *aBrowserApp = mBrowserApp;
     }
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -84,18 +84,16 @@ using mozilla::Unused;
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::widget;
 using namespace mozilla::layers;
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
 
-// The dimensions of the current android view
-static gfx::IntSize gAndroidBounds = gfx::IntSize(0, 0);
 static gfx::IntSize gAndroidScreenBounds;
 
 #include "mozilla/layers/CompositorChild.h"
 #include "mozilla/layers/CompositorParent.h"
 #include "mozilla/layers/LayerTransactionParent.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Services.h"
 #include "nsThreadUtils.h"
@@ -136,17 +134,17 @@ public:
         return NS_OK;
     }
 };
 
 NS_IMPL_ISUPPORTS(ContentCreationNotifier,
                   nsIObserver)
 
 // All the toplevel windows that have been created; these are in
-// stacking order, so the window at gAndroidBounds[0] is the topmost
+// stacking order, so the window at gTopLevelWindows[0] is the topmost
 // one.
 static nsTArray<nsWindow*> gTopLevelWindows;
 
 // FIXME: because we don't support multiple GeckoViews for every feature
 // yet, we have to default to a particular GeckoView for certain calls.
 static nsWindow* gGeckoViewWindow;
 
 static bool sFailedToCreateGLContext = false;
@@ -1150,45 +1148,41 @@ nsWindow::IsTopLevel()
 }
 
 NS_IMETHODIMP
 nsWindow::Create(nsIWidget* aParent,
                  nsNativeWidget aNativeParent,
                  const LayoutDeviceIntRect& aRect,
                  nsWidgetInitData* aInitData)
 {
-    ALOG("nsWindow[%p]::Create %p [%d %d %d %d]", (void*)this, (void*)aParent, aRect.x, aRect.y, aRect.width, aRect.height);
+    ALOG("nsWindow[%p]::Create %p [%d %d %d %d]", (void*)this, (void*)aParent,
+         aRect.x, aRect.y, aRect.width, aRect.height);
+
     nsWindow *parent = (nsWindow*) aParent;
     if (aNativeParent) {
         if (parent) {
-            ALOG("Ignoring native parent on Android window [%p], since parent was specified (%p %p)", (void*)this, (void*)aNativeParent, (void*)aParent);
+            ALOG("Ignoring native parent on Android window [%p], "
+                 "since parent was specified (%p %p)", (void*)this,
+                 (void*)aNativeParent, (void*)aParent);
         } else {
             parent = (nsWindow*) aNativeParent;
         }
     }
 
     mBounds = aRect;
 
-    // for toplevel windows, bounds are fixed to full screen size
-    if (!parent) {
-        mBounds.x = 0;
-        mBounds.y = 0;
-        mBounds.width = gAndroidBounds.width;
-        mBounds.height = gAndroidBounds.height;
-    }
-
     BaseCreate(nullptr, aInitData);
 
-    NS_ASSERTION(IsTopLevel() || parent, "non top level windowdoesn't have a parent!");
+    NS_ASSERTION(IsTopLevel() || parent,
+                 "non-top-level window doesn't have a parent!");
 
     if (IsTopLevel()) {
         gTopLevelWindows.AppendElement(this);
-    }
-
-    if (parent) {
+
+    } else if (parent) {
         parent->mChildren.AppendElement(this);
         mParent = parent;
     }
 
 #ifdef DEBUG_ANDROID_WIDGET
     DumpWindows();
 #endif
 
@@ -1332,20 +1326,19 @@ nsWindow::Show(bool aState)
         // if it's a toplevel widget?
 
         // XXX we should synthesize a eMouseExitFromWidget (for old top
         // window)/eMouseEnterIntoWidget (for new top window) since we need
         // to pretend that the top window always has focus.  Not sure
         // if Show() is the right place to do this, though.
 
         if (aState) {
-            // It just became visible, so send a resize update if necessary
-            // and bring it to the front.
-            Resize(0, 0, gAndroidBounds.width, gAndroidBounds.height, false);
+            // It just became visible, so bring it to the front.
             BringToFront();
+
         } else if (nsWindow::TopWindow() == this) {
             // find the next visible window to show
             unsigned int i;
             for (i = 1; i < gTopLevelWindows.Length(); i++) {
                 nsWindow *win = gTopLevelWindows[i];
                 if (!win->mIsVisible)
                     continue;
 
@@ -1541,45 +1534,34 @@ nsWindow::BringToFront()
     if (!IsTopLevel()) {
         FindTopLevel()->BringToFront();
         return;
     }
 
     RefPtr<nsWindow> kungFuDeathGrip(this);
 
     nsWindow *oldTop = nullptr;
-    nsWindow *newTop = this;
-    if (!gTopLevelWindows.IsEmpty())
+    if (!gTopLevelWindows.IsEmpty()) {
         oldTop = gTopLevelWindows[0];
+    }
 
     gTopLevelWindows.RemoveElement(this);
     gTopLevelWindows.InsertElementAt(0, this);
 
     if (oldTop) {
       nsIWidgetListener* listener = oldTop->GetWidgetListener();
       if (listener) {
           listener->WindowDeactivated();
       }
     }
 
-    if (Destroyed()) {
-        // somehow the deactivate event handler destroyed this window.
-        // try to recover by grabbing the next window in line and activating
-        // that instead
-        if (gTopLevelWindows.IsEmpty())
-            return;
-        newTop = gTopLevelWindows[0];
-    }
-
     if (mWidgetListener) {
         mWidgetListener->WindowActivated();
     }
 
-    // force a window resize
-    nsAppShell::Get()->ResendLastResizeEvent(newTop);
     RedrawAll();
 }
 
 NS_IMETHODIMP
 nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect)
 {
     LayoutDeviceIntPoint p = WidgetToScreenOffset();
 
@@ -1686,86 +1668,16 @@ nsWindow::CreateLayerManager(int aCompos
 void
 nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
 {
     nsWindow *win = TopWindow();
     if (!win)
         return;
 
     switch (ae->Type()) {
-        case AndroidGeckoEvent::FORCED_RESIZE:
-            win->mBounds.width = 0;
-            win->mBounds.height = 0;
-            // also resize the children
-            for (uint32_t i = 0; i < win->mChildren.Length(); i++) {
-                win->mChildren[i]->mBounds.width = 0;
-                win->mChildren[i]->mBounds.height = 0;
-            }
-        case AndroidGeckoEvent::SIZE_CHANGED: {
-            const nsTArray<nsIntPoint>& points = ae->Points();
-            NS_ASSERTION(points.Length() == 2, "Size changed does not have enough coordinates");
-
-            int nw = points[0].x;
-            int nh = points[0].y;
-
-            if (ae->Type() == AndroidGeckoEvent::FORCED_RESIZE || nw != gAndroidBounds.width ||
-                nh != gAndroidBounds.height) {
-                gAndroidBounds.width = nw;
-                gAndroidBounds.height = nh;
-
-                // tell all the windows about the new size
-                for (size_t i = 0; i < gTopLevelWindows.Length(); ++i) {
-                    if (gTopLevelWindows[i]->mIsVisible)
-                        gTopLevelWindows[i]->Resize(gAndroidBounds.width,
-                                                    gAndroidBounds.height,
-                                                    false);
-                }
-            }
-
-            int newScreenWidth = points[1].x;
-            int newScreenHeight = points[1].y;
-
-            if (newScreenWidth == gAndroidScreenBounds.width &&
-                newScreenHeight == gAndroidScreenBounds.height)
-                break;
-
-            gAndroidScreenBounds.width = newScreenWidth;
-            gAndroidScreenBounds.height = newScreenHeight;
-
-            if (!XRE_IsParentProcess() &&
-                !Preferences::GetBool("browser.tabs.remote.desktopbehavior", false)) {
-                break;
-            }
-
-            // Tell the content process the new screen size.
-            nsTArray<ContentParent*> cplist;
-            ContentParent::GetAll(cplist);
-            for (uint32_t i = 0; i < cplist.Length(); ++i)
-                Unused << cplist[i]->SendScreenSizeChanged(gAndroidScreenBounds);
-
-            if (gContentCreationNotifier)
-                break;
-
-            // If the content process is not created yet, wait until it's
-            // created and then tell it the screen size.
-            nsCOMPtr<nsIObserverService> obs =
-                mozilla::services::GetObserverService();
-            if (!obs)
-                break;
-
-            RefPtr<ContentCreationNotifier> notifier = new ContentCreationNotifier;
-            if (NS_SUCCEEDED(obs->AddObserver(notifier, "ipc:content-created", false))) {
-                if (NS_SUCCEEDED(obs->AddObserver(notifier, "xpcom-shutdown", false)))
-                    gContentCreationNotifier = notifier;
-                else
-                    obs->RemoveObserver(notifier, "ipc:content-created");
-            }
-            break;
-        }
-
         case AndroidGeckoEvent::APZ_INPUT_EVENT: {
             win->UserActivity();
 
             WidgetTouchEvent touchEvent = ae->MakeTouchEvent(win);
             win->ProcessUntransformedAPZEvent(&touchEvent, ae->ApzGuid(), ae->ApzInputBlockId(), ae->ApzEventStatus());
             win->DispatchHitTest(touchEvent);
             break;
         }