Changeset 94710 in webkit


Ignore:
Timestamp:
Sep 7, 2011 1:59:39 PM (13 years ago)
Author:
mitz@apple.com
Message:

<rdar://problem/8881922> Support the hyphenate-limit-lines property
https://bugs.webkit.org/show_bug.cgi?id=67730

Reviewed by Dave Hyatt.

Source/WebCore:

Tests: fast/css/parsing-hyphenate-limit-lines.html

fast/text/hyphenate-limit-lines.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Added hyphenate-limit-lines.

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseValue): Ditto. Valid values are non-negative integers and the keyword
"no-limit".

  • css/CSSPropertyNames.in: Added -webkit-hyphenate-limit-lines.
  • css/CSSStyleSelector.cpp:

(WebCore::CSSStyleSelector::applyProperty): Added hyphenate-limit-lines.

  • css/CSSValueKeywords.in: Added the "no-limit" value keyword.
  • rendering/RenderBlock.h:
  • rendering/RenderBlockLineLayout.cpp:

(WebCore::RenderBlock::layoutRunsAndFloats): Count the number of consecutive hyphenated lines
before the start line and pass it to layoutRunsAndFloatsInRange().
(WebCore::RenderBlock::layoutRunsAndFloatsInRange): Keep track of the number of consecutive
hyphenated lines before the current line and pass it to LineBreaker::nextLineBreak().
(WebCore::tryHyphenating): Added parameters for the number of consecutive hyphenated lines before
the current line and the limit on consecutive hyphenated lines, and an early return if the limit
has been reached.
(WebCore::RenderBlock::LineBreaker::nextLineBreak): Added a parameter for the number of consecutive
hyphenated lines before the current line, which is passed through to tryHyphenating, along with
the value of hyphenate-limit-lines.

  • rendering/RootInlineBox.cpp:

(WebCore::RootInlineBox::isHyphenated): Added. Returns true if the line was hyphenated.

  • rendering/RootInlineBox.h:
  • rendering/style/RenderStyle.h:

(WebCore::InheritedFlags::hyphenationLimitLines): Added this getter.
(WebCore::InheritedFlags::setHyphenationLimitLines): Added this setter.
(WebCore::InheritedFlags::initialHyphenationLimitLines): Added. The initial value is -1,
corresponding to "no-limit".

  • rendering/style/StyleRareInheritedData.cpp:

(WebCore::StyleRareInheritedData::StyleRareInheritedData): Initialize new member variable.
(WebCore::StyleRareInheritedData::operator==): Compare new member variable.

  • rendering/style/StyleRareInheritedData.h:

LayoutTests:

  • fast/css/parsing-hyphenate-limit-lines-expected.txt: Added.
  • fast/css/parsing-hyphenate-limit-lines.html: Added.
  • fast/text/hyphenate-limit-lines.html: Added.
  • platform/mac/fast/text/hyphenate-limit-lines-expected.png: Added.
  • platform/mac/fast/text/hyphenate-limit-lines-expected.txt: Added.
