| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" | 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" |
| 6 | 6 |
| 7 #include <math.h> |
| 7 #include <set> | 8 #include <set> |
| 8 | 9 |
| 9 #include <pango/pango.h> | 10 #include <pango/pango.h> |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/debug/leak_annotations.h" | 13 #include "base/debug/leak_annotations.h" |
| 13 #include "base/environment.h" | 14 #include "base/environment.h" |
| 14 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/nix/mime_util_xdg.h" | 17 #include "base/nix/mime_util_xdg.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; | 374 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; |
| 374 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; | 375 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; |
| 375 } | 376 } |
| 376 | 377 |
| 377 g_free(hint_style); | 378 g_free(hint_style); |
| 378 g_free(rgba); | 379 g_free(rgba); |
| 379 | 380 |
| 380 return params; | 381 return params; |
| 381 } | 382 } |
| 382 | 383 |
| 383 // Queries GTK for its font DPI setting and returns the number of pixels in a | 384 double GetDPI() { |
| 384 // point. | |
| 385 double GetPixelsInPoint(float device_scale_factor) { | |
| 386 GtkSettings* gtk_settings = gtk_settings_get_default(); | 385 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 387 CHECK(gtk_settings); | 386 CHECK(gtk_settings); |
| 388 gint gtk_dpi = -1; | 387 gint gtk_dpi = -1; |
| 389 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); | 388 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); |
| 390 | 389 |
| 391 // GTK multiplies the DPI by 1024 before storing it. | 390 // GTK multiplies the DPI by 1024 before storing it. |
| 392 double dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; | 391 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; |
| 392 } |
| 393 |
| 394 // Queries GTK for its font DPI setting and returns the number of pixels in a |
| 395 // point. |
| 396 double GetPixelsInPoint(float device_scale_factor) { |
| 397 double dpi = GetDPI(); |
| 393 | 398 |
| 394 // Take device_scale_factor into account — if Chrome already scales the | 399 // Take device_scale_factor into account — if Chrome already scales the |
| 395 // entire UI up by 2x, we should not also scale up. | 400 // entire UI up by 2x, we should not also scale up. |
| 396 dpi /= device_scale_factor; | 401 dpi /= device_scale_factor; |
| 397 | 402 |
| 398 // There are 72 points in an inch. | 403 // There are 72 points in an inch. |
| 399 return dpi / 72.0; | 404 return dpi / 72.0; |
| 400 } | 405 } |
| 401 | 406 |
| 402 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { | 407 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { |
| (...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 LoadGtkValues(); | 1418 LoadGtkValues(); |
| 1414 NativeThemeGtk2::instance()->NotifyObservers(); | 1419 NativeThemeGtk2::instance()->NotifyObservers(); |
| 1415 } | 1420 } |
| 1416 | 1421 |
| 1417 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { | 1422 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { |
| 1418 device_scale_factor_ = device_scale_factor; | 1423 device_scale_factor_ = device_scale_factor; |
| 1419 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 1424 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
| 1420 UpdateDefaultFont(label_style->font_desc); | 1425 UpdateDefaultFont(label_style->font_desc); |
| 1421 } | 1426 } |
| 1422 | 1427 |
| 1428 float Gtk2UI::GetDeviceScaleFactor() const { |
| 1429 const int kCSSDefaultDPI = 96; |
| 1430 float scale = GetDPI() / kCSSDefaultDPI; |
| 1431 // Round to 2 decimals, e.g. to 1.33. |
| 1432 return roundf(scale * 100) / 100; |
| 1433 } |
| 1434 |
| 1423 } // namespace libgtk2ui | 1435 } // namespace libgtk2ui |
| 1424 | 1436 |
| 1425 views::LinuxUI* BuildGtk2UI() { | 1437 views::LinuxUI* BuildGtk2UI() { |
| 1426 return new libgtk2ui::Gtk2UI; | 1438 return new libgtk2ui::Gtk2UI; |
| 1427 } | 1439 } |
| OLD | NEW |