Bug 1699930 - Don't let GTK text scale affect non-native scrollbar sizes. r=mstange

This matches the native theme. We plumb it via LookAndFeel to avoid
having to load GTK settings in child processes.

Differential Revision: https://phabricator.services.mozilla.com/D109275
This commit is contained in:
Emilio Cobos Álvarez 2021-03-22 16:11:33 +00:00
Родитель c8b4a27dc9
Коммит 75e5766b67
6 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -353,6 +353,9 @@ gfxPlatformFontList* gfxPlatformGtk::CreatePlatformFontList() {
}
int32_t gfxPlatformGtk::GetFontScaleDPI() {
MOZ_ASSERT(XRE_IsParentProcess(),
"You can access this via LookAndFeel if you need it in child "
"processes");
if (MOZ_LIKELY(sDPI != 0)) {
return sDPI;
}

Просмотреть файл

@ -408,6 +408,9 @@ class LookAndFeel {
// should be added to the calculated caret width.
CaretAspectRatio,
// GTK text scale factor.
TextScaleFactor,
// Not an ID; used to define the range of valid IDs. Must be last.
End,
};

Просмотреть файл

@ -830,6 +830,9 @@ nsresult nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
EnsureInit();
aResult = mCaretRatio;
break;
case FloatID::TextScaleFactor:
aResult = gfxPlatformGtk::GetFontScaleFactor();
break;
default:
aResult = -1.0;
rv = NS_ERROR_FAILURE;

Просмотреть файл

@ -84,8 +84,9 @@ static inline gint GetMonitorScaleFactor(nsPresContext* aPresContext) {
// value. The computed monitor scale factor needs to be rounded before
// casting to integer to avoid rounding errors which would lead to
// returning 0.
int monitorScale = int(round(rootWidget->GetDefaultScale().scale /
gfxPlatformGtk::GetFontScaleFactor()));
int monitorScale = int(
round(rootWidget->GetDefaultScale().scale /
LookAndFeel::GetFloat(LookAndFeel::FloatID::TextScaleFactor)));
// Monitor scale can be negative if it has not been initialized in the
// puppet widget yet. We also make sure that we return positive value.
if (monitorScale < 1) {
@ -1093,8 +1094,7 @@ NS_IMETHODIMP
nsNativeThemeGTK::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
StyleAppearance aAppearance,
const nsRect& aRect,
const nsRect& aDirtyRect,
DrawOverflow) {
const nsRect& aDirtyRect, DrawOverflow) {
GtkWidgetState state;
WidgetNodeType gtkWidgetType;
GtkTextDirection direction = GetTextDirection(aFrame);

Просмотреть файл

@ -4975,6 +4975,9 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
G_CALLBACK(settings_changed_cb), this);
g_signal_connect_after(default_settings, "notify::gtk-xft-dpi",
G_CALLBACK(settings_xft_dpi_changed_cb), this);
// Text resolution affects system fonts and widget sizes.
g_signal_connect_after(default_settings, "notify::resolution",
G_CALLBACK(settings_changed_cb), this);
// For remote LookAndFeel, to refresh the content processes' copies:
g_signal_connect_after(default_settings, "notify::gtk-cursor-blink-time",
G_CALLBACK(settings_changed_cb), this);

Просмотреть файл

@ -174,6 +174,15 @@ void nsNativeBasicTheme::RecomputeScrollbarSizes() {
} else {
sHorizontalScrollbarHeight = sVerticalScrollbarWidth = defaultSize;
}
// On GTK, widgets don't account for text scale factor, but that's included
// in the usual DPI computations, so we undo that here, just like
// GetMonitorScaleFactor does it in nsNativeThemeGTK.
float scale =
LookAndFeel::GetFloat(LookAndFeel::FloatID::TextScaleFactor, 1.0f);
if (scale != 1.0f) {
sVerticalScrollbarWidth = float(sVerticalScrollbarWidth) / scale;
sHorizontalScrollbarHeight = float(sHorizontalScrollbarHeight) / scale;
}
}
static bool IsScrollbarWidthThin(nsIFrame* aFrame) {
@ -1599,7 +1608,8 @@ bool nsNativeBasicTheme::CreateWebRenderCommandsForWidget(
return false;
}
WebRenderBackendData data{aBuilder, aResources, aSc, aManager};
return DoDrawWidgetBackground(data, aFrame, aAppearance, aRect, DrawOverflow::Yes);
return DoDrawWidgetBackground(data, aFrame, aAppearance, aRect,
DrawOverflow::Yes);
}
static LayoutDeviceRect ToSnappedRect(const nsRect& aRect,