Title: [97696] trunk/Source/WebCore
Revision
97696
Author
[email protected]
Date
2011-10-17 18:38:49 -0700 (Mon, 17 Oct 2011)

Log Message

Unified spell-checking and legacy spell checking should be easy to switch
https://bugs.webkit.org/show_bug.cgi?id=69242

Patch by Shinya Kawanaka <[email protected]> on 2011-10-17
Reviewed by Hajime Morita.

WebCore has two different code paths for spell-checking:
          1) checkTextOfParagraph() for Snow Leopard or later
          2) checkSpellingOfString() for checkGrammarOfString() for other platforms.

This patch introduces a flag to change code paths dynamically.
This patch also includes build fix for QT, GTK, and Windows platforms.

No new tests because this patch does not change a behavior.

* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::hasMisspelling):
  Changed static if-USE(UNIFIED_TEXT_CHECKING) statement to dynamic
  condition branch to achieve easy code path change.
* accessibility/mac/WebAccessibilityObjectWrapper.mm: ditto.
(AXAttributeStringSetSpelling):
* editing/EditingAllInOne.cpp:
* editing/Editor.cpp:
(WebCore::Editor::advanceToNextMisspelling): ditto.
(WebCore::Editor::guessesForMisspelledOrUngrammaticalSelection): ditto.
(WebCore::Editor::markMisspellingsAfterTypingToWord): ditto.
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): ditto.
(WebCore::Editor::changeBackToReplacedString): ditto.
(WebCore::Editor::markMisspellingsAndBadGrammar): ditto.
(WebCore::Editor::unifiedTextCheckerEnabled):
  Utility method to check using unified text checking or not.
* editing/Editor.h:
* editing/TextCheckingHelper.cpp:
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
  Same as WebCore::AccessibilityObject::hasMisspelling.
(WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange): ditto.
(WebCore::TextCheckingHelper::unifiedTextCheckerEnabled):
  Utility method to check using unified text checking or not.
(WebCore::unifiedTextCheckerEnabled): ditto.
* editing/TextCheckingHelper.h:
* page/Settings.cpp:
(WebCore::Settings::Settings):
  Includes a flag to change the code path.
* page/Settings.h:
(WebCore::Settings::setUnifiedTextCheckerEnabled):
  Sets a flag to change the code path.
(WebCore::Settings::unifiedTextCheckerEnabled):
  A flag to change the code path.

Modified Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (97695 => 97696)


--- trunk/Source/WebCore/CMakeLists.txt	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/CMakeLists.txt	2011-10-18 01:38:49 UTC (rev 97696)
@@ -651,9 +651,11 @@
     editing/ReplaceNodeWithSpanCommand.cpp
     editing/ReplaceSelectionCommand.cpp
     editing/SetNodeAttributeCommand.cpp
+    editing/SetSelectionCommand.cpp
     editing/SmartReplace.cpp
     editing/SpellChecker.cpp
     editing/SpellingCorrectionController.cpp
+    editing/SpellingCorrectionCommand.cpp
     editing/SplitElementCommand.cpp
     editing/SplitTextNodeCommand.cpp
     editing/SplitTextNodeContainingElementCommand.cpp

Modified: trunk/Source/WebCore/ChangeLog (97695 => 97696)


