Reviewed by Darin
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Dec 2006 23:32:56 +0000 (23:32 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Dec 2006 23:32:56 +0000 (23:32 +0000)
        Move subrange helper function from spellchecking code to TextIterator

        * editing/TextIterator.h:
        added TextIterator::subrange
        * editing/TextIterator.cpp:
        (WebCore::CharacterIterator::advance):
        early return if count is <= 0; assert that it's not < 0
        (WebCore::TextIterator::subrange):
        new function, moved from FrameMac.mmm

        * bridge/mac/FrameMac.mm:
        moved subrange() function to TextIterator
        (WebCore::FrameMac::advanceToNextMisspelling):
        use TextIterator::subrange
        (WebCore::markAllMisspellingsInRange):
        ditto
        (WebCore::markAllBadGrammarInRange):
        ditto

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17980 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bridge/mac/FrameMac.mm
WebCore/editing/TextIterator.cpp
WebCore/editing/TextIterator.h

index 0b3280b923403b9c32b0b95e2ce8e40a602d4ad1..af15ed7187026e9f77efbadd1c5d4bf8f842a67b 100644 (file)
@@ -1,3 +1,26 @@
+2006-12-01  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Darin
+        
+        Move subrange helper function from spellchecking code to TextIterator
+
+        * editing/TextIterator.h:
+        added TextIterator::subrange
+        * editing/TextIterator.cpp:
+        (WebCore::CharacterIterator::advance):
+        early return if count is <= 0; assert that it's not < 0
+        (WebCore::TextIterator::subrange):
+        new function, moved from FrameMac.mmm
+
+        * bridge/mac/FrameMac.mm:
+        moved subrange() function to TextIterator
+        (WebCore::FrameMac::advanceToNextMisspelling):
+        use TextIterator::subrange
+        (WebCore::markAllMisspellingsInRange):
+        ditto
+        (WebCore::markAllBadGrammarInRange):
+        ditto
+
 2006-12-01  Darin Adler  <darin@apple.com>
 
         Reviewed by Mitz.
index 60d5029e6130f29a68869403e86a082b288bb2a2..5b2cd48e6efd2e18d25d0a20c21b2cf106740a1a 100644 (file)
@@ -559,20 +559,6 @@ static NSString *findFirstBadGrammarInRange(NSSpellChecker *checker, int tag, Ra
     
 #endif /* not BUILDING_ON_TIGER */
 
-static PassRefPtr<Range> subrange(Range* entireRange, unsigned offset, unsigned length)
-{
-    ExceptionCode ec = 0;
-    PassRefPtr<Range> result(entireRange);
-    CharacterIterator chars(entireRange);
-    chars.advance(offset);
-    result->setStart(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
-    ASSERT(ec == 0);
-    chars.advance(length);
-    result->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
-    ASSERT(ec == 0);
-    return result;
-}
-
 void FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
 {
     ExceptionCode ec = 0;
@@ -694,7 +680,7 @@ void FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
         ASSERT(detailNSRange.location != NSNotFound && detailNSRange.length > 0);
         
         // FIXME 4859190: This gets confused with doubled punctuation at the end of a paragraph
-        RefPtr<Range> badGrammarRange = subrange(grammarSearchRange.get(), grammarPhraseOffset + detailNSRange.location, detailNSRange.length);
+        RefPtr<Range> badGrammarRange = TextIterator::subrange(grammarSearchRange.get(), grammarPhraseOffset + detailNSRange.location, detailNSRange.length);
         selectionController()->setSelection(Selection(badGrammarRange.get(), SEL_DEFAULT_AFFINITY));
         revealSelection();
         
@@ -705,7 +691,7 @@ void FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
         // We found a misspelling, but not any earlier bad grammar. Select the misspelling, update the spelling panel, and store
         // a marker so we draw the red squiggle later.
         
-        RefPtr<Range> misspellingRange = subrange(spellingSearchRange.get(), misspellingOffset, [misspelledWord length]);
+        RefPtr<Range> misspellingRange = TextIterator::subrange(spellingSearchRange.get(), misspellingOffset, [misspelledWord length]);
         selectionController()->setSelection(Selection(misspellingRange.get(), DOWNSTREAM));
         revealSelection();
         
@@ -1259,7 +1245,7 @@ static void markAllMisspellingsInRange(NSSpellChecker *checker, int tag, Range*
             
             if (misspelledWord) {
                 // Compute range of misspelled word
-                RefPtr<Range> misspellingRange = subrange(searchRange, offsetFromStartOfSearchRange + misspellingNSRange.location, [misspelledWord length]);
+                RefPtr<Range> misspellingRange = TextIterator::subrange(searchRange, offsetFromStartOfSearchRange + misspellingNSRange.location, [misspelledWord length]);
                 
                 // Store marker for misspelled word
                 misspellingRange->startContainer(ec)->document()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
@@ -1317,7 +1303,7 @@ static void markAllBadGrammarInRange(NSSpellChecker *checker, int tag, Range* se
                 continue;
             
             // This detail is in the search range, so we need to mark it.
-            RefPtr<Range> badGrammarRange = subrange(searchRange, badGrammarPhraseNSRange.location - searchRangeStartOffset + detailNSRange.location, detailNSRange.length);
+            RefPtr<Range> badGrammarRange = TextIterator::subrange(searchRange, badGrammarPhraseNSRange.location - searchRangeStartOffset + detailNSRange.location, detailNSRange.length);
             ExceptionCode ec = 0;
             badGrammarRange->startContainer(ec)->document()->addMarker(badGrammarRange.get(), DocumentMarker::Grammar, [detail objectForKey:NSGrammarUserDescription]);
             ASSERT(ec == 0);
index 756b5c3023020431db14a76d3334931716630d05..45056e098c358311ae81ed1c8d0c8c1e49cc3be1 100644 (file)
@@ -803,6 +803,11 @@ PassRefPtr<Range> CharacterIterator::range() const
 
 void CharacterIterator::advance(int count)
 {
+    if (count <= 0) {
+        ASSERT(count == 0);
+        return;
+    }
+    
     m_atBreak = false;
 
     // easy if there is enough left in the current m_textIterator run
@@ -1023,6 +1028,22 @@ int TextIterator::rangeLength(const Range *r)
     return length;
 }
 
+PassRefPtr<Range> TextIterator::subrange(Range* entireRange, int characterOffset, int characterCount)
+{
+    ExceptionCode ec = 0;
+    
+    PassRefPtr<Range> result(entireRange);
+    CharacterIterator chars(entireRange);
+    chars.advance(characterOffset);
+    result->setStart(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
+    ASSERT(ec == 0);
+    chars.advance(characterCount);
+    result->setEnd(chars.range()->startContainer(ec), chars.range()->startOffset(ec), ec);
+    ASSERT(ec == 0);
+    
+    return result;
+}
+
 PassRefPtr<Range> TextIterator::rangeFromLocationAndLength(Element *scope, int rangeLocation, int rangeLength)
 {
     RefPtr<Range> resultRange = scope->document()->createRange();
index f11cc0cedabee1295b8c922b80f935f5c1545d8f..030edbc7ce04737dfaddc56c3ccb8b80740aebe2 100644 (file)
@@ -72,6 +72,7 @@ public:
      
     static int rangeLength(const Range *r);
     static PassRefPtr<Range> rangeFromLocationAndLength(Element *scope, int rangeLocation, int rangeLength);
+    static PassRefPtr<Range> subrange(Range* entireRange, int characterOffset, int characterCount);
     
 private:
     void exitNode();