Backed out changeset 1d7748535fa3 (bug 1282003)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Thu, 06 Oct 2016 20:37:00 +0200
changeset 421767 1196bb89841328837886df509bb2eca1f8c619d6
parent 421766 7ff5c0b99e1936648eb6209703b8670da757f851
child 421768 54ed443a6951acc52d169114d5989e61c672d644
push id31595
push userbgrinstead@mozilla.com
push dateThu, 06 Oct 2016 21:20:18 +0000
bugs1282003
milestone52.0a1
backs out1d7748535fa370332623ac29e50dd19e1ef6133b
Backed out changeset 1d7748535fa3 (bug 1282003)
gfx/src/nsDeviceContext.cpp
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
widget/android/GeneratedJNIWrappers.h
widget/android/nsWindow.cpp
widget/android/nsWindow.h
widget/nsBaseWidget.h
widget/nsIWidget.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -1,10 +1,9 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim: set sw=4 ts=4 expandtab: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsDeviceContext.h"
 #include <algorithm>                    // for max
 #include "gfxASurface.h"                // for gfxASurface, etc
 #include "gfxContext.h"
@@ -607,25 +606,17 @@ nsDeviceContext::FindScreen(nsIScreen** 
     if (mWidget->GetOwningTabChild()) {
         mScreenManager->ScreenForNativeWidget((void *)mWidget->GetOwningTabChild(),
                                               outScreen);
     }
     else if (mWidget->GetNativeData(NS_NATIVE_WINDOW)) {
         mScreenManager->ScreenForNativeWidget(mWidget->GetNativeData(NS_NATIVE_WINDOW),
                                               outScreen);
     }
-
-#ifdef MOZ_WIDGET_ANDROID
-    if (!(*outScreen)) {
-        nsCOMPtr<nsIScreen> screen = mWidget->GetWidgetScreen();
-        screen.forget(outScreen);
-    }
-#endif
-
-    if (!(*outScreen)) {
+    else {
         mScreenManager->GetPrimaryScreen(outScreen);
     }
 }
 
 bool
 nsDeviceContext::CalcPrintingSize()
 {
     if (!mPrintTarget) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -1,10 +1,9 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * vim: ts=4 sw=4 expandtab:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import java.util.Set;
 
@@ -44,17 +43,16 @@ public class GeckoView extends LayerView
     private static final String LOGTAG = "GeckoView";
 
     private ChromeDelegate mChromeDelegate;
     private ContentDelegate mContentDelegate;
 
     private InputConnectionListener mInputConnectionListener;
 
     private boolean onAttachedToWindowCalled;
-    private int screenId = 0; // default to the primary screen
 
     @Override
     public void handleMessage(final String event, final JSONObject message) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 try {
                     if (event.equals("Gecko:Ready")) {
@@ -111,17 +109,17 @@ public class GeckoView extends LayerView
     }
 
     @WrapForJNI(dispatchTo = "proxy")
     private static final class Window extends JNIObject {
         @WrapForJNI(skip = true)
         /* package */ Window() {}
 
         static native void open(Window instance, GeckoView view, Object compositor,
-                                String chromeURI, int width, int height, int screenId);
+                                String chromeURI, int width, int height);
 
         @Override protected native void disposeNative();
         native void close();
         native void reattach(GeckoView view, Object compositor);
         native void loadUri(String uri, int flags);
     }
 
     // Object to hold onto our nsWindow connection when GeckoView gets destroyed.
@@ -228,22 +226,21 @@ public class GeckoView extends LayerView
 
     private void openWindow() {
         final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
 
         final String chromeURI = getGeckoInterface().getDefaultChromeURI();
 
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
             Window.open(window, this, getCompositor(),
-                        chromeURI, metrics.widthPixels, metrics.heightPixels, screenId);
+                        chromeURI, metrics.widthPixels, metrics.heightPixels);
         } else {
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY, Window.class,
                     "open", window, GeckoView.class, this, Object.class, getCompositor(),
-                    String.class, chromeURI, metrics.widthPixels, metrics.heightPixels,
-                    screenId);
+                    String.class, chromeURI, metrics.widthPixels, metrics.heightPixels);
         }
     }
 
     private void reattachWindow() {
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
             window.reattach(this, getCompositor());
         } else {
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -3271,21 +3271,20 @@ public:
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<
                 Window::Param,
                 GeckoView::Param,
                 mozilla::jni::Object::Param,
                 mozilla::jni::String::Param,
                 int32_t,
-                int32_t,
                 int32_t> Args;
         static constexpr char name[] = "open";
         static constexpr char signature[] =
-                "(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Ljava/lang/String;III)V";
+                "(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Ljava/lang/String;II)V";
         static const bool isStatic = true;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::ANY;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::PROXY;
     };
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1,10 +1,9 @@
 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
