Skip to content

Commit

Permalink
Bug 1240749 - Fixes for DPI support in Gtk widget interface: remove i…
Browse files Browse the repository at this point in the history
…ncorrect Get[Avail]RectDisplayPix overrides, as desktop pixels == device pixels for the Gtk widget backend, and implement nsScreenGtk::GetDefaultCSSScaleFactor, required by nsGlobalWindow since per-monitor DPI patches in bug 890156. r=karlt
  • Loading branch information
jfkthame committed Feb 26, 2016
1 parent 60ea58c commit 51b8759
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 66 deletions.
39 changes: 6 additions & 33 deletions widget/gtk/nsScreenGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,6 @@ nsScreenGtk :: GetDPIScale()
return dpiScale;
}

NS_IMETHODIMP
nsScreenGtk :: GetRectDisplayPix(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
{
int32_t left, top, width, height;

GetRect(&left, &top, &width, &height);

double scaleFactor = 1.0 / GetDPIScale();
*outLeft = NSToIntRound(left * scaleFactor);
*outTop = NSToIntRound(top * scaleFactor);
*outWidth = NSToIntRound(width * scaleFactor);
*outHeight = NSToIntRound(height * scaleFactor);

return NS_OK;
}

NS_IMETHODIMP
nsScreenGtk :: GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
{
int32_t left, top, width, height;

GetAvailRect(&left, &top, &width, &height);

double scaleFactor = 1.0 / GetDPIScale();
*outLeft = NSToIntRound(left * scaleFactor);
*outTop = NSToIntRound(top * scaleFactor);
*outWidth = NSToIntRound(width * scaleFactor);
*outHeight = NSToIntRound(height * scaleFactor);

return NS_OK;
}

NS_IMETHODIMP
nsScreenGtk :: GetPixelDepth(int32_t *aPixelDepth)
{
Expand All @@ -133,14 +101,19 @@ nsScreenGtk :: GetPixelDepth(int32_t *aPixelDepth)

} // GetPixelDepth


NS_IMETHODIMP
nsScreenGtk :: GetColorDepth(int32_t *aColorDepth)
{
return GetPixelDepth ( aColorDepth );

} // GetColorDepth

NS_IMETHODIMP
nsScreenGtk::GetDefaultCSSScaleFactor(double* aScaleFactor)
{
*aScaleFactor = GetDPIScale();
return NS_OK;
}

void
nsScreenGtk :: Init (GdkWindow *aRootWindow)
Expand Down
15 changes: 8 additions & 7 deletions widget/gtk/nsScreenGtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class nsScreenGtk : public nsBaseScreen
nsScreenGtk();
~nsScreenGtk();

NS_IMETHOD GetId(uint32_t* aId);
NS_IMETHOD GetRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight);
NS_IMETHOD GetAvailRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight);
NS_IMETHOD GetRectDisplayPix(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight);
NS_IMETHOD GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight);
NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth);
NS_IMETHOD GetColorDepth(int32_t* aColorDepth);
NS_IMETHOD GetId(uint32_t* aId) override;
NS_IMETHOD GetRect(int32_t* aLeft, int32_t* aTop,
int32_t* aWidth, int32_t* aHeight) override;
NS_IMETHOD GetAvailRect(int32_t* aLeft, int32_t* aTop,
int32_t* aWidth, int32_t* aHeight) override;
NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override;
NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override;
NS_IMETHOD GetDefaultCSSScaleFactor(double* aScaleFactor) override;

void Init(GdkWindow *aRootWindow);
#ifdef MOZ_X11
Expand Down
28 changes: 5 additions & 23 deletions widget/gtk/nsScreenManagerGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,12 @@ nsScreenManagerGtk :: ScreenForId ( uint32_t aId, nsIScreen **outScreen )
// Returns the screen that contains the rectangle. If the rect overlaps
// multiple screens, it picks the screen with the greatest area of intersection.
//
// The coordinates are in CSS pixels (not app units) and in screen coordinates.
// The coordinates are in desktop pixels.
//
NS_IMETHODIMP
nsScreenManagerGtk :: ScreenForRect( int32_t aX, int32_t aY,
int32_t aWidth, int32_t aHeight,
nsIScreen **aOutScreen )
{
uint32_t scale = nsScreenGtk::GetDPIScale();
return ScreenForRectPix(aX*scale, aY*scale, aWidth*scale, aHeight*scale,
aOutScreen);
}

//
// ScreenForRectPix
//
// Returns the screen that contains the rectangle. If the rect overlaps
// multiple screens, it picks the screen with the greatest area of intersection.
//
// The coordinates are in device (X11) pixels.
//
nsresult
nsScreenManagerGtk :: ScreenForRectPix( int32_t aX, int32_t aY,
int32_t aWidth, int32_t aHeight,
nsIScreen **aOutScreen )
nsScreenManagerGtk::ScreenForRect(int32_t aX, int32_t aY,
int32_t aWidth, int32_t aHeight,
nsIScreen **aOutScreen)
{
nsresult rv;
rv = EnsureInit();
Expand Down Expand Up @@ -374,7 +356,7 @@ nsScreenManagerGtk :: ScreenForNativeWidget (void *aWidget, nsIScreen **outScree
gdk_window_get_geometry(GDK_WINDOW(aWidget), &x, &y, &width, &height);
#endif
gdk_window_get_origin(GDK_WINDOW(aWidget), &x, &y);
rv = ScreenForRectPix(x, y, width, height, outScreen);
rv = ScreenForRect(x, y, width, height, outScreen);
} else {
rv = GetPrimaryScreen(outScreen);
}
Expand Down
3 changes: 0 additions & 3 deletions widget/gtk/nsScreenManagerGtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class nsScreenManagerGtk : public nsIScreenManager
virtual ~nsScreenManagerGtk();

nsresult EnsureInit();
nsresult ScreenForRectPix(int32_t aX, int32_t aY,
int32_t aWidth, int32_t aHeight,
nsIScreen **aOutScreen);

// Cached screen array. Its length is the number of screens we have.
nsCOMArray<nsIScreen> mCachedScreenArray;
Expand Down

0 comments on commit 51b8759

Please sign in to comment.