[webkit-changes] [WebKit/WebKit] 72d333: Support text style based formatting in WKWebView
Richard Robinson
noreply at github.com
Mon Oct 10 20:55:58 PDT 2022
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 72d33310959128180edfd50213f746ee34d9465a
https://github.com/WebKit/WebKit/commit/72d33310959128180edfd50213f746ee34d9465a
Author: Richard Robinson <richard_robinson2 at apple.com>
Date: 2022-10-10 (Mon, 10 Oct 2022)
Changed paths:
M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
M Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm
M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
M Source/WebKit/UIProcess/mac/WebViewImpl.h
M Source/WebKit/UIProcess/mac/WebViewImpl.mm
M Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm
Log Message:
-----------
Support text style based formatting in WKWebView
https://bugs.webkit.org/show_bug.cgi?id=246261
rdar://100631963
Reviewed by Wenson Hsieh and Devin Rousso.
This PR adds support for text style based formatting in WKWebView for Cocoa
platforms. Clients may now set the font of a WKWebView to one of the Apple
platform text style fonts, such as `UICTFontTextStyleCallout`.
The SPI `[WKWebView _setFont:sender:]` has been added to macOS to match the
existing SPI on iOS.
Conversly, when the current text selection changes, clients may use the
existing delegate method `[WKUIDelegate _webView:didChangeFontAttributes:]`
to query for the platform text style, if any, via
```
[[[fontAttributes objectForKey:@"NSFont"] fontDescriptor] objectForKey:(__bridge NSString *)kCTFontDescriptorTextStyleAttribute];
```
which will return an `NSString *` matching one of the `UICTFontTextStyle` constants.
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView _setFont:sender:]):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _setFontForWebView:sender:]):
This now checks if the font provided is a system text style font, and if so,
overrides the font family attribute to specify the exact style instead of the
current generic system font.
* Source/WebKit/UIProcess/mac/WebViewImpl.h:
* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::_setFontForWebView):
This has effectively the same implementation as its iOS counterpart.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm:
(-[AppleFontTextStyleUIDelegate _webView:didChangeFontAttributes:]):
(TestWebKitAPI::TEST):
Canonical link: https://commits.webkit.org/255375@main
More information about the webkit-changes
mailing list