Navigation Menu

Skip to content

Commit

Permalink
Bug 1224403 (part 4) - Make {Get,Set}NonClientMargins() return/take a…
Browse files Browse the repository at this point in the history
… LayoutDeviceIntMargin. r=kats.

This required adding {To,From}UnknownMargin().

--HG--
extra : rebase_source : de7e8f56604825bcc1babe5e05a8f8623a402cad
  • Loading branch information
nnethercote committed Nov 12, 2015
1 parent f703d45 commit e2fe661
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dom/base/nsDOMWindowUtils.cpp
Expand Up @@ -3641,7 +3641,7 @@ nsDOMWindowUtils::SetChromeMargin(int32_t aTop,
nsCOMPtr<nsIWidget> widget;
baseWindow->GetMainWidget(getter_AddRefs(widget));
if (widget) {
nsIntMargin margins(aTop, aRight, aBottom, aLeft);
LayoutDeviceIntMargin margins(aTop, aRight, aBottom, aLeft);
return widget->SetNonClientMargins(margins);
}
}
Expand Down
8 changes: 5 additions & 3 deletions dom/xul/nsXULElement.cpp
Expand Up @@ -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)
{}

Expand All @@ -2021,7 +2021,7 @@ class MarginSetter : public nsRunnable

private:
nsCOMPtr<nsIWidget> mWidget;
nsIntMargin mMargin;
LayoutDeviceIntMargin mMargin;
};

void
Expand All @@ -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)));
}
}

Expand Down
17 changes: 15 additions & 2 deletions gfx/2d/Rect.h
Expand Up @@ -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<units> FromUnknownMargin(const IntMarginTyped<UnknownUnits>& aMargin) {
return IntMarginTyped<units>(aMargin.top, aMargin.right,
aMargin.bottom, aMargin.left);
}

IntMarginTyped<UnknownUnits> ToUnknownMargin() const {
return IntMarginTyped<UnknownUnits>(this->top, this->right,
this->bottom, this->left);
}
};
typedef IntMarginTyped<UnknownUnits> IntMargin;

Expand Down Expand Up @@ -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<units> FromUnknownRect(const IntRectTyped<UnknownUnits>& rect) {
return IntRectTyped<units>(rect.x, rect.y, rect.width, rect.height);
Expand Down
2 changes: 1 addition & 1 deletion widget/cocoa/nsCocoaWindow.h
Expand Up @@ -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<ThemeGeometry>& aThemeGeometries) override;
Expand Down
2 changes: 1 addition & 1 deletion widget/cocoa/nsCocoaWindow.mm
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions widget/nsBaseWidget.cpp
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions widget/nsBaseWidget.h
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions widget/nsIWidget.h
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions widget/windows/nsWindow.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions widget/windows/nsWindow.h
Expand Up @@ -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<mozilla::gfx::DrawTarget> StartRemoteDrawing() override;
virtual void EndRemoteDrawing() override;
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion xpfe/appshell/nsXULWindow.cpp
Expand Up @@ -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
Expand Down

0 comments on commit e2fe661

Please sign in to comment.