Bug 476726 - deCOMtaminate WidgetToScreen and ScreenToWidget; r+sr=roc
authorJeremy Lea <reg@openpave.org>
Sun, 15 Feb 2009 17:41:06 +0100
changeset 25004 719dca3419b5a13fe26bbc7d69b3ca53bf227dfe
parent 25003 787fde278f784af4ddfb5668ef115dd3f4a248c1
child 25005 c8cdcd82ba3221e19219cbafc88e6178f2421a20
child 25006 a3f2ff43ea118acdb88734277039ad83e282793f
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs476726
milestone1.9.2a1pre
Bug 476726 - deCOMtaminate WidgetToScreen and ScreenToWidget; r+sr=roc
accessible/src/base/nsCaretAccessible.cpp
content/events/src/nsDOMUIEvent.cpp
content/events/src/nsEventStateManager.cpp
embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
gfx/public/nsPoint.h
layout/base/nsLayoutUtils.cpp
layout/base/nsPresShell.cpp
layout/generic/nsFrame.cpp
layout/generic/nsObjectFrame.cpp
view/src/nsView.cpp
widget/public/nsIWidget.h
widget/src/cocoa/nsChildView.h
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsCocoaWindow.h
widget/src/cocoa/nsCocoaWindow.mm
widget/src/gtk2/nsWindow.cpp
widget/src/gtk2/nsWindow.h
widget/src/os2/nsWindow.cpp
widget/src/os2/nsWindow.h
widget/src/qt/nsWindow.cpp
widget/src/qt/nsWindow.h
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -339,17 +339,17 @@ nsCaretAccessible::GetCaretRect(nsIWidge
   NS_ENSURE_TRUE(*aOutWidget, nsIntRect());
 
   nsPresContext *presContext = presShell->GetPresContext();
   NS_ENSURE_TRUE(presContext, nsIntRect());
 
   rect += offsetFromWidget;
   caretRect = nsRect::ToOutsidePixels(rect, presContext->AppUnitsPerDevPixel());
 
-  (*aOutWidget)->WidgetToScreen(caretRect, caretRect);
+  caretRect.MoveBy((*aOutWidget)->WidgetToScreenOffset());
 
   // 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.
   PRInt32 charX, charY, charWidth, charHeight;
   if (NS_SUCCEEDED(mLastTextAccessible->GetCharacterExtents(mLastCaretOffset, &charX, &charY,
                                                             &charWidth, &charHeight,
                                                             nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE))) {
--- a/content/events/src/nsDOMUIEvent.cpp
+++ b/content/events/src/nsDOMUIEvent.cpp
@@ -131,19 +131,18 @@ nsDOMUIEvent::GetScreenPoint()
         mEvent->eventStructType != NS_DRAG_EVENT)) {
     return nsIntPoint(0, 0);
   }
 
   if (!((nsGUIEvent*)mEvent)->widget ) {
     return mEvent->refPoint;
   }
 
-  nsIntRect bounds(mEvent->refPoint, nsIntSize(1, 1));
-  nsIntRect offset;
-  ((nsGUIEvent*)mEvent)->widget->WidgetToScreen ( bounds, offset );
+  nsIntPoint offset = mEvent->refPoint + 
+    ((nsGUIEvent*)mEvent)->widget->WidgetToScreenOffset();
   nscoord factor = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
   return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
                     nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
 }
 
 nsIntPoint
 nsDOMUIEvent::GetClientPoint()
 {
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -582,20 +582,17 @@ nsMouseWheelTransaction::SetTimeout()
   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "nsITimer::InitWithFuncCallback failed");
 }
 
 nsIntPoint
 nsMouseWheelTransaction::GetScreenPoint(nsGUIEvent* aEvent)
 {
   NS_ASSERTION(aEvent, "aEvent is null");
   NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
-  nsIntRect tmpRect;
-  aEvent->widget->WidgetToScreen(nsIntRect(aEvent->refPoint, nsIntSize(1, 1)),
-                                 tmpRect);
-  return tmpRect.TopLeft();
+  return aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
 }
 
 PRUint32
 nsMouseWheelTransaction::GetTimeoutTime()
 {
   return (PRUint32)
     nsContentUtils::GetIntPref("mousewheel.transaction.timeout", 1500);
 }
@@ -2076,20 +2073,18 @@ nsEventStateManager::FireContextClick()
 //
 void
 nsEventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
                                               nsMouseEvent* inDownEvent,
                                               nsIFrame* inDownFrame)
 {
   // Note that |inDownEvent| could be either a mouse down event or a
   // synthesized mouse move event.
-  nsIntRect screenPt;
-  inDownEvent->widget->WidgetToScreen(nsIntRect(inDownEvent->refPoint, nsIntSize(1, 1)),
-                                      screenPt);
-  mGestureDownPoint = screenPt.TopLeft();
+  mGestureDownPoint = inDownEvent->refPoint + 
+    inDownEvent->widget->WidgetToScreenOffset();
 
   inDownFrame->GetContentForEvent(aPresContext, inDownEvent,
                                   getter_AddRefs(mGestureDownContent));
 
   mGestureDownFrameOwner = inDownFrame->GetContent();
   mGestureDownShift = inDownEvent->isShift;
   mGestureDownControl = inDownEvent->isControl;
   mGestureDownAlt = inDownEvent->isAlt;
@@ -2120,19 +2115,18 @@ void
 nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent)
 {
   NS_ASSERTION(aEvent->widget == mCurrentTarget->GetWindow(),
                "Incorrect widget in event");
 
   // Set the coordinates in the new event to the coordinates of
   // the old event, adjusted for the fact that the widget might be
   // different
-  nsIntRect tmpRect(0, 0, 1, 1);
-  aEvent->widget->WidgetToScreen(tmpRect, tmpRect);
-  aEvent->refPoint = mGestureDownPoint - tmpRect.TopLeft();
+  nsIntPoint tmpPoint = aEvent->widget->WidgetToScreenOffset();
+  aEvent->refPoint = mGestureDownPoint - tmpPoint;
   aEvent->isShift = mGestureDownShift;
   aEvent->isControl = mGestureDownControl;
   aEvent->isAlt = mGestureDownAlt;
   aEvent->isMeta = mGestureDownMeta;
 }
 
 //
 // GenerateDragGesture
@@ -2181,20 +2175,17 @@ nsEventStateManager::GenerateDragGesture
       lf->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, pixelThresholdY);
       if (!pixelThresholdX)
         pixelThresholdX = 5;
       if (!pixelThresholdY)
         pixelThresholdY = 5;
     }
 
     // fire drag gesture if mouse has moved enough
