<!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>[247439] 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/247439">247439</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2019-07-15 12:09:51 -0700 (Mon, 15 Jul 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>[macOS 10.15] Cannot unbold selected text when the system font is used
https://bugs.webkit.org/show_bug.cgi?id=199788
<rdar://problem/52142570>

Reviewed by Tim Horton.

Source/WebKit:

In macOS 10.15, +[NSFont fontWithName:size:] no longer recognizes system fonts (of name
".SFNS-*") and returns nil instead. However, our existing implementation of
WebPageProxy::fontAtSelection works by grabbing the font name in the web process, and
sending it over to the UI process, where it is mapped to an NSFont. As a result, this always
results in a nil font in macOS 10.15, which causes us to never update NSFontManager's
selected font. In turn, this means that once selected text is bolded, it can't be unbolded
via NSFontManager, since NSFontManager thinks that the text is still not bold.

To fix this, we simply encode and send a platform FontInfo instead of sending the font name.
This allows the UI process to reconstruct NSFonts from font attribute dictionaries instead,
and update the font manager.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::updateFontManagerIfNeeded):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::fontAtSelection):

Refactor this to send a FontInfo (containing a font attribute dictionary) instead of a font
name.

(WebKit::WebPageProxy::fontAtSelectionCallback): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Change FontAtSelection to use sendWithAsyncReply instead of sending a callback ID. This also
allows us to remove FontAtSelectionCallback.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::fontAtSelection):

Tools:

Add a new API test to verify that bolding and unbolding updates the
shared font manager's selected font.