--- trunk/Source/WebCore/ChangeLog	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/ChangeLog	2011-10-18 01:38:49 UTC (rev 97696)
@@ -1,3 +1,57 @@
+2011-10-17  Shinya Kawanaka  <[email protected]>
+
+        Unified spell-checking and legacy spell checking should be easy to switch
+        https://bugs.webkit.org/show_bug.cgi?id=69242
+
+        Reviewed by Hajime Morita.
+
+        WebCore has two different code paths for spell-checking:
+                  1) checkTextOfParagraph() for Snow Leopard or later
+                  2) checkSpellingOfString() for checkGrammarOfString() for other platforms.
+
+        This patch introduces a flag to change code paths dynamically.
+        This patch also includes build fix for QT, GTK, and Windows platforms.
+
+        No new tests because this patch does not change a behavior.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::hasMisspelling):
+          Changed static if-USE(UNIFIED_TEXT_CHECKING) statement to dynamic
+          condition branch to achieve easy code path change.
+        * accessibility/mac/WebAccessibilityObjectWrapper.mm: ditto.
+        (AXAttributeStringSetSpelling):
+        * editing/EditingAllInOne.cpp:
+        * editing/Editor.cpp:
+        (WebCore::Editor::advanceToNextMisspelling): ditto.
+        (WebCore::Editor::guessesForMisspelledOrUngrammaticalSelection): ditto.
+        (WebCore::Editor::markMisspellingsAfterTypingToWord): ditto.
+        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): ditto.
+        (WebCore::Editor::changeBackToReplacedString): ditto.
+        (WebCore::Editor::markMisspellingsAndBadGrammar): ditto.
+        (WebCore::Editor::unifiedTextCheckerEnabled):
+          Utility method to check using unified text checking or not.
+        * editing/Editor.h:
+        * editing/TextCheckingHelper.cpp:
+        (WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
+          Same as WebCore::AccessibilityObject::hasMisspelling.
+        (WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange): ditto.
+        (WebCore::TextCheckingHelper::unifiedTextCheckerEnabled):
+          Utility method to check using unified text checking or not.
+        (WebCore::unifiedTextCheckerEnabled): ditto.
+        * editing/TextCheckingHelper.h:
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings):
+          Includes a flag to change the code path.
+        * page/Settings.h:
+        (WebCore::Settings::setUnifiedTextCheckerEnabled):
+          Sets a flag to change the code path.
+        (WebCore::Settings::unifiedTextCheckerEnabled):
+          A flag to change the code path.
+
 2011-10-17  Julien Chaffraix  <[email protected]>
 
         Unreviewed build fix after 97691.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (97695 => 97696)


--- trunk/Source/WebCore/GNUmakefile.list.am	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2011-10-18 01:38:49 UTC (rev 97696)
@@ -1437,6 +1437,8 @@
 	Source/WebCore/editing/ReplaceSelectionCommand.h \
 	Source/WebCore/editing/SetNodeAttributeCommand.cpp \
 	Source/WebCore/editing/SetNodeAttributeCommand.h \
+	Source/WebCore/editing/SetSelectionCommand.cpp \
+	Source/WebCore/editing/SetSelectionCommand.h \
 	Source/WebCore/editing/SmartReplace.cpp \
 	Source/WebCore/editing/SmartReplace.h \
 	Source/WebCore/editing/SmartReplaceICU.cpp \
@@ -1444,6 +1446,7 @@
 	Source/WebCore/editing/SpellChecker.h \
 	Source/WebCore/editing/SpellingCorrectionController.cpp \
 	Source/WebCore/editing/SpellingCorrectionController.h \
+	Source/WebCore/editing/SpellingCorrectionCommand.cpp \
 	Source/WebCore/editing/SpellingCorrectionCommand.h \
 	Source/WebCore/editing/SplitElementCommand.cpp \
 	Source/WebCore/editing/SplitElementCommand.h \

Modified: trunk/Source/WebCore/WebCore.pro (97695 => 97696)


--- trunk/Source/WebCore/WebCore.pro	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/WebCore.pro	2011-10-18 01:38:49 UTC (rev 97696)
@@ -615,8 +615,10 @@
     editing/ReplaceNodeWithSpanCommand.cpp \
     editing/ReplaceSelectionCommand.cpp \
     editing/SetNodeAttributeCommand.cpp \
+    editing/SetSelectionCommand.cpp \
     editing/SmartReplaceICU.cpp \
     editing/SpellChecker.cpp \
