[Cocoa] Add SPI to expose typing attributes at the current selection on WKWebView
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Oct 2018 00:47:05 +0000 (00:47 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Oct 2018 00:47:05 +0000 (00:47 +0000)
commitb81252948c88183754e3b963be49147a1474ab6b
treed73f7cfbb7044daa28edf3d0a366bb8289c7870e
parent2201beb484fbe0a89df555a4979d8101061fdacf
[Cocoa] Add SPI to expose typing attributes at the current selection on WKWebView
https://bugs.webkit.org/show_bug.cgi?id=190119
<rdar://problem/44767062>

Reviewed by Tim Horton.

Source/WebKit:

Add support for new WebKit2 SPI to notify the UI delegate about font attributes when the editor state changes
(e.g. due to selection changes, or executing an edit command). See below for more detail.

Test: FontAttributes.FontAttributesAfterChangingSelection

* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:

Add a new optional `FontAttributes` member to EditorState's post-layout data. FontAttributes are computed and
sent over IPC only if the UI delegate implements the new delegate hook which requires information about font
attributes.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:

Add a new flag for the UI process to let a new web page know whether it should additionally compute font
attributes when computing editor state.

* UIProcess/API/APIUIClient.h:
(API::UIClient::needsFontAttributes const):
(API::UIClient::didChangeFontAttributes):
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didChangeEditorState]):
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::didChangeFontAttributes):

Call out to the UI delegate with a font attribute dictionary, created via FontAttributes on EditorState's
post-layout data.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setUIClient):

Update whether or not the UI process needs to know about font attributes. The UI process only requires font
attribute information if the UI delegate implements `-_webView:didChangeFontAttributes:`.

(WebKit::WebPageProxy::setNeedsFontAttributes):
(WebKit::WebPageProxy::creationParameters):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::editorStateChanged):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::editorStateChanged):

Update the cached font attributes in the UI process when receiving a new editor state update.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_cpuLimit):
(WebKit::WebPage::editorState const):
(WebKit::WebPage::setNeedsFontAttributes):

Add a new IPC hook to update whether or not the page should additionally compute font attributes. In the case
where the UI delegate changes from something that does not require font attributes to one that does, we
additionally schedule an editor state update.

(WebKit::WebPage::updateFontAttributesAfterEditorStateChange):

Private helper function to plumb FontAttributes to the UI client after an editor state change.

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Add a new API test that loads a document containing various rich text styles. This test moves the selection
around the document and checks the last set of font attributes received via the new UI delegate hook.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm: Added.
(-[FontAttributesListener _webView:didChangeFontAttributes:]):
(-[FontAttributesListener lastFontAttributes]):
(-[TestWKWebView selectElementWithIdentifier:]):
(-[TestWKWebView fontAttributesAfterNextPresentationUpdate]):
(ColorExpectation::ColorExpectation):
(ShadowExpectation::ShadowExpectation):
(checkColor):
(checkShadow):
(checkFont):
(webViewForTestingFontAttributes):
* TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236865 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/EditorState.cpp
Source/WebKit/Shared/EditorState.h
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/APIUIClient.h
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html [new file with mode: 0644]