diff --git a/layout/base/Units.h b/layout/base/Units.h index 1b500dee0504..256ec195d5d1 100644 --- a/layout/base/Units.h +++ b/layout/base/Units.h @@ -173,6 +173,7 @@ typedef gfx::ScaleFactor CSSToLayoutDeviceScale; typedef gfx::ScaleFactor CSSToLayerScale; typedef gfx::ScaleFactor CSSToScreenScale; typedef gfx::ScaleFactor CSSToParentLayerScale; +typedef gfx::ScaleFactor CSSToDesktopScale; typedef gfx::ScaleFactor LayoutDeviceToCSSScale; typedef gfx::ScaleFactor LayoutDeviceToLayerScale; @@ -202,6 +203,8 @@ typedef gfx::ScaleFactor ParentLayerToParentLayerScale; typedef gfx::ScaleFactor DesktopToLayoutDeviceScale; +typedef gfx::ScaleFactor + LayoutDeviceToDesktopScale; typedef gfx::ScaleFactors2D CSSToLayoutDeviceScale2D; diff --git a/widget/nsIBaseWindow.idl b/widget/nsIBaseWindow.idl index 3a7852011908..3276ed780d51 100644 --- a/widget/nsIBaseWindow.idl +++ b/widget/nsIBaseWindow.idl @@ -9,7 +9,9 @@ /*#include "nsIWidget.idl" Boy this would be nice.*/ [ptr] native nsIWidget(nsIWidget); -%{ C++ +%{C++ +#include "Units.h" + class nsIWidget; %} @@ -21,154 +23,154 @@ typedef voidPtr nativeWindow; * but rather a common set that nearly all windowed objects support. */ -[scriptable, uuid(ca635529-a977-4552-9b8a-66187e54d882)] +[scriptable, builtinclass, uuid(ca635529-a977-4552-9b8a-66187e54d882)] interface nsIBaseWindow : nsISupports { - /* - Allows a client to initialize an object implementing this interface with - the usually required window setup information. - It is possible to pass null for both parentNativeWindow and parentWidget, - but only docshells support this. + /* + Allows a client to initialize an object implementing this interface with + the usually required window setup information. + It is possible to pass null for both parentNativeWindow and parentWidget, + but only docshells support this. - @param parentNativeWindow - This allows a system to pass in the parenting - window as a native reference rather than relying on the calling - application to have created the parent window as an nsIWidget. This - value will be ignored (should be nullptr) if an nsIWidget is passed in to - the parentWidget parameter. + @param parentNativeWindow - This allows a system to pass in the parenting + window as a native reference rather than relying on the calling + application to have created the parent window as an nsIWidget. This + value will be ignored (should be nullptr) if an nsIWidget is passed in to + the parentWidget parameter. - @param parentWidget - This allows a system to pass in the parenting widget. - This allows some objects to optimize themselves and rely on the view - system for event flow rather than creating numerous native windows. If - one of these is not available, nullptr should be passed. + @param parentWidget - This allows a system to pass in the parenting widget. + This allows some objects to optimize themselves and rely on the view + system for event flow rather than creating numerous native windows. If + one of these is not available, nullptr should be passed. - @param x - This is the x co-ordinate relative to the parent to place the - window. + @param x - This is the x co-ordinate relative to the parent to place the + window. - @param y - This is the y co-ordinate relative to the parent to place the - window. + @param y - This is the y co-ordinate relative to the parent to place the + window. - @param cx - This is the width for the window to be. + @param cx - This is the width for the window to be. - @param cy - This is the height for the window to be. + @param cy - This is the height for the window to be. - @return NS_OK - Window Init succeeded without a problem. - NS_ERROR_UNEXPECTED - Call was unexpected at this time. Perhaps - initWindow() had already been called. - NS_ERROR_INVALID_ARG - controls that require either a parentNativeWindow - or a parentWidget may return invalid arg when they do not - receive what they are needing. - */ - [noscript]void initWindow(in nativeWindow parentNativeWindow, - in nsIWidget parentWidget, in long x, in long y, in long cx, in long cy); + @return NS_OK - Window Init succeeded without a problem. + NS_ERROR_UNEXPECTED - Call was unexpected at this time. Perhaps + initWindow() had already been called. + NS_ERROR_INVALID_ARG - controls that require either a parentNativeWindow + or a parentWidget may return invalid arg when they do not + receive what they are needing. + */ + [noscript]void initWindow(in nativeWindow parentNativeWindow, + in nsIWidget parentWidget, in long x, in long y, in long cx, in long cy); - /* - Tell the window that it should destroy itself. This call should not be - necessary as it will happen implictly when final release occurs on the - object. If for some reaons you want the window destroyed prior to release - due to cycle or ordering issues, then this call provides that ability. + /* + Tell the window that it should destroy itself. This call should not be + necessary as it will happen implictly when final release occurs on the + object. If for some reaons you want the window destroyed prior to release + due to cycle or ordering issues, then this call provides that ability. - @return NS_OK - Everything destroyed properly. - NS_ERROR_UNEXPECTED - This call was unexpected at this time. - Perhaps create() has not been called yet. - */ - void destroy(); + @return NS_OK - Everything destroyed properly. + NS_ERROR_UNEXPECTED - This call was unexpected at this time. + Perhaps create() has not been called yet. + */ + void destroy(); - /* - Sets the current x and y coordinates of the control. This is relative to - the parent window. - */ - void setPosition(in long x, in long y); + /* + Sets the current x and y coordinates of the control. This is relative to + the parent window. + */ + void setPosition(in long x, in long y); /* Ditto, with arguments in global desktop pixels rather than (potentially ambiguous) device pixels */ - void setPositionDesktopPix(in long x, in long y); + void setPositionDesktopPix(in long x, in long y); - /* - Gets the current x and y coordinates of the control. This is relatie to the - parent window. - */ - void getPosition(out long x, out long y); + /* + Gets the current x and y coordinates of the control. This is relative to the + parent window. + */ + void getPosition(out long x, out long y); - /* - Sets the width and height of the control. - */ - void setSize(in long cx, in long cy, in boolean fRepaint); + /* + Sets the width and height of the control. + */ + void setSize(in long cx, in long cy, in boolean fRepaint); - /* - Gets the width and height of the control. - */ - void getSize(out long cx, out long cy); + /* + Gets the width and height of the control. + */ + void getSize(out long cx, out long cy); - /** - * The 'flags' argument to setPositionAndSize is a set of these bits. - */ - const unsigned long eRepaint = 1; - const unsigned long eDelayResize = 2; + /** + * The 'flags' argument to setPositionAndSize is a set of these bits. + */ + const unsigned long eRepaint = 1; + const unsigned long eDelayResize = 2; - /* - Convenience function combining the SetPosition and SetSize into one call. - Also is more efficient than calling both. - */ - void setPositionAndSize(in long x, in long y, in long cx, in long cy, - in unsigned long flags); + /* + Convenience function combining the SetPosition and SetSize into one call. + Also is more efficient than calling both. + */ + void setPositionAndSize(in long x, in long y, in long cx, in long cy, + in unsigned long flags); - /* - Convenience function combining the GetPosition and GetSize into one call. - Also is more efficient than calling both. - */ - void getPositionAndSize(out long x, out long y, out long cx, out long cy); + /* + Convenience function combining the GetPosition and GetSize into one call. + Also is more efficient than calling both. + */ + void getPositionAndSize(out long x, out long y, out long cx, out long cy); - /** - * Tell the window to repaint itself - * @param aForce - if true, repaint immediately - * if false, the window may defer repainting as it sees fit. - */ - void repaint(in boolean force); + /** + * Tell the window to repaint itself + * @param aForce - if true, repaint immediately + * if false, the window may defer repainting as it sees fit. + */ + void repaint(in boolean force); - /* - This is the parenting widget for the control. This may be null if the - native window was handed in for the parent during initialization. - If this is returned, it should refer to the same object as - parentNativeWindow. + /* + This is the parenting widget for the control. This may be null if the + native window was handed in for the parent during initialization. + If this is returned, it should refer to the same object as + parentNativeWindow. - Setting this after Create() has been called may not be supported by some - implementations. + Setting this after Create() has been called may not be supported by some + implementations. - On controls that don't support widgets, setting this will return a - NS_ERROR_NOT_IMPLEMENTED error. - */ - [noscript] attribute nsIWidget parentWidget; + On controls that don't support widgets, setting this will return a + NS_ERROR_NOT_IMPLEMENTED error. + */ + [noscript] attribute nsIWidget parentWidget; - /* - This is the native window parent of the control. + /* + This is the native window parent of the control. - Setting this after Create() has been called may not be supported by some - implementations. + Setting this after Create() has been called may not be supported by some + implementations. - On controls that don't support setting nativeWindow parents, setting this - will return a NS_ERROR_NOT_IMPLEMENTED error. - */ - attribute nativeWindow parentNativeWindow; + On controls that don't support setting nativeWindow parents, setting this + will return a NS_ERROR_NOT_IMPLEMENTED error. + */ + attribute nativeWindow parentNativeWindow; - /* - This is the handle (HWND, GdkWindow*, ...) to the native window of the - control, exposed as an AString. + /* + This is the handle (HWND, GdkWindow*, ...) to the native window of the + control, exposed as an AString. - @return AString in hex format with "0x" prepended, or empty string if - mainWidget undefined + @return AString in hex format with "0x" prepended, or empty string if + mainWidget undefined - @throws NS_ERROR_NOT_IMPLEMENTED for non-XULWindows - */ - readonly attribute AString nativeHandle; + @throws NS_ERROR_NOT_IMPLEMENTED for non-XULWindows + */ + readonly attribute AString nativeHandle; - /* - Attribute controls the visibility of the object behind this interface. - Setting this attribute to false will hide the control. Setting it to - true will show it. - */ - attribute boolean visibility; + /* + Attribute controls the visibility of the object behind this interface. + Setting this attribute to false will hide the control. Setting it to + true will show it. + */ + attribute boolean visibility; /* a disabled window should accept no user interaction; it's a dead window, @@ -176,38 +178,58 @@ interface nsIBaseWindow : nsISupports */ attribute boolean enabled; - /* - Allows you to find out what the widget is of a given object. Depending - on the object, this may return the parent widget in which this object - lives if it has not had to create its own widget. - */ - [noscript] readonly attribute nsIWidget mainWidget; + /* + Allows you to find out what the widget is of a given object. Depending + on the object, this may return the parent widget in which this object + lives if it has not had to create its own widget. + */ + [noscript] readonly attribute nsIWidget mainWidget; - /* - The number of device pixels per CSS pixel used on this window's current - screen at the default zoom level. - This is the value returned by GetDefaultScale() of the underlying widget. - Note that this may change if the window is moved between screens with - differing resolutions. - */ - readonly attribute double unscaledDevicePixelsPerCSSPixel; + /* + The number of device pixels per CSS pixel used on this window's current + screen at the default zoom level. + This is the value returned by GetDefaultScale() of the underlying widget. + Note that this may change if the window is moved between screens with + differing resolutions. + */ + readonly attribute double unscaledDevicePixelsPerCSSPixel; - /* - The number of device pixels per display pixel on this window's current - screen. (The meaning of "display pixel" varies across OS environments; - it is the pixel units used by the desktop environment to manage screen - real estate and window positioning, which may correspond to (per-screen) - device pixels, or may be a virtual coordinate space that covers a multi- - monitor, mixed-dpi desktop space.) - This is the value returned by DevicePixelsPerDesktopPixel() of the underlying - widget. - Note that this may change if the window is moved between screens with - differing resolutions. - */ - readonly attribute double devicePixelsPerDesktopPixel; +%{C++ + mozilla::CSSToLayoutDeviceScale UnscaledDevicePixelsPerCSSPixel() { + double s = 1.0; + GetUnscaledDevicePixelsPerCSSPixel(&s); + return mozilla::CSSToLayoutDeviceScale(s); + } +%} - /* - Title of the window. - */ - attribute AString title; + /* + The number of device pixels per display pixel on this window's current + screen. (The meaning of "display pixel" varies across OS environments; + it is the pixel units used by the desktop environment to manage screen + real estate and window positioning, which may correspond to (per-screen) + device pixels, or may be a virtual coordinate space that covers a multi- + monitor, mixed-dpi desktop space.) + This is the value returned by GetDesktopToDeviceScale() of the underlying + widget. + Note that this may change if the window is moved between screens with + differing resolutions. + */ + readonly attribute double devicePixelsPerDesktopPixel; + +%{C++ + mozilla::DesktopToLayoutDeviceScale DevicePixelsPerDesktopPixel() { + double s = 1.0; + GetDevicePixelsPerDesktopPixel(&s); + return mozilla::DesktopToLayoutDeviceScale(s); + } + + mozilla::CSSToDesktopScale GetCSSToDesktopScale() { + return UnscaledDevicePixelsPerCSSPixel() / DevicePixelsPerDesktopPixel(); + } +%} + + /* + Title of the window. + */ + attribute AString title; }; diff --git a/widget/nsIScreen.idl b/widget/nsIScreen.idl index db9e3f8942bb..9c79f6093bbc 100644 --- a/widget/nsIScreen.idl +++ b/widget/nsIScreen.idl @@ -7,6 +7,8 @@ #include "nsISupports.idl" %{C++ +#include "Units.h" + /** * The display type of nsIScreen belongs to. */ @@ -17,7 +19,7 @@ enum class DisplayType: int32_t { }; %} -[scriptable, uuid(826e80c8-d70f-42e2-8aa9-82c05f2a370a)] +[scriptable, builtinclass, uuid(826e80c8-d70f-42e2-8aa9-82c05f2a370a)] interface nsIScreen : nsISupports { /** @@ -26,12 +28,40 @@ interface nsIScreen : nsISupports void GetRect(out long left, out long top, out long width, out long height); void GetAvailRect(out long left, out long top, out long width, out long height); +%{C++ + mozilla::LayoutDeviceIntRect GetRect() { + int32_t left = 0, top = 0, width = 0, height = 0; + GetRect(&left, &top, &width, &height); + return {left, top, width, height}; + } + + mozilla::LayoutDeviceIntRect GetAvailRect() { + int32_t left = 0, top = 0, width = 0, height = 0; + GetAvailRect(&left, &top, &width, &height); + return {left, top, width, height}; + } +%} + /** * And these report in desktop pixels */ void GetRectDisplayPix(out long left, out long top, out long width, out long height); void GetAvailRectDisplayPix(out long left, out long top, out long width, out long height); +%{C++ + mozilla::DesktopIntRect GetRectDisplayPix() { + int32_t left = 0, top = 0, width = 0, height = 0; + GetRectDisplayPix(&left, &top, &width, &height); + return {left, top, width, height}; + } + + mozilla::DesktopIntRect GetAvailRectDisplayPix() { + int32_t left = 0, top = 0, width = 0, height = 0; + GetAvailRectDisplayPix(&left, &top, &width, &height); + return {left, top, width, height}; + } +%} + readonly attribute long pixelDepth; readonly attribute long colorDepth; @@ -50,15 +80,30 @@ interface nsIScreen : nsISupports * GTK/X11). Per-monitor DPI is available in Windows 8.1+, GTK/Wayland or * macOS. */ - readonly attribute double contentsScaleFactor; + [infallible] readonly attribute double contentsScaleFactor; /** * The default number of device pixels per unscaled CSS pixel for this * screen. This is probably what contentsScaleFactor originally meant * to be, prior to confusion between CSS pixels and desktop pixel units. */ - readonly attribute double defaultCSSScaleFactor; + [infallible] readonly attribute double defaultCSSScaleFactor; +%{C++ + + mozilla::DesktopToLayoutDeviceScale GetDesktopToLayoutDeviceScale() { + return mozilla::DesktopToLayoutDeviceScale(GetContentsScaleFactor()); + } + + mozilla::CSSToLayoutDeviceScale GetCSSToLayoutDeviceScale() { + return mozilla::CSSToLayoutDeviceScale(GetDefaultCSSScaleFactor()); + } + + mozilla::CSSToDesktopScale GetCSSToDesktopScale() { + return GetCSSToLayoutDeviceScale() / GetDesktopToLayoutDeviceScale(); + } + +%} /** * The DPI of the screen. */ diff --git a/widget/nsIScreenManager.idl b/widget/nsIScreenManager.idl index 2864b960fb0d..9203d7891f30 100644 --- a/widget/nsIScreenManager.idl +++ b/widget/nsIScreenManager.idl @@ -7,21 +7,30 @@ #include "nsISupports.idl" #include "nsIScreen.idl" +%{C++ +#include "nsCOMPtr.h" +%} + [scriptable, uuid(e8a96e60-6b61-4a14-bacc-53891604b502)] interface nsIScreenManager : nsISupports { - // - // 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 pixels (not twips) and in screen coordinates. - // - nsIScreen screenForRect ( in long left, in long top, in long width, in long height ) ; + // 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 pixels (not twips) and in screen coordinates. + nsIScreen screenForRect(in long left, in long top, in long width, in long height) ; - // The screen with the menubar/taskbar. This shouldn't be needed very - // often. +%{C++ + already_AddRefed ScreenForRect(const mozilla::DesktopIntRect& aRect) { + nsCOMPtr screen; + ScreenForRect(aRect.x, aRect.y, aRect.width, aRect.height, getter_AddRefs(screen)); + return screen.forget(); + } +%} + + // The screen with the menubar/taskbar. This shouldn't be needed very often. readonly attribute nsIScreen primaryScreen; - // The total number of pixels across all monitors. + // The total number of pixels across all monitors. readonly attribute int64_t totalScreenPixels; };