Changeset 171016 in webkit


Ignore:
Timestamp:
Jul 11, 2014, 4:54:55 PM (11 years ago)
Author:
beidson@apple.com
Message:

Phone numbers that span two lines are not detected.
<rdar://problem/17601146> and https://bugs.webkit.org/show_bug.cgi?id=134808

Reviewed by Tim Horton.

  • editing/Editor.cpp:

(WebCore::Editor::scanSelectionForTelephoneNumbers): After scanning a range from the TextIterator,

create an "edge range" window around the end of the TextIterator range, and scan it.
Also make sure to not accumulate duplicate ranges that might have showed up in both the
TextIterator range and the edge window range.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r171015 r171016  
     12014-07-11  Brady Eidson  <beidson@apple.com>
     2
     3        Phone numbers that span two lines are not detected.
     4        <rdar://problem/17601146> and https://bugs.webkit.org/show_bug.cgi?id=134808
     5
     6        Reviewed by Tim Horton.
     7
     8        * editing/Editor.cpp:
     9        (WebCore::Editor::scanSelectionForTelephoneNumbers): After scanning a range from the TextIterator,
     10            create an "edge range" window around the end of the TextIterator range, and scan it.
     11            Also make sure to not accumulate duplicate ranges that might have showed up in both the
     12            TextIterator range and the edge window range.
     13
    1142014-07-11  Enrica Casucci  <enrica@apple.com>
    215
  • trunk/Source/WebCore/editing/Editor.cpp

    r170296 r171016  
    33703370        return;
    33713371    }
     3372    RefPtr<Range> selectedRange = frameSelection.toNormalizedRange();
    33723373
    33733374    // Extend the range a few characters in each direction to detect incompletely selected phone numbers.
     
    33853386    RefPtr<Range> extendedRange = extendedSelection.toNormalizedRange();
    33863387
    3387     // FIXME: This won't work if a phone number spans multiple chunks of text from the perspective of the TextIterator
    3388     // (By a style change, image, line break, etc.)
    3389     // One idea to handle this would be a model like text search that uses a rotating window.
    33903388    for (TextIterator textChunk(extendedRange.get()); !textChunk.atEnd(); textChunk.advance()) {
    3391         // TextIterator is supposed to never returns a Range that spans multiple Nodes.
    3392         ASSERT(textChunk.range()->startContainer() == textChunk.range()->endContainer());
    3393 
    3394         scanRangeForTelephoneNumbers(*textChunk.range(), textChunk.text(), markedRanges);
     3389        Vector<RefPtr<Range>> markedChunkRanges;
     3390        Vector<RefPtr<Range>> markedEdgeRanges;
     3391
     3392        // Scan the text iterator range.
     3393        RefPtr<Range> range = textChunk.range();
     3394        scanRangeForTelephoneNumbers(*range, textChunk.text(), markedChunkRanges);
     3395
     3396        // If this text iterator range's end position is before the end of the full range,
     3397        // then scan a window that is a bit before and a bit after this text iterator range.
     3398        RefPtr<Range> edgeRange;
     3399        if (range->endPosition() < extendedRange->endPosition()) {
     3400            Position endPosition = range->endPosition();
     3401            Position startPosition = endPosition;
     3402            for (int i = 0; i < charactersToExtend; ++i) {
     3403                startPosition = startPosition.previous(Character);
     3404                endPosition = endPosition.next(Character);
     3405            }
     3406
     3407            edgeRange = Range::create(range->ownerDocument(), startPosition, endPosition);
     3408            scanRangeForTelephoneNumbers(*edgeRange, plainText(edgeRange.get()), markedEdgeRanges);
     3409        }
     3410
     3411        // Add both of these sets of ranges to the full set of marked ranges, double checking to
     3412        // make sure we don't end up with two equivalent ranges in the full set.
     3413        for (auto& chunkRange : markedChunkRanges) {
     3414            bool matchesEdgeRange = false;
     3415            for (auto& edgeRange : markedEdgeRanges) {
     3416                if (areRangesEqual(chunkRange.get(), edgeRange.get())) {
     3417                    matchesEdgeRange = true;
     3418                    break;
     3419                }
     3420            }
     3421
     3422            if (!matchesEdgeRange)
     3423                markedRanges.append(chunkRange);
     3424        }
     3425
     3426        for (auto& range : markedEdgeRanges)
     3427            markedRanges.append(range);
     3428
     3429        // If the edge range's end position is past the end position of the original range, we're done scanning.
     3430        if (edgeRange && edgeRange->endPosition() >= extendedRange->endPosition())
     3431            break;
    33953432    }
    33963433
    33973434    // Only consider ranges with a detected telephone number if they overlap with the actual selection range.
    33983435    Vector<RefPtr<Range>> extendedMarkedRanges;
    3399     RefPtr<Range> selectedRange = frameSelection.toNormalizedRange();
    34003436    for (auto& range : markedRanges) {
    34013437        if (rangesOverlap(range.get(), selectedRange.get()))
Note: See TracChangeset for help on using the changeset viewer.