From 67af4817e93dadac8bf44ae7e16ba990327a0c33 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 19 Aug 2016 09:03:04 +1000 Subject: [PATCH] Bug 1293596 (part 2) - Rework nsIWidget bounds getters. r=mstange. This patch makes GetBounds(), GetScreenBounds() and GetClientBounds() more obviously infallible, like existing functions such as GetNaturalBounds() and GetClientSize(). This results in clearer behaviour in nsCocoaWindow.mm if Objective C exceptions occur. Along the way, the patch removes some useless failure checks for these functions. The patch also removes the NS_IMETHOD from GetRestoredBounds and makes that function MOZ_MUST_USE. --- accessible/generic/Accessible.cpp | 3 +- docshell/base/nsDocShell.cpp | 3 +- dom/base/nsDOMWindowUtils.cpp | 4 +- dom/base/nsGlobalWindow.cpp | 6 +- dom/events/EventStateManager.cpp | 3 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 6 +- embedding/browser/nsWebBrowser.cpp | 3 +- gfx/layers/client/ClientLayerManager.cpp | 3 +- gfx/tests/gtest/TestCompositor.cpp | 9 +- layout/base/nsLayoutUtils.cpp | 9 +- layout/base/nsPresContext.cpp | 3 +- layout/base/nsPresShell.cpp | 4 +- layout/generic/nsFrame.cpp | 6 +- layout/xul/PopupBoxObject.cpp | 3 +- layout/xul/nsResizerFrame.cpp | 2 +- layout/xul/nsTitleBarFrame.cpp | 3 +- view/nsView.cpp | 8 +- view/nsViewManager.cpp | 3 +- widget/PuppetWidget.cpp | 12 +- widget/PuppetWidget.h | 2 +- widget/android/nsWindow.cpp | 13 +- widget/android/nsWindow.h | 2 +- widget/cocoa/nsChildView.h | 6 +- widget/cocoa/nsChildView.mm | 30 +-- widget/cocoa/nsCocoaWindow.h | 4 +- widget/cocoa/nsCocoaWindow.mm | 30 ++- widget/gtk/nsWindow.cpp | 32 ++-- widget/gtk/nsWindow.h | 4 +- widget/nsBaseWidget.cpp | 39 ++-- widget/nsBaseWidget.h | 8 +- widget/nsIWidget.h | 34 ++-- widget/nsNativeTheme.cpp | 4 +- widget/uikit/nsWindow.h | 2 +- widget/uikit/nsWindow.mm | 22 +-- widget/windows/IMMHandler.cpp | 3 +- widget/windows/TSFTextStore.cpp | 9 +- widget/windows/nsWindow.cpp | 205 +++++++++++---------- widget/windows/nsWindow.h | 8 +- xpfe/appshell/nsWebShellWindow.cpp | 3 +- xpfe/appshell/nsXULWindow.cpp | 3 +- 40 files changed, 242 insertions(+), 314 deletions(-) diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index 7667477f8348..6138cd4fead9 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -525,8 +525,7 @@ Accessible::ChildAtPoint(int32_t aX, int32_t aY, nsIWidget* rootWidget = rootFrame->GetView()->GetNearestWidget(nullptr); NS_ENSURE_TRUE(rootWidget, nullptr); - LayoutDeviceIntRect rootRect; - rootWidget->GetScreenBounds(rootRect); + LayoutDeviceIntRect rootRect = rootWidget->GetScreenBounds(); WidgetMouseEvent dummyEvent(true, eMouseMove, rootWidget, WidgetMouseEvent::eSynthesized); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 1b9e264e120a..5b2fe04753de 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -5939,8 +5939,7 @@ nsDocShell::GetPositionAndSize(int32_t* aX, int32_t* aY, int32_t* aWidth, { if (mParentWidget) { // ensure size is up-to-date if window has changed resolution - LayoutDeviceIntRect r; - mParentWidget->GetClientBounds(r); + LayoutDeviceIntRect r = mParentWidget->GetClientBounds(); SetPositionAndSize(mBounds.x, mBounds.y, r.width, r.height, 0); } diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index affa069093f8..08ec0b69c0e3 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -2041,9 +2041,7 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, nsIFrame* popupFrame = nsLayoutUtils::GetPopupFrameForEventCoordinates(presContext->GetRootPresContext(), &dummyEvent); - LayoutDeviceIntRect widgetBounds; - nsresult rv = widget->GetClientBounds(widgetBounds); - NS_ENSURE_SUCCESS(rv, rv); + LayoutDeviceIntRect widgetBounds = widget->GetClientBounds(); widgetBounds.MoveTo(0, 0); // There is no popup frame at the point and the point isn't in our widget, diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 0b82fd877acc..e4a6f2b0c105 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -13827,11 +13827,7 @@ nsGlobalWindow::NotifyDefaultButtonLoaded(Element& aDefaultButton, aError.Throw(NS_ERROR_FAILURE); return; } - LayoutDeviceIntRect widgetRect; - aError = widget->GetScreenBounds(widgetRect); - if (aError.Failed()) { - return; - } + LayoutDeviceIntRect widgetRect = widget->GetScreenBounds(); // Convert the buttonRect coordinates from screen to the widget. buttonRect -= widgetRect.TopLeft(); diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 4d1b4f07471f..fc0734c9dc2f 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -4157,8 +4157,7 @@ GetWindowClientRectCenter(nsIWidget* aWidget) { NS_ENSURE_TRUE(aWidget, LayoutDeviceIntPoint(0, 0)); - LayoutDeviceIntRect rect; - aWidget->GetClientBounds(rect); + LayoutDeviceIntRect rect = aWidget->GetClientBounds(); LayoutDeviceIntPoint point(rect.x + rect.width / 2, rect.y + rect.height / 2); int32_t round = aWidget->RoundsWidgetCoordinatesTo(); diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index b5176bbd2887..c25cf8320a0d 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -1079,8 +1079,7 @@ NPBool nsPluginInstanceOwner::ConvertPointPuppet(PuppetWidget *widget, nsPoint windowPosition = AsNsPoint(rootWidget->GetWindowPosition()) / scaleFactor; // Window size is tab size + chrome size. - LayoutDeviceIntRect tabContentBounds; - NS_ENSURE_SUCCESS(puppetWidget->GetBounds(tabContentBounds), false); + LayoutDeviceIntRect tabContentBounds = puppetWidget->GetBounds(); tabContentBounds.ScaleInverseRoundOut(scaleFactor); int32_t windowH = tabContentBounds.height + int(chromeSize.y); @@ -1186,8 +1185,7 @@ NPBool nsPluginInstanceOwner::ConvertPointNoPuppet(nsIWidget *widget, screen->GetRect(&screenX, &screenY, &screenWidth, &screenHeight); screenHeight /= scaleFactor; - LayoutDeviceIntRect windowScreenBounds; - NS_ENSURE_SUCCESS(widget->GetScreenBounds(windowScreenBounds), false); + LayoutDeviceIntRect windowScreenBounds = widget->GetScreenBounds(); windowScreenBounds.ScaleInverseRoundOut(scaleFactor); int32_t windowX = windowScreenBounds.x; int32_t windowY = windowScreenBounds.y; diff --git a/embedding/browser/nsWebBrowser.cpp b/embedding/browser/nsWebBrowser.cpp index df58227ecddc..ec053d3e0dc4 100644 --- a/embedding/browser/nsWebBrowser.cpp +++ b/embedding/browser/nsWebBrowser.cpp @@ -1406,8 +1406,7 @@ nsWebBrowser::GetPositionAndSize(int32_t* aX, int32_t* aY, *aCY = mInitInfo->cy; } } else if (mInternalWidget) { - LayoutDeviceIntRect bounds; - NS_ENSURE_SUCCESS(mInternalWidget->GetBounds(bounds), NS_ERROR_FAILURE); + LayoutDeviceIntRect bounds = mInternalWidget->GetBounds(); if (aX) { *aX = bounds.x; diff --git a/gfx/layers/client/ClientLayerManager.cpp b/gfx/layers/client/ClientLayerManager.cpp index de0e59696bb2..bf898b19aa8a 100644 --- a/gfx/layers/client/ClientLayerManager.cpp +++ b/gfx/layers/client/ClientLayerManager.cpp @@ -520,8 +520,7 @@ ClientLayerManager::MakeSnapshotIfRequired() // The compositor doesn't draw to a different sized surface // when there's a rotation. Instead we rotate the result // when drawing into dt - LayoutDeviceIntRect outerBounds; - mWidget->GetBounds(outerBounds); + LayoutDeviceIntRect outerBounds = mWidget->GetBounds(); IntRect bounds = ToOutsideIntRect(mShadowTarget->GetClipExtents()); if (mTargetRotation) { diff --git a/gfx/tests/gtest/TestCompositor.cpp b/gfx/tests/gtest/TestCompositor.cpp index 10759f644c8c..6d2c5ad72ed4 100644 --- a/gfx/tests/gtest/TestCompositor.cpp +++ b/gfx/tests/gtest/TestCompositor.cpp @@ -36,12 +36,11 @@ public: NS_DECL_ISUPPORTS_INHERITED - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) override { - aRect = LayoutDeviceIntRect(0, 0, gCompWidth, gCompHeight); - return NS_OK; + virtual LayoutDeviceIntRect GetClientBounds() override { + return LayoutDeviceIntRect(0, 0, gCompWidth, gCompHeight); } - NS_IMETHOD GetBounds(LayoutDeviceIntRect& aRect) override { - return GetClientBounds(aRect); + virtual LayoutDeviceIntRect GetBounds() override { + return GetClientBounds(); } void* GetNativeData(uint32_t aDataType) override { diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index c08936099455..77b41b6b11e1 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -2991,8 +2991,7 @@ static LayoutDeviceIntPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRoo if (!parent) { break; } - LayoutDeviceIntRect bounds; - aWidget->GetBounds(bounds); + LayoutDeviceIntRect bounds = aWidget->GetBounds(); offset += bounds.TopLeft(); aWidget = parent; } @@ -8319,8 +8318,7 @@ UpdateCompositionBoundsForRCDRSF(ParentLayerRect& aCompBounds, #endif if (widget) { - LayoutDeviceIntRect widgetBounds; - widget->GetBounds(widgetBounds); + LayoutDeviceIntRect widgetBounds = widget->GetBounds(); widgetBounds.MoveTo(0, 0); aCompBounds = ParentLayerRect( ViewAs( @@ -8442,8 +8440,7 @@ nsLayoutUtils::CalculateRootCompositionSize(nsIFrame* aFrame, } } else { nsIWidget* widget = aFrame->GetNearestWidget(); - LayoutDeviceIntRect widgetBounds; - widget->GetBounds(widgetBounds); + LayoutDeviceIntRect widgetBounds = widget->GetBounds(); rootCompositionSize = ScreenSize( ViewAs(widgetBounds.Size(), PixelCastJustification::LayoutDeviceIsScreenForBounds)); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 04214395e493..988f5ab53c6c 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -2968,8 +2968,7 @@ SortConfigurations(nsTArray* aConfigurations) for (uint32_t j = 0; j < pluginsToMove.Length(); ++j) { if (i == j) continue; - LayoutDeviceIntRect bounds; - pluginsToMove[j].mChild->GetBounds(bounds); + LayoutDeviceIntRect bounds = pluginsToMove[j].mChild->GetBounds(); AutoTArray clipRects; pluginsToMove[j].mChild->GetWindowClipRegion(&clipRects); if (HasOverlap(bounds.TopLeft(), clipRects, diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index f5c441167408..e97ced9202aa 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -10254,8 +10254,8 @@ CompareTrees(nsPresContext* aFirstPresContext, nsIFrame* aFirstFrame, LogVerifyMessage(k1, k2, "child widgets are not matched\n"); } else if (nullptr != w1) { - w1->GetBounds(r1); - w2->GetBounds(r2); + r1 = w1->GetBounds(); + r2 = w2->GetBounds(); if (!r1.IsEqualEdges(r2)) { LogVerifyMessage(k1, k2, "(widget rects)", r1.ToUnknownRect(), r2.ToUnknownRect()); diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 0f1e68f53d83..9f80bd953890 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -5387,10 +5387,8 @@ nsIFrame::GetTransformMatrix(const nsIFrame* aStopAtAncestor, if (widget && rootPresContext) { nsIWidget* toplevel = rootPresContext->GetNearestWidget(); if (toplevel) { - LayoutDeviceIntRect screenBounds; - widget->GetClientBounds(screenBounds); - LayoutDeviceIntRect toplevelScreenBounds; - toplevel->GetClientBounds(toplevelScreenBounds); + LayoutDeviceIntRect screenBounds = widget->GetClientBounds(); + LayoutDeviceIntRect toplevelScreenBounds = toplevel->GetClientBounds(); LayoutDeviceIntPoint translation = screenBounds.TopLeft() - toplevelScreenBounds.TopLeft(); diff --git a/layout/xul/PopupBoxObject.cpp b/layout/xul/PopupBoxObject.cpp index 6a4952f6aeec..f8a915ae4908 100644 --- a/layout/xul/PopupBoxObject.cpp +++ b/layout/xul/PopupBoxObject.cpp @@ -283,8 +283,7 @@ PopupBoxObject::GetOuterScreenRect() if (view) { nsIWidget* widget = view->GetWidget(); if (widget) { - LayoutDeviceIntRect screenRect; - widget->GetScreenBounds(screenRect); + LayoutDeviceIntRect screenRect = widget->GetScreenBounds(); int32_t pp = menuPopupFrame->PresContext()->AppUnitsPerDevPixel(); rect->SetLayoutRect(LayoutDeviceIntRect::ToAppUnits(screenRect, pp)); diff --git a/layout/xul/nsResizerFrame.cpp b/layout/xul/nsResizerFrame.cpp index ac0e1bc0f964..b32b84fe5009 100644 --- a/layout/xul/nsResizerFrame.cpp +++ b/layout/xul/nsResizerFrame.cpp @@ -251,7 +251,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, if (menuPopupFrame) { nsCOMPtr widget = menuPopupFrame->GetWidget(); if (widget) - widget->GetScreenBounds(oldRect); + oldRect = widget->GetScreenBounds(); // convert the new rectangle into outer window coordinates LayoutDeviceIntPoint clientOffset = widget->GetClientOffset(); diff --git a/layout/xul/nsTitleBarFrame.cpp b/layout/xul/nsTitleBarFrame.cpp index ad5f93224dfe..2792403dcc02 100644 --- a/layout/xul/nsTitleBarFrame.cpp +++ b/layout/xul/nsTitleBarFrame.cpp @@ -125,8 +125,7 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, if (parent) { nsMenuPopupFrame* menuPopupFrame = static_cast(parent); nsCOMPtr widget = menuPopupFrame->GetWidget(); - LayoutDeviceIntRect bounds; - widget->GetScreenBounds(bounds); + LayoutDeviceIntRect bounds = widget->GetScreenBounds(); CSSPoint cssPos = (bounds.TopLeft() + nsMoveBy) / aPresContext->CSSToDevPixelScale(); diff --git a/view/nsView.cpp b/view/nsView.cpp index 154441a40f8e..8f509cadeb95 100644 --- a/view/nsView.cpp +++ b/view/nsView.cpp @@ -304,8 +304,7 @@ void nsView::DoResetWidgetBounds(bool aMoveOnly, nsWindowType type = widget->WindowType(); - LayoutDeviceIntRect curBounds; - widget->GetClientBounds(curBounds); + LayoutDeviceIntRect curBounds = widget->GetClientBounds(); bool invisiblePopup = type == eWindowType_popup && ((curBounds.IsEmpty() && mDimBounds.IsEmpty()) || mVis == nsViewVisibility_kHide); @@ -780,10 +779,9 @@ void nsView::List(FILE* out, int32_t aIndent) const fprintf(out, "%p ", (void*)this); if (nullptr != mWindow) { nscoord p2a = mViewManager->AppUnitsPerDevPixel(); - LayoutDeviceIntRect rect; - mWindow->GetClientBounds(rect); + LayoutDeviceIntRect rect = mWindow->GetClientBounds(); nsRect windowBounds = LayoutDeviceIntRect::ToAppUnits(rect, p2a); - mWindow->GetBounds(rect); + rect = mWindow->GetBounds(); nsRect nonclientBounds = LayoutDeviceIntRect::ToAppUnits(rect, p2a); nsrefcnt widgetRefCnt = mWindow.get()->AddRef() - 1; mWindow.get()->Release(); diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp index 93afabe222ba..63844a8ceed8 100644 --- a/view/nsViewManager.cpp +++ b/view/nsViewManager.cpp @@ -603,8 +603,7 @@ nsViewManager::InvalidateWidgetArea(nsView *aWidgetView, // plugin widgets are basically invisible #ifndef XP_MACOSX // GetBounds should compensate for chrome on a toplevel widget - LayoutDeviceIntRect bounds; - childWidget->GetBounds(bounds); + LayoutDeviceIntRect bounds = childWidget->GetBounds(); nsTArray clipRects; childWidget->GetWindowClipRegion(&clipRects); diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 3051e3c5ce27..cca0010565b5 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -251,8 +251,7 @@ PuppetWidget::ConfigureChildren(const nsTArray& aConfigurations) NS_ASSERTION(w->GetParent() == this, "Configured widget is not a child"); w->SetWindowClipRegion(configuration.mClipRegion, true); - LayoutDeviceIntRect bounds; - w->GetBounds(bounds); + LayoutDeviceIntRect bounds = w->GetBounds(); if (bounds.Size() != configuration.mBounds.Size()) { w->Resize(configuration.mBounds.x, configuration.mBounds.y, configuration.mBounds.width, configuration.mBounds.height, @@ -1241,11 +1240,10 @@ PuppetWidget::GetWindowPosition() return nsIntPoint(winX, winY) + GetOwningTabChild()->GetClientOffset().ToUnknownPoint(); } -NS_IMETHODIMP -PuppetWidget::GetScreenBounds(LayoutDeviceIntRect& aRect) { - aRect.MoveTo(WidgetToScreenOffset()); - aRect.SizeTo(mBounds.Size()); - return NS_OK; +LayoutDeviceIntRect +PuppetWidget::GetScreenBounds() +{ + return LayoutDeviceIntRect(WidgetToScreenOffset(), mBounds.Size()); } uint32_t PuppetWidget::GetMaxTouchPoints() const diff --git a/widget/PuppetWidget.h b/widget/PuppetWidget.h index b476e445a602..30c70675c5a5 100644 --- a/widget/PuppetWidget.h +++ b/widget/PuppetWidget.h @@ -209,7 +209,7 @@ public: // Get the screen position of the application window. nsIntPoint GetWindowPosition(); - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetScreenBounds() override; NS_IMETHOD StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent, int32_t aPanelX, int32_t aPanelY, diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index fabf3cd37037..ccb7700d61c3 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -1864,17 +1864,10 @@ nsWindow::BringToFront() RedrawAll(); } -NS_IMETHODIMP -nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetScreenBounds() { - LayoutDeviceIntPoint p = WidgetToScreenOffset(); - - aRect.x = p.x; - aRect.y = p.y; - aRect.width = mBounds.width; - aRect.height = mBounds.height; - - return NS_OK; + return LayoutDeviceIntRect(WidgetToScreenOffset(), mBounds.Size()); } LayoutDeviceIntPoint diff --git a/widget/android/nsWindow.h b/widget/android/nsWindow.h index 3683bff7e421..249faf853978 100644 --- a/widget/android/nsWindow.h +++ b/widget/android/nsWindow.h @@ -161,7 +161,7 @@ public: virtual bool IsEnabled() const override; NS_IMETHOD Invalidate(const LayoutDeviceIntRect& aRect) override; NS_IMETHOD SetFocus(bool aRaise = false) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetScreenBounds() override; virtual LayoutDeviceIntPoint WidgetToScreenOffset() override; NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, nsEventStatus& aStatus) override; diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index ceaf4734b3be..a25af9d013a8 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -321,9 +321,9 @@ public: NS_IMETHOD Enable(bool aState) override; virtual bool IsEnabled() const override; NS_IMETHOD SetFocus(bool aRaise) override; - NS_IMETHOD GetBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetBounds() override; + virtual LayoutDeviceIntRect GetClientBounds() override; + virtual LayoutDeviceIntRect GetScreenBounds() override; // Returns the "backing scale factor" of the view's window, which is the // ratio of pixels in the window's backing store to Cocoa points. Prior to diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 71bc69091fd1..f5b40c581cb6 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -873,28 +873,30 @@ NS_IMETHODIMP nsChildView::SetCursor(imgIContainer* aCursor, #pragma mark - // Get this component dimension -NS_IMETHODIMP nsChildView::GetBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsChildView::GetBounds() { - aRect = !mView ? mBounds : CocoaPointsToDevPixels([mView frame]); - return NS_OK; + return !mView ? mBounds : CocoaPointsToDevPixels([mView frame]); } -NS_IMETHODIMP nsChildView::GetClientBounds(mozilla::LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsChildView::GetClientBounds() { - GetBounds(aRect); + LayoutDeviceIntRect rect = GetBounds(); if (!mParentWidget) { // For top level widgets we want the position on screen, not the position // of this view inside the window. - aRect.MoveTo(WidgetToScreenOffset()); + rect.MoveTo(WidgetToScreenOffset()); } - return NS_OK; + return rect; } -NS_IMETHODIMP nsChildView::GetScreenBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsChildView::GetScreenBounds() { - GetBounds(aRect); - aRect.MoveTo(WidgetToScreenOffset()); - return NS_OK; + LayoutDeviceIntRect rect = GetBounds(); + rect.MoveTo(WidgetToScreenOffset()); + return rect; } double @@ -3695,8 +3697,7 @@ NSEvent* gLastDragMouseDownEvent = nil; return; #ifdef DEBUG_UPDATE - LayoutDeviceIntRect geckoBounds; - mGeckoChild->GetBounds(geckoBounds); + LayoutDeviceIntRect geckoBounds = mGeckoChild->GetBounds(); fprintf (stderr, "---- Update[%p][%p] [%f %f %f %f] cgc: %p\n gecko bounds: [%d %d %d %d]\n", self, mGeckoChild, @@ -3804,8 +3805,7 @@ NSEvent* gLastDragMouseDownEvent = nil; mWaitingForPaint = NO; - LayoutDeviceIntRect geckoBounds; - mGeckoChild->GetBounds(geckoBounds); + LayoutDeviceIntRect geckoBounds = mGeckoChild->GetBounds(); LayoutDeviceIntRegion region(geckoBounds); mGeckoChild->PaintWindow(region); diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h index 497082e6b99a..2a034c6733ed 100644 --- a/widget/cocoa/nsCocoaWindow.h +++ b/widget/cocoa/nsCocoaWindow.h @@ -280,8 +280,8 @@ public: NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint) override; NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override; - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetClientBounds() override; + virtual LayoutDeviceIntRect GetScreenBounds() override; void ReportMoveEvent(); void ReportSizeEvent(); NS_IMETHOD SetCursor(nsCursor aCursor) override; diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index c000be277e32..6a4f1f1eec8e 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -1606,14 +1606,14 @@ NS_IMETHODIMP nsCocoaWindow::Resize(double aWidth, double aHeight, bool aRepaint aWidth, aHeight, aRepaint, true); } -NS_IMETHODIMP nsCocoaWindow::GetClientBounds(mozilla::LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsCocoaWindow::GetClientBounds() { - NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; CGFloat scaleFactor = BackingScaleFactor(); if (!mWindow) { - aRect = nsCocoaUtils::CocoaRectToGeckoRectDevPix(NSZeroRect, scaleFactor); - return NS_OK; + return nsCocoaUtils::CocoaRectToGeckoRectDevPix(NSZeroRect, scaleFactor); } NSRect r; @@ -1624,11 +1624,9 @@ NS_IMETHODIMP nsCocoaWindow::GetClientBounds(mozilla::LayoutDeviceIntRect& aRect r = [mWindow contentRectForFrameRect:[mWindow frame]]; } - aRect = nsCocoaUtils::CocoaRectToGeckoRectDevPix(r, scaleFactor); + return nsCocoaUtils::CocoaRectToGeckoRectDevPix(r, scaleFactor); - return NS_OK; - - NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; + NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntRect(0, 0, 0, 0)); } void @@ -1642,19 +1640,19 @@ nsCocoaWindow::UpdateBounds() nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); } -NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(LayoutDeviceIntRect &aRect) +LayoutDeviceIntRect +nsCocoaWindow::GetScreenBounds() { - NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; #ifdef DEBUG LayoutDeviceIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix([mWindow frame], BackingScaleFactor()); NS_ASSERTION(mWindow && mBounds == r, "mBounds out of sync!"); #endif - aRect = mBounds; - return NS_OK; + return mBounds; - NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; + NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntRect(0, 0, 0, 0)); } double @@ -1969,8 +1967,7 @@ nsCocoaWindow::ReportSizeEvent() UpdateBounds(); if (mWidgetListener) { - LayoutDeviceIntRect innerBounds; - GetClientBounds(innerBounds); + LayoutDeviceIntRect innerBounds = GetClientBounds(); mWidgetListener->WindowResized(this, innerBounds.width, innerBounds.height); } @@ -2037,8 +2034,7 @@ LayoutDeviceIntPoint nsCocoaWindow::GetClientOffset() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; - LayoutDeviceIntRect clientRect; - GetClientBounds(clientRect); + LayoutDeviceIntRect clientRect = GetClientBounds(); return clientRect.TopLeft() - mBounds.TopLeft(); diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index aa8656260c03..877a996bd35b 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -1499,25 +1499,26 @@ nsWindow::SetFocus(bool aRaise) return NS_OK; } -NS_IMETHODIMP -nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetScreenBounds() { + LayoutDeviceIntRect rect; if (mIsTopLevel && mContainer) { // use the point including window decorations gint x, y; gdk_window_get_root_origin(gtk_widget_get_window(GTK_WIDGET(mContainer)), &x, &y); - aRect.MoveTo(GdkPointToDevicePixels({ x, y })); + rect.MoveTo(GdkPointToDevicePixels({ x, y })); } else { - aRect.MoveTo(WidgetToScreenOffset()); + rect.MoveTo(WidgetToScreenOffset()); } // mBounds.Size() is the window bounds, not the window-manager frame // bounds (bug 581863). gdk_window_get_frame_extents would give the // frame bounds, but mBounds.Size() is returned here for consistency // with Resize. - aRect.SizeTo(mBounds.Size()); + rect.SizeTo(mBounds.Size()); LOG(("GetScreenBounds %d,%d | %dx%d\n", - aRect.x, aRect.y, aRect.width, aRect.height)); - return NS_OK; + rect.x, rect.y, rect.width, rect.height)); + return rect; } LayoutDeviceIntSize @@ -1526,16 +1527,15 @@ nsWindow::GetClientSize() return LayoutDeviceIntSize(mBounds.width, mBounds.height); } -NS_IMETHODIMP -nsWindow::GetClientBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetClientBounds() { // 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). - GetBounds(aRect); - aRect.MoveBy(GetClientOffset()); - - return NS_OK; + LayoutDeviceIntRect rect = GetBounds(); + rect.MoveBy(GetClientOffset()); + return rect; } void @@ -2227,8 +2227,7 @@ nsWindow::OnExposeEvent(cairo_t *cr) if (kid && gdk_window_is_visible(gdkWin)) { AutoTArray clipRects; kid->GetWindowClipRegion(&clipRects); - LayoutDeviceIntRect bounds; - kid->GetBounds(bounds); + LayoutDeviceIntRect bounds = kid->GetBounds(); for (uint32_t i = 0; i < clipRects.Length(); ++i) { LayoutDeviceIntRect r = clipRects[i] + bounds.TopLeft(); region.Sub(region, r); @@ -2429,8 +2428,7 @@ nsWindow::OnConfigureEvent(GtkWidget *aWidget, GdkEventConfigure *aEvent) mPendingConfigures--; - LayoutDeviceIntRect screenBounds; - GetScreenBounds(screenBounds); + LayoutDeviceIntRect screenBounds = GetScreenBounds(); if (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog) { // This check avoids unwanted rollup on spurious configure events from diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 4188e9d462bf..805789c27c0a 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -134,8 +134,8 @@ public: NS_IMETHOD SetSizeMode(nsSizeMode aMode) override; NS_IMETHOD Enable(bool aState) override; NS_IMETHOD SetFocus(bool aRaise = false) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetScreenBounds() override; + virtual LayoutDeviceIntRect GetClientBounds() override; virtual LayoutDeviceIntSize GetClientSize() override; virtual LayoutDeviceIntPoint GetClientOffset() override; NS_IMETHOD SetCursor(nsCursor aCursor) override; diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index a0df170913a5..45fae9ecdccb 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -899,7 +899,7 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen) if (!mOriginalBounds) { mOriginalBounds = new LayoutDeviceIntRect(); } - GetScreenBounds(*mOriginalBounds); + *mOriginalBounds = GetScreenBounds(); // Move to top-left corner of screen and size to the screen dimensions nsCOMPtr screen = aScreen; @@ -974,8 +974,7 @@ nsBaseWidget::UseAPZ() void nsBaseWidget::CreateCompositor() { - LayoutDeviceIntRect rect; - GetBounds(rect); + LayoutDeviceIntRect rect = GetBounds(); CreateCompositor(rect.width, rect.height); } @@ -1493,8 +1492,7 @@ NS_IMETHODIMP nsBaseWidget::ResizeClient(double aWidth, NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient"); NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient"); - LayoutDeviceIntRect clientBounds; - GetClientBounds(clientBounds); + LayoutDeviceIntRect clientBounds = GetClientBounds(); // GetClientBounds and mBounds are device pixels; scale back to desktop pixels // if that's what this widget uses for the Move/Resize APIs @@ -1519,10 +1517,8 @@ NS_IMETHODIMP nsBaseWidget::ResizeClient(double aX, NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient"); NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient"); - LayoutDeviceIntRect clientBounds; - GetClientBounds(clientBounds); - - LayoutDeviceIntPoint clientOffset(GetClientOffset()); + LayoutDeviceIntRect clientBounds = GetClientBounds(); + LayoutDeviceIntPoint clientOffset = GetClientOffset(); if (BoundsUseDesktopPixels()) { DesktopToLayoutDeviceScale scale = GetDesktopToDeviceScale(); @@ -1551,19 +1547,20 @@ NS_IMETHODIMP nsBaseWidget::ResizeClient(double aX, * If the implementation of nsWindow supports borders this method MUST be overridden * **/ -NS_IMETHODIMP nsBaseWidget::GetClientBounds(LayoutDeviceIntRect &aRect) +LayoutDeviceIntRect +nsBaseWidget::GetClientBounds() { - return GetBounds(aRect); + return GetBounds(); } /** * If the implementation of nsWindow supports borders this method MUST be overridden * **/ -NS_IMETHODIMP nsBaseWidget::GetBounds(LayoutDeviceIntRect &aRect) +LayoutDeviceIntRect +nsBaseWidget::GetBounds() { - aRect = mBounds; - return NS_OK; + return mBounds; } /** @@ -1571,17 +1568,20 @@ NS_IMETHODIMP nsBaseWidget::GetBounds(LayoutDeviceIntRect &aRect) * this method must be overridden * **/ -NS_IMETHODIMP nsBaseWidget::GetScreenBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsBaseWidget::GetScreenBounds() { - return GetBounds(aRect); + return GetBounds(); } -NS_IMETHODIMP nsBaseWidget::GetRestoredBounds(LayoutDeviceIntRect& aRect) +nsresult +nsBaseWidget::GetRestoredBounds(LayoutDeviceIntRect& aRect) { if (SizeMode() != nsSizeMode_Normal) { return NS_ERROR_FAILURE; } - return GetScreenBounds(aRect); + aRect = GetScreenBounds(); + return NS_OK; } LayoutDeviceIntPoint @@ -1979,8 +1979,7 @@ nsIWidget::GetWidgetScreen() return nullptr; } - LayoutDeviceIntRect bounds; - GetScreenBounds(bounds); + LayoutDeviceIntRect bounds = GetScreenBounds(); DesktopIntRect deskBounds = RoundedToInt(bounds / GetDesktopToDeviceScale()); nsCOMPtr screen; screenManager->ScreenForRect(deskBounds.x, deskBounds.y, diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index 2e81b7a9e45f..277032a797db 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -214,10 +214,10 @@ public: NS_IMETHOD MoveClient(double aX, double aY) override; 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 GetBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetRestoredBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetBounds() override; + virtual LayoutDeviceIntRect GetClientBounds() override; + virtual LayoutDeviceIntRect GetScreenBounds() override; + virtual MOZ_MUST_USE nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override; NS_IMETHOD GetNonClientMargins(LayoutDeviceIntMargin& aMargins) override; NS_IMETHOD SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override; virtual LayoutDeviceIntPoint GetClientOffset() override; diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index 8fc2f0f124aa..0492f972355d 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -862,19 +862,17 @@ class nsIWidget : public nsISupports * popup widgets the returned rect is in screen coordinates and not * relative to its parent widget. * - * @param aRect On return it holds the x, y, width and height of - * this widget. + * @return the x, y, width and height of this widget. */ - NS_IMETHOD GetBounds(LayoutDeviceIntRect& aRect) = 0; + virtual LayoutDeviceIntRect GetBounds() = 0; /** * Get this widget's outside dimensions in device coordinates. This * includes any title bar on the window. * - * @param aRect On return it holds the x, y, width and height of - * this widget. + * @return the x, y, width and height of this widget. */ - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) = 0; + virtual LayoutDeviceIntRect GetScreenBounds() = 0; /** * Similar to GetScreenBounds except that this function will always @@ -888,7 +886,8 @@ class nsIWidget : public nsISupports * @param aRect On return it holds the x, y, width and height of * this widget. */ - NS_IMETHOD GetRestoredBounds(LayoutDeviceIntRect& aRect) = 0; + virtual MOZ_MUST_USE nsresult + GetRestoredBounds(LayoutDeviceIntRect& aRect) = 0; /** * Get this widget's client area bounds, if the window has a 3D border @@ -896,10 +895,9 @@ class nsIWidget : public nsISupports * position of the client area relative to the client area of the parent * widget (for root widgets and popup widgets it is in screen coordinates). * - * @param aRect On return it holds the x. y, width and height of - * the client area of this widget. + * @return the x, y, width and height of the client area of this widget. */ - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) = 0; + virtual LayoutDeviceIntRect GetClientBounds() = 0; /** * Get the non-client area dimensions of the window. @@ -933,9 +931,7 @@ class nsIWidget : public nsISupports virtual LayoutDeviceIntSize GetClientSize() { // Depending on the backend, overloading this method may be useful if // requesting the client offset is expensive. - LayoutDeviceIntRect rect; - GetClientBounds(rect); - return rect.Size(); + return GetClientBounds().Size(); } /** @@ -1894,13 +1890,7 @@ public: virtual bool WidgetPaintsBackground() { return false; } virtual bool NeedsPaint() { - if (!IsVisible()) { - return false; - } - LayoutDeviceIntRect bounds; - nsresult rv = GetBounds(bounds); - NS_ENSURE_SUCCESS(rv, false); - return !bounds.IsEmpty(); + return IsVisible() && !GetBounds().IsEmpty(); } /** @@ -1916,9 +1906,7 @@ public: * probably shouldn't call this method. */ virtual LayoutDeviceIntRect GetNaturalBounds() { - LayoutDeviceIntRect bounds; - GetBounds(bounds); - return bounds; + return GetBounds(); } /** diff --git a/widget/nsNativeTheme.cpp b/widget/nsNativeTheme.cpp index 0b2fa4a1fb0d..0002fb51fff6 100644 --- a/widget/nsNativeTheme.cpp +++ b/widget/nsNativeTheme.cpp @@ -593,8 +593,8 @@ nsNativeTheme::IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent) if (parent->GetContent() == parentContent) { if (aLeftOfParent) { LayoutDeviceIntRect selfBounds, parentBounds; - aFrame->GetNearestWidget()->GetScreenBounds(selfBounds); - parent->GetNearestWidget()->GetScreenBounds(parentBounds); + selfBounds = aFrame->GetNearestWidget()->GetScreenBounds(); + parentBounds = parent->GetNearestWidget()->GetScreenBounds(); *aLeftOfParent = selfBounds.x < parentBounds.x; } return true; diff --git a/widget/uikit/nsWindow.h b/widget/uikit/nsWindow.h index 8c66e545a940..195eb7e26af1 100644 --- a/widget/uikit/nsWindow.h +++ b/widget/uikit/nsWindow.h @@ -60,7 +60,7 @@ public: void EnteredFullScreen(bool aFullScreen); NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint) override; NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetScreenBounds() override; void ReportMoveEvent(); void ReportSizeEvent(); void ReportSizeModeEvent(nsSizeMode aMode); diff --git a/widget/uikit/nsWindow.mm b/widget/uikit/nsWindow.mm index 3bcd7bbcba75..bdd949f8524c 100644 --- a/widget/uikit/nsWindow.mm +++ b/widget/uikit/nsWindow.mm @@ -278,8 +278,7 @@ private: mWaitingForPaint = NO; - LayoutDeviceIntRect geckoBounds; - mGeckoChild->GetBounds(geckoBounds); + LayoutDeviceIntRect geckoBounds = mGeckoChild->GetBounds(); LayoutDeviceIntRegion region(geckoBounds); mGeckoChild->PaintWindow(region); @@ -305,8 +304,7 @@ private: - (void)drawRect:(CGRect)aRect inContext:(CGContextRef)aContext { #ifdef DEBUG_UPDATE - LayoutDeviceIntRect geckoBounds; - mGeckoChild->GetBounds(geckoBounds); + LayoutDeviceIntRect geckoBounds = mGeckoChild->GetBounds(); fprintf (stderr, "---- Update[%p][%p] [%f %f %f %f] cgc: %p\n gecko bounds: [%d %d %d %d]\n", self, mGeckoChild, @@ -774,23 +772,15 @@ void nsWindow::ReportSizeModeEvent(nsSizeMode aMode) void nsWindow::ReportSizeEvent() { if (mWidgetListener) { - LayoutDeviceIntRect innerBounds; - GetClientBounds(innerBounds); + LayoutDeviceIntRect innerBounds = GetClientBounds(); mWidgetListener->WindowResized(this, innerBounds.width, innerBounds.height); } } -NS_IMETHODIMP -nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetScreenBounds() { - LayoutDeviceIntPoint p = WidgetToScreenOffset(); - - aRect.x = p.x; - aRect.y = p.y; - aRect.width = mBounds.width; - aRect.height = mBounds.height; - - return NS_OK; + return LayoutDeviceIntRect(WidgetToScreenOffset(), mBounds.Size()); } LayoutDeviceIntPoint nsWindow::WidgetToScreenOffset() diff --git a/widget/windows/IMMHandler.cpp b/widget/windows/IMMHandler.cpp index db77c80b9c2c..14da039bbdbe 100644 --- a/widget/windows/IMMHandler.cpp +++ b/widget/windows/IMMHandler.cpp @@ -2432,8 +2432,7 @@ IMMHandler::SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow, nsWindow* toplevelWindow = aWindow->GetTopLevelWindow(false); LayoutDeviceIntRect pluginRectInScreen = editorRectEvent.mReply.mRect + toplevelWindow->WidgetToScreenOffset(); - LayoutDeviceIntRect winRectInScreen; - aWindow->GetClientBounds(winRectInScreen); + LayoutDeviceIntRect winRectInScreen = aWindow->GetClientBounds(); // composition window cannot be positioned on the edge of client area. winRectInScreen.width--; winRectInScreen.height--; diff --git a/widget/windows/TSFTextStore.cpp b/widget/windows/TSFTextStore.cpp index 9baabe88a003..2130606ebda9 100644 --- a/widget/windows/TSFTextStore.cpp +++ b/widget/windows/TSFTextStore.cpp @@ -3932,14 +3932,7 @@ TSFTextStore::GetScreenExtInternal(RECT& aScreenExt) return false; } - LayoutDeviceIntRect boundRect; - if (NS_FAILED(refWindow->GetClientBounds(boundRect))) { - MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("0x%p TSFTextStore::GetScreenExtInternal() FAILED due to " - "failed to get the client bounds", this)); - return false; - } - + LayoutDeviceIntRect boundRect = refWindow->GetClientBounds(); boundRect.MoveTo(0, 0); // Clip frame rect to window rect diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index fa03bce012a3..ba1b5562dbe3 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -2057,113 +2057,120 @@ NS_IMETHODIMP nsWindow::SetFocus(bool aRaise) // Return the window's full dimensions in screen coordinates. // If the window has a parent, converts the origin to an offset // of the parent's screen origin. -NS_IMETHODIMP nsWindow::GetBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetBounds() { - if (mWnd) { - RECT r; - VERIFY(::GetWindowRect(mWnd, &r)); - - // assign size - aRect.width = r.right - r.left; - aRect.height = r.bottom - r.top; - - // popup window bounds' are in screen coordinates, not relative to parent - // window - if (mWindowType == eWindowType_popup) { - aRect.x = r.left; - aRect.y = r.top; - return NS_OK; - } - - // chrome on parent: - // ___ 5,5 (chrome start) - // | ____ 10,10 (client start) - // | | ____ 20,20 (child start) - // | | | - // 20,20 - 5,5 = 15,15 (??) - // minus GetClientOffset: - // 15,15 - 5,5 = 10,10 - // - // no chrome on parent: - // ______ 10,10 (win start) - // | ____ 20,20 (child start) - // | | - // 20,20 - 10,10 = 10,10 - // - // walking the chain: - // ___ 5,5 (chrome start) - // | ___ 10,10 (client start) - // | | ___ 20,20 (child start) - // | | | __ 30,30 (child start) - // | | | | - // 30,30 - 20,20 = 10,10 (offset from second child to first) - // 20,20 - 5,5 = 15,15 + 10,10 = 25,25 (??) - // minus GetClientOffset: - // 25,25 - 5,5 = 20,20 (offset from second child to parent client) - - // convert coordinates if parent exists - HWND parent = ::GetParent(mWnd); - if (parent) { - RECT pr; - VERIFY(::GetWindowRect(parent, &pr)); - r.left -= pr.left; - r.top -= pr.top; - // adjust for chrome - nsWindow* pWidget = static_cast(GetParent()); - if (pWidget && pWidget->IsTopLevelWidget()) { - LayoutDeviceIntPoint clientOffset = pWidget->GetClientOffset(); - r.left -= clientOffset.x; - r.top -= clientOffset.y; - } - } - aRect.x = r.left; - aRect.y = r.top; - } else { - aRect = mBounds; + if (!mWnd) { + return mBounds; } - return NS_OK; + + RECT r; + VERIFY(::GetWindowRect(mWnd, &r)); + + LayoutDeviceIntRect rect; + + // assign size + rect.width = r.right - r.left; + rect.height = r.bottom - r.top; + + // popup window bounds' are in screen coordinates, not relative to parent + // window + if (mWindowType == eWindowType_popup) { + rect.x = r.left; + rect.y = r.top; + return rect; + } + + // chrome on parent: + // ___ 5,5 (chrome start) + // | ____ 10,10 (client start) + // | | ____ 20,20 (child start) + // | | | + // 20,20 - 5,5 = 15,15 (??) + // minus GetClientOffset: + // 15,15 - 5,5 = 10,10 + // + // no chrome on parent: + // ______ 10,10 (win start) + // | ____ 20,20 (child start) + // | | + // 20,20 - 10,10 = 10,10 + // + // walking the chain: + // ___ 5,5 (chrome start) + // | ___ 10,10 (client start) + // | | ___ 20,20 (child start) + // | | | __ 30,30 (child start) + // | | | | + // 30,30 - 20,20 = 10,10 (offset from second child to first) + // 20,20 - 5,5 = 15,15 + 10,10 = 25,25 (??) + // minus GetClientOffset: + // 25,25 - 5,5 = 20,20 (offset from second child to parent client) + + // convert coordinates if parent exists + HWND parent = ::GetParent(mWnd); + if (parent) { + RECT pr; + VERIFY(::GetWindowRect(parent, &pr)); + r.left -= pr.left; + r.top -= pr.top; + // adjust for chrome + nsWindow* pWidget = static_cast(GetParent()); + if (pWidget && pWidget->IsTopLevelWidget()) { + LayoutDeviceIntPoint clientOffset = pWidget->GetClientOffset(); + r.left -= clientOffset.x; + r.top -= clientOffset.y; + } + } + rect.x = r.left; + rect.y = r.top; + return rect; } // Get this component dimension -NS_IMETHODIMP nsWindow::GetClientBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetClientBounds() { - if (mWnd) { - RECT r; - VERIFY(::GetClientRect(mWnd, &r)); - - LayoutDeviceIntRect bounds; - GetBounds(bounds); - aRect.MoveTo(bounds.TopLeft() + GetClientOffset()); - aRect.width = r.right - r.left; - aRect.height = r.bottom - r.top; - - } else { - aRect.SetRect(0,0,0,0); + if (!mWnd) { + return LayoutDeviceIntRect(0, 0, 0, 0); } - return NS_OK; + + RECT r; + VERIFY(::GetClientRect(mWnd, &r)); + + LayoutDeviceIntRect bounds = GetBounds(); + LayoutDeviceIntRect rect; + rect.MoveTo(bounds.TopLeft() + GetClientOffset()); + rect.width = r.right - r.left; + rect.height = r.bottom - r.top; + return rect; } // Like GetBounds, but don't offset by the parent -NS_IMETHODIMP nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect) +LayoutDeviceIntRect +nsWindow::GetScreenBounds() { - if (mWnd) { - RECT r; - VERIFY(::GetWindowRect(mWnd, &r)); - - aRect.width = r.right - r.left; - aRect.height = r.bottom - r.top; - aRect.x = r.left; - aRect.y = r.top; - } else { - aRect = mBounds; + if (!mWnd) { + return mBounds; } - return NS_OK; + + RECT r; + VERIFY(::GetWindowRect(mWnd, &r)); + + LayoutDeviceIntRect rect; + rect.x = r.left; + rect.y = r.top; + rect.width = r.right - r.left; + rect.height = r.bottom - r.top; + return rect; } -NS_IMETHODIMP nsWindow::GetRestoredBounds(LayoutDeviceIntRect &aRect) +nsresult +nsWindow::GetRestoredBounds(LayoutDeviceIntRect &aRect) { if (SizeMode() == nsSizeMode_Normal) { - return GetScreenBounds(aRect); + aRect = GetScreenBounds(); + return NS_OK; } if (!mWnd) { return NS_ERROR_FAILURE; @@ -2860,14 +2867,12 @@ void nsWindow::UpdateOpaqueRegion(const LayoutDeviceIntRegion& aOpaqueRegion) for (nsIWidget* child = GetFirstChild(); child; child = child->GetNextSibling()) { if (child->IsPlugin()) { // Collect the bounds of all plugins for GetLargestRectangle. - LayoutDeviceIntRect childBounds; - child->GetBounds(childBounds); + LayoutDeviceIntRect childBounds = child->GetBounds(); pluginBounds.UnionRect(pluginBounds, childBounds); } } - LayoutDeviceIntRect clientBounds; - GetClientBounds(clientBounds); + LayoutDeviceIntRect clientBounds = GetClientBounds(); // Find the largest rectangle and use that to calculate the inset. Our top // priority is to include the bounds of all plugins. @@ -3764,9 +3769,7 @@ nsWindow::OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) return NS_OK; } - LayoutDeviceIntRect widgetRect; - nsresult rv = GetScreenBounds(widgetRect); - NS_ENSURE_SUCCESS(rv, rv); + LayoutDeviceIntRect widgetRect = GetScreenBounds(); LayoutDeviceIntRect buttonRect(aButtonRect + widgetRect.TopLeft()); LayoutDeviceIntPoint centerOfButton(buttonRect.x + buttonRect.width / 2, @@ -4255,8 +4258,7 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, // call the event callback if (mWidgetListener) { if (aEventMessage == eMouseMove) { - LayoutDeviceIntRect rect; - GetBounds(rect); + LayoutDeviceIntRect rect = GetBounds(); rect.x = 0; rect.y = 0; @@ -6652,8 +6654,7 @@ nsWindow::ConfigureChildren(const nsTArray& aConfigurations) "Configured widget is not a child"); nsresult rv = w->SetWindowClipRegion(configuration.mClipRegion, true); NS_ENSURE_SUCCESS(rv, rv); - LayoutDeviceIntRect bounds; - w->GetBounds(bounds); + LayoutDeviceIntRect bounds = w->GetBounds(); if (bounds.Size() != configuration.mBounds.Size()) { w->Resize(configuration.mBounds.x, configuration.mBounds.y, configuration.mBounds.width, configuration.mBounds.height, diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 08f53aa13417..471285642d0e 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -133,10 +133,10 @@ public: NS_IMETHOD Enable(bool aState) override; virtual bool IsEnabled() const override; NS_IMETHOD SetFocus(bool aRaise) override; - NS_IMETHOD GetBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetScreenBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetRestoredBounds(LayoutDeviceIntRect& aRect) override; - NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetBounds() override; + virtual LayoutDeviceIntRect GetScreenBounds() override; + virtual MOZ_MUST_USE nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override; + virtual LayoutDeviceIntRect GetClientBounds() override; virtual LayoutDeviceIntPoint GetClientOffset() override; void SetBackgroundColor(const nscolor& aColor) override; NS_IMETHOD SetCursor(imgIContainer* aCursor, diff --git a/xpfe/appshell/nsWebShellWindow.cpp b/xpfe/appshell/nsWebShellWindow.cpp index 271de3093f24..28d87ea8bee5 100644 --- a/xpfe/appshell/nsWebShellWindow.cpp +++ b/xpfe/appshell/nsWebShellWindow.cpp @@ -176,8 +176,7 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, deskRect, // Widget dimensions &widgetInitData); // Widget initialization data - LayoutDeviceIntRect r; - mWindow->GetClientBounds(r); + LayoutDeviceIntRect r = mWindow->GetClientBounds(); // Match the default background color of content. Important on windows // since we no longer use content child widgets. mWindow->SetBackgroundColor(NS_RGB(255,255,255)); diff --git a/xpfe/appshell/nsXULWindow.cpp b/xpfe/appshell/nsXULWindow.cpp index f5114db711aa..c174d784650f 100644 --- a/xpfe/appshell/nsXULWindow.cpp +++ b/xpfe/appshell/nsXULWindow.cpp @@ -673,12 +673,11 @@ NS_IMETHODIMP nsXULWindow::SetPositionAndSize(int32_t aX, int32_t aY, NS_IMETHODIMP nsXULWindow::GetPositionAndSize(int32_t* x, int32_t* y, int32_t* cx, int32_t* cy) { - LayoutDeviceIntRect rect; if (!mWindow) return NS_ERROR_FAILURE; - mWindow->GetScreenBounds(rect); + LayoutDeviceIntRect rect = mWindow->GetScreenBounds(); if (x) *x = rect.x;