+    editing/SpellingCorrectionCommand.cpp \
     editing/SpellingCorrectionController.cpp \
     editing/SplitElementCommand.cpp \
     editing/SplitTextNodeCommand.cpp \
@@ -1646,6 +1648,7 @@
     editing/ReplaceSelectionCommand.h \
     editing/SetNodeAttributeCommand.h \
     editing/SmartReplace.h \
+    editing/SpellingCorrectionCommand.h \
     editing/SpellingCorrectionController.h \
     editing/SplitElementCommand.h \
     editing/SplitTextNodeCommand.h \

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (97695 => 97696)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-10-18 01:38:49 UTC (rev 97696)
@@ -52616,6 +52616,62 @@
 					/>
 				</FileConfiguration>
 			</File>
+            <File
+                 RelativePath="..\editing\SetSelectionCommand.cpp"
+                 >
+                <FileConfiguration
+                      Name="Debug|Win32"
+                      ExcludedFromBuild="true"
+                     >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Release|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Debug_Cairo_CFLite|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Release_Cairo_CFLite|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Debug_All|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Production|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                </File>
+            <File
+                  RelativePath="..\editing\SetSelectionCommand.h"
+                  >
+                </File>
 			<File
 				RelativePath="..\editing\SmartReplace.h"
 				>
@@ -52728,6 +52784,62 @@
 				RelativePath="..\editing\SpellChecker.h"
 				>
 			</File>
+            <File
+                 RelativePath="..\editing\SpellingCorrectionCommand.cpp"
+                 >
+                <FileConfiguration
+                      Name="Debug|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Release|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Debug_Cairo_CFLite|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Release_Cairo_CFLite|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Debug_All|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                <FileConfiguration
+                      Name="Release_LTCG|Win32"
+                      ExcludedFromBuild="true"
+                      >
+                    <Tool
+                          Name="VCCLCompilerTool"
+                          />
+                    </FileConfiguration>
+                </File>
+            <File
+                  RelativePath="..\editing\SpellingCorrectionCommand.h"
+                  >
+            </File>
 			<File
 				RelativePath="..\editing\SpellingCorrectionController.cpp"
 				>

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (97695 => 97696)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2011-10-18 01:38:49 UTC (rev 97696)
@@ -50,6 +50,7 @@
 #include "RenderView.h"
 #include "RenderWidget.h"
 #include "RenderedPosition.h"
+#include "Settings.h"
 #include "TextCheckerClient.h"
 #include "TextCheckingHelper.h"
 #include "TextIterator.h"
@@ -289,19 +290,20 @@
     const UChar* chars = stringValue().characters();
     int charsLength = stringValue().length();
     bool isMisspelled = false;
-    
-#if USE(UNIFIED_TEXT_CHECKING)
-    Vector<TextCheckingResult> results;
-    checkTextOfParagraph(textChecker, chars, charsLength, TextCheckingTypeSpelling, results);
-    if (!results.isEmpty())
-        isMisspelled = true;
-#else
+
+    if (unifiedTextCheckerEnabled(frame)) {
+        Vector<TextCheckingResult> results;
+        checkTextOfParagraph(textChecker, chars, charsLength, TextCheckingTypeSpelling, results);
+        if (!results.isEmpty())
+            isMisspelled = true;
+        return isMisspelled;
+    }
+
     int misspellingLength = 0;
     int misspellingLocation = -1;
     textChecker->checkSpellingOfString(chars, charsLength, &misspellingLocation, &misspellingLength);
     if (misspellingLength || misspellingLocation != -1)
         isMisspelled = true;
-#endif
     
     return isMisspelled;
 }

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm (97695 => 97696)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm	2011-10-18 01:38:49 UTC (rev 97696)
@@ -690,21 +690,23 @@
 
 static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString, Node* node, const UChar* chars, int charLength, NSRange range)
 {
-#if USE(UNIFIED_TEXT_CHECKING)
-    // Check the spelling directly since document->markersForNode() does not store the misspelled marking when the cursor is in a word.
-    TextCheckerClient* checker = node->document()->frame()->editor()->textChecker();
+    if (unifiedTextCheckerEnabled(node->document()->frame())) {
+        // Check the spelling directly since document->markersForNode() does not store the misspelled marking when the cursor is in a word.
+        TextCheckerClient* checker = node->document()->frame()->editor()->textChecker();
 
-    // checkTextOfParagraph is the only spelling/grammar checker implemented in WK1 and WK2
-    Vector<TextCheckingResult> results;
-    checkTextOfParagraph(checker, chars, charLength, TextCheckingTypeSpelling, results);
-    
-    size_t size = results.size();
-    NSNumber* trueValue = [NSNumber numberWithBool:YES];
-    for (unsigned i = 0; i < size; i++) {
-        const TextCheckingResult& result = results[i];
-        AXAttributeStringSetNumber(attrString, NSAccessibilityMisspelledTextAttribute, trueValue, NSMakeRange(result.location + range.location, result.length));
-    }    
-#else
+        // checkTextOfParagraph is the only spelling/grammar checker implemented in WK1 and WK2
+        Vector<TextCheckingResult> results;
+        checkTextOfParagraph(checker, chars, charLength, TextCheckingTypeSpelling, results);
+
+        size_t size = results.size();
+        NSNumber* trueValue = [NSNumber numberWithBool:YES];
+        for (unsigned i = 0; i < size; i++) {
+            const TextCheckingResult& result = results[i];
+            AXAttributeStringSetNumber(attrString, NSAccessibilityMisspelledTextAttribute, trueValue, NSMakeRange(result.location + range.location, result.length));
+        }
+        return;
+    }
+
     int currentPosition = 0;
     while (charLength > 0) {
         const UChar* charData = chars + currentPosition;
@@ -721,7 +723,6 @@
         charLength -= (misspellingLocation + misspellingLength);
         currentPosition += (misspellingLocation + misspellingLength);
     }
-#endif    
 }
 
 static void AXAttributeStringSetHeadingLevel(NSMutableAttributedString* attrString, RenderObject* renderer, NSRange range)

Modified: trunk/Source/WebCore/editing/EditingAllInOne.cpp (97695 => 97696)


--- trunk/Source/WebCore/editing/EditingAllInOne.cpp	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/editing/EditingAllInOne.cpp	2011-10-18 01:38:49 UTC (rev 97696)
@@ -61,8 +61,10 @@
 #include <ReplaceNodeWithSpanCommand.cpp>
 #include <ReplaceSelectionCommand.cpp>
 #include <SetNodeAttributeCommand.cpp>
+#include <SetSelectionCommand.cpp>
 #include <SmartReplace.cpp>
 #include <SmartReplaceCF.cpp>
+#include <SpellingCorrectionCommand.cpp>
 #include <SpellingCorrectionController.cpp>
 #include <SpellChecker.cpp>
 #include <SplitElementCommand.cpp>

Modified: trunk/Source/WebCore/editing/Editor.cpp (97695 => 97696)


--- trunk/Source/WebCore/editing/Editor.cpp	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/editing/Editor.cpp	2011-10-18 01:38:49 UTC (rev 97696)
@@ -1628,45 +1628,11 @@
     String badGrammarPhrase;
     String misspelledWord;
 
-#if USE(UNIFIED_TEXT_CHECKING)
-    grammarSearchRange = spellingSearchRange->cloneRange(ec);
     bool isSpelling = true;
     int foundOffset = 0;
-    String foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
-    if (isSpelling) {
-        misspelledWord = foundItem;
-        misspellingOffset = foundOffset;
-    } else {
-        badGrammarPhrase = foundItem;
-        grammarPhraseOffset = foundOffset;
-    }
-#else
+    String foundItem;
     RefPtr<Range> firstMisspellingRange;
