- Revision
- 245595
- Author
- [email protected]
- Date
- 2019-05-21 14:54:05 -0700 (Tue, 21 May 2019)
Log Message
The cost of WebViewImpl::hasMarkedTextWithCompletionHandler should not increase with document size
https://bugs.webkit.org/show_bug.cgi?id=198075
<rdar://problem/37560103>
Reviewed by Tim Horton.
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::hasMarkedTextWithCompletionHandler):
Refactor hasMarkedTextWithCompletionHandler to use Editor::hasComposition, instead of computing the actual
marked text range. The latter is more expensive and unnecessary, since it uses TextIterator from the document
root to find editing offsets. This makes the cost of determining whether there is marked text proportional to
the document size.
This matches behavior in legacy WebKit, as well as iOS.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::hasMarkedText):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::hasMarkedText):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (245594 => 245595)
--- trunk/Source/WebKit/ChangeLog 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/ChangeLog 2019-05-21 21:54:05 UTC (rev 245595)
@@ -1,3 +1,29 @@
+2019-05-21 Wenson Hsieh <[email protected]>
+
+ The cost of WebViewImpl::hasMarkedTextWithCompletionHandler should not increase with document size
+ https://bugs.webkit.org/show_bug.cgi?id=198075
+ <rdar://problem/37560103>
+
+ Reviewed by Tim Horton.
+
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::hasMarkedTextWithCompletionHandler):
+
+ Refactor hasMarkedTextWithCompletionHandler to use Editor::hasComposition, instead of computing the actual
+ marked text range. The latter is more expensive and unnecessary, since it uses TextIterator from the document
+ root to find editing offsets. This makes the cost of determining whether there is marked text proportional to
+ the document size.
+
+ This matches behavior in legacy WebKit, as well as iOS.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::hasMarkedText):
+ * UIProcess/WebPageProxy.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::hasMarkedText):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+
2019-05-21 Jiewen Tan <[email protected]>
[WebAuthN] Make WebAuthN default on only on macOS
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (245594 => 245595)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2019-05-21 21:54:05 UTC (rev 245595)
@@ -4812,21 +4812,12 @@
});
}
-void WebViewImpl::hasMarkedTextWithCompletionHandler(void(^completionHandlerPtr)(BOOL hasMarkedText))
+void WebViewImpl::hasMarkedTextWithCompletionHandler(void(^completionHandler)(BOOL hasMarkedText))
{
- auto completionHandler = adoptNS([completionHandlerPtr copy]);
-
LOG(TextInput, "hasMarkedText");
- m_page->getMarkedRangeAsync([completionHandler](const EditingRange& editingRangeResult, WebKit::CallbackBase::Error error) {
- void (^completionHandlerBlock)(BOOL) = (void (^)(BOOL))completionHandler.get();
- if (error != WebKit::CallbackBase::Error::None) {
- LOG(TextInput, " ...hasMarkedText failed.");
- completionHandlerBlock(NO);
- return;
- }
- BOOL hasMarkedText = editingRangeResult.location != notFound;
- LOG(TextInput, " -> hasMarkedText returned %u", hasMarkedText);
- completionHandlerBlock(hasMarkedText);
+ m_page->hasMarkedText([completionHandler = makeBlockPtr(completionHandler)] (bool result) {
+ completionHandler(result);
+ LOG(TextInput, " -> hasMarkedText returned %u", result);
});
}
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (245594 => 245595)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-05-21 21:54:05 UTC (rev 245595)
@@ -7951,6 +7951,15 @@
process().send(Messages::WebPage::InsertTextAsync(text, replacementRange, WTFMove(options)), m_pageID);
}
+void WebPageProxy::hasMarkedText(CompletionHandler<void(bool)>&& callback)
+{
+ if (!hasRunningProcess()) {
+ callback(false);
+ return;
+ }
+ m_process->connection()->sendWithAsyncReply(Messages::WebPage::HasMarkedText(), WTFMove(callback), m_pageID);
+}
+
void WebPageProxy::getMarkedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&& callbackFunction)
{
if (!hasRunningProcess()) {
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (245594 => 245595)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-05-21 21:54:05 UTC (rev 245595)
@@ -769,6 +769,7 @@
void setTextAsync(const String&);
void insertTextAsync(const String& text, const EditingRange& replacementRange, InsertTextOptions&&);
+ void hasMarkedText(CompletionHandler<void(bool)>&&);
void getMarkedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
void getSelectedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
void characterIndexForPointAsync(const WebCore::IntPoint&, WTF::Function<void (uint64_t, CallbackBase::Error)>&&);
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (245594 => 245595)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-05-21 21:54:05 UTC (rev 245595)
@@ -5173,6 +5173,11 @@
frame.editor().confirmComposition(text);
}
+void WebPage::hasMarkedText(CompletionHandler<void(bool)>&& completionHandler)
+{
+ completionHandler(m_page->focusController().focusedOrMainFrame().editor().hasComposition());
+}
+
void WebPage::getMarkedRangeAsync(CallbackID callbackID)
{
Frame& frame = m_page->focusController().focusedOrMainFrame();
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (245594 => 245595)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-05-21 21:54:05 UTC (rev 245595)
@@ -789,6 +789,7 @@
void setTextAsync(const String&);
void insertTextAsync(const String& text, const EditingRange& replacementRange, InsertTextOptions&&);
+ void hasMarkedText(CompletionHandler<void(bool)>&&);
void getMarkedRangeAsync(CallbackID);
void getSelectedRangeAsync(CallbackID);
void characterIndexForPointAsync(const WebCore::IntPoint&, CallbackID);
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (245594 => 245595)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2019-05-21 20:30:14 UTC (rev 245594)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2019-05-21 21:54:05 UTC (rev 245595)
@@ -434,6 +434,7 @@
SetTextAsync(String text)
InsertTextAsync(String text, struct WebKit::EditingRange replacementRange, struct WebKit::InsertTextOptions options)
+ HasMarkedText() -> (bool hasMarkedText) Async
GetMarkedRangeAsync(WebKit::CallbackID callbackID)
GetSelectedRangeAsync(WebKit::CallbackID callbackID)
CharacterIndexForPointAsync(WebCore::IntPoint point, WebKit::CallbackID callbackID);