Title: [184353] trunk
Revision
184353
Author
mmaxfi...@apple.com
Date
2015-05-14 14:28:54 -0700 (Thu, 14 May 2015)

Log Message

[Mac] Expose more font weights for -apple-system
https://bugs.webkit.org/show_bug.cgi?id=144707

Reviewed by Simon Fraser.

Source/WebCore:

Previously, when we parsed a CSS declaration of the form font: keyword; where keyword
is one of caption, icon, menu, message-box, small-caption, -webkit-mini-control, -webkit-small-control,
or -webkit-control (which html.css does for form controls), we would ask the system what the appropriate
system font is, get that font's family name, and synthesize a font-family CSS property for the element.
Then, later when we actually go to look up the font, we would look up the font by family name using this
information. However, this round-tripping of a font through a family name is actually lossy, and is not
guaranteed to preserve system-font-ness (which we use for various things including metrics calculations).

This patch modifies this logic to specify a token family name instead, which the font lookup code special
cases (and reacts by making the appropriate system-font lookup call). This approach is currently how iOS
handles these system fonts; this patch simply brings this approach to OS X.

There is also an added progression here. We used to simply call [NSFont fontWithName:size:] on the system
font family name (which the parser found for us) which entirely disregards weight. This means that we
used to be getting synthesized bold in form controls which ask for a heavy weight. Migrating to this
system-font aware call means that we get the real bold font instead of synthesized bold.

Once this system-font-ness is guaranteed to be preserved between parsing time and font lookup time, we
can safely migrate to using [NSFont systemFontOfSize:weight] instead of [NSFont systemFontOfSize:] on
platforms which support it.

Tests: fast/text/systemFont.html
       fast/css/css2-system-fonts.html
       fast/forms/select/optgroup-rendering.html
       fast/forms/validation-message-appearance.html

* css/CSSParser.cpp:
(WebCore::CSSParser::parseSystemFont): Add a comment regarding why we are bothering with expanding out
the font property in the first place.
* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::FontCascade::primaryFontIsSystemFont): Update to use new system font tokens.
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::toNSFontWeight): New static method to map font weights to NSFontWeight constants available on
Yosemite and later.
(WebCore::fontWithFamilySpecialCase): Pull all these special-case font token name handling into a
separate function, which returns an Optional.
(WebCore::fontWithFamily):
* platform/mac/ThemeMac.mm:
(WebCore::ThemeMac::controlFont): Use the font token name instead of the generated system font family
name.
* platform/spi/mac/NSFontSPI.h: Add [NSFont systemFontWithSize:weight:] and the proper NSFontWeight
constants.
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::updateCachedSystemFontDescription): Use the font token names instead of the
generated system font family name.
(WebCore::RenderThemeMac::setFontFromControlSize): Ditto.

LayoutTests:

* platform/mac/fast/text/systemFont-expected.txt: Update expectations.
* platform/mac/fast/text/systemFont.html: Update test to include font weights for -apple-system.
* platform/mac/fast/css/css2-system-fonts-expected.txt: Updated to not hardcode the system font family name.
* platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt: Ditto.
* platform/mac/fast/forms/select/optgroup-rendering-expected.txt: Updated to not use synthetic bold.
* platform/mac/fast/forms/validation-message-appearance-expected.txt: Ditto.

Modified Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (184352 => 184353)


--- trunk/LayoutTests/ChangeLog	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/ChangeLog	2015-05-14 21:28:54 UTC (rev 184353)
@@ -1,3 +1,17 @@
+2015-05-14  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Mac] Expose more font weights for -apple-system
+        https://bugs.webkit.org/show_bug.cgi?id=144707
+
+        Reviewed by Simon Fraser.
+
+        * platform/mac/fast/text/systemFont-expected.txt: Update expectations.
+        * platform/mac/fast/text/systemFont.html: Update test to include font weights for -apple-system.
+        * platform/mac/fast/css/css2-system-fonts-expected.txt: Updated to not hardcode the system font family name.
+        * platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt: Ditto.
+        * platform/mac/fast/forms/select/optgroup-rendering-expected.txt: Updated to not use synthetic bold.
+        * platform/mac/fast/forms/validation-message-appearance-expected.txt: Ditto.
+
 2015-05-14  Filip Pizlo  <fpi...@apple.com>
 
         Unreviewed, skip js/regress-141098.html. The fix will be tracked in https://bugs.webkit.org/show_bug.cgi?id=145007