-    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)
-    grammarSearchRange = spellingSearchRange->cloneRange(ec);
-    if (!misspelledWord.isEmpty()) {
-        // Stop looking at start of next misspelled word
-        CharacterIterator chars(grammarSearchRange.get());
-        chars.advance(misspellingOffset);
-        grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
-    }
-    
-    if (isGrammarCheckingEnabled())
-        badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
-#endif
-#endif
-    
-    // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the
-    // block rather than at a selection).
-    if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
-        spellingSearchRange->setStart(topNode, 0, ec);
-        // going until the end of the very first chunk we tested is far enough
-        spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, ec);
-        
-#if USE(UNIFIED_TEXT_CHECKING)
+    if (unifiedTextCheckerEnabled()) {
         grammarSearchRange = spellingSearchRange->cloneRange(ec);
         foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
         if (isSpelling) {
@@ -1676,7 +1642,7 @@
             badGrammarPhrase = foundItem;
             grammarPhraseOffset = foundOffset;
         }
-#else
+    } else {
         misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
 
 #if USE(GRAMMAR_CHECKING)
@@ -1687,11 +1653,45 @@
             chars.advance(misspellingOffset);
             grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
         }
-
+    
         if (isGrammarCheckingEnabled())
             badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
 #endif
+    }
+    
+    // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the
+    // block rather than at a selection).
+    if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
+        spellingSearchRange->setStart(topNode, 0, ec);
+        // going until the end of the very first chunk we tested is far enough
+        spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, ec);
+        
+        if (unifiedTextCheckerEnabled()) {
+            grammarSearchRange = spellingSearchRange->cloneRange(ec);
+            foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
+            if (isSpelling) {
+                misspelledWord = foundItem;
+                misspellingOffset = foundOffset;
+            } else {
+                badGrammarPhrase = foundItem;
+                grammarPhraseOffset = foundOffset;
+            }
+        } else {
+            misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
+
+#if USE(GRAMMAR_CHECKING)
+            grammarSearchRange = spellingSearchRange->cloneRange(ec);
+            if (!misspelledWord.isEmpty()) {
+                // Stop looking at start of next misspelled word
+                CharacterIterator chars(grammarSearchRange.get());
+                chars.advance(misspellingOffset);
+                grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
+            }
+
+            if (isGrammarCheckingEnabled())
+                badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
 #endif
+        }
     }
     
     if (!badGrammarPhrase.isEmpty()) {
@@ -1791,12 +1791,13 @@
 
 Vector<String> Editor::guessesForMisspelledOrUngrammaticalSelection(bool& misspelled, bool& ungrammatical)
 {
-#if USE(UNIFIED_TEXT_CHECKING)
-    RefPtr<Range> range = frame()->selection()->toNormalizedRange();
-    if (!range)
-        return Vector<String>();
-    return TextCheckingHelper(client(), range).guessesForMisspelledOrUngrammaticalRange(isGrammarCheckingEnabled(), misspelled, ungrammatical);
-#else
+    if (unifiedTextCheckerEnabled()) {
+        RefPtr<Range> range = frame()->selection()->toNormalizedRange();
+        if (!range)
+            return Vector<String>();
+        return TextCheckingHelper(client(), range).guessesForMisspelledOrUngrammaticalRange(isGrammarCheckingEnabled(), misspelled, ungrammatical);
+    }
+
     misspelled = isSelectionMisspelled();
     if (misspelled) {
         ungrammatical = false;
@@ -1808,7 +1809,6 @@
     }
     ungrammatical = false;
     return Vector<String>();
-#endif
 }
 
 void Editor::showSpellingGuessPanel()
@@ -1850,41 +1850,38 @@
 
 void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping, bool doReplacement)
 {
-#if USE(UNIFIED_TEXT_CHECKING)
-    m_spellingCorrector->applyPendingCorrection(selectionAfterTyping);
+    if (unifiedTextCheckerEnabled()) {
+        m_spellingCorrector->applyPendingCorrection(selectionAfterTyping);
 
-    TextCheckingTypeMask textCheckingOptions = 0;
+        TextCheckingTypeMask textCheckingOptions = 0;
 
-    if (isContinuousSpellCheckingEnabled())
-        textCheckingOptions |= TextCheckingTypeSpelling;
+        if (isContinuousSpellCheckingEnabled())
+            textCheckingOptions |= TextCheckingTypeSpelling;
 
 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
-    if (doReplacement 
-        && (isAutomaticQuoteSubstitutionEnabled()
-            || isAutomaticLinkDetectionEnabled()
-            || isAutomaticDashSubstitutionEnabled()
-            || isAutomaticTextReplacementEnabled()
-            || ((textCheckingOptions & TextCheckingTypeSpelling) && isAutomaticSpellingCorrectionEnabled())))
-        textCheckingOptions |= TextCheckingTypeReplacement;
+        if (doReplacement
+            && (isAutomaticQuoteSubstitutionEnabled()
+                || isAutomaticLinkDetectionEnabled()
+                || isAutomaticDashSubstitutionEnabled()
+                || isAutomaticTextReplacementEnabled()
+                || ((textCheckingOptions & TextCheckingTypeSpelling) && isAutomaticSpellingCorrectionEnabled())))
+            textCheckingOptions |= TextCheckingTypeReplacement;
 #endif
-    if (!textCheckingOptions & (TextCheckingTypeSpelling | TextCheckingTypeReplacement))
-        return;
+        if (!(textCheckingOptions & (TextCheckingTypeSpelling | TextCheckingTypeReplacement)))
+            return;
 
-    if (isGrammarCheckingEnabled())
-        textCheckingOptions |= TextCheckingTypeGrammar;
+        if (isGrammarCheckingEnabled())
+            textCheckingOptions |= TextCheckingTypeGrammar;
 
-    VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
-    if (textCheckingOptions & TextCheckingTypeGrammar) {
-        VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart));
-        markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get());
-    } else {
-        markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get());
+        VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
+        if (textCheckingOptions & TextCheckingTypeGrammar) {
+            VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart));
+            markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get());
+        } else
+            markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get());
+        return;
     }
 
