Bug 1224403 (part 2) - Split GetClientOffset() into typed and untyped versions. r=kats.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 11 Nov 2015 19:56:06 -0800
changeset 308730 cfde91a29f0357a661370fb2742b8d209856a76d
parent 308729 c8c6d723b1b2a74dd26cfbabbd8d50eba7c698ee
child 308731 b89c50c056eb4375ed5c779816fee7075eacb96f
push id7515
push usermjzffr@gmail.com
push dateFri, 13 Nov 2015 14:42:42 +0000
reviewerskats
bugs1224403
milestone45.0a1
Bug 1224403 (part 2) - Split GetClientOffset() into typed and untyped versions. r=kats.
accessible/generic/HyperTextAccessible.cpp
layout/xul/nsMenuPopupFrame.cpp
layout/xul/nsResizerFrame.cpp
layout/xul/nsXULPopupManager.cpp
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
widget/nsIWidget.h
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -1516,17 +1516,17 @@ HyperTextAccessible::GetCaretRect(nsIWid
   // on the widget.
   *aWidget = frame->GetNearestWidget(offset);
   NS_ENSURE_TRUE(*aWidget, nsIntRect());
   rect.MoveBy(offset);
 
   nsIntRect caretRect;
   caretRect = rect.ToOutsidePixels(frame->PresContext()->AppUnitsPerDevPixel());
   // ((content screen origin) - (content offset in the widget)) = widget origin on the screen
-  caretRect.MoveBy((*aWidget)->WidgetToScreenOffsetUntyped() - (*aWidget)->GetClientOffset());
+  caretRect.MoveBy((*aWidget)->WidgetToScreenOffsetUntyped() - (*aWidget)->GetClientOffsetUntyped());
 
   // Correct for character size, so that caret always matches the size of
   // the character. This is important for font size transitions, and is
   // necessary because the Gecko caret uses the previous character's size as
   // the user moves forward in the text by character.
   nsIntRect charRect = CharBounds(CaretOffset(),
                                   nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE);
   if (!charRect.IsEmpty()) {
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -1496,17 +1496,17 @@ nsMenuPopupFrame::SetPopupPosition(nsIFr
   NS_ASSERTION(view, "popup with no view");
 
   // Offset the position by the width and height of the borders and titlebar.
   // Even though GetClientOffset should return (0, 0) when there is no
   // titlebar or borders, we skip these calculations anyway for non-panels
   // to save time since they will never have a titlebar.
   nsIWidget* widget = view->GetWidget();
   if (mPopupType == ePopupTypePanel && widget) {
-    mLastClientOffset = widget->GetClientOffset();
+    mLastClientOffset = widget->GetClientOffsetUntyped();
     viewPoint.x += presContext->DevPixelsToAppUnits(mLastClientOffset.x);
     viewPoint.y += presContext->DevPixelsToAppUnits(mLastClientOffset.y);
   }
 
   presContext->GetPresShell()->GetViewManager()->
     MoveViewTo(view, viewPoint.x, viewPoint.y);
 
   // Now that we've positioned the view, sync up the frame's origin.
@@ -2163,17 +2163,17 @@ nsMenuPopupFrame::DestroyFrom(nsIFrame* 
 }
 
 
 void
 nsMenuPopupFrame::MoveTo(const CSSIntPoint& aPos, bool aUpdateAttrs)
 {
   nsIWidget* widget = GetWidget();
   if ((mScreenRect.x == aPos.x && mScreenRect.y == aPos.y) &&
-      (!widget || widget->GetClientOffset() == mLastClientOffset)) {
+      (!widget || widget->GetClientOffsetUntyped() == mLastClientOffset)) {
     return;
   }
 
   // reposition the popup at the specified coordinates. Don't clear the anchor
   // and position, because the popup can be reset to its anchor position by
   // using (-1, -1) as coordinates. Subtract off the margin as it will be
   // added to the position when SetPopupPosition is called.
   nsMargin margin(0, 0, 0, 0);
--- a/layout/xul/nsResizerFrame.cpp
+++ b/layout/xul/nsResizerFrame.cpp
@@ -248,17 +248,17 @@ nsResizerFrame::HandleEvent(nsPresContex
         LayoutDeviceIntRect oldRect;
         nsWeakFrame weakFrame(menuPopupFrame);
         if (menuPopupFrame) {
           nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
           if (widget)
             widget->GetScreenBounds(oldRect);
 
           // convert the new rectangle into outer window coordinates
-          nsIntPoint clientOffset = widget->GetClientOffset();
+          LayoutDeviceIntPoint clientOffset = widget->GetClientOffset();
           rect.x -= clientOffset.x;
           rect.y -= clientOffset.y;
         }
 
         SizeInfo sizeInfo, originalSizeInfo;
         sizeInfo.width.AppendInt(cssRect.width);
         sizeInfo.height.AppendInt(cssRect.height);
         ResizeContent(contentToResize, direction, sizeInfo, &originalSizeInfo);
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -468,17 +468,17 @@ nsXULPopupManager::PopupMoved(nsIFrame* 
   if (!view)
     return;
 
   // Don't do anything if the popup is already at the specified location. This
   // prevents recursive calls when a popup is positioned.
   nsIntRect curDevSize = view->CalcWidgetBounds(eWindowType_popup);
   nsIWidget* widget = menuPopupFrame->GetWidget();
   if (curDevSize.x == aPnt.x && curDevSize.y == aPnt.y &&
-      (!widget || widget->GetClientOffset() == menuPopupFrame->GetLastClientOffset())) {
+      (!widget || widget->GetClientOffsetUntyped() == menuPopupFrame->GetLastClientOffset())) {
     return;
   }
 
   // Update the popup's position using SetPopupPosition if the popup is
   // anchored and at the parent level as these maintain their position
   // relative to the parent window. Otherwise, just update the popup to
   // the specified screen coordinates.
   if (menuPopupFrame->IsAnchored() &&
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -546,17 +546,17 @@ public:
   NS_IMETHOD StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
                             int32_t aPanelX, int32_t aPanelY,
                             nsString& aCommitted) override;
 
   NS_IMETHOD SetPluginFocused(bool& aFocused) override;
 
   bool IsPluginFocused() { return mPluginFocused; }
 
-  virtual nsIntPoint GetClientOffset() override;
+  virtual nsIntPoint GetClientOffsetUntyped() override;
 
   void DispatchAPZWheelInputEvent(mozilla::InputData& aEvent, bool aCanTriggerSwipe);
 
   void SwipeFinished();
 
 protected:
   virtual ~nsChildView();
 
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1515,17 +1515,17 @@ void nsChildView::ReportMoveEvent()
 void nsChildView::ReportSizeEvent()
 {
   if (mWidgetListener)
     mWidgetListener->WindowResized(this, mBounds.width, mBounds.height);
 }
 
 #pragma mark -
 
-nsIntPoint nsChildView::GetClientOffset()
+nsIntPoint nsChildView::GetClientOffsetUntyped()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   NSPoint origin = [mView convertPoint:NSMakePoint(0, 0) toView:nil];
   origin.y = [[mView window] frame].size.height - origin.y;
   return CocoaPointsToDevPixels(origin);
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0, 0));
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -266,17 +266,17 @@ public:
     NS_IMETHOD              Show(bool aState) override;
     virtual nsIWidget*      GetSheetWindowParent(void) override;
     NS_IMETHOD              Enable(bool aState) override;
     virtual bool            IsEnabled() const override;
     NS_IMETHOD              SetModal(bool aState) override;
     virtual bool            IsVisible() const override;
     NS_IMETHOD              SetFocus(bool aState=false) override;
     virtual mozilla::LayoutDeviceIntPoint WidgetToScreenOffset() override;
-    virtual nsIntPoint GetClientOffset() override;
+    virtual nsIntPoint GetClientOffsetUntyped() override;
     virtual mozilla::LayoutDeviceIntSize
     ClientToWindowSize(const mozilla::LayoutDeviceIntSize& aClientSize) override;
 
     virtual void* GetNativeData(uint32_t aDataType) override;
 
     NS_IMETHOD              ConstrainPosition(bool aAllowSlop,
                                               int32_t *aX, int32_t *aY) override;
     virtual void            SetSizeConstraints(const SizeConstraints& aConstraints) override;
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -1973,17 +1973,17 @@ LayoutDeviceIntPoint nsCocoaWindow::Widg
   }
   r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(rect, BackingScaleFactor());
 
   return LayoutDeviceIntPoint::FromUnknownPoint(r.TopLeft());
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntPoint(0,0));
 }
 
-nsIntPoint nsCocoaWindow::GetClientOffset()
+nsIntPoint nsCocoaWindow::GetClientOffsetUntyped()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   nsIntRect clientRect;
   GetClientBoundsUntyped(clientRect);
 
   return clientRect.TopLeft() - mBounds.TopLeft();
 
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -1510,17 +1510,17 @@ nsWindow::GetClientSize()
 
 NS_IMETHODIMP
 nsWindow::GetClientBoundsUntyped(nsIntRect &aRect)
 {
     // GetBounds returns a rect whose top left represents the top left of the
     // outer bounds, but whose width/height represent the size of the inner
     // bounds (which is messed up).
     GetBoundsUntyped(aRect);
-    aRect.MoveBy(GetClientOffset());
+    aRect.MoveBy(GetClientOffsetUntyped());
 
     return NS_OK;
 }
 
 void
 nsWindow::UpdateClientOffset()
 {
     PROFILER_LABEL("nsWindow", "UpdateClientOffset", js::ProfileEntry::Category::GRAPHICS);
@@ -1558,17 +1558,17 @@ nsWindow::UpdateClientOffset()
     int32_t top = int32_t(frame_extents[2]);
 
     g_free(frame_extents);
 
     mClientOffset = nsIntPoint(left, top);
 }
 
 nsIntPoint
-nsWindow::GetClientOffset()
+nsWindow::GetClientOffsetUntyped()
 {
     return mClientOffset;
 }
 
 gboolean
 nsWindow::OnPropertyNotifyEvent(GtkWidget* aWidget, GdkEventProperty* aEvent)
 
 {
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -129,17 +129,17 @@ public:
                                    bool                        aActivate) override;
     void               SetZIndex(int32_t aZIndex) override;
     NS_IMETHOD         SetSizeMode(nsSizeMode aMode) override;
     NS_IMETHOD         Enable(bool aState) override;
     NS_IMETHOD         SetFocus(bool aRaise = false) override;
     NS_IMETHOD         GetScreenBoundsUntyped(nsIntRect &aRect) override;
     NS_IMETHOD         GetClientBoundsUntyped(nsIntRect &aRect) override;
     virtual mozilla::gfx::IntSize GetClientSize() override;
-    virtual nsIntPoint GetClientOffset() override;
+    virtual nsIntPoint GetClientOffsetUntyped() override;
     NS_IMETHOD         SetCursor(nsCursor aCursor) override;
     NS_IMETHOD         SetCursor(imgIContainer* aCursor,
                                  uint32_t aHotspotX, uint32_t aHotspotY) override;
     NS_IMETHOD         Invalidate(const nsIntRect &aRect) override;
     virtual void*      GetNativeData(uint32_t aDataType) override;
     void               SetNativeData(uint32_t aDataType, uintptr_t aVal) override;
     NS_IMETHOD         SetTitle(const nsAString& aTitle) override;
     NS_IMETHOD         SetIcon(const nsAString& aIconSpec) override;
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -1234,17 +1234,17 @@ void nsBaseWidget::OnDestroy()
 
 NS_METHOD nsBaseWidget::SetWindowClass(const nsAString& xulWinType)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_METHOD nsBaseWidget::MoveClient(double aX, double aY)
 {
-  nsIntPoint clientOffset(GetClientOffset());
+  LayoutDeviceIntPoint clientOffset(GetClientOffset());
 
   // GetClientOffset returns device pixels; scale back to display pixels
   // if that's what this widget uses for the Move/Resize APIs
   CSSToLayoutDeviceScale scale = BoundsUseDisplayPixels()
                                     ? GetDefaultScale()
                                     : CSSToLayoutDeviceScale(1.0);
   aX -= clientOffset.x * 1.0 / scale.scale;
   aY -= clientOffset.y * 1.0 / scale.scale;
@@ -1285,17 +1285,17 @@ NS_METHOD nsBaseWidget::ResizeClient(dou
 
   LayoutDeviceIntRect clientBounds;
   GetClientBounds(clientBounds);
 
   double scale = BoundsUseDisplayPixels() ? 1.0 / GetDefaultScale().scale : 1.0;
   aWidth = mBounds.width * scale + (aWidth - clientBounds.width * scale);
   aHeight = mBounds.height * scale + (aHeight - clientBounds.height * scale);
 
-  nsIntPoint clientOffset(GetClientOffset());
+  LayoutDeviceIntPoint clientOffset(GetClientOffset());
   aX -= clientOffset.x * scale;
   aY -= clientOffset.y * scale;
 
   return Resize(aX, aY, aWidth, aHeight, aRepaint);
 }
 
 //-------------------------------------------------------------------------
 //
@@ -1335,17 +1335,18 @@ NS_METHOD nsBaseWidget::GetScreenBoundsU
 NS_METHOD nsBaseWidget::GetRestoredBoundsUntyped(nsIntRect &aRect)
 {
   if (SizeMode() != nsSizeMode_Normal) {
     return NS_ERROR_FAILURE;
   }
   return GetScreenBoundsUntyped(aRect);
 }
 
-nsIntPoint nsBaseWidget::GetClientOffset()
+nsIntPoint
+nsBaseWidget::GetClientOffsetUntyped()
 {
   return nsIntPoint(0, 0);
 }
 
 NS_IMETHODIMP
 nsBaseWidget::GetNonClientMargins(nsIntMargin &margins)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -188,17 +188,17 @@ public:
   NS_IMETHOD              ResizeClient(double aWidth, double aHeight, bool aRepaint) override;
   NS_IMETHOD              ResizeClient(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
   NS_IMETHOD              GetBoundsUntyped(nsIntRect &aRect) override;
   NS_IMETHOD              GetClientBoundsUntyped(nsIntRect &aRect) override;
   NS_IMETHOD              GetScreenBoundsUntyped(nsIntRect &aRect) override;
   NS_IMETHOD              GetRestoredBoundsUntyped(nsIntRect &aRect) override;
   NS_IMETHOD              GetNonClientMargins(nsIntMargin &margins) override;
   NS_IMETHOD              SetNonClientMargins(nsIntMargin &margins) override;
-  virtual nsIntPoint      GetClientOffset() override;
+  virtual nsIntPoint      GetClientOffsetUntyped() override;
   NS_IMETHOD              EnableDragDrop(bool aEnable) override;
   NS_IMETHOD              GetAttention(int32_t aCycleCount) override;
   virtual bool            HasPendingInputEvent() override;
   NS_IMETHOD              SetIcon(const nsAString &anIconSpec) override;
   NS_IMETHOD              SetWindowTitlebarColor(nscolor aColor, bool aActive) override;
   virtual void            SetDrawsInTitlebar(bool aState) override {}
   virtual bool            ShowsResizeIndicator(nsIntRect* aResizerRect) override;
   virtual void            FreeNativeData(void * data, uint32_t aDataType) override {}
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -895,21 +895,27 @@ class nsIWidget : public nsISupports {
      *  dimensions between zero and size < system default.
      *
      */
     NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0;
 
     /**
      * Get the client offset from the window origin.
      *
+     * The untyped version exists temporarily to ease conversion to typed
+     * coordinates.
+     *
      * @return the x and y of the offset.
      *
      */
-    virtual nsIntPoint GetClientOffset() = 0;
-
+    virtual mozilla::LayoutDeviceIntPoint GetClientOffset() {
+      nsIntPoint tmp = GetClientOffsetUntyped();
+      return mozilla::LayoutDeviceIntPoint::FromUnknownPoint(tmp);
+    }
+    virtual nsIntPoint GetClientOffsetUntyped() = 0;
 
     /**
      * Equivalent to GetClientBounds but only returns the size.
      */
     virtual mozilla::gfx::IntSize GetClientSize() {
       // Dependeing on the backend, overloading this method may be useful if
       // if requesting the client offset is expensive.
       mozilla::LayoutDeviceIntRect rect;
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -1913,17 +1913,17 @@ NS_METHOD nsWindow::GetBoundsUntyped(nsI
     if (parent) {
       RECT pr;
       VERIFY(::GetWindowRect(parent, &pr));
       r.left -= pr.left;
       r.top  -= pr.top;
       // adjust for chrome
       nsWindow* pWidget = static_cast<nsWindow*>(GetParent());
       if (pWidget && pWidget->IsTopLevelWidget()) {
-        nsIntPoint clientOffset = pWidget->GetClientOffset();
+        LayoutDeviceIntPoint clientOffset = pWidget->GetClientOffset();
         r.left -= clientOffset.x;
         r.top  -= clientOffset.y;
       }
     }
     aRect.x = r.left;
     aRect.y = r.top;
   } else {
     aRect = mBounds;
@@ -1935,17 +1935,17 @@ NS_METHOD nsWindow::GetBoundsUntyped(nsI
 NS_METHOD nsWindow::GetClientBoundsUntyped(nsIntRect &aRect)
 {
   if (mWnd) {
     RECT r;
     VERIFY(::GetClientRect(mWnd, &r));
 
     nsIntRect bounds;
     GetBoundsUntyped(bounds);
-    aRect.MoveTo(bounds.TopLeft() + GetClientOffset());
+    aRect.MoveTo(bounds.TopLeft() + GetClientOffsetUntyped());
     aRect.width  = r.right - r.left;
     aRect.height = r.bottom - r.top;
 
   } else {
     aRect.SetRect(0,0,0,0);
   }
   return NS_OK;
 }
@@ -1990,17 +1990,18 @@ NS_METHOD nsWindow::GetRestoredBoundsUnt
   aRect.SetRect(r.left, r.top, r.right - r.left, r.bottom - r.top);
   aRect.MoveBy(mi.rcWork.left - mi.rcMonitor.left,
                mi.rcWork.top - mi.rcMonitor.top);
   return NS_OK;
 }
 
 // return the x,y offset of the client area from the origin
 // of the window. If the window is borderless returns (0,0).
-nsIntPoint nsWindow::GetClientOffset()
+nsIntPoint
+nsWindow::GetClientOffsetUntyped()
 {
   if (!mWnd) {
     return nsIntPoint(0, 0);
   }
 
   RECT r1;
   GetWindowRect(mWnd, &r1);
   LayoutDeviceIntPoint pt = WidgetToScreenOffset();
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -115,17 +115,17 @@ public:
   NS_IMETHOD              SetSizeMode(nsSizeMode aMode);
   NS_IMETHOD              Enable(bool aState);
   virtual bool            IsEnabled() const;
   NS_IMETHOD              SetFocus(bool aRaise);
   NS_IMETHOD              GetBoundsUntyped(nsIntRect &aRect);
   NS_IMETHOD              GetScreenBoundsUntyped(nsIntRect &aRect);
   NS_IMETHOD              GetRestoredBoundsUntyped(nsIntRect &aRect) override;
   NS_IMETHOD              GetClientBoundsUntyped(nsIntRect &aRect);
-  virtual nsIntPoint      GetClientOffset();
+  virtual nsIntPoint      GetClientOffsetUntyped() override;
   void                    SetBackgroundColor(const nscolor &aColor);
   NS_IMETHOD              SetCursor(imgIContainer* aCursor,
                                     uint32_t aHotspotX, uint32_t aHotspotY);
   NS_IMETHOD              SetCursor(nsCursor aCursor);
   virtual nsresult        ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
   virtual bool PrepareForFullscreenTransition(nsISupports** aData) override;
   virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
                                            uint16_t aDuration,