Commit a563e17c authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

2010-11-19 Jia Pu <jpu@apple.com>

        Reviewed by Dan Bernstein.

        Regression: contraction is considered misspelling.
        https://bugs.webkit.org/show_bug.cgi?id=49423
        <rdar://problem/8654206>

        * platform/mac-leopard/Skipped:
        * platform/mac-snowleopard/Skipped:
        * platform/mac-tiger/Skipped:
        * platform/mac-wk2/Skipped:
        * platform/mac/editing/spelling/autocorrection-contraction-expected.checksum: Added.
        * platform/mac/editing/spelling/autocorrection-contraction-expected.png: Added.
        * platform/mac/editing/spelling/autocorrection-contraction-expected.txt: Added.
        * platform/mac/editing/spelling/autocorrection-contraction.html: Added.
2010-11-19  Jia Pu  <jpu@apple.com>

        Reviewed by Dan Bernstein.

        Regression: contraction is considered misspelling.
        https://bugs.webkit.org/show_bug.cgi?id=49423
        <rdar://problem/8654206>

        Test: platform/mac/editing/spelling/autocorrection-contraction.html
              manual-tests/autocorrection/autocorrection-contraction.html

        * editing/Editor.cpp:
        (WebCore::isAmbiguousBoundaryCharacter): Moved function to the top of the file so that it can
          be used by all other functions in the file.
        (WebCore::Editor::markMisspellingsAfterTypingToWord): Renamed markMisspellingsAfterTypingToPosition()
          to improve readability, and to pass in additional argument. Before we apply pending
          autocorrection, we check to see if currently typed character makes current word a partial
          contraction, for instance "wouldn'". If that's the case, we would not apply the pending
          correction.
        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Make sure currently typed word
          is not a partial contraction, such as "wouldn'", before mark it as misspelled. Also update
          the location of ambiguous boundary if other replacements have changed the length of the
          paragraph.
        * editing/Editor.h:
        * editing/TypingCommand.cpp:
        (WebCore::TypingCommand::markMisspellingsAfterTyping): Adopt renamed function.
        * manual-tests/autocorrection/autocorrection-contraction.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72469 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 91d38a7e
2010-11-19 Jia Pu <jpu@apple.com>
Reviewed by Dan Bernstein.
Regression: contraction is considered misspelling.
https://bugs.webkit.org/show_bug.cgi?id=49423
<rdar://problem/8654206>
* platform/mac-leopard/Skipped:
* platform/mac-snowleopard/Skipped:
* platform/mac-tiger/Skipped:
* platform/mac-wk2/Skipped:
* platform/mac/editing/spelling/autocorrection-contraction-expected.checksum: Added.
* platform/mac/editing/spelling/autocorrection-contraction-expected.png: Added.
* platform/mac/editing/spelling/autocorrection-contraction-expected.txt: Added.
* platform/mac/editing/spelling/autocorrection-contraction.html: Added.
2010-11-19 James Simonsen <simonjam@chromium.org>
 