-#else
-    UNUSED_PARAM(selectionAfterTyping);
-    UNUSED_PARAM(doReplacement);
-
     if (!isContinuousSpellCheckingEnabled())
         return;
 
@@ -1923,7 +1920,6 @@
     
     // Check grammar of entire sentence
     markBadGrammar(VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart)));
-#endif
 }
     
 void Editor::markMisspellingsOrBadGrammar(const VisibleSelection& selection, bool checkSpelling, RefPtr<Range>& firstMisspellingRange)
@@ -1991,7 +1987,8 @@
 
 void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* spellingRange, Range* grammarRange)
 {
-#if USE(UNIFIED_TEXT_CHECKING)
+    ASSERT(unifiedTextCheckerEnabled());
+
     // There shouldn't be pending autocorrection at this moment.
     ASSERT(!m_spellingCorrector->hasPendingCorrection());
 
@@ -2182,17 +2179,12 @@
             m_frame->selection()->modify(FrameSelection::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)
+    ASSERT(unifiedTextCheckerEnabled());
+
     if (replacedString.isEmpty())
         return;
 
@@ -2206,28 +2198,25 @@
     RefPtr<Range> changedRange = paragraph.subrange(paragraph.checkingStart(), replacedString.length());
     changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::Replacement, String());
     m_spellingCorrector->markReversed(changedRange.get());
