Commit 2f7c32d8 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Revert "Do clean up in PlatformFontMac"

This reverts commit c2e39ede.

Reason for revert: Breaks Mac builder (https://ci.chromium.org/p/chromium/builders/ci/Mac%20Builder/119092)

Original change's description:
> Do clean up in PlatformFontMac
> 
> Do not try to derive one weight of font from another.
> Use the API to directly generate them.
> 
> PlatformFontMacTest.FontWeightAPIConsistency tested that
> our understanding of shifting weights up and down was
> correct. The code no longer shifts weights up and down
> as that is unreliable and version-specific, so there is
> no need to test weight shifting and it is removed.
> 
> This also fixes Big Sur issues.
> 
> Bug: 1101426
> Change-Id: I2165c3550ad295b3ee7742f3289874ed2bb89c68
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340262
> Commit-Queue: Avi Drissman <avi@chromium.org>
> Auto-Submit: Avi Drissman <avi@chromium.org>
> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#796044}

TBR=ellyjones@chromium.org,avi@chromium.org

Change-Id: I7a7d792d80eadfab524fc7235c3b9a349a34c970
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1101426
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343490Reviewed-by: default avatarDominique Fauteux-Chapleau <domfc@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796059}
parent cfbe56f1
......@@ -8,39 +8,18 @@
#include "base/compiler_specific.h"
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/optional.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/platform_font.h"
namespace gfx {
class GFX_EXPORT PlatformFontMac : public PlatformFont {
class PlatformFontMac : public PlatformFont {
public:
// An enum indicating a type of system-specified font.
// - kGeneral: +[NSFont systemFontOfSize:(weight:)]
// - kMenu: +[NSFont menuFontOfSize:]
// - kToolTip: +[NSFont toolTipsFontOfSize:]
enum class SystemFontType { kGeneral, kMenu, kToolTip };
// Constructs a PlatformFontMac for a system-specified font of
// |system_font_type| type. For a non-system-specified font, use any other
// constructor.
explicit PlatformFontMac(SystemFontType system_font_type);
// Constructs a PlatformFontMac for containing the NSFont* |native_font|. Do
// not call this for a system-specified font; use the |SystemFontType|
// constructor for that. |native_font| must not be null.
PlatformFontMac();
explicit PlatformFontMac(NativeFont native_font);
// Constructs a PlatformFontMac representing the font with name |font_name|
// and the size |font_size|. Do not call this for a system-specified font; use
// the |SystemFontType| constructor for that.
PlatformFontMac(const std::string& font_name,
int font_size);
// Constructs a PlatformFontMac representing the font specified by |typeface|
// and the size |font_size_pixels|. Do not call this for a system-specified
// font; use the |SystemFontType| constructor for that.
PlatformFontMac(sk_sp<SkTypeface> typeface,
int font_size_pixels,
const base::Optional<FontRenderParams>& params);
......@@ -62,44 +41,35 @@ class GFX_EXPORT PlatformFontMac : public PlatformFont {
NativeFont GetNativeFont() const override;
sk_sp<SkTypeface> GetNativeSkTypeface() const override;
// A utility function to get the weight of an NSFont. Used by the unit test.
static Font::Weight GetFontWeightFromNSFontForTesting(NSFont* font);
private:
struct FontSpec {
std::string name; // Corresponds to -[NSFont fontFamily].
int size;
int style;
Font::Weight weight;
};
PlatformFontMac(NativeFont font,
base::Optional<SystemFontType> system_font_type);
PlatformFontMac(const std::string& font_name,
int font_size,
int font_style,
Font::Weight font_weight);
PlatformFontMac(NativeFont font,
base::Optional<SystemFontType> system_font_type,
FontSpec spec);
const std::string& font_name,
int font_size,
int font_style,
Font::Weight font_weight);
~PlatformFontMac() override;
// Calculates and caches the font metrics and initializes |render_params_|.
// Calculates and caches the font metrics and inits |render_params_|.
void CalculateMetricsAndInitRenderParams();
// Returns an autoreleased NSFont created with the passed-in specifications.
NSFont* NSFontWithSpec(FontSpec font_spec) const;
// The NSFont instance for this object. If this object was constructed from an
// NSFont instance, this holds that NSFont instance. Otherwise this NSFont
// instance is constructed from the name, size, and style. If there is no
// active font that matched those criteria a default font is used.
base::scoped_nsobject<NSFont> native_font_;
// If the font is a system font, and if so, what kind.
const base::Optional<SystemFontType> system_font_type_;
// The name/size/style/weight quartet that specify the font. Initialized in
// the constructors.
const FontSpec font_spec_;
// The name/size/style trio that specify the font. Initialized in the
// constructors.
const std::string font_name_; // Corresponds to -[NSFont fontFamily].
const int font_size_;
const int font_style_;
const Font::Weight font_weight_;
// Cached metrics, generated in CalculateMetrics().
int height_;
......
This diff is collapsed.
This diff is collapsed.
......@@ -10,7 +10,6 @@
#include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/gfx/font_list.h"
#import "ui/gfx/mac/coordinate_conversion.h"
#include "ui/gfx/platform_font_mac.h"
namespace {
......@@ -33,10 +32,8 @@ int TooltipManagerMac::GetMaxWidth(const gfx::Point& location) const {
}
const gfx::FontList& TooltipManagerMac::GetFontList() const {
static base::NoDestructor<gfx::FontList> font_list([]() {
return gfx::Font(new gfx::PlatformFontMac(
gfx::PlatformFontMac::SystemFontType::kToolTip));
}());
static base::NoDestructor<gfx::FontList> font_list(
[]() { return gfx::Font([NSFont toolTipsFontOfSize:0]); }());
return *font_list;
}
......
......@@ -7,7 +7,6 @@
#import <AppKit/AppKit.h>
#include "base/mac/mac_util.h"
#include "ui/gfx/platform_font_mac.h"
namespace {
......@@ -43,8 +42,7 @@ void InitMaterialMenuConfig(views::MenuConfig* config) {
namespace views {
void MenuConfig::Init() {
font_list = gfx::FontList(gfx::Font(
new gfx::PlatformFontMac(gfx::PlatformFontMac::SystemFontType::kMenu)));
font_list = gfx::FontList(gfx::Font([NSFont menuFontOfSize:0.0]));
check_selected_combobox_item = true;
arrow_key_selection_wraps = false;
use_mnemonics = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment