From 54fada914e9dab184a6705c58effb3f8e60c26ac Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 25 Aug 2016 13:43:27 +1000 Subject: [PATCH] Bug 1296993 (part 3) - Streamline nsIWidget::ConstrainPosition. r=mstange. This patch does the following. - Removes the return value, because none of the call sites check it. - Puts an empty implementation into nsBaseWidget. - Removes the empty implementations from several nsIWidget instances, because they can use the nsBaseWidget one. --- gfx/tests/gtest/TestCompositor.cpp | 2 -- widget/PuppetWidget.h | 8 ++++---- widget/android/nsWindow.cpp | 4 +--- widget/android/nsWindow.h | 6 +++--- widget/cocoa/nsChildView.h | 2 -- widget/cocoa/nsChildView.mm | 6 ------ widget/cocoa/nsCocoaWindow.h | 2 +- widget/cocoa/nsCocoaWindow.mm | 10 ++++++---- widget/gonk/nsWindow.cpp | 8 -------- widget/gonk/nsWindow.h | 3 --- widget/gtk/nsWindow.cpp | 8 +++----- widget/gtk/nsWindow.h | 2 +- widget/nsBaseWidget.h | 3 +++ widget/nsIWidget.h | 7 +++---- widget/uikit/nsWindow.h | 2 -- widget/uikit/nsWindow.mm | 8 -------- widget/windows/nsWindow.cpp | 14 ++++++-------- widget/windows/nsWindow.h | 2 +- 18 files changed, 32 insertions(+), 65 deletions(-) diff --git a/gfx/tests/gtest/TestCompositor.cpp b/gfx/tests/gtest/TestCompositor.cpp index 6899a3d61b098..22bfd110edff9 100644 --- a/gfx/tests/gtest/TestCompositor.cpp +++ b/gfx/tests/gtest/TestCompositor.cpp @@ -68,8 +68,6 @@ class MockWidget : public nsBaseWidget nsWidgetInitData* aInitData = nullptr) override { return NS_OK; } NS_IMETHOD Show(bool aState) override { return NS_OK; } virtual bool IsVisible() const override { return true; } - NS_IMETHOD ConstrainPosition(bool aAllowSlop, - int32_t *aX, int32_t *aY) override { return NS_OK; } NS_IMETHOD Move(double aX, double aY) override { return NS_OK; } NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint) override { return NS_OK; } NS_IMETHOD Resize(double aX, double aY, diff --git a/widget/PuppetWidget.h b/widget/PuppetWidget.h index 2799ec972a15e..3357218a6201b 100644 --- a/widget/PuppetWidget.h +++ b/widget/PuppetWidget.h @@ -83,10 +83,10 @@ class PuppetWidget : public nsBaseWidget virtual bool IsVisible() const override { return mVisible; } - NS_IMETHOD ConstrainPosition(bool /*ignored aAllowSlop*/, - int32_t* aX, - int32_t* aY) override - { *aX = kMaxDimension; *aY = kMaxDimension; return NS_OK; } + virtual void ConstrainPosition(bool /*ignored aAllowSlop*/, + int32_t* aX, + int32_t* aY) override + { *aX = kMaxDimension; *aY = kMaxDimension; } // Widget position is controlled by the parent process via TabChild. NS_IMETHOD Move(double aX, double aY) override diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 9047c4823c0b1..c402a6236bd32 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -1742,7 +1742,7 @@ nsWindow::IsVisible() const return mIsVisible; } -NS_IMETHODIMP +void nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) @@ -1754,8 +1754,6 @@ nsWindow::ConstrainPosition(bool aAllowSlop, *aX = 0; *aY = 0; } - - return NS_OK; } NS_IMETHODIMP diff --git a/widget/android/nsWindow.h b/widget/android/nsWindow.h index c18a90e3ffeb4..50d9f19a88691 100644 --- a/widget/android/nsWindow.h +++ b/widget/android/nsWindow.h @@ -141,9 +141,9 @@ class nsWindow : public nsBaseWidget virtual double GetDefaultScaleInternal() override; NS_IMETHOD Show(bool aState) override; virtual bool IsVisible() const override; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, - int32_t *aX, - int32_t *aY) override; + virtual void ConstrainPosition(bool aAllowSlop, + int32_t *aX, + int32_t *aY) override; NS_IMETHOD Move(double aX, double aY) override; NS_IMETHOD Resize(double aWidth, diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index eb49f178caffb..a8ae76fbc4bdd 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -312,8 +312,6 @@ class nsChildView : public nsBaseWidget virtual nsIWidget* GetParent(void) override; virtual float GetDPI() override; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, - int32_t *aX, int32_t *aY) override; NS_IMETHOD Move(double aX, double aY) override; NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint) override; NS_IMETHOD Resize(double aX, double aY, diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 87cab5d7f3210..f4be982b702cb 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -948,12 +948,6 @@ static void PrintViewHierarchy(NSView *view) return 1; } -NS_IMETHODIMP nsChildView::ConstrainPosition(bool aAllowSlop, - int32_t *aX, int32_t *aY) -{ - return NS_OK; -} - // Move this component, aX and aY are in the parent widget coordinate system NS_IMETHODIMP nsChildView::Move(double aX, double aY) { diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h index cfe01ecca3b79..e165a7fe2f598 100644 --- a/widget/cocoa/nsCocoaWindow.h +++ b/widget/cocoa/nsCocoaWindow.h @@ -252,7 +252,7 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa virtual void* GetNativeData(uint32_t aDataType) override; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, + virtual void ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) override; virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override; NS_IMETHOD Move(double aX, double aY) override; diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index aa8827a0f5dea..3690aa34b6c21 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -1112,11 +1112,13 @@ static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle) #define kWindowPositionSlop 20 -NS_IMETHODIMP nsCocoaWindow::ConstrainPosition(bool aAllowSlop, - int32_t *aX, int32_t *aY) +void +nsCocoaWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) { + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + if (!mWindow || ![mWindow screen]) { - return NS_OK; + return; } nsIntRect screenBounds; @@ -1166,7 +1168,7 @@ static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle) } } - return NS_OK; + NS_OBJC_END_TRY_ABORT_BLOCK; } void nsCocoaWindow::SetSizeConstraints(const SizeConstraints& aConstraints) diff --git a/widget/gonk/nsWindow.cpp b/widget/gonk/nsWindow.cpp index 729fafd0be4aa..c4acd2bcaf0f3 100644 --- a/widget/gonk/nsWindow.cpp +++ b/widget/gonk/nsWindow.cpp @@ -385,14 +385,6 @@ nsWindow::IsVisible() const return mVisible; } -NS_IMETHODIMP -nsWindow::ConstrainPosition(bool aAllowSlop, - int32_t *aX, - int32_t *aY) -{ - return NS_OK; -} - NS_IMETHODIMP nsWindow::Move(double aX, double aY) diff --git a/widget/gonk/nsWindow.h b/widget/gonk/nsWindow.h index d642a63d4541b..38a593e807482 100644 --- a/widget/gonk/nsWindow.h +++ b/widget/gonk/nsWindow.h @@ -56,9 +56,6 @@ class nsWindow : public nsBaseWidget NS_IMETHOD Show(bool aState); virtual bool IsVisible() const; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, - int32_t *aX, - int32_t *aY); NS_IMETHOD Move(double aX, double aY); NS_IMETHOD Resize(double aWidth, diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index a91bb2d3c683f..f596070ee347f 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -968,11 +968,11 @@ nsWindow::RegisterTouchWindow() #endif } -NS_IMETHODIMP +void nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) { if (!mIsTopLevel || !mShell) - return NS_OK; + return; double dpiScale = GetDefaultScale().scale; @@ -991,7 +991,7 @@ nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) // We don't have any screen so leave the coordinates as is if (!screen) - return NS_OK; + return; nsIntRect screenRect; if (mSizeMode != nsSizeMode_Fullscreen) { @@ -1025,8 +1025,6 @@ nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) else if (*aY >= screenRect.YMost() - logHeight) *aY = screenRect.YMost() - logHeight; } - - return NS_OK; } void nsWindow::SetSizeConstraints(const SizeConstraints& aConstraints) diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index d30c2cb671dda..2208366f590e3 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -109,7 +109,7 @@ class nsWindow : public nsBaseWidget virtual nsresult SetParent(nsIWidget* aNewParent) override; virtual void SetModal(bool aModal) override; virtual bool IsVisible() const override; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, + virtual void ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) override; virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override; diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index dee3f8898d1c5..50171e75666b8 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -214,6 +214,9 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override { return mozilla::DesktopToLayoutDeviceScale(1.0); } + virtual void ConstrainPosition(bool aAllowSlop, + int32_t *aX, + int32_t *aY) override {} 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; diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index 4fd19f8863566..05013ca30785f 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -678,12 +678,11 @@ class nsIWidget : public nsISupports * out: the x position constrained to fit on the screen(s). * @param aY in: an y position expressed in screen coordinates. * out: the y position constrained to fit on the screen(s). - * @return vapid success indication. but see also the parameters. * **/ - NS_IMETHOD ConstrainPosition(bool aAllowSlop, - int32_t *aX, - int32_t *aY) = 0; + virtual void ConstrainPosition(bool aAllowSlop, + int32_t *aX, + int32_t *aY) = 0; /** * NOTE: diff --git a/widget/uikit/nsWindow.h b/widget/uikit/nsWindow.h index f778ef4422ab6..67c95d9e2ef1d 100644 --- a/widget/uikit/nsWindow.h +++ b/widget/uikit/nsWindow.h @@ -51,8 +51,6 @@ class nsWindow : virtual void SetBackgroundColor(const nscolor &aColor) override; virtual void* GetNativeData(uint32_t aDataType) override; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, - int32_t *aX, int32_t *aY) override; NS_IMETHOD Move(double aX, double aY) override; NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, bool aActivate) override; diff --git a/widget/uikit/nsWindow.mm b/widget/uikit/nsWindow.mm index 9f54f950193a8..1da49137c1a2a 100644 --- a/widget/uikit/nsWindow.mm +++ b/widget/uikit/nsWindow.mm @@ -582,14 +582,6 @@ - (void)drawRect:(CGRect)aRect inContext:(CGContextRef)aContext return NS_OK; } -NS_IMETHODIMP -nsWindow::ConstrainPosition(bool aAllowSlop, - int32_t *aX, - int32_t *aY) -{ - return NS_OK; -} - NS_IMETHODIMP nsWindow::Move(double aX, double aY) { diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 582e2df201f75..9d551809f0ad6 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -1908,11 +1908,11 @@ nsWindow::SetSizeMode(nsSizeMode aMode) // Constrain a potential move to fit onscreen // Position (aX, aY) is specified in Windows screen (logical) pixels, // except when using per-monitor DPI, in which case it's device pixels. -NS_IMETHODIMP nsWindow::ConstrainPosition(bool aAllowSlop, - int32_t *aX, int32_t *aY) +void +nsWindow::ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) { if (!mIsTopWidgetWindow) // only a problem for top-level windows - return NS_OK; + return; double dpiScale = GetDesktopToDeviceScale().scale; @@ -1927,7 +1927,7 @@ NS_IMETHODIMP nsWindow::ConstrainPosition(bool aAllowSlop, nsCOMPtr screenmgr = do_GetService(sScreenManagerContractID); if (!screenmgr) { - return NS_ERROR_NOT_AVAILABLE; + return; } nsCOMPtr screen; int32_t left, top, width, height; @@ -1938,13 +1938,13 @@ NS_IMETHODIMP nsWindow::ConstrainPosition(bool aAllowSlop, // For normalized windows, use the desktop work area. nsresult rv = screen->GetAvailRectDisplayPix(&left, &top, &width, &height); if (NS_FAILED(rv)) { - return rv; + return; } } else { // For full screen windows, use the desktop. nsresult rv = screen->GetRectDisplayPix(&left, &top, &width, &height); if (NS_FAILED(rv)) { - return rv; + return; } } screenRect.left = left; @@ -1975,8 +1975,6 @@ NS_IMETHODIMP nsWindow::ConstrainPosition(bool aAllowSlop, else if (*aY >= screenRect.bottom - logHeight) *aY = screenRect.bottom - logHeight; } - - return NS_OK; } /************************************************************** diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 42a664c990676..8e52a6d630005 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -120,7 +120,7 @@ class nsWindow : public nsWindowBase NS_IMETHOD Show(bool bState) override; virtual bool IsVisible() const override; - NS_IMETHOD ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) override; + virtual void ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY) override; virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override; virtual const SizeConstraints GetSizeConstraints() override; NS_IMETHOD Move(double aX, double aY) override;