Text Autosizing: Increase line height in proportion to font size.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Aug 2012 19:17:54 +0000 (19:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Aug 2012 19:17:54 +0000 (19:17 +0000)
commit8111125cd93744366fbd966245384e5b3e76f1e7
tree15da5dd875c1d05d8f9527faeea1a83c89a89b14
parente0f76a4457bb0abdc7d2935c526226c0c9f2bf84
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125925 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text-autosizing/em-margin-border-padding-expected.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/em-margin-border-padding.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/font-scale-factor-expected.html
LayoutTests/fast/text-autosizing/font-scale-factor.html
LayoutTests/fast/text-autosizing/narrow-child-expected.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/narrow-child.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/nested-em-line-height-expected.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/nested-em-line-height.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/simple-paragraph-expected.html
LayoutTests/fast/text-autosizing/simple-paragraph.html
LayoutTests/fast/text-autosizing/span-child-expected.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/span-child.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/wide-child-expected.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/wide-child.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/StyleBuilder.cpp
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/page/animation/CSSPropertyAnimation.cpp
Source/WebCore/platform/blackberry/RenderThemeBlackBerry.cpp
Source/WebCore/rendering/RenderTextControlSingleLine.cpp
Source/WebCore/rendering/TextAutosizer.cpp
Source/WebCore/rendering/TextAutosizer.h
Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/StyleVisualData.cpp
Source/WebCore/rendering/style/StyleVisualData.h