Modified: trunk/LayoutTests/platform/mac/fast/css/css2-system-fonts-expected.txt (184352 => 184353)


--- trunk/LayoutTests/platform/mac/fast/css/css2-system-fonts-expected.txt	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/platform/mac/fast/css/css2-system-fonts-expected.txt	2015-05-14 21:28:54 UTC (rev 184353)
@@ -1,10 +1,10 @@
 This tests platform specific system font styles. If any of the styles appear in monospace the test fails.
-caption: normal normal normal 13px/16px '.HelveticaNeueDeskInterface-Regular'
-icon: normal normal normal 13px/16px '.HelveticaNeueDeskInterface-Regular'
-menu: normal normal normal 13px/16px '.HelveticaNeueDeskInterface-Regular'
-message-box: normal normal normal 13px/16px '.HelveticaNeueDeskInterface-Regular'
-small-caption: normal normal normal 11px/13px '.HelveticaNeueDeskInterface-Regular'
-status-bar: normal normal normal 10px/12px '.HelveticaNeueDeskInterface-Regular'
--webkit-mini-control: normal normal normal 9px/11px '.HelveticaNeueDeskInterface-Regular'
--webkit-small-control: normal normal normal 11px/13px '.HelveticaNeueDeskInterface-Regular'
--webkit-control: normal normal normal 13px/16px '.HelveticaNeueDeskInterface-Regular'
+caption: normal normal normal 13px/16px -apple-system
+icon: normal normal normal 13px/16px -apple-system
+menu: normal normal normal 13px/16px -apple-menu
+message-box: normal normal normal 13px/16px -apple-system
+small-caption: normal normal normal 11px/13px -apple-system
+status-bar: normal normal normal 10px/12px -apple-status-bar
+-webkit-mini-control: normal normal normal 9px/11px -apple-system
+-webkit-small-control: normal normal normal 11px/13px -apple-system
+-webkit-control: normal normal normal 13px/16px -apple-system

Modified: trunk/LayoutTests/platform/mac/fast/forms/select/optgroup-rendering-expected.txt (184352 => 184353)


--- trunk/LayoutTests/platform/mac/fast/forms/select/optgroup-rendering-expected.txt	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/platform/mac/fast/forms/select/optgroup-rendering-expected.txt	2015-05-14 21:28:54 UTC (rev 184353)
@@ -4,10 +4,10 @@
   RenderBlock {HTML} at (0,0) size 800x323
     RenderBody {BODY} at (8,8) size 784x307
       RenderBlock {FORM} at (0,0) size 784x307
