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 1079883002: Revert of device scale factor detection: use gtk-xft-dpi consistently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | ui/views/linux_ui/linux_ui.h » ('j') | 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 <set> 7 #include <set>
8 8
9 #include <pango/pango.h> 9 #include <pango/pango.h>
10 10
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; 373 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
374 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; 374 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
375 } 375 }
376 376
377 g_free(hint_style); 377 g_free(hint_style);
378 g_free(rgba); 378 g_free(rgba);
379 379
380 return params; 380 return params;
381 } 381 }
382 382
383 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) {
384 GtkSettings* gtk_settings = gtk_settings_get_default(); 386 GtkSettings* gtk_settings = gtk_settings_get_default();
385 CHECK(gtk_settings); 387 CHECK(gtk_settings);
386 gint gtk_dpi = -1; 388 gint gtk_dpi = -1;
387 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL); 389 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL);
388 390
389 // GTK multiplies the DPI by 1024 before storing it. 391 // GTK multiplies the DPI by 1024 before storing it.
390 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; 392 double dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0;
391 }
392
393 // Queries GTK for its font DPI setting and returns the number of pixels in a
394 // point.
395 double GetPixelsInPoint(float device_scale_factor) {
396 double dpi = GetDPI();
397 393
398 // Take device_scale_factor into account — if Chrome already scales the 394 // Take device_scale_factor into account — if Chrome already scales the
399 // entire UI up by 2x, we should not also scale up. 395 // entire UI up by 2x, we should not also scale up.
400 dpi /= device_scale_factor; 396 dpi /= device_scale_factor;
401 397
402 // There are 72 points in an inch. 398 // There are 72 points in an inch.
403 return dpi / 72.0; 399 return dpi / 72.0;
404 } 400 }
405 401
406 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 402 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 LoadGtkValues(); 1413 LoadGtkValues();
1418 NativeThemeGtk2::instance()->NotifyObservers(); 1414 NativeThemeGtk2::instance()->NotifyObservers();
1419 } 1415 }
1420 1416
1421 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { 1417 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
1422 device_scale_factor_ = device_scale_factor; 1418 device_scale_factor_ = device_scale_factor;
1423 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); 1419 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
1424 UpdateDefaultFont(label_style->font_desc); 1420 UpdateDefaultFont(label_style->font_desc);
1425 } 1421 }
1426 1422
1427 float Gtk2UI::GetDeviceScaleFactor() const {
1428 const int kCSSDefaultDPI = 96;
1429 const float scale = GetDPI() / kCSSDefaultDPI;
1430 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale));
1431 }
1432
1433 } // namespace libgtk2ui 1423 } // namespace libgtk2ui
1434 1424
1435 views::LinuxUI* BuildGtk2UI() { 1425 views::LinuxUI* BuildGtk2UI() {
1436 return new libgtk2ui::Gtk2UI; 1426 return new libgtk2ui::Gtk2UI;
1437 } 1427 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | ui/views/linux_ui/linux_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698