Changeset 97696 in webkit


Ignore:
Timestamp:
Oct 17, 2011 6:38:49 PM (12 years ago)
Author:
commit-queue@webkit.org
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 <shinyak@google.com> 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.

Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r97669 r97696  
    652652    editing/ReplaceSelectionCommand.cpp
    653653    editing/SetNodeAttributeCommand.cpp
     654    editing/SetSelectionCommand.cpp
    654655    editing/SmartReplace.cpp
    655656    editing/SpellChecker.cpp
    656657    editing/SpellingCorrectionController.cpp
     658    editing/SpellingCorrectionCommand.cpp
    657659    editing/SplitElementCommand.cpp
    658660    editing/SplitTextNodeCommand.cpp
  • trunk/Source/WebCore/ChangeLog

    r97695 r97696  
     12011-10-17  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Unified spell-checking and legacy spell checking should be easy to switch
     4        https://bugs.webkit.org/show_bug.cgi?id=69242
     5
     6        Reviewed by Hajime Morita.
     7
     8        WebCore has two different code paths for spell-checking:
     9                  1) checkTextOfParagraph() for Snow Leopard or later
     10                  2) checkSpellingOfString() for checkGrammarOfString() for other platforms.
     11
     12        This patch introduces a flag to change code paths dynamically.
     13        This patch also includes build fix for QT, GTK, and Windows platforms.
     14
     15        No new tests because this patch does not change a behavior.
     16
     17        * CMakeLists.txt:
     18        * GNUmakefile.list.am:
     19        * WebCore.pro:
     20        * WebCore.vcproj/WebCore.vcproj:
     21        * accessibility/AccessibilityObject.cpp:
     22        (WebCore::AccessibilityObject::hasMisspelling):
     23          Changed static if-USE(UNIFIED_TEXT_CHECKING) statement to dynamic
     24          condition branch to achieve easy code path change.
     25        * accessibility/mac/WebAccessibilityObjectWrapper.mm: ditto.
     26        (AXAttributeStringSetSpelling):
     27        * editing/EditingAllInOne.cpp:
     28        * editing/Editor.cpp:
     29        (WebCore::Editor::advanceToNextMisspelling): ditto.
     30        (WebCore::Editor::guessesForMisspelledOrUngrammaticalSelection): ditto.
     31        (WebCore::Editor::markMisspellingsAfterTypingToWord): ditto.
     32        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): ditto.
     33        (WebCore::Editor::changeBackToReplacedString): ditto.
     34        (WebCore::Editor::markMisspellingsAndBadGrammar): ditto.
     35        (WebCore::Editor::unifiedTextCheckerEnabled):
     36          Utility method to check using unified text checking or not.
     37        * editing/Editor.h:
     38        * editing/TextCheckingHelper.cpp:
     39        (WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar):
     40          Same as WebCore::AccessibilityObject::hasMisspelling.
     41        (WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange): ditto.
     42        (WebCore::TextCheckingHelper::unifiedTextCheckerEnabled):
     43          Utility method to check using unified text checking or not.
     44        (WebCore::unifiedTextCheckerEnabled): ditto.
     45        * editing/TextCheckingHelper.h:
     46        * page/Settings.cpp:
     47        (WebCore::Settings::Settings):
     48          Includes a flag to change the code path.
     49        * page/Settings.h:
     50        (WebCore::Settings::setUnifiedTextCheckerEnabled):
     51          Sets a flag to change the code path.
     52        (WebCore::Settings::unifiedTextCheckerEnabled):
     53          A flag to change the code path.
     54
    1552011-10-17  Julien Chaffraix  <jchaffraix@webkit.org>
    256
  • trunk/Source/WebCore/GNUmakefile.list.am

    r97669 r97696  
    14381438        Source/WebCore/editing/SetNodeAttributeCommand.cpp \
    14391439        Source/WebCore/editing/SetNodeAttributeCommand.h \
     1440        Source/WebCore/editing/SetSelectionCommand.cpp \
     1441        Source/WebCore/editing/SetSelectionCommand.h \
    14401442        Source/WebCore/editing/SmartReplace.cpp \
    14411443        Source/WebCore/editing/SmartReplace.h \
     
    14451447        Source/WebCore/editing/SpellingCorrectionController.cpp \
    14461448        Source/WebCore/editing/SpellingCorrectionController.h \
     1449        Source/WebCore/editing/SpellingCorrectionCommand.cpp \
    14471450        Source/WebCore/editing/SpellingCorrectionCommand.h \
    14481451        Source/WebCore/editing/SplitElementCommand.cpp \
  • trunk/Source/WebCore/WebCore.pro

    r97669 r97696  
    616616    editing/ReplaceSelectionCommand.cpp \
    617617    editing/SetNodeAttributeCommand.cpp \
     618    editing/SetSelectionCommand.cpp \
    618619    editing/SmartReplaceICU.cpp \
    619620    editing/SpellChecker.cpp \
     621    editing/SpellingCorrectionCommand.cpp \
    620622    editing/SpellingCorrectionController.cpp \
    621623    editing/SplitElementCommand.cpp \
     
    16471649    editing/SetNodeAttributeCommand.h \
    16481650    editing/SmartReplace.h \
     1651    editing/SpellingCorrectionCommand.h \
    16491652    editing/SpellingCorrectionController.h \
    16501653    editing/SplitElementCommand.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r97669 r97696  
    5261752617                                </FileConfiguration>
    5261852618                        </File>
     52619            <File
     52620                 RelativePath="..\editing\SetSelectionCommand.cpp"
     52621                 >
     52622                <FileConfiguration
     52623                      Name="Debug|Win32"
     52624                      ExcludedFromBuild="true"
     52625                     >
     52626                    <Tool
     52627                          Name="VCCLCompilerTool"
     52628                          />
     52629                    </FileConfiguration>
     52630                <FileConfiguration
     52631                      Name="Release|Win32"
     52632                      ExcludedFromBuild="true"
     52633                      >
     52634                    <Tool
     52635                          Name="VCCLCompilerTool"
     52636                          />
     52637                    </FileConfiguration>
     52638                <FileConfiguration
     52639                      Name="Debug_Cairo_CFLite|Win32"
     52640                      ExcludedFromBuild="true"
     52641                      >
     52642                    <Tool
     52643                          Name="VCCLCompilerTool"
     52644                          />
     52645                    </FileConfiguration>
     52646                <FileConfiguration
     52647                      Name="Release_Cairo_CFLite|Win32"
     52648                      ExcludedFromBuild="true"
     52649                      >
     52650                    <Tool
     52651                          Name="VCCLCompilerTool"
     52652                          />
     52653                    </FileConfiguration>
     52654                <FileConfiguration
     52655                      Name="Debug_All|Win32"
     52656                      ExcludedFromBuild="true"
     52657                      >
     52658                    <Tool
     52659                          Name="VCCLCompilerTool"
     52660                          />
     52661                    </FileConfiguration>
     52662                <FileConfiguration
     52663                      Name="Production|Win32"
     52664                      ExcludedFromBuild="true"
     52665                      >
     52666                    <Tool
     52667                          Name="VCCLCompilerTool"
     52668                          />
     52669                    </FileConfiguration>
     52670                </File>
     52671            <File
     52672                  RelativePath="..\editing\SetSelectionCommand.h"
     52673                  >
     52674                </File>
    5261952675                        <File
    5262052676                                RelativePath="..\editing\SmartReplace.h"
     
    5272952785                                >
    5273052786                        </File>
     52787            <File
     52788                 RelativePath="..\editing\SpellingCorrectionCommand.cpp"
     52789                 >
     52790                <FileConfiguration
     52791                      Name="Debug|Win32"
     52792                      ExcludedFromBuild="true"
     52793                      >
     52794                    <Tool
     52795                          Name="VCCLCompilerTool"
     52796                          />
     52797                    </FileConfiguration>
     52798                <FileConfiguration
     52799                      Name="Release|Win32"
     52800                      ExcludedFromBuild="true"
     52801                      >
     52802                    <Tool
     52803                          Name="VCCLCompilerTool"
     52804                          />
     52805                    </FileConfiguration>
     52806                <FileConfiguration
     52807                      Name="Debug_Cairo_CFLite|Win32"
     52808                      ExcludedFromBuild="true"
     52809                      >
     52810                    <Tool
     52811                          Name="VCCLCompilerTool"
     52812                          />
     52813                    </FileConfiguration>
     52814                <FileConfiguration
     52815                      Name="Release_Cairo_CFLite|Win32"
     52816                      ExcludedFromBuild="true"
     52817                      >
     52818                    <Tool
     52819                          Name="VCCLCompilerTool"
     52820                          />
     52821                    </FileConfiguration>
     52822                <FileConfiguration
     52823                      Name="Debug_All|Win32"
     52824                      ExcludedFromBuild="true"
     52825                      >
     52826                    <Tool
     52827                          Name="VCCLCompilerTool"
     52828                          />
     52829                    </FileConfiguration>
     52830                <FileConfiguration
     52831                      Name="Release_LTCG|Win32"
     52832                      ExcludedFromBuild="true"
     52833                      >
     52834                    <Tool
     52835                          Name="VCCLCompilerTool"
     52836                          />
     52837                    </FileConfiguration>
     52838                </File>
     52839            <File
     52840                  RelativePath="..\editing\SpellingCorrectionCommand.h"
     52841                  >
     52842            </File>
    5273152843                        <File
    5273252844                                RelativePath="..\editing\SpellingCorrectionController.cpp"
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r97669 r97696  
    5151#include "RenderWidget.h"
    5252#include "RenderedPosition.h"
     53#include "Settings.h"
    5354#include "TextCheckerClient.h"
    5455#include "TextCheckingHelper.h"
     
    290291    int charsLength = stringValue().length();
    291292    bool isMisspelled = false;
    292    
    293 #if USE(UNIFIED_TEXT_CHECKING)
    294     Vector<TextCheckingResult> results;
    295     checkTextOfParagraph(textChecker, chars, charsLength, TextCheckingTypeSpelling, results);
    296     if (!results.isEmpty())
    297         isMisspelled = true;
    298 #else
     293
     294    if (unifiedTextCheckerEnabled(frame)) {
     295        Vector<TextCheckingResult> results;
     296        checkTextOfParagraph(textChecker, chars, charsLength, TextCheckingTypeSpelling, results);
     297        if (!results.isEmpty())
     298            isMisspelled = true;
     299        return isMisspelled;
     300    }
     301
    299302    int misspellingLength = 0;
    300303    int misspellingLocation = -1;
     
    302305    if (misspellingLength || misspellingLocation != -1)
    303306        isMisspelled = true;
    304 #endif
    305307   
    306308    return isMisspelled;
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm

    r97669 r97696  
    691691static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString, Node* node, const UChar* chars, int charLength, NSRange range)
    692692{
    693 #if USE(UNIFIED_TEXT_CHECKING)
    694     // Check the spelling directly since document->markersForNode() does not store the misspelled marking when the cursor is in a word.
    695     TextCheckerClient* checker = node->document()->frame()->editor()->textChecker();
    696 
    697     // checkTextOfParagraph is the only spelling/grammar checker implemented in WK1 and WK2
    698     Vector<TextCheckingResult> results;
    699     checkTextOfParagraph(checker, chars, charLength, TextCheckingTypeSpelling, results);
    700    
    701     size_t size = results.size();
    702     NSNumber* trueValue = [NSNumber numberWithBool:YES];
    703     for (unsigned i = 0; i < size; i++) {
    704         const TextCheckingResult& result = results[i];
    705         AXAttributeStringSetNumber(attrString, NSAccessibilityMisspelledTextAttribute, trueValue, NSMakeRange(result.location + range.location, result.length));
    706     }   
    707 #else
     693    if (unifiedTextCheckerEnabled(node->document()->frame())) {
     694        // Check the spelling directly since document->markersForNode() does not store the misspelled marking when the cursor is in a word.
     695        TextCheckerClient* checker = node->document()->frame()->editor()->textChecker();
     696
     697        // checkTextOfParagraph is the only spelling/grammar checker implemented in WK1 and WK2
     698        Vector<TextCheckingResult> results;
     699        checkTextOfParagraph(checker, chars, charLength, TextCheckingTypeSpelling, results);
     700
     701        size_t size = results.size();
     702        NSNumber* trueValue = [NSNumber numberWithBool:YES];
     703        for (unsigned i = 0; i < size; i++) {
     704            const TextCheckingResult& result = results[i];
     705            AXAttributeStringSetNumber(attrString, NSAccessibilityMisspelledTextAttribute, trueValue, NSMakeRange(result.location + range.location, result.length));
     706        }
     707        return;
     708    }
     709
    708710    int currentPosition = 0;
    709711    while (charLength > 0) {
     
    722724        currentPosition += (misspellingLocation + misspellingLength);
    723725    }
    724 #endif   
    725726}
    726727
  • trunk/Source/WebCore/editing/EditingAllInOne.cpp

    r92286 r97696  
    6262#include <ReplaceSelectionCommand.cpp>
    6363#include <SetNodeAttributeCommand.cpp>
     64#include <SetSelectionCommand.cpp>
    6465#include <SmartReplace.cpp>
    6566#include <SmartReplaceCF.cpp>
     67#include <SpellingCorrectionCommand.cpp>
    6668#include <SpellingCorrectionController.cpp>
    6769#include <SpellChecker.cpp>
  • trunk/Source/WebCore/editing/Editor.cpp

    r97585 r97696  
    16291629    String misspelledWord;
    16301630
    1631 #if USE(UNIFIED_TEXT_CHECKING)
    1632     grammarSearchRange = spellingSearchRange->cloneRange(ec);
    16331631    bool isSpelling = true;
    16341632    int foundOffset = 0;
    1635     String foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
    1636     if (isSpelling) {
    1637         misspelledWord = foundItem;
    1638         misspellingOffset = foundOffset;
    1639     } else {
    1640         badGrammarPhrase = foundItem;
    1641         grammarPhraseOffset = foundOffset;
    1642     }
    1643 #else
     1633    String foundItem;
    16441634    RefPtr<Range> firstMisspellingRange;
    1645     misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
    1646 
    1647 #if USE(GRAMMAR_CHECKING)
    1648     // Search for bad grammar that occurs prior to the next misspelled word (if any)
    1649     grammarSearchRange = spellingSearchRange->cloneRange(ec);
    1650     if (!misspelledWord.isEmpty()) {
    1651         // Stop looking at start of next misspelled word
    1652         CharacterIterator chars(grammarSearchRange.get());
    1653         chars.advance(misspellingOffset);
    1654         grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
    1655     }
    1656    
    1657     if (isGrammarCheckingEnabled())
    1658         badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
    1659 #endif
    1660 #endif
    1661    
    1662     // 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
    1663     // block rather than at a selection).
    1664     if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
    1665         spellingSearchRange->setStart(topNode, 0, ec);
    1666         // going until the end of the very first chunk we tested is far enough
    1667         spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, ec);
    1668        
    1669 #if USE(UNIFIED_TEXT_CHECKING)
     1635    if (unifiedTextCheckerEnabled()) {
    16701636        grammarSearchRange = spellingSearchRange->cloneRange(ec);
    16711637        foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
     
    16771643            grammarPhraseOffset = foundOffset;
    16781644        }
    1679 #else
     1645    } else {
    16801646        misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
    16811647
     
    16881654            grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
    16891655        }
    1690 
     1656   
    16911657        if (isGrammarCheckingEnabled())
    16921658            badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
    16931659#endif
     1660    }
     1661   
     1662    // 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
     1663    // block rather than at a selection).
     1664    if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
     1665        spellingSearchRange->setStart(topNode, 0, ec);
     1666        // going until the end of the very first chunk we tested is far enough
     1667        spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfterWrap, ec);
     1668       
     1669        if (unifiedTextCheckerEnabled()) {
     1670            grammarSearchRange = spellingSearchRange->cloneRange(ec);
     1671            foundItem = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, foundOffset, grammarDetail);
     1672            if (isSpelling) {
     1673                misspelledWord = foundItem;
     1674                misspellingOffset = foundOffset;
     1675            } else {
     1676                badGrammarPhrase = foundItem;
     1677                grammarPhraseOffset = foundOffset;
     1678            }
     1679        } else {
     1680            misspelledWord = TextCheckingHelper(client(), spellingSearchRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
     1681
     1682#if USE(GRAMMAR_CHECKING)
     1683            grammarSearchRange = spellingSearchRange->cloneRange(ec);
     1684            if (!misspelledWord.isEmpty()) {
     1685                // Stop looking at start of next misspelled word
     1686                CharacterIterator chars(grammarSearchRange.get());
     1687                chars.advance(misspellingOffset);
     1688                grammarSearchRange->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
     1689            }
     1690
     1691            if (isGrammarCheckingEnabled())
     1692                badGrammarPhrase = TextCheckingHelper(client(), grammarSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
    16941693#endif
     1694        }
    16951695    }
    16961696   
     
    17921792Vector<String> Editor::guessesForMisspelledOrUngrammaticalSelection(bool& misspelled, bool& ungrammatical)
    17931793{
    1794 #if USE(UNIFIED_TEXT_CHECKING)
    1795     RefPtr<Range> range = frame()->selection()->toNormalizedRange();
    1796     if (!range)
    1797         return Vector<String>();
    1798     return TextCheckingHelper(client(), range).guessesForMisspelledOrUngrammaticalRange(isGrammarCheckingEnabled(), misspelled, ungrammatical);
    1799 #else
     1794    if (unifiedTextCheckerEnabled()) {
     1795        RefPtr<Range> range = frame()->selection()->toNormalizedRange();
     1796        if (!range)
     1797            return Vector<String>();
     1798        return TextCheckingHelper(client(), range).guessesForMisspelledOrUngrammaticalRange(isGrammarCheckingEnabled(), misspelled, ungrammatical);
     1799    }
     1800
    18001801    misspelled = isSelectionMisspelled();
    18011802    if (misspelled) {
     
    18091810    ungrammatical = false;
    18101811    return Vector<String>();
    1811 #endif
    18121812}
    18131813
     
    18511851void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping, bool doReplacement)
    18521852{
    1853 #if USE(UNIFIED_TEXT_CHECKING)
    1854     m_spellingCorrector->applyPendingCorrection(selectionAfterTyping);
    1855 
    1856     TextCheckingTypeMask textCheckingOptions = 0;
    1857 
    1858     if (isContinuousSpellCheckingEnabled())
    1859         textCheckingOptions |= TextCheckingTypeSpelling;
     1853    if (unifiedTextCheckerEnabled()) {
     1854        m_spellingCorrector->applyPendingCorrection(selectionAfterTyping);
     1855
     1856        TextCheckingTypeMask textCheckingOptions = 0;
     1857
     1858        if (isContinuousSpellCheckingEnabled())
     1859            textCheckingOptions |= TextCheckingTypeSpelling;
    18601860
    18611861#if USE(AUTOMATIC_TEXT_REPLACEMENT)
    1862     if (doReplacement
    1863         && (isAutomaticQuoteSubstitutionEnabled()
    1864             || isAutomaticLinkDetectionEnabled()
    1865             || isAutomaticDashSubstitutionEnabled()
    1866             || isAutomaticTextReplacementEnabled()
    1867             || ((textCheckingOptions & TextCheckingTypeSpelling) && isAutomaticSpellingCorrectionEnabled())))
    1868         textCheckingOptions |= TextCheckingTypeReplacement;
     1862        if (doReplacement
     1863            && (isAutomaticQuoteSubstitutionEnabled()
     1864                || isAutomaticLinkDetectionEnabled()
     1865                || isAutomaticDashSubstitutionEnabled()
     1866                || isAutomaticTextReplacementEnabled()
     1867                || ((textCheckingOptions & TextCheckingTypeSpelling) && isAutomaticSpellingCorrectionEnabled())))
     1868            textCheckingOptions |= TextCheckingTypeReplacement;
    18691869#endif
    1870     if (!textCheckingOptions & (TextCheckingTypeSpelling | TextCheckingTypeReplacement))
    1871         return;
    1872 
    1873     if (isGrammarCheckingEnabled())
    1874         textCheckingOptions |= TextCheckingTypeGrammar;
    1875 
    1876     VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
    1877     if (textCheckingOptions & TextCheckingTypeGrammar) {
    1878         VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart));
    1879         markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get());
    1880     } else {
    1881         markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get());
    1882     }
    1883 
    1884 #else
    1885     UNUSED_PARAM(selectionAfterTyping);
    1886     UNUSED_PARAM(doReplacement);
     1870        if (!(textCheckingOptions & (TextCheckingTypeSpelling | TextCheckingTypeReplacement)))
     1871            return;
     1872
     1873        if (isGrammarCheckingEnabled())
     1874            textCheckingOptions |= TextCheckingTypeGrammar;
     1875
     1876        VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
     1877        if (textCheckingOptions & TextCheckingTypeGrammar) {
     1878            VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart));
     1879            markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get());
     1880        } else
     1881            markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get());
     1882        return;
     1883    }
    18871884
    18881885    if (!isContinuousSpellCheckingEnabled())
     
    19241921    // Check grammar of entire sentence
    19251922    markBadGrammar(VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart)));
    1926 #endif
    19271923}
    19281924   
     
    19921988void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* spellingRange, Range* grammarRange)
    19931989{
    1994 #if USE(UNIFIED_TEXT_CHECKING)
     1990    ASSERT(unifiedTextCheckerEnabled());
     1991
    19951992    // There shouldn't be pending autocorrection at this moment.
    19961993    ASSERT(!m_spellingCorrector->hasPendingCorrection());
     
    21832180        }
    21842181    }
    2185 #else
    2186     ASSERT_NOT_REACHED();
    2187     UNUSED_PARAM(textCheckingOptions);
    2188     UNUSED_PARAM(spellingRange);
    2189     UNUSED_PARAM(grammarRange);
    2190 #endif // USE(UNIFIED_TEXT_CHECKING)
    21912182}
    21922183
    21932184void Editor::changeBackToReplacedString(const String& replacedString)
    21942185{
    2195 #if USE(UNIFIED_TEXT_CHECKING)
     2186    ASSERT(unifiedTextCheckerEnabled());
     2187
    21962188    if (replacedString.isEmpty())
    21972189        return;
     
    22072199    changedRange->startContainer()->document()->markers()->addMarker(changedRange.get(), DocumentMarker::Replacement, String());
    22082200    m_spellingCorrector->markReversed(changedRange.get());
    2209 #else
    2210     ASSERT_NOT_REACHED();
    2211     UNUSED_PARAM(replacedString);
    2212 #endif // USE(UNIFIED_TEXT_CHECKING)
    22132201}
    22142202
     
    22162204void Editor::markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection)
    22172205{
    2218 #if USE(UNIFIED_TEXT_CHECKING)
    2219     if (!isContinuousSpellCheckingEnabled())
    2220         return;
    2221     TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling | TextCheckingTypeCorrection;
    2222     if (markGrammar && isGrammarCheckingEnabled())
    2223         textCheckingOptions |= TextCheckingTypeGrammar;
    2224     markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get());
    2225 #else
     2206    if (unifiedTextCheckerEnabled()) {
     2207        if (!isContinuousSpellCheckingEnabled())
     2208            return;
     2209        TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling | TextCheckingTypeCorrection;
     2210        if (markGrammar && isGrammarCheckingEnabled())
     2211            textCheckingOptions |= TextCheckingTypeGrammar;
     2212        markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get());
     2213        return;
     2214    }
     2215
    22262216    RefPtr<Range> firstMisspellingRange;
    22272217    markMisspellings(spellingSelection, firstMisspellingRange);
    22282218    if (markGrammar)
    22292219        markBadGrammar(grammarSelection);
    2230 #endif
    22312220}
    22322221
     
    30813070}
    30823071
     3072bool Editor::unifiedTextCheckerEnabled() const
     3073{
     3074    return WebCore::unifiedTextCheckerEnabled(m_frame);
     3075}
     3076
    30833077} // namespace WebCore
  • trunk/Source/WebCore/editing/Editor.h

    r97585 r97696  
    418418
    419419    Node* findEventTargetFromSelection() const;
     420
     421    bool unifiedTextCheckerEnabled() const;
    420422};
    421423
  • trunk/Source/WebCore/editing/TextCheckingHelper.cpp

    r96568 r97696  
    3030#include "Document.h"
    3131#include "DocumentMarkerController.h"
     32#include "Frame.h"
    3233#include "Range.h"
     34#include "Settings.h"
    3335#include "TextCheckerClient.h"
    3436#include "TextIterator.h"
     
    226228String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool checkGrammar, bool& outIsSpelling, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail)
    227229{
    228 #if USE(UNIFIED_TEXT_CHECKING)
     230    if (!unifiedTextCheckerEnabled())
     231        return "";
     232
    229233    String firstFoundItem;
    230234    String misspelledWord;
     
    345349    }
    346350    return firstFoundItem;
    347 #else
    348     ASSERT_NOT_REACHED();
    349     UNUSED_PARAM(checkGrammar);
    350     UNUSED_PARAM(outIsSpelling);
    351     UNUSED_PARAM(outFirstFoundOffset);
    352     UNUSED_PARAM(outGrammarDetail);
    353     return "";
    354 #endif // USE(UNIFIED_TEXT_CHECKING)
    355351}
    356352
     
    511507Vector<String> TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange(bool checkGrammar, bool& misspelled, bool& ungrammatical) const
    512508{
    513 #if USE(UNIFIED_TEXT_CHECKING)
     509    if (!unifiedTextCheckerEnabled())
     510        return Vector<String>();
     511
    514512    Vector<String> guesses;
    515513    ExceptionCode ec;
     
    563561    }
    564562    return guesses;
    565 #else
    566     ASSERT_NOT_REACHED();
    567     UNUSED_PARAM(checkGrammar);
    568     UNUSED_PARAM(misspelled);
    569     UNUSED_PARAM(ungrammatical);
    570     return Vector<String>();
    571 #endif // USE(UNIFIED_TEXT_CHECKING)
    572563}
    573564
     
    589580    int ignoredOffset;
    590581    findFirstBadGrammar(ignoredGrammarDetail, ignoredOffset, true);
     582}
     583
     584bool TextCheckingHelper::unifiedTextCheckerEnabled() const
     585{
     586    if (!m_range)
     587        return false;
     588
     589    Document* doc = m_range->ownerDocument();
     590    if (!doc)
     591        return false;
     592
     593    return WebCore::unifiedTextCheckerEnabled(doc->frame());
    591594}
    592595
     
    608611}
    609612
    610 }
     613bool unifiedTextCheckerEnabled(const Frame* frame)
     614{
     615    if (!frame)
     616        return false;
     617
     618    const Settings* settings = frame->settings();
     619    if (!settings)
     620        return false;
     621
     622    return settings->unifiedTextCheckerEnabled();
     623}
     624
     625}
  • trunk/Source/WebCore/editing/TextCheckingHelper.h

    r96571 r97696  
    9191    EditorClient* m_client;
    9292    RefPtr<Range> m_range;
     93
     94    bool unifiedTextCheckerEnabled() const;
    9395};
    9496
     
    9698    TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results);
    9799
     100bool unifiedTextCheckerEnabled(const Frame*);
     101
    98102} // namespace WebCore
    99103
  • trunk/Source/WebCore/page/Settings.cpp

    r97574 r97696  
    197197#endif
    198198    , m_asynchronousSpellCheckingEnabled(false)
     199#if USE(UNIFIED_TEXT_CHECKING)
     200    , m_unifiedTextCheckerEnabled(true)
     201#else
     202    , m_unifiedTextCheckerEnabled(false)
     203#endif
    199204    , m_memoryInfoEnabled(false)
    200205    , m_interactiveFormValidation(false)
  • trunk/Source/WebCore/page/Settings.h

    r97574 r97696  
    381381        void setAsynchronousSpellCheckingEnabled(bool flag) { m_asynchronousSpellCheckingEnabled = flag; }
    382382        bool asynchronousSpellCheckingEnabled() const  { return m_asynchronousSpellCheckingEnabled; }
     383
     384        void setUnifiedTextCheckerEnabled(bool flag) { m_unifiedTextCheckerEnabled = flag; }
     385        bool unifiedTextCheckerEnabled() const { return m_unifiedTextCheckerEnabled; }
    383386
    384387        void setMemoryInfoEnabled(bool flag) { m_memoryInfoEnabled = flag; }
     
    569572#endif
    570573        bool m_asynchronousSpellCheckingEnabled: 1;
     574        bool m_unifiedTextCheckerEnabled: 1;
    571575        bool m_memoryInfoEnabled: 1;
    572576        bool m_interactiveFormValidation: 1;
Note: See TracChangeset for help on using the changeset viewer.