diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index bf34769f9de5..93ba05b6e23f 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -4353,6 +4353,15 @@ mirror: always rust: true +# Set the number of device pixels per CSS pixel. A value <= 0 means choose +# automatically based on user settings for the platform (e.g., "UI scale factor" +# on Mac). A positive value is used as-is. This effectively controls the size +# of a CSS "px". This is only used for windows on the screen, not for printing. +- name: layout.css.devPixelsPerPx + type: AtomicFloat + value: -1.0f + mirror: always + # text underline offset - name: layout.css.text-underline-offset.enabled type: bool diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 5a6eb5204339..90ca2ef897a7 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2868,12 +2868,6 @@ pref("layout.css.report_errors", true); // interpretation of physical units such as "pt". pref("layout.css.dpi", -1); -// Set the number of device pixels per CSS pixel. A value <= 0 means choose -// automatically based on user settings for the platform (e.g., "UI scale factor" -// on Mac). A positive value is used as-is. This effectively controls the size -// of a CSS "px". This is only used for windows on the screen, not for printing. -pref("layout.css.devPixelsPerPx", "-1.0"); - // Set the threshold distance in CSS pixels below which scrolling will snap to // an edge, when scroll snapping is set to "proximity". pref("layout.css.scroll-snap.proximity-threshold", 200); diff --git a/widget/Screen.cpp b/widget/Screen.cpp index f5145e92fe50..4fb196fe8776 100644 --- a/widget/Screen.cpp +++ b/widget/Screen.cpp @@ -7,6 +7,7 @@ #include "Screen.h" #include "mozilla/dom/DOMTypes.h" +#include "mozilla/StaticPrefs_layout.h" namespace mozilla { namespace widget { @@ -103,7 +104,7 @@ Screen::GetContentsScaleFactor(double* aOutScale) { NS_IMETHODIMP Screen::GetDefaultCSSScaleFactor(double* aOutScale) { - double scale = nsIWidget::DefaultScaleOverride(); + double scale = StaticPrefs::layout_css_devPixelsPerPx(); if (scale > 0.0) { *aOutScale = scale; } else { diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 305c033d4455..5de79779e010 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -20,6 +20,7 @@ #include "gfxPlatformGtk.h" #include "mozilla/FontPropertyTypes.h" #include "mozilla/RelativeLuminanceUtils.h" +#include "mozilla/StaticPrefs_layout.h" #include "ScreenHelperGTK.h" #include "gtkdrawing.h" @@ -812,7 +813,7 @@ bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, } // Scale the font for the current monitor - double scaleFactor = nsIWidget::DefaultScaleOverride(); + double scaleFactor = StaticPrefs::layout_css_devPixelsPerPx(); if (scaleFactor > 0) { aFontStyle.size *= widget::ScreenHelperGTK::GetGTKMonitorScaleFactor() / scaleFactor; diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index 11f7034d0ecc..b45f93b5b244 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -73,7 +73,7 @@ static int gLastGdkError; static inline gint GetMonitorScaleFactor(nsIFrame* aFrame) { // When the layout.css.devPixelsPerPx is set the scale can be < 1, // the real monitor scale cannot go under 1. - double scale = nsIWidget::DefaultScaleOverride(); + double scale = StaticPrefs::layout_css_devPixelsPerPx(); if (scale <= 0) { nsIWidget* rootWidget = aFrame->PresContext()->GetRootWidget(); if (rootWidget) { diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 2d6f56b04f76..33d125e0352c 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -72,6 +72,7 @@ #include "mozilla/gfx/gfxVars.h" #include "mozilla/Move.h" #include "mozilla/Sprintf.h" +#include "mozilla/StaticPrefs_layout.h" #include "mozilla/webrender/WebRenderTypes.h" #include "nsRefPtrHashtable.h" #include "TouchEvents.h" @@ -517,7 +518,7 @@ nsIWidget* nsBaseWidget::GetSheetWindowParent(void) { return nullptr; } float nsBaseWidget::GetDPI() { return 96.0f; } CSSToLayoutDeviceScale nsIWidget::GetDefaultScale() { - double devPixelsPerCSSPixel = DefaultScaleOverride(); + double devPixelsPerCSSPixel = StaticPrefs::layout_css_devPixelsPerPx(); if (devPixelsPerCSSPixel <= 0.0) { devPixelsPerCSSPixel = GetDefaultScaleInternal(); @@ -526,23 +527,6 @@ CSSToLayoutDeviceScale nsIWidget::GetDefaultScale() { return CSSToLayoutDeviceScale(devPixelsPerCSSPixel); } -/* static */ -double nsIWidget::DefaultScaleOverride() { - // The number of device pixels per CSS pixel. A value <= 0 means choose - // automatically based on the DPI. A positive value is used as-is. This - // effectively controls the size of a CSS "px". - static float devPixelsPerCSSPixel = -1.0f; - - static bool valueCached = false; - if (!valueCached) { - Preferences::AddFloatVarCache(&devPixelsPerCSSPixel, - "layout.css.devPixelsPerPx", -1.0f); - valueCached = true; - } - - return devPixelsPerCSSPixel; -} - //------------------------------------------------------------------------- // // Add a child to the list of children diff --git a/widget/windows/TaskbarPreview.cpp b/widget/windows/TaskbarPreview.cpp index 376dd9b166f5..267ef3bf04f2 100644 --- a/widget/windows/TaskbarPreview.cpp +++ b/widget/windows/TaskbarPreview.cpp @@ -25,6 +25,7 @@ #include "mozilla/dom/HTMLCanvasElement.h" #include "mozilla/gfx/2D.h" #include "mozilla/gfx/DataSurfaceHelpers.h" +#include "mozilla/StaticPrefs_layout.h" #include "mozilla/Telemetry.h" // Defined in dwmapi in a header that needs a higher numbered _WINNT #define @@ -232,7 +233,7 @@ TaskbarPreview::WndProc(UINT nMsg, WPARAM wParam, LPARAM lParam) { rv = mController->GetHeight(&height); if (NS_FAILED(rv)) break; - double scale = nsIWidget::DefaultScaleOverride(); + double scale = StaticPrefs::layout_css_devPixelsPerPx(); if (scale <= 0.0) { scale = WinUtils::LogToPhysFactor(PreviewWindow()); } diff --git a/widget/windows/nsNativeThemeWin.cpp b/widget/windows/nsNativeThemeWin.cpp index f7f772e54eb3..f968b83d1eff 100644 --- a/widget/windows/nsNativeThemeWin.cpp +++ b/widget/windows/nsNativeThemeWin.cpp @@ -1494,7 +1494,7 @@ static bool AssumeThemePartAndStateAreTransparent(int32_t aPart, // the system default resolution. static inline double GetThemeDpiScaleFactor(nsIFrame* aFrame) { if (WinUtils::IsPerMonitorDPIAware() || - nsIWidget::DefaultScaleOverride() > 0.0) { + StaticPrefs::layout_css_devPixelsPerPx() > 0.0) { nsIWidget* rootWidget = aFrame->PresContext()->GetRootWidget(); if (rootWidget) { double systemScale = WinUtils::SystemScaleFactor(); diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index bc8f9ea91146..8939e6ab553b 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -146,6 +146,7 @@ #include "InProcessWinCompositorWidget.h" #include "InputDeviceUtils.h" #include "ScreenHelperWin.h" +#include "mozilla/StaticPrefs_layout.h" #include "nsIGfxInfo.h" #include "nsUXThemeConstants.h" @@ -7227,7 +7228,7 @@ void nsWindow::OnDPIChanged(int32_t x, int32_t y, int32_t width, if (mWindowType == eWindowType_popup) { return; } - if (DefaultScaleOverride() > 0.0) { + if (StaticPrefs::layout_css_devPixelsPerPx() > 0.0) { return; } mDefaultScale = -1.0; // force recomputation of scale factor