1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
diff -up mozilla-release/widget/gtk/nsNativeThemeGTK.cpp.1144745-1 mozilla-release/widget/gtk/nsNativeThemeGTK.cpp
--- mozilla-release/widget/gtk/nsNativeThemeGTK.cpp.1144745-1 2015-05-13 10:25:28.638492635 +0200
+++ mozilla-release/widget/gtk/nsNativeThemeGTK.cpp 2015-05-13 10:28:41.438095846 +0200
@@ -32,6 +32,7 @@
#include "gfxPlatformGtk.h"
#include "gfxGdkNativeRenderer.h"
#include <algorithm>
+#include <dlfcn.h>
using namespace mozilla;
using namespace mozilla::gfx;
@@ -88,6 +89,24 @@ nsNativeThemeGTK::RefreshWidgetWindow(ns
vm->InvalidateAllViews();
}
+gint
+nsNativeThemeGTK::GdkScaleFactor()
+{
+#if (MOZ_WIDGET_GTK >= 3)
+ // Since GDK 3.10
+ static auto sGdkScreenGetMonitorScaleFactorPtr = (gint (*)(GdkScreen*, gint))
+ dlsym(RTLD_DEFAULT, "gdk_screen_get_monitor_scale_factor");
+ if (sGdkScreenGetMonitorScaleFactorPtr) {
+ // FIXME: In the future, we'll want to fix this for GTK on Wayland which
+ // supports a variable scale factor per display.
+ GdkScreen *screen = gdk_screen_get_default();
+ return sGdkScreenGetMonitorScaleFactorPtr(screen, 0);
+ }
+#endif
+ return 1;
+}
+
+
static bool IsFrameContentNodeInNamespace(nsIFrame *aFrame, uint32_t aNamespace)
{
nsIContent *content = aFrame ? aFrame->GetContent() : nullptr;
@@ -711,10 +730,10 @@ nsNativeThemeGTK::GetExtraSizeForWidget(
switch (aWidgetType) {
case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
aExtra->top = aExtra->bottom = 1;
- return true;
+ break;
case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
aExtra->left = aExtra->right = 1;
- return true;
+ break;
// Include the indicator spacing (the padding around the control).
case NS_THEME_CHECKBOX:
@@ -732,7 +751,7 @@ nsNativeThemeGTK::GetExtraSizeForWidget(
aExtra->right = indicator_spacing;
aExtra->bottom = indicator_spacing;
aExtra->left = indicator_spacing;
- return true;
+ break;
}
case NS_THEME_BUTTON :
{
@@ -745,7 +764,7 @@ nsNativeThemeGTK::GetExtraSizeForWidget(
aExtra->right = right;
aExtra->bottom = bottom;
aExtra->left = left;
- return true;
+ break;
}
}
case NS_THEME_FOCUS_OUTLINE:
@@ -753,7 +772,7 @@ nsNativeThemeGTK::GetExtraSizeForWidget(
moz_gtk_get_focus_outline_size(&aExtra->left, &aExtra->top);
aExtra->right = aExtra->left;
aExtra->bottom = aExtra->top;
- return true;
+ break;
}
case NS_THEME_TAB :
{
@@ -777,6 +796,11 @@ nsNativeThemeGTK::GetExtraSizeForWidget(
default:
return false;
}
+ aExtra->top *= GdkScaleFactor();
+ aExtra->right *= GdkScaleFactor();
+ aExtra->bottom *= GdkScaleFactor();
+ aExtra->left *= GdkScaleFactor();
+ return true;
}
NS_IMETHODIMP
@@ -803,6 +827,7 @@ nsNativeThemeGTK::DrawWidgetBackground(n
gfxRect rect = presContext->AppUnitsToGfxUnits(aRect);
gfxRect dirtyRect = presContext->AppUnitsToGfxUnits(aDirtyRect);
+ gint scaleFactor = GdkScaleFactor();
// Align to device pixels where sensible
// to provide crisper and faster drawing.
@@ -840,8 +865,10 @@ nsNativeThemeGTK::DrawWidgetBackground(n
// gdk rectangles are wrt the drawing rect.
- GdkRectangle gdk_rect = {-drawingRect.x, -drawingRect.y,
- widgetRect.width, widgetRect.height};
+ GdkRectangle gdk_rect = {-drawingRect.x/scaleFactor,
+ -drawingRect.y/scaleFactor,
+ widgetRect.width/scaleFactor,
+ widgetRect.height/scaleFactor};
// translate everything so (0,0) is the top left of the drawingRect
gfxContextAutoSaveRestore autoSR(ctx);
@@ -850,6 +877,7 @@ nsNativeThemeGTK::DrawWidgetBackground(n
tm = ctx->CurrentMatrix();
}
tm.Translate(rect.TopLeft() + gfxPoint(drawingRect.x, drawingRect.y));
+ tm.Scale(scaleFactor, scaleFactor); // Draw in GDK coords
ctx->SetMatrix(tm);
NS_ASSERTION(!IsWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType),
@@ -1038,6 +1066,11 @@ nsNativeThemeGTK::GetWidgetPadding(nsDev
aResult->left += horizontal_padding;
aResult->right += horizontal_padding;
+ aResult->top *= GdkScaleFactor();
+ aResult->right *= GdkScaleFactor();
+ aResult->bottom *= GdkScaleFactor();
+ aResult->left *= GdkScaleFactor();
+
return true;
}
}
@@ -1298,6 +1331,9 @@ nsNativeThemeGTK::GetMinimumWidgetSize(n
}
break;
}
+
+ *aResult = *aResult * GdkScaleFactor();
+
return NS_OK;
}
diff -up mozilla-release/widget/gtk/nsNativeThemeGTK.h.1144745-1 mozilla-release/widget/gtk/nsNativeThemeGTK.h
--- mozilla-release/widget/gtk/nsNativeThemeGTK.h.1144745-1 2015-05-08 18:55:27.000000000 +0200
+++ mozilla-release/widget/gtk/nsNativeThemeGTK.h 2015-05-13 10:25:28.642492647 +0200
@@ -81,6 +81,7 @@ private:
nsIntMargin* aExtra);
void RefreshWidgetWindow(nsIFrame* aFrame);
+ gint GdkScaleFactor();
uint8_t mDisabledWidgetTypes[32];
uint8_t mSafeWidgetStates[1024]; // 256 widgets * 32 bits per widget
|