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

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

Issue 1171693008: device scale factor detection: use gtk-xft-dpi consistently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2357
Patch Set: Created 5 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 | « 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 // Queries GTK for its font DPI setting and returns the number of pixels in a 383 double GetDPI() {
384 // point.
385 double GetPixelsInPoint(float device_scale_factor) {
386 GtkSettings* gtk_settings = gtk_settings_get_default(); 384 GtkSettings* gtk_settings = gtk_settings_get_default();
387 CHECK(gtk_settings); 385 CHECK(gtk_settings);
388 gint gtk_dpi = -1; 386 gint gtk_dpi = -1;
389 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL); 387 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL);
390 388
391 // GTK multiplies the DPI by 1024 before storing it. 389 // GTK multiplies the DPI by 1024 before storing it.
392 double dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; 390 return (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();
393 397
394 // Take device_scale_factor into account — if Chrome already scales the 398 // Take device_scale_factor into account — if Chrome already scales the
395 // entire UI up by 2x, we should not also scale up. 399 // entire UI up by 2x, we should not also scale up.
396 dpi /= device_scale_factor; 400 dpi /= device_scale_factor;
397 401
398 // There are 72 points in an inch. 402 // There are 72 points in an inch.
399 return dpi / 72.0; 403 return dpi / 72.0;
400 } 404 }
401 405
402 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 406 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 LoadGtkValues(); 1417 LoadGtkValues();
1414 NativeThemeGtk2::instance()->NotifyObservers(); 1418 NativeThemeGtk2::instance()->NotifyObservers();
1415 } 1419 }
1416 1420
1417 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { 1421 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
1418 device_scale_factor_ = device_scale_factor; 1422 device_scale_factor_ = device_scale_factor;
1419 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); 1423 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
1420 UpdateDefaultFont(label_style->font_desc); 1424 UpdateDefaultFont(label_style->font_desc);
1421 } 1425 }
1422 1426
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
1423 } // namespace libgtk2ui 1433 } // namespace libgtk2ui
1424 1434
1425 views::LinuxUI* BuildGtk2UI() { 1435 views::LinuxUI* BuildGtk2UI() {
1426 return new libgtk2ui::Gtk2UI; 1436 return new libgtk2ui::Gtk2UI;
1427 } 1437 }
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