Changeset 148163 in webkit


Ignore:
Timestamp:
Apr 10, 2013 6:27:26 PM (11 years ago)
Author:
rniwa@webkit.org
Message:

Cleanup local variables in Editor::markAndReplaceFor
https://bugs.webkit.org/show_bug.cgi?id=114383

Reviewed by Enrica Casucci.

Added resultEndLocation, which is the sum of resultLocation and resultLength.

Also replaced ambiguousBoundaryOffset by useAmbiguousBoundaryOffset since the ambiguous offset is always
selectionOffset -1 to avoid the extra house keeping and obnoxious -1 check.

  • editing/Editor.cpp:

(WebCore::Editor::markAndReplaceFor):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r148159 r148163  
     12013-04-10  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Cleanup local variables in Editor::markAndReplaceFor
     4        https://bugs.webkit.org/show_bug.cgi?id=114383
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Added resultEndLocation, which is the sum of resultLocation and resultLength.
     9
     10        Also replaced ambiguousBoundaryOffset by useAmbiguousBoundaryOffset since the ambiguous offset is always
     11        selectionOffset -1 to avoid the extra house keeping and obnoxious -1 check.
     12
     13        * editing/Editor.cpp:
     14        (WebCore::Editor::markAndReplaceFor):
     15
    1162013-04-10  Benjamin Poulain  <bpoulain@apple.com>
    217
  • trunk/Source/WebCore/editing/Editor.cpp

    r148124 r148163  
    21842184    const bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel;
    21852185    const bool shouldCheckForCorrection = shouldShowCorrectionPanel || (textCheckingOptions & TextCheckingTypeCorrection);
     2186#if !USE(AUTOCORRECTION_PANEL)
     2187    ASSERT(!shouldShowCorrectionPanel);
     2188#endif
    21862189
    21872190    // Expand the range to encompass entire paragraphs, since text checking needs that much context.
    21882191    int selectionOffset = 0;
    2189     int ambiguousBoundaryOffset = -1;
     2192    bool useAmbiguousBoundaryOffset = false;
    21902193    bool selectionChanged = false;
    21912194    bool restoreSelectionAfterChange = false;
     
    22012204                adjustSelectionForParagraphBoundaries = true;
    22022205            if (selectionOffset > 0 && selectionOffset <= paragraph.textLength() && isAmbiguousBoundaryCharacter(paragraph.textCharAt(selectionOffset - 1)))
    2203                 ambiguousBoundaryOffset = selectionOffset - 1;
     2206                useAmbiguousBoundaryOffset = true;
    22042207        }
    22052208    }
     
    22122215        const int resultLocation = results[i].location + offsetDueToReplacement;
    22132216        const int resultLength = results[i].length;
     2217        const int resultEndLocation = resultLocation + resultLength;
    22142218        const String& replacement = results[i].replacement;
    2215         const bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && resultLocation + resultLength == ambiguousBoundaryOffset;
     2219        const bool resultEndsAtAmbiguousBoundary = useAmbiguousBoundaryOffset && resultEndLocation == selectionOffset - 1;
    22162220
    22172221        // Only mark misspelling if:
     
    22212225        //    "wouldn'" as misspelled right after apostrophe is typed.
    22222226        if (shouldMarkSpelling && !shouldShowCorrectionPanel && resultType == TextCheckingTypeSpelling
    2223             && resultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
     2227            && resultLocation >= paragraph.checkingStart() && resultEndLocation <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
    22242228            ASSERT(resultLength > 0 && resultLocation >= 0);
    22252229            RefPtr<Range> misspellingRange = paragraph.subrange(resultLocation, resultLength);
     
    22382242                }
    22392243            }
    2240         } else if (resultLocation + resultLength <= spellingRangeEndOffset && resultLocation + resultLength >= paragraph.checkingStart()
     2244        } else if (resultEndLocation <= spellingRangeEndOffset && resultEndLocation >= paragraph.checkingStart()
    22412245            && isAutomaticTextReplacementType(resultType)) {
    22422246            // In this case the result range just has to touch the spelling range, so we can handle replacing non-word text such as punctuation.
    22432247            ASSERT(resultLength > 0 && resultLocation >= 0);
    22442248
    2245             if (shouldShowCorrectionPanel && (resultLocation + resultLength < spellingRangeEndOffset || resultType != TextCheckingTypeCorrection))
     2249            if (shouldShowCorrectionPanel && (resultEndLocation < spellingRangeEndOffset || resultType != TextCheckingTypeCorrection))
    22462250                continue;
    22472251
     
    22542258
    22552259            // adding links should be done only immediately after they are typed
    2256             int resultEnd = resultLocation + resultLength;
    2257             if (resultType == TextCheckingTypeLink
    2258                 && (selectionOffset > resultEnd + 1 || selectionOffset <= resultLocation))
     2260            if (resultType == TextCheckingTypeLink && (selectionOffset > resultEndLocation + 1 || selectionOffset <= resultLocation))
    22592261                continue;
    22602262
     
    22682270
    22692271            if (shouldShowCorrectionPanel) {
    2270 #if !USE(AUTOCORRECTION_PANEL)
    2271                 ASSERT_NOT_REACHED();
    2272 #endif
    2273                 // shouldShowCorrectionPanel can be true only when the panel is available.
    2274                 if (resultLocation + resultLength == spellingRangeEndOffset) {
     2272                if (resultEndLocation == spellingRangeEndOffset) {
    22752273                    // We only show the correction panel on the last word.
    22762274                    m_alternativeTextController->show(rangeToReplace, replacement);
     
    23032301                selectionChanged = true;
    23042302                offsetDueToReplacement += replacement.length() - resultLength;
    2305                 if (resultLocation < selectionOffset) {
     2303                if (resultLocation < selectionOffset)
    23062304                    selectionOffset += replacement.length() - resultLength;
    2307                     if (ambiguousBoundaryOffset >= 0)
    2308                         ambiguousBoundaryOffset = selectionOffset - 1;
    2309                 }
    23102305
    23112306                // Add a marker so that corrections can easily be undone and won't be re-corrected.
Note: See TracChangeset for help on using the changeset viewer.