Replace TextCheckingTypeMask with OptionSet
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2018 16:47:43 +0000 (16:47 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2018 16:47:43 +0000 (16:47 +0000)
commit814e66dd621f5b452b2ba5f08b164fd80f88da9a
treefb88781c59e1f66009aaa9dcba5cbd288e41aa7b
parentad6f382a84d2009ad62c965e3ed4fa4c02772a87
Replace TextCheckingTypeMask with OptionSet
https://bugs.webkit.org/show_bug.cgi?id=188678

Reviewed by Antti Koivisto.

Source/WebCore:

Replaces TextCheckingTypeMask with an OptionSet to improve type safety and code clarity. Additionally
change the values of TextCheckingType such that all the enumerators fit within an uint8_t.

* PlatformMac.cmake:
* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::hasMisspelling const):
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(AXAttributeStringSetSpelling):
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::timerFired):
(WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
* editing/Editor.cpp:
(WebCore::Editor::replaceSelectionWithFragment):
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::isAutomaticTextReplacementType):
(WebCore::Editor::markAndReplaceFor): For now, change a local variable from const to non-const to work
around the following MSVC compiler bug: <https://developercommunity.visualstudio.com/content/problem/316713/msvc-cant-compile-webkits-optionsetcontainsany.html>.
(WebCore::Editor::markMisspellingsAndBadGrammar):
(WebCore::Editor::updateMarkersForWordsAffectedByEditing):
(WebCore::Editor::editorUIUpdateTimerFired):
(WebCore::Editor::resolveTextCheckingTypeMask):
* editing/Editor.h:
* editing/SpellChecker.cpp:
(WebCore::SpellCheckRequest::SpellCheckRequest):
(WebCore::SpellCheckRequest::create):
(WebCore::SpellChecker::didCheckSucceed):
* editing/SpellChecker.h:
* editing/TextCheckingHelper.cpp:
(WebCore::findGrammaticalErrors):
(WebCore::findMisspellings):
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
(WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange const):
(WebCore::checkTextOfParagraph):
* editing/TextCheckingHelper.h:
* loader/EmptyClients.cpp:
* platform/text/TextCheckerClient.h:
* platform/text/TextChecking.h: Remove TextCheckingTypeMask. Reorganized the fields of TextCheckingRequestData
to coallesce padding and move it to the end of class. Also used default initializer syntax and defaulted (= default)
the default constructor of TextCheckingRequestData, removing the need for a user-defined default constructor.
(WebCore::TextCheckingRequestData::TextCheckingRequestData):
(WebCore::TextCheckingRequestData::text const): Changed return type from String to const String&
to avoid unnecessary ref-count churn for callers that do not need to take a shared ownership in
this string.
(WebCore::TextCheckingRequestData::checkingTypes const): Renamed; formerly named mask.
(WebCore::TextCheckingRequestData::mask const): Deleted.
* platform/text/mac/TextCheckingMac.mm: Added.
(WebCore::nsTextCheckingTypes):
* testing/Internals.cpp:
(WebCore::Internals::handleAcceptedCandidate):

Source/WebKit:

* Scripts/webkit/messages.py: Add WebCore::TextCheckingType to the special case map so that
the generator knows what header has the definition for this type.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<TextCheckingRequestData>::encode):
(IPC::ArgumentCoder<TextCheckingRequestData>::decode):
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::coreTextCheckingType):
(WebKit::textCheckingResultFromNSTextCheckingResult):
* UIProcess/TextChecker.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::checkTextOfParagraph):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/gtk/TextCheckerGtk.cpp:
(WebKit::TextChecker::requestCheckingOfString):
(WebKit::TextChecker::checkTextOfParagraph): Also simplified return expressions.
* UIProcess/ios/TextCheckerIOS.mm:
(WebKit::TextChecker::checkTextOfParagraph):
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::checkTextOfParagraph):
* UIProcess/win/TextCheckerWin.cpp:
(WebKit::TextChecker::checkTextOfParagraph):
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::shouldEraseMarkersAfterChangeSelection const):
(WebKit::WebEditorClient::checkTextOfParagraph):
* WebProcess/WebCoreSupport/WebEditorClient.h:

Source/WebKitLegacy/mac:

Currently we have code in WebEditorClient::checkTextOfParagraph() that incorrectly assumes
that the enumerators of TextCheckingType have a one-to-one correspondence with NSTextCheckingType.
(This is not the case because there is not corresponding NSTextCheckingType for TextCheckingTypeShowCorrectionPanel).
We now explicitly convert from OptionSet<TextCheckingType> to NSTextCheckingTypes.

* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::checkTextOfParagraph):
(WebEditorClient::shouldEraseMarkersAfterChangeSelection const):
(core): Fix up code style nits; compare resultType on the right-hand side instead of the
left as this is more readable and unncessary now that modern compilers like Clang have
diagnostics to catch accidental assignments when equality was intended.
(WebEditorClient::didCheckSucceed):
* WebView/WebView.mm:
(coreTextCheckingType):
(textCheckingResultFromNSTextCheckingResult):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235120 268f45cc-cd09-0410-ab3c-d52691b4dbfc
36 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PlatformMac.cmake
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
Source/WebCore/editing/AlternativeTextController.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/SpellChecker.cpp
Source/WebCore/editing/SpellChecker.h
Source/WebCore/editing/TextCheckingHelper.cpp
Source/WebCore/editing/TextCheckingHelper.h
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/platform/text/TextCheckerClient.h
Source/WebCore/platform/text/TextChecking.h
Source/WebCore/platform/text/mac/TextCheckingMac.mm [new file with mode: 0644]
Source/WebCore/testing/Internals.cpp
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/TextChecker.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/gtk/TextCheckerGtk.cpp
Source/WebKit/UIProcess/ios/TextCheckerIOS.mm
Source/WebKit/UIProcess/mac/TextCheckerMac.mm
Source/WebKit/UIProcess/win/TextCheckerWin.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.h
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKitLegacy/mac/WebView/WebView.mm