-#else
-    ASSERT_NOT_REACHED();
-    UNUSED_PARAM(replacedString);
-#endif // USE(UNIFIED_TEXT_CHECKING)
 }
 
 
 void Editor::markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection)
 {
-#if USE(UNIFIED_TEXT_CHECKING)
-    if (!isContinuousSpellCheckingEnabled())
+    if (unifiedTextCheckerEnabled()) {
+        if (!isContinuousSpellCheckingEnabled())
+            return;
+        TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling | TextCheckingTypeCorrection;
+        if (markGrammar && isGrammarCheckingEnabled())
+            textCheckingOptions |= TextCheckingTypeGrammar;
+        markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get());
         return;
-    TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling | TextCheckingTypeCorrection;
-    if (markGrammar && isGrammarCheckingEnabled())
-        textCheckingOptions |= TextCheckingTypeGrammar;
-    markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get());
-#else
+    }
+
     RefPtr<Range> firstMisspellingRange;
     markMisspellings(spellingSelection, firstMisspellingRange);
     if (markGrammar)
         markBadGrammar(grammarSelection);
-#endif
 }
 
 void Editor::unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction)
@@ -3080,4 +3069,9 @@
     m_deleteButtonController->deviceScaleFactorChanged();
 }
 
+bool Editor::unifiedTextCheckerEnabled() const
+{
+    return WebCore::unifiedTextCheckerEnabled(m_frame);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/editing/Editor.h (97695 => 97696)


--- trunk/Source/WebCore/editing/Editor.h	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/editing/Editor.h	2011-10-18 01:38:49 UTC (rev 97696)
@@ -417,6 +417,8 @@
     void changeSelectionAfterCommand(const VisibleSelection& newSelection, bool closeTyping, bool clearTypingStyle);
 
     Node* findEventTargetFromSelection() const;
+
+    bool unifiedTextCheckerEnabled() const;
 };
 
 inline void Editor::setStartNewKillRingSequence(bool flag)

Modified: trunk/Source/WebCore/editing/TextCheckingHelper.cpp (97695 => 97696)


--- trunk/Source/WebCore/editing/TextCheckingHelper.cpp	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/editing/TextCheckingHelper.cpp	2011-10-18 01:38:49 UTC (rev 97696)
@@ -29,7 +29,9 @@
 
 #include "Document.h"
 #include "DocumentMarkerController.h"
+#include "Frame.h"
 #include "Range.h"
+#include "Settings.h"
 #include "TextCheckerClient.h"
 #include "TextIterator.h"
 #include "VisiblePosition.h"
@@ -225,7 +227,9 @@
 
 String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, bool& outIsSpelling, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail)
 {
-#if USE(UNIFIED_TEXT_CHECKING)
+    if (!unifiedTextCheckerEnabled())
+        return "";
+
     String firstFoundItem;
     String misspelledWord;
     String badGrammarPhrase;
@@ -344,14 +348,6 @@
         totalLengthProcessed += currentLength;
     }
     return firstFoundItem;
-#else
-    ASSERT_NOT_REACHED();
-    UNUSED_PARAM(checkGrammar);
-    UNUSED_PARAM(outIsSpelling);
-    UNUSED_PARAM(outFirstFoundOffset);
-    UNUSED_PARAM(outGrammarDetail);
-    return "";
-#endif // USE(UNIFIED_TEXT_CHECKING)
 }
 
 int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int /*badGrammarPhraseLength*/, int startOffset, int endOffset, bool markAll)
@@ -510,7 +506,9 @@
 
 Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool checkGrammar, bool& misspelled, bool& ungrammatical) const
 {
-#if USE(UNIFIED_TEXT_CHECKING)
+    if (!unifiedTextCheckerEnabled())
+        return Vector<String>();
+
     Vector<String> guesses;
     ExceptionCode ec;
     misspelled = false;
@@ -562,13 +560,6 @@
         }
     }
     return guesses;