-    nsIntRect tmpRect;
-    aEvent->widget->WidgetToScreen(nsIntRect(aEvent->refPoint, nsIntSize(1, 1)),
-                                   tmpRect);
-    nsIntPoint pt = tmpRect.TopLeft();
+    nsIntPoint pt = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
     if (PR_ABS(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
         PR_ABS(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
 #ifdef CLICK_HOLD_CONTEXT_MENUS
       // stop the click-hold before we fire off the drag gesture, in case
       // it takes a long time
       KillClickHoldTimer();
 #endif
 
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
@@ -1477,19 +1477,17 @@ ChromeTooltipListener::sTooltipCallback(
       PRBool textFound = PR_FALSE;
 
       self->mTooltipTextProvider->GetNodeText(
           self->mPossibleTooltipNode, getter_Copies(tooltipText), &textFound);
       
       if (textFound) {
         nsString tipText(tooltipText);
         self->CreateAutoHideTimer();
-        nsIntRect widgetDot(0, 0, 1, 1);
-        nsIntRect screenDot;
-        widget->WidgetToScreen(widgetDot, screenDot);
+        nsIntPoint screenDot = widget->WidgetToScreenOffset();
         self->ShowTooltip (self->mMouseScreenX - screenDot.x,
                            self->mMouseScreenY - screenDot.y,
                            tipText);
       }
     }
     
     // release tooltip target if there is one, NO MATTER WHAT
     self->mPossibleTooltipNode = nsnull;
--- a/gfx/public/nsPoint.h
+++ b/gfx/public/nsPoint.h
@@ -106,12 +106,15 @@ struct nsIntPoint {
     y += aPoint.y;
     return *this;
   }
   nsIntPoint& operator-=(const nsIntPoint& aPoint) {
     x -= aPoint.x;
     y -= aPoint.y;
     return *this;
   }
+  nsIntPoint operator-() const {
+    return nsIntPoint(-x, -y);
+  }
   void MoveTo(PRInt32 aX, PRInt32 aY) {x = aX; y = aY;}
 };
 
 #endif /* NSPOINT_H */
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -839,21 +839,18 @@ nsLayoutUtils::TranslateWidgetToView(nsP
   nsIntPoint fromOffset = GetWidgetOffset(aWidget, fromRoot);
   nsIWidget* toRoot;
   nsIntPoint toOffset = GetWidgetOffset(viewWidget, toRoot);
 
   nsIntPoint widgetPoint;
   if (fromRoot == toRoot) {
     widgetPoint = aPt + fromOffset - toOffset;
   } else {
-    nsIntRect widgetRect(0, 0, 0, 0);
-    nsIntRect screenRect;
-    aWidget->WidgetToScreen(widgetRect, screenRect);
-    viewWidget->ScreenToWidget(screenRect, widgetRect);
-    widgetPoint = aPt + widgetRect.TopLeft();
+    nsIntPoint screenPoint = aWidget->WidgetToScreenOffset();
+    widgetPoint = aPt + screenPoint - viewWidget->WidgetToScreenOffset();
   }
 
   nsPoint widgetAppUnits(aPresContext->DevPixelsToAppUnits(widgetPoint.x),
                          aPresContext->DevPixelsToAppUnits(widgetPoint.y));
   return widgetAppUnits - viewOffset;
 }
 
 // Combine aNewBreakType with aOrigBreakType, but limit the break types
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -6010,19 +6010,18 @@ PresShell::AdjustContextMenuKeyEvent(nsM
 #else
       nsIFrame* itemFrame = 
         (static_cast<nsMenuPopupFrame *>(popupFrame))->GetCurrentMenuItem();
       if (!itemFrame)
         itemFrame = popupFrame;
 
       nsCOMPtr<nsIWidget> widget = popupFrame->GetWindow();
       aEvent->widget = widget;
-      nsIntRect widgetRect(0, 0, 1, 1);
-      widget->WidgetToScreen(widgetRect, widgetRect);
-      aEvent->refPoint = itemFrame->GetScreenRect().BottomLeft() - widgetRect.TopLeft();
+      nsIntPoint widgetPoint = widget->WidgetToScreenOffset();
+      aEvent->refPoint = itemFrame->GetScreenRect().BottomLeft() - widgetPoint;
 
       mCurrentEventContent = itemFrame->GetContent();
       mCurrentEventFrame = itemFrame;
 
       return PR_TRUE;
 #endif
     }
   }
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -3550,23 +3550,22 @@ nsRect nsIFrame::GetScreenRectInAppUnits
   nsPoint toViewOffset(0,0);
   nsIView* view = GetClosestView(&toViewOffset);
 
   if (view) {
     nsPoint toWidgetOffset(0,0);
     nsIWidget* widget = view->GetNearestWidget(&toWidgetOffset);
 
     if (widget) {
-      nsIntRect localRect(0,0,0,0), screenRect;
-      widget->WidgetToScreen(localRect, screenRect);
+      nsIntPoint screenPoint = widget->WidgetToScreenOffset();
 
       retval = mRect;
       retval.MoveTo(toViewOffset + toWidgetOffset);
-      retval.x += PresContext()->DevPixelsToAppUnits(screenRect.x);
-      retval.y += PresContext()->DevPixelsToAppUnits(screenRect.y);
+      retval.x += PresContext()->DevPixelsToAppUnits(screenPoint.x);
+      retval.y += PresContext()->DevPixelsToAppUnits(screenPoint.y);
     }
   }
 
   return retval;
 }
 
 // Returns the offset from this frame to the closest geometric parent that
 // has a view. Also returns the containing view or null in case of error
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -3824,20 +3824,19 @@ nsEventStatus nsPluginInstanceOwner::Pro
         const nsPresContext* presContext = mOwner->PresContext();
         nsPoint appPoint =
           nsLayoutUtils::GetEventCoordinatesRelativeTo(&anEvent, mOwner); 
         nsIntPoint pluginPoint(presContext->AppUnitsToDevPixels(appPoint.x),
                                presContext->AppUnitsToDevPixels(appPoint.y));
         const nsMouseEvent& mouseEvent =
           static_cast<const nsMouseEvent&>(anEvent);
         // Get reference point relative to screen:
-        nsIntRect windowRect(anEvent.refPoint, nsIntSize(1, 1));
-        nsIntRect rootPoint(-1,-1,1,1);
+        nsIntPoint rootPoint(-1,-1);
         if (widget)