-        RenderListBox {SELECT} at (2,2) size 67x281 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
-        RenderText {#text} at (71,264) size 4x18
-          text run at (71,264) width 4: " "
-        RenderBR {BR} at (75,264) size 0x18
+        RenderListBox {SELECT} at (2,2) size 69x281 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
+        RenderText {#text} at (73,264) size 4x18
+          text run at (73,264) width 4: " "
+        RenderBR {BR} at (77,264) size 0x18
         RenderMenuList {SELECT} at (2,287) size 75x18 [bgcolor=#FFFFFF]
           RenderBlock (anonymous) at (0,0) size 75x18
             RenderText at (8,2) size 30x13

Modified: trunk/LayoutTests/platform/mac/fast/forms/validation-message-appearance-expected.txt (184352 => 184353)


--- trunk/LayoutTests/platform/mac/fast/forms/validation-message-appearance-expected.txt	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/platform/mac/fast/forms/validation-message-appearance-expected.txt	2015-05-14 21:28:54 UTC (rev 184353)
@@ -25,8 +25,8 @@
     RenderBlock {DIV} at (10,10) size 0x64
     RenderBlock {DIV} at (10,10) size 200x64
       RenderBlock {DIV} at (0,0) size 200x16
-        RenderText {#text} at (0,0) size 86x16
-          text run at (0,0) width 86: "value missing"
+        RenderText {#text} at (0,0) size 90x16
+          text run at (0,0) width 90: "value missing"
       RenderBlock {DIV} at (0,16) size 200x48
         RenderText {#text} at (0,0) size 147x16
           text run at (0,0) width 147: "Needs at least 8 letters."

Modified: trunk/LayoutTests/platform/mac/fast/text/systemFont-expected.txt (184352 => 184353)


--- trunk/LayoutTests/platform/mac/fast/text/systemFont-expected.txt	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/platform/mac/fast/text/systemFont-expected.txt	2015-05-14 21:28:54 UTC (rev 184353)
@@ -1,8 +1,8 @@
-layer at (0,0) size 785x2036
+layer at (0,0) size 785x2198
   RenderView at (0,0) size 785x600
-layer at (0,0) size 785x2036
-  RenderBlock {HTML} at (0,0) size 785x2036
-    RenderBody {BODY} at (8,8) size 769x2020
+layer at (0,0) size 785x2198
+  RenderBlock {HTML} at (0,0) size 785x2198
+    RenderBody {BODY} at (8,8) size 769x2182
       RenderBlock {DIV} at (0,0) size 769x897
         RenderBlock {DIV} at (0,0) size 769x28
           RenderText {#text} at (0,0) size 438x28
@@ -78,7 +78,35 @@
           RenderText {#text} at (0,0) size 756x170
             text run at (0,0) width 756: "This is a test for -apple-"
             text run at (0,85) width 373: "system font"
-      RenderBlock {DIV} at (0,1738) size 769x282
+      RenderBlock {DIV} at (0,1738) size 769x162
+        RenderBlock {DIV} at (0,0) size 769x18
+          RenderText {#text} at (0,0) size 302x18
+            text run at (0,0) width 302: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,18) size 769x18
+          RenderText {#text} at (0,0) size 316x18
+            text run at (0,0) width 316: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,36) size 769x18
+          RenderText {#text} at (0,0) size 335x18
+            text run at (0,0) width 335: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,54) size 769x18
+          RenderText {#text} at (0,0) size 350x18
+            text run at (0,0) width 350: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,72) size 769x18
+          RenderText {#text} at (0,0) size 362x18
+            text run at (0,0) width 362: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,90) size 769x18
+          RenderText {#text} at (0,0) size 374x18
+            text run at (0,0) width 374: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,108) size 769x18
+          RenderText {#text} at (0,0) size 374x18
+            text run at (0,0) width 374: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,126) size 769x18
+          RenderText {#text} at (0,0) size 396x18
+            text run at (0,0) width 396: "This is a font weight test for -apple-system font"
+        RenderBlock {DIV} at (0,144) size 769x18
+          RenderText {#text} at (0,0) size 396x18
+            text run at (0,0) width 396: "This is a font weight test for -apple-system font"
+      RenderBlock {DIV} at (0,1900) size 769x282
         RenderBlock {DIV} at (0,0) size 769x56
           RenderText {#text} at (0,0) size 644x56
             text run at (0,0) width 644: "This is a test for -apple-system-monospaced-numbers font -"

Modified: trunk/LayoutTests/platform/mac/fast/text/systemFont.html (184352 => 184353)


--- trunk/LayoutTests/platform/mac/fast/text/systemFont.html	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/platform/mac/fast/text/systemFont.html	2015-05-14 21:28:54 UTC (rev 184353)
@@ -24,6 +24,17 @@
         <div style="font-family: -apple-system; font-size: 72px">This is a test for -apple-system font</div>
     </div>
     <div>
+        <div style="font-family: -apple-system; font-weight: 100">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 200">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 300">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 400">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 500">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 600">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 700">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 800">This is a font weight test for -apple-system font</div>
+        <div style="font-family: -apple-system; font-weight: 900">This is a font weight test for -apple-system font</div>
+    </div>
+    <div>
         <div style="font-family: -apple-system-monospaced-numbers; font-size: 24px">This is a test for -apple-system-monospaced-numbers font - 00:11:22:33</div>
         <div style="font: 30.0px '-apple-system-monospaced-numbers'">This is a test for -apple-system-monospaced-numbers font - 00:11:22:33</div>
         <div style="font-family: -apple-system-monospaced-numbers; font-size: 30px">This is a test for -apple-system-monospaced-numbers font - 00:11:22:33</div>

Deleted: trunk/LayoutTests/platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt (184352 => 184353)


--- trunk/LayoutTests/platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt	2015-05-14 21:28:54 UTC (rev 184353)
@@ -1,10 +0,0 @@
-This tests platform specific system font styles. If any of the styles appear in monospace the test fails.
-caption: normal normal normal 13px/16px '.LucidaGrandeUI'
-icon: normal normal normal 13px/16px '.LucidaGrandeUI'
-menu: normal normal normal 13px/16px '.LucidaGrandeUI'
-message-box: normal normal normal 13px/16px '.LucidaGrandeUI'
-small-caption: normal normal normal 11px/13px '.LucidaGrandeUI'
-status-bar: normal normal normal 10px/12px '.LucidaGrandeUI'
--webkit-mini-control: normal normal normal 9px/11px '.LucidaGrandeUI'
--webkit-small-control: normal normal normal 11px/13px '.LucidaGrandeUI'
--webkit-control: normal normal normal 13px/16px '.LucidaGrandeUI'

Modified: trunk/Source/WebCore/ChangeLog (184352 => 184353)


--- trunk/Source/WebCore/ChangeLog	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/ChangeLog	2015-05-14 21:28:54 UTC (rev 184353)
@@ -1,3 +1,57 @@
+2015-05-14  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Mac] Expose more font weights for -apple-system
+        https://bugs.webkit.org/show_bug.cgi?id=144707
+
+        Reviewed by Simon Fraser.
+
+        Previously, when we parsed a CSS declaration of the form font: keyword; where keyword
+        is one of caption, icon, menu, message-box, small-caption, -webkit-mini-control, -webkit-small-control,
+        or -webkit-control (which html.css does for form controls), we would ask the system what the appropriate
+        system font is, get that font's family name, and synthesize a font-family CSS property for the element.
+        Then, later when we actually go to look up the font, we would look up the font by family name using this
+        information. However, this round-tripping of a font through a family name is actually lossy, and is not
+        guaranteed to preserve system-font-ness (which we use for various things including metrics calculations).
+
+        This patch modifies this logic to specify a token family name instead, which the font lookup code special
+        cases (and reacts by making the appropriate system-font lookup call). This approach is currently how iOS
+        handles these system fonts; this patch simply brings this approach to OS X.
+
+        There is also an added progression here. We used to simply call [NSFont fontWithName:size:] on the system
+        font family name (which the parser found for us) which entirely disregards weight. This means that we
+        used to be getting synthesized bold in form controls which ask for a heavy weight. Migrating to this
+        system-font aware call means that we get the real bold font instead of synthesized bold.
+
+        Once this system-font-ness is guaranteed to be preserved between parsing time and font lookup time, we
+        can safely migrate to using [NSFont systemFontOfSize:weight] instead of [NSFont systemFontOfSize:] on
+        platforms which support it.
+
+        Tests: fast/text/systemFont.html
+               fast/css/css2-system-fonts.html
+               fast/forms/select/optgroup-rendering.html
+               fast/forms/validation-message-appearance.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseSystemFont): Add a comment regarding why we are bothering with expanding out
+        the font property in the first place.
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::FontCascade::primaryFontIsSystemFont): Update to use new system font tokens.
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::toNSFontWeight): New static method to map font weights to NSFontWeight constants available on
+        Yosemite and later.
+        (WebCore::fontWithFamilySpecialCase): Pull all these special-case font token name handling into a
+        separate function, which returns an Optional.
+        (WebCore::fontWithFamily):
+        * platform/mac/ThemeMac.mm:
+        (WebCore::ThemeMac::controlFont): Use the font token name instead of the generated system font family
+        name.
+        * platform/spi/mac/NSFontSPI.h: Add [NSFont systemFontWithSize:weight:] and the proper NSFontWeight
+        constants.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::updateCachedSystemFontDescription): Use the font token names instead of the
+        generated system font family name.
+        (WebCore::RenderThemeMac::setFontFromControlSize): Ditto.
+
 2015-05-14  Roger Fong  <roger_f...@apple.com>
 
         Add internals setting to disable wireless playback availability for layout tests

Modified: trunk/Source/WebCore/css/CSSParser.cpp (184352 => 184353)


--- trunk/Source/WebCore/css/CSSParser.cpp	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2015-05-14 21:28:54 UTC (rev 184353)
@@ -6613,6 +6613,7 @@
     if (!fontDescription.isAbsoluteSize())
         return;
 
+    // We must set font's constituent properties, even for system fonts, so the cascade functions correctly.
     ShorthandScope scope(this, CSSPropertyFont);
     addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(fontDescription.italic() == FontItalicOn ? CSSValueItalic : CSSValueNormal), important);
     addProperty(CSSPropertyFontWeight, cssValuePool().createValue(fontDescription.weight()), important);

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (184352 => 184353)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-05-14 21:28:54 UTC (rev 184353)
@@ -687,9 +687,12 @@
     const auto& fontData = primaryFont();
     return !fontData.isSVGFont() && CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(fontData.platformData().ctFont())).get());
 #else
-    // System fonts are hidden by having a name that begins with a period, so simply search
-    // for that here rather than try to keep the list up to date.
-    return firstFamily().startsWith('.');
+    const String& firstFamily = this->firstFamily();
+    return equalIgnoringASCIICase(firstFamily, "-webkit-system-font")
+        || equalIgnoringASCIICase(firstFamily, "-apple-system-font")
+        || equalIgnoringASCIICase(firstFamily, "-apple-system")
+        || equalIgnoringASCIICase(firstFamily, "-apple-menu")
+        || equalIgnoringASCIICase(firstFamily, "-apple-status-bar");
 #endif
 }
 

Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (184352 => 184353)


--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2015-05-14 21:28:54 UTC (rev 184353)
@@ -43,6 +43,7 @@
 #import <AppKit/AppKit.h>
 #import <wtf/MainThread.h>
 #import <wtf/NeverDestroyed.h>
+#import <wtf/Optional.h>
 #import <wtf/StdLibExtras.h>
 #import <wtf/Threading.h>
 #import <wtf/text/AtomicStringHash.h>
@@ -203,17 +204,38 @@
     return appKitFontWeights[fontWeight];
 }
 
-// Family name is somewhat of a misnomer here. We first attempt to find an exact match
-// comparing the desiredFamily to the PostScript name of the installed fonts. If that fails
-// we then do a search based on the family names of the installed fonts.
-static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+static CGFloat toNSFontWeight(FontWeight fontWeight)
 {
-    if (equalIgnoringASCIICase(family.string(), String(@"-webkit-system-font")) || equalIgnoringASCIICase(family.string(), String(@"-apple-system")) || equalIgnoringASCIICase(family.string(), String(@"-apple-system-font"))) {
-        // We ignore italic for system font.
+    static CGFloat nsFontWeights[] = {
+        NSFontWeightUltraLight,
+        NSFontWeightThin,
+        NSFontWeightLight,
+        NSFontWeightRegular,
+        NSFontWeightMedium,
+        NSFontWeightSemibold,
+        NSFontWeightBold,
+        NSFontWeightHeavy,
+        NSFontWeightBlack
+    };
+    ASSERT(fontWeight >= 0 && fontWeight <= 8);
+    return nsFontWeights[fontWeight];
+}
+#endif
+
+static Optional<NSFont*> fontWithFamilySpecialCase(const AtomicString& family, FontWeight weight, float size)
+{
+    if (equalIgnoringASCIICase(family.string(), "-webkit-system-font")
+        || equalIgnoringASCIICase(family.string(), "-apple-system")
+        || equalIgnoringASCIICase(family.string(), "-apple-system-font")) {
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+        return [NSFont systemFontOfSize:size weight:toNSFontWeight(weight)];
+#else
         return (weight >= FontWeight600) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
+#endif
     }
 
-    if (equalIgnoringASCIICase(family.string(), String(@"-apple-system-monospaced-numbers"))) {
+    if (equalIgnoringASCIICase(family.string(), "-apple-system-monospaced-numbers")) {
         NSArray *featureArray = @[ @{ NSFontFeatureTypeIdentifierKey : @(kNumberSpacingType),
             NSFontFeatureSelectorIdentifierKey : @(kMonospacedNumbersSelector) } ];
 
@@ -222,6 +244,23 @@
         return [NSFont fontWithDescriptor:desc size:size];
     }
 
+    if (equalIgnoringASCIICase(family.string(), "-apple-menu"))
+        return [NSFont menuFontOfSize:size];
+
+    if (equalIgnoringASCIICase(family.string(), "-apple-status-bar"))
+        return [NSFont labelFontOfSize:size];
+
+    return Optional<NSFont*>(Nullopt);
+}
+
+// Family name is somewhat of a misnomer here. We first attempt to find an exact match
+// comparing the desiredFamily to the PostScript name of the installed fonts. If that fails
+// we then do a search based on the family names of the installed fonts.
+static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
+{
+    if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, size))
+        return specialCase.value();
+
     NSFontManager *fontManager = [NSFontManager sharedFontManager];
     NSString *desiredFamily = family;
     NSString *availableFamily;
@@ -230,8 +269,6 @@
 
 #if ENABLE(PLATFORM_FONT_LOOKUP)
 
-    if (family.length() > 0 && family.string().at(0) == '.')
-        return [NSFont fontWithName:desiredFamily size:size];
     const auto& whitelist = fontWhitelist();
     if (whitelist.size() && !whitelist.contains(family.lower()))
         return nil;

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (184352 => 184353)


--- trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-05-14 21:28:54 UTC (rev 184353)
@@ -675,7 +675,7 @@
             fontDescription.setIsAbsoluteSize(true);
 
             NSFont* nsFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSizeForFont(font)]];
