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/libgtkui/gtk_ui.h" | 5 #include "chrome/browser/ui/libgtkui/gtk_ui.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
| 9 #include <X11/Xcursor/Xcursor.h> | 9 #include <X11/Xcursor/Xcursor.h> |
| 10 | 10 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 // GTK multiplies the DPI by 1024 before storing it. | 357 // GTK multiplies the DPI by 1024 before storing it. |
| 358 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; | 358 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; |
| 359 } | 359 } |
| 360 | 360 |
| 361 float GetRawDeviceScaleFactor() { | 361 float GetRawDeviceScaleFactor() { |
| 362 if (display::Display::HasForceDeviceScaleFactor()) | 362 if (display::Display::HasForceDeviceScaleFactor()) |
| 363 return display::Display::GetForcedDeviceScaleFactor(); | 363 return display::Display::GetForcedDeviceScaleFactor(); |
| 364 return GetDpi() / kDefaultDPI; | 364 return GetDpi() / kDefaultDPI; |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Returns the font size for the *raw* device scale factor in points. | |
| 368 // The |ui_device_scale_factor| is used to cancel the scale to be applied by UI | |
| 369 // and to compensate the scale when the device_scale_factor is floored. | |
| 370 double GetFontSizePixelsInPoint(float ui_device_scale_factor) { | |
| 371 // There are 72 points in an inch. | |
| 372 double point = GetDpi() / 72.0; | |
| 373 | |
| 374 // Take device_scale_factor into account — if Chrome already scales the | |
| 375 // entire UI up by 2x, we should not also scale up. | |
| 376 point /= ui_device_scale_factor; | |
| 377 | |
| 378 // Allow the scale lower than 1.0 only for fonts. Don't always use | |
| 379 // the raw value however, because the 1.0~1.3 is rounded to 1.0. | |
| 380 float raw_scale = GetRawDeviceScaleFactor(); | |
| 381 if (raw_scale < 1.0f) | |
| 382 return point * raw_scale / ui_device_scale_factor; | |
| 383 return point; | |
| 384 } | |
| 385 | |
| 386 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { | 367 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { |
| 387 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 368 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 388 switch (base::nix::GetDesktopEnvironment(env.get())) { | 369 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 389 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 370 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
| 390 case base::nix::DESKTOP_ENVIRONMENT_KDE5: | 371 case base::nix::DESKTOP_ENVIRONMENT_KDE5: |
| 391 // Starting with KDE 4.4, windows' titlebars can be dragged with the | 372 // Starting with KDE 4.4, windows' titlebars can be dragged with the |
| 392 // middle mouse button to create tab groups. We don't support that in | 373 // middle mouse button to create tab groups. We don't support that in |
| 393 // Chrome, but at least avoid lowering windows in response to middle | 374 // Chrome, but at least avoid lowering windows in response to middle |
| 394 // clicks to avoid surprising users who expect the KDE behavior. | 375 // clicks to avoid surprising users who expect the KDE behavior. |
| 395 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; | 376 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 // If the size is absolute, it's specified in Pango units. There are | 964 // If the size is absolute, it's specified in Pango units. There are |
| 984 // PANGO_SCALE Pango units in a device unit (pixel). | 965 // PANGO_SCALE Pango units in a device unit (pixel). |
| 985 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; | 966 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; |
| 986 default_font_size_pixels_ = size_pixels; | 967 default_font_size_pixels_ = size_pixels; |
| 987 query.pixel_size = size_pixels; | 968 query.pixel_size = size_pixels; |
| 988 } else { | 969 } else { |
| 989 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). | 970 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). |
| 990 // Round the value when converting to pixels to match GTK's logic. | 971 // Round the value when converting to pixels to match GTK's logic. |
| 991 const double size_points = pango_font_description_get_size(desc) / | 972 const double size_points = pango_font_description_get_size(desc) / |
| 992 static_cast<double>(PANGO_SCALE); | 973 static_cast<double>(PANGO_SCALE); |
| 993 default_font_size_pixels_ = static_cast<int>( | 974 default_font_size_pixels_ = |
| 994 GetFontSizePixelsInPoint(GetDeviceScaleFactor()) * size_points); | 975 static_cast<int>(kDefaultDPI / 72.0 * size_points + 0.5); |
|
oshima
2017/02/08 21:15:31
+ 0.5 was a regression in original CL
| |
| 995 query.point_size = static_cast<int>(size_points); | 976 query.point_size = static_cast<int>(size_points); |
| 996 } | 977 } |
| 997 | 978 |
| 998 query.style = gfx::Font::NORMAL; | 979 query.style = gfx::Font::NORMAL; |
| 999 query.weight = | 980 query.weight = |
| 1000 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); | 981 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); |
| 1001 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? | 982 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? |
| 1002 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) | 983 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) |
| 1003 query.style |= gfx::Font::ITALIC; | 984 query.style |= gfx::Font::ITALIC; |
| 1004 | 985 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1043 | 1024 |
| 1044 float GtkUi::GetDeviceScaleFactor() const { | 1025 float GtkUi::GetDeviceScaleFactor() const { |
| 1045 return device_scale_factor_; | 1026 return device_scale_factor_; |
| 1046 } | 1027 } |
| 1047 | 1028 |
| 1048 } // namespace libgtkui | 1029 } // namespace libgtkui |
| 1049 | 1030 |
| 1050 views::LinuxUI* BuildGtkUi() { | 1031 views::LinuxUI* BuildGtkUi() { |
| 1051 return new libgtkui::GtkUi; | 1032 return new libgtkui::GtkUi; |
| 1052 } | 1033 } |
| OLD | NEW |