Chromium Code Reviews| 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> | 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> | |
| 11 | 12 |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/debug/leak_annotations.h" | 14 #include "base/debug/leak_annotations.h" |
| 14 #include "base/environment.h" | 15 #include "base/environment.h" |
| 15 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/nix/mime_util_xdg.h" | 18 #include "base/nix/mime_util_xdg.h" |
| 18 #include "base/nix/xdg_util.h" | 19 #include "base/nix/xdg_util.h" |
| 19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 42 #include "third_party/skia/include/core/SkCanvas.h" | 43 #include "third_party/skia/include/core/SkCanvas.h" |
| 43 #include "third_party/skia/include/core/SkColor.h" | 44 #include "third_party/skia/include/core/SkColor.h" |
| 44 #include "third_party/skia/include/core/SkShader.h" | 45 #include "third_party/skia/include/core/SkShader.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
| 46 #include "ui/gfx/canvas.h" | 47 #include "ui/gfx/canvas.h" |
| 47 #include "ui/gfx/geometry/rect.h" | 48 #include "ui/gfx/geometry/rect.h" |
| 48 #include "ui/gfx/geometry/size.h" | 49 #include "ui/gfx/geometry/size.h" |
| 49 #include "ui/gfx/image/image.h" | 50 #include "ui/gfx/image/image.h" |
| 50 #include "ui/gfx/skbitmap_operations.h" | 51 #include "ui/gfx/skbitmap_operations.h" |
| 51 #include "ui/gfx/skia_util.h" | 52 #include "ui/gfx/skia_util.h" |
| 53 #include "ui/gfx/x/x11_types.h" | |
| 52 #include "ui/resources/grit/ui_resources.h" | 54 #include "ui/resources/grit/ui_resources.h" |
| 53 #include "ui/views/controls/button/label_button.h" | 55 #include "ui/views/controls/button/label_button.h" |
| 54 #include "ui/views/controls/button/label_button_border.h" | 56 #include "ui/views/controls/button/label_button_border.h" |
| 55 #include "ui/views/linux_ui/window_button_order_observer.h" | 57 #include "ui/views/linux_ui/window_button_order_observer.h" |
| 56 | 58 |
| 57 #if defined(USE_GCONF) | 59 #if defined(USE_GCONF) |
| 58 #include "chrome/browser/ui/libgtk2ui/gconf_listener.h" | 60 #include "chrome/browser/ui/libgtk2ui/gconf_listener.h" |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 // A minimized port of GtkThemeService into something that can provide colors | 63 // A minimized port of GtkThemeService into something that can provide colors |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; | 373 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; |
| 372 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; | 374 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; |
| 373 } | 375 } |
| 374 | 376 |
| 375 g_free(hint_style); | 377 g_free(hint_style); |
| 376 g_free(rgba); | 378 g_free(rgba); |
| 377 | 379 |
| 378 return params; | 380 return params; |
| 379 } | 381 } |
| 380 | 382 |
| 381 double GetDPI() { | 383 double GetBaseDPI() { |
| 384 XDisplay* xdisplay = gfx::GetXDisplay(); | |
| 385 int xscreen = DefaultScreen(xdisplay); | |
| 386 return (DisplayHeight(xdisplay, xscreen) * 25.4) / | |
| 387 DisplayHeightMM(xdisplay, xscreen); | |
| 388 } | |
| 389 | |
| 390 double GetFontDPI() { | |
| 382 GtkSettings* gtk_settings = gtk_settings_get_default(); | 391 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 383 CHECK(gtk_settings); | 392 CHECK(gtk_settings); |
| 384 gint gtk_dpi = -1; | 393 gint gtk_dpi = -1; |
| 385 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); | 394 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); |
| 386 | 395 |
| 387 // GTK multiplies the DPI by 1024 before storing it. | 396 // GTK multiplies the DPI by 1024 before storing it. |
| 388 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; | 397 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : GetBaseDPI(); |
| 389 } | 398 } |
| 390 | 399 |
| 391 // Queries GTK for its font DPI setting and returns the number of pixels in a | 400 // Queries GTK for its font DPI setting and returns the number of pixels in a |
| 392 // point. | 401 // point. |
| 393 double GetPixelsInPoint(float device_scale_factor) { | 402 double GetPixelsInPoint(float device_scale_factor) { |
| 394 double dpi = GetDPI(); | 403 double dpi = GetFontDPI(); |
| 395 | 404 |
| 396 // Take device_scale_factor into account — if Chrome already scales the | 405 // Take device_scale_factor into account — if Chrome already scales the |
| 397 // entire UI up by 2x, we should not also scale up. | 406 // entire UI up by 2x, we should not also scale up. |
| 398 dpi /= device_scale_factor; | 407 dpi /= device_scale_factor; |
| 399 | 408 |
| 400 // There are 72 points in an inch. | 409 // There are 72 points in an inch. |
| 401 return dpi / 72.0; | 410 return dpi / 72.0; |
| 402 } | 411 } |
| 403 | 412 |
| 404 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { | 413 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1417 NativeThemeGtk2::instance()->NotifyObservers(); | 1426 NativeThemeGtk2::instance()->NotifyObservers(); |
| 1418 } | 1427 } |
| 1419 | 1428 |
| 1420 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { | 1429 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { |
| 1421 device_scale_factor_ = device_scale_factor; | 1430 device_scale_factor_ = device_scale_factor; |
| 1422 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 1431 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
| 1423 UpdateDefaultFont(label_style->font_desc); | 1432 UpdateDefaultFont(label_style->font_desc); |
| 1424 } | 1433 } |
| 1425 | 1434 |
| 1426 float Gtk2UI::GetDeviceScaleFactor() const { | 1435 float Gtk2UI::GetDeviceScaleFactor() const { |
| 1427 const int kCSSDefaultDPI = 96; | 1436 float scale = GetFontDPI() / GetBaseDPI(); |
| 1428 float scale = GetDPI() / kCSSDefaultDPI; | 1437 // Round to 1 decimals, e.g. to 1.4. |
|
Evan Stade
2015/05/14 22:43:04
nit: 1 decimal
oshima
2015/05/14 22:45:12
Done.
| |
| 1429 // Round to 2 decimals, e.g. to 1.33. | 1438 return roundf(scale * 10) / 10; |
| 1430 return roundf(scale * 100) / 100; | |
| 1431 } | 1439 } |
| 1432 | 1440 |
| 1433 } // namespace libgtk2ui | 1441 } // namespace libgtk2ui |
| 1434 | 1442 |
| 1435 views::LinuxUI* BuildGtk2UI() { | 1443 views::LinuxUI* BuildGtk2UI() { |
| 1436 return new libgtk2ui::Gtk2UI; | 1444 return new libgtk2ui::Gtk2UI; |
| 1437 } | 1445 } |
| OLD | NEW |