-            fontDescription.setOneFamily([nsFont webCoreFamilyName]);
+            fontDescription.setOneFamily(AtomicString("-apple-system", AtomicString::ConstructFromLiteral));
             fontDescription.setComputedSize([nsFont pointSize] * zoomFactor);
             fontDescription.setSpecifiedSize([nsFont pointSize] * zoomFactor);
             return fontDescription;

Modified: trunk/Source/WebCore/platform/spi/mac/NSFontSPI.h (184352 => 184353)


--- trunk/Source/WebCore/platform/spi/mac/NSFontSPI.h	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/platform/spi/mac/NSFontSPI.h	2015-05-14 21:28:54 UTC (rev 184353)
@@ -25,6 +25,7 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 
+#import <AppKit/NSFontDescriptor_Private.h>
 #import <AppKit/NSFont_Private.h>
 
 #else
@@ -32,6 +33,20 @@
 @interface NSFont (Private)
 + (NSFont *)findFontLike:(NSFont *)aFont forCharacter:(UInt32)c inLanguage:(id) language;
 + (NSFont *)findFontLike:(NSFont *)aFont forString:(NSString *)string withRange:(NSRange)range inLanguage:(id) language;
+
++ (NSFont *)systemFontOfSize:(CGFloat)size weight:(CGFloat)weight;
 @end
 
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+extern const CGFloat NSFontWeightUltraLight;
+extern const CGFloat NSFontWeightThin;
+extern const CGFloat NSFontWeightLight;
+extern const CGFloat NSFontWeightRegular;
+extern const CGFloat NSFontWeightMedium;
+extern const CGFloat NSFontWeightSemibold;
+extern const CGFloat NSFontWeightBold;
+extern const CGFloat NSFontWeightHeavy;
+extern const CGFloat NSFontWeightBlack;
 #endif
