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

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

Issue 2683653006: Don't allow font scale to be lower than 1.0 (Closed)
Patch Set: rebase 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // GTK multiplies the DPI by 1024 before storing it. 367 // GTK multiplies the DPI by 1024 before storing it.
368 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; 368 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI;
369 } 369 }
370 370
371 float GetRawDeviceScaleFactor() { 371 float GetRawDeviceScaleFactor() {
372 if (display::Display::HasForceDeviceScaleFactor()) 372 if (display::Display::HasForceDeviceScaleFactor())
373 return display::Display::GetForcedDeviceScaleFactor(); 373 return display::Display::GetForcedDeviceScaleFactor();
374 return GetDpi() / kDefaultDPI; 374 return GetDpi() / kDefaultDPI;
375 } 375 }
376 376
377 // Returns the font size for the *raw* device scale factor in points.
378 // The |ui_device_scale_factor| is used to cancel the scale to be applied by UI
379 // and to compensate the scale when the device_scale_factor is floored.
380 double GetFontSizePixelsInPoint(float ui_device_scale_factor) {
381 // There are 72 points in an inch.
382 double point = GetDpi() / 72.0;
383
384 // Take device_scale_factor into account — if Chrome already scales the
385 // entire UI up by 2x, we should not also scale up.
386 point /= ui_device_scale_factor;
387
388 // Allow the scale lower than 1.0 only for fonts. Don't always use
389 // the raw value however, because the 1.0~1.3 is rounded to 1.0.
390 float raw_scale = GetRawDeviceScaleFactor();
391 if (raw_scale < 1.0f)
392 return point * raw_scale / ui_device_scale_factor;
393 return point;
394 }
395
396 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 377 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
397 std::unique_ptr<base::Environment> env(base::Environment::Create()); 378 std::unique_ptr<base::Environment> env(base::Environment::Create());
398 switch (base::nix::GetDesktopEnvironment(env.get())) { 379 switch (base::nix::GetDesktopEnvironment(env.get())) {
399 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 380 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
400 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 381 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
401 // Starting with KDE 4.4, windows' titlebars can be dragged with the 382 // Starting with KDE 4.4, windows' titlebars can be dragged with the
402 // middle mouse button to create tab groups. We don't support that in 383 // middle mouse button to create tab groups. We don't support that in
403 // Chrome, but at least avoid lowering windows in response to middle 384 // Chrome, but at least avoid lowering windows in response to middle
404 // clicks to avoid surprising users who expect the KDE behavior. 385 // clicks to avoid surprising users who expect the KDE behavior.
405 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; 386 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE;
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 // If the size is absolute, it's specified in Pango units. There are 1001 // If the size is absolute, it's specified in Pango units. There are
1021 // PANGO_SCALE Pango units in a device unit (pixel). 1002 // PANGO_SCALE Pango units in a device unit (pixel).
1022 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; 1003 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE;
1023 default_font_size_pixels_ = size_pixels; 1004 default_font_size_pixels_ = size_pixels;
1024 query.pixel_size = size_pixels; 1005 query.pixel_size = size_pixels;
1025 } else { 1006 } else {
1026 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). 1007 // Non-absolute sizes are in points (again scaled by PANGO_SIZE).
1027 // Round the value when converting to pixels to match GTK's logic. 1008 // Round the value when converting to pixels to match GTK's logic.
1028 const double size_points = pango_font_description_get_size(desc) / 1009 const double size_points = pango_font_description_get_size(desc) /
1029 static_cast<double>(PANGO_SCALE); 1010 static_cast<double>(PANGO_SCALE);
1030 default_font_size_pixels_ = static_cast<int>( 1011 default_font_size_pixels_ =
1031 GetFontSizePixelsInPoint(GetDeviceScaleFactor()) * size_points); 1012 static_cast<int>(kDefaultDPI / 72.0 * size_points + 0.5);
1032 query.point_size = static_cast<int>(size_points); 1013 query.point_size = static_cast<int>(size_points);
1033 } 1014 }
1034 1015
1035 query.style = gfx::Font::NORMAL; 1016 query.style = gfx::Font::NORMAL;
1036 query.weight = 1017 query.weight =
1037 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); 1018 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc));
1038 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? 1019 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE?
1039 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) 1020 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC)
1040 query.style |= gfx::Font::ITALIC; 1021 query.style |= gfx::Font::ITALIC;
1041 1022
1042 default_font_render_params_ = 1023 default_font_render_params_ =
(...skipping 19 matching lines...) Expand all
1062 1043
1063 float Gtk2UI::GetDeviceScaleFactor() const { 1044 float Gtk2UI::GetDeviceScaleFactor() const {
1064 return device_scale_factor_; 1045 return device_scale_factor_;
1065 } 1046 }
1066 1047
1067 } // namespace libgtkui 1048 } // namespace libgtkui
1068 1049
1069 views::LinuxUI* BuildGtk2UI() { 1050 views::LinuxUI* BuildGtk2UI() {
1070 return new libgtkui::Gtk2UI; 1051 return new libgtkui::Gtk2UI;
1071 } 1052 }
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