- * vim: set sw=4 ts=4 expandtab:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <android/log.h>
 #include <android/native_window.h>
 #include <android/native_window_jni.h>
 #include <math.h>
@@ -342,18 +341,17 @@ private:
     nsCOMPtr<nsPIDOMWindowOuter> mDOMWindow;
 
 public:
     // Create and attach a window.
     static void Open(const jni::Class::LocalRef& aCls,
                      GeckoView::Window::Param aWindow,
                      GeckoView::Param aView, jni::Object::Param aCompositor,
                      jni::String::Param aChromeURI,
-                     int32_t aWidth, int32_t aHeight,
-                     int32_t screenId);
+                     int32_t aWidth, int32_t aHeight);
 
     // Close and destroy the nsWindow.
     void Close();
 
     // Reattach this nsWindow to a new GeckoView.
     void Reattach(const GeckoView::Window::LocalRef& inst,
                   GeckoView::Param aView, jni::Object::Param aCompositor);
 
@@ -1318,18 +1316,17 @@ nsWindow::GeckoViewSupport::~GeckoViewSu
 }
 
 /* static */ void
 nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
                                  GeckoView::Window::Param aWindow,
                                  GeckoView::Param aView,
                                  jni::Object::Param aCompositor,
                                  jni::String::Param aChromeURI,
