RESOLVED FIXED 190119
[Cocoa] Add SPI to expose typing attributes at the current selection on WKWebView
https://bugs.webkit.org/show_bug.cgi?id=190119
Summary [Cocoa] Add SPI to expose typing attributes at the current selection on WKWeb...
Wenson Hsieh
Reported 2018-09-30 14:58:38 PDT
Attachments
Patch (39.70 KB, patch)
2018-10-03 08:39 PDT, Wenson Hsieh
achristensen: review-
Patch (45.69 KB, patch)
2018-10-03 14:39 PDT, Wenson Hsieh
thorton: review+
Patch for EWS (45.52 KB, patch)
2018-10-04 16:59 PDT, Wenson Hsieh
no flags
Wenson Hsieh
Comment 1 2018-10-03 08:39:45 PDT
Alex Christensen
Comment 2 2018-10-03 11:07:40 PDT
Comment on attachment 351524 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=351524&action=review > Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h:124 > +- (void)_webView:(WKWebView *)webView fontAttributesDidChange:(NSDictionary<NSString *, id> *)fontAttributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); Why not use a KVO observable property on the WKWebView? This sounds exactly like what KVO is for. > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1264 > + if ([uiDelegate respondsToSelector:@selector(_webView:fontAttributesDidChange:)]) { We cache the results of all the respondsToSelector booleans in UIDelegate.h for performance. Reading 1 bit is much faster than respondsToSelector.
Wenson Hsieh
Comment 3 2018-10-03 14:34:53 PDT
(In reply to Alex Christensen from comment #2) > Comment on attachment 351524 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=351524&action=review > > > Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h:124 > > +- (void)_webView:(WKWebView *)webView fontAttributesDidChange:(NSDictionary<NSString *, id> *)fontAttributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > > Why not use a KVO observable property on the WKWebView? This sounds exactly > like what KVO is for. Yes, this would be an elegant interface, but I'd need to know whether or not to compute and propagate font attributes when computing editor state, so I'd need to override -addObserver: and -removeObserver: to know whether we need font attributes in the UI process. Given this, I don't think adding a new delegate method is worse than this KVO-able property. > > > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1264 > > + if ([uiDelegate respondsToSelector:@selector(_webView:fontAttributesDidChange:)]) { > > We cache the results of all the respondsToSelector booleans in UIDelegate.h > for performance. Reading 1 bit is much faster than respondsToSelector. Good call! Done.
Wenson Hsieh
Comment 4 2018-10-03 14:39:51 PDT
Tim Horton
Comment 5 2018-10-04 15:07:22 PDT
Comment on attachment 351547 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=351547&action=review > Source/WebKit/ChangeLog:9 > + Add support new WebKit2 SPI to notify the UI delegate about font attributes when the editor state changes (e.g. "add support new"? > Source/WebKit/Shared/EditorState.cpp:141 > + encoder << !!fontAttributes; Don't we have the ability to directly encode optionals now? > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1255 > + // FIXME: We should either rename -_webView:editorStateDidChange: to clarify that it's only intended for use when testing, > + // or remove it entirely and use -_webView:fontAttributesDidChange: instead once text alignment is supported in the set of Are there any clients other than our testing code? If not, maybe just rename it right away? > Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:156 > + m_delegateMethods.webViewFontAttributesDidChange = [delegate respondsToSelector:@selector(_webView:fontAttributesDidChange:)]; I think "webView:didChangeFontAttributes:" is more traditional style, but I see you were copying an existing method. > Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm:94 > +enum class Nullability : uint8_t { Null, NonNull }; Is this about nullability (can it be null) or nullity (is it null)
Wenson Hsieh
Comment 6 2018-10-04 16:39:44 PDT
Comment on attachment 351547 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=351547&action=review >> Source/WebKit/ChangeLog:9 >> + Add support new WebKit2 SPI to notify the UI delegate about font attributes when the editor state changes (e.g. > > "add support new"? I accidentally a word :P >> Source/WebKit/Shared/EditorState.cpp:141 >> + encoder << !!fontAttributes; > > Don't we have the ability to directly encode optionals now? Sounds good — I changed it to this on the encoding side: encoder << fontAttributes; ...and this on the decoding side: std::optional<std::optional<FontAttributes>> optionalFontAttributes; decoder >> optionalFontAttributes; if (!optionalFontAttributes) return false; result.fontAttributes = optionalFontAttributes.value(); >> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1255 >> + // or remove it entirely and use -_webView:fontAttributesDidChange: instead once text alignment is supported in the set of > > Are there any clients other than our testing code? If not, maybe just rename it right away? There aren't any clients apart from our testing code (at least, from what I can tell using internal tooling). I'm going to clean this up in a followup patch, when I decide what I want to do with these. One idea I have is refactoring them to actually test user-facing state (e.g. calling -canPerformAction:withSender:, -textStylingAtPosition:inDirection:, etc.), but I could also repurpose those tests to be about font attributes. Or I could simply rename the delegate hook. >> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:156 >> + m_delegateMethods.webViewFontAttributesDidChange = [delegate respondsToSelector:@selector(_webView:fontAttributesDidChange:)]; > > I think "webView:didChangeFontAttributes:" is more traditional style, but I see you were copying an existing method. Sounds good — renamed to `_webView:didChangeFontAttributes:` >> Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm:94 >> +enum class Nullability : uint8_t { Null, NonNull }; > > Is this about nullability (can it be null) or nullity (is it null) It is indeed about Nullity — renamed!
Wenson Hsieh
Comment 7 2018-10-04 16:59:41 PDT
Created attachment 351644 [details] Patch for EWS
WebKit Commit Bot
Comment 8 2018-10-04 17:47:14 PDT
Comment on attachment 351644 [details] Patch for EWS Clearing flags on attachment: 351644 Committed r236865: <https://trac.webkit.org/changeset/236865>
Note You need to log in before you can comment on or make changes to this bug.