Bug 1300421 - Back out 4 csets from bug 1288760 for regressing event coordinate reporting. r=jfkthame
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 29 Sep 2016 10:20:52 -0400
changeset 315846 75abc730f8202005d6469a7ec324b7aba5a89374
parent 315845 9e9080a2e3462fc576b679603853f4395fadff8f
child 315847 69248cb145dec2602d030a0cd17ff6bd8ecaf6b9
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1300421, 1288760
milestone52.0a1
Bug 1300421 - Back out 4 csets from bug 1288760 for regressing event coordinate reporting. r=jfkthame MozReview-Commit-ID: AJ2PkSfYCpv
dom/events/Event.cpp
dom/ipc/PScreenManager.ipdl
dom/ipc/ScreenManagerParent.cpp
layout/xul/nsMenuPopupFrame.cpp
widget/ScreenProxy.cpp
widget/ScreenProxy.h
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
widget/nsIWidget.h
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -23,17 +23,16 @@
 #include "nsCOMPtr.h"
 #include "nsDeviceContext.h"
 #include "nsError.h"
 #include "nsGlobalWindow.h"
 #include "nsIFrame.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
-#include "nsIScreen.h"
 #include "nsIScrollableFrame.h"
 #include "nsJSEnvironment.h"
 #include "nsLayoutUtils.h"
 #include "nsPIWindowRoot.h"
 #include "WorkerPrivate.h"
 
 namespace mozilla {
 namespace dom {
@@ -923,56 +922,27 @@ Event::GetScreenCoords(nsPresContext* aP
 
   // Doing a straight conversion from LayoutDeviceIntPoint to CSSIntPoint
   // seem incorrect, but it is needed to maintain legacy functionality.
   WidgetGUIEvent* guiEvent = aEvent->AsGUIEvent();
   if (!aPresContext || !(guiEvent && guiEvent->mWidget)) {
     return CSSIntPoint(aPoint.x, aPoint.y);
   }
 
+  nsPoint pt =
+    LayoutDevicePixel::ToAppUnits(aPoint, aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
 
-  int32_t appPerDevFullZoom =
-    aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
-
-  LayoutDevicePoint devPt = aPoint;
   if (nsIPresShell* ps = aPresContext->GetPresShell()) {
-    // convert to appUnits in order to use RemoveResolution, then back to
-    // device pixels
-    nsPoint pt =
-      LayoutDevicePixel::ToAppUnits(aPoint, appPerDevFullZoom);
     pt = pt.RemoveResolution(nsLayoutUtils::GetCurrentAPZResolutionScale(ps));
-    devPt = LayoutDevicePixel::FromAppUnits(pt, appPerDevFullZoom);
   }
 
-  devPt += guiEvent->mWidget->WidgetToScreenOffset();
+  pt += LayoutDevicePixel::ToAppUnits(guiEvent->mWidget->WidgetToScreenOffset(),
+                                      aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
 
-  nsCOMPtr<nsIScreen> screen = guiEvent->mWidget->GetWidgetScreen();
-  if (screen) {
-    // subtract device-pixel origin of current screen
-    int32_t x, y, w, h;
-    screen->GetRect(&x, &y, &w, &h);
-    devPt.x -= x;
-    devPt.y -= y;
-    // then convert position *within the current screen* to unscaled CSS px
-    double cssToDevScale;
-    screen->GetDefaultCSSScaleFactor(&cssToDevScale);
-    CSSIntPoint cssPt(NSToIntRound(devPt.x / cssToDevScale),
-                      NSToIntRound(devPt.y / cssToDevScale));
-    // finally, add the desktop-pixel origin of the screen, to get a global
-    // CSS pixel value that is compatible with window.screenX/Y positions
-    screen->GetRectDisplayPix(&x, &y, &w, &h);
-    cssPt.x += x;
-    cssPt.y += y;
-    return cssPt;
-  }
-
-  // this shouldn't happen, but just in case...
-  NS_WARNING("failed to find screen, using default CSS px conversion");
-  return CSSPixel::FromAppUnitsRounded(
-      LayoutDevicePixel::ToAppUnits(aPoint, appPerDevFullZoom));
+  return CSSPixel::FromAppUnitsRounded(pt);
 }
 
 // static
 CSSIntPoint
 Event::GetPageCoords(nsPresContext* aPresContext,
                      WidgetEvent* aEvent,
                      LayoutDeviceIntPoint aPoint,
                      CSSIntPoint aDefaultPoint)
--- a/dom/ipc/PScreenManager.ipdl
+++ b/dom/ipc/PScreenManager.ipdl
@@ -18,17 +18,16 @@ struct ScreenDetails {
   uint32_t id;
   nsIntRect rect;
   nsIntRect rectDisplayPix;
   nsIntRect availRect;
   nsIntRect availRectDisplayPix;
   int32_t pixelDepth;
   int32_t colorDepth;
   double contentsScaleFactor;
-  double defaultCSSScaleFactor;
 };
 
 prio(normal upto high) sync protocol PScreenManager
 {
   manager PContent;
 
 parent:
     prio(high) sync Refresh()
--- a/dom/ipc/ScreenManagerParent.cpp
+++ b/dom/ipc/ScreenManagerParent.cpp
@@ -211,21 +211,16 @@ ScreenManagerParent::ExtractScreenDetail
   NS_ENSURE_SUCCESS(rv, false);
   aDetails.colorDepth() = colorDepth;
 
   double contentsScaleFactor = 1.0;
   rv = aScreen->GetContentsScaleFactor(&contentsScaleFactor);
   NS_ENSURE_SUCCESS(rv, false);
   aDetails.contentsScaleFactor() = contentsScaleFactor;
 
-  double defaultCSSScaleFactor = 1.0;
-  rv = aScreen->GetDefaultCSSScaleFactor(&defaultCSSScaleFactor);
-  NS_ENSURE_SUCCESS(rv, false);
-  aDetails.defaultCSSScaleFactor() = defaultCSSScaleFactor;
-
   return true;
 }
 
 void
 ScreenManagerParent::ActorDestroy(ActorDestroyReason why)
 {
 }
 
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -797,41 +797,17 @@ nsMenuPopupFrame::InitializePopupAtScree
                                           int32_t aXPos, int32_t aYPos,
                                           bool aIsContextMenu)
 {
   EnsureWidget();
 
   mPopupState = ePopupShowing;
   mAnchorContent = nullptr;
   mTriggerContent = aTriggerContent;
-
-  nsCOMPtr<nsIScreenManager> screenMgr =
-    do_GetService("@mozilla.org/gfx/screenmanager;1");
-  nsCOMPtr<nsIScreen> screen;
-  if (screenMgr) {
-    // aXPos and aYPos are "global desktop" coordinates in units of
-    // CSS pixels, but nsMenuPopupFrame wants CSS pixels that are
-    // directly scaled from device pixels, without being offset for
-    // the screen origin. So we need to undo the offset that was
-    // applied to the global CSS coordinate values in the mouse event.
-    screenMgr->ScreenForRect(aXPos, aYPos, 1, 1,
-                             getter_AddRefs(screen));
-    double cssToDevScale, deskToDevScale;
-    screen->GetDefaultCSSScaleFactor(&cssToDevScale);
-    screen->GetContentsScaleFactor(&deskToDevScale);
-    double scale = deskToDevScale / cssToDevScale;
-    int32_t w, h;
-    DesktopIntPoint origin;
-    screen->GetRectDisplayPix(&origin.x, &origin.y, &w, &h);
-    mScreenRect.x = aXPos + (origin.x * scale) - origin.x;
-    mScreenRect.y = aYPos + (origin.y * scale) - origin.y;
-    mScreenRect.width = mScreenRect.height = 0;
-  } else {
-    mScreenRect = nsIntRect(aXPos, aYPos, 0, 0);
-  }
+  mScreenRect = nsIntRect(aXPos, aYPos, 0, 0);
   mXPos = 0;
   mYPos = 0;
   mFlip = FlipType_Default;
   mPopupAnchor = POPUPALIGNMENT_NONE;
   mPopupAlignment = POPUPALIGNMENT_NONE;
   mIsContextMenu = aIsContextMenu;
   mAdjustOffsetForContextMenu = aIsContextMenu;
   mAnchorType = MenuPopupAnchorType_Point;
--- a/widget/ScreenProxy.cpp
+++ b/widget/ScreenProxy.cpp
@@ -16,17 +16,16 @@ namespace mozilla {
 namespace widget {
 
 using namespace mozilla::dom;
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 ScreenProxy::ScreenProxy(nsScreenManagerProxy* aScreenManager, ScreenDetails aDetails)
   : mContentsScaleFactor(0)
-  , mDefaultCSSScaleFactor(0)
   , mScreenManager(aScreenManager)
   , mId(0)
   , mPixelDepth(0)
   , mColorDepth(0)
   , mCacheValid(false)
   , mCacheWillInvalidate(false)
 {
   PopulateByDetails(aDetails);
@@ -124,50 +123,27 @@ ScreenProxy::GetColorDepth(int32_t *aCol
   if (!EnsureCacheIsValid()) {
     return NS_ERROR_FAILURE;
   }
 
   *aColorDepth = mColorDepth;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-ScreenProxy::GetContentsScaleFactor(double* aContentsScaleFactor)
-{
-  if (!EnsureCacheIsValid()) {
-    return NS_ERROR_FAILURE;
-  }
-
-  *aContentsScaleFactor = mContentsScaleFactor;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-ScreenProxy::GetDefaultCSSScaleFactor(double* aScaleFactor)
-{
-  if (!EnsureCacheIsValid()) {
-    return NS_ERROR_FAILURE;
-  }
-
-  *aScaleFactor = mDefaultCSSScaleFactor;
-  return NS_OK;
-}
-
 void
 ScreenProxy::PopulateByDetails(ScreenDetails aDetails)
 {
   mId = aDetails.id();
   mRect = nsIntRect(aDetails.rect());
   mRectDisplayPix = nsIntRect(aDetails.rectDisplayPix());
   mAvailRect = nsIntRect(aDetails.availRect());
   mAvailRectDisplayPix = nsIntRect(aDetails.availRectDisplayPix());
   mPixelDepth = aDetails.pixelDepth();
   mColorDepth = aDetails.colorDepth();
   mContentsScaleFactor = aDetails.contentsScaleFactor();
-  mDefaultCSSScaleFactor = aDetails.defaultCSSScaleFactor();
 }
 
 bool
 ScreenProxy::EnsureCacheIsValid()
 {
   if (mCacheValid) {
     return true;
   }
--- a/widget/ScreenProxy.h
+++ b/widget/ScreenProxy.h
@@ -39,28 +39,24 @@ public:
                             int32_t* aHeight) override;
     NS_IMETHOD GetAvailRectDisplayPix(int32_t* aLeft,
                                       int32_t* aTop,
                                       int32_t* aWidth,
                                       int32_t* aHeight) override;
     NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override;
     NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override;
 
-    NS_IMETHOD GetContentsScaleFactor(double* aContentsScaleFactor) override;
-    NS_IMETHOD GetDefaultCSSScaleFactor(double* aScaleFactor) override;
-
 private:
 
     void PopulateByDetails(mozilla::dom::ScreenDetails aDetails);
     bool EnsureCacheIsValid();
     void InvalidateCacheOnNextTick();
     void InvalidateCache();
 
     double mContentsScaleFactor;
-    double mDefaultCSSScaleFactor;
     RefPtr<nsScreenManagerProxy> mScreenManager;
     uint32_t mId;
     int32_t mPixelDepth;
     int32_t mColorDepth;
     nsIntRect mRect;
     nsIntRect mRectDisplayPix;
     nsIntRect mAvailRect;
     nsIntRect mAvailRectDisplayPix;
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -1919,17 +1919,17 @@ nsBaseWidget::StartAsyncScrollbarDrag(co
 
   APZThreadUtils::RunOnControllerThread(NewRunnableMethod
     <ScrollableLayerGuid, AsyncDragMetrics>(mAPZC,
                                             &IAPZCTreeManager::StartScrollbarDrag,
                                             guid, aDragMetrics));
 }
 
 already_AddRefed<nsIScreen>
-nsIWidget::GetWidgetScreen()
+nsBaseWidget::GetWidgetScreen()
 {
   nsCOMPtr<nsIScreenManager> screenManager;
   screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
   if (!screenManager) {
     return nullptr;
   }
 
   LayoutDeviceIntRect bounds = GetScreenBounds();
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -333,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.
-     */
-    already_AddRefed<nsIScreen> GetWidgetScreen();
-
-    /**
      * 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