Index: chrome/browser/ui/libgtk2ui/gtk2_ui.cc |
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc |
index 1925e13cd9d18a880669eba77bdc66c6416b08fd..0c50dcdb5f81976bc633dc894d867f0015404b57 100644 |
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc |
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc |
@@ -8,6 +8,7 @@ |
#include <set> |
#include <pango/pango.h> |
+#include <X11/Xlib.h> |
#include "base/command_line.h" |
#include "base/debug/leak_annotations.h" |
@@ -49,6 +50,7 @@ |
#include "ui/gfx/image/image.h" |
#include "ui/gfx/skbitmap_operations.h" |
#include "ui/gfx/skia_util.h" |
+#include "ui/gfx/x/x11_types.h" |
#include "ui/resources/grit/ui_resources.h" |
#include "ui/views/controls/button/label_button.h" |
#include "ui/views/controls/button/label_button_border.h" |
@@ -378,20 +380,27 @@ gfx::FontRenderParams GetGtkFontRenderParams() { |
return params; |
} |
-double GetDPI() { |
+double GetBaseDPI() { |
+ XDisplay* xdisplay = gfx::GetXDisplay(); |
+ int xscreen = DefaultScreen(xdisplay); |
+ return (static_cast<double>(DisplayWidth(xdisplay, xscreen)) * 25.4) / |
Evan Stade
2015/05/13 22:09:27
is this casting truly necessary? 25.4 is already a
oshima
2015/05/13 22:21:23
I was lazy, sorry. (was cut&paste) Fixed.
|
+ static_cast<double>(DisplayWidthMM(xdisplay, xscreen)); |
+} |
+ |
+double GetFontDPI() { |
GtkSettings* gtk_settings = gtk_settings_get_default(); |
CHECK(gtk_settings); |
gint gtk_dpi = -1; |
g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); |
// GTK multiplies the DPI by 1024 before storing it. |
- return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; |
+ return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : GetBaseDPI(); |
} |
// Queries GTK for its font DPI setting and returns the number of pixels in a |
// point. |
double GetPixelsInPoint(float device_scale_factor) { |
- double dpi = GetDPI(); |
+ double dpi = GetFontDPI(); |
// Take device_scale_factor into account — if Chrome already scales the |
// entire UI up by 2x, we should not also scale up. |
@@ -1424,10 +1433,9 @@ void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { |
} |
float Gtk2UI::GetDeviceScaleFactor() const { |
- const int kCSSDefaultDPI = 96; |
- float scale = GetDPI() / kCSSDefaultDPI; |
- // Round to 2 decimals, e.g. to 1.33. |
- return roundf(scale * 100) / 100; |
+ float scale = GetFontDPI() / GetBaseDPI(); |
+ // Round to 1 decimals, e.g. to 1.4. |
+ return roundf(scale * 10) / 10; |
} |
} // namespace libgtk2ui |