WebKit Bugzilla
Attachment 347303 Details for
Bug 188678
: Replace TextCheckingTypeMask with OptionSet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188678-20180816141432.patch (text/plain), 54.00 KB, created by
Daniel Bates
on 2018-08-16 14:14:33 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Daniel Bates
Created:
2018-08-16 14:14:33 PDT
Size:
54.00 KB
patch
obsolete
>Subversion Revision: 234848 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 6eb7da9f613a06de1b4518e02133c48f9bc75bcd..0258ca80bbf3e5ef9e9fbe44e90544d44b71a32e 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,43 @@ >+2018-08-16 Daniel Bates <dabates@apple.com> >+ >+ Make TextCheckingTypeMask an OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=188678 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Make TextCheckingTypeMask 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. >+ >+ * 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): >+ (WebCore::Editor::markMisspellingsAndBadGrammar): >+ (WebCore::Editor::updateMarkersForWordsAffectedByEditing): >+ (WebCore::Editor::editorUIUpdateTimerFired): >+ (WebCore::Editor::resolveTextCheckingTypeMask): >+ * editing/SpellChecker.cpp: >+ (WebCore::SpellChecker::didCheckSucceed): >+ * editing/TextCheckingHelper.cpp: >+ (WebCore::findGrammaticalErrors): >+ (WebCore::findMisspellings): >+ (WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar): >+ (WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange const): >+ (WebCore::checkTextOfParagraph): >+ * platform/text/TextChecking.h: >+ (WebCore::TextCheckingRequestData::TextCheckingRequestData): >+ * testing/Internals.cpp: >+ (WebCore::Internals::handleAcceptedCandidate): >+ > 2018-08-14 Antoine Quint <graouts@apple.com> > > [Web Animations] Crash under AnimationTimeline::cancelOrRemoveDeclarativeAnimation() >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 91b71f7bfc9b73f757f8b74ae88fbfcb4b4f3d2a..f6ce26c70397a1e40d8db2974f589b93d0f6935e 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,22 @@ >+2018-08-16 Daniel Bates <dabates@apple.com> >+ >+ Make TextCheckingTypeMask an OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=188678 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * UIProcess/Cocoa/WebViewImpl.mm: >+ (WebKit::coreTextCheckingType): >+ (WebKit::textCheckingResultFromNSTextCheckingResult): >+ * UIProcess/gtk/TextCheckerGtk.cpp: >+ (WebKit::TextChecker::requestCheckingOfString): >+ (WebKit::TextChecker::checkTextOfParagraph): Also simplified return expressions. >+ * UIProcess/mac/TextCheckerMac.mm: >+ (WebKit::TextChecker::checkTextOfParagraph): >+ * WebProcess/WebCoreSupport/WebEditorClient.cpp: >+ (WebKit::WebEditorClient::shouldEraseMarkersAfterChangeSelection const): >+ (WebKit::WebEditorClient::checkTextOfParagraph): >+ > 2018-08-13 Wenson Hsieh <wenson_hsieh@apple.com> > > [WK2] [macOS] Implement a mechanism to test drag and drop >diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog >index 77093f102445849d564e90ff87bad866f1a160df..4296ab097afe7354eaebbddd693677a668998d22 100644 >--- a/Source/WebKitLegacy/mac/ChangeLog >+++ b/Source/WebKitLegacy/mac/ChangeLog >@@ -1,3 +1,26 @@ >+2018-08-16 Daniel Bates <dabates@apple.com> >+ >+ Make TextCheckingTypeMask an OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=188678 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 TextCheckingTypeMask to NSTextCheckingTypes. >+ >+ * 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. >+ (nsTextCheckingTypes): >+ * WebView/WebView.mm: >+ (coreTextCheckingType): >+ (textCheckingResultFromNSTextCheckingResult): >+ > 2018-08-13 Alex Christensen <achristensen@webkit.org> > > Use a 1-byte enum class for TextDirection >diff --git a/Source/WebCore/accessibility/AccessibilityObject.cpp b/Source/WebCore/accessibility/AccessibilityObject.cpp >index 77d1fdbc4ea0604dcc26b3b0afb945267bfdbef9..766e98497cd94748841bbb67335d15e5ae4ec0fc 100644 >--- a/Source/WebCore/accessibility/AccessibilityObject.cpp >+++ b/Source/WebCore/accessibility/AccessibilityObject.cpp >@@ -437,7 +437,7 @@ bool AccessibilityObject::hasMisspelling() const > > if (unifiedTextCheckerEnabled(frame)) { > Vector<TextCheckingResult> results; >- checkTextOfParagraph(*textChecker, stringValue(), TextCheckingTypeSpelling, results, frame->selection().selection()); >+ checkTextOfParagraph(*textChecker, stringValue(), TextCheckingType::Spelling, results, frame->selection().selection()); > if (!results.isEmpty()) > isMisspelled = true; > return isMisspelled; >diff --git a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm b/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm >index e3af278d3450a4cb791b3541138ef5f4882d3bb7..04c186a08ac8af28607c41ba7edd0a017c92bf66 100644 >--- a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm >+++ b/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm >@@ -909,7 +909,7 @@ static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString, > > // checkTextOfParagraph is the only spelling/grammar checker implemented in WK1 and WK2 > Vector<TextCheckingResult> results; >- checkTextOfParagraph(*checker, text, TextCheckingTypeSpelling, results, node->document().frame()->selection().selection()); >+ checkTextOfParagraph(*checker, text, TextCheckingType::Spelling, results, node->document().frame()->selection().selection()); > > size_t size = results.size(); > for (unsigned i = 0; i < size; i++) { >diff --git a/Source/WebCore/editing/AlternativeTextController.cpp b/Source/WebCore/editing/AlternativeTextController.cpp >index 83f83dda4249f345d40508d8177013f59a363abb..e64f9478a249b1b5e2289fc809ee038978342541 100644 >--- a/Source/WebCore/editing/AlternativeTextController.cpp >+++ b/Source/WebCore/editing/AlternativeTextController.cpp >@@ -284,7 +284,7 @@ void AlternativeTextController::timerFired() > VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary); > VisibleSelection adjacentWords = VisibleSelection(p, start); > auto adjacentWordRange = adjacentWords.toNormalizedRange(); >- m_frame.editor().markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeSpelling | TextCheckingTypeReplacement | TextCheckingTypeShowCorrectionPanel, adjacentWordRange.copyRef(), adjacentWordRange.copyRef(), nullptr); >+ m_frame.editor().markAllMisspellingsAndBadGrammarInRanges({ TextCheckingType::Spelling, TextCheckingType::Replacement, TextCheckingType::ShowCorrectionPanel }, adjacentWordRange.copyRef(), adjacentWordRange.copyRef(), nullptr); > } > break; > case AlternativeTextTypeReversion: { >@@ -540,7 +540,7 @@ bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const T > { > DocumentMarkerController& markerController = m_frame.document()->markers(); > if (markerController.hasMarkers(rangeWithAlternative, DocumentMarker::Replacement)) { >- if (result.type == TextCheckingTypeCorrection) >+ if (result.type == TextCheckingType::Correction) > recordSpellcheckerResponseForModifiedCorrection(rangeWithAlternative, stringToBeReplaced, result.replacement); > return false; > } >diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp >index 1bac7f4e36df365eb2ef2b7280cc842442a94aea..4a79274368b592569845d4ab12552c083f38b9ed 100644 >--- a/Source/WebCore/editing/Editor.cpp >+++ b/Source/WebCore/editing/Editor.cpp >@@ -667,7 +667,7 @@ void Editor::replaceSelectionWithFragment(DocumentFragment& fragment, bool selec > return; > > auto rangeToCheck = Range::create(document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); >- if (auto request = SpellCheckRequest::create(resolveTextCheckingTypeMask(*nodeToCheck, TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextCheckingProcessBatch, rangeToCheck.copyRef(), rangeToCheck.copyRef(), rangeToCheck.copyRef())) >+ if (auto request = SpellCheckRequest::create(resolveTextCheckingTypeMask(*nodeToCheck, { TextCheckingType::Spelling, TextCheckingType::Grammar }), TextCheckingProcessBatch, rangeToCheck.copyRef(), rangeToCheck.copyRef(), rangeToCheck.copyRef())) > m_spellChecker->requestCheckingFor(request.releaseNonNull()); > } > >@@ -2339,10 +2339,10 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, > #if PLATFORM(IOS) > UNUSED_PARAM(selectionAfterTyping); > UNUSED_PARAM(doReplacement); >- TextCheckingTypeMask textCheckingOptions = 0; >+ TextCheckingTypeMask textCheckingOptions; > if (isContinuousSpellCheckingEnabled()) >- textCheckingOptions |= TextCheckingTypeSpelling; >- if (!(textCheckingOptions & TextCheckingTypeSpelling)) >+ textCheckingOptions |= TextCheckingType::Spelling; >+ if (!textCheckingOptions.contains(TextCheckingType::Spelling)) > return; > > VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); >@@ -2356,10 +2356,10 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, > if (unifiedTextCheckerEnabled()) { > m_alternativeTextController->applyPendingCorrection(selectionAfterTyping); > >- TextCheckingTypeMask textCheckingOptions = 0; >+ TextCheckingTypeMask textCheckingOptions; > > if (isContinuousSpellCheckingEnabled()) >- textCheckingOptions |= TextCheckingTypeSpelling; >+ textCheckingOptions |= TextCheckingType::Spelling; > > #if USE(AUTOMATIC_TEXT_REPLACEMENT) > if (doReplacement >@@ -2367,14 +2367,14 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, > || isAutomaticLinkDetectionEnabled() > || isAutomaticDashSubstitutionEnabled() > || isAutomaticTextReplacementEnabled() >- || ((textCheckingOptions & TextCheckingTypeSpelling) && isAutomaticSpellingCorrectionEnabled()))) >- textCheckingOptions |= TextCheckingTypeReplacement; >+ || (textCheckingOptions.contains(TextCheckingType::Spelling) && isAutomaticSpellingCorrectionEnabled()))) >+ textCheckingOptions |= TextCheckingType::Replacement; > #endif >- if (!(textCheckingOptions & (TextCheckingTypeSpelling | TextCheckingTypeReplacement))) >+ if (!textCheckingOptions.contains(TextCheckingType::Spelling) && !textCheckingOptions.contains(TextCheckingType::Replacement)) > return; > > if (isGrammarCheckingEnabled()) >- textCheckingOptions |= TextCheckingTypeGrammar; >+ textCheckingOptions |= TextCheckingType::Grammar; > > auto sentenceStart = startOfSentence(wordStart); > auto sentenceEnd = endOfSentence(wordStart); >@@ -2563,8 +2563,8 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC > // There shouldn't be pending autocorrection at this moment. > ASSERT(!m_alternativeTextController->hasPendingCorrection()); > >- bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; >- bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel; >+ bool shouldMarkGrammar = textCheckingOptions.contains(TextCheckingType::Grammar); >+ bool shouldShowCorrectionPanel = textCheckingOptions.contains(TextCheckingType::ShowCorrectionPanel); > > // This function is called with selections already expanded to word boundaries. > if (!client() || !spellingRange || (shouldMarkGrammar && !grammarRange)) >@@ -2605,16 +2605,16 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textC > static bool isAutomaticTextReplacementType(TextCheckingType type) > { > switch (type) { >- case TextCheckingTypeNone: >- case TextCheckingTypeSpelling: >- case TextCheckingTypeGrammar: >+ case TextCheckingType::None: >+ case TextCheckingType::Spelling: >+ case TextCheckingType::Grammar: > return false; >- case TextCheckingTypeLink: >- case TextCheckingTypeQuote: >- case TextCheckingTypeDash: >- case TextCheckingTypeReplacement: >- case TextCheckingTypeCorrection: >- case TextCheckingTypeShowCorrectionPanel: >+ case TextCheckingType::Link: >+ case TextCheckingType::Quote: >+ case TextCheckingType::Dash: >+ case TextCheckingType::Replacement: >+ case TextCheckingType::Correction: >+ case TextCheckingType::ShowCorrectionPanel: > return true; > } > ASSERT_NOT_REACHED(); >@@ -2647,12 +2647,12 @@ void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<Te > TextCheckingTypeMask textCheckingOptions = request.data().mask(); > TextCheckingParagraph paragraph(request.checkingRange(), request.automaticReplacementRange(), &request.paragraphRange()); > >- const bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; >- const bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; >- const bool shouldMarkLink = textCheckingOptions & TextCheckingTypeLink; >- const bool shouldPerformReplacement = textCheckingOptions & (TextCheckingTypeQuote | TextCheckingTypeDash | TextCheckingTypeReplacement); >- const bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel; >- const bool shouldCheckForCorrection = shouldShowCorrectionPanel || (textCheckingOptions & TextCheckingTypeCorrection); >+ const bool shouldMarkSpelling = textCheckingOptions.contains(TextCheckingType::Spelling); >+ const bool shouldMarkGrammar = textCheckingOptions.contains(TextCheckingType::Grammar); >+ const bool shouldMarkLink = textCheckingOptions.contains(TextCheckingType::Link); >+ const bool shouldPerformReplacement = textCheckingOptions.containsAny({ TextCheckingType::Quote, TextCheckingType::Dash, TextCheckingType::Replacement }); >+ const bool shouldShowCorrectionPanel = textCheckingOptions.contains(TextCheckingType::ShowCorrectionPanel); >+ const bool shouldCheckForCorrection = shouldShowCorrectionPanel || textCheckingOptions.contains(TextCheckingType::Correction); > #if !USE(AUTOCORRECTION_PANEL) > ASSERT(!shouldShowCorrectionPanel); > #endif >@@ -2694,14 +2694,14 @@ void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<Te > // 2. Result falls within spellingRange. > // 3. The word in question doesn't end at an ambiguous boundary. For instance, we would not mark > // "wouldn'" as misspelled right after apostrophe is typed. >- if (shouldMarkSpelling && !shouldShowCorrectionPanel && resultType == TextCheckingTypeSpelling >+ if (shouldMarkSpelling && !shouldShowCorrectionPanel && resultType == TextCheckingType::Spelling > && resultLocation >= paragraph.checkingStart() && resultEndLocation <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { > ASSERT(resultLength > 0 && resultLocation >= 0); > auto misspellingRange = paragraph.subrange(resultLocation, resultLength); > if (!m_alternativeTextController->isSpellingMarkerAllowed(misspellingRange)) > continue; > misspellingRange->startContainer().document().markers().addMarker(misspellingRange.ptr(), DocumentMarker::Spelling, replacement); >- } else if (shouldMarkGrammar && resultType == TextCheckingTypeGrammar && paragraph.checkingRangeCovers(resultLocation, resultLength)) { >+ } else if (shouldMarkGrammar && resultType == TextCheckingType::Grammar && paragraph.checkingRangeCovers(resultLocation, resultLength)) { > ASSERT(resultLength > 0 && resultLocation >= 0); > for (auto& detail : results[i].details) { > ASSERT(detail.length > 0 && detail.location >= 0); >@@ -2716,7 +2716,7 @@ void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<Te > ASSERT(resultLength > 0 && resultLocation >= 0); > > if (shouldShowCorrectionPanel && (resultEndLocation < automaticReplacementEndLocation >- || !(resultType & (TextCheckingTypeReplacement | TextCheckingTypeCorrection)))) >+ || (resultType != TextCheckingType::Replacement && resultType != TextCheckingType::Correction))) > continue; > > // Apply replacement if: >@@ -2726,8 +2726,8 @@ void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<Te > bool doReplacement = replacement.length() > 0 && !resultEndsAtAmbiguousBoundary; > auto rangeToReplace = paragraph.subrange(resultLocation, resultLength); > >- // adding links should be done only immediately after they are typed >- if (resultType == TextCheckingTypeLink && selectionOffset != resultEndLocation + 1) >+ // Adding links should be done only immediately after they are typed. >+ if (resultType == TextCheckingType::Link && selectionOffset != resultEndLocation + 1) > continue; > > if (!(shouldPerformReplacement || shouldCheckForCorrection || shouldMarkLink) || !doReplacement) >@@ -2754,7 +2754,7 @@ void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<Te > continue; > } > >- if (resultType == TextCheckingTypeLink) { >+ if (resultType == TextCheckingType::Link) { > m_frame.selection().setSelection(selectionToReplace); > selectionChanged = true; > restoreSelectionAfterChange = false; >@@ -2777,7 +2777,7 @@ void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<Te > if (resultLocation < selectionOffset) > selectionOffset += replacement.length() - resultLength; > >- if (resultType == TextCheckingTypeCorrection) { >+ if (resultType == TextCheckingType::Correction) { > auto replacementRange = paragraph.subrange(resultLocation, replacement.length()); > m_alternativeTextController->recordAutocorrectionResponse(AutocorrectionResponse::Accepted, replacedString, replacementRange.ptr()); > >@@ -2837,9 +2837,9 @@ void Editor::markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelec > return; > > // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling and grammar, but don't autocorrect misspellings. >- TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling; >+ TextCheckingTypeMask textCheckingOptions { TextCheckingType::Spelling }; > if (markGrammar && isGrammarCheckingEnabled()) >- textCheckingOptions |= TextCheckingTypeGrammar; >+ textCheckingOptions |= TextCheckingType::Grammar; > auto spellCheckingRange = spellingSelection.toNormalizedRange(); > markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellCheckingRange.copyRef(), spellCheckingRange.copyRef(), grammarSelection.toNormalizedRange()); > return; >@@ -2861,7 +2861,7 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA > if (!document().markers().hasMarkers()) > return; > >- if (!m_alternativeTextController->shouldRemoveMarkersUponEditing() && (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingTypeSpelling))) >+ if (!m_alternativeTextController->shouldRemoveMarkersUponEditing() && (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingType::Spelling))) > return; > > // We want to remove the markers from a word if an editing command will change the word. This can happen in one of >@@ -3652,11 +3652,11 @@ void Editor::editorUIUpdateTimerFired() > } > } > >- if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingTypeSpelling)) { >+ if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingType::Spelling)) { > if (RefPtr<Range> wordRange = newAdjacentWords.toNormalizedRange()) > document().markers().removeMarkers(wordRange.get(), DocumentMarker::Spelling); > } >- if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingTypeGrammar)) { >+ if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingType::Grammar)) { > if (RefPtr<Range> sentenceRange = newSelectedSentence.toNormalizedRange()) > document().markers().removeMarkers(sentenceRange.get(), DocumentMarker::Grammar); > } >@@ -3720,44 +3720,44 @@ TextCheckingTypeMask Editor::resolveTextCheckingTypeMask(const Node& rootEditabl > if (auto* host = rootEditableElement.shadowHost()) > onlyAllowsTextReplacement = is<HTMLInputElement>(host) && downcast<HTMLInputElement>(*host).isSpellcheckDisabledExceptTextReplacement(); > if (onlyAllowsTextReplacement) >- textCheckingOptions &= TextCheckingTypeReplacement; >+ textCheckingOptions = TextCheckingType::Replacement; > #else > UNUSED_PARAM(rootEditableElement); > #endif > >- bool shouldMarkSpelling = textCheckingOptions & TextCheckingTypeSpelling; >- bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; >+ bool shouldMarkSpelling = textCheckingOptions.contains(TextCheckingType::Spelling); >+ bool shouldMarkGrammar = textCheckingOptions.contains(TextCheckingType::Grammar); > #if !PLATFORM(IOS) >- bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel; >- bool shouldCheckForCorrection = shouldShowCorrectionPanel || (textCheckingOptions & TextCheckingTypeCorrection); >+ bool shouldShowCorrectionPanel = textCheckingOptions.contains(TextCheckingType::ShowCorrectionPanel); >+ bool shouldCheckForCorrection = shouldShowCorrectionPanel || textCheckingOptions.contains(TextCheckingType::Correction); > #endif > >- TextCheckingTypeMask checkingTypes = 0; >+ TextCheckingTypeMask checkingTypes; > if (shouldMarkSpelling) >- checkingTypes |= TextCheckingTypeSpelling; >+ checkingTypes |= TextCheckingType::Spelling; > if (shouldMarkGrammar) >- checkingTypes |= TextCheckingTypeGrammar; >+ checkingTypes |= TextCheckingType::Grammar; > #if !PLATFORM(IOS) > if (shouldCheckForCorrection) >- checkingTypes |= TextCheckingTypeCorrection; >+ checkingTypes |= TextCheckingType::Correction; > if (shouldShowCorrectionPanel) >- checkingTypes |= TextCheckingTypeShowCorrectionPanel; >+ checkingTypes |= TextCheckingType::ShowCorrectionPanel; > > #if USE(AUTOMATIC_TEXT_REPLACEMENT) >- bool shouldPerformReplacement = textCheckingOptions & TextCheckingTypeReplacement; >+ bool shouldPerformReplacement = textCheckingOptions.contains(TextCheckingType::Replacement); > if (shouldPerformReplacement) { > if (!onlyAllowsTextReplacement) { > if (isAutomaticLinkDetectionEnabled()) >- checkingTypes |= TextCheckingTypeLink; >+ checkingTypes |= TextCheckingType::Link; > if (isAutomaticQuoteSubstitutionEnabled()) >- checkingTypes |= TextCheckingTypeQuote; >+ checkingTypes |= TextCheckingType::Quote; > if (isAutomaticDashSubstitutionEnabled()) >- checkingTypes |= TextCheckingTypeDash; >+ checkingTypes |= TextCheckingType::Dash; > if (shouldMarkSpelling && isAutomaticSpellingCorrectionEnabled()) >- checkingTypes |= TextCheckingTypeCorrection; >+ checkingTypes |= TextCheckingType::Correction; > } > if (isAutomaticTextReplacementEnabled()) >- checkingTypes |= TextCheckingTypeReplacement; >+ checkingTypes |= TextCheckingType::Replacement; > } > #endif > #endif // !PLATFORM(IOS) >diff --git a/Source/WebCore/editing/SpellChecker.cpp b/Source/WebCore/editing/SpellChecker.cpp >index c054c5ade540904223b9093c140a3586667961e3..3c19c41bd2a8addb382e9cedb3f6f27ab4e4e29d 100644 >--- a/Source/WebCore/editing/SpellChecker.cpp >+++ b/Source/WebCore/editing/SpellChecker.cpp >@@ -217,9 +217,9 @@ void SpellChecker::didCheckSucceed(int sequence, const Vector<TextCheckingResult > TextCheckingRequestData requestData = m_processingRequest->data(); > if (requestData.sequence() == sequence) { > OptionSet<DocumentMarker::MarkerType> markerTypes; >- if (requestData.mask() & TextCheckingTypeSpelling) >+ if (requestData.mask() & TextCheckingType::Spelling) > markerTypes |= DocumentMarker::Spelling; >- if (requestData.mask() & TextCheckingTypeGrammar) >+ if (requestData.mask() & TextCheckingType::Grammar) > markerTypes |= DocumentMarker::Grammar; > if (!markerTypes.isEmpty()) > m_frame.document()->markers().removeMarkers(&m_processingRequest->checkingRange(), markerTypes); >diff --git a/Source/WebCore/editing/TextCheckingHelper.cpp b/Source/WebCore/editing/TextCheckingHelper.cpp >index d5190666c05cccfb55eaf97548fbd88065050e68..bc9629b23a3a712fe093af2dd4983c876de9c9de 100644 >--- a/Source/WebCore/editing/TextCheckingHelper.cpp >+++ b/Source/WebCore/editing/TextCheckingHelper.cpp >@@ -62,7 +62,7 @@ static void findGrammaticalErrors(TextCheckerClient& client, StringView text, Ve > ASSERT(static_cast<unsigned>(badGrammarLength) <= text.length() - checkLocation - badGrammarLocation); > > TextCheckingResult badGrammar; >- badGrammar.type = TextCheckingTypeGrammar; >+ badGrammar.type = TextCheckingType::Grammar; > badGrammar.location = checkLocation + badGrammarLocation; > badGrammar.length = badGrammarLength; > badGrammar.details = WTFMove(badGrammarDetails); >@@ -96,7 +96,7 @@ static void findMisspellings(TextCheckerClient& client, StringView text, Vector< > ASSERT(misspellingLocation + misspellingLength <= wordLength); > > TextCheckingResult misspelling; >- misspelling.type = TextCheckingTypeSpelling; >+ misspelling.type = TextCheckingType::Spelling; > misspelling.location = wordStart + misspellingLocation; > misspelling.length = misspellingLength; > misspelling.replacement = client.getAutoCorrectSuggestionForMisspelledWord(text.substring(misspelling.location, misspelling.length).toStringWithoutCopying()); >@@ -351,14 +351,14 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b > unsigned grammarDetailIndex = 0; > > Vector<TextCheckingResult> results; >- TextCheckingTypeMask checkingTypes = checkGrammar ? (TextCheckingTypeSpelling | TextCheckingTypeGrammar) : TextCheckingTypeSpelling; >+ TextCheckingTypeMask checkingTypes = checkGrammar ? TextCheckingTypeMask { TextCheckingType::Spelling, TextCheckingType::Grammar } : TextCheckingTypeMask { TextCheckingType::Spelling }; > VisibleSelection currentSelection; > if (Frame* frame = paragraphRange->ownerDocument().frame()) > currentSelection = frame->selection().selection(); > checkTextOfParagraph(*m_client.textChecker(), paragraphString, checkingTypes, results, currentSelection); > > for (auto& result : results) { >- if (result.type == TextCheckingTypeSpelling && result.location >= currentStartOffset && result.location + result.length <= currentEndOffset) { >+ if (result.type == TextCheckingType::Spelling && result.location >= currentStartOffset && result.location + result.length <= currentEndOffset) { > ASSERT(result.length > 0); > ASSERT(result.location >= 0); > spellingLocation = result.location; >@@ -366,7 +366,7 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b > ASSERT(misspelledWord.length()); > break; > } >- if (checkGrammar && result.type == TextCheckingTypeGrammar && result.location < currentEndOffset && result.location + result.length > currentStartOffset) { >+ if (checkGrammar && result.type == TextCheckingType::Grammar && result.location < currentEndOffset && result.location + result.length > currentStartOffset) { > ASSERT(result.length > 0); > ASSERT(result.location >= 0); > // We can't stop after the first grammar result, since there might still be a spelling result after >@@ -583,14 +583,14 @@ Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool > return guesses; > > Vector<TextCheckingResult> results; >- TextCheckingTypeMask checkingTypes = checkGrammar ? (TextCheckingTypeSpelling | TextCheckingTypeGrammar) : TextCheckingTypeSpelling; >+ TextCheckingTypeMask checkingTypes = checkGrammar ? TextCheckingTypeMask { TextCheckingType::Spelling, TextCheckingType::Grammar } : TextCheckingTypeMask { TextCheckingType::Spelling }; > VisibleSelection currentSelection; > if (Frame* frame = m_range->ownerDocument().frame()) > currentSelection = frame->selection().selection(); > checkTextOfParagraph(*m_client.textChecker(), paragraph.text(), checkingTypes, results, currentSelection); > > for (auto& result : results) { >- if (result.type == TextCheckingTypeSpelling && paragraph.checkingRangeMatches(result.location, result.length)) { >+ if (result.type == TextCheckingType::Spelling && paragraph.checkingRangeMatches(result.location, result.length)) { > String misspelledWord = paragraph.checkingSubstring(); > ASSERT(misspelledWord.length()); > m_client.textChecker()->getGuessesForWord(misspelledWord, String(), currentSelection, guesses); >@@ -604,7 +604,7 @@ Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool > return guesses; > > for (auto& result : results) { >- if (result.type == TextCheckingTypeGrammar && paragraph.isCheckingRangeCoveredBy(result.location, result.length)) { >+ if (result.type == TextCheckingType::Grammar && paragraph.isCheckingRangeCoveredBy(result.location, result.length)) { > for (auto& detail : result.details) { > ASSERT(detail.length > 0); > ASSERT(detail.location >= 0); >@@ -655,13 +655,13 @@ void checkTextOfParagraph(TextCheckerClient& client, StringView text, TextChecki > UNUSED_PARAM(currentSelection); > > Vector<TextCheckingResult> mispellings; >- if (checkingTypes & TextCheckingTypeSpelling) >+ if (checkingTypes.contains(TextCheckingType::Spelling)) > findMisspellings(client, text, mispellings); > > #if USE(GRAMMAR_CHECKING) > // Look for grammatical errors that occur before the first misspelling. > Vector<TextCheckingResult> grammaticalErrors; >- if (checkingTypes & TextCheckingTypeGrammar) { >+ if (checkingTypes.contains(TextCheckingType::Grammar)) { > unsigned grammarCheckLength = text.length(); > for (auto& mispelling : mispellings) > grammarCheckLength = std::min<unsigned>(grammarCheckLength, mispelling.location); >diff --git a/Source/WebCore/platform/text/TextChecking.h b/Source/WebCore/platform/text/TextChecking.h >index 7d58a5008bb330f98873370e6490771e7e842543..a2ff922d8a3ab65e0b60a4eadb199fd1aeb8f931 100644 >--- a/Source/WebCore/platform/text/TextChecking.h >+++ b/Source/WebCore/platform/text/TextChecking.h >@@ -1,5 +1,6 @@ > /* > * Copyright (c) 2011 Google Inc. All rights reserved. >+ * Copyright (C) 2018 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions are >@@ -28,28 +29,28 @@ > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > */ > >-#ifndef TextChecking_h >-#define TextChecking_h >+#pragma once > >+#include <wtf/OptionSet.h> > #include <wtf/RefCounted.h> > #include <wtf/Vector.h> > #include <wtf/text/WTFString.h> > > namespace WebCore { > >-enum TextCheckingType { >- TextCheckingTypeNone = 0, >- TextCheckingTypeSpelling = 1 << 1, >- TextCheckingTypeGrammar = 1 << 2, >- TextCheckingTypeLink = 1 << 5, >- TextCheckingTypeQuote = 1 << 6, >- TextCheckingTypeDash = 1 << 7, >- TextCheckingTypeReplacement = 1 << 8, >- TextCheckingTypeCorrection = 1 << 9, >- TextCheckingTypeShowCorrectionPanel = 1 << 10 >+enum class TextCheckingType : uint8_t { >+ None = 0, >+ Spelling = 1 << 0, >+ Grammar = 1 << 1, >+ Link = 1 << 2, >+ Quote = 1 << 3, >+ Dash = 1 << 4, >+ Replacement = 1 << 5, >+ Correction = 1 << 6, >+ ShowCorrectionPanel = 1 << 7, > }; > >-typedef unsigned TextCheckingTypeMask; >+using TextCheckingTypeMask = OptionSet<TextCheckingType>; > > enum TextCheckingProcessType { > TextCheckingProcessBatch, >@@ -78,7 +79,7 @@ class TextCheckingRequestData { > public: > TextCheckingRequestData() > : m_sequence(unrequestedTextCheckingSequence) >- , m_mask(TextCheckingTypeNone) >+ , m_mask(TextCheckingType::None) > , m_processType(TextCheckingProcessIncremental) > { } > TextCheckingRequestData(int sequence, const String& text, TextCheckingTypeMask mask, TextCheckingProcessType processType) >@@ -110,5 +111,3 @@ public: > }; > > } >- >-#endif // TextChecking_h >diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp >index 13b7b707e2738e33f810ce49ccd5a1af0bd72745..af1479e480eaa77ec53dcbe78a7a9db0210e09f7 100644 >--- a/Source/WebCore/testing/Internals.cpp >+++ b/Source/WebCore/testing/Internals.cpp >@@ -2195,7 +2195,7 @@ void Internals::handleAcceptedCandidate(const String& candidate, unsigned locati > return; > > TextCheckingResult result; >- result.type = TextCheckingTypeNone; >+ result.type = TextCheckingType::None; > result.location = location; > result.length = length; > result.replacement = candidate; >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >index 56de23c36e44819bdd8e8c1c26124c9ceaddbcf2..3f9d539c46ea32b17f244969ed27b1e56baff06f 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >@@ -3090,31 +3090,29 @@ void WebViewImpl::handleRequestedCandidates(NSInteger sequenceNumber, NSArray<NS > #endif > } > >-static WebCore::TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult) >+static constexpr WebCore::TextCheckingType coreTextCheckingType(NSTextCheckingType type) > { >- WebCore::TextCheckingResult result; >- >- // FIXME: Right now we only request candidates for spelling, replacement, and correction, but we plan to >- // support more types, and we will have to update this at that time. >- switch ([nsResult resultType]) { >- case NSTextCheckingTypeSpelling: >- result.type = WebCore::TextCheckingTypeSpelling; >- break; >- case NSTextCheckingTypeReplacement: >- result.type = WebCore::TextCheckingTypeReplacement; >- break; >+ switch (type) { > case NSTextCheckingTypeCorrection: >- result.type = WebCore::TextCheckingTypeCorrection; >- break; >+ return WebCore::TextCheckingType::Correction; >+ case NSTextCheckingTypeReplacement: >+ return WebCore::TextCheckingType::Replacement; >+ case NSTextCheckingTypeSpelling: >+ return WebCore::TextCheckingType::Spelling; > default: >- result.type = WebCore::TextCheckingTypeNone; >+ return WebCore::TextCheckingType::None; > } >+} > >+static WebCore::TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult) >+{ > NSRange resultRange = [nsResult range]; >+ >+ WebCore::TextCheckingResult result; >+ result.type = coreTextCheckingType(nsResult.resultType); > result.location = resultRange.location; > result.length = resultRange.length; >- result.replacement = [nsResult replacementString]; >- >+ result.replacement = nsResult.replacementString; > return result; > } > >diff --git a/Source/WebKit/UIProcess/gtk/TextCheckerGtk.cpp b/Source/WebKit/UIProcess/gtk/TextCheckerGtk.cpp >index faff0929db2e31fe86d83283f0c04c33a63de164..c3aa0f3506974923336a8377f02e3e92c1c5d4a6 100644 >--- a/Source/WebKit/UIProcess/gtk/TextCheckerGtk.cpp >+++ b/Source/WebKit/UIProcess/gtk/TextCheckerGtk.cpp >@@ -203,7 +203,7 @@ void TextChecker::requestCheckingOfString(Ref<TextCheckerCompletion>&& completio > #if ENABLE(SPELLCHECK) > TextCheckingRequestData request = completion->textCheckingRequestData(); > ASSERT(request.sequence() != unrequestedTextCheckingSequence); >- ASSERT(request.mask() != TextCheckingTypeNone); >+ ASSERT(request.mask() != TextCheckingType::None); > > completion->didFinishCheckingText(checkTextOfParagraph(completion->spellDocumentTag(), request.text(), insertionPoint, request.mask(), false)); > #else >@@ -244,12 +244,12 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume > { > UNUSED_PARAM(insertionPoint); > #if ENABLE(SPELLCHECK) >- if (!(checkingTypes & TextCheckingTypeSpelling)) >- return Vector<TextCheckingResult>(); >+ if (!checkingTypes.contains(TextCheckingType::Spelling)) >+ return { }; > > UBreakIterator* textIterator = wordBreakIterator(text); > if (!textIterator) >- return Vector<TextCheckingResult>(); >+ return { }; > > // Omit the word separators at the beginning/end of the text to don't unnecessarily > // involve the client to check spelling for them. >@@ -267,7 +267,7 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume > break; > > TextCheckingResult misspellingResult; >- misspellingResult.type = TextCheckingTypeSpelling; >+ misspellingResult.type = TextCheckingType::Spelling; > misspellingResult.location = offset + misspellingLocation; > misspellingResult.length = misspellingLength; > paragraphCheckingResult.append(misspellingResult); >diff --git a/Source/WebKit/UIProcess/mac/TextCheckerMac.mm b/Source/WebKit/UIProcess/mac/TextCheckerMac.mm >index c92fe5fcd945b22a20fe2e6b441a1844510046e0..fcb1edb2d9176b1dd81cb2b493011c5d82117fff 100644 >--- a/Source/WebKit/UIProcess/mac/TextCheckerMac.mm >+++ b/Source/WebKit/UIProcess/mac/TextCheckerMac.mm >@@ -352,14 +352,14 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume > ASSERT(resultRange.length > 0); > if (resultType == NSTextCheckingTypeSpelling && (checkingTypes & NSTextCheckingTypeSpelling)) { > TextCheckingResult result; >- result.type = TextCheckingTypeSpelling; >+ result.type = TextCheckingType::Spelling; > result.location = resultRange.location; > result.length = resultRange.length; > results.append(result); > } else if (resultType == NSTextCheckingTypeGrammar && (checkingTypes & NSTextCheckingTypeGrammar)) { > TextCheckingResult result; > NSArray *details = [incomingResult grammarDetails]; >- result.type = TextCheckingTypeGrammar; >+ result.type = TextCheckingType::Grammar; > result.location = resultRange.location; > result.length = resultRange.length; > for (NSDictionary *incomingDetail in details) { >@@ -381,35 +381,35 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume > results.append(result); > } else if (resultType == NSTextCheckingTypeLink && (checkingTypes & NSTextCheckingTypeLink)) { > TextCheckingResult result; >- result.type = TextCheckingTypeLink; >+ result.type = TextCheckingType::Link; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [[incomingResult URL] absoluteString]; > results.append(result); > } else if (resultType == NSTextCheckingTypeQuote && (checkingTypes & NSTextCheckingTypeQuote)) { > TextCheckingResult result; >- result.type = TextCheckingTypeQuote; >+ result.type = TextCheckingType::Quote; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; > results.append(result); > } else if (resultType == NSTextCheckingTypeDash && (checkingTypes & NSTextCheckingTypeDash)) { > TextCheckingResult result; >- result.type = TextCheckingTypeDash; >+ result.type = TextCheckingType::Dash; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; > results.append(result); > } else if (resultType == NSTextCheckingTypeReplacement && (checkingTypes & NSTextCheckingTypeReplacement)) { > TextCheckingResult result; >- result.type = TextCheckingTypeReplacement; >+ result.type = TextCheckingType::Replacement; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; > results.append(result); > } else if (resultType == NSTextCheckingTypeCorrection && (checkingTypes & NSTextCheckingTypeCorrection)) { > TextCheckingResult result; >- result.type = TextCheckingTypeCorrection; >+ result.type = TextCheckingType::Correction; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; >diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp >index d87a5384cd7e0984b7814d590eb65956ff40b75a..9ed7cbb13e77e14ffd5cff489d58922c9638737a 100644 >--- a/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp >+++ b/Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp >@@ -467,7 +467,7 @@ bool WebEditorClient::shouldEraseMarkersAfterChangeSelection(WebCore::TextChecki > { > // This prevents erasing spelling markers on OS X Lion or later to match AppKit on these Mac OS X versions. > #if PLATFORM(COCOA) >- return type != TextCheckingTypeSpelling; >+ return type != TextCheckingType::Spelling; > #else > UNUSED_PARAM(type); > return true; >@@ -522,7 +522,8 @@ Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stri > { > Vector<TextCheckingResult> results; > >- m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes, insertionPointFromCurrentSelection(currentSelection)), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results)); >+ // FIXME: Pass TextCheckingTypeMask without conversion to its underlying storage type. >+ m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes.toRaw(), insertionPointFromCurrentSelection(currentSelection)), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results)); > > return results; > } >diff --git a/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm b/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm >index d311dd65f170c1b25d47a3279753a5d535b575eb..3b972084479ed42ec8da3d90d321121078d2bebc 100644 >--- a/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm >+++ b/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm >@@ -935,7 +935,7 @@ bool WebEditorClient::performTwoStepDrop(DocumentFragment& fragment, Range& dest > > Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes, const VisibleSelection&) > { >- ASSERT(checkingTypes & NSTextCheckingTypeSpelling); >+ ASSERT(checkingTypes.contains(TextCheckingType::Spelling)); > > Vector<TextCheckingResult> results; > >@@ -944,7 +944,7 @@ Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stri > NSRange resultRange = [incomingResult rangeValue]; > ASSERT(resultRange.location != NSNotFound && resultRange.length > 0); > TextCheckingResult result; >- result.type = TextCheckingTypeSpelling; >+ result.type = TextCheckingType::Spelling; > result.location = resultRange.location; > result.length = resultRange.length; > results.append(result); >@@ -965,7 +965,7 @@ bool WebEditorClient::performTwoStepDrop(DocumentFragment&, Range&, bool) > bool WebEditorClient::shouldEraseMarkersAfterChangeSelection(TextCheckingType type) const > { > // This prevents erasing spelling markers on OS X Lion or later to match AppKit on these Mac OS X versions. >- return type != TextCheckingTypeSpelling; >+ return type != TextCheckingType::Spelling; > } > > void WebEditorClient::ignoreWordInSpellDocument(const String& text) >@@ -1037,16 +1037,16 @@ static Vector<TextCheckingResult> core(NSArray *incomingResults, TextCheckingTyp > NSTextCheckingType resultType = [incomingResult resultType]; > ASSERT(resultRange.location != NSNotFound); > ASSERT(resultRange.length > 0); >- if (NSTextCheckingTypeSpelling == resultType && 0 != (checkingTypes & NSTextCheckingTypeSpelling)) { >+ if (resultType == NSTextCheckingTypeSpelling && checkingTypes.contains(TextCheckingType::Spelling)) { > TextCheckingResult result; >- result.type = TextCheckingTypeSpelling; >+ result.type = TextCheckingType::Spelling; > result.location = resultRange.location; > result.length = resultRange.length; > results.append(result); >- } else if (NSTextCheckingTypeGrammar == resultType && 0 != (checkingTypes & NSTextCheckingTypeGrammar)) { >+ } else if (resultType == NSTextCheckingTypeGrammar && checkingTypes.contains(TextCheckingType::Grammar)) { > TextCheckingResult result; > NSArray *details = [incomingResult grammarDetails]; >- result.type = TextCheckingTypeGrammar; >+ result.type = TextCheckingType::Grammar; > result.location = resultRange.location; > result.length = resultRange.length; > for (NSDictionary *incomingDetail in details) { >@@ -1066,37 +1066,37 @@ static Vector<TextCheckingResult> core(NSArray *incomingResults, TextCheckingTyp > result.details.append(detail); > } > results.append(result); >- } else if (NSTextCheckingTypeLink == resultType && 0 != (checkingTypes & NSTextCheckingTypeLink)) { >+ } else if (resultType == NSTextCheckingTypeLink && checkingTypes.contains(TextCheckingType::Link)) { > TextCheckingResult result; >- result.type = TextCheckingTypeLink; >+ result.type = TextCheckingType::Link; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [[incomingResult URL] absoluteString]; > results.append(result); >- } else if (NSTextCheckingTypeQuote == resultType && 0 != (checkingTypes & NSTextCheckingTypeQuote)) { >+ } else if (resultType == NSTextCheckingTypeQuote && checkingTypes.contains(TextCheckingType::Quote)) { > TextCheckingResult result; >- result.type = TextCheckingTypeQuote; >+ result.type = TextCheckingType::Quote; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; > results.append(result); >- } else if (NSTextCheckingTypeDash == resultType && 0 != (checkingTypes & NSTextCheckingTypeDash)) { >+ } else if (resultType == NSTextCheckingTypeDash && checkingTypes.contains(TextCheckingType::Dash)) { > TextCheckingResult result; >- result.type = TextCheckingTypeDash; >+ result.type = TextCheckingType::Dash; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; > results.append(result); >- } else if (NSTextCheckingTypeReplacement == resultType && 0 != (checkingTypes & NSTextCheckingTypeReplacement)) { >+ } else if (resultType == NSTextCheckingTypeReplacement && checkingTypes.contains(TextCheckingType::Replacement)) { > TextCheckingResult result; >- result.type = TextCheckingTypeReplacement; >+ result.type = TextCheckingType::Replacement; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; > results.append(result); >- } else if (NSTextCheckingTypeCorrection == resultType && 0 != (checkingTypes & NSTextCheckingTypeCorrection)) { >+ } else if (resultType == NSTextCheckingTypeCorrection && checkingTypes.contains(TextCheckingType::Correction)) { > TextCheckingResult result; >- result.type = TextCheckingTypeCorrection; >+ result.type = TextCheckingType::Correction; > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = [incomingResult replacementString]; >@@ -1116,13 +1116,33 @@ static int insertionPointFromCurrentSelection(const VisibleSelection& currentSel > } > #endif > >-Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes, const VisibleSelection& currentSelection) >+constexpr NSTextCheckingTypes nsTextCheckingTypes(TextCheckingTypeMask types) >+{ >+ NSTextCheckingTypes mask = 0; >+ if (types.contains(TextCheckingType::Spelling)) >+ mask |= NSTextCheckingTypeSpelling; >+ if (types.contains(TextCheckingType::Grammar)) >+ mask |= NSTextCheckingTypeGrammar; >+ if (types.contains(TextCheckingType::Link)) >+ mask |= NSTextCheckingTypeLink; >+ if (types.contains(TextCheckingType::Quote)) >+ mask |= NSTextCheckingTypeQuote; >+ if (types.contains(TextCheckingType::Dash)) >+ mask |= NSTextCheckingTypeDash; >+ if (types.contains(TextCheckingType::Replacement)) >+ mask |= NSTextCheckingTypeReplacement; >+ if (types.contains(TextCheckingType::Correction)) >+ mask |= NSTextCheckingTypeCorrection; >+ return mask; >+} >+ >+Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask coreCheckingTypes, const VisibleSelection& currentSelection) > { > NSDictionary *options = nil; > #if HAVE(ADVANCED_SPELL_CHECKING) > options = @{ NSTextCheckingInsertionPointKey : [NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)] }; > #endif >- return core([[NSSpellChecker sharedSpellChecker] checkString:string.createNSStringWithoutCopying().get() range:NSMakeRange(0, string.length()) types:(checkingTypes | NSTextCheckingTypeOrthography) options:options inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL], checkingTypes); >+ return core([[NSSpellChecker sharedSpellChecker] checkString:string.createNSStringWithoutCopying().get() range:NSMakeRange(0, string.length()) types:(nsTextCheckingTypes(coreCheckingTypes) | NSTextCheckingTypeOrthography) options:options inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL], coreCheckingTypes); > } > > void WebEditorClient::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail) >diff --git a/Source/WebKitLegacy/mac/WebView/WebView.mm b/Source/WebKitLegacy/mac/WebView/WebView.mm >index d4d1e6efceaa6dbc493e86e26ce4f81611ea03df..9e8a4f4e6be980bc0d8df96c1f3ebb1ac4077672 100644 >--- a/Source/WebKitLegacy/mac/WebView/WebView.mm >+++ b/Source/WebKitLegacy/mac/WebView/WebView.mm >@@ -7282,29 +7282,29 @@ - (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSStr > return nil; > } > >-static TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult) >+constexpr TextCheckingType coreTextCheckingType(NSTextCheckingType type) > { >- WebCore::TextCheckingResult result; >- >- switch ([nsResult resultType]) { >- case NSTextCheckingTypeSpelling: >- result.type = WebCore::TextCheckingTypeSpelling; >- break; >- case NSTextCheckingTypeReplacement: >- result.type = WebCore::TextCheckingTypeReplacement; >- break; >+ switch (type) { > case NSTextCheckingTypeCorrection: >- result.type = WebCore::TextCheckingTypeCorrection; >- break; >+ return TextCheckingType::Correction; >+ case NSTextCheckingTypeReplacement: >+ return TextCheckingType::Replacement; >+ case NSTextCheckingTypeSpelling: >+ return TextCheckingType::Spelling; > default: >- result.type = WebCore::TextCheckingTypeNone; >+ return TextCheckingType::None; > } >+} > >+static TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult) >+{ > NSRange resultRange = nsResult.range; >+ >+ TextCheckingResult result; >+ result.type = coreTextCheckingType(nsResult.resultType); > result.location = resultRange.location; > result.length = resultRange.length; > result.replacement = nsResult.replacementString; >- > return result; > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188678
:
347303
|
347312
|
347313
|
347316
|
347318
|
347365
|
347562
|
347563
|
347565
|
347566
|
347603
|
347633