Changeset 17508 in webkit


Ignore:
Timestamp:
Oct 31, 2006, 6:49:02 PM (18 years ago)
Author:
sullivan
Message:

Reviewed by Maciej


  • fixed <rdar://problem/4804627> ToolTips do not appear for grammar suggestions


The foundation of this was in my last checkin. This checkin is all about displaying
the correct string in the toolTip.

  • dom/DocumentMarker.h: New description field in this struct.
  • bridge/mac/FrameMac.mm: (WebCore::FrameMac::advanceToNextMisspelling): When adding a grammar marker, supply the appropriate description. Also, added a comment about the remaining work to make grammar checking return sensible answers. (WebCore::FrameMac::markMisspellings): ditto (yes, still needs some refactoring to minimize duplicated code)


  • dom/Document.h:
  • dom/Document.cpp: (WebCore::Document::addMarker): Now takes an optional description string (WebCore::Document::markerContainingPoint): New function, returns a pointer to the (first) marker of the specified type whose rect contains the specified point, or 0 if none.


  • rendering/HitTestResult.cpp: (WebCore::HitTestResult::spellingToolTip): Replaced hardwired string placeholder implementation with code that uses markerContainingPoint and gets the description from the marker.
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r17506 r17508  
     12006-10-31  John Sullivan  <sullivan@apple.com>
     2
     3        Reviewed by Maciej
     4       
     5        - fixed <rdar://problem/4804627> ToolTips do not appear for grammar suggestions
     6       
     7        The foundation of this was in my last checkin. This checkin is all about displaying
     8        the correct string in the toolTip.
     9
     10        * dom/DocumentMarker.h:
     11        New description field in this struct.
     12
     13        * bridge/mac/FrameMac.mm:
     14        (WebCore::FrameMac::advanceToNextMisspelling):
     15        When adding a grammar marker, supply the appropriate description. Also, added a comment
     16        about the remaining work to make grammar checking return sensible answers.
     17        (WebCore::FrameMac::markMisspellings):
     18        ditto (yes, still needs some refactoring to minimize duplicated code)
     19       
     20        * dom/Document.h:
     21        * dom/Document.cpp:
     22        (WebCore::Document::addMarker):
     23        Now takes an optional description string
     24        (WebCore::Document::markerContainingPoint):
     25        New function, returns a pointer to the (first) marker of the specified type whose rect
     26        contains the specified point, or 0 if none.
     27       
     28        * rendering/HitTestResult.cpp:
     29        (WebCore::HitTestResult::spellingToolTip):
     30        Replaced hardwired string placeholder implementation with code that uses markerContainingPoint
     31        and gets the description from the marker.
     32
    1332006-10-31  Geoffrey Garen  <ggaren@apple.com>
    234
  • trunk/WebCore/bridge/mac/FrameMac.mm

    r17504 r17508  
    635635    int searchEndAfterWrapOffset = it.range()->endOffset(exception);
    636636
     637    // FIXME: We need to compute the entire paragraph(s?) containing the search range, and use that as "chunk" below,
     638    // so there's enough context for the spell checker to evaluate grammar (4811175) and in some cases even spelling (4149250).
     639    // That means we need to compute the right offset to pass to the NSSpellChecker methods.
     640
    637641    while (1) {
    638642        if (!it.atEnd()) {      // we may be starting at the end of the doc, and already by atEnd
     
    708712                selectionController()->setSelection(Selection(badRangeToMark.get(), DOWNSTREAM));
    709713                revealSelection();
    710                 // Mark misspelling in document.
    711                 document()->addMarker(badRangeToMark.get(), markMisspelling ? DocumentMarker::Spelling : DocumentMarker::Grammar);
    712714               
    713                 if (markMisspelling)
     715                if (markMisspelling) {
    714716                    [checker updateSpellingPanelWithMisspelledWord:[chunk substringWithRange:misspellingNSRange]];
     717                    document()->addMarker(badRangeToMark.get(), DocumentMarker::Spelling);
     718                }
    715719#ifndef BUILDING_ON_TIGER
    716                 else
     720                else {
    717721                    [checker updateSpellingPanelWithGrammarString:[chunk substringWithRange:badGrammarNSRange] detail:grammarDetail];
     722                    document()->addMarker(badRangeToMark.get(), DocumentMarker::Grammar, [grammarDetail objectForKey:NSGrammarUserDescription]);
     723                }
    718724#endif
    719725               
     
    25312537   
    25322538    WordAwareIterator it(searchRange.get());
     2539   
     2540    // FIXME: We need to compute the entire paragraph(s?) containing the search range, and use that as "chunk" below,
     2541    // so there's enough context for the spell checker to evaluate grammar (4811175) and in some cases even spelling (4149250).
     2542    // That means we need to compute the right offset to pass to the NSSpellChecker methods.
    25332543   
    25342544    while (!it.atEnd()) {      // we may be starting at the end of the doc, and already by atEnd
     
    26022612                chars.advance(badNSRangeToMark.length);
    26032613                badRangeToMark->setEnd(chars.range()->startContainer(exception), chars.range()->startOffset(exception), exception);
    2604                 // Mark misspelling in document.
    2605                 document()->addMarker(badRangeToMark.get(), markMisspelling ? DocumentMarker::Spelling : DocumentMarker::Grammar);
    2606                
     2614                if (markMisspelling)
     2615                    document()->addMarker(badRangeToMark.get(), DocumentMarker::Spelling);
     2616                else
     2617                    document()->addMarker(badRangeToMark.get(), DocumentMarker::Grammar, [grammarDetail objectForKey:NSGrammarUserDescription]);
     2618
    26072619                startIndex = badNSRangeToMark.location + badNSRangeToMark.length;
    26082620            }
  • trunk/WebCore/dom/Document.cpp

    r17494 r17508  
    26652665}
    26662666
    2667 void Document::addMarker(Range *range, DocumentMarker::MarkerType type)
     2667void Document::addMarker(Range *range, DocumentMarker::MarkerType type, String description)
    26682668{
    26692669    // Use a TextIterator to visit the potentially multiple nodes the range covers.
     
    26712671        RefPtr<Range> textPiece = markedText.range();
    26722672        int exception = 0;
    2673         DocumentMarker marker = {type, textPiece->startOffset(exception), textPiece->endOffset(exception)};
     2673        DocumentMarker marker = {type, textPiece->startOffset(exception), textPiece->endOffset(exception), description};
    26742674        addMarker(textPiece->startContainer(exception), marker);
    26752675    }
     
    28582858}
    28592859
     2860DocumentMarker* Document::markerContainingPoint(const IntPoint& point, DocumentMarker::MarkerType markerType)
     2861{
     2862    // outer loop: process each node that contains any markers
     2863    MarkerMap::iterator end = m_markers.end();
     2864    for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != end; ++nodeIterator) {
     2865        // inner loop; process each marker in this node
     2866        MarkerMapVectorPair* vectorPair = nodeIterator->second;
     2867        Vector<DocumentMarker>& markers = vectorPair->first;
     2868        Vector<IntRect>& rects = vectorPair->second;
     2869        ASSERT(markers.size() == rects.size());
     2870        unsigned markerCount = markers.size();
     2871        for (unsigned markerIndex = 0; markerIndex < markerCount; ++markerIndex) {
     2872            DocumentMarker& marker = markers[markerIndex];
     2873           
     2874            // skip marker that is wrong type
     2875            if (marker.type != markerType && markerType != DocumentMarker::AllMarkers)
     2876                continue;
     2877           
     2878            IntRect& r = rects[markerIndex];
     2879           
     2880            // skip placeholder rects
     2881            if (r == placeholderRectForMarker())
     2882                continue;
     2883           
     2884            if (r.contains(point))
     2885                return &marker;
     2886        }
     2887    }
     2888   
     2889    return 0;
     2890}
     2891
    28602892Vector<DocumentMarker> Document::markersForNode(Node* node)
    28612893{
  • trunk/WebCore/dom/Document.h

    r17431 r17508  
    531531    String queryCommandValue(const String& command);
    532532   
    533     void addMarker(Range*, DocumentMarker::MarkerType);
     533    void addMarker(Range*, DocumentMarker::MarkerType, String description = String());
    534534    void addMarker(Node*, DocumentMarker);
    535535    void copyMarkers(Node *srcNode, unsigned startOffset, int length, Node *dstNode, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
     
    543543    void shiftMarkers(Node*, unsigned startOffset, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
    544544
     545    DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
    545546    Vector<DocumentMarker> markersForNode(Node*);
    546547    Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers);
  • trunk/WebCore/dom/DocumentMarker.h

    r17345 r17508  
    2424#define DOM_DocumentMarker_h
    2525
     26#include "PlatformString.h"
     27
    2628namespace WebCore {
     29    class String;
    2730
    28 // A range of a node within a document that is "marked", such as being misspelled
     31// A range of a node within a document that is "marked", such as the range of a misspelled word.
     32// It optionally includes a description that could be displayed in the user interface.
    2933struct DocumentMarker {
    3034
     
    3943    unsigned startOffset;
    4044    unsigned endOffset;
     45    String description;
    4146
    4247    bool operator==(const DocumentMarker& o) const
  • trunk/WebCore/rendering/HitTestResult.cpp

    r17501 r17508  
    119119String HitTestResult::spellingToolTip() const
    120120{
    121     // Return the tool tip string associated with this point
    122     // FIXME: At the moment this returns the same hardwired string for all bad grammar rects. This needs to
    123     // instead return an instance-specific string that was stashed away when the bad grammar was discovered.
    124     // Checking it in now just to modularize the work a little.
    125     Vector<IntRect> rects = m_innerNonSharedNode->document()->renderedRectsForMarkers(DocumentMarker::Grammar);
    126     unsigned count = rects.size();
    127     for (unsigned index = 0; index < count; ++index)
    128         if (rects[index].contains(m_point))
    129             return "Questionable grammar!";
    130 
     121    // Return the tool tip string associated with this point, if any. Only markers associated with bad grammar
     122    // currently supply strings, but maybe someday markers associated with misspelled words will also.
     123    DocumentMarker* marker = m_innerNonSharedNode->document()->markerContainingPoint(m_point, DocumentMarker::Grammar);
     124    if (marker)
     125        return marker->description;
     126   
    131127    return String();
    132128}
Note: See TracChangeset for help on using the changeset viewer.