Changeset 236865 in webkit
- Timestamp:
- Oct 4, 2018 5:47:05 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r236860 r236865 1 2018-10-04 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Add SPI to expose typing attributes at the current selection on WKWebView 4 https://bugs.webkit.org/show_bug.cgi?id=190119 5 <rdar://problem/44767062> 6 7 Reviewed by Tim Horton. 8 9 Add support for new WebKit2 SPI to notify the UI delegate about font attributes when the editor state changes 10 (e.g. due to selection changes, or executing an edit command). See below for more detail. 11 12 Test: FontAttributes.FontAttributesAfterChangingSelection 13 14 * Shared/EditorState.cpp: 15 (WebKit::EditorState::PostLayoutData::encode const): 16 (WebKit::EditorState::PostLayoutData::decode): 17 * Shared/EditorState.h: 18 19 Add a new optional `FontAttributes` member to EditorState's post-layout data. FontAttributes are computed and 20 sent over IPC only if the UI delegate implements the new delegate hook which requires information about font 21 attributes. 22 23 * Shared/WebPageCreationParameters.cpp: 24 (WebKit::WebPageCreationParameters::encode const): 25 (WebKit::WebPageCreationParameters::decode): 26 * Shared/WebPageCreationParameters.h: 27 28 Add a new flag for the UI process to let a new web page know whether it should additionally compute font 29 attributes when computing editor state. 30 31 * UIProcess/API/APIUIClient.h: 32 (API::UIClient::needsFontAttributes const): 33 (API::UIClient::didChangeFontAttributes): 34 * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: 35 * UIProcess/API/Cocoa/WKWebView.mm: 36 (-[WKWebView _didChangeEditorState]): 37 * UIProcess/Cocoa/UIDelegate.h: 38 * UIProcess/Cocoa/UIDelegate.mm: 39 (WebKit::UIDelegate::setDelegate): 40 (WebKit::UIDelegate::UIClient::didChangeFontAttributes): 41 42 Call out to the UI delegate with a font attribute dictionary, created via FontAttributes on EditorState's 43 post-layout data. 44 45 * UIProcess/WebPageProxy.cpp: 46 (WebKit::WebPageProxy::setUIClient): 47 48 Update whether or not the UI process needs to know about font attributes. The UI process only requires font 49 attribute information if the UI delegate implements `-_webView:didChangeFontAttributes:`. 50 51 (WebKit::WebPageProxy::setNeedsFontAttributes): 52 (WebKit::WebPageProxy::creationParameters): 53 * UIProcess/WebPageProxy.h: 54 * UIProcess/ios/WebPageProxyIOS.mm: 55 (WebKit::WebPageProxy::editorStateChanged): 56 * UIProcess/mac/WebPageProxyMac.mm: 57 (WebKit::WebPageProxy::editorStateChanged): 58 59 Update the cached font attributes in the UI process when receiving a new editor state update. 60 61 * WebProcess/WebPage/WebPage.cpp: 62 (WebKit::m_cpuLimit): 63 (WebKit::WebPage::editorState const): 64 (WebKit::WebPage::setNeedsFontAttributes): 65 66 Add a new IPC hook to update whether or not the page should additionally compute font attributes. In the case 67 where the UI delegate changes from something that does not require font attributes to one that does, we 68 additionally schedule an editor state update. 69 70 (WebKit::WebPage::updateFontAttributesAfterEditorStateChange): 71 72 Private helper function to plumb FontAttributes to the UI client after an editor state change. 73 74 * WebProcess/WebPage/WebPage.h: 75 * WebProcess/WebPage/WebPage.messages.in: 76 1 77 2018-10-04 Jeremy Jones <jeremyj@apple.com> 2 78 -
trunk/Source/WebKit/Shared/EditorState.cpp
r235011 r236865 139 139 encoder << stringForCandidateRequest; 140 140 #endif 141 encoder << fontAttributes; 141 142 encoder << canCut; 142 143 encoder << canCopy; … … 200 201 return false; 201 202 #endif 203 204 std::optional<std::optional<FontAttributes>> optionalFontAttributes; 205 decoder >> optionalFontAttributes; 206 if (!optionalFontAttributes) 207 return false; 208 209 result.fontAttributes = optionalFontAttributes.value(); 202 210 203 211 if (!decoder.decode(result.canCut)) -
trunk/Source/WebKit/Shared/EditorState.h
r235011 r236865 28 28 #include "ArgumentCoders.h" 29 29 #include <WebCore/Color.h> 30 #include <WebCore/FontAttributes.h> 30 31 #include <WebCore/IntRect.h> 31 32 #include <wtf/text/WTFString.h> … … 115 116 #endif 116 117 118 std::optional<WebCore::FontAttributes> fontAttributes; 119 117 120 bool canCut { false }; 118 121 bool canCopy { false }; -
trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp
r233552 r236865 111 111 encoder << hasRegisteredServiceWorkers; 112 112 #endif 113 encoder << needsFontAttributes; 113 114 encoder << iceCandidateFilteringEnabled; 114 115 encoder << enumeratingAllNetworkInterfacesEnabled; … … 306 307 #endif 307 308 309 if (!decoder.decode(parameters.needsFontAttributes)) 310 return std::nullopt; 311 308 312 if (!decoder.decode(parameters.iceCandidateFilteringEnabled)) 309 313 return std::nullopt; -
trunk/Source/WebKit/Shared/WebPageCreationParameters.h
r234920 r236865 174 174 #endif 175 175 176 bool needsFontAttributes { false }; 177 176 178 // WebRTC members. 177 179 bool iceCandidateFilteringEnabled { true }; -
trunk/Source/WebKit/UIProcess/API/APIUIClient.h
r231457 r236865 41 41 namespace WebCore { 42 42 class ResourceRequest; 43 struct FontAttributes; 43 44 struct SecurityOriginData; 44 45 struct WindowFeatures; … … 124 125 } 125 126 127 virtual bool needsFontAttributes() const { return false; } 128 virtual void didChangeFontAttributes(const WebCore::FontAttributes&) { } 129 126 130 virtual bool runOpenPanel(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, OpenPanelParameters*, WebKit::WebOpenPanelResultListenerProxy*) { return false; } 127 131 virtual void decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, Function<void(bool)>&) { } -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
r235961 r236865 121 121 122 122 - (void)_webView:(WKWebView *)webView requestStorageAccessPanelForDomain:(NSString *)requestingDomain underCurrentDomain:(NSString *)currentDomain completionHandler:(void (^)(BOOL result))completionHandler WK_API_AVAILABLE(macosx(10.14), ios(12.0)); 123 124 - (void)_webView:(WKWebView *)webView didChangeFontAttributes:(NSDictionary<NSString *, id> *)fontAttributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 123 125 124 126 #if TARGET_OS_IPHONE -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r236724 r236865 1251 1251 { 1252 1252 id <WKUIDelegatePrivate> uiDelegate = (id <WKUIDelegatePrivate>)self.UIDelegate; 1253 1254 // FIXME: We should either rename -_webView:editorStateDidChange: to clarify that it's only intended for use when testing, 1255 // or remove it entirely and use -_webView:didChangeFontAttributes: instead once text alignment is supported in the set of 1256 // font attributes. 1253 1257 if ([uiDelegate respondsToSelector:@selector(_webView:editorStateDidChange:)]) 1254 1258 [uiDelegate _webView:self editorStateDidChange:dictionaryRepresentationForEditorState(_page->editorState())]; -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h
r235259 r236865 122 122 void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, API::Data&) final; 123 123 #endif 124 bool needsFontAttributes() const final { return m_uiDelegate.m_delegateMethods.webViewDidChangeFontAttributes; } 125 void didChangeFontAttributes(const WebCore::FontAttributes&) final; 124 126 bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final; 125 127 bool checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final; … … 199 201 bool webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler : 1; 200 202 bool webViewMediaCaptureStateDidChange : 1; 203 bool webViewDidChangeFontAttributes : 1; 201 204 #if PLATFORM(IOS) 202 205 #if HAVE(APP_LINKS) -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
r235935 r236865 51 51 #import "_WKFrameHandleInternal.h" 52 52 #import "_WKHitTestResultInternal.h" 53 #import <WebCore/FontAttributes.h> 53 54 #import <WebCore/SecurityOriginData.h> 54 55 #import <WebCore/URL.h> … … 153 154 m_delegateMethods.webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler = [delegate respondsToSelector:@selector(_webView:checkUserMediaPermissionForURL:mainFrameURL:frameIdentifier:decisionHandler:)]; 154 155 m_delegateMethods.webViewMediaCaptureStateDidChange = [delegate respondsToSelector:@selector(_webView:mediaCaptureStateDidChange:)]; 156 m_delegateMethods.webViewDidChangeFontAttributes = [delegate respondsToSelector:@selector(_webView:didChangeFontAttributes:)]; 155 157 m_delegateMethods.dataDetectionContextForWebView = [delegate respondsToSelector:@selector(_dataDetectionContextForWebView:)]; 156 158 m_delegateMethods.webViewImageOrMediaDocumentSizeChanged = [delegate respondsToSelector:@selector(_webView:imageOrMediaDocumentSizeChanged:)]; … … 883 885 } 884 886 #endif 887 888 void UIDelegate::UIClient::didChangeFontAttributes(const WebCore::FontAttributes& fontAttributes) 889 { 890 if (!needsFontAttributes()) 891 return; 892 893 auto privateUIDelegate = (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get(); 894 [privateUIDelegate _webView:m_uiDelegate.m_webView didChangeFontAttributes:fontAttributes.createDictionary().get()]; 895 } 885 896 886 897 bool UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaOrigin, API::SecurityOrigin& topLevelOrigin, UserMediaPermissionRequestProxy& request) -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r236762 r236865 607 607 m_process->send(Messages::WebPage::SetCanRunBeforeUnloadConfirmPanel(m_uiClient->canRunBeforeUnloadConfirmPanel()), m_pageID); 608 608 setCanRunModal(m_uiClient->canRunModal()); 609 setNeedsFontAttributes(m_uiClient->needsFontAttributes()); 609 610 } 610 611 … … 1732 1733 auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken()); 1733 1734 m_process->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID); 1735 } 1736 1737 void WebPageProxy::updateFontAttributesAfterEditorStateChange() 1738 { 1739 m_cachedFontAttributesAtSelectionStart.reset(); 1740 1741 if (m_editorState.isMissingPostLayoutData) 1742 return; 1743 1744 if (auto fontAttributes = m_editorState.postLayoutData().fontAttributes) { 1745 m_uiClient->didChangeFontAttributes(*fontAttributes); 1746 m_cachedFontAttributesAtSelectionStart = WTFMove(fontAttributes); 1747 } 1748 } 1749 1750 void WebPageProxy::setNeedsFontAttributes(bool needsFontAttributes) 1751 { 1752 if (m_needsFontAttributes == needsFontAttributes) 1753 return; 1754 1755 m_needsFontAttributes = needsFontAttributes; 1756 1757 if (isValid()) 1758 m_process->send(Messages::WebPage::SetNeedsFontAttributes(needsFontAttributes), m_pageID); 1734 1759 } 1735 1760 … … 6355 6380 #endif 6356 6381 6382 parameters.needsFontAttributes = m_needsFontAttributes; 6383 6357 6384 m_process->addWebUserContentControllerProxy(m_userContentController, parameters); 6358 6385 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r236746 r236865 1848 1848 void continueNavigationInNewProcess(API::Navigation&, Ref<WebProcessProxy>&&); 1849 1849 1850 void setNeedsFontAttributes(bool); 1851 void updateFontAttributesAfterEditorStateChange(); 1852 1850 1853 WeakPtr<PageClient> m_pageClient; 1851 1854 Ref<API::PageConfiguration> m_configuration; … … 2260 2263 RunLoop::Timer<WebPageProxy> m_resetRecentCrashCountTimer; 2261 2264 unsigned m_recentCrashCount { 0 }; 2265 2266 bool m_needsFontAttributes { false }; 2262 2267 }; 2263 2268 -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r236724 r236865 1054 1054 1055 1055 m_editorState = editorState; 1056 m_cachedFontAttributesAtSelectionStart.reset();1057 1056 1058 1057 // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood). … … 1066 1065 // even during composition to support phrase boundary gesture. 1067 1066 pageClient().selectionDidChange(); 1067 updateFontAttributesAfterEditorStateChange(); 1068 1068 } 1069 1069 -
trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
r236724 r236865 651 651 652 652 m_editorState = editorState; 653 m_cachedFontAttributesAtSelectionStart.reset();654 653 655 654 // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood). … … 661 660 662 661 pageClient().selectionDidChange(); 662 updateFontAttributesAfterEditorStateChange(); 663 663 } 664 664 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r236724 r236865 600 600 #endif 601 601 602 m_needsFontAttributes = parameters.needsFontAttributes; 603 602 604 #if ENABLE(WEB_RTC) 603 605 if (!parameters.iceCandidateFilteringEnabled) … … 935 937 postLayoutData.canCopy = editor.canCopy(); 936 938 postLayoutData.canPaste = editor.canPaste(); 939 940 if (m_needsFontAttributes) 941 postLayoutData.fontAttributes = editor.fontAttributesAtSelectionStart(); 937 942 938 943 #if PLATFORM(COCOA) … … 2492 2497 } 2493 2498 2499 void WebPage::setNeedsFontAttributes(bool needsFontAttributes) 2500 { 2501 if (m_needsFontAttributes == needsFontAttributes) 2502 return; 2503 2504 m_needsFontAttributes = needsFontAttributes; 2505 2506 if (m_needsFontAttributes) 2507 sendPartialEditorStateAndSchedulePostLayoutUpdate(); 2508 } 2509 2494 2510 void WebPage::restoreSessionInternal(const Vector<BackForwardListItemState>& itemStates, WasRestoredByAPIRequest restoredByAPIRequest, WebBackForwardListProxy::OverwriteExistingItem overwrite) 2495 2511 { -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r236724 r236865 1180 1180 void setEditable(bool); 1181 1181 1182 void setNeedsFontAttributes(bool); 1183 1182 1184 void mouseEvent(const WebMouseEvent&); 1183 1185 void keyEvent(const WebKeyboardEvent&); … … 1741 1743 1742 1744 bool m_isSuspended { false }; 1745 bool m_needsFontAttributes { false }; 1743 1746 }; 1744 1747 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r236724 r236865 210 210 ExecuteEditCommand(String name, String argument) 211 211 212 SetNeedsFontAttributes(bool needsFontAttributes) 213 212 214 RequestFontAttributesAtSelectionStart(WebKit::CallbackID callbackID) 213 215 -
trunk/Tools/ChangeLog
r236858 r236865 1 2018-10-04 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Add SPI to expose typing attributes at the current selection on WKWebView 4 https://bugs.webkit.org/show_bug.cgi?id=190119 5 <rdar://problem/44767062> 6 7 Reviewed by Tim Horton. 8 9 Add a new API test that loads a document containing various rich text styles. This test moves the selection 10 around the document and checks the last set of font attributes received via the new UI delegate hook. 11 12 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 13 * TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm: Added. 14 (-[FontAttributesListener _webView:didChangeFontAttributes:]): 15 (-[FontAttributesListener lastFontAttributes]): 16 (-[TestWKWebView selectElementWithIdentifier:]): 17 (-[TestWKWebView fontAttributesAfterNextPresentationUpdate]): 18 (ColorExpectation::ColorExpectation): 19 (ShadowExpectation::ShadowExpectation): 20 (checkColor): 21 (checkShadow): 22 (checkFont): 23 (webViewForTestingFontAttributes): 24 * TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html: Added. 25 1 26 2018-10-04 Alan Coon <alancoon@apple.com> 2 27 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r236854 r236865 109 109 2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; }; 110 110 2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; }; 111 2E92B8F7216490D4005B64F0 /* rich-text-attributes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E92B8F6216490C3005B64F0 /* rich-text-attributes.html */; }; 112 2E92B8FA2164A0C1005B64F0 /* FontAttributes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E92B8F8216490EA005B64F0 /* FontAttributes.mm */; }; 111 113 2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E9896141D8F092B00739892 /* text-and-password-inputs.html */; }; 112 114 2EB29D5E1F762DB90023A5F1 /* dump-datatransfer-types.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EB29D5D1F762DA50023A5F1 /* dump-datatransfer-types.html */; }; … … 1155 1157 A12DDC001E8373E700CF6CAE /* rendered-image-excluding-overflow.html in Copy Resources */, 1156 1158 F46849C01EEF5EF300B937FE /* rich-and-plain-text.html in Copy Resources */, 1159 2E92B8F7216490D4005B64F0 /* rich-text-attributes.html in Copy Resources */, 1157 1160 0F5651F91FCE513500310FBC /* scroll-to-anchor.html in Copy Resources */, 1158 1161 F4E0A296211FC5FB00AF7C7F /* selected-text-and-textarea.html in Copy Resources */, … … 1357 1360 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; }; 1358 1361 2E7EF7AC1F266A8100DFB67C /* AppKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppKitSPI.h; sourceTree = "<group>"; }; 1362 2E92B8F6216490C3005B64F0 /* rich-text-attributes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "rich-text-attributes.html"; sourceTree = "<group>"; }; 1363 2E92B8F8216490EA005B64F0 /* FontAttributes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FontAttributes.mm; sourceTree = "<group>"; }; 1359 1364 2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; }; 1360 1365 2EB29D5D1F762DA50023A5F1 /* dump-datatransfer-types.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "dump-datatransfer-types.html"; sourceTree = "<group>"; }; … … 2341 2346 2D8104CB1BEC13E70020DA46 /* FindInPage.mm */, 2342 2347 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */, 2348 2E92B8F8216490EA005B64F0 /* FontAttributes.mm */, 2343 2349 5CB5B3BD1FFC517E00C27BB0 /* FrameHandleSerialization.mm */, 2344 2350 CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */, … … 2761 2767 A12DDBFF1E8373C100CF6CAE /* rendered-image-excluding-overflow.html */, 2762 2768 F46849BF1EEF5EDC00B937FE /* rich-and-plain-text.html */, 2769 2E92B8F6216490C3005B64F0 /* rich-text-attributes.html */, 2763 2770 F4E0A295211FC5A300AF7C7F /* selected-text-and-textarea.html */, 2764 2771 F4D65DA71F5E46C0009D8C27 /* selected-text-image-link-and-editable.html */, … … 3801 3808 7A909A801D877480007E10F8 /* FloatSize.cpp in Sources */, 3802 3809 F4BC0B142146C849002A0478 /* FocusPreservationTests.mm in Sources */, 3810 2E92B8FA2164A0C1005B64F0 /* FontAttributes.mm in Sources */, 3803 3811 1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */, 3804 3812 F456AB1C213EDBA300CB2CEF /* FontManagerTests.mm in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.