Changeset 244570 in webkit


Ignore:
Timestamp:
Apr 23, 2019 4:46:46 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

Return annotated text checking strings via UIWKDocumentContext
https://bugs.webkit.org/show_bug.cgi?id=197177
<rdar://problem/49064839>

Reviewed by Ryosuke Niwa.

  • WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h:
  • WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:

(WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::requestDocumentEditingContext):
Respect the UIWKDocumentRequestAnnotation flag, returning an attributed
string containing the platform text checking annotations.

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244567 r244570  
     12019-04-23  Tim Horton  <timothy_horton@apple.com>
     2
     3        Return annotated text checking strings via UIWKDocumentContext
     4        https://bugs.webkit.org/show_bug.cgi?id=197177
     5        <rdar://problem/49064839>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h:
     10        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
     11        (WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
     12        * WebProcess/WebPage/ios/WebPageIOS.mm:
     13        (WebKit::WebPage::requestDocumentEditingContext):
     14        Respect the UIWKDocumentRequestAnnotation flag, returning an attributed
     15        string containing the platform text checking annotations.
     16
    1172019-04-23  Commit Queue  <commit-queue@webkit.org>
    218
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h

    r243195 r244570  
    3939}
    4040
     41namespace WebCore {
     42class VisiblePosition;
     43}
     44
    4145namespace WebKit {
    4246
     
    4751    TextCheckingControllerProxy(WebPage&);
    4852    ~TextCheckingControllerProxy();
     53
     54    AttributedString annotatedSubstringBetweenPositions(const WebCore::VisiblePosition&, const WebCore::VisiblePosition&);
    4955
    5056private:
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm

    r243195 r244570  
    164164}
    165165
     166AttributedString TextCheckingControllerProxy::annotatedSubstringBetweenPositions(const WebCore::VisiblePosition& start, const WebCore::VisiblePosition& end)
     167{
     168    RetainPtr<NSMutableAttributedString> string = adoptNS([[NSMutableAttributedString alloc] init]);
     169    NSUInteger stringLength = 0;
     170
     171    RefPtr<Document> document = start.deepEquivalent().document();
     172    if (!document)
     173        return { };
     174
     175    auto entireRange = makeRange(start, end);
     176    if (!entireRange)
     177        return { };
     178
     179    RefPtr<Node> commonAncestor = entireRange->commonAncestorContainer();
     180    size_t entireRangeLocation;
     181    size_t entireRangeLength;
     182    TextIterator::getLocationAndLengthFromRange(commonAncestor.get(), entireRange.get(), entireRangeLocation, entireRangeLength);
     183
     184    for (TextIterator it(start.deepEquivalent(), end.deepEquivalent()); !it.atEnd(); it.advance()) {
     185        int currentTextLength = it.text().length();
     186        if (!currentTextLength)
     187            continue;
     188
     189        [string appendAttributedString:[[[NSAttributedString alloc] initWithString:it.text().createNSStringWithoutCopying().get()] autorelease]];
     190
     191        RefPtr<Range> currentTextRange = it.range();
     192        auto markers = document->markers().markersInRange(*currentTextRange, DocumentMarker::PlatformTextChecking);
     193        for (const auto* marker : markers) {
     194            if (!WTF::holds_alternative<DocumentMarker::PlatformTextCheckingData>(marker->data()))
     195                continue;
     196
     197            auto& textCheckingData = WTF::get<DocumentMarker::PlatformTextCheckingData>(marker->data());
     198            auto subrange = TextIterator::subrange(*currentTextRange, marker->startOffset(), marker->endOffset() - marker->startOffset());
     199
     200            size_t subrangeLocation;
     201            size_t subrangeLength;
     202            TextIterator::getLocationAndLengthFromRange(commonAncestor.get(), &subrange.get(), subrangeLocation, subrangeLength);
     203
     204            ASSERT(subrangeLocation > entireRangeLocation);
     205            ASSERT(subrangeLocation + subrangeLength < entireRangeLength);
     206            [string addAttribute:textCheckingData.key value:textCheckingData.value range:NSMakeRange(subrangeLocation - entireRangeLocation, subrangeLength)];
     207        }
     208
     209        stringLength += currentTextLength;
     210    }
     211
     212    return string.autorelease();
     213}
     214
    166215} // namespace WebKit
    167216
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r244537 r244570  
    4343#import "RemoteLayerTreeDrawingArea.h"
    4444#import "SandboxUtilities.h"
     45#import "TextCheckingControllerProxy.h"
    4546#import "UIKitSPI.h"
    4647#import "UserData.h"
     
    35743575    }
    35753576
    3576     // FIXME: Support Annotation option.
     3577#if ENABLE(PLATFORM_DRIVEN_TEXT_CHECKING)
     3578    if (request.options.contains(DocumentEditingContextRequest::Options::Annotation))
     3579        context.annotatedText = m_textCheckingControllerProxy->annotatedSubstringBetweenPositions(contextBeforeStart, contextAfterEnd);
     3580#endif
    35773581
    35783582    completionHandler(context);
Note: See TracChangeset for help on using the changeset viewer.