Commit 102429ef authored by morrita@google.com's avatar morrita@google.com

2011-03-23 MORITA Hajime <morrita@google.com>

        Reviewed by Kent Tamura.

        Spellcheck feature specific symbols should be defined.
        https://bugs.webkit.org/show_bug.cgi?id=56818

        * Introduced USE(UNIFIED_TEXT_CHECKING), USE(GRAMMAR_CHECKING) and USE(AUTOMATIC_TEXT_REPLACEMENT)
        * Replaced a part of of BUILDING_ON_* conditionals with them.

        Note that small amount of code path on Editor.cpp is now compiled under USE(GRAMMAR_CHECKING)
        because these code path is already built under non-Mac ports and
        Keeping them buildable for such platforms reduces the build breakage risk.
        These path is guarded by Settings thus should never get reached.

        No new tests. No behavioral change.

        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * editing/Editor.cpp:
        (WebCore::Editor::advanceToNextMisspelling):
        (WebCore::Editor::isSelectionUngrammatical):
        (WebCore::Editor::guessesForUngrammaticalSelection):
        (WebCore::Editor::guessesForMisspelledOrUngrammaticalSelection):
        (WebCore::Editor::markMisspellingsAfterTypingToWord):
        (WebCore::Editor::markMisspellingsOrBadGrammar):
        (WebCore::Editor::markBadGrammar):
        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
        (WebCore::Editor::changeBackToReplacedString):
        (WebCore::Editor::markMisspellingsAndBadGrammar):
        * editing/Editor.h:
        * editing/TextCheckingHelper.cpp:
        (WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
        (WebCore::TextCheckingHelper::findFirstGrammarDetail):
        (WebCore::TextCheckingHelper::findFirstBadGrammar):
        (WebCore::TextCheckingHelper::isUngrammatical):
        (WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange):
        (WebCore::TextCheckingHelper::markAllBadGrammar):
        * loader/EmptyClients.h:
        * platform/text/TextCheckerClient.h:
        * platform/text/TextChecking.h: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@81855 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 07c080f6
2011-03-23 MORITA Hajime <morrita@google.com>
Reviewed by Kent Tamura.
Spellcheck feature specific symbols should be defined.
https://bugs.webkit.org/show_bug.cgi?id=56818
* Introduced USE(UNIFIED_TEXT_CHECKING), USE(GRAMMAR_CHECKING) and USE(AUTOMATIC_TEXT_REPLACEMENT)
* Replaced a part of of BUILDING_ON_* conditionals with them.
Note that small amount of code path on Editor.cpp is now compiled under USE(GRAMMAR_CHECKING)
because these code path is already built under non-Mac ports and
Keeping them buildable for such platforms reduces the build breakage risk.
These path is guarded by Settings thus should never get reached.
No new tests. No behavioral change.
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* editing/Editor.cpp:
(WebCore::Editor::advanceToNextMisspelling):
(WebCore::Editor::isSelectionUngrammatical):
(WebCore::Editor::guessesForUngrammaticalSelection):
(WebCore::Editor::guessesForMisspelledOrUngrammaticalSelection):
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::markMisspellingsOrBadGrammar):
(WebCore::Editor::markBadGrammar):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::changeBackToReplacedString):
(WebCore::Editor::markMisspellingsAndBadGrammar):
* editing/Editor.h:
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
(WebCore::TextCheckingHelper::findFirstGrammarDetail):
(WebCore::TextCheckingHelper::findFirstBadGrammar):
(WebCore::TextCheckingHelper::isUngrammatical):
(WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange):
(WebCore::TextCheckingHelper::markAllBadGrammar):
* loader/EmptyClients.h:
* platform/text/TextCheckerClient.h:
* platform/text/TextChecking.h: Added.
2011-03-23 Kent Tamura <tkent@chromium.org>
Reviewed by Dimitri Glazkov.
......@@ -910,6 +910,7 @@
'platform/text/TextBreakIterator.h',
'platform/text/TextBreakIteratorInternalICU.h',
'platform/text/TextCheckerClient.h',
'platform/text/TextChecking.h',
'platform/text/TextCodec.h',
'platform/text/TextCodecICU.h',
'platform/text/TextCodecLatin1.h',
......
......@@ -1947,6 +1947,7 @@ HEADERS += \
platform/Length.h \
platform/text/LineEnding.h \
platform/text/TextCheckerClient.h \
platform/text/TextChecking.h \
platform/LinkHash.h \
platform/Logging.h \
platform/Language.h \
......
......@@ -30564,6 +30564,10 @@
RelativePath="..\platform\text\TextCheckerClient.h"
>
</File>
<File
RelativePath="..\platform\text\TextChecking.h"
>
</File>
<File
RelativePath="..\platform\text\TextCodec.cpp"
>
......@@ -3205,6 +3205,7 @@
A77979280D6B9E64003851B9 /* JSImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77979240D6B9E64003851B9 /* JSImageData.cpp */; };
A77979290D6B9E64003851B9 /* JSImageData.h in Headers */ = {isa = PBXBuildFile; fileRef = A77979250D6B9E64003851B9 /* JSImageData.h */; };
A77B41A012E675A90054343D /* TextEventInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = A77B419F12E675A90054343D /* TextEventInputType.h */; settings = {ATTRIBUTES = (Private, ); }; };
A77D0012133B0AEB00D6658C /* TextChecking.h in Headers */ = {isa = PBXBuildFile; fileRef = A77D0011133B0AEB00D6658C /* TextChecking.h */; settings = {ATTRIBUTES = (Private, ); }; };
A784941B0B5FE507001E237A /* Clipboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A784941A0B5FE507001E237A /* Clipboard.cpp */; };
A78FE13B12366B1000ACE8D0 /* SpellChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A78FE13912366B1000ACE8D0 /* SpellChecker.cpp */; };
A78FE13C12366B1000ACE8D0 /* SpellChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = A78FE13A12366B1000ACE8D0 /* SpellChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -9695,6 +9696,7 @@
A77979240D6B9E64003851B9 /* JSImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSImageData.cpp; sourceTree = "<group>"; };
A77979250D6B9E64003851B9 /* JSImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSImageData.h; sourceTree = "<group>"; };
A77B419F12E675A90054343D /* TextEventInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEventInputType.h; sourceTree = "<group>"; };
A77D0011133B0AEB00D6658C /* TextChecking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextChecking.h; sourceTree = "<group>"; };
A784941A0B5FE507001E237A /* Clipboard.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Clipboard.cpp; sourceTree = "<group>"; };
A78FE13912366B1000ACE8D0 /* SpellChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpellChecker.cpp; sourceTree = "<group>"; };
A78FE13A12366B1000ACE8D0 /* SpellChecker.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = SpellChecker.h; sourceTree = "<group>"; };
......@@ -17758,6 +17760,7 @@
B2C3DA070D006C1D00EF6F26 /* TextBreakIteratorICU.cpp */,
B2C3DA080D006C1D00EF6F26 /* TextBreakIteratorInternalICU.h */,
A7151BD712F1558F005A0F64 /* TextCheckerClient.h */,
A77D0011133B0AEB00D6658C /* TextChecking.h */,
B2C3DA090D006C1D00EF6F26 /* TextCodec.cpp */,
B2C3DA0A0D006C1D00EF6F26 /* TextCodec.h */,
26E98A0F130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h */,
......@@ -22438,6 +22441,7 @@
B2C3DA380D006C1D00EF6F26 /* TextBreakIteratorInternalICU.h in Headers */,
A7151BD812F1558F005A0F64 /* TextCheckerClient.h in Headers */,
A7DBF8DE1276919C006B6008 /* TextCheckingHelper.h in Headers */,
A77D0012133B0AEB00D6658C /* TextChecking.h in Headers */,
B2C3DA3A0D006C1D00EF6F26 /* TextCodec.h in Headers */,
26E98A10130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h in Headers */,
B2C3DA3C0D006C1D00EF6F26 /* TextCodecICU.h in Headers */,
......@@ -1371,7 +1371,7 @@ int Editor::spellCheckerDocumentTag()
return client() ? client()->spellCheckerDocumentTag() : 0;
}
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(AUTOMATIC_TEXT_REPLACEMENT)
void Editor::uppercaseWord()
{
......@@ -1823,14 +1823,16 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
int searchEndOffsetAfterWrap = spellingSearchRange->endOffset(ec);
int misspellingOffset = 0;
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
RefPtr<Range> grammarSearchRange = spellingSearchRange->cloneRange(ec);
String misspelledWord;
String badGrammarPhrase;
GrammarDetail grammarDetail;
int grammarPhraseOffset = 0;
RefPtr<Range> grammarSearchRange;
String badGrammarPhrase;
String misspelledWord;
#if USE(UNIFIED_TEXT_CHECKING)
grammarSearchRange = spellingSearchRange->cloneRange(ec);
bool isSpelling = true;
int foundOffset = 0;
GrammarDetail grammarDetail;
String foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
if (isSpelling) {
misspelledWord = foundItem;
......@@ -1841,15 +1843,11 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
}
#else
RefPtr<Range> firstMisspellingRange;
String misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
String badGrammarPhrase;
#ifndef BUILDING_ON_TIGER
int grammarPhraseOffset = 0;
GrammarDetail grammarDetail;
misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
#if USE(GRAMMAR_CHECKING)
// Search for bad grammar that occurs prior to the next misspelled word (if any)
RefPtr<Range> grammarSearchRange = spellingSearchRange->cloneRange(ec);
grammarSearchRange = spellingSearchRange->cloneRange(ec);
if (!misspelledWord.isEmpty()) {
// Stop looking at start of next misspelled word
CharacterIterator chars(grammarSearchRange.get());
......@@ -1869,7 +1867,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
// going until the end of the very first chunk we tested is far enough
spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, ec);
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
grammarSearchRange = spellingSearchRange->cloneRange(ec);
foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
if (isSpelling) {
......@@ -1882,7 +1880,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
#else
misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
#ifndef BUILDING_ON_TIGER
#if USE(GRAMMAR_CHECKING)
grammarSearchRange = spellingSearchRange->cloneRange(ec);
if (!misspelledWord.isEmpty()) {
// Stop looking at start of next misspelled word
......@@ -1898,9 +1896,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
}
if (!badGrammarPhrase.isEmpty()) {
#ifdef BUILDING_ON_TIGER
ASSERT_NOT_REACHED();
#else
ASSERT(WTF_USE_GRAMMAR_CHECKING);
// We found bad grammar. Since we only searched for bad grammar up to the first misspelled word, the bad grammar
// takes precedence and we ignore any potential misspelled word. Select the grammar detail, update the spelling
// panel, and store a marker so we draw the green squiggle later.
......@@ -1915,7 +1911,6 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
client()->updateSpellingUIWithGrammarString(badGrammarPhrase, grammarDetail);
frame()->document()->markers()->addMarker(badGrammarRange.get(), DocumentMarker::Grammar, grammarDetail.userDescription);
#endif
} else if (!misspelledWord.isEmpty()) {
// We found a misspelling, but not any earlier bad grammar. Select the misspelling, update the spelling panel, and store
// a marker so we draw the red squiggle later.
......@@ -1958,23 +1953,23 @@ bool Editor::isSelectionMisspelled()
bool Editor::isSelectionUngrammatical()
{
#ifdef BUILDING_ON_TIGER
return false;
#else
#if USE(GRAMMAR_CHECKING)
Vector<String> ignoredGuesses;
return TextCheckingHelper(client(), frame()->selection()->toNormalizedRange()).isUngrammatical(ignoredGuesses);
#else
return false;
#endif
}
Vector<String> Editor::guessesForUngrammaticalSelection()
{
#ifdef BUILDING_ON_TIGER
return Vector<String>();
#else
#if USE(GRAMMAR_CHECKING)
Vector<String> guesses;
// Ignore the result of isUngrammatical; we just want the guesses, whether or not there are any
TextCheckingHelper(client(), frame()->selection()->toNormalizedRange()).isUngrammatical(guesses);
return guesses;
#else
return Vector<String>();
#endif
}
......@@ -1991,7 +1986,7 @@ Vector<String> Editor::guessesForMisspelledSelection()
Vector<String> Editor::guessesForMisspelledOrUngrammaticalSelection(bool& misspelled, bool& ungrammatical)
{
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
return TextCheckingHelper(client(), frame()->selection()->toNormalizedRange()).guessesForMisspelledOrUngrammaticalRange(isGrammarCheckingEnabled(), misspelled, ungrammatical);
#else
misspelled = isSelectionMisspelled();
......@@ -2060,7 +2055,7 @@ void Editor::markMisspellingsAndBadGrammar(const VisibleSelection &movingSelecti
void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping)
{
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
#if SUPPORT_AUTOCORRECTION_PANEL
// Apply pending autocorrection before next round of spell checking.
bool doApplyCorrection = true;
......@@ -2082,12 +2077,14 @@ void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart,
if (isContinuousSpellCheckingEnabled())
textCheckingOptions |= MarkSpelling;
#if USE(AUTOMATIC_TEXT_REPLACEMENT)
if (isAutomaticQuoteSubstitutionEnabled()
|| isAutomaticLinkDetectionEnabled()
|| isAutomaticDashSubstitutionEnabled()
|| isAutomaticTextReplacementEnabled()
|| ((textCheckingOptions & MarkSpelling) && isAutomaticSpellingCorrectionEnabled()))
textCheckingOptions |= PerformReplacement;
#endif
if (!textCheckingOptions & (MarkSpelling | PerformReplacement))
return;
......@@ -2176,12 +2173,9 @@ void Editor::markMisspellingsOrBadGrammar(const VisibleSelection& selection, boo
if (checkSpelling)
checker.markAllMisspellings(firstMisspellingRange);
else {
#ifdef BUILDING_ON_TIGER
ASSERT_NOT_REACHED();
#else
ASSERT(WTF_USE_GRAMMAR_CHECKING);
if (isGrammarCheckingEnabled())
checker.markAllBadGrammar();
#endif
}
}
......@@ -2207,17 +2201,14 @@ void Editor::markMisspellings(const VisibleSelection& selection, RefPtr<Range>&
void Editor::markBadGrammar(const VisibleSelection& selection)
{
#ifndef BUILDING_ON_TIGER
ASSERT(WTF_USE_GRAMMAR_CHECKING);
RefPtr<Range> firstMisspellingRange;
markMisspellingsOrBadGrammar(selection, false, firstMisspellingRange);
#else
UNUSED_PARAM(selection);
#endif
}
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCheckingOptions, Range* spellingRange, Range* grammarRange)
{
#if USE(UNIFIED_TEXT_CHECKING)
// There shouldn't be pending autocorrection at this moment.
ASSERT(!m_correctionPanelInfo.rangeToBeReplaced);
......@@ -2278,6 +2269,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
if (shouldShowCorrectionPanel)
checkingTypes |= TextCheckingTypeCorrection;
if (shouldPerformReplacement) {
#if USE(AUTOMATIC_TEXT_REPLACEMENT)
if (isAutomaticLinkDetectionEnabled())
checkingTypes |= TextCheckingTypeLink;
if (isAutomaticQuoteSubstitutionEnabled())
......@@ -2288,6 +2280,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
checkingTypes |= TextCheckingTypeReplacement;
if (shouldMarkSpelling && isAutomaticSpellingCorrectionEnabled())
checkingTypes |= TextCheckingTypeCorrection;
#endif
}
textChecker()->checkTextOfParagraph(paragraph.textCharacters(), paragraph.textLength(), checkingTypes, results);
......@@ -2456,10 +2449,17 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
m_frame->selection()->modify(SelectionController::AlterationMove, DirectionForward, CharacterGranularity);
}
}
#else
ASSERT_NOT_REACHED();
UNUSED_PARAM(textCheckingOptions);
UNUSED_PARAM(spellingRange);
UNUSED_PARAM(grammarRange);
#endif // USE(UNIFIED_TEXT_CHECKING)
}
void Editor::changeBackToReplacedString(const String& replacedString)
{
#if USE(UNIFIED_TEXT_CHECKING)
if (replacedString.isEmpty())
return;
......@@ -2478,13 +2478,16 @@ void Editor::changeBackToReplacedString(const String& replacedString)
#if SUPPORT_AUTOCORRECTION_PANEL
changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::SpellCheckingExemption);
#endif
#else
ASSERT_NOT_REACHED();
UNUSED_PARAM(replacedString);
#endif // USE(UNIFIED_TEXT_CHECKING)
}
#endif
void Editor::markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection)
{
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
if (!isContinuousSpellCheckingEnabled())
return;
TextCheckingOptions textCheckingOptions = MarkSpelling;
......
......@@ -36,6 +36,7 @@
#include "EditorInsertAction.h"
#include "FindOptions.h"
#include "SelectionController.h"
#include "TextChecking.h"
#include "Timer.h"
#include "VisibleSelection.h"
#include "WritingDirection.h"
......@@ -222,7 +223,7 @@ public:
void markMisspellings(const VisibleSelection&, RefPtr<Range>& firstMisspellingRange);
void markBadGrammar(const VisibleSelection&);
void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(AUTOMATIC_TEXT_REPLACEMENT)
void uppercaseWord();
void lowercaseWord();
void capitalizeWord();
......@@ -239,6 +240,8 @@ public:
void toggleAutomaticTextReplacement();
bool isAutomaticSpellingCorrectionEnabled();
void toggleAutomaticSpellingCorrection();
#endif
enum TextCheckingOptionFlags {
MarkSpelling = 1 << 0,
MarkGrammar = 1 << 1,
......@@ -249,7 +252,7 @@ public:
void markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions, Range* spellingRange, Range* grammarRange);
void changeBackToReplacedString(const String& replacedString);
#endif
void advanceToNextMisspelling(bool startBeforeSelection = false);
void showSpellingGuessPanel();
bool spellingPanelIsShowing();
......
......@@ -224,7 +224,7 @@ String TextCheckingHelper::findFirstMisspelling(int& firstMisspellingOffset, boo
String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, bool& outIsSpelling, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail)
{
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
String firstFoundItem;
String misspelledWord;
String badGrammarPhrase;
......@@ -350,12 +350,12 @@ String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, b
UNUSED_PARAM(outFirstFoundOffset);
UNUSED_PARAM(outGrammarDetail);
return "";
#endif
#endif // USE(UNIFIED_TEXT_CHECKING)
}
int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int /*badGrammarPhraseLength*/, int startOffset, int endOffset, bool markAll)
{
#ifndef BUILDING_ON_TIGER
#if USE(GRAMMAR_CHECKING)
// Found some bad grammar. Find the earliest detail range that starts in our search range (if any).
// Optionally add a DocumentMarker for each detail in the range.
int earliestDetailLocationSoFar = -1;
......@@ -402,7 +402,7 @@ int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& gram
String TextCheckingHelper::findFirstBadGrammar(GrammarDetail& outGrammarDetail, int& outGrammarPhraseOffset, bool markAll)
{
#ifndef BUILDING_ON_TIGER
ASSERT(WTF_USE_GRAMMAR_CHECKING);
// Initialize out parameters; these will be updated if we find something to return.
outGrammarDetail.location = -1;
outGrammarDetail.length = 0;
......@@ -458,18 +458,12 @@ String TextCheckingHelper::findFirstBadGrammar(GrammarDetail& outGrammarDetail,
}
return firstBadGrammarPhrase;
#else
ASSERT_NOT_REACHED();
UNUSED_PARAM(outGrammarDetail);
UNUSED_PARAM(outGrammarPhraseOffset);
UNUSED_PARAM(markAll);
#endif
}
bool TextCheckingHelper::isUngrammatical(Vector<String>& guessesVector) const
{
#ifndef BUILDING_ON_TIGER
ASSERT(WTF_USE_GRAMMAR_CHECKING);
if (!m_client)
return false;
......@@ -511,16 +505,11 @@ bool TextCheckingHelper::isUngrammatical(Vector<String>& guessesVector) const
m_client->updateSpellingUIWithGrammarString(badGrammarPhrase, grammarDetail);
return true;
#else
ASSERT_NOT_REACHED();
UNUSED_PARAM(guessesVector);
return true;
#endif
}
Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool checkGrammar, bool& misspelled, bool& ungrammatical) const
{
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
Vector<String> guesses;
ExceptionCode ec;
misspelled = false;
......@@ -578,7 +567,7 @@ Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool
UNUSED_PARAM(misspelled);
UNUSED_PARAM(ungrammatical);
return Vector<String>();
#endif
#endif // USE(UNIFIED_TEXT_CHECKING)
}
......@@ -592,15 +581,12 @@ void TextCheckingHelper::markAllMisspellings(RefPtr<Range>& firstMisspellingRang
void TextCheckingHelper::markAllBadGrammar()
{
#ifndef BUILDING_ON_TIGER
// Use the "markAll" feature of findFirstBadGrammar. Ignore the return value and "out parameters"; all we need to
ASSERT(WTF_USE_GRAMMAR_CHECKING);
// Use the "markAll" feature of ofindFirstBadGrammar. Ignore the return value and "out parameters"; all we need to
// do is mark every instance.
GrammarDetail ignoredGrammarDetail;
int ignoredOffset;
findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true);
#else
ASSERT_NOT_REACHED();
#endif
}
}
......@@ -406,7 +406,7 @@ public:
virtual String getAutoCorrectSuggestionForMisspelledWord(const String&) { return String(); }
virtual void checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*) { }
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
virtual void checkTextOfParagraph(const UChar*, int, uint64_t, Vector<TextCheckingResult>&) { };
#endif
......
......@@ -28,6 +28,8 @@
#ifndef TextCheckerClient_h
#define TextCheckerClient_h
#include "TextChecking.h"
#include <wtf/Forward.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
......@@ -70,7 +72,7 @@ public:
virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength) = 0;
virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) = 0;
virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) = 0;
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#if USE(UNIFIED_TEXT_CHECKING)
virtual void checkTextOfParagraph(const UChar* text, int length, uint64_t checkingTypes, Vector<TextCheckingResult>& results) = 0;
#endif
......
/*
* Copyright (c) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TextChecking_h
#define TextChecking_h
namespace WebCore {
#if !defined(BUILDING_ON_TIGER)
#define WTF_USE_GRAMMAR_CHECKING 1
#endif
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
#define WTF_USE_UNIFIED_TEXT_CHECKING 1
#define WTF_USE_AUTOMATIC_TEXT_REPLACEMENT 1
#endif
}
#endif // TextChecking_h
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