-          widget->WidgetToScreen(windowRect, rootPoint);
+          rootPoint = anEvent.refPoint + widget->WidgetToScreenOffset();
 #ifdef MOZ_WIDGET_GTK2
         Window root = GDK_ROOT_WINDOW();
 #else
         Window root = None; // Could XQueryTree, but this is not important.
 #endif
 
         switch (anEvent.message)
           {
@@ -4732,24 +4731,17 @@ WindowRef nsPluginInstanceOwner::FixUpPl
   else if (drawingModel == NPDrawingModelCoreGraphics)
 #endif
   {
     // This would be a lot easier if we could use obj-c here,
     // but we can't. Since we have only nsIWidget and we can't
     // use its native widget (an obj-c object) we have to go
     // from the widget's screen coordinates to its window coords
     // instead of straight to window coords.
-    nsIntRect geckoBounds;
-    mWidget->GetBounds(geckoBounds);
-    // we need a rect that is the entire *internal* rect, so the
-    // x and y coords are 0, width is the same.
-    geckoBounds.x = 0;
-    geckoBounds.y = 0;
-    nsIntRect geckoScreenCoords;
-    mWidget->WidgetToScreen(geckoBounds, geckoScreenCoords);
+    nsIntPoint geckoScreenCoords = mWidget->WidgetToScreenOffset();
 
     Rect windowRect;
     WindowRef window = (WindowRef)pluginPort->cgPort.window;
     ::GetWindowBounds(window, kWindowStructureRgn, &windowRect);
 
     mPluginWindow->x = geckoScreenCoords.x - windowRect.left;
     mPluginWindow->y = geckoScreenCoords.y - windowRect.top;
   }
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -368,20 +368,19 @@ nsIntRect nsView::CalcWidgetBounds(nsWin
   if (GetParent()) {
     // put offset into screen coordinates
     nsPoint offset;
     nsIWidget* parentWidget = GetParent()->GetNearestWidget(&offset);
     viewBounds += offset;
 
     if (parentWidget && aType == eWindowType_popup &&
         mVis == nsViewVisibility_kShow) {
-      nsIntRect screenRect(0,0,1,1);
-      parentWidget->WidgetToScreen(screenRect, screenRect);
-      viewBounds += nsPoint(NSIntPixelsToAppUnits(screenRect.x, p2a),
-                            NSIntPixelsToAppUnits(screenRect.y, p2a));
+      nsIntPoint screenPoint = parentWidget->WidgetToScreenOffset();
+      viewBounds += nsPoint(NSIntPixelsToAppUnits(screenPoint.x, p2a),
+                            NSIntPixelsToAppUnits(screenPoint.y, p2a));
     }
   }
 
   nsIntRect newBounds = nsRect::ToNearestPixels(viewBounds, p2a);
 
   nsPoint roundedOffset(NSIntPixelsToAppUnits(newBounds.x, p2a),
                         NSIntPixelsToAppUnits(newBounds.y, p2a));
   mViewToWidgetOffset = viewBounds.TopLeft() - roundedOffset;
@@ -804,31 +803,29 @@ nsPoint nsIView::GetOffsetTo(const nsIVi
     }
   }
 
   return offset;
 }
 
 nsIntPoint nsIView::GetScreenPosition() const
 {
-  nsIntRect screenRect(0,0,0,0);  
+  nsIntPoint screenPoint(0,0);  
   nsPoint toWidgetOffset(0,0);
   nsIWidget* widget = GetNearestWidget(&toWidgetOffset);
   if (widget) {
     nsCOMPtr<nsIDeviceContext> dx;
     mViewManager->GetDeviceContext(*getter_AddRefs(dx));
     PRInt32 p2a = dx->AppUnitsPerDevPixel();
-    nsIntRect ourRect(NSAppUnitsToIntPixels(toWidgetOffset.x, p2a),
-                      NSAppUnitsToIntPixels(toWidgetOffset.y, p2a),
-                      0,
-                      0);
-    widget->WidgetToScreen(ourRect, screenRect);
+    nsIntPoint ourPoint(NSAppUnitsToIntPixels(toWidgetOffset.x, p2a),
+                        NSAppUnitsToIntPixels(toWidgetOffset.y, p2a));
+    screenPoint = ourPoint + widget->WidgetToScreenOffset();
   }
   
-  return nsIntPoint(screenRect.x, screenRect.y);
+  return screenPoint;
 }
 
 nsIWidget* nsIView::GetNearestWidget(nsPoint* aOffset) const
 {
   nsPoint pt(0, 0);
   const nsView* v;
   for (v = static_cast<const nsView*>(this);
        v && !v->HasWidget(); v = v->GetParent()) {
--- a/widget/public/nsIWidget.h
+++ b/widget/public/nsIWidget.h
@@ -92,20 +92,20 @@ typedef nsEventStatus (* EVENT_CALLBACK)
 #ifdef XP_MACOSX
 #define NS_NATIVE_PLUGIN_PORT_QD    100
 #define NS_NATIVE_PLUGIN_PORT_CG    101
 #endif
 #ifdef XP_WIN
 #define NS_NATIVE_TSF_POINTER       100
 #endif
 
-// 075a7792-6ba9-454e-b431-25a43fdbd3f6
+// 0dda48db-4f61-44a7-9f92-041cd92b8a9c
 #define NS_IWIDGET_IID \
-{ 0x075a7792, 0x6ba9, 0x454e, \
-  { 0xb4, 0x31, 0x25, 0xa4, 0x3f, 0xdb, 0xd3, 0xf6 } }
+{ 0x0dda48db, 0x4f61, 0x44a7, \
+  { 0x9f, 0x92, 0x04, 0x1c, 0xd9, 0x2b, 0x8a, 0x9c } }
 
 // Hide the native window systems real window type so as to avoid
 // including native window system types and APIs. This is necessary
 // to ensure cross-platform code.
 typedef void* nsNativeWidget;
 
 /*
  * Window shadow styles
@@ -896,32 +896,22 @@ class nsIWidget : public nsISupports {
      * Set the widget's MenuBar's visibility
      *
      * @param aShow PR_TRUE to show, PR_FALSE to hide
      */
 
     NS_IMETHOD ShowMenuBar(PRBool aShow) = 0;
 
     /**
-     * Convert from this widget coordinates to screen coordinates.
+     * Return this widget's origin in screen coordinates.
      *
-     * @param  aOldRect  widget coordinates stored in the x,y members
-     * @param  aNewRect  screen coordinates stored in the x,y members
+     * @return screen coordinates stored in the x,y members
      */
 
-    NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect) = 0;
-
-    /**
-     * Convert from screen coordinates to this widget's coordinates.
-     *
-     * @param  aOldRect  screen coordinates stored in the x,y members
-     * @param  aNewRect  widget's coordinates stored in the x,y members
-     */
-
-    NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect) = 0;
+    virtual nsIntPoint WidgetToScreenOffset() = 0;
 
     /**
      * When adjustments are to made to a whole set of child widgets, call this
      * before resizing/positioning the child windows to minimize repaints. Must
      * be followed by EndResizingChildren() after child windows have been
      * adjusted.
      *
      */
