Add support for the initial-letter CSS property to first-letter
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Sep 2014 19:26:38 +0000 (19:26 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Sep 2014 19:26:38 +0000 (19:26 +0000)
commit37487a2d5afb81ceef510f46f861dc34b3ca7fae
tree59c43f8eab15fa89c2111b44f8c5d064be3797a7
parentbb029a1fcfd470779a14e07ec7e12243d3c7bc99
Add support for the initial-letter CSS property to first-letter
https://bugs.webkit.org/show_bug.cgi?id=136484

Reviewed by Dean Jackson.
Source/WebCore:

New tests in fast/css-generated-content/initial-letter-*.html

This patch add support for the CSS initial-letter property, enabling
better drop caps support in WebKit. Letters size to a specified number of
paragraph lines, and align to the cap-height of the first line and the baseline
of the last line.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
Add -webkit-initial-letter to the list.

* css/CSSLineBoxContainValue.cpp:
(WebCore::CSSLineBoxContainValue::customCSSText):
* css/CSSLineBoxContainValue.h:
Add support for a new value of line-box-contain, initial-letter, that causes
lines to use cap-height above the baseline and the glyph bounds below the
baseline.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
Add support for parsing of initial-letter.

(WebCore::CSSParser::parseLineBoxContain):
Add the new line-box-contain value for first-letters with initial-letter set.

* css/CSSPropertyNames.in:
Add the new initial-letter property.

* css/CSSValueKeywords.in:
Add the new initial-letter line-box-contain value.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyProperty):
Map initial-letter into the RenderStyle.

* platform/graphics/FontMetrics.h:
(WebCore::FontMetrics::hasCapHeight):
(WebCore::FontMetrics::floatCapHeight):
(WebCore::FontMetrics::setCapHeight):
(WebCore::FontMetrics::capHeight):
* platform/graphics/ios/SimpleFontDataIOS.mm:
(WebCore::SimpleFontData::platformInit):
* platform/graphics/mac/SimpleFontDataMac.mm:
(WebCore::SimpleFontData::platformInit):
Add support for cap-height to the font system. iOS and Mac have been patched.
Other platforms will need to add support for cap-height to get this feature.
hasCapHeight() will return false for unsupported platforms for graceful
degradation.

* rendering/RenderBlock.cpp:
(WebCore::styleForFirstLetter):
Modified to check for initialLetterDrop/Height and to adjust the style
accordingly (e.g., to apply float when needed).

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::computeLogicalLocationForFloat):
Code to adjust the float's position and margin to do cap-height alignment
and sunken letters.

* rendering/RenderBlockFlow.h:
Remove the const from computeLogicalLocationForFloat, since the margin of the
float can now be modified dynamically for sunken first-letters.

* rendering/RootInlineBox.cpp:
(WebCore::RootInlineBox::ascentAndDescentForBox):
Add support for initial-letter line-box-contain value.

* rendering/RootInlineBox.h:
Add the includeInitialLetterForBox method to support the new line-box-contain value.

* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::changeRequiresLayout):
* rendering/style/RenderStyle.h:
* rendering/style/StyleRareNonInheritedData.cpp:
(WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
(WebCore::StyleRareNonInheritedData::operator==):
* rendering/style/StyleRareNonInheritedData.h:
Normal maintenance stuff for addition of a new CSS property (making sure it is diffed
properly for layout changes and copied on assignment, etc.)

LayoutTests:

* fast/css-generated-content/initial-letter-basic.html: Added.
* fast/css-generated-content/initial-letter-border-padding.html: Added.
* fast/css-generated-content/initial-letter-descender.html: Added.
* fast/css-generated-content/initial-letter-raised.html: Added.
* fast/css-generated-content/initial-letter-sunken.html: Added.
* platform/mac/fast/css-generated-content/initial-letter-basic-expected.png: Added.
* platform/mac/fast/css-generated-content/initial-letter-basic-expected.txt: Added.
* platform/mac/fast/css-generated-content/initial-letter-border-padding-expected.png: Added.
* platform/mac/fast/css-generated-content/initial-letter-border-padding-expected.txt: Added.
* platform/mac/fast/css-generated-content/initial-letter-descender-expected.png: Added.
* platform/mac/fast/css-generated-content/initial-letter-descender-expected.txt: Added.
* platform/mac/fast/css-generated-content/initial-letter-raised-expected.png: Added.
* platform/mac/fast/css-generated-content/initial-letter-raised-expected.txt: Added.
* platform/mac/fast/css-generated-content/initial-letter-sunken-expected.png: Added.
* platform/mac/fast/css-generated-content/initial-letter-sunken-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173217 268f45cc-cd09-0410-ab3c-d52691b4dbfc
37 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css-generated-content/initial-letter-basic.html [new file with mode: 0644]
LayoutTests/fast/css-generated-content/initial-letter-border-padding.html [new file with mode: 0644]
LayoutTests/fast/css-generated-content/initial-letter-descender.html [new file with mode: 0644]
LayoutTests/fast/css-generated-content/initial-letter-raised.html [new file with mode: 0644]
LayoutTests/fast/css-generated-content/initial-letter-sunken.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-basic-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-basic-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-border-padding-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-border-padding-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-descender-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-descender-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-raised-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-raised-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-sunken-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-sunken-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSLineBoxContainValue.cpp
Source/WebCore/css/CSSLineBoxContainValue.h
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/platform/graphics/FontMetrics.h
Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm
Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockFlow.h
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RootInlineBox.cpp
Source/WebCore/rendering/RootInlineBox.h
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp
Source/WebCore/rendering/style/StyleRareNonInheritedData.h