* TestWebKitAPI/Tests/mac/FontManagerTests.mm:
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessCocoaWebViewImplmm">trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxymessagesin">trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKitUIProcessmacWebPageProxyMacmm">trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagemessagesin">trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsmacFontManagerTestsmm">trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/ChangeLog       2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2019-07-15  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [macOS 10.15] Cannot unbold selected text when the system font is used
+        https://bugs.webkit.org/show_bug.cgi?id=199788
+        <rdar://problem/52142570>
+
+        Reviewed by Tim Horton.
+
+        In macOS 10.15, +[NSFont fontWithName:size:] no longer recognizes system fonts (of name
+        ".SFNS-*") and returns nil instead. However, our existing implementation of
+        WebPageProxy::fontAtSelection works by grabbing the font name in the web process, and
+        sending it over to the UI process, where it is mapped to an NSFont. As a result, this always
+        results in a nil font in macOS 10.15, which causes us to never update NSFontManager's
+        selected font. In turn, this means that once selected text is bolded, it can't be unbolded
+        via NSFontManager, since NSFontManager thinks that the text is still not bold.
+
+        To fix this, we simply encode and send a platform FontInfo instead of sending the font name.
+        This allows the UI process to reconstruct NSFonts from font attribute dictionaries instead,
+        and update the font manager.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::updateFontManagerIfNeeded):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::fontAtSelection):
+
+        Refactor this to send a FontInfo (containing a font attribute dictionary) instead of a font
+        name.
+
+        (WebKit::WebPageProxy::fontAtSelectionCallback): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
+        Change FontAtSelection to use sendWithAsyncReply instead of sending a callback ID. This also
+        allows us to remove FontAtSelectionCallback.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::fontAtSelection):
+
</ins><span class="cx"> 2019-07-15  Jiewen Tan  <jiewen_tan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS] SOAuthorizationSession should tell AppSSO whether the UIClient is capable of showing the extension UI
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessCocoaWebViewImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm       2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm  2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #import "AppKitSPI.h"
</span><span class="cx"> #import "AttributedString.h"
</span><span class="cx"> #import "ColorSpaceData.h"
</span><ins>+#import "FontInfo.h"
</ins><span class="cx"> #import "FullscreenClient.h"
</span><span class="cx"> #import "GenericCallback.h"
</span><span class="cx"> #import "InsertTextOptions.h"
</span><span class="lines">@@ -2809,9 +2810,20 @@
</span><span class="cx">     if (!fontPanelIsVisible && !m_page->editorState().isContentRichlyEditable)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_page->fontAtSelection([](const String& fontName, double fontSize, bool selectionHasMultipleFonts, WebKit::CallbackBase::Error error) {
-        if (NSFont *font = [NSFont fontWithName:fontName size:fontSize])
-            [NSFontManager.sharedFontManager setSelectedFont:font isMultiple:selectionHasMultipleFonts];
</del><ins>+    m_page->fontAtSelection([](const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts) {
+        NSDictionary *attributeDictionary = (__bridge NSDictionary *)fontInfo.fontAttributeDictionary.get();
+        if (!attributeDictionary)
+            return;
+
+        NSFontDescriptor *descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:attributeDictionary];
+        if (!descriptor)
+            return;
+
+        NSFont *font = [NSFont fontWithDescriptor:descriptor size:fontSize];
+        if (!font)
+            return;
+
+        [NSFontManager.sharedFontManager setSelectedFont:font isMultiple:selectionHasMultipleFonts];
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -282,6 +282,7 @@
</span><span class="cx"> struct DocumentEditingContextRequest;
</span><span class="cx"> struct EditingRange;
</span><span class="cx"> struct EditorState;
</span><ins>+struct FontInfo;
</ins><span class="cx"> struct FrameInfoData;
</span><span class="cx"> struct InsertTextOptions;
</span><span class="cx"> struct InteractionInformationRequest;
</span><span class="lines">@@ -337,7 +338,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> typedef GenericCallback<const AttributedString&, const EditingRange&> AttributedStringForCharacterRangeCallback;
</span><del>-typedef GenericCallback<const String&, double, bool> FontAtSelectionCallback;
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><span class="lines">@@ -788,7 +788,7 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup);
</span><span class="cx">     void attributedSubstringForCharacterRangeAsync(const EditingRange&, WTF::Function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>&&);
</span><del>-    void fontAtSelection(WTF::Function<void (const String&, double, bool, CallbackBase::Error)>&&);
</del><ins>+    void fontAtSelection(Function<void(const FontInfo&, double, bool)>&&);
</ins><span class="cx"> 
</span><span class="cx">     void startWindowDrag();
</span><span class="cx">     NSWindow *platformWindow();
</span><span class="lines">@@ -1869,7 +1869,6 @@
</span><span class="cx">     void rectForCharacterRangeCallback(const WebCore::IntRect&, const EditingRange&, CallbackID);
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     void attributedStringForCharacterRangeCallback(const AttributedString&, const EditingRange&, CallbackID);
</span><del>-    void fontAtSelectionCallback(const String&, double, bool, CallbackID);
</del><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><span class="cx">     void gestureCallback(const WebCore::IntPoint&, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID);
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in   2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in      2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -180,7 +180,6 @@
</span><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     AttributedStringForCharacterRangeCallback(struct WebKit::AttributedString string, struct WebKit::EditingRange actualRange, WebKit::CallbackID callbackID)
</span><del>-    FontAtSelectionCallback(String fontName, double fontSize, bool selectioHasMultipleFonts, WebKit::CallbackID callbackID)
</del><span class="cx"> #endif
</span><span class="cx">     FontAttributesCallback(struct WebCore::FontAttributes attributes, WebKit::CallbackID callbackID)
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessmacWebPageProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm     2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm        2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import "ColorSpaceData.h"
</span><span class="cx"> #import "DataReference.h"
</span><span class="cx"> #import "EditorState.h"
</span><ins>+#import "FontInfo.h"
</ins><span class="cx"> #import "InsertTextOptions.h"
</span><span class="cx"> #import "MenuUtilities.h"
</span><span class="cx"> #import "NativeWebKeyboardEvent.h"
</span><span class="lines">@@ -240,30 +241,15 @@
</span><span class="cx">     callback->performCallbackWithReturnValue(string, actualRange);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPageProxy::fontAtSelection(WTF::Function<void (const String&, double, bool, CallbackBase::Error)>&& callbackFunction)
</del><ins>+void WebPageProxy::fontAtSelection(Function<void(const FontInfo&, double, bool)>&& callback)
</ins><span class="cx"> {
</span><span class="cx">     if (!hasRunningProcess()) {
</span><del>-        callbackFunction(String(), 0, false, CallbackBase::Error::Unknown);
</del><ins>+        callback({ }, 0, false);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><del>-    
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
-    
-    process().send(Messages::WebPage::FontAtSelection(callbackID), m_pageID);
</del><ins>+    m_process->connection()->sendWithAsyncReply(Messages::WebPage::FontAtSelection(), WTFMove(callback), m_pageID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPageProxy::fontAtSelectionCallback(const String& fontName, double fontSize, bool selectionHasMultipleFonts, CallbackID callbackID)
-{
-    auto callback = m_callbacks.take<FontAtSelectionCallback>(callbackID);
-    if (!callback) {
-        // FIXME: Log error or assert.
-        // this can validly happen if a load invalidated the callback, though
-        return;
-    }
-    
-    callback->performCallbackWithReturnValue(fontName, fontSize, selectionHasMultipleFonts);
-}
-
</del><span class="cx"> String WebPageProxy::stringSelectionForPasteboard()
</span><span class="cx"> {
</span><span class="cx">     String value;
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -258,6 +258,7 @@
</span><span class="cx"> struct BackForwardListItemState;
</span><span class="cx"> struct DataDetectionResult;
</span><span class="cx"> struct EditorState;
</span><ins>+struct FontInfo;
</ins><span class="cx"> struct InsertTextOptions;
</span><span class="cx"> struct InteractionInformationAtPosition;
</span><span class="cx"> struct InteractionInformationRequest;
</span><span class="lines">@@ -810,7 +811,7 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool registerUndoGroup = false);
</span><span class="cx">     void attributedSubstringForCharacterRangeAsync(const EditingRange&, CallbackID);
</span><del>-    void fontAtSelection(CallbackID);
</del><ins>+    void fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&&);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA) && ENABLE(SERVICE_CONTROLS)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in       2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in  2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -445,7 +445,7 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     InsertDictatedTextAsync(String text, struct WebKit::EditingRange replacementRange, Vector<WebCore::DictationAlternative> dictationAlternatives, bool registerUndoGroup)
</span><span class="cx">     AttributedSubstringForCharacterRangeAsync(struct WebKit::EditingRange range, WebKit::CallbackID callbackID);
</span><del>-    FontAtSelection(WebKit::CallbackID callbackID);
</del><ins>+    FontAtSelection() -> (struct WebKit::FontInfo info, double fontSize, bool hasMultipleFonts) Async
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     SetAlwaysShowsHorizontalScroller(bool alwaysShowsHorizontalScroller)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm    2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import "DataReference.h"
</span><span class="cx"> #import "EditingRange.h"
</span><span class="cx"> #import "EditorState.h"
</span><ins>+#import "FontInfo.h"
</ins><span class="cx"> #import "InjectedBundleHitTestResult.h"
</span><span class="cx"> #import "PDFKitImports.h"
</span><span class="cx"> #import "PDFPlugin.h"
</span><span class="lines">@@ -376,22 +377,35 @@
</span><span class="cx">     send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback(attributedString, rangeToSend, callbackID));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::fontAtSelection(CallbackID callbackID)
</del><ins>+void WebPage::fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&& reply)
</ins><span class="cx"> {
</span><del>-    String fontName;
-    double fontSize = 0;
</del><span class="cx">     bool selectionHasMultipleFonts = false;
</span><del>-    Frame& frame = m_page->focusController().focusedOrMainFrame();
-    
-    if (!frame.selection().selection().isNone()) {
-        if (auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts)) {
-            if (auto ctFont = font->getCTFont()) {
-                fontName = adoptCF(CTFontCopyPostScriptName(ctFont)).get();
-                fontSize = CTFontGetSize(ctFont);
-            }
-        }
</del><ins>+    auto& frame = m_page->focusController().focusedOrMainFrame();
+
+    if (frame.selection().selection().isNone()) {
+        reply({ }, 0, false);
+        return;
</ins><span class="cx">     }
</span><del>-    send(Messages::WebPageProxy::FontAtSelectionCallback(fontName, fontSize, selectionHasMultipleFonts, callbackID));
</del><ins>+
+    auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts);
+    if (!font) {
+        reply({ }, 0, false);
+        return;
+    }
+
+    auto ctFont = font->getCTFont();
+    if (!ctFont) {
+        reply({ }, 0, false);
+        return;
+    }
+
+    auto fontDescriptor = adoptCF(CTFontCopyFontDescriptor(ctFont));
+    if (!fontDescriptor) {
+        reply({ }, 0, false);
+        return;
+    }
+
+    reply({ adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get())) }, CTFontGetSize(ctFont), selectionHasMultipleFonts);
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Tools/ChangeLog       2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2019-07-15  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [macOS 10.15] Cannot unbold selected text when the system font is used
+        https://bugs.webkit.org/show_bug.cgi?id=199788
+        <rdar://problem/52142570>
+
+        Reviewed by Tim Horton.
+
+        Add a new API test to verify that bolding and unbolding updates the
+        shared font manager's selected font.
+
+        * TestWebKitAPI/Tests/mac/FontManagerTests.mm:
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2019-07-15  Jiewen Tan  <jiewen_tan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS] SOAuthorizationSession should tell AppSSO whether the UIClient is capable of showing the extension UI
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsmacFontManagerTestsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm (247438 => 247439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm  2019-07-15 18:59:19 UTC (rev 247438)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm     2019-07-15 19:09:51 UTC (rev 247439)
</span><span class="lines">@@ -506,6 +506,37 @@
</span><span class="cx">     EXPECT_NULL(attributes[NSBackgroundColorAttributeName]);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(FontManagerTests, SetSelectedSystemFontAfterTogglingBold)
+{
+    NSFontManager *fontManager = NSFontManager.sharedFontManager;
+
+    auto webView = webViewForFontManagerTesting(NSFontManager.sharedFontManager, @"<body style='font-family: system-ui;' contenteditable>Foo</body>");
+    [webView selectWord:nil];
+    [webView waitForNextPresentationUpdate];
+    [webView waitForNextPresentationUpdate];
+    auto initialSelectedFont = retainPtr([fontManager selectedFont]);
+
+    [webView _synchronouslyExecuteEditCommand:@"ToggleBold" argument:nil];
+    [webView waitForNextPresentationUpdate];
+    auto selectedFontAfterBolding = retainPtr([fontManager selectedFont]);
+
+    [webView _synchronouslyExecuteEditCommand:@"ToggleBold" argument:nil];
+    [webView waitForNextPresentationUpdate];
+    auto selectedFontAfterUnbolding = retainPtr([fontManager selectedFont]);
+
+    [webView _synchronouslyExecuteEditCommand:@"ToggleBold" argument:nil];
+    [webView waitForNextPresentationUpdate];
+    auto selectedFontAfterBoldingAgain = retainPtr([fontManager selectedFont]);
+
+    EXPECT_WK_STREQ([initialSelectedFont fontName], [selectedFontAfterUnbolding fontName]);
+    EXPECT_WK_STREQ([selectedFontAfterBolding fontName], [selectedFontAfterBoldingAgain fontName]);
+    EXPECT_FALSE([[initialSelectedFont fontName] isEqual:[selectedFontAfterBolding fontName]]);
+    EXPECT_EQ([initialSelectedFont pointSize], 16.);
+    EXPECT_EQ([selectedFontAfterBolding pointSize], 16.);
+    EXPECT_EQ([selectedFontAfterUnbolding pointSize], 16.);
+    EXPECT_EQ([selectedFontAfterBoldingAgain pointSize], 16.);
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre>
</div>
</div>

</body>
</html>