Changeset 20967 in webkit


Ignore:
Timestamp:
Apr 19, 2007 10:02:19 PM (17 years ago)
Author:
hyatt
Message:

Fix for bug 13208, implement word-break. This patch produces a partial
implementation of word-break. word-break: break-all is implemented. In
addition, a custom value, word-break: break-word is added that is a hybrid
of word-wrap: break-word and word-break: break-all (and more useful than
either).

Reviewed by beth

Added fast/text/word-break.html

  • css/CSSComputedStyleDeclaration.cpp: (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
  • css/CSSPropertyNames.in:
  • css/CSSValueKeywords.in:
  • css/cssparser.cpp: (WebCore::CSSParser::parseValue):
  • css/cssstyleselector.cpp: (WebCore::CSSStyleSelector::applyProperty):
  • rendering/RenderStyle.cpp: (WebCore::StyleRareInheritedData::StyleRareInheritedData): (WebCore::StyleRareInheritedData::operator==): (WebCore::RenderStyle::diff):
  • rendering/RenderStyle.h: (WebCore::): (WebCore::RenderStyle::breakWords): (WebCore::RenderStyle::wordBreak): (WebCore::RenderStyle::setWordBreak): (WebCore::RenderStyle::initialWordBreak): (WebCore::RenderStyle::initialWordWrap):
  • rendering/RenderText.cpp: (WebCore::RenderText::calcMinMaxWidthInternal):
  • rendering/RenderTextControl.cpp: (WebCore::RenderTextControl::createInnerTextStyle): (WebCore::RenderTextControl::calcHeight):
  • rendering/bidi.cpp: (WebCore::RenderBlock::findNextLineBreak):
Location:
trunk
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r20966 r20967  
     12007-04-19  David Hyatt  <hyatt@apple.com>
     2
     3        Fix for bug 13208, implement word-break.  This patch produces a partial
     4        implementation of word-break.  word-break: break-all is implemented.  In
     5        addition, a custom value, word-break: break-word is added that is a hybrid
     6        of word-wrap: break-word and word-break: break-all (and more useful than
     7        either).
     8
     9        Reviewed by beth
     10
     11        Added fast/text/word-break.html
     12
     13        * css/CSSComputedStyleDeclaration.cpp:
     14        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
     15        * css/CSSPropertyNames.in:
     16        * css/CSSValueKeywords.in:
     17        * css/cssparser.cpp:
     18        (WebCore::CSSParser::parseValue):
     19        * css/cssstyleselector.cpp:
     20        (WebCore::CSSStyleSelector::applyProperty):
     21        * rendering/RenderStyle.cpp:
     22        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
     23        (WebCore::StyleRareInheritedData::operator==):
     24        (WebCore::RenderStyle::diff):
     25        * rendering/RenderStyle.h:
     26        (WebCore::):
     27        (WebCore::RenderStyle::breakWords):
     28        (WebCore::RenderStyle::wordBreak):
     29        (WebCore::RenderStyle::setWordBreak):
     30        (WebCore::RenderStyle::initialWordBreak):
     31        (WebCore::RenderStyle::initialWordWrap):
     32        * rendering/RenderText.cpp:
     33        (WebCore::RenderText::calcMinMaxWidthInternal):
     34        * rendering/RenderTextControl.cpp:
     35        (WebCore::RenderTextControl::createInnerTextStyle):
     36        (WebCore::RenderTextControl::calcHeight):
     37        * rendering/bidi.cpp:
     38        (WebCore::RenderBlock::findNextLineBreak):
     39
    1402007-04-20  Mark Rowe  <mrowe@apple.com>
    241
  • trunk/WebCore/css/CSSComputedStyleDeclaration.cpp

    r20889 r20967  
    14071407        case CSS_PROP_WIDTH:
    14081408            return new CSSPrimitiveValue(renderer->contentWidth(), CSSPrimitiveValue::CSS_PX);
     1409        case CSS_PROP_WORD_BREAK:
     1410            switch (style->wordBreak()) {
     1411                case NormalWordBreak:
     1412                    return new CSSPrimitiveValue(CSS_VAL_NORMAL);
     1413                case BreakAllWordBreak:
     1414                    return new CSSPrimitiveValue(CSS_VAL_BREAK_ALL);
     1415                case BreakWordBreak:
     1416                    return new CSSPrimitiveValue(CSS_VAL_BREAK_WORD);
     1417            }
    14091418        case CSS_PROP_WORD_SPACING:
    14101419            return new CSSPrimitiveValue(style->wordSpacing(), CSSPrimitiveValue::CSS_PX);
    14111420        case CSS_PROP_WORD_WRAP:
    14121421            switch (style->wordWrap()) {
    1413                 case WBNORMAL:
     1422                case NormalWordWrap:
    14141423                    return new CSSPrimitiveValue(CSS_VAL_NORMAL);
    1415                 case BREAK_WORD:
     1424                case BreakWordWrap:
    14161425                    return new CSSPrimitiveValue(CSS_VAL_BREAK_WORD);
    14171426            }
  • trunk/WebCore/css/CSSPropertyNames.in

    r19862 r20967  
    137137widows
    138138width
     139word-break
    139140word-spacing
    140141word-wrap
  • trunk/WebCore/css/CSSValueKeywords.in

    r20841 r20967  
    462462
    463463#
     464# CSS_PROP_WORD_BREAK
     465#
     466break-all
     467
     468#
    464469# CSS_PROP_WORD_WRAP
    465470#
  • trunk/WebCore/css/cssparser.cpp

    r20889 r20967  
    904904        else
    905905            valid_primitive = validUnit(value, FLength, strict);
     906        break;
     907
     908    case CSS_PROP_WORD_BREAK:          // normal | break-all | break-word (this is a custom extension)
     909        if (id == CSS_VAL_NORMAL || id == CSS_VAL_BREAK_ALL || CSS_VAL_BREAK_WORD)
     910            valid_primitive = true;
    906911        break;
    907912
  • trunk/WebCore/css/cssstyleselector.cpp

    r20889 r20967  
    26642664    }
    26652665
    2666     case CSS_PROP_WORD_WRAP:
    2667     {
     2666    case CSS_PROP_WORD_BREAK: {
     2667        HANDLE_INHERIT_AND_INITIAL(wordBreak, WordBreak)
     2668
     2669        EWordBreak b;
     2670        switch (primitiveValue->getIdent()) {
     2671        case CSS_VAL_BREAK_ALL:
     2672            b = BreakAllWordBreak;
     2673            break;
     2674        case CSS_VAL_BREAK_WORD:
     2675            b = BreakWordBreak;
     2676            break;
     2677        case CSS_VAL_NORMAL:
     2678        default:
     2679            b = NormalWordBreak;
     2680            break;
     2681        }
     2682        style->setWordBreak(b);
     2683        return;
     2684    }
     2685
     2686    case CSS_PROP_WORD_WRAP: {
    26682687        HANDLE_INHERIT_AND_INITIAL(wordWrap, WordWrap)
    2669 
    2670         if(!primitiveValue->getIdent()) return;
    26712688
    26722689        EWordWrap s;
    26732690        switch(primitiveValue->getIdent()) {
    26742691        case CSS_VAL_BREAK_WORD:
    2675             s = BREAK_WORD;
     2692            s = BreakWordWrap;
    26762693            break;
    26772694        case CSS_VAL_NORMAL:
    26782695        default:
    2679             s = WBNORMAL;
    2680             break;
    2681         }
     2696            s = NormalWordWrap;
     2697            break;
     2698        }
     2699
    26822700        style->setWordWrap(s);
    26832701        return;
  • trunk/WebCore/rendering/RenderStyle.cpp

    r19862 r20967  
    525525    , textSecurity(RenderStyle::initialTextSecurity())
    526526    , userModify(READ_ONLY)
    527     , wordWrap(WBNORMAL)
     527    , wordBreak(RenderStyle::initialWordBreak())
     528    , wordWrap(RenderStyle::initialWordWrap())
    528529    , nbspMode(NBNORMAL)
    529530    , khtmlLineBreak(LBNORMAL)
     
    542543    , textSecurity(o.textSecurity)
    543544    , userModify(o.userModify)
     545    , wordBreak(o.wordBreak)
    544546    , wordWrap(o.wordWrap)
    545547    , nbspMode(o.nbspMode)
     
    564566        && textSecurity == o.textSecurity
    565567        && userModify == o.userModify
     568        && wordBreak == o.wordBreak
    566569        && wordWrap == o.wordWrap
    567570        && nbspMode == o.nbspMode
     
    944947        if (rareInheritedData->highlight != other->rareInheritedData->highlight ||
    945948            rareInheritedData->textSizeAdjust != other->rareInheritedData->textSizeAdjust ||
     949            rareInheritedData->wordBreak != other->rareInheritedData->wordBreak ||
    946950            rareInheritedData->wordWrap != other->rareInheritedData->wordWrap ||
    947951            rareInheritedData->nbspMode != other->rareInheritedData->nbspMode ||
  • trunk/WebCore/rendering/RenderStyle.h

    r20889 r20967  
    719719// Word Break Values. Matches WinIE, rather than CSS3
    720720
     721enum EWordBreak {
     722    NormalWordBreak, BreakAllWordBreak, BreakWordBreak
     723};
     724
    721725enum EWordWrap {
    722     WBNORMAL, BREAK_WORD
     726    NormalWordWrap, BreakWordWrap
    723727};
    724728
     
    881885    unsigned textSecurity : 2; // ETextSecurity
    882886    unsigned userModify : 2; // EUserModify (editing)
     887    unsigned wordBreak : 2; // EWordBreak
    883888    unsigned wordWrap : 1; // EWordWrap
    884889    unsigned nbspMode : 1; // ENBSPMode
     
    13731378        return whiteSpace() == PRE_WRAP || khtmlLineBreak() == AFTER_WHITE_SPACE;
    13741379    }
     1380    bool breakWords() const {
     1381        return wordBreak() == BreakWordBreak || wordWrap() == BreakWordWrap;
     1382    }
    13751383
    13761384    const Color & backgroundColor() const { return background->m_color; }
     
    14571465    EMarginCollapse marginTopCollapse() const { return static_cast<EMarginCollapse>(rareNonInheritedData->marginTopCollapse); }
    14581466    EMarginCollapse marginBottomCollapse() const { return static_cast<EMarginCollapse>(rareNonInheritedData->marginBottomCollapse); }
     1467    EWordBreak wordBreak() const { return static_cast<EWordBreak>(rareInheritedData->wordBreak); }
    14591468    EWordWrap wordWrap() const { return static_cast<EWordWrap>(rareInheritedData->wordWrap); }
    14601469    ENBSPMode nbspMode() const { return static_cast<ENBSPMode>(rareInheritedData->nbspMode); }
     
    16981707    void setMarginTopCollapse(EMarginCollapse c) { SET_VAR(rareNonInheritedData, marginTopCollapse, c); }
    16991708    void setMarginBottomCollapse(EMarginCollapse c) { SET_VAR(rareNonInheritedData, marginBottomCollapse, c); }
     1709    void setWordBreak(EWordBreak b) { SET_VAR(rareInheritedData, wordBreak, b); }
    17001710    void setWordWrap(EWordWrap b) { SET_VAR(rareInheritedData, wordWrap, b); }
    17011711    void setNBSPMode(ENBSPMode b) { SET_VAR(rareInheritedData, nbspMode, b); }
     
    18451855    static EMarginCollapse initialMarginTopCollapse() { return MCOLLAPSE; }
    18461856    static EMarginCollapse initialMarginBottomCollapse() { return MCOLLAPSE; }
    1847     static EWordWrap initialWordWrap() { return WBNORMAL; }
     1857    static EWordBreak initialWordBreak() { return NormalWordBreak; }
     1858    static EWordWrap initialWordWrap() { return NormalWordWrap; }
    18481859    static ENBSPMode initialNBSPMode() { return NBNORMAL; }
    18491860    static EKHTMLLineBreak initialKHTMLLineBreak() { return LBNORMAL; }
  • trunk/WebCore/rendering/RenderText.cpp

    r20959 r20967  
    537537    bool breakNBSP = style()->autoWrap() && style()->nbspMode() == SPACE;
    538538
     539    bool breakAll = (style()->wordBreak() == BreakAllWordBreak || style()->wordBreak() == BreakWordBreak) && style()->autoWrap();
     540
    539541    for (int i = 0; i < len; i++) {
    540542        UChar c = txt[i];
     
    574576            continue;
    575577
    576         bool hasBreak = isBreakable(txt, i, len, nextBreakable, breakNBSP);
     578        bool hasBreak = breakAll || isBreakable(txt, i, len, nextBreakable, breakNBSP);
    577579        int j = i;
    578580        while (c != '\n' && !isSpaceAccordingToStyle(c, style()) && c != '\t' && c != softHyphen) {
     
    581583                break;
    582584            c = txt[j];
    583             if (isBreakable(txt, j, len, nextBreakable, breakNBSP))
     585            if (breakAll || isBreakable(txt, j, len, nextBreakable, breakNBSP))
    584586                break;
    585587        }
  • trunk/WebCore/rendering/RenderTextControl.cpp

    r20685 r20967  
    149149        if (static_cast<HTMLTextAreaElement*>(element)->wrap() == HTMLTextAreaElement::ta_NoWrap) {
    150150            textBlockStyle->setWhiteSpace(PRE);
    151             textBlockStyle->setWordWrap(WBNORMAL);
     151            textBlockStyle->setWordWrap(NormalWordWrap);
    152152        } else {
    153153            textBlockStyle->setWhiteSpace(PRE_WRAP);
    154             textBlockStyle->setWordWrap(BREAK_WORD);
     154            textBlockStyle->setWordWrap(BreakWordWrap);
    155155        }
    156156    } else {
    157157        textBlockStyle->setWhiteSpace(PRE);
    158         textBlockStyle->setWordWrap(WBNORMAL);
     158        textBlockStyle->setWordWrap(NormalWordWrap);
    159159        textBlockStyle->setOverflowX(OHIDDEN);
    160160        textBlockStyle->setOverflowY(OHIDDEN);
     
    598598    int scrollbarSize = 0;
    599599    // We are able to have a horizontal scrollbar if the overflow style is scroll, or if its auto and there's no word wrap.
    600     if (m_innerText->renderer()->style()->overflowX() == OSCROLL ||  (m_innerText->renderer()->style()->overflowX() == OAUTO && m_innerText->renderer()->style()->wordWrap() == WBNORMAL))
     600    if (m_innerText->renderer()->style()->overflowX() == OSCROLL ||  (m_innerText->renderer()->style()->overflowX() == OAUTO && m_innerText->renderer()->style()->wordWrap() == NormalWordWrap))
    601601        scrollbarSize = 15;
    602602
  • trunk/WebCore/rendering/bidi.cpp

    r20889 r20967  
    22272227            // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word,
    22282228            // which is only possible if the word is the first thing on the line, that is, if |w| is zero.
    2229             bool breakWords = o->style()->wordWrap() == BREAK_WORD && ((autoWrap && !w) || currWS == PRE);
     2229            bool breakWords = o->style()->breakWords() && ((autoWrap && !w) || currWS == PRE);
    22302230            bool midWordBreak = false;
    2231            
     2231            bool breakAll = o->style()->wordBreak() == BreakAllWordBreak && autoWrap;
     2232
    22322233            while (len) {
    22332234                bool previousCharacterIsSpace = currentCharacterIsSpace;
     
    22772278                currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace);
    22782279
    2279                 if (breakWords && !midWordBreak) {
     2280                if (breakAll || (breakWords && !midWordBreak)) {
    22802281                    wrapW += t->width(pos, 1, f, w + wrapW);
    22812282                    midWordBreak = w + wrapW > width;
     
    22832284
    22842285                bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(str, pos, strlen, nextBreakable, breakNBSP));
    2285 
    2286                 if (betweenWords || midWordBreak) {
     2286   
     2287                if (betweenWords || midWordBreak || breakAll) {
    22872288                    bool stoppedIgnoringSpaces = false;
    22882289                    if (ignoringSpaces) {
Note: See TracChangeset for help on using the changeset viewer.