Changeset 43039 in webkit


Ignore:
Timestamp:
Apr 29, 2009 6:35:07 PM (15 years ago)
Author:
justin.garcia@apple.com
Message:

WebCore:

2009-04-29 Douglas Davidson <ddavidso@apple.com>

Reviewed by Justin Garcia.

<rdar://problem/6836921> Mail exhibits issues with text checking, e.g. menu items not always validated correctly


Updates to the text checking code to enable text checking even if spellchecking is turned off
and fix an off-by-one error in selection handling.

  • editing/Editor.cpp: (WebCore::Editor::markMisspellingsAfterTypingToPosition): (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): (WebCore::Editor::markMisspellingsAndBadGrammar):
  • editing/Editor.h:
  • editing/TypingCommand.cpp: (WebCore::TypingCommand::markMisspellingsAfterTyping):

WebKit/mac:

2009-04-29 Douglas Davidson <ddavidso@apple.com>

Reviewed by Justin Garcia.


<rdar://problem/6836921> Mail exhibits issues with text checking, e.g. menu items not always validated correctly

  • WebView/WebHTMLView.mm: (-[WebHTMLView validateUserInterfaceItemWithoutDelegate:]): (-[WebHTMLView orderFrontSubstitutionsPanel:]):
  • WebView/WebView.mm: (-[WebView validateUserInterfaceItemWithoutDelegate:]):
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r43037 r43039  
     12009-04-29  Douglas Davidson  <ddavidso@apple.com>
     2
     3        Reviewed by Justin Garcia.
     4
     5        <rdar://problem/6836921> Mail exhibits issues with text checking, e.g. menu items not always validated correctly
     6       
     7        Updates to the text checking code to enable text checking even if spellchecking is turned off
     8        and fix an off-by-one error in selection handling.
     9
     10        * editing/Editor.cpp:
     11        (WebCore::Editor::markMisspellingsAfterTypingToPosition):
     12        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
     13        (WebCore::Editor::markMisspellingsAndBadGrammar):
     14        * editing/Editor.h:
     15        * editing/TypingCommand.cpp:
     16        (WebCore::TypingCommand::markMisspellingsAfterTyping):
     17
    1182009-04-29  Oliver Hunt  <oliver@apple.com>
    219
  • trunk/WebCore/editing/Editor.cpp

    r43035 r43039  
    21572157void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition &p)
    21582158{
     2159#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
     2160    bool markSpelling = isContinuousSpellCheckingEnabled();
     2161    bool markGrammar = markSpelling && isGrammarCheckingEnabled();
     2162    bool performTextCheckingReplacements = isAutomaticQuoteSubstitutionEnabled()
     2163                                        || isAutomaticLinkDetectionEnabled()
     2164                                        || isAutomaticDashSubstitutionEnabled()
     2165                                        || isAutomaticTextReplacementEnabled()
     2166                                        || (markSpelling && isAutomaticSpellingCorrectionEnabled());
     2167    if (!markSpelling && !performTextCheckingReplacements)
     2168        return;
     2169   
     2170    VisibleSelection adjacentWords = VisibleSelection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary));
     2171    if (markGrammar) {
     2172        VisibleSelection selectedSentence = VisibleSelection(startOfSentence(p), endOfSentence(p));
     2173        markAllMisspellingsAndBadGrammarInRanges(true, adjacentWords.toNormalizedRange().get(), true, selectedSentence.toNormalizedRange().get(), performTextCheckingReplacements);
     2174    } else {
     2175        markAllMisspellingsAndBadGrammarInRanges(markSpelling, adjacentWords.toNormalizedRange().get(), false, adjacentWords.toNormalizedRange().get(), performTextCheckingReplacements);
     2176    }
     2177#else
    21592178    if (!isContinuousSpellCheckingEnabled())
    21602179        return;
    21612180   
    2162 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    2163     VisibleSelection adjacentWords = VisibleSelection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary));
    2164     if (isGrammarCheckingEnabled()) {
    2165         VisibleSelection selectedSentence = VisibleSelection(startOfSentence(p), endOfSentence(p));
    2166         markAllMisspellingsAndBadGrammarInRanges(adjacentWords.toNormalizedRange().get(), true, selectedSentence.toNormalizedRange().get(), true);
    2167     } else {
    2168         markAllMisspellingsAndBadGrammarInRanges(adjacentWords.toNormalizedRange().get(), false, adjacentWords.toNormalizedRange().get(), true);
    2169     }
    2170 #else
    21712181    // Check spelling of one word
    21722182    markMisspellings(VisibleSelection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary)));
     
    22502260#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    22512261
    2252 void Editor::markAllMisspellingsAndBadGrammarInRanges(Range* spellingRange, bool markGrammar, Range* grammarRange, bool performTextCheckingReplacements)
     2262void Editor::markAllMisspellingsAndBadGrammarInRanges(bool markSpelling, Range* spellingRange, bool markGrammar, Range* grammarRange, bool performTextCheckingReplacements)
    22532263{
    22542264    // This function is called with selections already expanded to word boundaries.
     
    22992309                selectionOffset = TextIterator::rangeLength(offsetAsRange.get());
    23002310                restoreSelectionAfterChange = true;         
    2301                 adjustSelectionForParagraphBoundaries = (selectionOffset >= paragraphLength) ? true : false;
     2311                adjustSelectionForParagraphBoundaries = (selectionOffset > paragraphLength) ? true : false;
    23022312            }
    23032313        }
     
    23052315   
    23062316    Vector<TextCheckingResult> results;
    2307     uint64_t checkingTypes = markGrammar ? (TextCheckingTypeSpelling | TextCheckingTypeGrammar) : TextCheckingTypeSpelling;
     2317    uint64_t checkingTypes = 0;
     2318    if (markSpelling)
     2319        checkingTypes |= TextCheckingTypeSpelling;
     2320    if (markGrammar)
     2321        checkingTypes |= TextCheckingTypeGrammar;
    23082322    if (performTextCheckingReplacements) {
    23092323        if (isAutomaticLinkDetectionEnabled())
     
    23152329        if (isAutomaticTextReplacementEnabled())
    23162330            checkingTypes |= TextCheckingTypeReplacement;
    2317         if (isAutomaticSpellingCorrectionEnabled())
     2331        if (markSpelling && isAutomaticSpellingCorrectionEnabled())
    23182332            checkingTypes |= TextCheckingTypeCorrection;
    23192333    }
     
    23242338        int resultLocation = result->location + offsetDueToReplacement;
    23252339        int resultLength = result->length;
    2326         if (result->type == TextCheckingTypeSpelling && resultLocation >= spellingRangeStartOffset && resultLocation + resultLength <= spellingRangeEndOffset) {
     2340        if (markSpelling && result->type == TextCheckingTypeSpelling && resultLocation >= spellingRangeStartOffset && resultLocation + resultLength <= spellingRangeEndOffset) {
    23272341            ASSERT(resultLength > 0 && resultLocation >= 0);
    23282342            RefPtr<Range> misspellingRange = TextIterator::subrange(spellingRange, resultLocation - spellingRangeStartOffset, resultLength);
     
    23972411    if (!isContinuousSpellCheckingEnabled())
    23982412        return;
    2399     markAllMisspellingsAndBadGrammarInRanges(spellingSelection.toNormalizedRange().get(), markGrammar && isGrammarCheckingEnabled(), grammarSelection.toNormalizedRange().get(), false);
     2413    markAllMisspellingsAndBadGrammarInRanges(true, spellingSelection.toNormalizedRange().get(), markGrammar && isGrammarCheckingEnabled(), grammarSelection.toNormalizedRange().get(), false);
    24002414#else
    24012415    markMisspellings(spellingSelection);
  • trunk/WebCore/editing/Editor.h

    r42911 r43039  
    218218    bool isAutomaticSpellingCorrectionEnabled();
    219219    void toggleAutomaticSpellingCorrection();
    220     void markAllMisspellingsAndBadGrammarInRanges(Range* spellingRange, bool markGrammar, Range* grammarRange, bool performTextCheckingReplacements);
     220    void markAllMisspellingsAndBadGrammarInRanges(bool markSpelling, Range* spellingRange, bool markGrammar, Range* grammarRange, bool performTextCheckingReplacements);
    221221#endif
    222222    void advanceToNextMisspelling(bool startBeforeSelection = false);
  • trunk/WebCore/editing/TypingCommand.cpp

    r43035 r43039  
    282282void TypingCommand::markMisspellingsAfterTyping()
    283283{
     284#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
     285    if (!document()->frame()->editor()->isContinuousSpellCheckingEnabled()
     286     && !document()->frame()->editor()->isAutomaticQuoteSubstitutionEnabled()
     287     && !document()->frame()->editor()->isAutomaticLinkDetectionEnabled()
     288     && !document()->frame()->editor()->isAutomaticDashSubstitutionEnabled()
     289     && !document()->frame()->editor()->isAutomaticTextReplacementEnabled())
     290        return;
     291#else
    284292    if (!document()->frame()->editor()->isContinuousSpellCheckingEnabled())
    285293        return;
     294#endif
    286295    // Take a look at the selection that results after typing and determine whether we need to spellcheck.
    287296    // Since the word containing the current selection is never marked, this does a check to
  • trunk/WebKit/mac/ChangeLog

    r43025 r43039  
     12009-04-29  Douglas Davidson  <ddavidso@apple.com>
     2
     3        Reviewed by Justin Garcia.
     4       
     5        <rdar://problem/6836921> Mail exhibits issues with text checking, e.g. menu items not always validated correctly
     6
     7        * WebView/WebHTMLView.mm:
     8        (-[WebHTMLView validateUserInterfaceItemWithoutDelegate:]):
     9        (-[WebHTMLView orderFrontSubstitutionsPanel:]):
     10        * WebView/WebView.mm:
     11        (-[WebView validateUserInterfaceItemWithoutDelegate:]):
     12
    1132009-04-29  David Hyatt  <hyatt@apple.com>
    214
  • trunk/WebKit/mac/WebView/WebHTMLView.mm

    r42936 r43039  
    26602660
    26612661#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
     2662    if (action == @selector(orderFrontSubstitutionsPanel:)) {
     2663        NSMenuItem *menuItem = (NSMenuItem *)item;
     2664        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
     2665            BOOL panelShowing = [[[NSSpellChecker sharedSpellChecker] substitutionsPanel] isVisible];
     2666            [menuItem setTitle:panelShowing
     2667                ? UI_STRING("Hide Substitutions", "menu item title")
     2668                : UI_STRING("Show Substitutions", "menu item title")];
     2669        }
     2670        return [self _canEdit];
     2671    }
    26622672    // FIXME 4799134: WebView is the bottleneck for this logic, but we must validate
    26632673    // the selector here because we implement it here, and we must implement it here because the AppKit
     
    49925002
    49935003#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
     5004
     5005- (void)orderFrontSubstitutionsPanel:(id)sender
     5006{
     5007    COMMAND_PROLOGUE
     5008
     5009    NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
     5010    if (!checker) {
     5011        LOG_ERROR("No NSSpellChecker");
     5012        return;
     5013    }
     5014   
     5015    NSPanel *substitutionsPanel = [checker substitutionsPanel];
     5016    if ([substitutionsPanel isVisible]) {
     5017        [substitutionsPanel orderOut:sender];
     5018        return;
     5019    }
     5020    [substitutionsPanel orderFront:sender];
     5021}
    49945022
    49955023// FIXME 4799134: WebView is the bottleneck for this logic, but we must implement these methods here because
  • trunk/WebKit/mac/WebView/WebView.mm

    r43025 r43039  
    253253macro(moveWordRightAndModifySelection) \
    254254macro(outdent) \
     255macro(orderFrontSubstitutionsPanel) \
    255256macro(pageDown) \
    256257macro(pageDownAndModifySelection) \
     
    37523753        }
    37533754        return retVal;
     3755    } else if (action == @selector(toggleSmartInsertDelete:)) {
     3756        BOOL checkMark = [self smartInsertDeleteEnabled];
     3757        if ([(NSObject *)item isKindOfClass:[NSMenuItem class]]) {
     3758            NSMenuItem *menuItem = (NSMenuItem *)item;
     3759            [menuItem setState:checkMark ? NSOnState : NSOffState];
     3760        }
     3761        return YES;
    37543762#ifndef BUILDING_ON_TIGER
    37553763    } else if (action == @selector(toggleGrammarChecking:)) {
Note: See TracChangeset for help on using the changeset viewer.