Commit 4d538b1b authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Make button fonts NORMAL weight on macOS 10.11 and 10.9.

Apple doesn't ship a MEDIUM weight font in 10.11 or 10.9. The font
system will upgrade it to BOLD (this is covered by tests in
platform_font_mac_unittests.mm). BOLD is too bold for buttons in UI,
so use a NORMAL weight.

Bug: 751414
Change-Id: I5dbac5a165120c919a92476f9fce6747c7e733c1
Reviewed-on: https://chromium-review.googlesource.com/597511
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491955}
parent 891cdcc6
...@@ -98,7 +98,7 @@ const gfx::FontList& HarmonyTypographyProvider::GetFont(int context, ...@@ -98,7 +98,7 @@ const gfx::FontList& HarmonyTypographyProvider::GetFont(int context,
switch (context) { switch (context) {
case views::style::CONTEXT_BUTTON_MD: case views::style::CONTEXT_BUTTON_MD:
font_weight = WeightNotLighterThanNormal(gfx::Font::Weight::MEDIUM); font_weight = MediumWeightForUI();
break; break;
case views::style::CONTEXT_DIALOG_TITLE: case views::style::CONTEXT_DIALOG_TITLE:
size_delta = kTitleSize - gfx::PlatformFont::kDefaultBaseFontSize; size_delta = kTitleSize - gfx::PlatformFont::kDefaultBaseFontSize;
......
...@@ -5,11 +5,16 @@ ...@@ -5,11 +5,16 @@
#include "ui/views/style/typography_provider.h" #include "ui/views/style/typography_provider.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h"
#include "ui/base/default_style.h" #include "ui/base/default_style.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#endif
using gfx::Font; using gfx::Font;
namespace views { namespace views {
...@@ -30,13 +35,27 @@ Font::Weight GetValueBolderThan(Font::Weight weight) { ...@@ -30,13 +35,27 @@ Font::Weight GetValueBolderThan(Font::Weight weight) {
} // namespace } // namespace
// static // static
Font::Weight TypographyProvider::WeightNotLighterThanNormal( Font::Weight TypographyProvider::MediumWeightForUI() {
Font::Weight weight) { #if defined(OS_MACOSX)
// System fonts are not user-configurable on Mac, so there's a simpler check.
// However, 10.9 and 10.11 do not ship with a MEDIUM weight system font. In
// that case, trying to use MEDIUM there will give a bold font, which will
// look worse with the surrounding NORMAL text than just using NORMAL.
return (base::mac::IsOS10_9() || base::mac::IsOS10_11())
? Font::Weight::NORMAL
: Font::Weight::MEDIUM;
#else
// NORMAL may already have at least MEDIUM weight. Return NORMAL in that case
// since trying to return MEDIUM would actually make the font lighter-weight
// than the surrounding text. For example, Windows can be configured to use a
// BOLD font for dialog text; deriving MEDIUM from that would replace the BOLD
// attribute with something lighter.
if (ResourceBundle::GetSharedInstance() if (ResourceBundle::GetSharedInstance()
.GetFontListWithDelta(0, Font::NORMAL, Font::Weight::NORMAL) .GetFontListWithDelta(0, Font::NORMAL, Font::Weight::NORMAL)
.GetFontWeight() < weight) .GetFontWeight() < Font::Weight::MEDIUM)
return weight; return Font::Weight::MEDIUM;
return Font::Weight::NORMAL; return Font::Weight::NORMAL;
#endif
} }
const gfx::FontList& DefaultTypographyProvider::GetFont(int context, const gfx::FontList& DefaultTypographyProvider::GetFont(int context,
...@@ -90,7 +109,7 @@ void DefaultTypographyProvider::GetDefaultFont(int context, ...@@ -90,7 +109,7 @@ void DefaultTypographyProvider::GetDefaultFont(int context,
switch (context) { switch (context) {
case style::CONTEXT_BUTTON_MD: case style::CONTEXT_BUTTON_MD:
*size_delta = ui::kLabelFontSizeDelta; *size_delta = ui::kLabelFontSizeDelta;
*font_weight = WeightNotLighterThanNormal(Font::Weight::MEDIUM); *font_weight = MediumWeightForUI();
break; break;
case style::CONTEXT_DIALOG_TITLE: case style::CONTEXT_DIALOG_TITLE:
*size_delta = ui::kTitleFontSizeDelta; *size_delta = ui::kTitleFontSizeDelta;
......
...@@ -37,13 +37,12 @@ class VIEWS_EXPORT TypographyProvider { ...@@ -37,13 +37,12 @@ class VIEWS_EXPORT TypographyProvider {
// Gets the line spacing, or 0 if it should be provided by gfx::FontList. // Gets the line spacing, or 0 if it should be provided by gfx::FontList.
virtual int GetLineHeight(int context, int style) const = 0; virtual int GetLineHeight(int context, int style) const = 0;
// The system may indicate a "bold" UI font is preferred (e.g. by selecting // Returns the weight that will result in the ResourceBundle returning an
// the "Bold" checkbox in Windows under "Change only the text size" in // appropriate "medium" weight for UI. This caters for systems that are known
// Control Panel). In this case, a user's gfx::Weight::NORMAL font will // to be unable to provide a system font with weight other than NORMAL or BOLD
// already be bold, and requesting a MEDIUM font will result in a font that is // and for user configurations where the NORMAL font is already BOLD. In both
// less bold. So this method returns NORMAL, if the NORMAL font is at least as // of these cases, NORMAL is returned instead.
// bold as |weight|. static gfx::Font::Weight MediumWeightForUI();
static gfx::Font::Weight WeightNotLighterThanNormal(gfx::Font::Weight weight);
protected: protected:
TypographyProvider() = default; TypographyProvider() = default;
......
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