--- a/widget/src/cocoa/nsChildView.h
+++ b/widget/src/cocoa/nsChildView.h
@@ -351,18 +351,17 @@ public:
   NS_IMETHOD              Invalidate(PRBool aIsSynchronous);
   NS_IMETHOD              Invalidate(const nsIntRect &aRect, PRBool aIsSynchronous);
   NS_IMETHOD              InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
   NS_IMETHOD              Validate();
 
   virtual void*           GetNativeData(PRUint32 aDataType);
   NS_IMETHOD              SetColorMap(nsColorMap *aColorMap);
   NS_IMETHOD              Scroll(PRInt32 aDx, PRInt32 aDy, nsIntRect *aClipRect);
-  NS_IMETHOD              WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect);
-  NS_IMETHOD              ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect);
+  virtual nsIntPoint      WidgetToScreenOffset();
   NS_IMETHOD              BeginResizingChildren(void);
   NS_IMETHOD              EndResizingChildren(void);
   virtual PRBool          ShowsResizeIndicator(nsIntRect* aResizerRect);
 
   static  PRBool          ConvertStatus(nsEventStatus aStatus)
                           { return aStatus == nsEventStatus_eConsumeNoDefault; }
   NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
 
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -2092,76 +2092,41 @@ PRBool nsChildView::PointInWidget(Point 
 
   // finally tell whether it's a hit
   return widgetRect.Contains(aThePoint.h, aThePoint.v);
 }
 
 #pragma mark -
 
 
-//    Convert the given rect to global coordinates.
-//    @param aLocalRect  -- rect in local coordinates of this widget
-//    @param aGlobalRect -- |aLocalRect| in global coordinates
-NS_IMETHODIMP nsChildView::WidgetToScreen(const nsIntRect& aLocalRect, nsIntRect& aGlobalRect)
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
-  NSRect temp;
-  GeckoRectToNSRect(aLocalRect, temp);
+//    Return the offset between this child view and the screen.
+//    @return       -- widget origin in screen coordinates
+nsIntPoint nsChildView::WidgetToScreenOffset()
+{
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
+
+  NSPoint temp;
+  temp.x = 0;
+  temp.y = 0;
   
-  // 1. First translate this rect into window coords. The returned rect is always in
+  // 1. First translate this point into window coords. The returned point is always in
   //    bottom-left coordinates.
-  //
-  //    NOTE: convertRect:toView:nil doesn't care if |mView| is a flipped view (with
-  //          top-left coords) and so assumes that our passed-in rect's origin is in
-  //          bottom-left coordinates. We adjust this further down, by subtracting
-  //          the final screen rect's origin by the rect's height, to get the origo
-  //          where we want it.
-  temp = [mView convertRect:temp toView:nil];  
+  temp = [mView convertPoint:temp toView:nil];  
   
   // 2. We turn the window-coord rect's origin into screen (still bottom-left) coords.
-  temp.origin = [[mView nativeWindow] convertBaseToScreen:temp.origin];
+  temp = [[mView nativeWindow] convertBaseToScreen:temp];
   
   // 3. Since we're dealing in bottom-left coords, we need to make it top-left coords
   //    before we pass it back to Gecko.
-  FlipCocoaScreenCoordinate(temp.origin);
-  
-  // 4. If this is rect has a size (and is not simply a point), it is important to account 
-  //    for the fact that convertRect:toView:nil thought our passed-in point was in bottom-left 
-  //    coords in step #1. Thus, we subtract the rect's height, to get the top-left rect's origin 
-  //     where we want it.
-  temp.origin.y -= temp.size.height;
+  FlipCocoaScreenCoordinate(temp);
   
-  NSRectToGeckoRect(temp, aGlobalRect);
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-
-//    Convert the given rect to local coordinates.
-//    @param aGlobalRect  -- rect in screen coordinates 
-//    @param aLocalRect -- |aGlobalRect| in coordinates of this widget
-NS_IMETHODIMP nsChildView::ScreenToWidget(const nsIntRect& aGlobalRect, nsIntRect& aLocalRect)
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
-  NSRect temp;
-  GeckoRectToNSRect(aGlobalRect, temp);
-  FlipCocoaScreenCoordinate(temp.origin);
-
-  temp.origin = [[mView nativeWindow] convertScreenToBase:temp.origin];   // convert to screen coords
-  temp = [mView convertRect:temp fromView:nil];                     // convert to window coords
-
-  NSRectToGeckoRect(temp, aLocalRect);
-  
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-} 
+  return nsIntPoint(NSToIntRound(temp.x), NSToIntRound(temp.y));
+
+  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0,0));
+}
 
 
 // Convert the coordinates to some device coordinates so GFX can draw.
 void nsChildView::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY)
 {
   PRInt32 offX = 0, offY = 0;
   this->CalcOffset(offX,offY);
 
--- a/widget/src/cocoa/nsCocoaWindow.h
+++ b/widget/src/cocoa/nsCocoaWindow.h
@@ -217,18 +217,17 @@ public:
     NS_IMETHOD              Enable(PRBool aState);
     NS_IMETHOD              IsEnabled(PRBool *aState);
     NS_IMETHOD              SetModal(PRBool aState);
     NS_IMETHOD              IsVisible(PRBool & aState);
     NS_IMETHOD              SetFocus(PRBool aState=PR_FALSE);
     NS_IMETHOD              SetMenuBar(void* aMenuBar);
     virtual nsMenuBarX*     GetMenuBar();
     NS_IMETHOD              ShowMenuBar(PRBool aShow);
-    NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect);
-    NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect);
+    virtual nsIntPoint WidgetToScreenOffset();
     
     virtual void* GetNativeData(PRUint32 aDataType) ;
 
     NS_IMETHOD              ConstrainPosition(PRBool aAllowSlop,
                                               PRInt32 *aX, PRInt32 *aY);
     NS_IMETHOD              Move(PRInt32 aX, PRInt32 aY);
     NS_IMETHOD              PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
                                         nsIWidget *aWidget, PRBool aActivate);
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -1216,47 +1216,25 @@ NS_IMETHODIMP nsCocoaWindow::SetFocus(PR
 
 
 NS_IMETHODIMP nsCocoaWindow::ShowMenuBar(PRBool aShow)
 {
   return NS_ERROR_FAILURE;
 }
 
 
-NS_IMETHODIMP nsCocoaWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
+nsIntPoint nsCocoaWindow::WidgetToScreenOffset()
 {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
 
-  aNewRect.x = r.x + aOldRect.x;
-  aNewRect.y = r.y + aOldRect.y;
-  aNewRect.width = aOldRect.width;
-  aNewRect.height = aOldRect.height;
-
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
-}
-
-
-NS_IMETHODIMP nsCocoaWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
-
-  nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
-
-  aNewRect.x = aOldRect.x - r.x;
-  aNewRect.y = aOldRect.y - r.y;
-  aNewRect.width = aOldRect.width;
-  aNewRect.height = aOldRect.height;
-
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
+  return r.TopLeft();
+
+  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0,0));
 }
 
 
 nsMenuBarX* nsCocoaWindow::GetMenuBar()
 {
   return mMenuBar;
 }
 
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -1345,18 +1345,17 @@ nsWindow::SetFocus(PRBool aRaise)
               (void *)this));
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::GetScreenBounds(nsIntRect &aRect)
 {
-    nsIntRect origin(0, 0, mBounds.width, mBounds.height);
-    WidgetToScreen(origin, aRect);
+    aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size());
     LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
          aRect.x, aRect.y,
          mBounds.width, mBounds.height,
          aRect.width, aRect.height));
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1848,58 +1847,32 @@ nsWindow::SetMenuBar(void * aMenuBar)
 }
 
 NS_IMETHODIMP
 nsWindow::ShowMenuBar(PRBool aShow)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
-nsWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
+nsIntPoint
+nsWindow::WidgetToScreenOffset()
 {
     gint x = 0, y = 0;
 
     if (mContainer) {
         gdk_window_get_root_origin(GTK_WIDGET(mContainer)->window,
                                    &x, &y);
-        LOG(("WidgetToScreen (container) %d %d\n", x, y));
+        LOG(("WidgetToScreenOffset (container) %d %d\n", x, y));
     }
     else if (mDrawingarea) {
         gdk_window_get_origin(mDrawingarea->inner_window, &x, &y);
-        LOG(("WidgetToScreen (drawing) %d %d\n", x, y));
-    }
-
-    aNewRect.x = x + aOldRect.x;
-    aNewRect.y = y + aOldRect.y;
-    aNewRect.width = aOldRect.width;
-    aNewRect.height = aOldRect.height;
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
-{
-    gint x = 0, y = 0;
-
-    if (mContainer) {
-        gdk_window_get_root_origin(GTK_WIDGET(mContainer)->window,
-                                   &x, &y);
-    }
-    else if (mDrawingarea) {
-        gdk_window_get_origin(mDrawingarea->inner_window, &x, &y);
-    }
-
-    aNewRect.x = aOldRect.x - x;
-    aNewRect.y = aOldRect.y - y;
-    aNewRect.width = aOldRect.width;
-    aNewRect.height = aOldRect.height;
-
-    return NS_OK;
+        LOG(("WidgetToScreenOffset (drawing) %d %d\n", x, y));
+    }
+
+    return nsIntPoint(x, y);
 }
 
 NS_IMETHODIMP
 nsWindow::BeginResizingChildren(void)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
@@ -2375,20 +2348,17 @@ nsWindow::OnConfigureEvent(GtkWidget *aW
         return FALSE;
 
     // Toplevel windows need to have their bounds set so that we can
     // keep track of our location.  It's not often that the x,y is set
     // by the layout engine.  Width and height are set elsewhere.
     if (mIsTopLevel) {
         mPlaced = PR_TRUE;
         // Need to translate this into the right coordinates
-        nsIntRect oldrect, newrect;
-        WidgetToScreen(oldrect, newrect);
-        mBounds.x = newrect.x;
-        mBounds.y = newrect.y;
+        mBounds.MoveTo(WidgetToScreenOffset());
     }
 
     nsGUIEvent event(PR_TRUE, NS_MOVE, this);
 
     event.refPoint.x = aEvent->x;
     event.refPoint.y = aEvent->y;
 
     // XXX mozilla will invalidate the entire window after this move
@@ -2538,21 +2508,17 @@ nsWindow::OnMotionNotifyEvent(GtkWidget 
     gdouble pressure = 0;
     gdk_event_get_axis ((GdkEvent*)aEvent, GDK_AXIS_PRESSURE, &pressure);
     // Sometime gdk generate 0 pressure value between normal values
     // We have to ignore that and use last valid value
     if (pressure)
       mLastMotionPressure = pressure;
     event.pressure = mLastMotionPressure;
 
-    nsRect windowRect;
-    ScreenToWidget(nsRect(nscoord(cursorX), nscoord(cursorY), 1, 1), windowRect);
-
-    event.refPoint.x = windowRect.x;
-    event.refPoint.y = windowRect.y;
+    event.refPoint = nsIntPoint(cursorX, cursorY) - WidgetToScreenOffset();
 
     event.isShift   = (aEvent->state & GDK_SHIFT_MASK)
         ? PR_TRUE : PR_FALSE;
     event.isControl = (aEvent->state & GDK_CONTROL_MASK)
         ? PR_TRUE : PR_FALSE;
     event.isAlt     = (aEvent->state & GDK_MOD1_MASK)
         ? PR_TRUE : PR_FALSE;
 
@@ -2632,21 +2598,18 @@ nsWindow::OnMotionNotifyEvent(GtkWidget 
 #endif /* MOZ_X11 */
     }
     else {
         // XXX see OnScrollEvent()
         if (aEvent->window == mDrawingarea->inner_window) {
             event.refPoint.x = nscoord(aEvent->x);
             event.refPoint.y = nscoord(aEvent->y);
         } else {
-            nsIntRect windowRect;
-            ScreenToWidget(nsIntRect(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root), 1, 1), windowRect);
-
-            event.refPoint.x = windowRect.x;
-            event.refPoint.y = windowRect.y;
+            nsIntPoint point(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root));
+            event.refPoint = point - WidgetToScreenOffset();
         }
 
         event.isShift   = (aEvent->state & GDK_SHIFT_MASK)
             ? PR_TRUE : PR_FALSE;
         event.isControl = (aEvent->state & GDK_CONTROL_MASK)
             ? PR_TRUE : PR_FALSE;
         event.isAlt     = (aEvent->state & GDK_MOD1_MASK)
             ? PR_TRUE : PR_FALSE;
@@ -2663,21 +2626,18 @@ void
 nsWindow::InitButtonEvent(nsMouseEvent &aEvent,
                           GdkEventButton *aGdkEvent)
 {
     // XXX see OnScrollEvent()
     if (aGdkEvent->window == mDrawingarea->inner_window) {
         aEvent.refPoint.x = nscoord(aGdkEvent->x);
         aEvent.refPoint.y = nscoord(aGdkEvent->y);
     } else {
-        nsIntRect windowRect;
-        ScreenToWidget(nsIntRect(NSToIntFloor(aGdkEvent->x_root), NSToIntFloor(aGdkEvent->y_root), 1, 1), windowRect);
-
-        aEvent.refPoint.x = windowRect.x;
-        aEvent.refPoint.y = windowRect.y;
+        nsIntPoint point(NSToIntFloor(aGdkEvent->x_root), NSToIntFloor(aGdkEvent->y_root));
+        aEvent.refPoint = point - WidgetToScreenOffset();
     }
 
     aEvent.isShift   = (aGdkEvent->state & GDK_SHIFT_MASK) != 0;
     aEvent.isControl = (aGdkEvent->state & GDK_CONTROL_MASK) != 0;
     aEvent.isAlt     = (aGdkEvent->state & GDK_MOD1_MASK) != 0;
     aEvent.isMeta    = (aGdkEvent->state & GDK_MOD4_MASK) != 0;
 
     aEvent.time = aGdkEvent->time;
@@ -3218,28 +3178,25 @@ nsWindow::OnScrollEvent(GtkWidget *aWidg
         break;
     case GDK_SCROLL_RIGHT:
         event.scrollFlags = nsMouseScrollEvent::kIsHorizontal;
         event.delta = 1;
         break;
     }
 
     if (aEvent->window == mDrawingarea->inner_window) {
-        // we are the window that the event happened on so no need for expensive ScreenToWidget
+        // we are the window that the event happened on so no need for expensive WidgetToScreenOffset
         event.refPoint.x = nscoord(aEvent->x);
         event.refPoint.y = nscoord(aEvent->y);
     } else {
         // XXX we're never quite sure which GdkWindow the event came from due to our custom bubbling
         // in scroll_event_cb(), so use ScreenToWidget to translate the screen root coordinates into
         // coordinates relative to this widget.
-        nsIntRect windowRect;
-        ScreenToWidget(nsIntRect(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root), 1, 1), windowRect);
-
-        event.refPoint.x = windowRect.x;
-        event.refPoint.y = windowRect.y;
+        nsIntPoint point(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root));
+        event.refPoint = point - WidgetToScreenOffset();
     }
 
     event.isShift   = (aEvent->state & GDK_SHIFT_MASK) != 0;
     event.isControl = (aEvent->state & GDK_CONTROL_MASK) != 0;
     event.isAlt     = (aEvent->state & GDK_MOD1_MASK) != 0;
     event.isMeta    = (aEvent->state & GDK_MOD4_MASK) != 0;
 
     event.time = aEvent->time;
