Changeset 244570 in webkit
- Timestamp:
- Apr 23, 2019 4:46:46 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r244567 r244570 1 2019-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 1 17 2019-04-23 Commit Queue <commit-queue@webkit.org> 2 18 -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h
r243195 r244570 39 39 } 40 40 41 namespace WebCore { 42 class VisiblePosition; 43 } 44 41 45 namespace WebKit { 42 46 … … 47 51 TextCheckingControllerProxy(WebPage&); 48 52 ~TextCheckingControllerProxy(); 53 54 AttributedString annotatedSubstringBetweenPositions(const WebCore::VisiblePosition&, const WebCore::VisiblePosition&); 49 55 50 56 private: -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
r243195 r244570 164 164 } 165 165 166 AttributedString 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 166 215 } // namespace WebKit 167 216 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r244537 r244570 43 43 #import "RemoteLayerTreeDrawingArea.h" 44 44 #import "SandboxUtilities.h" 45 #import "TextCheckingControllerProxy.h" 45 46 #import "UIKitSPI.h" 46 47 #import "UserData.h" … … 3574 3575 } 3575 3576 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 3577 3581 3578 3582 completionHandler(context);
Note: See TracChangeset
for help on using the changeset viewer.