Reviewed by Tony Chang.
......@@ -100,6 +100,7 @@ media/video-played-ranges-1.html
media/video-played-reset.html
# Disable spelling tests for autocorrection panel
platform/mac/editing/spelling/autocorrection-contraction.html
platform/mac/editing/spelling/autocorrection-delete.html
platform/mac/editing/spelling/autocorrection-removing-underline-after-paste.html
platform/mac/editing/spelling/autocorrection-removing-underline.html
......
......@@ -125,6 +125,7 @@ canvas/philip/tests/2d.gradient.interpolate.overlap.html
canvas/philip/tests/2d.gradient.interpolate.overlap2.html
# Disable spelling tests for autocorrection panel
platform/mac/editing/spelling/autocorrection-contraction.html
platform/mac/editing/spelling/autocorrection-delete.html
platform/mac/editing/spelling/autocorrection-removing-underline-after-paste.html
platform/mac/editing/spelling/autocorrection-removing-underline.html
......
......@@ -205,6 +205,7 @@ fast/harness/show-modal-dialog.html
http/tests/misc/401-alternative-content.php
# Disable spelling tests for autocorrection panel
platform/mac/editing/spelling/autocorrection-contraction.html
platform/mac/editing/spelling/autocorrection-delete.html
platform/mac/editing/spelling/autocorrection-removing-underline-after-paste.html
platform/mac/editing/spelling/autocorrection-removing-underline.html
......
......@@ -488,6 +488,7 @@ platform/mac/editing/deleting/backward-delete.html
platform/mac/editing/pasteboard/dataTransfer-set-data-file-url.html
platform/mac/editing/selection/doubleclick-should-not-expand-across-lines.html
platform/mac/editing/selection/word-thai.html
platform/mac/editing/spelling/autocorrection-contraction.html
platform/mac/editing/spelling/autocorrection-delete.html
platform/mac/editing/spelling/autocorrection-removing-underline-after-paste.html
platform/mac/editing/spelling/autocorrection-removing-underline.html
......
930bf7053c4d5296bb0e8eca1beff5d4
\ No newline at end of file
<html>
<head>
<style>
.editing {
border: 2px solid red;
padding: 12px;
font-size: 24px;
}
</style>
<script src=../../../../editing/editing.js language="JavaScript" type="text/JavaScript" ></script>
<script>
function editingTest() {
typeCharacterCommand('t');
typeCharacterCommand('h');
typeCharacterCommand('i');
typeCharacterCommand('s');
typeCharacterCommand(' ');
typeCharacterCommand('w');
typeCharacterCommand('a');
typeCharacterCommand('s');
typeCharacterCommand('n');
typeCharacterCommand('\'');
typeCharacterCommand('t');
typeCharacterCommand(' ');
typeCharacterCommand('\n');
typeCharacterCommand('t');
typeCharacterCommand('h');
typeCharacterCommand('i');
typeCharacterCommand('s');
typeCharacterCommand(' ');
typeCharacterCommand('w');
typeCharacterCommand('o');
typeCharacterCommand('u');
typeCharacterCommand('l');
typeCharacterCommand('d');
typeCharacterCommand('n');
typeCharacterCommand('\'');
typeCharacterCommand('t');
typeCharacterCommand(' ');
typeCharacterCommand('\n');
typeCharacterCommand('t');
typeCharacterCommand('h');
typeCharacterCommand('i');
typeCharacterCommand('s');
typeCharacterCommand(' ');
typeCharacterCommand('d');
typeCharacterCommand('o');
typeCharacterCommand('e');
typeCharacterCommand('s');
typeCharacterCommand('n');
typeCharacterCommand('\'');
typeCharacterCommand('t');
typeCharacterCommand(' ');
typeCharacterCommand('\n');
typeCharacterCommand('w');
typeCharacterCommand('o');
typeCharacterCommand('u');
typeCharacterCommand('l');
typeCharacterCommand('d');
typeCharacterCommand('n');
typeCharacterCommand(' ');
typeCharacterCommand('w');
typeCharacterCommand('o');
typeCharacterCommand('u');
typeCharacterCommand('l');
typeCharacterCommand('d');
typeCharacterCommand('n');
typeCharacterCommand('\'');
typeCharacterCommand('t');
typeCharacterCommand('\n');
typeCharacterCommand('w');
typeCharacterCommand('o');
typeCharacterCommand('u');
typeCharacterCommand('l');
typeCharacterCommand('d');
typeCharacterCommand('n');
typeCharacterCommand('\'');
typeCharacterCommand(' ');
typeCharacterCommand('w');
typeCharacterCommand('o');
typeCharacterCommand('u');
typeCharacterCommand('l');
typeCharacterCommand('d');
typeCharacterCommand('n');
typeCharacterCommand('\'');
typeCharacterCommand('t');
typeCharacterCommand(' ');
}
</script>
<title>Autocorrection Contraction Test</title>
</head>
<body>
<div>This test verifies that valid word in contraction form has neither spelling error nor autocorrection underlines.</div>
<div contenteditable id="root" class="editing">
<span id="test"></span>
</div>
<script>
runEditingTest();
</script>
</body>
</html>
2010-11-19 Jia Pu <jpu@apple.com>
Reviewed by Dan Bernstein.
Regression: contraction is considered misspelling.
https://bugs.webkit.org/show_bug.cgi?id=49423
<rdar://problem/8654206>
Test: platform/mac/editing/spelling/autocorrection-contraction.html
manual-tests/autocorrection/autocorrection-contraction.html
* editing/Editor.cpp:
(WebCore::isAmbiguousBoundaryCharacter): Moved function to the top of the file so that it can
be used by all other functions in the file.
(WebCore::Editor::markMisspellingsAfterTypingToWord): Renamed markMisspellingsAfterTypingToPosition()
to improve readability, and to pass in additional argument. Before we apply pending
autocorrection, we check to see if currently typed character makes current word a partial
contraction, for instance "wouldn'". If that's the case, we would not apply the pending
correction.
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Make sure currently typed word
is not a partial contraction, such as "wouldn'", before mark it as misspelled. Also update
the location of ambiguous boundary if other replacements have changed the length of the
paragraph.
* editing/Editor.h:
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::markMisspellingsAfterTyping): Adopt renamed function.
* manual-tests/autocorrection/autocorrection-contraction.html: Added.
2010-11-19 Andreas Kling <kling@webkit.org>
 
