Skip to content

Commit

Permalink
EWordSide should be an enum class
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261770
rdar://115743034

Reviewed by Michael Catanzaro.

This commit narrows down the underlying type of EWordSide and converts it
to an enum class for type safety.

* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::startCharacterOffsetOfWord):
(WebCore::AXObjectCache::endCharacterOffsetOfWord):
(WebCore::AXObjectCache::previousWordStartCharacterOffset):
(WebCore::AXObjectCache::nextWordEndCharacterOffset):
(WebCore::AXObjectCache::leftWordRange):
(WebCore::AXObjectCache::rightWordRange):
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::positionOfLeftWord const):
(WebCore::AccessibilityObject::positionOfRightWord const):
* Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:
(WebCore::AccessibilityObjectAtspi::boundaryOffset const):
* Source/WebCore/editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyPendingCorrection):
(WebCore::AlternativeTextController::timerFired):
(WebCore::AlternativeTextController::respondToChangedSelection):
* Source/WebCore/editing/Editor.cpp:
(WebCore::didApplyAutocorrection):
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::updateMarkersForWordsAffectedByEditing):
(WebCore::Editor::editorUIUpdateTimerFired):
* Source/WebCore/editing/TypingCommand.cpp:
(WebCore::TypingCommand::markMisspellingsAfterTyping):
* Source/WebCore/editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::adjustSelectionRespectingGranularity):
* Source/WebCore/editing/VisibleUnits.cpp:
(WebCore::startOfWord):
(WebCore::endOfWord):
(WebCore::isStartOfWord):
(WebCore::atBoundaryOfGranularity):
(WebCore::withinTextUnitOfGranularity):
(WebCore::nextWordBoundaryInDirection):
(WebCore::enclosingTextUnitOfGranularity):
* Source/WebCore/editing/VisibleUnits.h:

Canonical link: https://commits.webkit.org/268296@main
  • Loading branch information
aprotyas committed Sep 22, 2023
1 parent 5aa322f commit 456666e
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 67 deletions.
16 changes: 8 additions & 8 deletions Source/WebCore/accessibility/AXObjectCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3247,13 +3247,13 @@ CharacterOffset AXObjectCache::previousCharacterOffset(const CharacterOffset& ch
return characterOffsetForNodeAndOffset(*characterOffset.node, previousOffset, TraverseOptionIncludeStart);
}

CharacterOffset AXObjectCache::startCharacterOffsetOfWord(const CharacterOffset& characterOffset, EWordSide side)
CharacterOffset AXObjectCache::startCharacterOffsetOfWord(const CharacterOffset& characterOffset, WordSide side)
{
if (characterOffset.isNull())
return CharacterOffset();

CharacterOffset c = characterOffset;
if (side == RightWordIfOnBoundary) {
if (side == WordSide::RightWordIfOnBoundary) {
CharacterOffset endOfParagraph = endCharacterOffsetOfParagraph(c);
if (c.isEqual(endOfParagraph))
return c;
Expand All @@ -3269,13 +3269,13 @@ CharacterOffset AXObjectCache::startCharacterOffsetOfWord(const CharacterOffset&
return previousBoundary(c, startWordBoundary);
}

CharacterOffset AXObjectCache::endCharacterOffsetOfWord(const CharacterOffset& characterOffset, EWordSide side)
CharacterOffset AXObjectCache::endCharacterOffsetOfWord(const CharacterOffset& characterOffset, WordSide side)
{
if (characterOffset.isNull())
return CharacterOffset();

CharacterOffset c = characterOffset;
if (side == LeftWordIfOnBoundary) {
if (side == WordSide::LeftWordIfOnBoundary) {
CharacterOffset startOfParagraph = startCharacterOffsetOfParagraph(c);
if (c.isEqual(startOfParagraph))
return c;
Expand All @@ -3301,7 +3301,7 @@ CharacterOffset AXObjectCache::previousWordStartCharacterOffset(const CharacterO
if (previousOffset.isNull())
return CharacterOffset();

return startCharacterOffsetOfWord(previousOffset, RightWordIfOnBoundary);
return startCharacterOffsetOfWord(previousOffset, WordSide::RightWordIfOnBoundary);
}

CharacterOffset AXObjectCache::nextWordEndCharacterOffset(const CharacterOffset& characterOffset)
Expand All @@ -3313,19 +3313,19 @@ CharacterOffset AXObjectCache::nextWordEndCharacterOffset(const CharacterOffset&
if (nextOffset.isNull())
return CharacterOffset();

return endCharacterOffsetOfWord(nextOffset, LeftWordIfOnBoundary);
return endCharacterOffsetOfWord(nextOffset, WordSide::LeftWordIfOnBoundary);
}

std::optional<SimpleRange> AXObjectCache::leftWordRange(const CharacterOffset& characterOffset)
{
CharacterOffset start = startCharacterOffsetOfWord(characterOffset, LeftWordIfOnBoundary);
CharacterOffset start = startCharacterOffsetOfWord(characterOffset, WordSide::LeftWordIfOnBoundary);
CharacterOffset end = endCharacterOffsetOfWord(start);
return rangeForUnorderedCharacterOffsets(start, end);
}

std::optional<SimpleRange> AXObjectCache::rightWordRange(const CharacterOffset& characterOffset)
{
CharacterOffset start = startCharacterOffsetOfWord(characterOffset, RightWordIfOnBoundary);
CharacterOffset start = startCharacterOffsetOfWord(characterOffset, WordSide::RightWordIfOnBoundary);
CharacterOffset end = endCharacterOffsetOfWord(start);
return rangeForUnorderedCharacterOffsets(start, end);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/accessibility/AXObjectCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ class AXObjectCache : public CanMakeWeakPtr<AXObjectCache>, public CanMakeChecke
enum class NeedsContextAtParagraphStart : bool { No, Yes };
CharacterOffset previousBoundary(const CharacterOffset&, BoundarySearchFunction, NeedsContextAtParagraphStart = NeedsContextAtParagraphStart::No);
CharacterOffset nextBoundary(const CharacterOffset&, BoundarySearchFunction);
CharacterOffset startCharacterOffsetOfWord(const CharacterOffset&, EWordSide = RightWordIfOnBoundary);
CharacterOffset endCharacterOffsetOfWord(const CharacterOffset&, EWordSide = RightWordIfOnBoundary);
CharacterOffset startCharacterOffsetOfWord(const CharacterOffset&, WordSide = WordSide::RightWordIfOnBoundary);
CharacterOffset endCharacterOffsetOfWord(const CharacterOffset&, WordSide = WordSide::RightWordIfOnBoundary);
CharacterOffset startCharacterOffsetOfParagraph(const CharacterOffset&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
CharacterOffset endCharacterOffsetOfParagraph(const CharacterOffset&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
CharacterOffset startCharacterOffsetOfSentence(const CharacterOffset&);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/accessibility/AccessibilityObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,13 +1455,13 @@ VisiblePositionRange AccessibilityObject::visiblePositionRangeForUnorderedPositi

VisiblePositionRange AccessibilityObject::positionOfLeftWord(const VisiblePosition& visiblePos) const
{
auto start = startOfWord(visiblePos, LeftWordIfOnBoundary);
auto start = startOfWord(visiblePos, WordSide::LeftWordIfOnBoundary);
return { start, endOfWord(start) };
}

VisiblePositionRange AccessibilityObject::positionOfRightWord(const VisiblePosition& visiblePos) const
{
auto start = startOfWord(visiblePos, RightWordIfOnBoundary);
auto start = startOfWord(visiblePos, WordSide::RightWordIfOnBoundary);
return { start, endOfWord(start) };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ IntPoint AccessibilityObjectAtspi::boundaryOffset(unsigned utf16Offset, TextGran
if (!utf16Offset && m_hasListMarkerAtStart)
return { 0, 1 };

startPosition = isStartOfWord(offsetPosition) && deprecatedIsEditingWhitespace(offsetPosition.characterBefore()) ? offsetPosition : startOfWord(offsetPosition, LeftWordIfOnBoundary);
startPosition = isStartOfWord(offsetPosition) && deprecatedIsEditingWhitespace(offsetPosition.characterBefore()) ? offsetPosition : startOfWord(offsetPosition, WordSide::LeftWordIfOnBoundary);
endPostion = nextWordPosition(startPosition);
auto positionAfterSpacingAndFollowingWord = nextWordPosition(endPostion);
if (positionAfterSpacingAndFollowingWord != endPostion) {
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/editing/AlternativeTextController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void AlternativeTextController::applyPendingCorrection(const VisibleSelection& s
// Apply pending autocorrection before next round of spell checking.
bool doApplyCorrection = true;
VisiblePosition startOfSelection = selectionAfterTyping.visibleStart();
VisibleSelection currentWord = VisibleSelection(startOfWord(startOfSelection, LeftWordIfOnBoundary), endOfWord(startOfSelection, RightWordIfOnBoundary));
VisibleSelection currentWord = VisibleSelection(startOfWord(startOfSelection, WordSide::LeftWordIfOnBoundary), endOfWord(startOfSelection, WordSide::RightWordIfOnBoundary));
if (currentWord.visibleEnd() == startOfSelection) {
if (auto wordRange = currentWord.firstRange()) {
String wordText = plainText(*wordRange);
Expand Down Expand Up @@ -253,7 +253,7 @@ void AlternativeTextController::timerFired()
case AlternativeTextType::Correction: {
VisibleSelection selection(m_document.selection().selection());
VisiblePosition start(selection.start(), selection.affinity());
VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary);
VisiblePosition p = startOfWord(start, WordSide::LeftWordIfOnBoundary);
VisibleSelection adjacentWords = VisibleSelection(p, start);
auto adjacentWordRange = adjacentWords.toNormalizedRange();
m_document.editor().markAllMisspellingsAndBadGrammarInRanges({ TextCheckingType::Spelling, TextCheckingType::Replacement, TextCheckingType::ShowCorrectionPanel }, adjacentWordRange, adjacentWordRange, std::nullopt);
Expand Down Expand Up @@ -407,7 +407,7 @@ void AlternativeTextController::respondToChangedSelection(const VisibleSelection
if (selectionPosition.isNull())
return;

VisiblePosition endPositionOfWord = endOfWord(selectionPosition, LeftWordIfOnBoundary);
VisiblePosition endPositionOfWord = endOfWord(selectionPosition, WordSide::LeftWordIfOnBoundary);
if (selectionPosition != endPositionOfWord)
return;

Expand Down
40 changes: 20 additions & 20 deletions Source/WebCore/editing/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ static inline bool didApplyAutocorrection(Document& document, AlternativeTextCon
auto selection = document.selection().selection();
auto startOfSelection = selection.start();

auto wordStart = startOfWord(startOfSelection, LeftWordIfOnBoundary);
auto wordEnd = endOfWord(startOfSelection, LeftWordIfOnBoundary);
auto wordStart = startOfWord(startOfSelection, WordSide::LeftWordIfOnBoundary);
auto wordEnd = endOfWord(startOfSelection, WordSide::LeftWordIfOnBoundary);

if (auto range = makeSimpleRange(wordStart, wordEnd)) {
if (document.markers().hasMarkers(*range, DocumentMarker::CorrectionIndicator))
Expand Down Expand Up @@ -2697,7 +2697,7 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition& wordStart,
if (!textCheckingOptions.contains(TextCheckingType::Spelling))
return;

auto adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
auto adjacentWords = VisibleSelection(startOfWord(wordStart, WordSide::LeftWordIfOnBoundary), endOfWord(wordStart, WordSide::RightWordIfOnBoundary));
auto adjacentWordRange = adjacentWords.toNormalizedRange();

#if ENABLE(POST_EDITING_GRAMMAR_CHECKING)
Expand Down Expand Up @@ -2790,7 +2790,7 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition& wordStart,
if (!spellCheckingRange)
return;

auto adjacentWordRange = intersection(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)).toNormalizedRange(), fullSentenceRange);
auto adjacentWordRange = intersection(VisibleSelection(startOfWord(wordStart, WordSide::LeftWordIfOnBoundary), endOfWord(wordStart, WordSide::RightWordIfOnBoundary)).toNormalizedRange(), fullSentenceRange);
if (!adjacentWordRange)
return;

Expand All @@ -2808,7 +2808,7 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition& wordStart,
return;

// Check spelling of one word
auto misspellingRange = markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)));
auto misspellingRange = markMisspellings(VisibleSelection(startOfWord(wordStart, WordSide::LeftWordIfOnBoundary), endOfWord(wordStart, WordSide::RightWordIfOnBoundary)));

// Autocorrect the misspelled word.
if (!misspellingRange)
Expand Down Expand Up @@ -3245,20 +3245,20 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA
if (startOfSelection.isNull())
return;
// First word is the word that ends after or on the start of selection.
VisiblePosition startOfFirstWord = startOfWord(startOfSelection, LeftWordIfOnBoundary);
VisiblePosition endOfFirstWord = endOfWord(startOfSelection, LeftWordIfOnBoundary);
VisiblePosition startOfFirstWord = startOfWord(startOfSelection, WordSide::LeftWordIfOnBoundary);
VisiblePosition endOfFirstWord = endOfWord(startOfSelection, WordSide::LeftWordIfOnBoundary);
// Last word is the word that begins before or on the end of selection
VisiblePosition startOfLastWord = startOfWord(endOfSelection, RightWordIfOnBoundary);
VisiblePosition endOfLastWord = endOfWord(endOfSelection, RightWordIfOnBoundary);
VisiblePosition startOfLastWord = startOfWord(endOfSelection, WordSide::RightWordIfOnBoundary);
VisiblePosition endOfLastWord = endOfWord(endOfSelection, WordSide::RightWordIfOnBoundary);

if (startOfFirstWord.isNull()) {
startOfFirstWord = startOfWord(startOfSelection, RightWordIfOnBoundary);
endOfFirstWord = endOfWord(startOfSelection, RightWordIfOnBoundary);
startOfFirstWord = startOfWord(startOfSelection, WordSide::RightWordIfOnBoundary);
endOfFirstWord = endOfWord(startOfSelection, WordSide::RightWordIfOnBoundary);
}

if (endOfLastWord.isNull()) {
startOfLastWord = startOfWord(endOfSelection, LeftWordIfOnBoundary);
endOfLastWord = endOfWord(endOfSelection, LeftWordIfOnBoundary);
startOfLastWord = startOfWord(endOfSelection, WordSide::LeftWordIfOnBoundary);
endOfLastWord = endOfWord(endOfSelection, WordSide::LeftWordIfOnBoundary);
}

auto originalEndOfFirstWord = endOfFirstWord;
Expand All @@ -3268,7 +3268,7 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA
// we choose next word as the first word.
if (doNotRemoveIfSelectionAtWordBoundary && endOfFirstWord == startOfSelection) {
startOfFirstWord = nextWordPosition(startOfFirstWord);
endOfFirstWord = endOfWord(startOfFirstWord, RightWordIfOnBoundary);
endOfFirstWord = endOfWord(startOfFirstWord, WordSide::RightWordIfOnBoundary);
if (startOfFirstWord == originalStartOfLastWord)
return;
}
Expand All @@ -3277,7 +3277,7 @@ void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionA
// we choose previous word as the last word.
if (doNotRemoveIfSelectionAtWordBoundary && startOfLastWord == endOfSelection) {
startOfLastWord = previousWordPosition(startOfLastWord);
endOfLastWord = endOfWord(startOfLastWord, RightWordIfOnBoundary);
endOfLastWord = endOfWord(startOfLastWord, WordSide::RightWordIfOnBoundary);
if (endOfLastWord == originalEndOfFirstWord)
return;
}
Expand Down Expand Up @@ -4008,18 +4008,18 @@ void Editor::editorUIUpdateTimerFired()
if (document->selection().selection().isContentEditable() || caretBrowsing) {
VisiblePosition newStart(document->selection().selection().visibleStart());
#if !PLATFORM(IOS_FAMILY)
newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
newAdjacentWords = VisibleSelection(startOfWord(newStart, WordSide::LeftWordIfOnBoundary), endOfWord(newStart, WordSide::RightWordIfOnBoundary));
#else
// If this bug gets fixed, this PLATFORM(IOS_FAMILY) code could be removed:
// <rdar://problem/7259611> Word boundary code on iPhone gives different results than desktop
EWordSide startWordSide = LeftWordIfOnBoundary;
WordSide startWordSide = WordSide::LeftWordIfOnBoundary;
UChar32 c = newStart.characterBefore();
// FIXME: VisiblePosition::characterAfter() and characterBefore() do not emit newlines the same
// way as TextIterator, so we do an isStartOfParagraph check here.
if (deprecatedIsSpaceOrNewline(c) || c == noBreakSpace || isStartOfParagraph(newStart)) {
startWordSide = RightWordIfOnBoundary;
startWordSide = WordSide::RightWordIfOnBoundary;
}
newAdjacentWords = VisibleSelection(startOfWord(newStart, startWordSide), endOfWord(newStart, RightWordIfOnBoundary));
newAdjacentWords = VisibleSelection(startOfWord(newStart, startWordSide), endOfWord(newStart, WordSide::RightWordIfOnBoundary));
#endif // !PLATFORM(IOS_FAMILY)
if (isContinuousGrammarCheckingEnabled)
newSelectedSentence = VisibleSelection(startOfSentence(newStart), endOfSentence(newStart));
Expand All @@ -4030,7 +4030,7 @@ void Editor::editorUIUpdateTimerFired()
// oldSelection may no longer be in the document.
if (m_editorUIUpdateTimerShouldCheckSpellingAndGrammar && oldSelection.isContentEditable() && oldSelection.start().deprecatedNode() && oldSelection.start().anchorNode()->isConnected()) {
VisiblePosition oldStart(oldSelection.visibleStart());
VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, WordSide::LeftWordIfOnBoundary), endOfWord(oldStart, WordSide::RightWordIfOnBoundary));
if (oldAdjacentWords != newAdjacentWords) {
if (isContinuousGrammarCheckingEnabled) {
VisibleSelection oldSelectedSentence = VisibleSelection(startOfSentence(oldStart), endOfSentence(oldStart));
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/editing/TypingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ void TypingCommand::markMisspellingsAfterTyping(Type commandType)
VisiblePosition previous = start.previous();
if (previous.isNotNull()) {
#if !PLATFORM(IOS_FAMILY)
VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary);
VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary);
VisiblePosition p1 = startOfWord(previous, WordSide::LeftWordIfOnBoundary);
VisiblePosition p2 = startOfWord(start, WordSide::LeftWordIfOnBoundary);
if (p1 != p2) {
auto range = makeSimpleRange(p1, p2);
String trimmedPreviousWord;
Expand All @@ -475,12 +475,12 @@ void TypingCommand::markMisspellingsAfterTyping(Type commandType)
UNUSED_PARAM(commandType);
// If this bug gets fixed, this PLATFORM(IOS_FAMILY) code could be removed:
// <rdar://problem/7259611> Word boundary code on iPhone gives different results than desktop
EWordSide startWordSide = LeftWordIfOnBoundary;
WordSide startWordSide = WordSide::LeftWordIfOnBoundary;
UChar32 c = previous.characterAfter();
// FIXME: VisiblePosition::characterAfter() and characterBefore() do not emit newlines the same
// way as TextIterator, so we do an isEndOfParagraph check here.
if (deprecatedIsSpaceOrNewline(c) || c == noBreakSpace || isEndOfParagraph(previous)) {
startWordSide = RightWordIfOnBoundary;
startWordSide = WordSide::RightWordIfOnBoundary;
}
VisiblePosition p1 = startOfWord(previous, startWordSide);
VisiblePosition p2 = startOfWord(start, startWordSide);
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/editing/VisibleSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ void VisibleSelection::adjustSelectionRespectingGranularity(TextGranularity gran
// last word to the line break (also RightWordIfOnBoundary);
VisiblePosition start = VisiblePosition(m_start, m_affinity);
VisiblePosition originalEnd(m_end, m_affinity);
EWordSide side = RightWordIfOnBoundary;
WordSide side = WordSide::RightWordIfOnBoundary;
if (isEndOfEditableOrNonEditableContent(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
side = LeftWordIfOnBoundary;
side = WordSide::LeftWordIfOnBoundary;
m_start = startOfWord(start, side).deepEquivalent();
side = RightWordIfOnBoundary;
side = WordSide::RightWordIfOnBoundary;
if (isEndOfEditableOrNonEditableContent(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
side = LeftWordIfOnBoundary;
side = WordSide::LeftWordIfOnBoundary;

VisiblePosition wordEnd(endOfWord(originalEnd, side));
VisiblePosition end(wordEnd);
Expand Down
Loading

0 comments on commit 456666e

Please sign in to comment.