--- a/widget/src/gtk2/nsWindow.h
+++ b/widget/src/gtk2/nsWindow.h
@@ -203,20 +203,17 @@ public:
                                   PRInt32     aDy);
     virtual void*      GetNativeData(PRUint32 aDataType);
     NS_IMETHOD         SetBorderStyle(nsBorderStyle aBorderStyle);
     NS_IMETHOD         SetTitle(const nsAString& aTitle);
     NS_IMETHOD         SetIcon(const nsAString& aIconSpec);
     NS_IMETHOD         SetWindowClass(const nsAString& xulWinType);
     NS_IMETHOD         SetMenuBar(void * aMenuBar);
     NS_IMETHOD         ShowMenuBar(PRBool aShow);
-    NS_IMETHOD         WidgetToScreen(const nsIntRect& aOldRect,
-                                      nsIntRect& aNewRect);
-    NS_IMETHOD         ScreenToWidget(const nsIntRect& aOldRect,
-                                      nsIntRect& aNewRect);
+    virtual nsIntPoint WidgetToScreenOffset();
     NS_IMETHOD         BeginResizingChildren(void);
     NS_IMETHOD         EndResizingChildren(void);
     NS_IMETHOD         EnableDragDrop(PRBool aEnable);
     virtual void       ConvertToDeviceCoordinates(nscoord &aX,
                                                   nscoord &aY);
     NS_IMETHOD         PreCreateWidget(nsWidgetInitData *aWidgetInitData);
     NS_IMETHOD         CaptureMouse(PRBool aCapture);
     NS_IMETHOD         CaptureRollupEvents(nsIRollupListener *aListener,
--- a/widget/src/os2/nsWindow.cpp
+++ b/widget/src/os2/nsWindow.cpp
@@ -362,43 +362,25 @@ NS_METHOD nsWindow::EndResizingChildren(
       WinSetMultWindowPos( 0/*hab*/, mSWPs, mlUsed);
       free( mSWPs);
       mSWPs = nsnull;
       mlUsed = mlHave = 0;
    }
    return NS_OK;
 }
 
-NS_METHOD nsWindow::WidgetToScreen(const nsIntRect &aOldRect, nsIntRect &aNewRect)
+nsIntPoint nsWindow::WidgetToScreenOffset()
 {
-  POINTL point = { aOldRect.x, aOldRect.y };
+  POINTL point = { 0, 0 };
   NS2PM( point);
 
   WinMapWindowPoints( mWnd, HWND_DESKTOP, &point, 1);
 
-  aNewRect.x = point.x;
-  aNewRect.y = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN) - point.y - 1;
-  aNewRect.width = aOldRect.width;
-  aNewRect.height = aOldRect.height;
-  return NS_OK;
-}
-
-NS_METHOD nsWindow::ScreenToWidget( const nsIntRect &aOldRect, nsIntRect &aNewRect)
-{
-  POINTL point = { aOldRect.x,
-                   WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN) - aOldRect.y - 1 };
-  WinMapWindowPoints( HWND_DESKTOP, mWnd, &point, 1);
-
-  PM2NS( point);
-
-  aNewRect.x = point.x;
-  aNewRect.y = point.y;
-  aNewRect.width = aOldRect.width;
-  aNewRect.height = aOldRect.height;
-  return NS_OK;
+  return nsIntPoint(point.x,
+                    WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN) - point.y - 1);
 }
 
 //-------------------------------------------------------------------------
 //
 // Initialize an event to dispatch
 //
 //-------------------------------------------------------------------------
 void nsWindow::InitEvent(nsGUIEvent& event, nsIntPoint* aPoint)
--- a/widget/src/os2/nsWindow.h
+++ b/widget/src/os2/nsWindow.h
@@ -157,18 +157,17 @@ class nsWindow : public nsBaseWidget,
    NS_IMETHOD ModalEventFilter( PRBool aRealEvent, void *aEvent,
                                 PRBool *aForWindow );
 
    NS_IMETHOD GetPreferredSize( PRInt32 &aWidth, PRInt32 &aHeight);
    NS_IMETHOD SetPreferredSize( PRInt32 aWidth, PRInt32 aHeight);
 
    NS_IMETHOD BeginResizingChildren();
    NS_IMETHOD EndResizingChildren();
-   NS_IMETHOD WidgetToScreen( const nsIntRect &aOldRect, nsIntRect &aNewRect);
-   NS_IMETHOD ScreenToWidget( const nsIntRect &aOldRect, nsIntRect &aNewRect);
+   virtual nsIntPoint WidgetToScreenOffset();
    NS_IMETHOD DispatchEvent( struct nsGUIEvent *event, nsEventStatus &aStatus);
    NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
 
    NS_IMETHOD              GetLastInputEventTime(PRUint32& aTime);
 
    // Widget appearance
    NS_IMETHOD              SetColorMap( nsColorMap *aColorMap);
    NS_IMETHOD              SetCursor( nsCursor aCursor);
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -411,23 +411,18 @@ nsWindow::Move(PRInt32 aX, PRInt32 aY)
 
 
     if (!mDrawingArea)
         return NS_OK;
 
     QPoint pos(aX, aY);
     if (mDrawingArea) {
         if (mParent && mDrawingArea->windowType() == Qt::Popup) {
-            nsIntRect oldrect, newrect;
-            oldrect.x = aX;
-            oldrect.y = aY;
-
-            mParent->WidgetToScreen(oldrect, newrect);
-
-            pos = QPoint(newrect.x, newrect.y);
+            if (mParent->mDrawingArea)
+                pos = mParent->mDrawingArea->mapToGlobal(pos);
 #ifdef DEBUG_WIDGETS
             qDebug("pos is [%d,%d]", pos.x(), pos.y());
 #endif
         } else {
             qDebug("Widget within another? (%p)", (void*)mDrawingArea);
         }
     }
 
@@ -583,18 +578,17 @@ nsWindow::SetFocus(PRBool aRaise)
               (void *)this));
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::GetScreenBounds(nsIntRect &aRect)
 {
-    nsIntRect origin(0, 0, mBounds.width, mBounds.height);
-    WidgetToScreen(origin, aRect);
+    aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size());
     LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
          aRect.x, aRect.y,
          mBounds.width, mBounds.height,
          aRect.width, aRect.height));
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -908,48 +902,27 @@ nsWindow::SetIcon(const nsAString& aIcon
 }
 
 NS_IMETHODIMP
 nsWindow::ShowMenuBar(PRBool aShow)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
-nsWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
+nsIntPoint
+nsWindow::WidgetToScreenOffset()
 {
-    NS_ENSURE_TRUE(mDrawingArea, NS_OK);
-
-    QPoint origin(aOldRect.x, aOldRect.y);
+    NS_ENSURE_TRUE(mDrawingArea, nsIntPoint(0,0));
+
+    QPoint origin(0, 0);
     origin = mDrawingArea->mapToGlobal(origin);
 
-    aNewRect.x = origin.x();
-    aNewRect.y = origin.y();
-    aNewRect.width = aOldRect.width;
-    aNewRect.height = aOldRect.height;
-
-    return NS_OK;
+    return nsIntPoint(origin.x(), origin.y());
 }
-
-NS_IMETHODIMP
-nsWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
-{
-    NS_ENSURE_TRUE(mDrawingArea, NS_OK);
-
-    QPoint origin(aOldRect.x, aOldRect.y);
-    origin = mDrawingArea->mapFromGlobal(origin);
-
-    aNewRect.x = origin.x();
-    aNewRect.y = origin.y();
-    aNewRect.width = aOldRect.width;
-    aNewRect.height = aOldRect.height;
-
-    return NS_OK;
-}
-
+ 
 NS_IMETHODIMP
 nsWindow::BeginResizingChildren(void)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsWindow::EndResizingChildren(void)
@@ -1220,20 +1193,17 @@ nsWindow::OnMoveEvent(QMoveEvent *aEvent
     }
 
     // Toplevel windows need to have their bounds set so that we can
     // keep track of our location.  It's not often that the x,y is set
     // by the layout engine.  Width and height are set elsewhere.
     QPoint pos = aEvent->pos();
     if (mIsTopLevel) {
         // Need to translate this into the right coordinates
-        nsIntRect oldrect, newrect;
-        WidgetToScreen(oldrect, newrect);
-        mBounds.x = newrect.x;
-        mBounds.y = newrect.y;
+        mBounds.MoveTo(WidgetToScreenOffset());
     }
 
     nsGUIEvent event(PR_TRUE, NS_MOVE, this);
 
     event.refPoint.x = pos.x();
     event.refPoint.y = pos.y();
 
     // XXX mozilla will invalidate the entire window after this move
