Skip to content

Commit

Permalink
Bug 1296993 (part 3) - Streamline nsIWidget::ConstrainPosition. r=mst…
Browse files Browse the repository at this point in the history
…ange.

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.
  • Loading branch information
nnethercote committed Aug 25, 2016
1 parent 5444b7c commit 54fada9
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 65 deletions.
2 changes: 0 additions & 2 deletions gfx/tests/gtest/TestCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions widget/android/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ nsWindow::IsVisible() const
return mIsVisible;
}

NS_IMETHODIMP
void
nsWindow::ConstrainPosition(bool aAllowSlop,
int32_t *aX,
int32_t *aY)
Expand All @@ -1754,8 +1754,6 @@ nsWindow::ConstrainPosition(bool aAllowSlop,
*aX = 0;
*aY = 0;
}

return NS_OK;
}

NS_IMETHODIMP
Expand Down
6 changes: 3 additions & 3 deletions widget/android/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions widget/cocoa/nsChildView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions widget/gonk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions widget/gonk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions widget/gtk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion widget/gtk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions widget/uikit/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions widget/uikit/nsWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 6 additions & 8 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -1927,7 +1927,7 @@ NS_IMETHODIMP nsWindow::ConstrainPosition(bool aAllowSlop,

nsCOMPtr<nsIScreenManager> screenmgr = do_GetService(sScreenManagerContractID);
if (!screenmgr) {
return NS_ERROR_NOT_AVAILABLE;
return;
}
nsCOMPtr<nsIScreen> screen;
int32_t left, top, width, height;
Expand All @@ -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;
Expand Down Expand Up @@ -1975,8 +1975,6 @@ NS_IMETHODIMP nsWindow::ConstrainPosition(bool aAllowSlop,
else if (*aY >= screenRect.bottom - logHeight)
*aY = screenRect.bottom - logHeight;
}

return NS_OK;
}

/**************************************************************
Expand Down
2 changes: 1 addition & 1 deletion widget/windows/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 54fada9

Please sign in to comment.