Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Issue 2022383002: Keep using the same DPI scale (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <math.h>
8 #include <pango/pango.h> 8 #include <pango/pango.h>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; 424 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
425 } 425 }
426 426
427 g_free(hint_style); 427 g_free(hint_style);
428 g_free(rgba); 428 g_free(rgba);
429 429
430 return params; 430 return params;
431 } 431 }
432 432
433 double GetDPI() { 433 double GetDPI() {
434 GtkSettings* gtk_settings = gtk_settings_get_default(); 434 // Linux chrome currently does not support dynamic DPI changes.
435 CHECK(gtk_settings); 435 // Keep using the first value detected.
Elliot Glaysher 2016/06/01 17:22:43 I has a sad.
436 gint gtk_dpi = -1; 436 static double dpi = -1.f;
437 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL); 437 if (dpi < 0) {
438 const double kDefaultDPI = 96;
438 439
439 // GTK multiplies the DPI by 1024 before storing it. 440 GtkSettings* gtk_settings = gtk_settings_get_default();
440 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; 441 CHECK(gtk_settings);
442 gint gtk_dpi = -1;
443 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL);
444
445 // GTK multiplies the DPI by 1024 before storing it.
446 dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI;
447
448 // DSF is always >=1.0 on win/cros and lower DSF has never been considered
449 // nor tested.
450 dpi = std::max(kDefaultDPI, dpi);
451 }
452 return dpi;
441 } 453 }
442 454
443 // Queries GTK for its font DPI setting and returns the number of pixels in a 455 // Queries GTK for its font DPI setting and returns the number of pixels in a
444 // point. 456 // point.
445 double GetPixelsInPoint(float device_scale_factor) { 457 double GetPixelsInPoint(float device_scale_factor) {
446 double dpi = GetDPI(); 458 double dpi = GetDPI();
447 459
448 // Take device_scale_factor into account — if Chrome already scales the 460 // Take device_scale_factor into account — if Chrome already scales the
449 // entire UI up by 2x, we should not also scale up. 461 // entire UI up by 2x, we should not also scale up.
450 dpi /= device_scale_factor; 462 dpi /= device_scale_factor;
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 // Blacklist scaling factors <130% (crbug.com/484400) and round 1401 // Blacklist scaling factors <130% (crbug.com/484400) and round
1390 // to 1 decimal to prevent rendering problems (crbug.com/485183). 1402 // to 1 decimal to prevent rendering problems (crbug.com/485183).
1391 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; 1403 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10;
1392 } 1404 }
1393 1405
1394 } // namespace libgtk2ui 1406 } // namespace libgtk2ui
1395 1407
1396 views::LinuxUI* BuildGtk2UI() { 1408 views::LinuxUI* BuildGtk2UI() {
1397 return new libgtk2ui::Gtk2UI; 1409 return new libgtk2ui::Gtk2UI;
1398 } 1410 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698