Title: [148163] trunk/Source/WebCore
- Revision
- 148163
- Author
- [email protected]
- Date
- 2013-04-10 18:27:26 -0700 (Wed, 10 Apr 2013)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (148162 => 148163)
--- trunk/Source/WebCore/ChangeLog 2013-04-11 01:25:33 UTC (rev 148162)
+++ trunk/Source/WebCore/ChangeLog 2013-04-11 01:27:26 UTC (rev 148163)
@@ -1,3 +1,18 @@
+2013-04-10 Ryosuke Niwa <[email protected]>
+
+ 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):
+
2013-04-10 Benjamin Poulain <[email protected]>
Mass remove all the empty directories
Modified: trunk/Source/WebCore/editing/Editor.cpp (148162 => 148163)
--- trunk/Source/WebCore/editing/Editor.cpp 2013-04-11 01:25:33 UTC (rev 148162)
+++ trunk/Source/WebCore/editing/Editor.cpp 2013-04-11 01:27:26 UTC (rev 148163)
@@ -2183,10 +2183,13 @@
const bool shouldPerformReplacement = textCheckingOptions & TextCheckingTypeReplacement;
const bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel;
const bool shouldCheckForCorrection = shouldShowCorrectionPanel || (textCheckingOptions & TextCheckingTypeCorrection);
+#if !USE(AUTOCORRECTION_PANEL)
+ ASSERT(!shouldShowCorrectionPanel);
+#endif
// Expand the range to encompass entire paragraphs, since text checking needs that much context.
int selectionOffset = 0;
- int ambiguousBoundaryOffset = -1;
+ bool useAmbiguousBoundaryOffset = false;
bool selectionChanged = false;
bool restoreSelectionAfterChange = false;
bool adjustSelectionForParagraphBoundaries = false;
@@ -2200,7 +2203,7 @@
if (selectionOffset > 0 && (selectionOffset > paragraph.textLength() || paragraph.textCharAt(selectionOffset - 1) == newlineCharacter))
adjustSelectionForParagraphBoundaries = true;
if (selectionOffset > 0 && selectionOffset <= paragraph.textLength() && isAmbiguousBoundaryCharacter(paragraph.textCharAt(selectionOffset - 1)))
- ambiguousBoundaryOffset = selectionOffset - 1;
+ useAmbiguousBoundaryOffset = true;
}
}
@@ -2211,8 +2214,9 @@
const TextCheckingType resultType = results[i].type;
const int resultLocation = results[i].location + offsetDueToReplacement;
const int resultLength = results[i].length;
+ const int resultEndLocation = resultLocation + resultLength;
const String& replacement = results[i].replacement;
- const bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && resultLocation + resultLength == ambiguousBoundaryOffset;
+ const bool resultEndsAtAmbiguousBoundary = useAmbiguousBoundaryOffset && resultEndLocation == selectionOffset - 1;
// Only mark misspelling if:
// 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false.
@@ -2220,7 +2224,7 @@
// 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
- && resultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
+ && resultLocation >= paragraph.checkingStart() && resultEndLocation <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
ASSERT(resultLength > 0 && resultLocation >= 0);
RefPtr<Range> misspellingRange = paragraph.subrange(resultLocation, resultLength);
if (!m_alternativeTextController->isSpellingMarkerAllowed(misspellingRange))
@@ -2237,12 +2241,12 @@
badGrammarRange->startContainer()->document()->markers()->addMarker(badGrammarRange.get(), DocumentMarker::Grammar, detail.userDescription);
}
}
- } else if (resultLocation + resultLength <= spellingRangeEndOffset && resultLocation + resultLength >= paragraph.checkingStart()
+ } else if (resultEndLocation <= spellingRangeEndOffset && resultEndLocation >= paragraph.checkingStart()
&& isAutomaticTextReplacementType(resultType)) {
// In this case the result range just has to touch the spelling range, so we can handle replacing non-word text such as punctuation.
ASSERT(resultLength > 0 && resultLocation >= 0);
- if (shouldShowCorrectionPanel && (resultLocation + resultLength < spellingRangeEndOffset || resultType != TextCheckingTypeCorrection))
+ if (shouldShowCorrectionPanel && (resultEndLocation < spellingRangeEndOffset || resultType != TextCheckingTypeCorrection))
continue;
// Apply replacement if:
@@ -2253,9 +2257,7 @@
RefPtr<Range> rangeToReplace = paragraph.subrange(resultLocation, resultLength);
// adding links should be done only immediately after they are typed
- int resultEnd = resultLocation + resultLength;
- if (resultType == TextCheckingTypeLink
- && (selectionOffset > resultEnd + 1 || selectionOffset <= resultLocation))
+ if (resultType == TextCheckingTypeLink && (selectionOffset > resultEndLocation + 1 || selectionOffset <= resultLocation))
continue;
if (!(shouldPerformReplacement || shouldCheckForCorrection || shouldMarkLink) || !doReplacement)
@@ -2267,11 +2269,7 @@
continue;
if (shouldShowCorrectionPanel) {
-#if !USE(AUTOCORRECTION_PANEL)
- ASSERT_NOT_REACHED();
-#endif
- // shouldShowCorrectionPanel can be true only when the panel is available.
- if (resultLocation + resultLength == spellingRangeEndOffset) {
+ if (resultEndLocation == spellingRangeEndOffset) {
// We only show the correction panel on the last word.
m_alternativeTextController->show(rangeToReplace, replacement);
break;
@@ -2302,11 +2300,8 @@
selectionChanged = true;
offsetDueToReplacement += replacement.length() - resultLength;
- if (resultLocation < selectionOffset) {
+ if (resultLocation < selectionOffset)
selectionOffset += replacement.length() - resultLength;
- if (ambiguousBoundaryOffset >= 0)
- ambiguousBoundaryOffset = selectionOffset - 1;
- }
// Add a marker so that corrections can easily be undone and won't be re-corrected.
if (resultType == TextCheckingTypeCorrection)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes