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> | |
8 #include <set> | 7 #include <set> |
9 | 8 |
10 #include <pango/pango.h> | 9 #include <pango/pango.h> |
11 | 10 |
12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
13 #include "base/debug/leak_annotations.h" | 12 #include "base/debug/leak_annotations.h" |
14 #include "base/environment.h" | 13 #include "base/environment.h" |
15 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
16 #include "base/logging.h" | 15 #include "base/logging.h" |
17 #include "base/nix/mime_util_xdg.h" | 16 #include "base/nix/mime_util_xdg.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; | 373 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; |
375 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; | 374 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; |
376 } | 375 } |
377 | 376 |
378 g_free(hint_style); | 377 g_free(hint_style); |
379 g_free(rgba); | 378 g_free(rgba); |
380 | 379 |
381 return params; | 380 return params; |
382 } | 381 } |
383 | 382 |
384 double GetDPI() { | 383 // Queries GTK for its font DPI setting and returns the number of pixels in a |
| 384 // point. |
| 385 double GetPixelsInPoint(float device_scale_factor) { |
385 GtkSettings* gtk_settings = gtk_settings_get_default(); | 386 GtkSettings* gtk_settings = gtk_settings_get_default(); |
386 CHECK(gtk_settings); | 387 CHECK(gtk_settings); |
387 gint gtk_dpi = -1; | 388 gint gtk_dpi = -1; |
388 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); | 389 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); |
389 | 390 |
390 // GTK multiplies the DPI by 1024 before storing it. | 391 // GTK multiplies the DPI by 1024 before storing it. |
391 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; | 392 double dpi = (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(); | |
398 | 393 |
399 // Take device_scale_factor into account — if Chrome already scales the | 394 // Take device_scale_factor into account — if Chrome already scales the |
400 // entire UI up by 2x, we should not also scale up. | 395 // entire UI up by 2x, we should not also scale up. |
401 dpi /= device_scale_factor; | 396 dpi /= device_scale_factor; |
402 | 397 |
403 // There are 72 points in an inch. | 398 // There are 72 points in an inch. |
404 return dpi / 72.0; | 399 return dpi / 72.0; |
405 } | 400 } |
406 | 401 |
407 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { | 402 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 LoadGtkValues(); | 1413 LoadGtkValues(); |
1419 NativeThemeGtk2::instance()->NotifyObservers(); | 1414 NativeThemeGtk2::instance()->NotifyObservers(); |
1420 } | 1415 } |
1421 | 1416 |
1422 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { | 1417 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { |
1423 device_scale_factor_ = device_scale_factor; | 1418 device_scale_factor_ = device_scale_factor; |
1424 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 1419 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
1425 UpdateDefaultFont(label_style->font_desc); | 1420 UpdateDefaultFont(label_style->font_desc); |
1426 } | 1421 } |
1427 | 1422 |
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 | |
1435 } // namespace libgtk2ui | 1423 } // namespace libgtk2ui |
1436 | 1424 |
1437 views::LinuxUI* BuildGtk2UI() { | 1425 views::LinuxUI* BuildGtk2UI() { |
1438 return new libgtk2ui::Gtk2UI; | 1426 return new libgtk2ui::Gtk2UI; |
1439 } | 1427 } |
OLD | NEW |