Changeset 17508 in webkit
- Timestamp:
- Oct 31, 2006, 6:49:02 PM (18 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r17506 r17508 1 2006-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 1 33 2006-10-31 Geoffrey Garen <ggaren@apple.com> 2 34 -
trunk/WebCore/bridge/mac/FrameMac.mm
r17504 r17508 635 635 int searchEndAfterWrapOffset = it.range()->endOffset(exception); 636 636 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 637 641 while (1) { 638 642 if (!it.atEnd()) { // we may be starting at the end of the doc, and already by atEnd … … 708 712 selectionController()->setSelection(Selection(badRangeToMark.get(), DOWNSTREAM)); 709 713 revealSelection(); 710 // Mark misspelling in document.711 document()->addMarker(badRangeToMark.get(), markMisspelling ? DocumentMarker::Spelling : DocumentMarker::Grammar);712 714 713 if (markMisspelling) 715 if (markMisspelling) { 714 716 [checker updateSpellingPanelWithMisspelledWord:[chunk substringWithRange:misspellingNSRange]]; 717 document()->addMarker(badRangeToMark.get(), DocumentMarker::Spelling); 718 } 715 719 #ifndef BUILDING_ON_TIGER 716 else 720 else { 717 721 [checker updateSpellingPanelWithGrammarString:[chunk substringWithRange:badGrammarNSRange] detail:grammarDetail]; 722 document()->addMarker(badRangeToMark.get(), DocumentMarker::Grammar, [grammarDetail objectForKey:NSGrammarUserDescription]); 723 } 718 724 #endif 719 725 … … 2531 2537 2532 2538 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. 2533 2543 2534 2544 while (!it.atEnd()) { // we may be starting at the end of the doc, and already by atEnd … … 2602 2612 chars.advance(badNSRangeToMark.length); 2603 2613 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 2607 2619 startIndex = badNSRangeToMark.location + badNSRangeToMark.length; 2608 2620 } -
trunk/WebCore/dom/Document.cpp
r17494 r17508 2665 2665 } 2666 2666 2667 void Document::addMarker(Range *range, DocumentMarker::MarkerType type )2667 void Document::addMarker(Range *range, DocumentMarker::MarkerType type, String description) 2668 2668 { 2669 2669 // Use a TextIterator to visit the potentially multiple nodes the range covers. … … 2671 2671 RefPtr<Range> textPiece = markedText.range(); 2672 2672 int exception = 0; 2673 DocumentMarker marker = {type, textPiece->startOffset(exception), textPiece->endOffset(exception) };2673 DocumentMarker marker = {type, textPiece->startOffset(exception), textPiece->endOffset(exception), description}; 2674 2674 addMarker(textPiece->startContainer(exception), marker); 2675 2675 } … … 2858 2858 } 2859 2859 2860 DocumentMarker* 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 ▮ 2886 } 2887 } 2888 2889 return 0; 2890 } 2891 2860 2892 Vector<DocumentMarker> Document::markersForNode(Node* node) 2861 2893 { -
trunk/WebCore/dom/Document.h
r17431 r17508 531 531 String queryCommandValue(const String& command); 532 532 533 void addMarker(Range*, DocumentMarker::MarkerType );533 void addMarker(Range*, DocumentMarker::MarkerType, String description = String()); 534 534 void addMarker(Node*, DocumentMarker); 535 535 void copyMarkers(Node *srcNode, unsigned startOffset, int length, Node *dstNode, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers); … … 543 543 void shiftMarkers(Node*, unsigned startOffset, int delta, DocumentMarker::MarkerType = DocumentMarker::AllMarkers); 544 544 545 DocumentMarker* markerContainingPoint(const IntPoint&, DocumentMarker::MarkerType = DocumentMarker::AllMarkers); 545 546 Vector<DocumentMarker> markersForNode(Node*); 546 547 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType = DocumentMarker::AllMarkers); -
trunk/WebCore/dom/DocumentMarker.h
r17345 r17508 24 24 #define DOM_DocumentMarker_h 25 25 26 #include "PlatformString.h" 27 26 28 namespace WebCore { 29 class String; 27 30 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. 29 33 struct DocumentMarker { 30 34 … … 39 43 unsigned startOffset; 40 44 unsigned endOffset; 45 String description; 41 46 42 47 bool operator==(const DocumentMarker& o) const -
trunk/WebCore/rendering/HitTestResult.cpp
r17501 r17508 119 119 String HitTestResult::spellingToolTip() const 120 120 { 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 131 127 return String(); 132 128 }
Note:
See TracChangeset
for help on using the changeset viewer.