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

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

Issue 1276553007: Revert broken Linux hidpi changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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/BUILD.gn ('k') | chrome/browser/ui/libgtk2ui/libgtk2ui.gyp » ('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 <math.h> 7 #include <math.h>
8 #include <set> 8 #include <set>
9 9
10 #include <pango/pango.h> 10 #include <pango/pango.h>
11 #include <X11/Xlib.h>
12 #include <gio/gio.h>
13 11
14 #include "base/command_line.h" 12 #include "base/command_line.h"
15 #include "base/debug/leak_annotations.h" 13 #include "base/debug/leak_annotations.h"
16 #include "base/environment.h" 14 #include "base/environment.h"
17 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
18 #include "base/logging.h" 16 #include "base/logging.h"
19 #include "base/nix/mime_util_xdg.h" 17 #include "base/nix/mime_util_xdg.h"
20 #include "base/nix/xdg_util.h" 18 #include "base/nix/xdg_util.h"
21 #include "base/stl_util.h" 19 #include "base/stl_util.h"
22 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
(...skipping 22 matching lines...) Expand all
45 #include "third_party/skia/include/core/SkColor.h" 43 #include "third_party/skia/include/core/SkColor.h"
46 #include "third_party/skia/include/core/SkShader.h" 44 #include "third_party/skia/include/core/SkShader.h"
47 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
48 #include "ui/gfx/canvas.h" 46 #include "ui/gfx/canvas.h"
49 #include "ui/gfx/display.h" 47 #include "ui/gfx/display.h"
50 #include "ui/gfx/geometry/rect.h" 48 #include "ui/gfx/geometry/rect.h"
51 #include "ui/gfx/geometry/size.h" 49 #include "ui/gfx/geometry/size.h"
52 #include "ui/gfx/image/image.h" 50 #include "ui/gfx/image/image.h"
53 #include "ui/gfx/skbitmap_operations.h" 51 #include "ui/gfx/skbitmap_operations.h"
54 #include "ui/gfx/skia_util.h" 52 #include "ui/gfx/skia_util.h"
55 #include "ui/gfx/x/x11_types.h" 53 #include "ui/gfx/x/x11_types.h"
stapelberg 2015/08/07 10:38:22 You might be able to remove the x11_types.h includ
Michael Moss 2015/08/07 16:45:40 Done.
56 #include "ui/native_theme/native_theme.h" 54 #include "ui/native_theme/native_theme.h"
57 #include "ui/resources/grit/ui_resources.h" 55 #include "ui/resources/grit/ui_resources.h"
58 #include "ui/views/controls/button/label_button.h" 56 #include "ui/views/controls/button/label_button.h"
59 #include "ui/views/controls/button/label_button_border.h" 57 #include "ui/views/controls/button/label_button_border.h"
60 #include "ui/views/linux_ui/window_button_order_observer.h" 58 #include "ui/views/linux_ui/window_button_order_observer.h"
61 #include "ui/views/resources/grit/views_resources.h" 59 #include "ui/views/resources/grit/views_resources.h"
62 60
63 #if defined(USE_GCONF) 61 #if defined(USE_GCONF)
64 #include "chrome/browser/ui/libgtk2ui/gconf_listener.h" 62 #include "chrome/browser/ui/libgtk2ui/gconf_listener.h"
65 #endif 63 #endif
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; 375 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
378 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; 376 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
379 } 377 }
380 378
381 g_free(hint_style); 379 g_free(hint_style);
382 g_free(rgba); 380 g_free(rgba);
383 381
384 return params; 382 return params;
385 } 383 }
386 384
387 double GetBaseDPI() { 385 double GetDPI() {
388 XDisplay* xdisplay = gfx::GetXDisplay();
389 int xscreen = DefaultScreen(xdisplay);
390 return (DisplayHeight(xdisplay, xscreen) * 25.4) /
391 DisplayHeightMM(xdisplay, xscreen);
392 }
393
394 double GetFontDPI() {
395 GtkSettings* gtk_settings = gtk_settings_get_default(); 386 GtkSettings* gtk_settings = gtk_settings_get_default();
396 CHECK(gtk_settings); 387 CHECK(gtk_settings);
397 gint gtk_dpi = -1; 388 gint gtk_dpi = -1;
398 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL); 389 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL);
399 390
400 // GTK multiplies the DPI by 1024 before storing it. 391 // GTK multiplies the DPI by 1024 before storing it.
401 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : GetBaseDPI(); 392 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0;
402 } 393 }
403 394
404 // Queries GTK for its font DPI setting and returns the number of pixels in a 395 // Queries GTK for its font DPI setting and returns the number of pixels in a
405 // point. 396 // point.
406 double GetPixelsInPoint(float device_scale_factor) { 397 double GetPixelsInPoint(float device_scale_factor) {
407 double dpi = GetFontDPI(); 398 double dpi = GetDPI();
408 399
409 // Take device_scale_factor into account — if Chrome already scales the 400 // Take device_scale_factor into account — if Chrome already scales the
410 // entire UI up by 2x, we should not also scale up. 401 // entire UI up by 2x, we should not also scale up.
411 dpi /= device_scale_factor; 402 dpi /= device_scale_factor;
412 403
413 // There are 72 points in an inch. 404 // There are 72 points in an inch.
414 return dpi / 72.0; 405 return dpi / 72.0;
415 } 406 }
416 407
417 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 408 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
418 scoped_ptr<base::Environment> env(base::Environment::Create()); 409 scoped_ptr<base::Environment> env(base::Environment::Create());
419 switch (base::nix::GetDesktopEnvironment(env.get())) { 410 switch (base::nix::GetDesktopEnvironment(env.get())) {
420 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 411 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
421 // Starting with KDE 4.4, windows' titlebars can be dragged with the 412 // Starting with KDE 4.4, windows' titlebars can be dragged with the
422 // middle mouse button to create tab groups. We don't support that in 413 // middle mouse button to create tab groups. We don't support that in
423 // Chrome, but at least avoid lowering windows in response to middle 414 // Chrome, but at least avoid lowering windows in response to middle
424 // clicks to avoid surprising users who expect the KDE behavior. 415 // clicks to avoid surprising users who expect the KDE behavior.
425 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; 416 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE;
426 default: 417 default:
427 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; 418 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER;
428 } 419 }
429 } 420 }
430 421
431 double GetGnomeTextScalingFactor() {
432 const char kDesktopInterfaceSchema[] = "org.gnome.desktop.interface";
433 for (const gchar* const* schemas = g_settings_list_schemas(); *schemas;
434 schemas++) {
435 if (!strcmp(kDesktopInterfaceSchema, static_cast<const char*>(*schemas))) {
436 GSettings* settings = g_settings_new(kDesktopInterfaceSchema);
437 double scale = g_settings_get_double(settings, "text-scaling-factor");
438 g_object_unref(settings);
439 return scale;
440 }
441 }
442 // Fallback if the schema does not exist.
443 return GetFontDPI() / GetBaseDPI();
444 }
445
446 } // namespace 422 } // namespace
447 423
448 Gtk2UI::Gtk2UI() 424 Gtk2UI::Gtk2UI()
449 : default_font_size_pixels_(0), 425 : default_font_size_pixels_(0),
450 default_font_style_(gfx::Font::NORMAL), 426 default_font_style_(gfx::Font::NORMAL),
451 middle_click_action_(GetDefaultMiddleClickAction()), 427 middle_click_action_(GetDefaultMiddleClickAction()),
452 device_scale_factor_(1.0) { 428 device_scale_factor_(1.0) {
453 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); 429 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
454 } 430 }
455 431
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 1431
1456 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { 1432 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
1457 device_scale_factor_ = device_scale_factor; 1433 device_scale_factor_ = device_scale_factor;
1458 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); 1434 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
1459 UpdateDefaultFont(label_style->font_desc); 1435 UpdateDefaultFont(label_style->font_desc);
1460 } 1436 }
1461 1437
1462 float Gtk2UI::GetDeviceScaleFactor() const { 1438 float Gtk2UI::GetDeviceScaleFactor() const {
1463 if (gfx::Display::HasForceDeviceScaleFactor()) 1439 if (gfx::Display::HasForceDeviceScaleFactor())
1464 return gfx::Display::GetForcedDeviceScaleFactor(); 1440 return gfx::Display::GetForcedDeviceScaleFactor();
1465 // Linux chrome does not support dynamnic scale factor change. Use the 1441 const int kCSSDefaultDPI = 96;
1466 // value obtanied during startup. The value is rounded to 1 decimal, e.g. 1442 float scale = GetDPI() / kCSSDefaultDPI;
1467 // to 1.4, for safety. 1443 // Round to 2 decimals, e.g. to 1.33.
1468 static float device_scale_factor = 1444 return roundf(scale * 100) / 100;
stapelberg 2015/08/07 10:38:22 I think we should keep the rounding to 1 decimal,
Michael Moss 2015/08/07 16:45:40 Done.
1469 roundf(GetGnomeTextScalingFactor() * 10) / 10;
1470 return device_scale_factor;
1471 } 1445 }
1472 1446
1473 } // namespace libgtk2ui 1447 } // namespace libgtk2ui
1474 1448
1475 views::LinuxUI* BuildGtk2UI() { 1449 views::LinuxUI* BuildGtk2UI() {
1476 return new libgtk2ui::Gtk2UI; 1450 return new libgtk2ui::Gtk2UI;
1477 } 1451 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/BUILD.gn ('k') | chrome/browser/ui/libgtk2ui/libgtk2ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698