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

Side by Side Diff: chrome/browser/ui/libgtkui/gtk_ui.cc

Issue 2680933007: Don't allow font scale to be lower than 1.0 (Closed)
Patch Set: Don't allow font scale to be lower than 1.0 Created 3 years, 10 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 | « no previous file | no next file » | 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/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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // GTK multiplies the DPI by 1024 before storing it. 368 // GTK multiplies the DPI by 1024 before storing it.
369 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; 369 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI;
370 } 370 }
371 371
372 float GetRawDeviceScaleFactor() { 372 float GetRawDeviceScaleFactor() {
373 if (display::Display::HasForceDeviceScaleFactor()) 373 if (display::Display::HasForceDeviceScaleFactor())
374 return display::Display::GetForcedDeviceScaleFactor(); 374 return display::Display::GetForcedDeviceScaleFactor();
375 return GetDpi() / kDefaultDPI; 375 return GetDpi() / kDefaultDPI;
376 } 376 }
377 377
378 // Returns the font size for the *raw* device scale factor in points.
379 // The |ui_device_scale_factor| is used to cancel the scale to be applied by UI
380 // and to compensate the scale when the device_scale_factor is floored.
381 double GetFontSizePixelsInPoint(float ui_device_scale_factor) {
382 // There are 72 points in an inch.
383 double point = GetDpi() / 72.0;
384
385 // Take device_scale_factor into account — if Chrome already scales the
386 // entire UI up by 2x, we should not also scale up.
387 point /= ui_device_scale_factor;
388
389 // Allow the scale lower than 1.0 only for fonts. Don't always use
390 // the raw value however, because the 1.0~1.3 is rounded to 1.0.
391 float raw_scale = GetRawDeviceScaleFactor();
392 if (raw_scale < 1.0f)
393 return point * raw_scale / ui_device_scale_factor;
394 return point;
395 }
396
397 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 378 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
398 std::unique_ptr<base::Environment> env(base::Environment::Create()); 379 std::unique_ptr<base::Environment> env(base::Environment::Create());
399 switch (base::nix::GetDesktopEnvironment(env.get())) { 380 switch (base::nix::GetDesktopEnvironment(env.get())) {
400 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 381 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
401 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 382 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
402 // Starting with KDE 4.4, windows' titlebars can be dragged with the 383 // Starting with KDE 4.4, windows' titlebars can be dragged with the
403 // middle mouse button to create tab groups. We don't support that in 384 // middle mouse button to create tab groups. We don't support that in
404 // Chrome, but at least avoid lowering windows in response to middle 385 // Chrome, but at least avoid lowering windows in response to middle
405 // clicks to avoid surprising users who expect the KDE behavior. 386 // clicks to avoid surprising users who expect the KDE behavior.
406 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; 387 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE;
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // If the size is absolute, it's specified in Pango units. There are 972 // If the size is absolute, it's specified in Pango units. There are
992 // PANGO_SCALE Pango units in a device unit (pixel). 973 // PANGO_SCALE Pango units in a device unit (pixel).
993 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; 974 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE;
994 default_font_size_pixels_ = size_pixels; 975 default_font_size_pixels_ = size_pixels;
995 query.pixel_size = size_pixels; 976 query.pixel_size = size_pixels;
996 } else { 977 } else {
997 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). 978 // Non-absolute sizes are in points (again scaled by PANGO_SIZE).
998 // Round the value when converting to pixels to match GTK's logic. 979 // Round the value when converting to pixels to match GTK's logic.
999 const double size_points = pango_font_description_get_size(desc) / 980 const double size_points = pango_font_description_get_size(desc) /
1000 static_cast<double>(PANGO_SCALE); 981 static_cast<double>(PANGO_SCALE);
1001 default_font_size_pixels_ = static_cast<int>( 982 default_font_size_pixels_ =
1002 GetFontSizePixelsInPoint(GetDeviceScaleFactor()) * size_points); 983 static_cast<int>(kDefaultDPI / 72.0 * size_points + 0.5);
1003 query.point_size = static_cast<int>(size_points); 984 query.point_size = static_cast<int>(size_points);
1004 } 985 }
1005 986
1006 query.style = gfx::Font::NORMAL; 987 query.style = gfx::Font::NORMAL;
1007 query.weight = 988 query.weight =
1008 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); 989 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc));
1009 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? 990 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE?
1010 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) 991 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC)
1011 query.style |= gfx::Font::ITALIC; 992 query.style |= gfx::Font::ITALIC;
1012 993
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1032
1052 float GtkUi::GetDeviceScaleFactor() const { 1033 float GtkUi::GetDeviceScaleFactor() const {
1053 return device_scale_factor_; 1034 return device_scale_factor_;
1054 } 1035 }
1055 1036
1056 } // namespace libgtkui 1037 } // namespace libgtkui
1057 1038
1058 views::LinuxUI* BuildGtkUi() { 1039 views::LinuxUI* BuildGtkUi() {
1059 return new libgtkui::GtkUi; 1040 return new libgtkui::GtkUi;
1060 } 1041 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698