Bug 890156 - patch 1 - Add nsIWidget::GetDesktopToDeviceScale() method. r=emk

This commit is contained in:
Jonathan Kew 2015-12-04 16:58:05 +00:00
parent c2c031081e
commit de2d99a0c7
6 changed files with 40 additions and 16 deletions

View File

@ -390,6 +390,10 @@ public:
// pixels" and the Cocoa "points" coordinate system.
CGFloat BackingScaleFactor() const;
mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final {
return mozilla::DesktopToLayoutDeviceScale(BackingScaleFactor());
}
// Call if the window's backing scale factor changes - i.e., it is moved
// between HiDPI and non-HiDPI screens
void BackingScaleFactorChanged();

View File

@ -324,6 +324,10 @@ public:
virtual double GetDefaultScaleInternal() override;
virtual int32_t RoundsWidgetCoordinatesTo() override;
mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final {
return mozilla::DesktopToLayoutDeviceScale(BackingScaleFactor());
}
NS_IMETHOD SetTitle(const nsAString& aTitle) override;
NS_IMETHOD Invalidate(const LayoutDeviceIntRect& aRect) override;

View File

@ -291,8 +291,9 @@ nsresult nsCocoaWindow::Create(nsIWidget* aParent,
}
// now we can convert newBounds to device pixels for the window we created,
// as the child view expects a rect expressed in the dev pix of its parent
DesktopToLayoutDeviceScale scale(BackingScaleFactor());
return CreatePopupContentView(RoundedToInt(newBounds * scale));
LayoutDeviceIntRect devRect =
RoundedToInt(newBounds * GetDesktopToDeviceScale());
return CreatePopupContentView(devRect);
}
mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed;
@ -307,8 +308,8 @@ nsresult nsCocoaWindow::Create(nsIWidget* aParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
DesktopToLayoutDeviceScale scale(GetDefaultScaleInternal());
DesktopIntRect desktopRect = RoundedToInt(aRect / scale);
DesktopIntRect desktopRect =
RoundedToInt(aRect / GetDesktopToDeviceScale());
return Create(aParent, aNativeParent, desktopRect, aInitData);
}

View File

@ -831,9 +831,9 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen)
if (aFullScreen) {
if (!mOriginalBounds) {
mOriginalBounds = new CSSIntRect();
mOriginalBounds = new LayoutDeviceIntRect();
}
*mOriginalBounds = GetScaledScreenBounds();
GetScreenBounds(*mOriginalBounds);
// Move to top-left corner of screen and size to the screen dimensions
nsCOMPtr<nsIScreen> screen = aScreen;
@ -847,8 +847,13 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen)
}
}
} else if (mOriginalBounds) {
Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width,
mOriginalBounds->height, true);
if (BoundsUseDesktopPixels()) {
DesktopRect deskRect = *mOriginalBounds / GetDesktopToDeviceScale();
Resize(deskRect.x, deskRect.y, deskRect.width, deskRect.height, true);
} else {
Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width,
mOriginalBounds->height, true);
}
}
return NS_OK;

View File

@ -186,6 +186,11 @@ public:
bool BoundsUseDesktopPixels() const {
return mWindowType <= eWindowType_popup;
}
// Default implementation, to be overridden by platforms where desktop coords
// are virtualized and may not correspond to device pixels on the screen.
mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
return mozilla::DesktopToLayoutDeviceScale(1.0);
}
NS_IMETHOD MoveClient(double aX, double aY) override;
NS_IMETHOD ResizeClient(double aWidth, double aHeight, bool aRepaint) override;
NS_IMETHOD ResizeClient(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
@ -514,7 +519,7 @@ protected:
nsCursor mCursor;
nsBorderStyle mBorderStyle;
nsIntRect mBounds;
CSSIntRect* mOriginalBounds;
LayoutDeviceIntRect* mOriginalBounds;
// When this pointer is null, the widget is not clipped
mozilla::UniquePtr<LayoutDeviceIntRect[]> mClipRects;
uint32_t mClipRectCount;

View File

@ -429,10 +429,8 @@ class nsIWidget : public nsISupports {
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
{
// GetDefaultScaleInternal() here is a placeholder, to be replaced by
// GetDesktopToDeviceScale in a later patch
mozilla::DesktopToLayoutDeviceScale scale(GetDefaultScaleInternal());
LayoutDeviceIntRect devPixRect = RoundedToInt(aRect * scale);
LayoutDeviceIntRect devPixRect =
RoundedToInt(aRect * GetDesktopToDeviceScale());
return Create(aParent, aNativeParent, devPixRect, aInitData);
}
@ -546,6 +544,13 @@ class nsIWidget : public nsISupports {
*/
virtual float GetDPI() = 0;
/**
* Return the scaling factor between device pixels and the platform-
* dependent "desktop pixels" used to manage window positions on a
* potentially multi-screen, mixed-resolution desktop.
*/
virtual mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() = 0;
/**
* Returns the CompositorVsyncDispatcher associated with this widget
*/
@ -858,7 +863,7 @@ class nsIWidget : public nsISupports {
NS_IMETHOD GetBounds(LayoutDeviceIntRect& aRect) = 0;
/**
* Get this widget's outside dimensions in global coordinates. This
* Get this widget's outside dimensions in device coordinates. This
* includes any title bar on the window.
*
* @param aRect On return it holds the x, y, width and height of
@ -878,7 +883,7 @@ class nsIWidget : public nsISupports {
* @param aRect On return it holds the x, y, width and height of
* this widget.
*/
NS_IMETHOD GetRestoredBounds(mozilla::LayoutDeviceIntRect& aRect) = 0;
NS_IMETHOD GetRestoredBounds(LayoutDeviceIntRect& aRect) = 0;
/**
* Get this widget's client area bounds, if the window has a 3D border
@ -889,7 +894,7 @@ class nsIWidget : public nsISupports {
* @param aRect On return it holds the x. y, width and height of
* the client area of this widget.
*/
NS_IMETHOD GetClientBounds(mozilla::LayoutDeviceIntRect& aRect) = 0;
NS_IMETHOD GetClientBounds(LayoutDeviceIntRect& aRect) = 0;
/**
* Get the non-client area dimensions of the window.