Changeset 21270 in webkit


Ignore:
Timestamp:
May 4, 2007 9:08:29 PM (17 years ago)
Author:
sfalken
Message:

Reviewed by Oliver.

Use TextBreakIterator for sentence breaking instead of TextBoundaries.

  • WebCore.xcodeproj/project.pbxproj: Added TextBreakIeratorInternalICUMac.mm
  • editing/visible_units.cpp: (WebCore::startSentenceBoundary): Call TextBreakIterator instead of TextBoundaries. (WebCore::endSentenceBoundary): Call TextBreakIterator instead of TextBoundaries. (WebCore::previousSentencePositionBoundary): Call TextBreakIterator instead of TextBoundaries. (WebCore::nextSentencePositionBoundary): Call TextBreakIterator instead of TextBoundaries.
  • platform/TextBoundaries.h: Removed findSentenceBoundary, findNextSentenceFromIndex.
  • platform/TextBreakIterator.h: Added sentenceBreakIterator.
  • platform/TextBreakIteratorICU.cpp: (WebCore::setUpIterator): Add locale parameter (needed to maintain functionality that TextBoundaries code had). (WebCore::characterBreakIterator): Pass en_us for locale (same as old code). (WebCore::wordBreakIterator): Pass en_us for locale (same as old code). (WebCore::lineBreakIterator): Pass en_us for locale (same as old code). (WebCore::sentenceBreakIterator): Added.
  • platform/TextBreakIteratorInternalICU.h: Added.
  • platform/gdk/TemporaryLinkStubs.cpp: Removed findNextSentenceFromIndex, findSentenceBoundary. (WebCore::currentTextBreakLocaleID): Added stub.
  • platform/mac/TextBoundaries.mm: Removed currentTextBreakLocaleID, findSentenceBoundary, findNextSentenceFromIndex.
  • platform/mac/TextBreakIteratorInternalICUMac.mm: Added. (WebCore::currentTextBreakLocaleID): Moved from TextBoundaries.mm
  • platform/qt/TextBoundaries.cpp: Removed findNextSentenceFromIndex, findSentenceBoundary.
