- Revision
- 233434
- Author
- [email protected]
- Date
- 2018-07-02 13:56:53 -0700 (Mon, 02 Jul 2018)
Log Message
Clean up some spellchecking code
https://bugs.webkit.org/show_bug.cgi?id=187238
Reviewed by Tim Horton.
A few minor tweaks to modernize some spellchecking code. No change in behavior.
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::timerFired):
* editing/Editor.cpp:
(WebCore::Editor::markMisspellingsAfterTypingToWord):
Use move semantics when passing Ranges to markAllMisspellingsAndBadGrammarInRanges.
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
Change this to take RefPtr<Range>&& instead of Range*.
(WebCore::Editor::markMisspellingsAndBadGrammar):
Remove an unnecessary call to `RefPtr::get()`.
* editing/Editor.h:
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingParagraph::invalidateParagraphRangeValues):
(WebCore::TextCheckingParagraph::checkingStart const):
(WebCore::TextCheckingParagraph::checkingEnd const):
(WebCore::TextCheckingParagraph::checkingLength const):
(WebCore::TextCheckingParagraph::automaticReplacementStart const):
(WebCore::TextCheckingParagraph::automaticReplacementLength const):
Currently, all of these cached range offsets are `int`s, and use a value of -1 to denote that their values are
missing and must be recomputed. Instead, make these `std::optional`s and let `std::nullopt` represent the
missing value.
* editing/TextCheckingHelper.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (233433 => 233434)
--- trunk/Source/WebCore/ChangeLog 2018-07-02 20:54:55 UTC (rev 233433)
+++ trunk/Source/WebCore/ChangeLog 2018-07-02 20:56:53 UTC (rev 233434)
@@ -1,3 +1,42 @@
+2018-07-02 Wenson Hsieh <[email protected]>
+
+ Clean up some spellchecking code
+ https://bugs.webkit.org/show_bug.cgi?id=187238
+
+ Reviewed by Tim Horton.
+
+ A few minor tweaks to modernize some spellchecking code. No change in behavior.
+
+ * editing/AlternativeTextController.cpp:
+ (WebCore::AlternativeTextController::timerFired):
+ * editing/Editor.cpp:
+ (WebCore::Editor::markMisspellingsAfterTypingToWord):
+
+ Use move semantics when passing Ranges to markAllMisspellingsAndBadGrammarInRanges.
+
+ (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
+
+ Change this to take RefPtr<Range>&& instead of Range*.
+
+ (WebCore::Editor::markMisspellingsAndBadGrammar):
+
+ Remove an unnecessary call to `RefPtr::get()`.
+
+ * editing/Editor.h:
+ * editing/TextCheckingHelper.cpp:
+ (WebCore::TextCheckingParagraph::invalidateParagraphRangeValues):
+ (WebCore::TextCheckingParagraph::checkingStart const):
+ (WebCore::TextCheckingParagraph::checkingEnd const):
+ (WebCore::TextCheckingParagraph::checkingLength const):
+ (WebCore::TextCheckingParagraph::automaticReplacementStart const):
+ (WebCore::TextCheckingParagraph::automaticReplacementLength const):
+
+ Currently, all of these cached range offsets are `int`s, and use a value of -1 to denote that their values are
+ missing and must be recomputed. Instead, make these `std::optional`s and let `std::nullopt` represent the
+ missing value.
+
+ * editing/TextCheckingHelper.h:
+
2018-07-02 Antoine Quint <[email protected]>
Crash in WebCore::WebAnimation::timeToNextRequiredTick when running imported/w3c/web-platform-tests/web-animations/interfaces/Animatable/animate-no-browsing-context.html
Modified: trunk/Source/WebCore/editing/AlternativeTextController.cpp (233433 => 233434)
--- trunk/Source/WebCore/editing/AlternativeTextController.cpp 2018-07-02 20:54:55 UTC (rev 233433)
+++ trunk/Source/WebCore/editing/AlternativeTextController.cpp 2018-07-02 20:56:53 UTC (rev 233434)
@@ -284,7 +284,7 @@
VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary);
VisibleSelection adjacentWords = VisibleSelection(p, start);
auto adjacentWordRange = adjacentWords.toNormalizedRange();
- m_frame.editor().markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeSpelling | TextCheckingTypeReplacement | TextCheckingTypeShowCorrectionPanel, adjacentWordRange.get(), adjacentWordRange.get(), nullptr);
+ m_frame.editor().markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeSpelling | TextCheckingTypeReplacement | TextCheckingTypeShowCorrectionPanel, adjacentWordRange.copyRef(), adjacentWordRange.copyRef(), nullptr);
}
break;
case AlternativeTextTypeReversion: {
Modified: trunk/Source/WebCore/editing/Editor.cpp (233433 => 233434)
--- trunk/Source/WebCore/editing/Editor.cpp 2018-07-02 20:54:55 UTC (rev 233433)
+++ trunk/Source/WebCore/editing/Editor.cpp 2018-07-02 20:56:53 UTC (rev 233434)
@@ -2343,7 +2343,7 @@
VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
auto adjacentWordRange = adjacentWords.toNormalizedRange();
- markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWordRange.get(), adjacentWordRange.get(), adjacentWordRange.get());
+ markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWordRange.copyRef(), adjacentWordRange.copyRef(), adjacentWordRange.copyRef());
#else
#if !USE(AUTOMATIC_TEXT_REPLACEMENT)
UNUSED_PARAM(doReplacement);
@@ -2428,7 +2428,7 @@
// full sentence as we can, respecting boundaries where spellchecking is disabled.
fullSentenceRange->ownerDocument().markers().removeMarkers(fullSentenceRange.get(), DocumentMarker::Grammar);
spellCheckingRange->ownerDocument().markers().removeMarkers(spellCheckingRange.get(), DocumentMarker::Spelling);
- markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellCheckingRange.get(), adjacentWordRange.get(), fullSentenceRange.get());
+ markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, WTFMove(spellCheckingRange), WTFMove(adjacentWordRange), WTFMove(fullSentenceRange));
return;
}
@@ -2552,7 +2552,7 @@
#endif
}
-void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* spellingRange, Range* automaticReplacementRange, Range* grammarRange)
+void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, RefPtr<Range>&& spellingRange, RefPtr<Range>&& automaticReplacementRange, RefPtr<Range>&& grammarRange)
{
ASSERT(unifiedTextCheckerEnabled());
@@ -2574,18 +2574,17 @@
if (!isSpellCheckingEnabledFor(&editableNode))
return;
- Range& rangeToCheck = shouldMarkGrammar ? *grammarRange : *spellingRange;
- TextCheckingParagraph paragraphToCheck(rangeToCheck);
+ auto rangeToCheck = shouldMarkGrammar ? grammarRange.releaseNonNull() : spellingRange.releaseNonNull();
+ TextCheckingParagraph paragraphToCheck(rangeToCheck.get());
if (paragraphToCheck.isEmpty())
return;
- Ref<Range> paragraphRange = paragraphToCheck.paragraphRange();
bool asynchronous = m_frame.settings().asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel;
// In asynchronous mode, we intentionally check paragraph-wide sentence.
const auto resolvedOptions = resolveTextCheckingTypeMask(editableNode, textCheckingOptions);
- auto& textReplacementRange = automaticReplacementRange ? *automaticReplacementRange : rangeToCheck;
- auto request = SpellCheckRequest::create(resolvedOptions, TextCheckingProcessIncremental, asynchronous ? paragraphRange.get() : rangeToCheck, textReplacementRange, paragraphRange.copyRef());
+ auto textReplacementRange = automaticReplacementRange ? makeRef(*automaticReplacementRange) : rangeToCheck.copyRef();
+ auto request = SpellCheckRequest::create(resolvedOptions, TextCheckingProcessIncremental, asynchronous ? makeRef(paragraphToCheck.paragraphRange()) : WTFMove(rangeToCheck), WTFMove(textReplacementRange), paragraphToCheck.paragraphRange());
if (!request)
return;
@@ -2838,7 +2837,7 @@
if (markGrammar && isGrammarCheckingEnabled())
textCheckingOptions |= TextCheckingTypeGrammar;
auto spellCheckingRange = spellingSelection.toNormalizedRange();
- markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellCheckingRange.get(), spellCheckingRange.get(), grammarSelection.toNormalizedRange().get());
+ markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellCheckingRange.copyRef(), spellCheckingRange.copyRef(), grammarSelection.toNormalizedRange());
return;
}
Modified: trunk/Source/WebCore/editing/Editor.h (233433 => 233434)
--- trunk/Source/WebCore/editing/Editor.h 2018-07-02 20:54:55 UTC (rev 233433)
+++ trunk/Source/WebCore/editing/Editor.h 2018-07-02 20:56:53 UTC (rev 233434)
@@ -293,7 +293,7 @@
bool isOverwriteModeEnabled() const { return m_overwriteModeEnabled; }
WEBCORE_EXPORT void toggleOverwriteModeEnabled();
- void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask, Range* spellingRange, Range* automaticReplacementRange, Range* grammarRange);
+ void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask, RefPtr<Range>&& spellingRange, RefPtr<Range>&& automaticReplacementRange, RefPtr<Range>&& grammarRange);
#if PLATFORM(IOS)
NO_RETURN_DUE_TO_ASSERT
#endif
Modified: trunk/Source/WebCore/editing/TextCheckingHelper.cpp (233433 => 233434)
--- trunk/Source/WebCore/editing/TextCheckingHelper.cpp 2018-07-02 20:54:55 UTC (rev 233433)
+++ trunk/Source/WebCore/editing/TextCheckingHelper.cpp 2018-07-02 20:56:53 UTC (rev 233434)
@@ -138,9 +138,10 @@
void TextCheckingParagraph::invalidateParagraphRangeValues()
{
- m_checkingStart = m_checkingEnd = -1;
- m_automaticReplacementStart = -1;
- m_automaticReplacementLength = -1;
+ m_checkingStart.reset();
+ m_checkingEnd.reset();
+ m_automaticReplacementStart.reset();
+ m_automaticReplacementLength.reset();
m_offsetAsRange = nullptr;
m_text = String();
}
@@ -198,43 +199,43 @@
int TextCheckingParagraph::checkingStart() const
{
- if (m_checkingStart == -1)
+ if (!m_checkingStart)
m_checkingStart = TextIterator::rangeLength(&offsetAsRange());
- return m_checkingStart;
+ return *m_checkingStart;
}
int TextCheckingParagraph::checkingEnd() const
{
- if (m_checkingEnd == -1)
+ if (!m_checkingEnd)
m_checkingEnd = checkingStart() + TextIterator::rangeLength(m_checkingRange.ptr());
- return m_checkingEnd;
+ return *m_checkingEnd;
}
int TextCheckingParagraph::checkingLength() const
{
- if (-1 == m_checkingLength)
+ if (!m_checkingLength)
m_checkingLength = TextIterator::rangeLength(m_checkingRange.ptr());
- return m_checkingLength;
+ return *m_checkingLength;
}
int TextCheckingParagraph::automaticReplacementStart() const
{
- if (m_automaticReplacementStart != -1)
- return m_automaticReplacementStart;
+ if (m_automaticReplacementStart)
+ return *m_automaticReplacementStart;
auto startOffsetRange = Range::create(paragraphRange().startContainer().document(), paragraphRange().startPosition(), m_automaticReplacementRange->startPosition());
m_automaticReplacementStart = TextIterator::rangeLength(startOffsetRange.ptr());
- return m_automaticReplacementStart;
+ return *m_automaticReplacementStart;
}
int TextCheckingParagraph::automaticReplacementLength() const
{
- if (m_automaticReplacementLength != -1)
- return m_automaticReplacementLength;
+ if (m_automaticReplacementLength)
+ return *m_automaticReplacementLength;
auto endOffsetRange = Range::create(paragraphRange().startContainer().document(), paragraphRange().startPosition(), m_automaticReplacementRange->endPosition());
m_automaticReplacementLength = TextIterator::rangeLength(endOffsetRange.ptr()) - automaticReplacementStart();
- return m_automaticReplacementLength;
+ return *m_automaticReplacementLength;
}
TextCheckingHelper::TextCheckingHelper(EditorClient& client, Range& range)
Modified: trunk/Source/WebCore/editing/TextCheckingHelper.h (233433 => 233434)
--- trunk/Source/WebCore/editing/TextCheckingHelper.h 2018-07-02 20:54:55 UTC (rev 233433)
+++ trunk/Source/WebCore/editing/TextCheckingHelper.h 2018-07-02 20:56:53 UTC (rev 233434)
@@ -75,11 +75,11 @@
mutable RefPtr<Range> m_paragraphRange;
mutable RefPtr<Range> m_offsetAsRange;
mutable String m_text;
- mutable int m_checkingStart { -1 };
- mutable int m_checkingEnd { -1 };
- mutable int m_checkingLength { -1 };
- mutable int m_automaticReplacementStart { -1 };
- mutable int m_automaticReplacementLength { -1 };
+ mutable std::optional<int> m_checkingStart;
+ mutable std::optional<int> m_checkingEnd;
+ mutable std::optional<int> m_checkingLength;
+ mutable std::optional<int> m_automaticReplacementStart;
+ mutable std::optional<int> m_automaticReplacementLength;
};
class TextCheckingHelper {