Changeset 125925 in webkit


Ignore:
Timestamp:
Aug 17, 2012 12:17:54 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Text Autosizing: Increase line height in proportion to font size.
https://bugs.webkit.org/show_bug.cgi?id=91660

Patch by John Mellor <johnme@chromium.org> on 2012-08-17
Reviewed by Julien Chaffraix.

Source/WebCore:

This patch causes line heights to be increased in proportion to font
size (so autosized text doesn't overlap itself). It does this by adding
a textAutosizingMultiplier() to RenderStyle, which the lineHeight()
getter multiplies its response by.

It also cleans up one or two things, for example treatAsInline is
renamed isNotAnAutosizingContainer to clarify that its purpose is to
discriminate autosizing containers (the smallest unit that we can turn
Text Autosizing on or off for; in particular these are not allowed to
be line participants, since multiple sizes on one line looks awful).

Tests: fast/text-autosizing/em-margin-border-padding.html

fast/text-autosizing/narrow-child.html
fast/text-autosizing/nested-em-line-height.html
fast/text-autosizing/simple-paragraph.html
fast/text-autosizing/span-child.html
fast/text-autosizing/wide-child.html

  • css/StyleBuilder.cpp:

(WebCore::ApplyPropertyLineHeight::applyValue):

Replaced Length(-100.0, Percent) with RenderStyle::initialLineHeight(),
which is equivalent but makes the intent clearer.

(WebCore::ApplyPropertyLineHeight::createHandler):

Use specifiedLineHeight to match setLineHeight which takes a specified
line height (and generally this avoids accidentally inheriting text
autosizing).

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::applyProperty):

Similarly use specifiedLineHeight when inheriting line height.

  • page/animation/CSSPropertyAnimation.cpp:

(WebCore::CSSPropertyAnimation::ensurePropertyMap):

Get and set specified lineHeight/fontSize if Text Autosizing is
enabled to avoid setting the specified value to the computed value
(causing values to be multiplied more than once!).

  • platform/blackberry/RenderThemeBlackBerry.cpp:

(WebCore::RenderThemeBlackBerry::adjustMediaControlStyle):

Adjust for renamed setBlendedFontSize, and maintain cast to int.

  • rendering/RenderTextControlSingleLine.cpp:

(WebCore::RenderTextControlSingleLine::createInnerTextStyle):

Replaced Length(-100.0, Percent) with RenderStyle::initialLineHeight(),
which is equivalent but makes the intent clearer.

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::processSubtree):

Use nextInPreOrderMatchingFilter instead of traverseNext, and some
other methods that got renamed.

(WebCore::TextAutosizer::processBox):

Renamed from processBlock, since RenderBoxes are sufficient; use
renamed nextInPreOrderMatchingFilter; make two calls to setMultiplier
(one for parent for line height) instead of processText.

(WebCore::TextAutosizer::setMultiplier):

Simplified from previous processText method; this just sets the
style's textAutosizingMultiplier (and the style does the rest).

(WebCore::TextAutosizer::isNotAnAutosizingContainer):

Renamed from treatAsInline; added explanatory comment; changed
isRenderBlock to isBox as boxes still have logicalWidth; changed
isInlineBlockOrInlineTable to isInline as it was an omission that
other inlines were allowed.

(WebCore::TextAutosizer::nextInPreOrderMatchingFilter):

Renamed from TextAutosizer::traverseNext.

(RenderObjectFilterFunctor):

Renamed from RenderObjectFilter to clafiry that it's a function ptr.

  • rendering/TextAutosizer.h:

(TextAutosizer): Previously mentioned renamings.

  • rendering/mathml/RenderMathMLSubSup.cpp:

(WebCore::RenderMathMLSubSup::fixScriptsStyle):

Adjust for renamed setBlendedFontSize.

  • rendering/style/RenderStyle.cpp:

(WebCore::RenderStyle::diff):

textAutosizingMultiplier is a StyleDifferenceLayout (we want
setNeedsLayoutAndPrefWidthsRecalc to get called).

(WebCore::RenderStyle::setFontSize):

Renamed from setBlendedFontSize; if Text Autosizing is enabled and a
multiplier is set it auto-calculates the computedSize; float
param instead of int as discussed on webkit.org/b/91660.

  • rendering/style/RenderStyle.h:

Added specifiedFontSize, computedFontSize and specifiedLineHeight
getters; changed lineHeight to dynamically calculate autosized line
height, and made computedLineHeight use this value instead of the
specified line height; also added textAutosizingMultiplier
getter/setter (the setter updated the font description's computed
size, by calling setFontSize); also renamed the parameter to
setLineHeight to explicitly note that it's setting the
specifiedLineHeight (and can still be adjusted by autosizing).

  • rendering/style/StyleVisualData.cpp/.h:

Added m_textAutosizingMultiplier (this seems the best place to put a
non-inherited non-rare presentational property).

LayoutTests:

Adjusted the expectation for simple-paragraph.html and
font-scale-factor.html now that line-height is correctly increased.
Also added 5 more tests making sure that autosized children of
non-autosized parents work correctly, and vice versa; that nested
inline elements behave correctly; and documenting the behavior of
margins, borders, and padding with em lengths.

  • fast/text-autosizing/em-margin-border-padding-expected.html: Added.
  • fast/text-autosizing/em-margin-border-padding.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
  • fast/text-autosizing/font-scale-factor-expected.html:
  • fast/text-autosizing/font-scale-factor.html:
  • fast/text-autosizing/narrow-child-expected.html: Added.
  • fast/text-autosizing/narrow-child.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
  • fast/text-autosizing/nested-em-line-height-expected.html: Added.
  • fast/text-autosizing/nested-em-line-height.html: Added.
  • fast/text-autosizing/simple-paragraph-expected.html:
  • fast/text-autosizing/simple-paragraph.html:
  • fast/text-autosizing/span-child-expected.html: Added.
  • fast/text-autosizing/span-child.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
  • fast/text-autosizing/wide-child-expected.html: Added.
  • fast/text-autosizing/wide-child.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
Location:
trunk
Files:
6 added
18 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r125921 r125925  
     12012-08-17  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Increase line height in proportion to font size.
     4        https://bugs.webkit.org/show_bug.cgi?id=91660
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        Adjusted the expectation for simple-paragraph.html and
     9        font-scale-factor.html now that line-height is correctly increased.
     10        Also added 5 more tests making sure that autosized children of
     11        non-autosized parents work correctly, and vice versa; that nested
     12        inline elements behave correctly; and documenting the behavior of
     13        margins, borders, and padding with em lengths.
     14
     15        * fast/text-autosizing/em-margin-border-padding-expected.html: Added.
     16        * fast/text-autosizing/em-margin-border-padding.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
     17        * fast/text-autosizing/font-scale-factor-expected.html:
     18        * fast/text-autosizing/font-scale-factor.html:
     19        * fast/text-autosizing/narrow-child-expected.html: Added.
     20        * fast/text-autosizing/narrow-child.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
     21        * fast/text-autosizing/nested-em-line-height-expected.html: Added.
     22        * fast/text-autosizing/nested-em-line-height.html: Added.
     23        * fast/text-autosizing/simple-paragraph-expected.html:
     24        * fast/text-autosizing/simple-paragraph.html:
     25        * fast/text-autosizing/span-child-expected.html: Added.
     26        * fast/text-autosizing/span-child.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
     27        * fast/text-autosizing/wide-child-expected.html: Added.
     28        * fast/text-autosizing/wide-child.html: Copied from LayoutTests/fast/text-autosizing/simple-paragraph.html.
     29
    1302012-08-17  Zan Dobersek  <zandobersek@gmail.com>
    231
  • trunk/LayoutTests/fast/text-autosizing/em-margin-border-padding.html

    r125924 r125925  
     1<!DOCTYPE html>
    12<html>
    23<head>
     
    1920<body>
    2021
    21 <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     22<p style="margin: 1em; border: 1em solid blue; padding: 1em">
     23    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
     24</p>
    2225
    2326</body>
  • trunk/LayoutTests/fast/text-autosizing/font-scale-factor-expected.html

    r124372 r125925  
     1<!DOCTYPE html>
    12<html>
    23  <head>
     
    1011  </head>
    1112  <body>
    12     <!-- FIXME: The line-height and margin-top shouldn't need to be changed here. The margins are a bug. See http://wkbug.com/91660. -->
    13     <p style="font-size: 5rem; line-height: 0.30; margin: 2.20rem 0 1rem 0">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     13    <div style="font-size: 5rem">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</div>
    1414  </body>
    1515</html>
  • trunk/LayoutTests/fast/text-autosizing/font-scale-factor.html

    r124372 r125925  
     1<!DOCTYPE html>
    12<html>
    23  <head>
     
    1920  </head>
    2021  <body>
    21     <!-- FIXME: The line-height and margin-top shouldn't need to be changed here. See http://wkbug.com/91660. -->
    22     <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     22    <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</div>
    2323  </body>
    2424</html>
  • trunk/LayoutTests/fast/text-autosizing/narrow-child.html

    r125924 r125925  
     1<!DOCTYPE html>
    12<html>
    23<head>
     
    1920<body>
    2021
    21 <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     22<div>
     23    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     24    <div style="width: 320px">
     25        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     26    </div>
     27    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     28</div>
    2229
    2330</body>
  • trunk/LayoutTests/fast/text-autosizing/simple-paragraph-expected.html

    r121907 r125925  
     1<!DOCTYPE html>
    12<html>
    23<head>
     
    1011<body>
    1112
    12 <!-- The font-size change is intentional; the line-height change is a known FIXME; the margin-top change is a bug -->
    13 <p style="font-size: 2.5rem; line-height: 0.6; margin-top: 0.8rem">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     13<div style="font-size: 2.5rem">
     14    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
     15</div>
    1416
    1517</body>
  • trunk/LayoutTests/fast/text-autosizing/simple-paragraph.html

    r121907 r125925  
     1<!DOCTYPE html>
    12<html>
    23<head>
     
    1920<body>
    2021
    21 <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     22<div>
     23    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
     24</div>
    2225
    2326</body>
  • trunk/LayoutTests/fast/text-autosizing/span-child.html

    r125924 r125925  
     1<!DOCTYPE html>
    12<html>
    23<head>
     
    1920<body>
    2021
    21 <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     22<div>
     23    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     24    <span>
     25        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     26    </span>
     27    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     28</div>
    2229
    2330</body>
  • trunk/LayoutTests/fast/text-autosizing/wide-child.html

    r125924 r125925  
     1<!DOCTYPE html>
    12<html>
    23<head>
     
    1920<body>
    2021
    21 <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
     22<div style="width: 320px">
     23    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     24    <div style="width: 800px">
     25        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     26    </div>
     27    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     28</div>
    2229
    2330</body>
  • trunk/Source/WebCore/ChangeLog

    r125924 r125925  
     12012-08-17  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Increase line height in proportion to font size.
     4        https://bugs.webkit.org/show_bug.cgi?id=91660
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        This patch causes line heights to be increased in proportion to font
     9        size (so autosized text doesn't overlap itself). It does this by adding
     10        a textAutosizingMultiplier() to RenderStyle, which the lineHeight()
     11        getter multiplies its response by.
     12
     13        It also cleans up one or two things, for example treatAsInline is
     14        renamed isNotAnAutosizingContainer to clarify that its purpose is to
     15        discriminate autosizing containers (the smallest unit that we can turn
     16        Text Autosizing on or off for; in particular these are not allowed to
     17        be line participants, since multiple sizes on one line looks awful).
     18
     19        Tests: fast/text-autosizing/em-margin-border-padding.html
     20               fast/text-autosizing/narrow-child.html
     21               fast/text-autosizing/nested-em-line-height.html
     22               fast/text-autosizing/simple-paragraph.html
     23               fast/text-autosizing/span-child.html
     24               fast/text-autosizing/wide-child.html
     25
     26        * css/StyleBuilder.cpp:
     27        (WebCore::ApplyPropertyLineHeight::applyValue):
     28
     29            Replaced Length(-100.0, Percent) with RenderStyle::initialLineHeight(),
     30            which is equivalent but makes the intent clearer.
     31
     32        (WebCore::ApplyPropertyLineHeight::createHandler):
     33
     34            Use specifiedLineHeight to match setLineHeight which takes a specified
     35            line height (and generally this avoids accidentally inheriting text
     36            autosizing).
     37
     38        * css/StyleResolver.cpp:
     39        (WebCore::StyleResolver::applyProperty):
     40
     41            Similarly use specifiedLineHeight when inheriting line height.
     42
     43        * page/animation/CSSPropertyAnimation.cpp:
     44        (WebCore::CSSPropertyAnimation::ensurePropertyMap):
     45
     46            Get and set specified lineHeight/fontSize if Text Autosizing is
     47            enabled to avoid setting the specified value to the computed value
     48            (causing values to be multiplied more than once!).
     49
     50        * platform/blackberry/RenderThemeBlackBerry.cpp:
     51        (WebCore::RenderThemeBlackBerry::adjustMediaControlStyle):
     52
     53            Adjust for renamed setBlendedFontSize, and maintain cast to int.
     54
     55        * rendering/RenderTextControlSingleLine.cpp:
     56        (WebCore::RenderTextControlSingleLine::createInnerTextStyle):
     57
     58            Replaced Length(-100.0, Percent) with RenderStyle::initialLineHeight(),
     59            which is equivalent but makes the intent clearer.
     60
     61        * rendering/TextAutosizer.cpp:
     62        (WebCore::TextAutosizer::processSubtree):
     63
     64            Use nextInPreOrderMatchingFilter instead of traverseNext, and some
     65            other methods that got renamed.
     66
     67        (WebCore::TextAutosizer::processBox):
     68
     69            Renamed from processBlock, since RenderBoxes are sufficient; use
     70            renamed nextInPreOrderMatchingFilter; make two calls to setMultiplier
     71            (one for parent for line height) instead of processText.
     72
     73        (WebCore::TextAutosizer::setMultiplier):
     74
     75            Simplified from previous processText method; this just sets the
     76            style's textAutosizingMultiplier (and the style does the rest).
     77
     78        (WebCore::TextAutosizer::isNotAnAutosizingContainer):
     79
     80            Renamed from treatAsInline; added explanatory comment; changed
     81            isRenderBlock to isBox as boxes still have logicalWidth; changed
     82            isInlineBlockOrInlineTable to isInline as it was an omission that
     83            other inlines were allowed.
     84
     85        (WebCore::TextAutosizer::nextInPreOrderMatchingFilter):
     86
     87            Renamed from TextAutosizer::traverseNext.
     88
     89        (RenderObjectFilterFunctor):
     90
     91            Renamed from RenderObjectFilter to clafiry that it's a function ptr.
     92
     93        * rendering/TextAutosizer.h:
     94        (TextAutosizer): Previously mentioned renamings.
     95
     96        * rendering/mathml/RenderMathMLSubSup.cpp:
     97        (WebCore::RenderMathMLSubSup::fixScriptsStyle):
     98
     99            Adjust for renamed setBlendedFontSize.
     100
     101        * rendering/style/RenderStyle.cpp:
     102        (WebCore::RenderStyle::diff):
     103
     104            textAutosizingMultiplier is a StyleDifferenceLayout (we want
     105            setNeedsLayoutAndPrefWidthsRecalc to get called).
     106
     107        (WebCore::RenderStyle::setFontSize):
     108
     109            Renamed from setBlendedFontSize; if Text Autosizing is enabled and a
     110            multiplier is set it auto-calculates the computedSize; float
     111            param instead of int as discussed on webkit.org/b/91660.
     112
     113        * rendering/style/RenderStyle.h:
     114
     115            Added specifiedFontSize, computedFontSize and specifiedLineHeight
     116            getters; changed lineHeight to dynamically calculate autosized line
     117            height, and made computedLineHeight use this value instead of the
     118            specified line height; also added textAutosizingMultiplier
     119            getter/setter (the setter updated the font description's computed
     120            size, by calling setFontSize); also renamed the parameter to
     121            setLineHeight to explicitly note that it's setting the
     122            specifiedLineHeight (and can still be adjusted by autosizing).
     123
     124        * rendering/style/StyleVisualData.cpp/.h:
     125
     126            Added m_textAutosizingMultiplier (this seems the best place to put a
     127            non-inherited non-rare presentational property).
     128
    11292012-08-17  Raphael Kubo da Costa  <rakuco@webkit.org>
    2130
  • trunk/Source/WebCore/css/StyleBuilder.cpp

    r125716 r125925  
    12121212
    12131213        if (primitiveValue->getIdent() == CSSValueNormal)
    1214             lineHeight = Length(-100.0, Percent);
     1214            lineHeight = RenderStyle::initialLineHeight();
    12151215        else if (primitiveValue->isLength()) {
    12161216            double multiplier = styleResolver->style()->effectiveZoom();
     
    12341234    static PropertyHandler createHandler()
    12351235    {
    1236         PropertyHandler handler = ApplyPropertyDefaultBase<Length, &RenderStyle::lineHeight, Length, &RenderStyle::setLineHeight, Length, &RenderStyle::initialLineHeight>::createHandler();
     1236        PropertyHandler handler = ApplyPropertyDefaultBase<Length, &RenderStyle::specifiedLineHeight, Length, &RenderStyle::setLineHeight, Length, &RenderStyle::initialLineHeight>::createHandler();
    12371237        return PropertyHandler(handler.inheritFunction(), handler.initialFunction(), &applyValue);
    12381238    }
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r125716 r125925  
    36703670        if (isInherit) {
    36713671            FontDescription fontDescription = m_parentStyle->fontDescription();
    3672             m_style->setLineHeight(m_parentStyle->lineHeight());
     3672            m_style->setLineHeight(m_parentStyle->specifiedLineHeight());
    36733673            m_lineHeightValue = 0;
    36743674            setFontDescription(fontDescription);
  • trunk/Source/WebCore/page/animation/CSSPropertyAnimation.cpp

    r120780 r125925  
    10881088    gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers));
    10891089
    1090     gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyFontSize, &RenderStyle::fontSize, &RenderStyle::setBlendedFontSize));
     1090    gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyFontSize,
     1091        // Must pass a specified size to setFontSize if Text Autosizing is enabled, but a computed size
     1092        // if text zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
     1093        // FIXME: Find some way to assert that text zoom isn't activated when Text Autosizing is compiled in.
     1094#if ENABLE(TEXT_AUTOSIZING)
     1095        &RenderStyle::specifiedFontSize,
     1096#else
     1097        &RenderStyle::computedFontSize,
     1098#endif
     1099        &RenderStyle::setFontSize));
    10911100    gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth));
    10921101    gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap));
     
    10961105    gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing));
    10971106    gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex));
    1098     gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::lineHeight, &RenderStyle::setLineHeight));
     1107    gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight));
    10991108    gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset));
    11001109    gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth));
  • trunk/Source/WebCore/platform/blackberry/RenderThemeBlackBerry.cpp

    r125811 r125925  
    789789        style->setHeight(controlsHeight);
    790790        style->setPaddingRight(padding);
    791         style->setBlendedFontSize(fontSize);
     791        style->setFontSize(static_cast<int>(fontSize));
    792792        break;
    793793    case MediaVolumeSliderContainerPart:
  • trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp

    r125648 r125925  
    352352    // Do not allow line-height to be smaller than our default.
    353353    if (textBlockStyle->fontMetrics().lineSpacing() > lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes))
    354         textBlockStyle->setLineHeight(Length(-100.0f, Percent));
     354        textBlockStyle->setLineHeight(RenderStyle::initialLineHeight());
    355355
    356356    textBlockStyle->setDisplay(BLOCK);
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r124372 r125925  
    2828#include "InspectorInstrumentation.h"
    2929#include "RenderObject.h"
     30#include "RenderStyle.h"
    3031#include "RenderText.h"
    3132#include "RenderView.h"
     
    5758    }
    5859
    59     for (RenderObject* descendant = traverseNext(layoutRoot, layoutRoot); descendant; descendant = traverseNext(descendant, layoutRoot)) {
    60         if (!treatAsInline(descendant))
    61             processBlock(toRenderBlock(descendant), windowSize);
     60    for (RenderObject* descendant = layoutRoot->nextInPreOrder(layoutRoot); descendant; descendant = descendant->nextInPreOrder(layoutRoot)) {
     61        if (isNotAnAutosizingContainer(descendant))
     62            continue;
     63        processBox(toRenderBox(descendant), windowSize);
    6264    }
    6365
     
    6567}
    6668
    67 void TextAutosizer::processBlock(RenderBlock* block, const IntSize& windowSize)
     69void TextAutosizer::processBox(RenderBox* box, const IntSize& windowSize)
    6870{
    69     int windowLogicalWidth = block->isHorizontalWritingMode() ? windowSize.width() : windowSize.height();
    70     float multiplier = static_cast<float>(block->logicalWidth()) / windowLogicalWidth; // FIXME: This is overly simplistic.
     71    int windowLogicalWidth = box->isHorizontalWritingMode() ? windowSize.width() : windowSize.height();
     72    float multiplier = static_cast<float>(box->logicalWidth()) / windowLogicalWidth; // FIXME: This is overly simplistic.
    7173    multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
    7274
    7375    if (multiplier < 1)
    7476        return;
    75     for (RenderObject* descendant = traverseNext(block, block, treatAsInline); descendant; descendant = traverseNext(descendant, block, treatAsInline)) {
    76         if (descendant->isText())
    77             processText(toRenderText(descendant), multiplier);
     77    RenderObject* descendant = nextInPreOrderMatchingFilter(box, box, isNotAnAutosizingContainer);
     78    while (descendant) {
     79        if (descendant->isText()) {
     80            setMultiplier(descendant, multiplier);
     81            setMultiplier(descendant->parent(), multiplier); // Parent does line spacing.
     82            // FIXME: Increase list marker size proportionately.
     83        }
     84        descendant = nextInPreOrderMatchingFilter(descendant, box, isNotAnAutosizingContainer);
    7885    }
    7986}
    8087
    81 void TextAutosizer::processText(RenderText* text, float multiplier)
     88void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier)
    8289{
    83     float specifiedSize = text->style()->fontDescription().specifiedSize();
    84     float newSize = specifiedSize * multiplier; // FIXME: This is overly simplistic.
    85 
    86     RefPtr<RenderStyle> style = RenderStyle::clone(text->style());
    87     FontDescription fontDescription(style->fontDescription());
    88     fontDescription.setComputedSize(newSize);
    89     style->setFontDescription(fontDescription);
    90     style->font().update(style->font().fontSelector());
    91     text->setStyle(style.release());
    92 
    93     // FIXME: Increase computed line height proportionately.
    94     // FIXME: Increase list marker size proportionately.
     90    RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style());
     91    newStyle->setTextAutosizingMultiplier(multiplier);
     92    renderer->setStyle(newStyle.release());
    9593}
    9694
    97 bool TextAutosizer::treatAsInline(const RenderObject* renderer)
     95bool TextAutosizer::isNotAnAutosizingContainer(const RenderObject* renderer)
    9896{
    99     return !renderer->isRenderBlock() || renderer->isListItem() || renderer->isInlineBlockOrInlineTable();
     97    // "Autosizing containers" are the smallest unit for which we can enable/disable
     98    // Text Autosizing. A uniform text size multiplier is enforced within them.
     99    // - Must be RenderBoxes since they need a well-defined logicalWidth().
     100    // - Must not be inline, as different multipliers on one line looks terrible.
     101    // - Must not be list items, as items in the same list should look consistent.
     102    return !renderer->isBox() || renderer->isInline() || renderer->isListItem();
    100103}
    101104
    102 // FIXME: Consider making this a method on RenderObject if it remains this generic.
    103 RenderObject* TextAutosizer::traverseNext(RenderObject* current, const RenderObject* stayWithin, RenderObjectFilter filter)
     105RenderObject* TextAutosizer::nextInPreOrderMatchingFilter(RenderObject* current, const RenderObject* stayWithin, RenderObjectFilterFunctor filter)
    104106{
    105     for (RenderObject* child = current->firstChild(); child; child = child->nextSibling()) {
    106         if (!filter || filter(child)) {
    107             ASSERT(!stayWithin || child->isDescendantOf(stayWithin));
     107    for (RenderObject* child = current->firstChild(); child; child = child->nextSibling())
     108        if (filter(child))
    108109            return child;
    109         }
    110     }
    111110
    112     for (RenderObject* ancestor = current; ancestor; ancestor = ancestor->parent()) {
     111    for (const RenderObject* ancestor = current; ancestor; ancestor = ancestor->parent()) {
    113112        if (ancestor == stayWithin)
    114113            return 0;
    115         for (RenderObject* sibling = ancestor->nextSibling(); sibling; sibling = sibling->nextSibling()) {
    116             if (!filter || filter(sibling)) {
    117                 ASSERT(!stayWithin || sibling->isDescendantOf(stayWithin));
     114        for (RenderObject* sibling = ancestor->nextSibling(); sibling; sibling = sibling->nextSibling())
     115            if (filter(sibling))
    118116                return sibling;
    119             }
    120         }
    121117    }
    122118
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r121920 r125925  
    3737
    3838class Document;
    39 class RenderBlock;
     39class RenderBox;
    4040class RenderObject;
    4141class RenderStyle;
     
    5555    explicit TextAutosizer(Document*);
    5656
    57     void processBlock(RenderBlock*, const IntSize& windowSize);
    58     void processText(RenderText*, float multiplier);
     57    void processBox(RenderBox*, const IntSize& windowSize);
     58    void setMultiplier(RenderObject*, float);
    5959
    60     typedef bool (*RenderObjectFilter)(const RenderObject*);
    61     static bool treatAsInline(const RenderObject*);
     60    static bool isNotAnAutosizingContainer(const RenderObject*);
    6261
    63     RenderObject* traverseNext(RenderObject* current, const RenderObject* stayWithin, RenderObjectFilter = 0);
     62    typedef bool (*RenderObjectFilterFunctor)(const RenderObject*);
     63    // Use to traverse the tree of descendants, excluding any subtrees within that whose root doesn't pass the filter.
     64    static RenderObject* nextInPreOrderMatchingFilter(RenderObject* current, const RenderObject* stayWithin, RenderObjectFilterFunctor);
    6465
    6566    Document* m_document;
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp

    r124512 r125925  
    7272    scriptsStyle->setTextAlign(LEFT);
    7373    // Set this wrapper's font-size for its line-height & baseline position, for its children.
    74     scriptsStyle->setBlendedFontSize(static_cast<int>(0.75 * style()->fontSize()));
     74    scriptsStyle->setFontSize(static_cast<int>(0.75 * style()->fontSize()));
    7575}
    7676
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r125612 r125925  
    488488            return StyleDifferenceLayout;
    489489    }
     490
     491#if ENABLE(TEXT_AUTOSIZING)
     492    if (visual->m_textAutosizingMultiplier != other->visual->m_textAutosizingMultiplier)
     493        return StyleDifferenceLayout;
     494#endif
    490495
    491496    if (inherited->line_height != other->inherited->line_height
     
    11851190const FontMetrics& RenderStyle::fontMetrics() const { return inherited->font.fontMetrics(); }
    11861191const FontDescription& RenderStyle::fontDescription() const { return inherited->font.fontDescription(); }
     1192float RenderStyle::specifiedFontSize() const { return fontDescription().specifiedSize(); }
     1193float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
    11871194int RenderStyle::fontSize() const { return inherited->font.pixelSize(); }
    11881195
     
    11991206}
    12001207
    1201 Length RenderStyle::lineHeight() const { return inherited->line_height; }
    1202 void RenderStyle::setLineHeight(Length v) { SET_VAR(inherited, line_height, v); }
     1208Length RenderStyle::specifiedLineHeight() const { return inherited->line_height; }
     1209Length RenderStyle::lineHeight() const
     1210{
     1211    const Length& lh = inherited->line_height;
     1212#if ENABLE(TEXT_AUTOSIZING)
     1213    // Unlike fontDescription().computedSize() and hence fontSize(), this is
     1214    // recalculated on demand as we only store the specified line height.
     1215    // FIXME: Should consider scaling the fixed part of any calc expressions
     1216    // too, though this involves messily poking into CalcExpressionLength.
     1217    float multiplier = textAutosizingMultiplier();
     1218    if (multiplier > 1 && lh.isFixed())
     1219        return Length(lh.value() * multiplier, Fixed);
     1220#endif
     1221    return lh;
     1222}
     1223void RenderStyle::setLineHeight(Length specifiedLineHeight) { SET_VAR(inherited, line_height, specifiedLineHeight); }
    12031224
    12041225int RenderStyle::computedLineHeight(RenderView* renderView) const
    12051226{
    1206     const Length& lh = inherited->line_height;
     1227    const Length& lh = lineHeight();
    12071228
    12081229    // Negative value means the line height is not set. Use the font's built-in spacing.
     
    12221243void RenderStyle::setLetterSpacing(int v) { inherited.access()->font.setLetterSpacing(v); }
    12231244
    1224 void RenderStyle::setBlendedFontSize(int size)
    1225 {
     1245void RenderStyle::setFontSize(float size)
     1246{
     1247    // size must be specifiedSize if Text Autosizing is enabled, but computedSize if text
     1248    // zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
     1249
    12261250    FontSelector* currentFontSelector = font().fontSelector();
    12271251    FontDescription desc(fontDescription());
    12281252    desc.setSpecifiedSize(size);
    12291253    desc.setComputedSize(size);
     1254
     1255#if ENABLE(TEXT_AUTOSIZING)
     1256    float multiplier = textAutosizingMultiplier();
     1257    if (multiplier > 1) {
     1258        // FIXME: Large font sizes needn't be multiplied as much since they are already more legible.
     1259        desc.setComputedSize(size * multiplier);
     1260    }
     1261#endif
     1262
    12301263    setFontDescription(desc);
    12311264    font().update(currentFontSelector);
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r125612 r125925  
    598598    const FontMetrics& fontMetrics() const;
    599599    const FontDescription& fontDescription() const;
     600    float specifiedFontSize() const;
     601    float computedFontSize() const;
    600602    int fontSize() const;
     603
     604#if ENABLE(TEXT_AUTOSIZING)
     605    float textAutosizingMultiplier() const { return visual->m_textAutosizingMultiplier; }
     606#endif
    601607
    602608    Length textIndent() const { return rareInheritedData->indent; }
     
    614620    bool isLeftToRightDirection() const { return direction() == LTR; }
    615621
     622    Length specifiedLineHeight() const;
    616623    Length lineHeight() const;
    617624    int computedLineHeight(RenderView* = 0) const;
     
    11031110
    11041111    bool setFontDescription(const FontDescription&);
    1105 
    1106     // Only used for blending font sizes when animating, or MathML anonymous blocks.
    1107     void setBlendedFontSize(int);
     1112    // Only used for blending font sizes when animating, for MathML anonymous blocks, and for text autosizing.
     1113    void setFontSize(float);
     1114
     1115#if ENABLE(TEXT_AUTOSIZING)
     1116    void setTextAutosizingMultiplier(float v)
     1117    {
     1118        SET_VAR(visual, m_textAutosizingMultiplier, v)
     1119        setFontSize(fontDescription().specifiedSize());
     1120    }
     1121#endif
    11081122
    11091123    void setColor(const Color&);
     
    11151129    void setTextDecoration(ETextDecoration v) { SET_VAR(visual, textDecoration, v); }
    11161130    void setDirection(TextDirection v) { inherited_flags._direction = v; }
    1117     void setLineHeight(Length);
     1131    void setLineHeight(Length specifiedLineHeight);
    11181132    bool setZoom(float);
    11191133    void setZoomWithoutReturnValue(float f) { setZoom(f); }
  • trunk/Source/WebCore/rendering/style/StyleVisualData.cpp

    r59629 r125925  
    3030    : hasClip(false)
    3131    , textDecoration(RenderStyle::initialTextDecoration())
     32#if ENABLE(TEXT_AUTOSIZING)
     33    , m_textAutosizingMultiplier(1)
     34#endif
    3235    , m_zoom(RenderStyle::initialZoom())
    3336{
     
    4346    , hasClip(o.hasClip)
    4447    , textDecoration(o.textDecoration)
     48#if ENABLE(TEXT_AUTOSIZING)
     49    , m_textAutosizingMultiplier(o.m_textAutosizingMultiplier)
     50#endif
    4551    , m_zoom(RenderStyle::initialZoom())
    4652{
  • trunk/Source/WebCore/rendering/style/StyleVisualData.h

    r97314 r125925  
    4141    bool operator==(const StyleVisualData& o) const
    4242    {
    43         return ( clip == o.clip &&
    44                  hasClip == o.hasClip &&
    45                  textDecoration == o.textDecoration &&
    46                  m_zoom == o.m_zoom);
     43        return clip == o.clip
     44            && hasClip == o.hasClip
     45            && textDecoration == o.textDecoration
     46#if ENABLE(TEXT_AUTOSIZING)
     47            && m_textAutosizingMultiplier == o.m_textAutosizingMultiplier
     48#endif
     49            && m_zoom == o.m_zoom;
    4750    }
    4851    bool operator!=(const StyleVisualData& o) const { return !(*this == o); }
     
    5154    bool hasClip : 1;
    5255    unsigned textDecoration : ETextDecorationBits; // Text decorations defined *only* by this element.
    53    
     56
     57#if ENABLE(TEXT_AUTOSIZING)
     58    float m_textAutosizingMultiplier;
     59#endif
    5460    float m_zoom;
    5561
Note: See TracChangeset for help on using the changeset viewer.