From e2fe66176b4c1f66aea92d577aaac72bbb616006 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 11 Nov 2015 23:05:04 -0800 Subject: [PATCH] Bug 1224403 (part 4) - Make {Get,Set}NonClientMargins() return/take a LayoutDeviceIntMargin. r=kats. This required adding {To,From}UnknownMargin(). --HG-- extra : rebase_source : de7e8f56604825bcc1babe5e05a8f8623a402cad --- dom/base/nsDOMWindowUtils.cpp | 2 +- dom/xul/nsXULElement.cpp | 8 +++++--- gfx/2d/Rect.h | 17 +++++++++++++++-- widget/cocoa/nsCocoaWindow.h | 2 +- widget/cocoa/nsCocoaWindow.mm | 2 +- widget/nsBaseWidget.cpp | 4 ++-- widget/nsBaseWidget.h | 6 ++++-- widget/nsIWidget.h | 5 ++--- widget/windows/nsWindow.cpp | 8 ++++---- widget/windows/nsWindow.h | 10 ++++++---- xpfe/appshell/nsXULWindow.cpp | 3 ++- 11 files changed, 43 insertions(+), 24 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 4414b71cc8a53..0b6e90934e6db 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3641,7 +3641,7 @@ nsDOMWindowUtils::SetChromeMargin(int32_t aTop, nsCOMPtr widget; baseWindow->GetMainWidget(getter_AddRefs(widget)); if (widget) { - nsIntMargin margins(aTop, aRight, aBottom, aLeft); + LayoutDeviceIntMargin margins(aTop, aRight, aBottom, aLeft); return widget->SetNonClientMargins(margins); } } diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 2ddbbb271fa71..01636f635e4c3 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -2007,7 +2007,7 @@ class MarginSetter : public nsRunnable explicit MarginSetter(nsIWidget* aWidget) : mWidget(aWidget), mMargin(-1, -1, -1, -1) {} - MarginSetter(nsIWidget *aWidget, const nsIntMargin& aMargin) : + MarginSetter(nsIWidget *aWidget, const LayoutDeviceIntMargin& aMargin) : mWidget(aWidget), mMargin(aMargin) {} @@ -2021,7 +2021,7 @@ class MarginSetter : public nsRunnable private: nsCOMPtr mWidget; - nsIntMargin mMargin; + LayoutDeviceIntMargin mMargin; }; void @@ -2046,7 +2046,9 @@ nsXULElement::SetChromeMargins(const nsAttrValue* aValue) gotMargins = nsContentUtils::ParseIntMarginValue(tmp, margins); } if (gotMargins) { - nsContentUtils::AddScriptRunner(new MarginSetter(mainWidget, margins)); + nsContentUtils::AddScriptRunner( + new MarginSetter( + mainWidget, LayoutDeviceIntMargin::FromUnknownMargin(margins))); } } diff --git a/gfx/2d/Rect.h b/gfx/2d/Rect.h index c2e8d7a2bddd7..2a674c99e4757 100644 --- a/gfx/2d/Rect.h +++ b/gfx/2d/Rect.h @@ -32,6 +32,19 @@ struct IntMarginTyped: IntMarginTyped() : Super() {} IntMarginTyped(int32_t aTop, int32_t aRight, int32_t aBottom, int32_t aLeft) : Super(aTop, aRight, aBottom, aLeft) {} + + // XXX When all of the code is ported, the following functions to convert + // to and from unknown types should be removed. + + static IntMarginTyped FromUnknownMargin(const IntMarginTyped& aMargin) { + return IntMarginTyped(aMargin.top, aMargin.right, + aMargin.bottom, aMargin.left); + } + + IntMarginTyped ToUnknownMargin() const { + return IntMarginTyped(this->top, this->right, + this->bottom, this->left); + } }; typedef IntMarginTyped IntMargin; @@ -83,8 +96,8 @@ struct IntRectTyped : void RoundIn() {} void RoundOut() {} - // XXX When all of the code is ported, the following functions to convert to and from - // unknown types should be removed. + // XXX When all of the code is ported, the following functions to convert + // to and from unknown types should be removed. static IntRectTyped FromUnknownRect(const IntRectTyped& rect) { return IntRectTyped(rect.x, rect.y, rect.width, rect.height); diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h index 2d9065017b75b..145e9c7e00406 100644 --- a/widget/cocoa/nsCocoaWindow.h +++ b/widget/cocoa/nsCocoaWindow.h @@ -340,7 +340,7 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa virtual void SetWindowAnimationType(WindowAnimationType aType) override; virtual void SetDrawsTitle(bool aDrawTitle) override; virtual void SetUseBrightTitlebarForeground(bool aBrightForeground) override; - NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) override; + NS_IMETHOD SetNonClientMargins(mozilla::LayoutDeviceIntMargin &margins) override; NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive) override; virtual void SetDrawsInTitlebar(bool aState) override; virtual void UpdateThemeGeometries(const nsTArray& aThemeGeometries) override; diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index f46813a33764b..03ed44e7c57aa 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -2167,7 +2167,7 @@ nsIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY), NS_OBJC_END_TRY_ABORT_BLOCK; } -NS_IMETHODIMP nsCocoaWindow::SetNonClientMargins(nsIntMargin &margins) +NS_IMETHODIMP nsCocoaWindow::SetNonClientMargins(LayoutDeviceIntMargin &margins) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 506d943687c5b..0e79e3e4715f8 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -1347,13 +1347,13 @@ nsBaseWidget::GetClientOffsetUntyped() } NS_IMETHODIMP -nsBaseWidget::GetNonClientMargins(nsIntMargin &margins) +nsBaseWidget::GetNonClientMargins(LayoutDeviceIntMargin &margins) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -nsBaseWidget::SetNonClientMargins(nsIntMargin &margins) +nsBaseWidget::SetNonClientMargins(LayoutDeviceIntMargin &margins) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index 1cc4454f40ca4..a4d313cca6e0b 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -191,8 +191,10 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference NS_IMETHOD GetClientBoundsUntyped(nsIntRect &aRect) override; NS_IMETHOD GetScreenBoundsUntyped(nsIntRect &aRect) override; NS_IMETHOD GetRestoredBoundsUntyped(nsIntRect &aRect) override; - NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) override; - NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) override; + NS_IMETHOD GetNonClientMargins( + mozilla::LayoutDeviceIntMargin &margins) override; + NS_IMETHOD SetNonClientMargins( + mozilla::LayoutDeviceIntMargin &margins) override; virtual nsIntPoint GetClientOffsetUntyped() override; NS_IMETHOD EnableDragDrop(bool aEnable) override; NS_IMETHOD GetAttention(int32_t aCycleCount) override; diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index ba97151212632..fd64fb2ade3c6 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -879,9 +879,8 @@ class nsIWidget : public nsISupports { /** * Get the non-client area dimensions of the window. - * */ - NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) = 0; + NS_IMETHOD GetNonClientMargins(mozilla::LayoutDeviceIntMargin &margins) = 0; /** * Sets the non-client area dimensions of the window. Pass -1 to restore @@ -895,7 +894,7 @@ class nsIWidget : public nsISupports { * dimensions between zero and size < system default. * */ - NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0; + NS_IMETHOD SetNonClientMargins(mozilla::LayoutDeviceIntMargin &margins) = 0; /** * Get the client offset from the window origin. diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 5df58f590f98f..014d103eefe27 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -2018,17 +2018,17 @@ nsWindow::SetDrawsInTitlebar(bool aState) if (aState) { // top, right, bottom, left for nsIntMargin - nsIntMargin margins(0, -1, -1, -1); + LayoutDeviceIntMargin margins(0, -1, -1, -1); SetNonClientMargins(margins); } else { - nsIntMargin margins(-1, -1, -1, -1); + LayoutDeviceIntMargin margins(-1, -1, -1, -1); SetNonClientMargins(margins); } } NS_IMETHODIMP -nsWindow::GetNonClientMargins(nsIntMargin &margins) +nsWindow::GetNonClientMargins(LayoutDeviceIntMargin &margins) { nsWindow * window = GetTopLevelWindow(true); if (window && window != this) { @@ -2303,7 +2303,7 @@ nsWindow::UpdateNonClientMargins(int32_t aSizeMode, bool aReflowWindow) } NS_IMETHODIMP -nsWindow::SetNonClientMargins(nsIntMargin &margins) +nsWindow::SetNonClientMargins(LayoutDeviceIntMargin &margins) { if (!mIsTopWidgetWindow || mBorderStyle == eBorderStyle_none) diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 93750921dd4c1..8d500c20fa1e1 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -195,8 +195,10 @@ class nsWindow : public nsWindowBase virtual void UpdateOpaqueRegion(const nsIntRegion& aOpaqueRegion); #endif // MOZ_XUL virtual nsIMEUpdatePreference GetIMEUpdatePreference(); - NS_IMETHOD GetNonClientMargins(nsIntMargin &margins); - NS_IMETHOD SetNonClientMargins(nsIntMargin &margins); + NS_IMETHOD GetNonClientMargins( + mozilla::LayoutDeviceIntMargin &margins) override; + NS_IMETHOD SetNonClientMargins( + mozilla::LayoutDeviceIntMargin &margins) override; void SetDrawsInTitlebar(bool aState); already_AddRefed StartRemoteDrawing() override; virtual void EndRemoteDrawing() override; @@ -517,9 +519,9 @@ class nsWindow : public nsWindowBase // Pre-calculated outward offset applied to default frames mozilla::LayoutDeviceIntMargin mNonClientOffset; // Margins set by the owner - nsIntMargin mNonClientMargins; + mozilla::LayoutDeviceIntMargin mNonClientMargins; // Margins we'd like to set once chrome is reshown: - nsIntMargin mFutureMarginsOnceChromeShows; + mozilla::LayoutDeviceIntMargin mFutureMarginsOnceChromeShows; // Indicates we need to apply margins once toggling chrome into showing: bool mFutureMarginsToUse; diff --git a/xpfe/appshell/nsXULWindow.cpp b/xpfe/appshell/nsXULWindow.cpp index 1925f937c1f86..f236b710ac94a 100644 --- a/xpfe/appshell/nsXULWindow.cpp +++ b/xpfe/appshell/nsXULWindow.cpp @@ -1428,7 +1428,8 @@ void nsXULWindow::SyncAttributesToWidget() nsIntMargin margins; windowElement->GetAttribute(NS_LITERAL_STRING("chromemargin"), attr); if (nsContentUtils::ParseIntMarginValue(attr, margins)) { - mWindow->SetNonClientMargins(margins); + LayoutDeviceIntMargin tmp = LayoutDeviceIntMargin::FromUnknownMargin(margins); + mWindow->SetNonClientMargins(tmp); } // "windowtype" attribute