Add an platform-driven spell-checking mechanism
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2019 07:32:40 +0000 (07:32 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2019 07:32:40 +0000 (07:32 +0000)
commit8380039cae847fa393aedf4d05ef1d06146d8edf
treed6828d6f7c33b424d2feef7672ff4ba2e7baeb29
parent882ba8dbb3fd07e770c578e27a5f9b61e9b6446f
Add an platform-driven spell-checking mechanism
https://bugs.webkit.org/show_bug.cgi?id=195795

Reviewed by Ryosuke Niwa.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::textInserted):
PlatformTextChecking markers are not expected
to propagate to newly inserted text, so remove them.

* dom/DocumentMarker.h:
(WebCore::DocumentMarker::allMarkers):
Add a new type of DocumentMarker, PlatformTextChecking,
and a new data variant that stores a key value pair of strings.

* dom/DocumentMarkerController.cpp:
(WebCore::DocumentMarkerController::addPlatformTextCheckingMarker):
(WebCore::DocumentMarkerController::removeMarkers):
(WebCore::DocumentMarkerController::filterMarkers):
(WebCore::shouldInsertAsSeparateMarker):
* dom/DocumentMarkerController.h:
Export some things.
Add addPlatformTextCheckingMarker, like the others.
Make it possible to filter out markers of a particular type
in a range with a predicate function.

* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers):
Propagate PlatformTextChecking data.
A future change should probably make it possible for
any DocumentMarker to copy its data here, instead of
special-casing each type that is important.

* editing/Editor.cpp:
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::markMisspellingsAndBadGrammar):
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
(WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange const):
(WebCore::platformDrivenTextCheckerEnabled):
* editing/TextCheckingHelper.h:
Bail from traditional spell checking if this mechanism is
enabled. (I wrote it this way to make it runtime switchable
in the near future, and to be similar to unifiedTextCheckerEnabled).

Source/WebKit:

* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* SourcesCocoa.txt:
* UIProcess/Cocoa/TextCheckingController.h: Added.
* UIProcess/Cocoa/TextCheckingController.mm: Added.
(WebKit::TextCheckingController::TextCheckingController):
(WebKit::TextCheckingController::replaceRelativeToSelection):
(WebKit::TextCheckingController::removeAnnotationRelativeToSelection):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setupInteraction]):
(-[WKContentView replaceSelectionOffset:length:withAnnotatedString:relativeReplacementRange:]):
(-[WKContentView removeAnnotation:forSelectionOffset:length:]):
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::textCheckingController):
Plumb two UITextInput methods through to the Web Content process.
I added a new object instead of just sticking things on WebPage
because there are quite a few more related ones coming down the pipeline,
and will also end up being messages going in the opposite direction.

* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h: Added.
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in: Added.
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm: Added.
(WebKit::TextCheckingControllerProxy::TextCheckingControllerProxy):
(WebKit::TextCheckingControllerProxy::~TextCheckingControllerProxy):
(WebKit::relevantMarkerTypes):
(WebKit::TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection):
(WebKit::TextCheckingControllerProxy::replaceRelativeToSelection):
(WebKit::TextCheckingControllerProxy::removeAnnotationRelativeToSelection):
Make it possible for the platform to maintain arbitrary key-value pairs
attached to document ranges, as a way for it to keep track of various
text checking context (e.g. if something has been checked, replaced,
what language it might be, ...).

Allow it to replace the text of a range and the annotations in that range,
or remove annotations in a range. Ranges are specified relative to
the selection.

One large missing piece is giving the platform the ability to retrieve
annotations in a range; that is coming in a future patch.

We translate certain annotations into traditional WebCore spelling
and grammar document markers, for normal display-time treatment.

* WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm:
(-[WKAccessibilityWebPageObject convertScreenPointToRootView:]):
(-[WKAccessibilityWebPageObject accessibilityHitTest:]):
Unified sources fixes.

Source/WTF:

* wtf/Platform.h:
Add an ENABLE flag.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243195 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/DocumentMarker.h
Source/WebCore/dom/DocumentMarkerController.cpp
Source/WebCore/dom/DocumentMarkerController.h
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/TextCheckingHelper.cpp
Source/WebCore/editing/TextCheckingHelper.h
Source/WebKit/ChangeLog
Source/WebKit/DerivedSources-input.xcfilelist
Source/WebKit/DerivedSources-output.xcfilelist
Source/WebKit/DerivedSources.make
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/Cocoa/TextCheckingController.h [new file with mode: 0644]
Source/WebKit/UIProcess/Cocoa/TextCheckingController.mm [new file with mode: 0644]
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h [new file with mode: 0644]
Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in [new file with mode: 0644]
Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm [new file with mode: 0644]
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm