Changeset 146104 in webkit


Ignore:
Timestamp:
Mar 18, 2013 12:43:22 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[css3-text] Add rendering support for -webkit-text-underline-position
https://bugs.webkit.org/show_bug.cgi?id=102795

Patch by Lamarque V. Souza <Lamarque.Souza@basyskom.com> on 2013-03-18
Reviewed by Levi Weintraub.

Source/WebCore:

This patch implements rendering support for values [ auto | alphabetic | under ]
of CSS3 property text-underline-position. We don't fully match the specification
as we don't support [ left | right ] and this is left for another implementation
as the rendering will need to be added.

Tests: fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all.html

fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic.html
fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto.html
fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow.html
fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under.html

  • rendering/InlineFlowBox.cpp:

(WebCore::InlineFlowBox::computeMaxLogicalTop): Added method to compute maximal logical top among all chidren of
this InlineTextBox.

  • rendering/InlineFlowBox.h:

(InlineFlowBox):

  • rendering/InlineTextBox.cpp:

(WebCore::computeUnderlineOffset): Added method to compute offset for text-underline-position property.
(WebCore::InlineTextBox::paintDecoration): Paint decoration at position calculated using computeUnderlineOffset().

  • rendering/RootInlineBox.cpp:

(WebCore::RootInlineBox::RootInlineBox):
(WebCore::RootInlineBox::alignBoxesInBlockDirection): Call method to compute maximal logical top among all
children of this RootInlineBox.

  • rendering/RootInlineBox.h:

(RootInlineBox):
(WebCore::RootInlineBox::maxLogicalTop): Added getter for m_maxLogicalTop class member.

  • rendering/style/RenderStyle.h: Added the usual getter / setter / initial methods for text-underline-position

property

LayoutTests:

Added text-underline-position tests for 'text-underline-position' CSS3
property, with 'webkit' prefix.

  • fast/css3-text/css3-text-decoration/text-underline-position/style.css: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all-expected.txt: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all.html: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic-expected.txt: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic.html: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto-expected.txt: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto.html: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-expected.txt: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow-expected.txt: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow.html: Added.
  • fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under.html: Added.
  • platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all-expected.png: Added.
  • platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic-expected.png: Added.
  • platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto-expected.png: Added.
  • platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-expected.png: Added.
  • platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow-expected.png: Added.
Location:
trunk
Files:
20 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r146100 r146104  
     12013-03-18  Lamarque V. Souza  <Lamarque.Souza@basyskom.com>
     2
     3        [css3-text] Add rendering support for -webkit-text-underline-position
     4        https://bugs.webkit.org/show_bug.cgi?id=102795
     5
     6        Reviewed by Levi Weintraub.
     7
     8        Added text-underline-position tests for 'text-underline-position' CSS3
     9        property, with 'webkit' prefix.
     10
     11        * fast/css3-text/css3-text-decoration/text-underline-position/style.css: Added.
     12        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all-expected.txt: Added.
     13        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all.html: Added.
     14        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic-expected.txt: Added.
     15        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic.html: Added.
     16        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto-expected.txt: Added.
     17        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto.html: Added.
     18        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-expected.txt: Added.
     19        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow-expected.txt: Added.
     20        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow.html: Added.
     21        * fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under.html: Added.
     22        * platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all-expected.png: Added.
     23        * platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic-expected.png: Added.
     24        * platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto-expected.png: Added.
     25        * platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-expected.png: Added.
     26        * platform/chromium-linux/fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow-expected.png: Added.
     27
    1282013-03-18  Michael Saboff  <msaboff@apple.com>
    229
  • trunk/Source/WebCore/ChangeLog

    r146103 r146104  
     12013-03-18  Lamarque V. Souza  <Lamarque.Souza@basyskom.com>
     2
     3        [css3-text] Add rendering support for -webkit-text-underline-position
     4        https://bugs.webkit.org/show_bug.cgi?id=102795
     5
     6        Reviewed by Levi Weintraub.
     7
     8        This patch implements rendering support for values [ auto | alphabetic | under ]
     9        of CSS3 property text-underline-position. We don't fully match the specification
     10        as we don't support [ left | right ] and this is left for another implementation
     11        as the rendering will need to be added.
     12
     13        Tests: fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-all.html
     14               fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-alphabetic.html
     15               fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-auto.html
     16               fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under-out-of-flow.html
     17               fast/css3-text/css3-text-decoration/text-underline-position/text-underline-position-under.html
     18
     19        * rendering/InlineFlowBox.cpp:
     20        (WebCore::InlineFlowBox::computeMaxLogicalTop): Added method to compute maximal logical top among all chidren of
     21        this InlineTextBox.
     22        * rendering/InlineFlowBox.h:
     23        (InlineFlowBox):
     24        * rendering/InlineTextBox.cpp:
     25        (WebCore::computeUnderlineOffset): Added method to compute offset for text-underline-position property.
     26        (WebCore::InlineTextBox::paintDecoration): Paint decoration at position calculated using computeUnderlineOffset().
     27        * rendering/RootInlineBox.cpp:
     28        (WebCore::RootInlineBox::RootInlineBox):
     29        (WebCore::RootInlineBox::alignBoxesInBlockDirection): Call method to compute maximal logical top among all
     30        children of this RootInlineBox.
     31        * rendering/RootInlineBox.h:
     32        (RootInlineBox):
     33        (WebCore::RootInlineBox::maxLogicalTop): Added getter for m_maxLogicalTop class member.
     34        * rendering/style/RenderStyle.h: Added the usual getter / setter / initial methods for text-underline-position
     35        property
     36
    1372013-03-18  Christian Biesinger  <cbiesinger@chromium.org>
    238
  • trunk/Source/WebCore/rendering/InlineFlowBox.cpp

    r144565 r146104  
    739739    }
    740740}
     741
     742#if ENABLE(CSS3_TEXT)
     743void InlineFlowBox::computeMaxLogicalTop(float& maxLogicalTop)
     744{
     745    for (InlineBox* curr = firstChild(); curr; curr = curr->nextOnLine()) {
     746        if (curr->renderer()->isOutOfFlowPositioned())
     747            continue; // Positioned placeholders don't affect calculations.
     748
     749        if (descendantsHaveSameLineHeightAndBaseline())
     750            continue;
     751
     752        maxLogicalTop = max<float>(maxLogicalTop, curr->y());
     753        float localMaxLogicalTop = 0;
     754        if (curr->isInlineFlowBox())
     755            toInlineFlowBox(curr)->computeMaxLogicalTop(localMaxLogicalTop);
     756        maxLogicalTop = max<float>(maxLogicalTop, localMaxLogicalTop);
     757    }
     758}
     759#endif // CSS3_TEXT
    741760
    742761void InlineFlowBox::flipLinesInBlockDirection(LayoutUnit lineTop, LayoutUnit lineBottom)
  • trunk/Source/WebCore/rendering/InlineFlowBox.h

    r140640 r146104  
    320320    InlineFlowBox* m_nextLineBox; // The next box that also uses our RenderObject
    321321
     322#if ENABLE(CSS3_TEXT)
     323    // Maximum logicalTop among all children of an InlineFlowBox. Used to
     324    // calculate the offset for TextUnderlinePositionUnder.
     325    void computeMaxLogicalTop(float& maxLogicalTop);
     326#endif // CSS3_TEXT
    322327private:
    323328    unsigned m_includeLogicalLeftEdge : 1;
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r141816 r146104  
    959959}
    960960
     961#if ENABLE(CSS3_TEXT)
     962static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const int textDecorationThickness)
     963{
     964    // Compute the gap between the font and the underline. Use at least one
     965    // pixel gap, if underline is thick then use a bigger gap.
     966    const int gap = max<int>(1, ceilf(textDecorationThickness / 2.0));
     967
     968    // According to the specification TextUnderlinePositionAuto should default to 'alphabetic' for horizontal text
     969    // and to 'under Left' for vertical text (e.g. japanese). We support only horizontal text for now.
     970    switch (underlinePosition) {
     971    case TextUnderlinePositionAlphabetic:
     972    case TextUnderlinePositionAuto:
     973        return fontMetrics.ascent() + gap; // Position underline near the alphabetic baseline.
     974    case TextUnderlinePositionUnder: {
     975        // Position underline relative to the under edge of the lowest element's content box.
     976        const float offset = inlineTextBox->root()->maxLogicalTop() - inlineTextBox->logicalTop();
     977        if (offset > 0)
     978            return inlineTextBox->logicalHeight() + gap + offset;
     979        return inlineTextBox->logicalHeight() + gap;
     980    }
     981    }
     982
     983    ASSERT_NOT_REACHED();
     984    return fontMetrics.ascent() + gap;
     985}
     986#endif // CSS3_TEXT
     987
    961988void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, ETextDecoration deco, TextDecorationStyle decorationStyle, const ShadowData* shadow)
    962989{
     
    10351062        if (deco & UNDERLINE) {
    10361063            context->setStrokeColor(underline, colorSpace);
     1064#if ENABLE(CSS3_TEXT)
     1065            TextUnderlinePosition underlinePosition = styleToUse->textUnderlinePosition();
     1066            const int underlineOffset = computeUnderlineOffset(underlinePosition, styleToUse->fontMetrics(), this, textDecorationThickness);
     1067            context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + underlineOffset), width, isPrinting);
     1068
     1069            if (decorationStyle == TextDecorationStyleDouble)
     1070                context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + underlineOffset + doubleOffset), width, isPrinting);
     1071#else
    10371072            // Leave one pixel of white between the baseline and the underline.
    10381073            context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + baseline + 1), width, isPrinting);
    1039 #if ENABLE(CSS3_TEXT)
    1040             if (decorationStyle == TextDecorationStyleDouble)
    1041                 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + baseline + 1 + doubleOffset), width, isPrinting);
    10421074#endif // CSS3_TEXT
    10431075        }
  • trunk/Source/WebCore/rendering/RootInlineBox.cpp

    r144497 r146104  
    5454    , m_lineTopWithLeading(0)
    5555    , m_lineBottomWithLeading(0)
     56#if ENABLE(CSS3_TEXT)
     57    , m_maxLogicalTop(0)
     58#endif // CSS3_TEXT
    5659{
    5760    setIsHorizontal(block->isHorizontalWritingMode());
     
    280283    if (isSVGRootInlineBox())
    281284        return 0;
     285
     286    // FIXME: figure out how to call computeMaxLogicalTop() when SVG is enabled.
    282287#endif
    283288
     
    331336        heightOfBlock += gridSnapAdjustment;
    332337    }
     338
     339#if ENABLE(CSS3_TEXT)
     340    m_maxLogicalTop = 0;
     341    computeMaxLogicalTop(m_maxLogicalTop);
     342#endif // CSS3_TEXT
    333343
    334344    return heightOfBlock + maxHeight;
  • trunk/Source/WebCore/rendering/RootInlineBox.h

    r140291 r146104  
    187187    }
    188188
     189#if ENABLE(CSS3_TEXT)
     190    // Used to calculate the underline offset for TextUnderlinePositionUnder.
     191    float maxLogicalTop() const { return m_maxLogicalTop; }
     192#endif // CSS3_TEXT
     193
    189194    Node* getLogicalStartBoxWithNode(InlineBox*&) const;
    190195    Node* getLogicalEndBoxWithNode(InlineBox*&) const;
     
    220225    LayoutUnit m_lineTopWithLeading;
    221226    LayoutUnit m_lineBottomWithLeading;
     227
     228#if ENABLE(CSS3_TEXT)
     229    // Maximum logicalTop among all children of an InlineFlowBox. Used to
     230    // calculate the offset for TextUnderlinePositionUnder.
     231    float m_maxLogicalTop;
     232#endif // CSS3_TEXT
    222233
    223234    struct LineFragmentationData {
Note: See TracChangeset for help on using the changeset viewer.