-                                 int32_t aWidth, int32_t aHeight,
-                                 int32_t aScreenId)
+                                 int32_t aWidth, int32_t aHeight)
 {
     MOZ_ASSERT(NS_IsMainThread());
 
     PROFILER_LABEL("nsWindow", "GeckoViewSupport::Open",
                    js::ProfileEntry::Category::OTHER);
 
     nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
     MOZ_RELEASE_ASSERT(ww);
@@ -1366,17 +1363,16 @@ nsWindow::GeckoViewSupport::Open(const j
     MOZ_RELEASE_ASSERT(domWindow);
 
     nsCOMPtr<nsPIDOMWindowOuter> pdomWindow =
             nsPIDOMWindowOuter::From(domWindow);
     nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(pdomWindow);
     MOZ_ASSERT(widget);
 
     const auto window = static_cast<nsWindow*>(widget.get());
-    window->SetScreenId(aScreenId);
 
     // Attach a new GeckoView support object to the new window.
     window->mGeckoViewSupport  = mozilla::MakeUnique<GeckoViewSupport>(
             window, GeckoView::Window::LocalRef(aCls.Env(), aWindow), aView);
 
     window->mGeckoViewSupport->mDOMWindow = pdomWindow;
 
     // Attach the Compositor to the new window.
@@ -1509,17 +1505,16 @@ nsWindow::DumpWindows(const nsTArray<nsW
     for (uint32_t i = 0; i < wins.Length(); ++i) {
         nsWindow *w = wins[i];
         LogWindow(w, i, indent);
         DumpWindows(w->mChildren, indent+1);
     }
 }
 
 nsWindow::nsWindow() :
-    mScreenId(0), // Use 0 (primary screen) as the default value.
     mIsVisible(false),
     mParent(nullptr),
     mAwaitingFullScreen(false),
     mIsFullScreen(false)
 {
 }
 
 nsWindow::~nsWindow()
@@ -1671,21 +1666,29 @@ nsWindow::GetDPI()
     if (AndroidBridge::Bridge())
         return AndroidBridge::Bridge()->GetDPI();
     return 160.0f;
 }
 
 double
 nsWindow::GetDefaultScaleInternal()
 {
-
-    nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
-    MOZ_ASSERT(screen);
-    RefPtr<nsScreenAndroid> screenAndroid = (nsScreenAndroid*) screen.get();
-    return screenAndroid->GetDensity();
+    static double density = 0.0;
+
+    if (density != 0.0) {
+        return density;
+    }
+
+    density = GeckoAppShell::GetDensity();
+
+    if (!density) {
+        density = 1.0;
+    }
+
+    return density;
 }
 
 NS_IMETHODIMP
 nsWindow::Show(bool aState)
 {
     ALOG("nsWindow[%p]::Show %d", (void*)this, aState);
 
     if (mWindowType == eWindowType_invisible) {
@@ -3607,30 +3610,17 @@ nsWindow::UpdateZoomConstraints(const ui
                                 const mozilla::Maybe<ZoomConstraints>& aConstraints)
 {
     nsBaseWidget::UpdateZoomConstraints(aPresShellId, aViewId, aConstraints);
 }
 
 CompositorBridgeParent*
 nsWindow::GetCompositorBridgeParent() const
 {
-    return mCompositorSession ? mCompositorSession->GetInProcessBridge() : nullptr;
-}
-
-already_AddRefed<nsIScreen>
-nsWindow::GetWidgetScreen()
-{
-    nsCOMPtr<nsIScreenManager> screenMgr =
-        do_GetService("@mozilla.org/gfx/screenmanager;1");
-    MOZ_ASSERT(screenMgr, "Failed to get nsIScreenManager");
-
-    nsCOMPtr<nsIScreen> screen;
-    screenMgr->ScreenForId(mScreenId, getter_AddRefs(screen));
-
-    return screen.forget();
+  return mCompositorSession ? mCompositorSession->GetInProcessBridge() : nullptr;
 }
 
 jni::DependentRef<java::GeckoLayerClient>
 nsWindow::GetLayerClient()
 {
     if (NativePtr<LayerViewSupport>::Locked lvs{mLayerViewSupport}) {
         return lvs->GetLayerClient().Get();
     }
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -1,10 +1,9 @@
 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * vim: set sw=4 ts=4 expandtab:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NSWINDOW_H_
 #define NSWINDOW_H_
 
 #include "nsBaseWidget.h"
@@ -41,21 +40,18 @@ private:
 public:
     using nsBaseWidget::GetLayerManager;
 
     nsWindow();
 
     NS_DECL_ISUPPORTS_INHERITED
 
     static void InitNatives();
-    void SetScreenId(uint32_t aScreenId) { mScreenId = aScreenId; }
 
 private:
-    uint32_t mScreenId;
-
     // An Event subclass that guards against stale events.
     template<typename Lambda,
              bool IsStatic = Lambda::isStatic,
              typename InstanceType = typename Lambda::ThisArgType,
              class Impl = typename Lambda::TargetClass>
     class WindowEvent;
 
     // Smart pointer for holding a pointer back to the nsWindow inside a native
@@ -164,17 +160,16 @@ public:
     virtual bool IsEnabled() const override;
     NS_IMETHOD Invalidate(const LayoutDeviceIntRect& aRect) override;
     NS_IMETHOD SetFocus(bool aRaise = false) override;
     virtual LayoutDeviceIntRect GetScreenBounds() override;
     virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
     NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
                              nsEventStatus& aStatus) override;
     nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent);
-    virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
     virtual nsresult MakeFullScreen(bool aFullScreen,
                                     nsIScreen* aTargetScreen = nullptr)
                                     override;
 
     NS_IMETHOD SetCursor(nsCursor aCursor) override { return NS_ERROR_NOT_IMPLEMENTED; }
     NS_IMETHOD SetCursor(imgIContainer* aCursor,
                          uint32_t aHotspotX,
                          uint32_t aHotspotY) override { return NS_ERROR_NOT_IMPLEMENTED; }
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -178,17 +178,16 @@ public:
   virtual void            SetShowsFullScreenButton(bool aShow) override {}
   virtual void            SetWindowAnimationType(WindowAnimationType aType) override {}
   NS_IMETHOD              HideWindowChrome(bool aShouldHide) override;
   virtual bool PrepareForFullscreenTransition(nsISupports** aData) override { return false; }
   virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
                                            uint16_t aDuration,
                                            nsISupports* aData,
                                            nsIRunnable* aCallback) override;
-  virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
   virtual nsresult        MakeFullScreen(bool aFullScreen,
                                          nsIScreen* aScreen = nullptr) override;
   void                    InfallibleMakeFullScreen(bool aFullScreen,
                                                    nsIScreen* aScreen = nullptr);
 
   virtual LayerManager*   GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
                                           LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
                                           LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;
@@ -334,16 +333,19 @@ public:
   nsPopupLevel PopupLevel() { return mPopupLevel; }
 
   virtual LayoutDeviceIntSize
   ClientToWindowSize(const LayoutDeviceIntSize& aClientSize) override
   {
     return aClientSize;
   }
 
+  // return the screen the widget is in.
+  already_AddRefed<nsIScreen> GetWidgetScreen();
+
   // return true if this is a popup widget with a native titlebar
   bool IsPopupWithTitleBar() const
   {
     return (mWindowType == eWindowType_popup &&
             mBorderStyle != eBorderStyle_default &&
             mBorderStyle & eBorderStyle_title);
   }
 
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1187,21 +1187,16 @@ class nsIWidget : public nsISupports
      * finishes.
      */
     virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
                                              uint16_t aDuration,
                                              nsISupports* aData,
                                              nsIRunnable* aCallback) = 0;
 
     /**
-     * Return the screen the widget is in, or null if we don't know.
-     */
-    virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
-
-    /**
      * Put the toplevel window into or out of fullscreen mode.
      * If aTargetScreen is given, attempt to go fullscreen on that screen,
      * if possible.  (If not, it behaves as if aTargetScreen is null.)
      * If !aFullScreen, aTargetScreen is ignored.
      * aTargetScreen support is currently only implemented on Windows.
      *
      * @return NS_OK if the widget is setup properly for fullscreen and
      * FullscreenChanged callback has been or will be called. If other