-#else
-    ASSERT_NOT_REACHED();
-    UNUSED_PARAM(checkGrammar);
-    UNUSED_PARAM(misspelled);
-    UNUSED_PARAM(ungrammatical);
-    return Vector<String>();
-#endif // USE(UNIFIED_TEXT_CHECKING)
 }
 
 
@@ -590,6 +581,18 @@
     findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true);
 }
 
+bool TextCheckingHelper::unifiedTextCheckerEnabled() const
+{
+    if (!m_range)
+        return false;
+
+    Document* doc = m_range->ownerDocument();
+    if (!doc)
+        return false;
+
+    return WebCore::unifiedTextCheckerEnabled(doc->frame());
+}
+
 void checkTextOfParagraph(TextCheckerClient* client, const UChar* text, int length,
                           TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
 {
@@ -607,4 +610,16 @@
 #endif
 }
 
+bool unifiedTextCheckerEnabled(const Frame* frame)
+{
+    if (!frame)
+        return false;
+
+    const Settings* settings = frame->settings();
+    if (!settings)
+        return false;
+
+    return settings->unifiedTextCheckerEnabled();
 }
+
+}

Modified: trunk/Source/WebCore/editing/TextCheckingHelper.h (97695 => 97696)


--- trunk/Source/WebCore/editing/TextCheckingHelper.h	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/editing/TextCheckingHelper.h	2011-10-18 01:38:49 UTC (rev 97696)
@@ -90,11 +90,15 @@
 private:
     EditorClient* m_client;
     RefPtr<Range> m_range;
+
+    bool unifiedTextCheckerEnabled() const;
 };
 
 void checkTextOfParagraph(TextCheckerClient*, const UChar* text, int length,
     TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results);
 
+bool unifiedTextCheckerEnabled(const Frame*);
+
 } // namespace WebCore
 
 #endif // TextCheckingHelper_h

Modified: trunk/Source/WebCore/page/Settings.cpp (97695 => 97696)


--- trunk/Source/WebCore/page/Settings.cpp	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/page/Settings.cpp	2011-10-18 01:38:49 UTC (rev 97696)
@@ -196,6 +196,11 @@
     , m_fullScreenAPIEnabled(false)
 #endif
     , m_asynchronousSpellCheckingEnabled(false)
+#if USE(UNIFIED_TEXT_CHECKING)
+    , m_unifiedTextCheckerEnabled(true)
+#else
+    , m_unifiedTextCheckerEnabled(false)
+#endif
     , m_memoryInfoEnabled(false)
     , m_interactiveFormValidation(false)
     , m_usePreHTML5ParserQuirks(false)

Modified: trunk/Source/WebCore/page/Settings.h (97695 => 97696)


--- trunk/Source/WebCore/page/Settings.h	2011-10-18 01:36:33 UTC (rev 97695)
+++ trunk/Source/WebCore/page/Settings.h	2011-10-18 01:38:49 UTC (rev 97696)
@@ -381,6 +381,9 @@
         void setAsynchronousSpellCheckingEnabled(bool flag) { m_asynchronousSpellCheckingEnabled = flag; }
         bool asynchronousSpellCheckingEnabled() const  { return m_asynchronousSpellCheckingEnabled; }
 
+        void setUnifiedTextCheckerEnabled(bool flag) { m_unifiedTextCheckerEnabled = flag; }
+        bool unifiedTextCheckerEnabled() const { return m_unifiedTextCheckerEnabled; }
+
         void setMemoryInfoEnabled(bool flag) { m_memoryInfoEnabled = flag; }
         bool memoryInfoEnabled() const { return m_memoryInfoEnabled; }
 
@@ -568,6 +571,7 @@
         bool m_fullScreenAPIEnabled : 1;
 #endif
         bool m_asynchronousSpellCheckingEnabled: 1;
+        bool m_unifiedTextCheckerEnabled: 1;
         bool m_memoryInfoEnabled: 1;
         bool m_interactiveFormValidation: 1;
         bool m_usePreHTML5ParserQuirks: 1;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to