Bug 1239855 - Fix for widget positioning/sizing on hidpi displays under Gtk. r=emk

This commit is contained in:
Jonathan Kew 2016-01-18 12:24:06 +00:00
parent 06e58001b4
commit c83d5c5d67
2 changed files with 16 additions and 14 deletions

View File

@ -1086,10 +1086,9 @@ nsWindow::Show(bool aState)
NS_IMETHODIMP NS_IMETHODIMP
nsWindow::Resize(double aWidth, double aHeight, bool aRepaint) nsWindow::Resize(double aWidth, double aHeight, bool aRepaint)
{ {
CSSToLayoutDeviceScale scale = BoundsUseDesktopPixels() ? GetDefaultScale() double scale = BoundsUseDesktopPixels() ? GetDesktopToDeviceScale().scale : 1.0;
: CSSToLayoutDeviceScale(1.0); int32_t width = NSToIntRound(scale * aWidth);
int32_t width = NSToIntRound(scale.scale * aWidth); int32_t height = NSToIntRound(scale * aHeight);
int32_t height = NSToIntRound(scale.scale * aHeight);
ConstrainSize(&width, &height); ConstrainSize(&width, &height);
// For top-level windows, aWidth and aHeight should possibly be // For top-level windows, aWidth and aHeight should possibly be
@ -1118,14 +1117,13 @@ NS_IMETHODIMP
nsWindow::Resize(double aX, double aY, double aWidth, double aHeight, nsWindow::Resize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint) bool aRepaint)
{ {
CSSToLayoutDeviceScale scale = BoundsUseDesktopPixels() ? GetDefaultScale() double scale = BoundsUseDesktopPixels() ? GetDesktopToDeviceScale().scale : 1.0;
: CSSToLayoutDeviceScale(1.0); int32_t width = NSToIntRound(scale * aWidth);
int32_t width = NSToIntRound(scale.scale * aWidth); int32_t height = NSToIntRound(scale * aHeight);
int32_t height = NSToIntRound(scale.scale * aHeight);
ConstrainSize(&width, &height); ConstrainSize(&width, &height);
int32_t x = NSToIntRound(scale.scale * aX); int32_t x = NSToIntRound(scale * aX);
int32_t y = NSToIntRound(scale.scale * aY); int32_t y = NSToIntRound(scale * aY);
mBounds.x = x; mBounds.x = x;
mBounds.y = y; mBounds.y = y;
mBounds.SizeTo(width, height); mBounds.SizeTo(width, height);
@ -1184,10 +1182,9 @@ nsWindow::Move(double aX, double aY)
LOG(("nsWindow::Move [%p] %f %f\n", (void *)this, LOG(("nsWindow::Move [%p] %f %f\n", (void *)this,
aX, aY)); aX, aY));
CSSToLayoutDeviceScale scale = BoundsUseDesktopPixels() ? GetDefaultScale() double scale = BoundsUseDesktopPixels() ? GetDesktopToDeviceScale().scale : 1.0;
: CSSToLayoutDeviceScale(1.0); int32_t x = NSToIntRound(aX * scale);
int32_t x = NSToIntRound(aX * scale.scale); int32_t y = NSToIntRound(aY * scale);
int32_t y = NSToIntRound(aY * scale.scale);
if (mWindowType == eWindowType_toplevel || if (mWindowType == eWindowType_toplevel ||
mWindowType == eWindowType_dialog) { mWindowType == eWindowType_dialog) {

View File

@ -104,6 +104,11 @@ public:
virtual nsIWidget *GetParent() override; virtual nsIWidget *GetParent() override;
virtual float GetDPI() override; virtual float GetDPI() override;
virtual double GetDefaultScaleInternal() override; virtual double GetDefaultScaleInternal() override;
// Under Gtk, we manage windows using device pixels so no scaling is needed:
mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final
{
return mozilla::DesktopToLayoutDeviceScale(1.0);
}
virtual nsresult SetParent(nsIWidget* aNewParent) override; virtual nsresult SetParent(nsIWidget* aNewParent) override;
NS_IMETHOD SetModal(bool aModal) override; NS_IMETHOD SetModal(bool aModal) override;
virtual bool IsVisible() const override; virtual bool IsVisible() const override;