Location:
trunk
Files:
5 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r94709 r94710  
     12011-09-07  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/8881922> Support the hyphenate-limit-lines property
     4        https://bugs.webkit.org/show_bug.cgi?id=67730
     5
     6        Reviewed by Dave Hyatt.
     7
     8        * fast/css/parsing-hyphenate-limit-lines-expected.txt: Added.
     9        * fast/css/parsing-hyphenate-limit-lines.html: Added.
     10        * fast/text/hyphenate-limit-lines.html: Added.
     11        * platform/mac/fast/text/hyphenate-limit-lines-expected.png: Added.
     12        * platform/mac/fast/text/hyphenate-limit-lines-expected.txt: Added.
     13
    1142011-09-07  Csaba Osztrogonác  <ossy@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r94706 r94710  
     12011-09-07  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/8881922> Support the hyphenate-limit-lines property
     4        https://bugs.webkit.org/show_bug.cgi?id=67730
     5
     6        Reviewed by Dave Hyatt.
     7
     8        Tests: fast/css/parsing-hyphenate-limit-lines.html
     9               fast/text/hyphenate-limit-lines.html
     10
     11        * css/CSSComputedStyleDeclaration.cpp:
     12        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Added hyphenate-limit-lines.
     13        * css/CSSParser.cpp:
     14        (WebCore::CSSParser::parseValue): Ditto. Valid values are non-negative integers and the keyword
     15        "no-limit".
     16        * css/CSSPropertyNames.in: Added -webkit-hyphenate-limit-lines.
     17        * css/CSSStyleSelector.cpp:
     18        (WebCore::CSSStyleSelector::applyProperty): Added hyphenate-limit-lines.
     19        * css/CSSValueKeywords.in: Added the "no-limit" value keyword.
     20        * rendering/RenderBlock.h:
     21        * rendering/RenderBlockLineLayout.cpp:
     22        (WebCore::RenderBlock::layoutRunsAndFloats): Count the number of consecutive hyphenated lines
     23        before the start line and pass it to layoutRunsAndFloatsInRange().
     24        (WebCore::RenderBlock::layoutRunsAndFloatsInRange): Keep track of the number of consecutive
     25        hyphenated lines before the current line and pass it to LineBreaker::nextLineBreak().
     26        (WebCore::tryHyphenating): Added parameters for the number of consecutive hyphenated lines before
     27        the current line and the limit on consecutive hyphenated lines, and an early return if the limit
     28        has been reached.
     29        (WebCore::RenderBlock::LineBreaker::nextLineBreak): Added a parameter for the number of consecutive
     30        hyphenated lines before the current line, which is passed through to tryHyphenating, along with
     31        the value of hyphenate-limit-lines.
     32        * rendering/RootInlineBox.cpp:
     33        (WebCore::RootInlineBox::isHyphenated): Added. Returns true if the line was hyphenated.
     34        * rendering/RootInlineBox.h:
     35        * rendering/style/RenderStyle.h:
     36        (WebCore::InheritedFlags::hyphenationLimitLines): Added this getter.
     37        (WebCore::InheritedFlags::setHyphenationLimitLines): Added this setter.
     38        (WebCore::InheritedFlags::initialHyphenationLimitLines): Added. The initial value is -1,
     39        corresponding to "no-limit".
     40        * rendering/style/StyleRareInheritedData.cpp:
     41        (WebCore::StyleRareInheritedData::StyleRareInheritedData): Initialize new member variable.
     42        (WebCore::StyleRareInheritedData::operator==): Compare new member variable.
     43        * rendering/style/StyleRareInheritedData.h:
     44
    1452011-09-02  Ojan Vafai  <ojan@chromium.org>
    246
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r94597 r94710  
    216216    CSSPropertyWebkitHyphenateLimitAfter,
    217217    CSSPropertyWebkitHyphenateLimitBefore,
     218    CSSPropertyWebkitHyphenateLimitLines,
    218219    CSSPropertyWebkitHyphens,
    219220    CSSPropertyWebkitLineBoxContain,
     
    13091310                return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
    13101311            return CSSPrimitiveValue::create(style->hyphenationLimitBefore(), CSSPrimitiveValue::CSS_NUMBER);
     1312        case CSSPropertyWebkitHyphenateLimitLines:
     1313            if (style->hyphenationLimitLines() < 0)
     1314                return CSSPrimitiveValue::createIdentifier(CSSValueNoLimit);
     1315            return CSSPrimitiveValue::create(style->hyphenationLimitLines(), CSSPrimitiveValue::CSS_NUMBER);
    13111316        case CSSPropertyWebkitBorderFit:
    13121317            if (style->borderFit() == BorderFitBorder)
  • trunk/Source/WebCore/css/CSSParser.cpp

    r94597 r94710  
    18971897    case CSSPropertyWebkitHyphenateLimitAfter:
    18981898        if (id == CSSValueAuto || validUnit(value, FInteger | FNonNeg, true))
     1899            validPrimitive = true;
     1900        break;
     1901
     1902    case CSSPropertyWebkitHyphenateLimitLines:
     1903        if (id == CSSValueNoLimit || validUnit(value, FInteger | FNonNeg, true))
    18991904            validPrimitive = true;
    19001905        break;
  • trunk/Source/WebCore/css/CSSPropertyNames.in

    r94593 r94710  
    258258-webkit-hyphenate-limit-after
    259259-webkit-hyphenate-limit-before
     260-webkit-hyphenate-limit-lines
    260261-webkit-hyphens
    261262-epub-hyphens = -webkit-hyphens
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r94657 r94710  
    35503550        else
    35513551            m_style->setHyphenationLimitBefore(primitiveValue->getValue<short>(CSSPrimitiveValue::CSS_NUMBER));
     3552        return;
     3553    }
     3554    case CSSPropertyWebkitHyphenateLimitLines: {
     3555        HANDLE_INHERIT_AND_INITIAL(hyphenationLimitLines, HyphenationLimitLines);
     3556        if (primitiveValue->getIdent() == CSSValueNoLimit)
     3557            m_style->setHyphenationLimitLines(-1);
     3558        else
     3559            m_style->setHyphenationLimitLines(primitiveValue->getValue<short>(CSSPrimitiveValue::CSS_NUMBER));
    35523560        return;
    35533561    }
  • trunk/Source/WebCore/css/CSSValueKeywords.in

    r94104 r94710  
    777777windowed
    778778
     779// -webkit-hyphenate-limit-lines
     780no-limit
     781
    779782// -webkit-hyphens
    780783// none
  • trunk/Source/WebCore/rendering/RenderBlock.h

    r94492 r94710  
    564564        }
    565565
    566         InlineIterator nextLineBreak(InlineBidiResolver&, LineInfo&, LineBreakIteratorInfo&, FloatingObject* lastFloatFromPreviousLine);
     566        InlineIterator nextLineBreak(InlineBidiResolver&, LineInfo&, LineBreakIteratorInfo&, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines);
    567567
    568568        bool lineWasHyphenated() { return m_hyphenated; }
     
    796796    RootInlineBox* createLineBoxesFromBidiRuns(BidiRunList<BidiRun>&, const InlineIterator& end, LineInfo&, VerticalPositionCache&, BidiRun* trailingSpaceRun);
    797797    void layoutRunsAndFloats(LineLayoutState&, bool hasInlineChild);
    798     void layoutRunsAndFloatsInRange(LineLayoutState&, InlineBidiResolver&, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus);
     798    void layoutRunsAndFloatsInRange(LineLayoutState&, InlineBidiResolver&, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines);
    799799    void linkToEndLineIfNeeded(LineLayoutState&);
    800800    static void repaintDirtyFloats(Vector<FloatWithRect>& floats);
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r94693 r94710  
    937937    RootInlineBox* startLine = determineStartPosition(layoutState, resolver);
    938938
     939    unsigned consecutiveHyphenatedLines = 0;
     940    if (startLine) {
     941        for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox())
     942            consecutiveHyphenatedLines++;
     943    }
     944
    939945    // FIXME: This would make more sense outside of this function, but since
    940946    // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
     
    985991    }
    986992
    987     layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus);
     993    layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines);
    988994    linkToEndLineIfNeeded(layoutState);
    989995    repaintDirtyFloats(layoutState.floats());
    990996}
    991997
    992 void RenderBlock::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus)
     998void RenderBlock::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines)
    993999{
    9941000    bool paginated = view()->layoutState() && view()->layoutState()->isPaginated();
     
    10161022        bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly();
    10171023        FloatingObject* lastFloatFromPreviousLine = (m_floatingObjects && !m_floatingObjects->set().isEmpty()) ? m_floatingObjects->set().last() : 0;
    1018         end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), lineBreakIteratorInfo, lastFloatFromPreviousLine);
     1024        end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), lineBreakIteratorInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines);
    10191025        if (resolver.position().atEnd()) {
    10201026            // FIXME: We shouldn't be creating any runs in findNextLineBreak to begin with!
     
    10461052            BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0;
    10471053
    1048             if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated())
     1054            if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) {
    10491055                bidiRuns.logicallyLastRun()->m_hasHyphen = true;
     1056                consecutiveHyphenatedLines++;
     1057            } else
     1058                consecutiveHyphenatedLines = 0;
    10501059
    10511060            // Now that the runs have been ordered, we create the line boxes.
     
    16801689}
    16811690
    1682 static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, int minimumPrefixLength, int minimumSuffixLength, int lastSpace, int pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated)
     1691static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLength, int minimumSuffixLength, int lastSpace, int pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated)
    16831692{
    16841693    // Map 'hyphenate-limit-{before,after}: auto;' to 2.
     
    16901699
    16911700    if (pos - lastSpace <= minimumSuffixLength)
     1701        return;
     1702
     1703    if (consecutiveHyphenatedLinesLimit >= 0 && consecutiveHyphenatedLines >= static_cast<unsigned>(consecutiveHyphenatedLinesLimit))
    16921704        return;
    16931705
     
    19501962
    19511963InlineIterator RenderBlock::LineBreaker::nextLineBreak(InlineBidiResolver& resolver, LineInfo& lineInfo,
    1952     LineBreakIteratorInfo& lineBreakIteratorInfo, FloatingObject* lastFloatFromPreviousLine)
     1964    LineBreakIteratorInfo& lineBreakIteratorInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines)
    19531965{
    19541966    reset();
     
    22692281                        if (lineWasTooWide || !width.fitsOnLine()) {
    22702282                            if (canHyphenate && !width.fitsOnLine()) {
    2271                                 tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated);
     2283                                tryHyphenating(t, f, style->locale(), consecutiveHyphenatedLines, m_block->style()->hyphenationLimitLines(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated);
    22722284                                if (m_hyphenated)
    22732285                                    goto end;
     
    23872399            if (!width.fitsOnLine()) {
    23882400                if (canHyphenate)
    2389                     tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated);
     2401                    tryHyphenating(t, f, style->locale(), consecutiveHyphenatedLines, m_block->style()->hyphenationLimitLines(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated);
    23902402
    23912403                if (!m_hyphenated && lBreak.previousInSameNode() == softHyphen && style->hyphens() != HyphensNone)
  • trunk/Source/WebCore/rendering/RootInlineBox.cpp

    r94084 r94710  
    8787        InlineFlowBox::clearTruncation();
    8888    }
     89}
     90
     91bool RootInlineBox::isHyphenated() const
     92{
     93    for (InlineBox* box = firstLeafChild(); box; box = box->nextLeafChild()) {
     94        if (box->isInlineTextBox()) {
     95            if (toInlineTextBox(box)->hasHyphen())
     96                return true;
     97        }
     98    }
     99
     100    return false;
    89101}
    90102
  • trunk/Source/WebCore/rendering/RootInlineBox.h

    r94084 r94710  
    9696
    9797    virtual void clearTruncation();
     98
     99    bool isHyphenated() const;
    98100
    99101    virtual int baselinePosition(FontBaseline baselineType) const { return boxModelObject()->baselinePosition(baselineType, m_firstLine, isHorizontal() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); }
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r94206 r94710  
    715715    short hyphenationLimitBefore() const { return rareInheritedData->hyphenationLimitBefore; }
    716716    short hyphenationLimitAfter() const { return rareInheritedData->hyphenationLimitAfter; }
     717    short hyphenationLimitLines() const { return rareInheritedData->hyphenationLimitLines; }
    717718    const AtomicString& hyphenationString() const { return rareInheritedData->hyphenationString; }
    718719    const AtomicString& locale() const { return rareInheritedData->locale; }
     
    10951096    void setHyphenationLimitBefore(short limit) { SET_VAR(rareInheritedData, hyphenationLimitBefore, limit); }
    10961097    void setHyphenationLimitAfter(short limit) { SET_VAR(rareInheritedData, hyphenationLimitAfter, limit); }
     1098    void setHyphenationLimitLines(short limit) { SET_VAR(rareInheritedData, hyphenationLimitLines, limit); }
    10971099    void setHyphenationString(const AtomicString& h) { SET_VAR(rareInheritedData, hyphenationString, h); }
    10981100    void setLocale(const AtomicString& locale) { SET_VAR(rareInheritedData, locale, locale); }
     
    13771379    static short initialHyphenationLimitBefore() { return -1; }
    13781380    static short initialHyphenationLimitAfter() { return -1; }
     1381    static short initialHyphenationLimitLines() { return -1; }
    13791382    static const AtomicString& initialHyphenationString() { return nullAtom; }
    13801383    static const AtomicString& initialLocale() { return nullAtom; }
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp

    r92871 r94710  
    5656    , hyphenationLimitBefore(-1)
    5757    , hyphenationLimitAfter(-1)
     58    , hyphenationLimitLines(-1)
    5859{
    5960}
     
    9293    , hyphenationLimitBefore(o.hyphenationLimitBefore)
    9394    , hyphenationLimitAfter(o.hyphenationLimitAfter)
     95    , hyphenationLimitLines(o.hyphenationLimitLines)
    9496    , locale(o.locale)
    9597    , textEmphasisCustomMark(o.textEmphasisCustomMark)
     
    137139        && hyphenationLimitBefore == o.hyphenationLimitBefore
    138140        && hyphenationLimitAfter == o.hyphenationLimitAfter
     141        && hyphenationLimitLines == o.hyphenationLimitLines
    139142        && textEmphasisFill == o.textEmphasisFill
    140143        && textEmphasisMark == o.textEmphasisMark
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h

    r87121 r94710  
    9393    short hyphenationLimitBefore;
    9494    short hyphenationLimitAfter;
     95    short hyphenationLimitLines;
    9596
    9697    AtomicString locale;
Note: See TracChangeset for help on using the changeset viewer.