Changeset 271187 in webkit
- Timestamp:
- Jan 5, 2021, 7:03:44 PM (6 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 8 edited
-
ChangeLog (modified) (1 diff)
-
UIProcess/Cocoa/WebViewImpl.mm (modified) (2 diffs)
-
UIProcess/WebPageProxy.h (modified) (3 diffs)
-
UIProcess/WebPageProxy.messages.in (modified) (1 diff)
-
UIProcess/mac/WebPageProxyMac.mm (modified) (1 diff)
-
WebProcess/WebPage/WebPage.h (modified) (1 diff)
-
WebProcess/WebPage/WebPage.messages.in (modified) (1 diff)
-
WebProcess/WebPage/mac/WebPageMac.mm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r271184 r271187 1 2021-01-05 Alex Christensen <achristensen@webkit.org> 2 3 Use sendWithAsyncReply instead of AttributedStringForCharacterRangeCallback and FontAtSelectionCallback 4 https://bugs.webkit.org/show_bug.cgi?id=220344 5 6 Reviewed by Geoffrey Garen. 7 8 * UIProcess/Cocoa/WebViewImpl.mm: 9 (WebKit::WebViewImpl::updateFontManagerIfNeeded): 10 (WebKit::WebViewImpl::attributedSubstringForProposedRange): 11 * UIProcess/WebPageProxy.h: 12 * UIProcess/WebPageProxy.messages.in: 13 * UIProcess/mac/WebPageProxyMac.mm: 14 (WebKit::WebPageProxy::attributedSubstringForCharacterRangeAsync): 15 (WebKit::WebPageProxy::fontAtSelection): 16 (WebKit::WebPageProxy::attributedStringForCharacterRangeCallback): Deleted. 17 (WebKit::WebPageProxy::fontAtSelectionCallback): Deleted. 18 * WebProcess/WebPage/WebPage.h: 19 * WebProcess/WebPage/WebPage.messages.in: 20 * WebProcess/WebPage/mac/WebPageMac.mm: 21 (WebKit::WebPage::attributedSubstringForCharacterRangeAsync): 22 (WebKit::WebPage::fontAtSelection): 23 1 24 2021-01-05 John Wilander <wilander@apple.com> 2 25 -
trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
r271162 r271187 2952 2952 return; 2953 2953 2954 m_page->fontAtSelection([](const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts, CallbackBase::Error error) { 2955 if (error != CallbackBase::Error::None) 2956 return; 2954 m_page->fontAtSelection([](const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts) { 2957 2955 2958 2956 BEGIN_BLOCK_OBJC_EXCEPTIONS … … 5026 5024 } 5027 5025 5028 void WebViewImpl::attributedSubstringForProposedRange(NSRange proposedRange, void(^completionHandlerPtr)(NSAttributedString *attrString, NSRange actualRange)) 5029 { 5030 auto completionHandler = adoptNS([completionHandlerPtr copy]); 5031 5026 void WebViewImpl::attributedSubstringForProposedRange(NSRange proposedRange, void(^completionHandler)(NSAttributedString *attrString, NSRange actualRange)) 5027 { 5032 5028 LOG(TextInput, "attributedSubstringFromRange:(%u, %u)", proposedRange.location, proposedRange.length); 5033 m_page->attributedSubstringForCharacterRangeAsync(proposedRange, [completionHandler](const WebCore::AttributedString& string, const EditingRange& actualRange, WebKit::CallbackBase::Error error) { 5034 void (^completionHandlerBlock)(NSAttributedString *, NSRange) = (void (^)(NSAttributedString *, NSRange))completionHandler.get(); 5035 if (error != WebKit::CallbackBase::Error::None) { 5036 LOG(TextInput, " ...attributedSubstringFromRange failed."); 5037 completionHandlerBlock(0, NSMakeRange(NSNotFound, 0)); 5038 return; 5039 } 5029 m_page->attributedSubstringForCharacterRangeAsync(proposedRange, [completionHandler = makeBlockPtr(completionHandler)](const WebCore::AttributedString& string, const EditingRange& actualRange) { 5040 5030 LOG(TextInput, " -> attributedSubstringFromRange returned %@", string.string.get()); 5041 completionHandler Block(string.string.get(), actualRange);5031 completionHandler(string.string.get(), actualRange); 5042 5032 }); 5043 5033 } -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r271171 r271187 400 400 #endif 401 401 402 #if PLATFORM(MAC)403 typedef GenericCallback<const WebCore::AttributedString&, const EditingRange&> AttributedStringForCharacterRangeCallback;404 typedef GenericCallback<const FontInfo&, double, bool> FontAtSelectionCallback;405 #endif406 407 402 #if PLATFORM(IOS_FAMILY) 408 403 typedef GenericCallback<const WebCore::IntPoint&, GestureType, GestureRecognizerState, OptionSet<SelectionFlags>> GestureCallback; … … 906 901 907 902 #if PLATFORM(MAC) 908 void attributedSubstringForCharacterRangeAsync(const EditingRange&, Function<void(const WebCore::AttributedString&, const EditingRange&, CallbackBase::Error)>&&);909 void fontAtSelection( Function<void(const FontInfo&, double, bool, CallbackBase::Error)>&&);903 void attributedSubstringForCharacterRangeAsync(const EditingRange&, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&&); 904 void fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&&); 910 905 911 906 void startWindowDrag(); … … 2159 2154 #endif 2160 2155 #if PLATFORM(MAC) 2161 void attributedStringForCharacterRangeCallback(const WebCore::AttributedString&, const EditingRange&, CallbackID);2162 2156 void fontAtSelectionCallback(const FontInfo&, double, bool, CallbackID); 2163 2157 #endif -
trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in
r271162 r271187 174 174 ApplicationManifestCallback(Optional<WebCore::ApplicationManifest> manifest, WebKit::CallbackID callbackID) 175 175 #endif 176 #if PLATFORM(MAC)177 AttributedStringForCharacterRangeCallback(struct WebCore::AttributedString string, struct WebKit::EditingRange actualRange, WebKit::CallbackID callbackID)178 FontAtSelectionCallback(struct WebKit::FontInfo fontInfo, double fontSize, bool selectionHasMultipleFonts, WebKit::CallbackID callbackID)179 #endif180 176 #if PLATFORM(IOS_FAMILY) 181 177 GestureCallback(WebCore::IntPoint point, enum:uint8_t WebKit::GestureType gestureType, enum:uint8_t WebKit::GestureRecognizerState gestureState, OptionSet<WebKit::SelectionFlags> flags, WebKit::CallbackID callbackID) -
trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
r270946 r271187 193 193 } 194 194 195 void WebPageProxy::attributedSubstringForCharacterRangeAsync(const EditingRange& range, Function<void(const WebCore::AttributedString&, const EditingRange&, CallbackBase::Error)>&& callbackFunction)195 void WebPageProxy::attributedSubstringForCharacterRangeAsync(const EditingRange& range, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&& callbackFunction) 196 196 { 197 197 if (!hasRunningProcess()) { 198 callbackFunction({ }, EditingRange(), CallbackBase::Error::Unknown); 199 return; 200 } 201 202 auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::attributedSubstringForCharacterRangeAsync"_s)); 203 204 send(Messages::WebPage::AttributedSubstringForCharacterRangeAsync(range, callbackID)); 205 } 206 207 void WebPageProxy::attributedStringForCharacterRangeCallback(const WebCore::AttributedString& string, const EditingRange& actualRange, CallbackID callbackID) 208 { 209 MESSAGE_CHECK(actualRange.isValid()); 210 211 auto callback = m_callbacks.take<AttributedStringForCharacterRangeCallback>(callbackID); 212 if (!callback) { 213 // FIXME: Log error or assert. 214 // this can validly happen if a load invalidated the callback, though 215 return; 216 } 217 218 callback->performCallbackWithReturnValue(string, actualRange); 219 } 220 221 void WebPageProxy::fontAtSelection(Function<void(const FontInfo&, double, bool, CallbackBase::Error)>&& callback) 198 callbackFunction({ }, { }); 199 return; 200 } 201 202 sendWithAsyncReply(Messages::WebPage::AttributedSubstringForCharacterRangeAsync(range), WTFMove(callbackFunction)); 203 } 204 205 void WebPageProxy::fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&& callback) 222 206 { 223 207 if (!hasRunningProcess()) { 224 callback({ }, 0, false, CallbackBase::Error::Unknown); 225 return; 226 } 227 228 auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::fontAtSelection"_s)); 229 send(Messages::WebPage::FontAtSelection(callbackID)); 230 } 231 232 void WebPageProxy::fontAtSelectionCallback(const FontInfo& fontInfo, double fontSize, bool selectionHasMultipleFonts, CallbackID callbackID) 233 { 234 auto callback = m_callbacks.take<FontAtSelectionCallback>(callbackID); 235 if (!callback) { 236 // FIXME: Log error or assert. 237 return; 238 } 239 240 callback->performCallbackWithReturnValue(fontInfo, fontSize, selectionHasMultipleFonts); 208 callback({ }, 0, false); 209 return; 210 } 211 212 sendWithAsyncReply(Messages::WebPage::FontAtSelection(), WTFMove(callback)); 241 213 } 242 214 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r271171 r271187 904 904 905 905 #if PLATFORM(MAC) 906 void attributedSubstringForCharacterRangeAsync(const EditingRange&, C allbackID);907 void fontAtSelection(C allbackID);906 void attributedSubstringForCharacterRangeAsync(const EditingRange&, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&&); 907 void fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&&); 908 908 #endif 909 909 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r271171 r271187 458 458 #endif 459 459 #if PLATFORM(MAC) 460 AttributedSubstringForCharacterRangeAsync(struct WebKit::EditingRange range , WebKit::CallbackID callbackID);461 FontAtSelection( WebKit::CallbackID callbackID)460 AttributedSubstringForCharacterRangeAsync(struct WebKit::EditingRange range) -> (struct WebCore::AttributedString string, struct WebKit::EditingRange range) Async 461 FontAtSelection() -> (struct WebKit::FontInfo fontInfo, double fontSize, bool selectionHasMultipleFonts) Async 462 462 #endif 463 463 -
trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
r268386 r271187 330 330 } 331 331 332 void WebPage::attributedSubstringForCharacterRangeAsync(const EditingRange& editingRange, C allbackID callbackID)332 void WebPage::attributedSubstringForCharacterRangeAsync(const EditingRange& editingRange, CompletionHandler<void(const WebCore::AttributedString&, const EditingRange&)>&& completionHandler) 333 333 { 334 334 Frame& frame = m_page->focusController().focusedOrMainFrame(); … … 336 336 const VisibleSelection& selection = frame.selection().selection(); 337 337 if (selection.isNone() || !selection.isContentEditable() || selection.isInPasswordField()) { 338 send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID));338 completionHandler({ }, { }); 339 339 return; 340 340 } … … 342 342 auto range = EditingRange::toRange(frame, editingRange); 343 343 if (!range) { 344 send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ }, EditingRange(), callbackID));344 completionHandler({ }, { }); 345 345 return; 346 346 } … … 361 361 if (!rangeToSend.isValid()) { 362 362 // Send an empty EditingRange as a last resort for <rdar://problem/27078089>. 363 send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ WTFMove(attributedString), nil }, EditingRange(), callbackID));364 return; 365 } 366 367 send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback({ WTFMove(attributedString), nil }, rangeToSend, callbackID));368 } 369 370 void WebPage::fontAtSelection(C allbackID callbackID)363 completionHandler({ WTFMove(attributedString), nil }, EditingRange()); 364 return; 365 } 366 367 completionHandler({ WTFMove(attributedString), nil }, rangeToSend); 368 } 369 370 void WebPage::fontAtSelection(CompletionHandler<void(const FontInfo&, double, bool)>&& completionHandler) 371 371 { 372 372 bool selectionHasMultipleFonts = false; … … 374 374 375 375 if (frame.selection().selection().isNone()) { 376 send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));376 completionHandler({ }, 0, false); 377 377 return; 378 378 } … … 380 380 auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts); 381 381 if (!font) { 382 send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));382 completionHandler({ }, 0, false); 383 383 return; 384 384 } … … 386 386 auto ctFont = font->getCTFont(); 387 387 if (!ctFont) { 388 send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));388 completionHandler({ }, 0, false); 389 389 return; 390 390 } … … 392 392 auto fontDescriptor = adoptCF(CTFontCopyFontDescriptor(ctFont)); 393 393 if (!fontDescriptor) { 394 send(Messages::WebPageProxy::FontAtSelectionCallback({ }, 0, false, callbackID));395 return; 396 } 397 398 send(Messages::WebPageProxy::FontAtSelectionCallback({ adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get())) }, CTFontGetSize(ctFont), selectionHasMultipleFonts, callbackID));394 completionHandler({ }, 0, false); 395 return; 396 } 397 398 completionHandler({ adoptCF(CTFontDescriptorCopyAttributes(fontDescriptor.get())) }, CTFontGetSize(ctFont), selectionHasMultipleFonts); 399 399 } 400 400
Note:
See TracChangeset
for help on using the changeset viewer.