+
+#endif

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (184352 => 184353)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-05-14 21:28:54 UTC (rev 184353)
@@ -347,15 +347,21 @@
 void RenderThemeMac::updateCachedSystemFontDescription(CSSValueID cssValueId, FontDescription& fontDescription) const
 {
     NSFont* font;
+    // System-font-ness can't be encapsulated by simply a font name. Instead, we must use a token
+    // which FontCache will look for.
+    // Make sure we keep this list of possible tokens in sync with FontCascade::primaryFontIsSystemFont()
+    String fontName(ASCIILiteral("-apple-system"));
     switch (cssValueId) {
         case CSSValueSmallCaption:
             font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
             break;
         case CSSValueMenu:
             font = [NSFont menuFontOfSize:[NSFont systemFontSize]];
+            fontName = String(ASCIILiteral("-apple-menu"));
             break;
         case CSSValueStatusBar:
             font = [NSFont labelFontOfSize:[NSFont labelFontSize]];
+            fontName = String(ASCIILiteral("-apple-status-bar"));
             break;
         case CSSValueWebkitMiniControl:
             font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
@@ -375,7 +381,7 @@
 
     NSFontManager *fontManager = [NSFontManager sharedFontManager];
     fontDescription.setIsAbsoluteSize(true);
-    fontDescription.setOneFamily([font webCoreFamilyName]);
+    fontDescription.setOneFamily(fontName);
     fontDescription.setSpecifiedSize([font pointSize]);
     fontDescription.setWeight(toFontWeight([fontManager weightOfFont:font]));
     fontDescription.setIsItalic([fontManager traitsOfFont:font] & NSItalicFontMask);
@@ -821,7 +827,7 @@
     fontDescription.setIsAbsoluteSize(true);
 
     NSFont* font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSize]];
-    fontDescription.setOneFamily([font webCoreFamilyName]);
+    fontDescription.setOneFamily(AtomicString("-apple-system", AtomicString::ConstructFromLiteral));
     fontDescription.setComputedSize([font pointSize] * style.effectiveZoom());
     fontDescription.setSpecifiedSize([font pointSize] * style.effectiveZoom());
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to