<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[184353] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/184353">184353</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2015-05-14 14:28:54 -0700 (Thu, 14 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacfastcsscss2systemfontsexpectedtxt">trunk/LayoutTests/platform/mac/fast/css/css2-system-fonts-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacfastformsselectoptgrouprenderingexpectedtxt">trunk/LayoutTests/platform/mac/fast/forms/select/optgroup-rendering-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacfastformsvalidationmessageappearanceexpectedtxt">trunk/LayoutTests/platform/mac/fast/forms/validation-message-appearance-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacfasttextsystemFontexpectedtxt">trunk/LayoutTests/platform/mac/fast/text/systemFont-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacfasttextsystemFonthtml">trunk/LayoutTests/platform/mac/fast/text/systemFont.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSParsercpp">trunk/Source/WebCore/css/CSSParser.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaFontCascadeCocoamm">trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacFontCacheMacmm">trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmacThemeMacmm">trunk/Source/WebCore/platform/mac/ThemeMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformspimacNSFontSPIh">trunk/Source/WebCore/platform/spi/mac/NSFontSPI.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderThemeMacmm">trunk/Source/WebCore/rendering/RenderThemeMac.mm</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsplatformmacmavericksfastcsscss2systemfontsexpectedtxt">trunk/LayoutTests/platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-05-14 21:24:35 UTC (rev 184352)
+++ trunk/LayoutTests/ChangeLog        2015-05-14 21:28:54 UTC (rev 184353)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-05-14  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [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.
+
</ins><span class="cx"> 2015-05-14  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, skip js/regress-141098.html. The fix will be tracked in https://bugs.webkit.org/show_bug.cgi?id=145007
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacfastcsscss2systemfontsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/fast/css/css2-system-fonts-expected.txt (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,10 +1,10 @@
</span><span class="cx"> This tests platform specific system font styles. If any of the styles appear in monospace the test fails.
</span><del>-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'
</del><ins>+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
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacfastformsselectoptgrouprenderingexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/fast/forms/select/optgroup-rendering-expected.txt (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -4,10 +4,10 @@
</span><span class="cx">   RenderBlock {HTML} at (0,0) size 800x323
</span><span class="cx">     RenderBody {BODY} at (8,8) size 784x307
</span><span class="cx">       RenderBlock {FORM} at (0,0) size 784x307
</span><del>-        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: &quot; &quot;
-        RenderBR {BR} at (75,264) size 0x18
</del><ins>+        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: &quot; &quot;
+        RenderBR {BR} at (77,264) size 0x18
</ins><span class="cx">         RenderMenuList {SELECT} at (2,287) size 75x18 [bgcolor=#FFFFFF]
</span><span class="cx">           RenderBlock (anonymous) at (0,0) size 75x18
</span><span class="cx">             RenderText at (8,2) size 30x13
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacfastformsvalidationmessageappearanceexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/fast/forms/validation-message-appearance-expected.txt (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -25,8 +25,8 @@
</span><span class="cx">     RenderBlock {DIV} at (10,10) size 0x64
</span><span class="cx">     RenderBlock {DIV} at (10,10) size 200x64
</span><span class="cx">       RenderBlock {DIV} at (0,0) size 200x16
</span><del>-        RenderText {#text} at (0,0) size 86x16
-          text run at (0,0) width 86: &quot;value missing&quot;
</del><ins>+        RenderText {#text} at (0,0) size 90x16
+          text run at (0,0) width 90: &quot;value missing&quot;
</ins><span class="cx">       RenderBlock {DIV} at (0,16) size 200x48
</span><span class="cx">         RenderText {#text} at (0,0) size 147x16
</span><span class="cx">           text run at (0,0) width 147: &quot;Needs at least 8 letters.&quot;
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacfasttextsystemFontexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/fast/text/systemFont-expected.txt (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,8 +1,8 @@
</span><del>-layer at (0,0) size 785x2036
</del><ins>+layer at (0,0) size 785x2198
</ins><span class="cx">   RenderView at (0,0) size 785x600
</span><del>-layer at (0,0) size 785x2036
-  RenderBlock {HTML} at (0,0) size 785x2036
-    RenderBody {BODY} at (8,8) size 769x2020
</del><ins>+layer at (0,0) size 785x2198
+  RenderBlock {HTML} at (0,0) size 785x2198
+    RenderBody {BODY} at (8,8) size 769x2182
</ins><span class="cx">       RenderBlock {DIV} at (0,0) size 769x897
</span><span class="cx">         RenderBlock {DIV} at (0,0) size 769x28
</span><span class="cx">           RenderText {#text} at (0,0) size 438x28
</span><span class="lines">@@ -78,7 +78,35 @@
</span><span class="cx">           RenderText {#text} at (0,0) size 756x170
</span><span class="cx">             text run at (0,0) width 756: &quot;This is a test for -apple-&quot;
</span><span class="cx">             text run at (0,85) width 373: &quot;system font&quot;
</span><del>-      RenderBlock {DIV} at (0,1738) size 769x282
</del><ins>+      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: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,18) size 769x18
+          RenderText {#text} at (0,0) size 316x18
+            text run at (0,0) width 316: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,36) size 769x18
+          RenderText {#text} at (0,0) size 335x18
+            text run at (0,0) width 335: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,54) size 769x18
+          RenderText {#text} at (0,0) size 350x18
+            text run at (0,0) width 350: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,72) size 769x18
+          RenderText {#text} at (0,0) size 362x18
+            text run at (0,0) width 362: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,90) size 769x18
+          RenderText {#text} at (0,0) size 374x18
+            text run at (0,0) width 374: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,108) size 769x18
+          RenderText {#text} at (0,0) size 374x18
+            text run at (0,0) width 374: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,126) size 769x18
+          RenderText {#text} at (0,0) size 396x18
+            text run at (0,0) width 396: &quot;This is a font weight test for -apple-system font&quot;
+        RenderBlock {DIV} at (0,144) size 769x18
+          RenderText {#text} at (0,0) size 396x18
+            text run at (0,0) width 396: &quot;This is a font weight test for -apple-system font&quot;
+      RenderBlock {DIV} at (0,1900) size 769x282
</ins><span class="cx">         RenderBlock {DIV} at (0,0) size 769x56
</span><span class="cx">           RenderText {#text} at (0,0) size 644x56
</span><span class="cx">             text run at (0,0) width 644: &quot;This is a test for -apple-system-monospaced-numbers font -&quot;
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacfasttextsystemFonthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/fast/text/systemFont.html (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -24,6 +24,17 @@
</span><span class="cx">         &lt;div style=&quot;font-family: -apple-system; font-size: 72px&quot;&gt;This is a test for -apple-system font&lt;/div&gt;
</span><span class="cx">     &lt;/div&gt;
</span><span class="cx">     &lt;div&gt;
</span><ins>+        &lt;div style=&quot;font-family: -apple-system; font-weight: 100&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 200&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 300&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 400&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 500&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 600&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 700&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 800&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+        &lt;div style=&quot;font-family: -apple-system; font-weight: 900&quot;&gt;This is a font weight test for -apple-system font&lt;/div&gt;
+    &lt;/div&gt;
+    &lt;div&gt;
</ins><span class="cx">         &lt;div style=&quot;font-family: -apple-system-monospaced-numbers; font-size: 24px&quot;&gt;This is a test for -apple-system-monospaced-numbers font - 00:11:22:33&lt;/div&gt;
</span><span class="cx">         &lt;div style=&quot;font: 30.0px '-apple-system-monospaced-numbers'&quot;&gt;This is a test for -apple-system-monospaced-numbers font - 00:11:22:33&lt;/div&gt;
</span><span class="cx">         &lt;div style=&quot;font-family: -apple-system-monospaced-numbers; font-size: 30px&quot;&gt;This is a test for -apple-system-monospaced-numbers font - 00:11:22:33&lt;/div&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacmavericksfastcsscss2systemfontsexpectedtxt"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/platform/mac-mavericks/fast/css/css2-system-fonts-expected.txt (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,10 +0,0 @@
</span><del>-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'
</del></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2015-05-14  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [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.
+
</ins><span class="cx"> 2015-05-14  Roger Fong  &lt;roger_fong@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add internals setting to disable wireless playback availability for layout tests
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParser.cpp (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -6613,6 +6613,7 @@
</span><span class="cx">     if (!fontDescription.isAbsoluteSize())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    // We must set font's constituent properties, even for system fonts, so the cascade functions correctly.
</ins><span class="cx">     ShorthandScope scope(this, CSSPropertyFont);
</span><span class="cx">     addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(fontDescription.italic() == FontItalicOn ? CSSValueItalic : CSSValueNormal), important);
</span><span class="cx">     addProperty(CSSPropertyFontWeight, cssValuePool().createValue(fontDescription.weight()), important);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaFontCascadeCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -687,9 +687,12 @@
</span><span class="cx">     const auto&amp; fontData = primaryFont();
</span><span class="cx">     return !fontData.isSVGFont() &amp;&amp; CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(fontData.platformData().ctFont())).get());
</span><span class="cx"> #else
</span><del>-    // 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('.');
</del><ins>+    const String&amp; firstFamily = this-&gt;firstFamily();
+    return equalIgnoringASCIICase(firstFamily, &quot;-webkit-system-font&quot;)
+        || equalIgnoringASCIICase(firstFamily, &quot;-apple-system-font&quot;)
+        || equalIgnoringASCIICase(firstFamily, &quot;-apple-system&quot;)
+        || equalIgnoringASCIICase(firstFamily, &quot;-apple-menu&quot;)
+        || equalIgnoringASCIICase(firstFamily, &quot;-apple-status-bar&quot;);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacFontCacheMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> #import &lt;AppKit/AppKit.h&gt;
</span><span class="cx"> #import &lt;wtf/MainThread.h&gt;
</span><span class="cx"> #import &lt;wtf/NeverDestroyed.h&gt;
</span><ins>+#import &lt;wtf/Optional.h&gt;
</ins><span class="cx"> #import &lt;wtf/StdLibExtras.h&gt;
</span><span class="cx"> #import &lt;wtf/Threading.h&gt;
</span><span class="cx"> #import &lt;wtf/text/AtomicStringHash.h&gt;
</span><span class="lines">@@ -203,17 +204,38 @@
</span><span class="cx">     return appKitFontWeights[fontWeight];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// 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&amp; family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
</del><ins>+#if __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101000
+static CGFloat toNSFontWeight(FontWeight fontWeight)
</ins><span class="cx"> {
</span><del>-    if (equalIgnoringASCIICase(family.string(), String(@&quot;-webkit-system-font&quot;)) || equalIgnoringASCIICase(family.string(), String(@&quot;-apple-system&quot;)) || equalIgnoringASCIICase(family.string(), String(@&quot;-apple-system-font&quot;))) {
-        // We ignore italic for system font.
</del><ins>+    static CGFloat nsFontWeights[] = {
+        NSFontWeightUltraLight,
+        NSFontWeightThin,
+        NSFontWeightLight,
+        NSFontWeightRegular,
+        NSFontWeightMedium,
+        NSFontWeightSemibold,
+        NSFontWeightBold,
+        NSFontWeightHeavy,
+        NSFontWeightBlack
+    };
+    ASSERT(fontWeight &gt;= 0 &amp;&amp; fontWeight &lt;= 8);
+    return nsFontWeights[fontWeight];
+}
+#endif
+
+static Optional&lt;NSFont*&gt; fontWithFamilySpecialCase(const AtomicString&amp; family, FontWeight weight, float size)
+{
+    if (equalIgnoringASCIICase(family.string(), &quot;-webkit-system-font&quot;)
+        || equalIgnoringASCIICase(family.string(), &quot;-apple-system&quot;)
+        || equalIgnoringASCIICase(family.string(), &quot;-apple-system-font&quot;)) {
+#if __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101000
+        return [NSFont systemFontOfSize:size weight:toNSFontWeight(weight)];
+#else
</ins><span class="cx">         return (weight &gt;= FontWeight600) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
</span><ins>+#endif
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (equalIgnoringASCIICase(family.string(), String(@&quot;-apple-system-monospaced-numbers&quot;))) {
</del><ins>+    if (equalIgnoringASCIICase(family.string(), &quot;-apple-system-monospaced-numbers&quot;)) {
</ins><span class="cx">         NSArray *featureArray = @[ @{ NSFontFeatureTypeIdentifierKey : @(kNumberSpacingType),
</span><span class="cx">             NSFontFeatureSelectorIdentifierKey : @(kMonospacedNumbersSelector) } ];
</span><span class="cx"> 
</span><span class="lines">@@ -222,6 +244,23 @@
</span><span class="cx">         return [NSFont fontWithDescriptor:desc size:size];
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (equalIgnoringASCIICase(family.string(), &quot;-apple-menu&quot;))
+        return [NSFont menuFontOfSize:size];
+
+    if (equalIgnoringASCIICase(family.string(), &quot;-apple-status-bar&quot;))
+        return [NSFont labelFontOfSize:size];
+
+    return Optional&lt;NSFont*&gt;(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&amp; family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
+{
+    if (const auto&amp; specialCase = fontWithFamilySpecialCase(family, weight, size))
+        return specialCase.value();
+
</ins><span class="cx">     NSFontManager *fontManager = [NSFontManager sharedFontManager];
</span><span class="cx">     NSString *desiredFamily = family;
</span><span class="cx">     NSString *availableFamily;
</span><span class="lines">@@ -230,8 +269,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(PLATFORM_FONT_LOOKUP)
</span><span class="cx"> 
</span><del>-    if (family.length() &gt; 0 &amp;&amp; family.string().at(0) == '.')
-        return [NSFont fontWithName:desiredFamily size:size];
</del><span class="cx">     const auto&amp; whitelist = fontWhitelist();
</span><span class="cx">     if (whitelist.size() &amp;&amp; !whitelist.contains(family.lower()))
</span><span class="cx">         return nil;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacThemeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -675,7 +675,7 @@
</span><span class="cx">             fontDescription.setIsAbsoluteSize(true);
</span><span class="cx"> 
</span><span class="cx">             NSFont* nsFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSizeForFont(font)]];
</span><del>-            fontDescription.setOneFamily([nsFont webCoreFamilyName]);
</del><ins>+            fontDescription.setOneFamily(AtomicString(&quot;-apple-system&quot;, AtomicString::ConstructFromLiteral));
</ins><span class="cx">             fontDescription.setComputedSize([nsFont pointSize] * zoomFactor);
</span><span class="cx">             fontDescription.setSpecifiedSize([nsFont pointSize] * zoomFactor);
</span><span class="cx">             return fontDescription;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformspimacNSFontSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/spi/mac/NSFontSPI.h (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><ins>+#import &lt;AppKit/NSFontDescriptor_Private.h&gt;
</ins><span class="cx"> #import &lt;AppKit/NSFont_Private.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #else
</span><span class="lines">@@ -32,6 +33,20 @@
</span><span class="cx"> @interface NSFont (Private)
</span><span class="cx"> + (NSFont *)findFontLike:(NSFont *)aFont forCharacter:(UInt32)c inLanguage:(id) language;
</span><span class="cx"> + (NSFont *)findFontLike:(NSFont *)aFont forString:(NSString *)string withRange:(NSRange)range inLanguage:(id) language;
</span><ins>+
++ (NSFont *)systemFontOfSize:(CGFloat)size weight:(CGFloat)weight;
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+#if __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 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;
</ins><span class="cx"> #endif
</span><ins>+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderThemeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (184352 => 184353)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -347,15 +347,21 @@
</span><span class="cx"> void RenderThemeMac::updateCachedSystemFontDescription(CSSValueID cssValueId, FontDescription&amp; fontDescription) const
</span><span class="cx"> {
</span><span class="cx">     NSFont* font;
</span><ins>+    // 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(&quot;-apple-system&quot;));
</ins><span class="cx">     switch (cssValueId) {
</span><span class="cx">         case CSSValueSmallCaption:
</span><span class="cx">             font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
</span><span class="cx">             break;
</span><span class="cx">         case CSSValueMenu:
</span><span class="cx">             font = [NSFont menuFontOfSize:[NSFont systemFontSize]];
</span><ins>+            fontName = String(ASCIILiteral(&quot;-apple-menu&quot;));
</ins><span class="cx">             break;
</span><span class="cx">         case CSSValueStatusBar:
</span><span class="cx">             font = [NSFont labelFontOfSize:[NSFont labelFontSize]];
</span><ins>+            fontName = String(ASCIILiteral(&quot;-apple-status-bar&quot;));
</ins><span class="cx">             break;
</span><span class="cx">         case CSSValueWebkitMiniControl:
</span><span class="cx">             font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
</span><span class="lines">@@ -375,7 +381,7 @@
</span><span class="cx"> 
</span><span class="cx">     NSFontManager *fontManager = [NSFontManager sharedFontManager];
</span><span class="cx">     fontDescription.setIsAbsoluteSize(true);
</span><del>-    fontDescription.setOneFamily([font webCoreFamilyName]);
</del><ins>+    fontDescription.setOneFamily(fontName);
</ins><span class="cx">     fontDescription.setSpecifiedSize([font pointSize]);
</span><span class="cx">     fontDescription.setWeight(toFontWeight([fontManager weightOfFont:font]));
</span><span class="cx">     fontDescription.setIsItalic([fontManager traitsOfFont:font] &amp; NSItalicFontMask);
</span><span class="lines">@@ -821,7 +827,7 @@
</span><span class="cx">     fontDescription.setIsAbsoluteSize(true);
</span><span class="cx"> 
</span><span class="cx">     NSFont* font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSize]];
</span><del>-    fontDescription.setOneFamily([font webCoreFamilyName]);
</del><ins>+    fontDescription.setOneFamily(AtomicString(&quot;-apple-system&quot;, AtomicString::ConstructFromLiteral));
</ins><span class="cx">     fontDescription.setComputedSize([font pointSize] * style.effectiveZoom());
</span><span class="cx">     fontDescription.setSpecifiedSize([font pointSize] * style.effectiveZoom());
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>