@@ -1894,23 +1864,18 @@ nsWindow::NativeResize(PRInt32 aX, PRInt
 {
     LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this,
          aX, aY, aWidth, aHeight));
 
     QPoint pos(aX, aY);
     if (mDrawingArea)
     {
         if (mParent && mDrawingArea->windowType() == Qt::Popup) {
-            nsIntRect oldrect, newrect;
-            oldrect.x = aX;
-            oldrect.y = aY;
-
-            mParent->WidgetToScreen(oldrect, newrect);
-
-            pos = QPoint(newrect.x, newrect.y);
+            if (mParent->mDrawingArea)
+                pos = mParent->mDrawingArea->mapToGlobal(pos);
 #ifdef DEBUG_WIDGETS
             qDebug("pos is [%d,%d]", pos.x(), pos.y());
 #endif
         } else {
 #ifdef DEBUG_WIDGETS
             qDebug("Widget with original position? (%p)", mDrawingArea);
 #endif
         }
@@ -2526,23 +2491,18 @@ nsWindow::Resize(PRInt32 aX, PRInt32 aY,
     if (!mDrawingArea)
         return NS_OK;
 
     QPoint pos(aX, aY);
 
     // XXXvlad what?
 #if 0
     if (mParent && mDrawingArea->windowType() == Qt::Popup) {
-        nsIntRect oldrect, newrect;
-        oldrect.x = aX;
-        oldrect.y = aY;
-
-        mParent->WidgetToScreen(oldrect, newrect);
-
-        pos = QPoint(newrect.x, newrect.y);
+        if (mParent->mDrawingArea)
+            pos = mParent->mDrawingArea->mapToGlobal(pos);
 #ifdef DEBUG_WIDGETS
         qDebug("pos is [%d,%d]", pos.x(), pos.y());
 #endif
     } else {
 #ifdef DEBUG_WIDGETS
         qDebug("Widget with original position? (%p)", mDrawingArea);
 #endif
     }
--- a/widget/src/qt/nsWindow.h
+++ b/widget/src/qt/nsWindow.h
@@ -191,20 +191,17 @@ public:
     NS_IMETHOD         PreCreateWidget(nsWidgetInitData *aWidgetInitData);
 
     virtual void*      GetNativeData(PRUint32 aDataType);
     NS_IMETHOD         SetBorderStyle(nsBorderStyle aBorderStyle);
     NS_IMETHOD         SetTitle(const nsAString& aTitle);
     NS_IMETHOD         SetIcon(const nsAString& aIconSpec);
     NS_IMETHOD         SetMenuBar(void * aMenuBar) { return NS_ERROR_FAILURE; }
     NS_IMETHOD         ShowMenuBar(PRBool aShow);
-    NS_IMETHOD         WidgetToScreen(const nsIntRect& aOldRect,
-                                      nsIntRect& aNewRect);
-    NS_IMETHOD         ScreenToWidget(const nsIntRect& aOldRect,
-                                      nsIntRect& aNewRect);
+    virtual nsIntPoint WidgetToScreenOffset();
     NS_IMETHOD         BeginResizingChildren(void);
     NS_IMETHOD         EndResizingChildren(void);
     NS_IMETHOD         GetPreferredSize (PRInt32 &aWidth,
                                          PRInt32 &aHeight);
     NS_IMETHOD         SetPreferredSize (PRInt32 aWidth,
                                          PRInt32 aHeight);
     NS_IMETHOD         DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus);
 
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -894,40 +894,23 @@ NS_METHOD nsWindow::EndResizingChildren(
 {
   if (NULL != mDeferredPositioner) {
     ::EndDeferWindowPos(mDeferredPositioner);
     mDeferredPositioner = NULL;
   }
   return NS_OK;
 }
 
-NS_METHOD nsWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
+nsIntPoint nsWindow::WidgetToScreenOffset()
 {
   POINT point;
-  point.x = aOldRect.x;
-  point.y = aOldRect.y;
+  point.x = 0;
+  point.y = 0;
   ::ClientToScreen(mWnd, &point);
-  aNewRect.x = point.x;
-  aNewRect.y = point.y;
-  aNewRect.width = aOldRect.width;
-  aNewRect.height = aOldRect.height;
-  return NS_OK;
-}
-
-NS_METHOD nsWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
-{
-  POINT point;
-  point.x = aOldRect.x;
-  point.y = aOldRect.y;
-  ::ScreenToClient(mWnd, &point);
-  aNewRect.x = point.x;
-  aNewRect.y = point.y;
-  aNewRect.width = aOldRect.width;
-  aNewRect.height = aOldRect.height;
-  return NS_OK;
+  return nsIntPoint(point.x, point.y);
 }
 
 LPARAM nsWindow::lParamToScreen(LPARAM lParam)
 {
   POINT pt;
   pt.x = GET_X_LPARAM(lParam);
   pt.y = GET_Y_LPARAM(lParam);
   ::ClientToScreen(mWnd, &pt);
@@ -6283,21 +6266,17 @@ PRBool nsWindow::DispatchMouseEvent(PRUi
   }
 
   event.isShift   = IS_VK_DOWN(NS_VK_SHIFT);
   event.isControl = IS_VK_DOWN(NS_VK_CONTROL);
   event.isMeta    = PR_FALSE;
   event.isAlt     = IS_VK_DOWN(NS_VK_ALT);
   event.button    = aButton;
 
-  nsIntRect mpWidget;
-  nsIntRect mpScreen;
-  mpWidget.x = eventPoint.x;
-  mpWidget.y = eventPoint.y;
-  WidgetToScreen(mpWidget, mpScreen);
+  nsIntPoint mpScreen = eventPoint + WidgetToScreenOffset();
 
   // Suppress mouse moves caused by widget creation
   if (aEventType == NS_MOUSE_MOVE) 
   {
     if ((gLastMouseMovePoint.x == mpScreen.x) && (gLastMouseMovePoint.y == mpScreen.y))
       return result;
     gLastMouseMovePoint.x = mpScreen.x;
     gLastMouseMovePoint.y = mpScreen.y;
@@ -7549,20 +7528,20 @@ nsWindow::ResolveIMECaretPos(nsIWidget* 
                              nsIntRect& aOutRect)
 {
   aOutRect = aCursorRect;
 
   if (aReferenceWidget == aNewOriginWidget)
     return;
 
   if (aReferenceWidget)
-    aReferenceWidget->WidgetToScreen(aOutRect, aOutRect);
+    aOutRect.MoveBy(aReferenceWidget->WidgetToScreenOffset());
 
   if (aNewOriginWidget)
-    aNewOriginWidget->ScreenToWidget(aOutRect, aOutRect);
+    aOutRect.MoveBy(-aNewOriginWidget->WidgetToScreenOffset());
 }
 
 //==========================================================================
 BOOL nsWindow::OnIMESelect(BOOL  aSelected, WORD aLangID)
 {
 #ifdef DEBUG_IME2
   printf("OnIMESelect\n");
 #endif
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -191,18 +191,17 @@ public:
   //XXX-Scroll is obsolete it is going away soon
   NS_IMETHOD              Scroll(PRInt32 aDx, PRInt32 aDy, nsIntRect *aClipRect);
   NS_IMETHOD              ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
   NS_IMETHOD              ScrollRect(nsIntRect &aRect, PRInt32 aDx, PRInt32 aDy);
   NS_IMETHOD              SetTitle(const nsAString& aTitle);
   NS_IMETHOD              SetIcon(const nsAString& aIconSpec);
   NS_IMETHOD              SetMenuBar(void * aMenuBar) { return NS_ERROR_FAILURE; }
   NS_IMETHOD              ShowMenuBar(PRBool aShow)         { return NS_ERROR_FAILURE; }
-  NS_IMETHOD              WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect);
-  NS_IMETHOD              ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect);
+  virtual nsIntPoint      WidgetToScreenOffset();
   NS_IMETHOD              BeginResizingChildren(void);
   NS_IMETHOD              EndResizingChildren(void);
   NS_IMETHOD              GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
   NS_IMETHOD              SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
   NS_IMETHOD              DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
   NS_IMETHOD              EnableDragDrop(PRBool aEnable);
 
   virtual void            SetUpForPaint(HDC aHDC);