Location:
trunk/WebCore
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r21269 r21270  
     12007-05-04  Steve Falkenburg  <sfalken@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        Use TextBreakIterator for sentence breaking instead of TextBoundaries.
     6
     7        * WebCore.xcodeproj/project.pbxproj: Added TextBreakIeratorInternalICUMac.mm
     8        * editing/visible_units.cpp:
     9        (WebCore::startSentenceBoundary): Call TextBreakIterator instead of TextBoundaries.
     10        (WebCore::endSentenceBoundary): Call TextBreakIterator instead of TextBoundaries.
     11        (WebCore::previousSentencePositionBoundary): Call TextBreakIterator instead of TextBoundaries.
     12        (WebCore::nextSentencePositionBoundary): Call TextBreakIterator instead of TextBoundaries.
     13        * platform/TextBoundaries.h: Removed findSentenceBoundary, findNextSentenceFromIndex.
     14        * platform/TextBreakIterator.h: Added sentenceBreakIterator.
     15        * platform/TextBreakIteratorICU.cpp:
     16        (WebCore::setUpIterator): Add locale parameter (needed to maintain functionality that TextBoundaries code had).
     17        (WebCore::characterBreakIterator): Pass en_us for locale (same as old code).
     18        (WebCore::wordBreakIterator): Pass en_us for locale (same as old code).
     19        (WebCore::lineBreakIterator): Pass en_us for locale (same as old code).
     20        (WebCore::sentenceBreakIterator): Added.
     21        * platform/TextBreakIteratorInternalICU.h: Added.
     22        * platform/gdk/TemporaryLinkStubs.cpp: Removed findNextSentenceFromIndex, findSentenceBoundary.
     23        (WebCore::currentTextBreakLocaleID): Added stub.
     24        * platform/mac/TextBoundaries.mm: Removed currentTextBreakLocaleID, findSentenceBoundary, findNextSentenceFromIndex.
     25        * platform/mac/TextBreakIteratorInternalICUMac.mm: Added.
     26        (WebCore::currentTextBreakLocaleID): Moved from TextBoundaries.mm
     27        * platform/qt/TextBoundaries.cpp: Removed findNextSentenceFromIndex, findSentenceBoundary.
     28
    1292007-05-04  Adele Peterson  <adele@apple.com>
    230
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r21197 r21270  
    22622262                AAC8DAB10AA1002000DC0907 /* SVGMetadataElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAC8DAAF0AA1002000DC0907 /* SVGMetadataElement.cpp */; };
    22632263                AAC8DAB20AA1002000DC0907 /* SVGMetadataElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AAC8DAB00AA1002000DC0907 /* SVGMetadataElement.h */; };
     2264                AACF144D0BEC1EF000827982 /* TextBreakIteratorInternalICUMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = AACF144C0BEC1EF000827982 /* TextBreakIteratorInternalICUMac.mm */; };
    22642265                AACF7C4E0B42EE6000080BD8 /* SVGParserUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = AACF7C4C0B42EE6000080BD8 /* SVGParserUtilities.h */; };
    22652266                AACF7C4F0B42EE6000080BD8 /* SVGParserUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AACF7C4D0B42EE6000080BD8 /* SVGParserUtilities.cpp */; };
     
    53425343                AAC8DAAF0AA1002000DC0907 /* SVGMetadataElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGMetadataElement.cpp; sourceTree = "<group>"; };
    53435344                AAC8DAB00AA1002000DC0907 /* SVGMetadataElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGMetadataElement.h; sourceTree = "<group>"; };
     5345                AACF144C0BEC1EF000827982 /* TextBreakIteratorInternalICUMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = TextBreakIteratorInternalICUMac.mm; sourceTree = "<group>"; };
    53445346                AACF7C4C0B42EE6000080BD8 /* SVGParserUtilities.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGParserUtilities.h; sourceTree = "<group>"; };
    53455347                AACF7C4D0B42EE6000080BD8 /* SVGParserUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGParserUtilities.cpp; sourceTree = "<group>"; };
     
    68906892                        isa = PBXGroup;
    68916893                        children = (
     6894                                AACF144C0BEC1EF000827982 /* TextBreakIteratorInternalICUMac.mm */,
    68926895                                A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */,
    68936896                                A795463D0B5C4C80007B438F /* DragDataMac.mm */,
     
    1262212625                                2D9066060BE141D400956998 /* LayoutState.cpp in Sources */,
    1262312626                                4A8C96EB0BE69032004EEFF0 /* SelectionControllerMac.mm in Sources */,
     12627                                AACF144D0BEC1EF000827982 /* TextBreakIteratorInternalICUMac.mm in Sources */,
    1262412628                        );
    1262512629                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/editing/visible_units.cpp

    r21221 r21270  
    3333#include "RenderLayer.h"
    3434#include "TextBoundaries.h"
     35#include "TextBreakIterator.h"
    3536#include "TextIterator.h"
    3637#include "htmlediting.h"
     
    515516static unsigned startSentenceBoundary(const UChar* characters, unsigned length)
    516517{
    517     int start, end;
    518     findSentenceBoundary(characters, length, length, &start, &end);
    519     return start;
     518    TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     519    return textBreakPreceding(iterator, length);
    520520}
    521521
     
    527527static unsigned endSentenceBoundary(const UChar* characters, unsigned length)
    528528{
    529     int start, end;
    530     findSentenceBoundary(characters, length, 0, &start, &end);
    531     return end;
     529    TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     530    int start = textBreakPreceding(iterator, length);
     531    return textBreakFollowing(iterator, start);
    532532}
    533533
     
    539539static unsigned previousSentencePositionBoundary(const UChar* characters, unsigned length)
    540540{
    541     return findNextSentenceFromIndex(characters, length, length, false);
     541    TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     542    return textBreakPreceding(iterator, length);
    542543}
    543544
     
    549550static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned length)
    550551{
    551     return findNextSentenceFromIndex(characters, length, 0, true);
     552    TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
     553    return textBreakFollowing(iterator, 0);
    552554}
    553555
  • trunk/WebCore/platform/TextBoundaries.h

    r18712 r21270  
    3434    int findNextWordFromIndex(const UChar*, int len, int position, bool forward);
    3535
    36     void findSentenceBoundary(const UChar*, int len, int position, int* start, int* end);
    37     int findNextSentenceFromIndex(const UChar*, int len, int position, bool forward);
    38 
    3936}
    4037
  • trunk/WebCore/platform/TextBreakIterator.h

    r19762 r21270  
    3333    TextBreakIterator* wordBreakIterator(const UChar*, int length);
    3434    TextBreakIterator* lineBreakIterator(const UChar*, int length);
     35    TextBreakIterator* sentenceBreakIterator(const UChar*, int length);
    3536
    3637    int textBreakFirst(TextBreakIterator*);
  • trunk/WebCore/platform/TextBreakIteratorICU.cpp

    r19762 r21270  
    2323#include "TextBreakIterator.h"
    2424
     25#include "TextBreakIteratorInternalICU.h"
     26
    2527#include <unicode/ubrk.h>
    2628
     
    2830
    2931static TextBreakIterator* setUpIterator(bool& createdIterator, TextBreakIterator*& iterator,
    30     UBreakIteratorType type, const UChar* string, int length)
     32    UBreakIteratorType type, const UChar* string, int length, const char* locale)
    3133{
    3234    if (!string)
     
    3941        // break iterators, though!
    4042        UErrorCode openStatus = U_ZERO_ERROR;
    41         iterator = static_cast<TextBreakIterator*>(ubrk_open(type, "en_us", 0, 0, &openStatus));
     43        iterator = static_cast<TextBreakIterator*>(ubrk_open(type, locale, 0, 0, &openStatus));
    4244        createdIterator = true;
    4345    }
     
    5860    static TextBreakIterator* staticCharacterBreakIterator;
    5961    return setUpIterator(createdCharacterBreakIterator,
    60         staticCharacterBreakIterator, UBRK_CHARACTER, string, length);
     62        staticCharacterBreakIterator, UBRK_CHARACTER, string, length, "en_us");
    6163}
    6264
     
    6668    static TextBreakIterator* staticWordBreakIterator;
    6769    return setUpIterator(createdWordBreakIterator,
    68         staticWordBreakIterator, UBRK_WORD, string, length);
     70        staticWordBreakIterator, UBRK_WORD, string, length, "en_us");
    6971}
    7072
     
    7476    static TextBreakIterator* staticLineBreakIterator;
    7577    return setUpIterator(createdLineBreakIterator,
    76         staticLineBreakIterator, UBRK_LINE, string, length);
     78        staticLineBreakIterator, UBRK_LINE, string, length, "en_us");
     79}
     80
     81TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
     82{
     83    static bool createdSentenceBreakIterator = false;
     84    static TextBreakIterator* staticSentenceBreakIterator;
     85    return setUpIterator(createdSentenceBreakIterator,
     86        staticSentenceBreakIterator, UBRK_SENTENCE, string, length, currentTextBreakLocaleID());
    7787}
    7888
  • trunk/WebCore/platform/gdk/TemporaryLinkStubs.cpp

    r21089 r21270  
    9999void Widget::invalidateRect(const IntRect&) { notImplementedGdk(); }
    100100
    101 int WebCore::findNextSentenceFromIndex(UChar const*, int, int, bool) { notImplementedGdk(); return 0; }
    102 void WebCore::findSentenceBoundary(UChar const*, int, int, int*, int*) { notImplementedGdk(); }
    103101int WebCore::findNextWordFromIndex(UChar const*, int, int, bool) { notImplementedGdk(); return 0; }
    104102void WebCore::findWordBoundary(UChar const* str, int len, int position, int* start, int* end) {*start = position; *end = position; }
     103const char* WebCore::currentTextBreakLocaleID() { notImplementedGdk(); return "en_us"; }
    105104
    106105void ChromeClientGdk::chromeDestroyed() { notImplementedGdk(); }
  • trunk/WebCore/platform/mac/TextBoundaries.mm

    r15438 r21270  
    2727#import "TextBoundaries.h"
    2828
    29 #import <unicode/ubrk.h>
    30 
    3129namespace WebCore {
    3230
     
    5452}
    5553
    56 // This code was swiped from the CarbonCore UnicodeUtilities. One change from that is to use the empty
    57 // string instead of the "old locale model" as the ultimate fallback. This change is per the UnicodeUtilities
    58 // engineer.
    59 //
    60 // NOTE: this abviously could be fairly expensive to do.  If it turns out to be a bottleneck, it might
    61 // help to instead put a call in the iteratory initializer to set the current text break locale.  Unfortunately,
    62 // we can not cache it across calls to our API since the result can change without our knowing (AFAIK
    63 // there are no notifiers for AppleTextBreakLocale and/or AppleLanguages changes).
    64 static char* currentTextBreakLocaleID()
    65 {
    66     const int localeStringLength = 32;
    67     static char localeStringBuffer[localeStringLength] = { 0 };
    68     char* localeString = &localeStringBuffer[0];
    69    
    70     // Empty string means "root locale", which what we use if we can't use a pref.
    71    
    72     // We get the parts string from AppleTextBreakLocale pref.
    73     // If that fails then look for the first language in the AppleLanguages pref.
    74     CFStringRef prefLocaleStr = (CFStringRef)CFPreferencesCopyValue(CFSTR("AppleTextBreakLocale"),
    75         kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
    76     if (!prefLocaleStr) {
    77         CFArrayRef appleLangArr = (CFArrayRef)CFPreferencesCopyValue(CFSTR("AppleLanguages"),
    78             kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
    79         if (appleLangArr)  {
    80             // Take the topmost language. Retain so that we can blindly release later.                                                                                                   
    81             prefLocaleStr = (CFStringRef)CFArrayGetValueAtIndex(appleLangArr, 0);
    82             if (prefLocaleStr)
    83                 CFRetain(prefLocaleStr);
    84             CFRelease(appleLangArr);
    85         }
    86     }
    87    
    88     if (prefLocaleStr) {
    89         // Canonicalize pref string in case it is not in the canonical format. This call is only available on Tiger and newer.
    90         CFStringRef canonLocaleCFStr = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, prefLocaleStr);
    91         if (canonLocaleCFStr) {
    92             CFStringGetCString(canonLocaleCFStr, localeString, localeStringLength, kCFStringEncodingASCII);
    93             CFRelease(canonLocaleCFStr);
    94         }
    95         CFRelease(prefLocaleStr);
    96     }
    97    
    98     return localeString;
    9954}
    100 
    101 void findSentenceBoundary(const UChar* chars, int len, int position, int* start, int* end)
    102 {
    103     int startPos = 0;
    104     int endPos = 0;
    105 
    106     UErrorCode status = U_ZERO_ERROR;
    107     UBreakIterator* boundary = ubrk_open(UBRK_SENTENCE, currentTextBreakLocaleID(), chars, len, &status);
    108     if (boundary && U_SUCCESS(status)) {
    109         startPos = ubrk_preceding(boundary, position);
    110         if (startPos == UBRK_DONE) {
    111             startPos = 0;
    112         }
    113         endPos = ubrk_following(boundary, startPos);
    114         if (endPos == UBRK_DONE)
    115             endPos = len;
    116 
    117         ubrk_close(boundary);
    118     }
    119    
    120     *start = startPos;
    121     *end = endPos;
    122 }
    123 
    124 int findNextSentenceFromIndex(const UChar* chars, int len, int position, bool forward)
    125 {
    126     int pos = 0;
    127    
    128     UErrorCode status = U_ZERO_ERROR;
    129     UBreakIterator* boundary = ubrk_open(UBRK_SENTENCE, currentTextBreakLocaleID(), chars, len, &status);
    130     if (boundary && U_SUCCESS(status)) {
    131         if (forward) {
    132             pos = ubrk_following(boundary, position);
    133             if (pos == UBRK_DONE)
    134                 pos = len;
    135         } else {
    136             pos = ubrk_preceding(boundary, position);
    137             if (pos == UBRK_DONE)
    138                 pos = 0;
    139         }
    140         ubrk_close(boundary);
    141     }
    142        
    143     return pos;
    144 }
    145 
    146 }
  • trunk/WebCore/platform/qt/TextBoundaries.cpp

    r18901 r21270  
    4444{
    4545
    46 int findNextSentenceFromIndex(UChar const* buffer, int len, int position, bool forward)
    47 {
    48     QString str(reinterpret_cast<QChar const*>(buffer), len);
    49     notImplemented();
    50     return 0;
    51 }
    52 
    53 void findSentenceBoundary(UChar const* buffer, int len, int position, int* start, int* end)
    54 {
    55     QString str(reinterpret_cast<QChar const*>(buffer), len);
    56     notImplemented();
    57 }
    58 
    5946int findNextWordFromIndex(UChar const* buffer, int len, int position, bool forward)
    6047{
Note: See TracChangeset for help on using the changeset viewer.