Bug 144707 - [Mac] Expose more font weights for -apple-system
Summary: [Mac] Expose more font weights for -apple-system
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Text (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.10
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on: 144786 145008
Blocks:
  Show dependency treegraph
 
Reported: 2015-05-06 13:31 PDT by Jon Lee
Modified: 2015-05-18 15:23 PDT (History)
6 users (show)

See Also:


Attachments
Patch (10.00 KB, patch)
2015-05-06 13:43 PDT, Jon Lee
no flags Details | Formatted Diff | Diff
Patch (23.38 KB, patch)
2015-05-12 19:14 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews105 for mac-mavericks-wk2 (315.81 KB, application/zip)
2015-05-12 19:46 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews100 for mac-mavericks (305.87 KB, application/zip)
2015-05-12 19:57 PDT, Build Bot
no flags Details
Patch (29.66 KB, patch)
2015-05-13 18:14 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (31.22 KB, patch)
2015-05-13 19:23 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (38.37 KB, patch)
2015-05-13 20:51 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (25.72 KB, patch)
2015-05-14 11:01 PDT, Myles C. Maxfield
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Lee 2015-05-06 13:31:39 PDT
Expose more font weights for -apple-system

rdar://problem/20809399
Comment 1 Jon Lee 2015-05-06 13:43:49 PDT
Created attachment 252515 [details]
Patch
Comment 2 Dean Jackson 2015-05-06 13:46:04 PDT
Comment on attachment 252515 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=252515&action=review

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:210
> +        NSFontWeightUltraLight, // Values between ultra-light and thin are swapped

Nit: Missing period at end of comment.
Comment 3 Myles C. Maxfield 2015-05-06 13:49:53 PDT
Comment on attachment 252515 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=252515&action=review

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:232
> +        return [NSFont systemFontOfSize:size weight:toNSFontWeight(weight)];

There's really not a good way to do this with CoreText?
Comment 4 Jon Lee 2015-05-06 15:57:20 PDT
Committed 183895.
https://trac.webkit.org/changeset/183895
Comment 5 Alexey Proskuryakov 2015-05-07 23:26:48 PDT
A number of tests became flaky after this commit. Ac couple examples: fast/text/international/unicode-bidi-plaintext-in-textarea.html and fast/text/updateNewFont.html

https://webkit-test-results.appspot.com/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=fast%2Ftext%2Finternational%2Funicode-bidi-plaintext-in-textarea.html

I'm going to roll out to confirm that this patch was the culprit.
Comment 6 WebKit Commit Bot 2015-05-07 23:29:08 PDT
Re-opened since this is blocked by bug 144786
Comment 7 Alexey Proskuryakov 2015-05-08 09:27:30 PDT
Rollout fixed the flakiness.
Comment 8 Jon Lee 2015-05-11 01:32:58 PDT
Figured out what the sequence was.

fast/css/multiple-tabs.html
fast/text/international/bidi-listbox-atsui.html
fast/text/international/bidi-listbox.html
fast/text/international/bidi-menulist.html
fast/text/international/hindi-spacing.html
fast/text/international/pop-up-button-text-alignment-and-direction.html
fast/text/international/unicode-bidi-plaintext-in-textarea.html
fast/text/updateNewFont.html

Running multiple-tabs.html causes the subsequent tests to fail.
Comment 9 Myles C. Maxfield 2015-05-12 19:14:56 PDT
Created attachment 253007 [details]
Patch
Comment 10 Build Bot 2015-05-12 19:46:13 PDT
Comment on attachment 253007 [details]
Patch

Attachment 253007 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5335025159503872

Number of test failures exceeded the failure limit.
Comment 11 Build Bot 2015-05-12 19:46:16 PDT
Created attachment 253009 [details]
Archive of layout-test-results from ews105 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 12 Build Bot 2015-05-12 19:57:31 PDT
Comment on attachment 253007 [details]
Patch

Attachment 253007 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/5703245590691840

Number of test failures exceeded the failure limit.
Comment 13 Build Bot 2015-05-12 19:57:33 PDT
Created attachment 253011 [details]
Archive of layout-test-results from ews100 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 14 Darin Adler 2015-05-12 21:42:11 PDT
Comment on attachment 253007 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253007&action=review

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:211
> +        NSFontWeightUltraLight, // Values between ultra-light and thin are swapped.

I don’t understand the grammar in the comment. Are you saying that two weights are out of increasing order here?

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:229
> +    if (equalIgnoringASCIICase(family.string(), String("-webkit-system-font", String::ConstructFromLiteral))
> +        || equalIgnoringASCIICase(family.string(), String("-apple-system", String::ConstructFromLiteral))
> +        || equalIgnoringASCIICase(family.string(), String("-apple-system-font", String::ConstructFromLiteral))) {

This is not the way to compare ignoring ASCII case. We should overload. It’s OK to require ASCIILiteral because that’s the way to indicate that something is a literal, but it’s not good to construct and then destroy a String just to do a comparison with a constant.

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:252
> +    return Optional<NSFont*>();

We use Nullopt for this.

> Source/WebCore/platform/mac/ThemeMac.mm:678
> +            fontDescription.setOneFamily(String("-apple-system", String::ConstructFromLiteral));

This should just be ASCIILiteral. Talk to Ben about the tradeoffs, please.

> Source/WebCore/rendering/RenderThemeMac.mm:359
> +            fontName = String("-apple-menu", String::ConstructFromLiteral);

ASCIILiteral please.
Comment 15 Jon Lee 2015-05-13 10:02:10 PDT
Comment on attachment 253007 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253007&action=review

> Source/WebCore/ChangeLog:11
> +        system font is, get that font's family name, and synthesize a font-family CSS propery for the element.

typo: property

>> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:211
>> +        NSFontWeightUltraLight, // Values between ultra-light and thin are swapped.
> 
> I don’t understand the grammar in the comment. Are you saying that two weights are out of increasing order here?

According to the W3C spec a font weight of Thin should be lighter than that of UltraLight, but AppKit's UltraLight is lighter than Thin. The weights as listed are in increasing order, even though semantically it appears two are swapped (I do not know which one is definitively correct).

The comment could be removed.

> Source/WebCore/rendering/RenderThemeMac.mm:382
> +        fontName = String("-apple-system", String::ConstructFromLiteral);

Why not just make this the default when you declare fontName?
Comment 16 Myles C. Maxfield 2015-05-13 18:14:27 PDT
Created attachment 253078 [details]
Patch
Comment 17 Myles C. Maxfield 2015-05-13 18:16:58 PDT
Comment on attachment 253078 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253078&action=review

> LayoutTests/platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt:2
> +caption: normal normal normal 13px/16px -apple-system

I might as well just delete this file
Comment 18 Myles C. Maxfield 2015-05-13 19:23:20 PDT
Created attachment 253085 [details]
Patch
Comment 19 Myles C. Maxfield 2015-05-13 20:51:17 PDT
Created attachment 253091 [details]
Patch
Comment 20 Benjamin Poulain 2015-05-13 21:00:07 PDT
Comment on attachment 253091 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253091&action=review

> Source/WTF/ChangeLog:8
> +        Create an overload for equalIgnoringASCIICase for string literals.

WTF LGTM.

> Source/WTF/wtf/text/WTFString.h:513
> +template<unsigned charactersCount>
> +inline bool equalIgnoringASCIICase(const String& a, const char (&b)[charactersCount]) { return equalIgnoringASCIICase(a.impl(), b); }

I would use
    equalIgnoringASCIICase<charactersCount>(a, b)
or
    equalIgnoringASCIICase(a, b, charactersCount - 1)

to enforce the right substitutions.
Comment 21 Myles C. Maxfield 2015-05-14 11:01:43 PDT
Created attachment 253129 [details]
Patch
Comment 22 Simon Fraser (smfr) 2015-05-14 14:19:04 PDT
Comment on attachment 253129 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253129&action=review

> Source/WebCore/ChangeLog:8
> +        Previously, when we parse a CSS declaration of the form font: keyword; where keyword

parsed

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:221
> +    return nsFontWeights[fontWeight];

Should this assert that fontWeight is in range?
Comment 23 Myles C. Maxfield 2015-05-14 14:29:36 PDT
Comment on attachment 253129 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253129&action=review

> Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm:690
>      // System fonts are hidden by having a name that begins with a period, so simply search

This comment is no longer accurate.
Comment 24 Myles C. Maxfield 2015-05-14 14:30:24 PDT
Committed r184353: <http://trac.webkit.org/changeset/184353>
Comment 25 Darin Adler 2015-05-16 12:07:55 PDT
Comment on attachment 253129 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253129&action=review

>> Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm:690
>>      // System fonts are hidden by having a name that begins with a period, so simply search
> 
> This comment is no longer accurate.

I hope you fixed it!

> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:227
> +    if (equalIgnoringASCIICase(family.string(), "-webkit-system-font")

I think this should be overloaded for AtomicString so we don’t have to do .string() explicitly.

> Source/WebCore/platform/mac/ThemeMac.mm:678
> +            fontDescription.setOneFamily(AtomicString("-apple-system", AtomicString::ConstructFromLiteral));

Please talk to Ben Poulain about this. I don’t think you should be using ConstructFromLiteral at call sites like this one. Maybe Ben can write down some guidelines so we can get this right.

> Source/WebCore/rendering/RenderThemeMac.mm:353
> +    String fontName(ASCIILiteral("-apple-system"));

Local variable should have type ASCIILiteral, not String, to avoid unnecessary extra memory allocation.

Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

> Source/WebCore/rendering/RenderThemeMac.mm:360
> +            fontName = String(ASCIILiteral("-apple-menu"));

Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

> Source/WebCore/rendering/RenderThemeMac.mm:364
> +            fontName = String(ASCIILiteral("-apple-status-bar"));

Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

> Source/WebCore/rendering/RenderThemeMac.mm:830
> +    fontDescription.setOneFamily(String("-apple-system", String::ConstructFromLiteral));

Please talk to Ben Poulain about this. I don’t think you should be using ConstructFromLiteral at call sites like this one. Maybe Ben can write down some guidelines so we can get this right.

Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.
Comment 26 Myles C. Maxfield 2015-05-18 11:27:24 PDT
Comment on attachment 253129 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253129&action=review

>>> Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm:690
>>>      // System fonts are hidden by having a name that begins with a period, so simply search
>> 
>> This comment is no longer accurate.
> 
> I hope you fixed it!

I did before committing.

>> Source/WebCore/platform/graphics/mac/FontCacheMac.mm:227
>> +    if (equalIgnoringASCIICase(family.string(), "-webkit-system-font")
> 
> I think this should be overloaded for AtomicString so we don’t have to do .string() explicitly.

Done.

>> Source/WebCore/platform/mac/ThemeMac.mm:678
>> +            fontDescription.setOneFamily(AtomicString("-apple-system", AtomicString::ConstructFromLiteral));
> 
> Please talk to Ben Poulain about this. I don’t think you should be using ConstructFromLiteral at call sites like this one. Maybe Ben can write down some guidelines so we can get this right.

I did; this is what Ben recommended.

>> Source/WebCore/rendering/RenderThemeMac.mm:353
>> +    String fontName(ASCIILiteral("-apple-system"));
> 
> Local variable should have type ASCIILiteral, not String, to avoid unnecessary extra memory allocation.
> 
> Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

Done.

>> Source/WebCore/rendering/RenderThemeMac.mm:360
>> +            fontName = String(ASCIILiteral("-apple-menu"));
> 
> Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

Done.

>> Source/WebCore/rendering/RenderThemeMac.mm:364
>> +            fontName = String(ASCIILiteral("-apple-status-bar"));
> 
> Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

Done.

>> Source/WebCore/rendering/RenderThemeMac.mm:830
>> +    fontDescription.setOneFamily(String("-apple-system", String::ConstructFromLiteral));
> 
> Please talk to Ben Poulain about this. I don’t think you should be using ConstructFromLiteral at call sites like this one. Maybe Ben can write down some guidelines so we can get this right.
> 
> Wasteful to create a String and then later turn that into an AtomicString. That means we will often be deleting the temporary StringImpl we created because we’ll find the already-existing AtomicStringImpl for this string.

I already fixed this in the version of the patch I committed.
Comment 27 Myles C. Maxfield 2015-05-18 15:23:48 PDT
See https://bugs.webkit.org/show_bug.cgi?id=145146