Changeset 245595 in webkit


Ignore:
Timestamp:
May 21, 2019 2:54:05 PM (5 years ago)
Author:
Wenson Hsieh
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:
Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245589 r245595  
     12019-05-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        The cost of WebViewImpl::hasMarkedTextWithCompletionHandler should not increase with document size
     4        https://bugs.webkit.org/show_bug.cgi?id=198075
     5        <rdar://problem/37560103>
     6
     7        Reviewed by Tim Horton.
     8
     9        * UIProcess/Cocoa/WebViewImpl.mm:
     10        (WebKit::WebViewImpl::hasMarkedTextWithCompletionHandler):
     11
     12        Refactor hasMarkedTextWithCompletionHandler to use Editor::hasComposition, instead of computing the actual
     13        marked text range. The latter is more expensive and unnecessary, since it uses TextIterator from the document
     14        root to find editing offsets. This makes the cost of determining whether there is marked text proportional to
     15        the document size.
     16
     17        This matches behavior in legacy WebKit, as well as iOS.
     18
     19        * UIProcess/WebPageProxy.cpp:
     20        (WebKit::WebPageProxy::hasMarkedText):
     21        * UIProcess/WebPageProxy.h:
     22        * WebProcess/WebPage/WebPage.cpp:
     23        (WebKit::WebPage::hasMarkedText):
     24        * WebProcess/WebPage/WebPage.h:
     25        * WebProcess/WebPage/WebPage.messages.in:
     26
    1272019-05-21  Jiewen Tan  <jiewen_tan@apple.com>
    228
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r245073 r245595  
    48134813}
    48144814
    4815 void WebViewImpl::hasMarkedTextWithCompletionHandler(void(^completionHandlerPtr)(BOOL hasMarkedText))
    4816 {
    4817     auto completionHandler = adoptNS([completionHandlerPtr copy]);
    4818 
     4815void WebViewImpl::hasMarkedTextWithCompletionHandler(void(^completionHandler)(BOOL hasMarkedText))
     4816{
    48194817    LOG(TextInput, "hasMarkedText");
    4820     m_page->getMarkedRangeAsync([completionHandler](const EditingRange& editingRangeResult, WebKit::CallbackBase::Error error) {
    4821         void (^completionHandlerBlock)(BOOL) = (void (^)(BOOL))completionHandler.get();
    4822         if (error != WebKit::CallbackBase::Error::None) {
    4823             LOG(TextInput, "    ...hasMarkedText failed.");
    4824             completionHandlerBlock(NO);
    4825             return;
    4826         }
    4827         BOOL hasMarkedText = editingRangeResult.location != notFound;
    4828         LOG(TextInput, "    -> hasMarkedText returned %u", hasMarkedText);
    4829         completionHandlerBlock(hasMarkedText);
     4818    m_page->hasMarkedText([completionHandler = makeBlockPtr(completionHandler)] (bool result) {
     4819        completionHandler(result);
     4820        LOG(TextInput, "    -> hasMarkedText returned %u", result);
    48304821    });
    48314822}
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r245540 r245595  
    79527952}
    79537953
     7954void WebPageProxy::hasMarkedText(CompletionHandler<void(bool)>&& callback)
     7955{
     7956    if (!hasRunningProcess()) {
     7957        callback(false);
     7958        return;
     7959    }
     7960    m_process->connection()->sendWithAsyncReply(Messages::WebPage::HasMarkedText(), WTFMove(callback), m_pageID);
     7961}
     7962
    79547963void WebPageProxy::getMarkedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&& callbackFunction)
    79557964{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r245565 r245595  
    770770    void setTextAsync(const String&);
    771771    void insertTextAsync(const String& text, const EditingRange& replacementRange, InsertTextOptions&&);
     772    void hasMarkedText(CompletionHandler<void(bool)>&&);
    772773    void getMarkedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
    773774    void getSelectedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r245543 r245595  
    51745174}
    51755175
     5176void WebPage::hasMarkedText(CompletionHandler<void(bool)>&& completionHandler)
     5177{
     5178    completionHandler(m_page->focusController().focusedOrMainFrame().editor().hasComposition());
     5179}
     5180
    51765181void WebPage::getMarkedRangeAsync(CallbackID callbackID)
    51775182{
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r245565 r245595  
    790790    void setTextAsync(const String&);
    791791    void insertTextAsync(const String& text, const EditingRange& replacementRange, InsertTextOptions&&);
     792    void hasMarkedText(CompletionHandler<void(bool)>&&);
    792793    void getMarkedRangeAsync(CallbackID);
    793794    void getSelectedRangeAsync(CallbackID);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r245335 r245595  
    435435    SetTextAsync(String text)
    436436    InsertTextAsync(String text, struct WebKit::EditingRange replacementRange, struct WebKit::InsertTextOptions options)
     437    HasMarkedText() -> (bool hasMarkedText) Async
    437438    GetMarkedRangeAsync(WebKit::CallbackID callbackID)
    438439    GetSelectedRangeAsync(WebKit::CallbackID callbackID)
Note: See TracChangeset for help on using the changeset viewer.