Skip to content

Commit

Permalink
Bug 1763023 - Push nsBaseWidget::mSizeMode into child classes r=handyman
Browse files Browse the repository at this point in the history
This member is no longer used on Windows, and having it in the
base class doesn't provide a real abstraction anyway since
the child classes will break if anything about it is changed.

Differential Revision: https://phabricator.services.mozilla.com/D145132
  • Loading branch information
Chris Martin committed May 2, 2022
1 parent d44e391 commit 86cb687
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 20 deletions.
6 changes: 6 additions & 0 deletions gfx/tests/gtest/MockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class MockWidget : public nsBaseWidget {

virtual void Enable(bool aState) override {}
virtual bool IsEnabled() const override { return true; }

virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override { mSizeMode = aMode; }

virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override {}
virtual void Invalidate(const LayoutDeviceIntRect& aRect) override {}
virtual nsresult SetTitle(const nsAString& title) override { return NS_OK; }
Expand All @@ -83,6 +87,8 @@ class MockWidget : public nsBaseWidget {
private:
~MockWidget() = default;

nsSizeMode mSizeMode = nsSizeMode_Normal;

int mCompWidth;
int mCompHeight;
};
Expand Down
1 change: 1 addition & 0 deletions widget/PuppetWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ PuppetWidget::PuppetWidget(BrowserChild* aBrowserChild)
mDefaultScale(-1),
mEnabled(false),
mVisible(false),
mSizeMode(nsSizeMode_Normal),
mNeedIMEStateInit(false),
mIgnoreCompositionEvents(false) {
// Setting 'Unknown' means "not yet cached".
Expand Down
5 changes: 5 additions & 0 deletions widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class PuppetWidget : public nsBaseWidget,
virtual void Enable(bool aState) override { mEnabled = aState; }
virtual bool IsEnabled() const override { return mEnabled; }

virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override { mSizeMode = aMode; }

virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override;

virtual void Invalidate(const LayoutDeviceIntRect& aRect) override;
Expand Down Expand Up @@ -398,6 +401,8 @@ class PuppetWidget : public nsBaseWidget,
bool mVisible;

private:
nsSizeMode mSizeMode;

bool mNeedIMEStateInit;
// When remote process requests to commit/cancel a composition, the
// composition may have already been committed in the main process. In such
Expand Down
3 changes: 2 additions & 1 deletion widget/android/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,7 @@ nsWindow::nsWindow()
mIsVisible(false),
mParent(nullptr),
mDynamicToolbarMaxHeight(0),
mSizeMode(nsSizeMode_Normal),
mIsFullScreen(false),
mCompositorWidgetDelegate(nullptr) {}

Expand Down Expand Up @@ -2110,7 +2111,7 @@ void nsWindow::SetSizeMode(nsSizeMode aMode) {
return;
}

nsBaseWidget::SetSizeMode(aMode);
mSizeMode = aMode;

switch (aMode) {
case nsSizeMode_Minimized:
Expand Down
2 changes: 2 additions & 0 deletions widget/android/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class nsWindow final : public nsBaseWidget {
virtual void Resize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint) override;
void SetZIndex(int32_t aZIndex) override;
virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override;
virtual void Enable(bool aState) override;
virtual bool IsEnabled() const override;
Expand Down Expand Up @@ -255,6 +256,7 @@ class nsWindow final : public nsBaseWidget {
mozilla::ScreenIntCoord mDynamicToolbarMaxHeight;
mozilla::ScreenIntMargin mSafeAreaInsets;

nsSizeMode mSizeMode;
bool mIsFullScreen;

bool UseExternalCompositingSurface() const override { return true; }
Expand Down
5 changes: 5 additions & 0 deletions widget/cocoa/nsChildView.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ class nsChildView final : public nsBaseWidget {

virtual void Enable(bool aState) override;
virtual bool IsEnabled() const override;

virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override { mSizeMode = aMode; }

virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override;
virtual LayoutDeviceIntRect GetBounds() override;
virtual LayoutDeviceIntRect GetClientBounds() override;
Expand Down Expand Up @@ -554,6 +558,7 @@ class nsChildView final : public nsBaseWidget {
mutable CGFloat mBackingScaleFactor;

bool mVisible;
nsSizeMode mSizeMode;
bool mDrawing;
bool mIsDispatchPaint; // Is a paint event being dispatched

Expand Down
1 change: 1 addition & 0 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ static inline void FlipCocoaScreenCoordinate(NSPoint& inPoint) {
mCompositingLock("ChildViewCompositing"),
mBackingScaleFactor(0.0),
mVisible(false),
mSizeMode(nsSizeMode_Normal),
mDrawing(false),
mIsDispatchPaint(false) {}

Expand Down
2 changes: 2 additions & 0 deletions widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, int32_t* aY) override;
virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
virtual void Move(double aX, double aY) override;
virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override;
virtual void GetWorkspaceID(nsAString& workspaceID) override;
virtual void MoveToWorkspace(const nsAString& workspaceID) override;
Expand Down Expand Up @@ -404,6 +405,7 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
bool mWindowMadeHere; // true if we created the window, false for embedding
bool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
// this is used for sibling sheet contention only
nsSizeMode mSizeMode;
bool mInFullScreenMode;
bool mInFullScreenTransition; // true from the request to enter/exit fullscreen
// (MakeFullScreen() call) to EnteredFullScreen()
Expand Down
1 change: 1 addition & 0 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ static void RollUpPopups() {
mAnimationType(nsIWidget::eGenericWindowAnimation),
mWindowMadeHere(false),
mSheetNeedsShow(false),
mSizeMode(nsSizeMode_Normal),
mInFullScreenMode(false),
mInFullScreenTransition(false),
mIgnoreOcclusionCount(0),
Expand Down
2 changes: 1 addition & 1 deletion widget/gtk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ void nsWindow::SetSizeMode(nsSizeMode aMode) {
LOG("nsWindow::SetSizeMode %d\n", aMode);

// Save the requested state.
nsBaseWidget::SetSizeMode(aMode);
mSizeMode = aMode;

// return if there's no shell or our current state is the same as
// the mode we were just set to.
Expand Down
2 changes: 2 additions & 0 deletions widget/gtk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class nsWindow final : public nsBaseWidget {
bool IsEnabled() const override;

void SetZIndex(int32_t aZIndex) override;
nsSizeMode SizeMode() override { return mSizeMode; }
void SetSizeMode(nsSizeMode aMode) override;
void GetWorkspaceID(nsAString& workspaceID) override;
void MoveToWorkspace(const nsAString& workspaceID) override;
Expand Down Expand Up @@ -526,6 +527,7 @@ class nsWindow final : public nsBaseWidget {
// in some reasonable time when page content is not updated.
int mCompositorPauseTimeoutID = 0;

nsSizeMode mSizeMode = nsSizeMode_Normal;
nsSizeMode mSizeState = nsSizeMode_Normal;
float mAspectRatio = 0.0f;
float mAspectRatioSaved = 0.0f;
Expand Down
3 changes: 2 additions & 1 deletion widget/headless/HeadlessWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ HeadlessWidget::HeadlessWidget()
mDestroyed(false),
mTopLevel(nullptr),
mCompositorWidget(nullptr),
mSizeMode(nsSizeMode_Normal),
mLastSizeMode(nsSizeMode_Normal),
mEffectiveSizeMode(nsSizeMode_Normal),
mRestoreBounds(0, 0, 0, 0) {
Expand Down Expand Up @@ -300,7 +301,7 @@ void HeadlessWidget::SetSizeMode(nsSizeMode aMode) {
return;
}

nsBaseWidget::SetSizeMode(aMode);
mSizeMode = aMode;

// Normally in real widget backends a window event would be triggered that
// would cause the window manager to handle resizing the window. In headless
Expand Down
2 changes: 2 additions & 0 deletions widget/headless/HeadlessWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class HeadlessWidget : public nsBaseWidget {
virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
virtual void Resize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint) override;
virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override;
virtual nsresult MakeFullScreen(bool aFullScreen) override;
virtual void Enable(bool aState) override;
Expand Down Expand Up @@ -141,6 +142,7 @@ class HeadlessWidget : public nsBaseWidget {
bool mDestroyed;
nsIWidget* mTopLevel;
HeadlessCompositorWidget* mCompositorWidget;
nsSizeMode mSizeMode;
// The size mode before entering fullscreen mode.
nsSizeMode mLastSizeMode;
// The last size mode set while the window was visible.
Expand Down
13 changes: 0 additions & 13 deletions widget/nsBaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ nsBaseWidget::nsBaseWidget(nsBorderStyle aBorderStyle)
mBorderStyle(aBorderStyle),
mBounds(0, 0, 0, 0),
mOriginalBounds(nullptr),
mSizeMode(nsSizeMode_Normal),
mIsTiled(false),
mPopupLevel(ePopupLevelTop),
mPopupType(ePopupTypeAny),
Expand Down Expand Up @@ -691,18 +690,6 @@ void nsBaseWidget::SetZIndex(int32_t aZIndex) {
}
}

//-------------------------------------------------------------------------
//
// Maximize, minimize or restore the window. The BaseWidget implementation
// merely stores the state.
//
//-------------------------------------------------------------------------
void nsBaseWidget::SetSizeMode(nsSizeMode aMode) {
MOZ_ASSERT(aMode == nsSizeMode_Normal || aMode == nsSizeMode_Minimized ||
aMode == nsSizeMode_Maximized || aMode == nsSizeMode_Fullscreen);
mSizeMode = aMode;
}

void nsBaseWidget::GetWorkspaceID(nsAString& workspaceID) {
workspaceID.Truncate();
}
Expand Down
3 changes: 0 additions & 3 deletions widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget* aWidget,
bool aActivate) override {}

void SetSizeMode(nsSizeMode aMode) override;
nsSizeMode SizeMode() override { return mSizeMode; }
void GetWorkspaceID(nsAString& workspaceID) override;
void MoveToWorkspace(const nsAString& workspaceID) override;
bool IsTiled() const override { return mIsTiled; }
Expand Down Expand Up @@ -719,7 +717,6 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
nsBorderStyle mBorderStyle;
LayoutDeviceIntRect mBounds;
LayoutDeviceIntRect* mOriginalBounds;
nsSizeMode mSizeMode;
bool mIsTiled;
nsPopupLevel mPopupLevel;
nsPopupType mPopupType;
Expand Down
1 change: 1 addition & 0 deletions widget/tests/gtest/MockWinWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MockWinWidget : public nsBaseWidget {
HWND GetWnd() { return mWnd; }

nsSizeMode SizeMode() override;
void SetSizeMode(nsSizeMode aMode) override {}

void* GetNativeData(uint32_t aDataType) override { return nullptr; }

Expand Down
2 changes: 2 additions & 0 deletions widget/uikit/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class nsWindow final : public nsBaseWidget {
virtual void* GetNativeData(uint32_t aDataType) override;

virtual void Move(double aX, double aY) override;
virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override;
void EnteredFullScreen(bool aFullScreen);
virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
Expand Down Expand Up @@ -94,6 +95,7 @@ class nsWindow final : public nsBaseWidget {

ChildView* mNativeView;
bool mVisible;
nsSizeMode mSizeMode;
nsTArray<nsWindow*> mChildren;
nsWindow* mParent;
InputContext mInputContext;
Expand Down
3 changes: 2 additions & 1 deletion widget/uikit/nsWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ - (void)drawRect:(CGRect)aRect inContext:(CGContextRef)aContext {
}
@end

nsWindow::nsWindow() : mNativeView(nullptr), mVisible(false), mParent(nullptr) {}
nsWindow::nsWindow()
: mNativeView(nullptr), mVisible(false), mSizeMode(nsSizeMode_Normal), mParent(nullptr) {}

nsWindow::~nsWindow() {
[mNativeView widgetDestroyed]; // Safe if mNativeView is nil.
Expand Down

0 comments on commit 86cb687

Please sign in to comment.