Reviewed by Antonio Gomes.
......@@ -84,6 +84,14 @@ namespace WebCore {
using namespace std;
using namespace HTMLNames;
static inline bool isAmbiguousBoundaryCharacter(UChar character)
{
// These are characters that can behave as word boundaries, but can appear within words.
// If they are just typed, i.e. if they are immediately followed by a caret, we want to delay text checking until the next character has been typed.
// FIXME: this is required until 6853027 is fixed and text checking can do this for us.
return character == '\'' || character == rightSingleQuotationMark || character == hebrewPunctuationGershayim;
}
// When an event handler has moved the selection outside of a text control
// we should use the target control's selection for this editing operation.
VisibleSelection Editor::selectionForCommand(Event* event)
......@@ -2010,15 +2018,25 @@ void Editor::markMisspellingsAndBadGrammar(const VisibleSelection &movingSelecti
markBadGrammar(movingSelection);
}
void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition &p)
void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping)
{
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if SUPPORT_AUTOCORRECTION_PANEL
// Apply pending autocorrection before next round of spell checking.
applyCorrectionPanelInfo(true);
bool doApplyCorrection = true;
VisiblePosition startOfSelection = selectionAfterTyping.visibleStart();
VisibleSelection currentWord = VisibleSelection(startOfWord(startOfSelection, LeftWordIfOnBoundary), endOfWord(startOfSelection, RightWordIfOnBoundary));
if (currentWord.visibleEnd() == startOfSelection) {
String wordText = plainText(currentWord.toNormalizedRange().get());
if (wordText.length() > 0 && isAmbiguousBoundaryCharacter(wordText[wordText.length() - 1]))
doApplyCorrection = false;
}
if (doApplyCorrection)
applyCorrectionPanelInfo(true);
m_correctionPanelInfo.m_rangeToBeReplaced.clear();
#else
UNUSED_PARAM(selectionAfterTyping);
#endif
TextCheckingOptions textCheckingOptions = 0;
if (isContinuousSpellCheckingEnabled())
textCheckingOptions |= MarkSpelling;
......@@ -2036,20 +2054,21 @@ void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition &p)
if (isGrammarCheckingEnabled())
textCheckingOptions |= MarkGrammar;
VisibleSelection adjacentWords = VisibleSelection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary));
VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
if (textCheckingOptions & MarkGrammar) {
VisibleSelection selectedSentence = VisibleSelection(startOfSentence(p), endOfSentence(p));
VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart));
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get());
} else {
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get());
}
#else
UNUSED_PARAM(selectionAfterTyping);
if (!isContinuousSpellCheckingEnabled())
return;
// Check spelling of one word
RefPtr<Range> misspellingRange;
markMisspellings(VisibleSelection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary)), misspellingRange);
markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)), misspellingRange);
// Autocorrect the misspelled word.
if (!misspellingRange)
......@@ -2081,7 +2100,7 @@ void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition &p)
return;
// Check grammar of entire sentence
markBadGrammar(VisibleSelection(startOfSentence(p), endOfSentence(p)));
markBadGrammar(VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart)));
#endif
}
......@@ -2155,15 +2174,6 @@ void Editor::markBadGrammar(const VisibleSelection& selection)
}
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
static inline bool isAmbiguousBoundaryCharacter(UChar character)
{
// These are characters that can behave as word boundaries, but can appear within words.
// If they are just typed, i.e. if they are immediately followed by a caret, we want to delay text checking until the next character has been typed.
// FIXME: this is required until 6853027 is fixed and text checking can do this for us.
return character == '\'' || character == rightSingleQuotationMark || character == hebrewPunctuationGershayim;
}
void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCheckingOptions, Range* spellingRange, Range* grammarRange)
{
bool shouldMarkSpelling = textCheckingOptions & MarkSpelling;
......@@ -2249,7 +2259,14 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
const TextCheckingResult* result = &results[i];
int resultLocation = result->location + offsetDueToReplacement;
int resultLength = result->length;
if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && resultLocation >= spellingParagraph.checkingStart() && resultLocation + resultLength <= spellingRangeEndOffset) {
bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && resultLocation + resultLength == ambiguousBoundaryOffset;
// Only mark misspelling if:
// 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false.
// 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 && result->type == TextCheckingTypeSpelling && resultLocation >= spellingParagraph.checkingStart() && resultLocation + resultLength <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
ASSERT(resultLength > 0 && resultLocation >= 0);
RefPtr<Range> misspellingRange = spellingParagraph.subrange(resultLocation, resultLength);
misspellingRange->startContainer(ec)->document()->markers()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
......@@ -2276,14 +2293,14 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
continue;
int replacementLength = result->replacement.length();
bool doReplacement = (replacementLength > 0);
// Apply replacement if:
// 1. The replacement length is non-zero.
// 2. The result doesn't end at an ambiguous boundary.
// (FIXME: this is required until 6853027 is fixed and text checking can do this for us
bool doReplacement = replacementLength > 0 && !resultEndsAtAmbiguousBoundary;
RefPtr<Range> rangeToReplace = paragraph.subrange(resultLocation, resultLength);
VisibleSelection selectionToReplace(rangeToReplace.get(), DOWNSTREAM);
// avoid correcting text after an ambiguous boundary character has been typed
// FIXME: this is required until 6853027 is fixed and text checking can do this for us
if (ambiguousBoundaryOffset >= 0 && resultLocation + resultLength == ambiguousBoundaryOffset)
doReplacement = false;
// adding links should be done only immediately after they are typed
if (result->type == TextCheckingTypeLink && selectionOffset > resultLocation + resultLength + 1)
......@@ -2344,8 +2361,12 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
if (doReplacement) {
replaceSelectionWithText(result->replacement, false, false);
offsetDueToReplacement += replacementLength - resultLength;
if (resultLocation < selectionOffset)
if (resultLocation < selectionOffset) {
selectionOffset += replacementLength - resultLength;
if (ambiguousBoundaryOffset >= 0)
ambiguousBoundaryOffset = selectionOffset - 1;
}
if (result->type == TextCheckingTypeCorrection) {
// Add a marker so that corrections can easily be undone and won't be re-corrected.
RefPtr<Range> replacedRange = paragraph.subrange(resultLocation, replacementLength);
......
......@@ -210,7 +210,7 @@ public:
Vector<String> guessesForMisspelledOrUngrammaticalSelection(bool& misspelled, bool& ungrammatical);
bool isSpellCheckingEnabledInFocusedNode() const;
bool isSpellCheckingEnabledFor(Node*) const;
void markMisspellingsAfterTypingToPosition(const VisiblePosition&);
void markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping);
void markMisspellings(const VisibleSelection&, RefPtr<Range>& firstMisspellingRange);
void markBadGrammar(const VisibleSelection&);
void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
......
......@@ -310,7 +310,7 @@ void TypingCommand::markMisspellingsAfterTyping(ETypingCommand commandType)
VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary);
VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary);
if (p1 != p2)
document()->frame()->editor()->markMisspellingsAfterTypingToPosition(p1);
document()->frame()->editor()->markMisspellingsAfterTypingToWord(p1, endingSelection());
#if SUPPORT_AUTOCORRECTION_PANEL
else if (commandType == TypingCommand::InsertText)
document()->frame()->editor()->startCorrectionPanelTimer(CorrectionPanelInfo::PanelTypeCorrection);
......
<html>
<head>
<style>
.editing {
border: 2px solid red;
padding: 12px;
font-size: 24px;
}
</style>
<script src=../../../LayoutTests/editing/editing.js language="JavaScript" type="text/JavaScript" ></script>
<script>
function keepTyping() {
typeCharacterCommand('\'');
typeCharacterCommand('t');
typeCharacterCommand(' ');
}
function editingTest() {
typeCharacterCommand('t');
typeCharacterCommand('h');
typeCharacterCommand('i');
typeCharacterCommand('s');
typeCharacterCommand(' ');
typeCharacterCommand('w');
typeCharacterCommand('o');
typeCharacterCommand('u');
typeCharacterCommand('l');
typeCharacterCommand('d');
typeCharacterCommand('n');
setTimeout("keepTyping()", 1000);
}
</script>
<title>Delete to Dismiss Reversion Panel Test</title>
</head>
<body>
<div><p>This test verifies that, after typing an apostrophe, if the current word is part of a contraction, previously shown autocorrection will not be applied.</p>
<p>After loading the page, you should see correction panel shows "would" for "wouldn". Then after typing "'t", the correction panel dissappears and the final sentence is "this wouldn't".</p>
<div contenteditable id="root" class="editing">
<span id="test"></span>
</div>
<script>
runEditingTest();
</script>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment