Remove 'font' shorthand property special casing
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Jan 2015 02:11:14 +0000 (02:11 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Jan 2015 02:11:14 +0000 (02:11 +0000)
commitb4aecc5da9143c48758bdb209d2c001e2ec0e46a
treea484764b1f3102ee7a0c942a9006f28290334099
parent9947f4903d7682bee9809e9cdec7fa74b6a95994
Remove 'font' shorthand property special casing
https://bugs.webkit.org/show_bug.cgi?id=140577

Reviewed by Darin Adler.

Source/WebCore:

Expand system font values during 'font' property parsing. The 'font'
CSS property was the only shorthand that wasn't always expanded in
the CSS parser, so it needed a lot of special handling that we can
now get rid of.

This patch is inspired from the following Blink revision:
https://src.chromium.org/viewvc/blink?view=rev&revision=184449

Tests:
- fast/css/css2-system-fonts.html (existing)
- fast/css/CSSPrimitiveValue-font-family-primitiveType.html (new)
- fast/css/font-systemFontID-parsing.html (new)
- fast/css/font-shorthand-line-height.html (rebased)

* WebCore.xcodeproj/project.pbxproj:
* css/CSSCalculationValue.cpp:
(WebCore::hasDoubleValue):
Handle CSS_FONT_FAMILY similarly to CSS_STRING in the switch.

* css/CSSFontFamily.h: Added.
Introduce new CSSFontFamily class to store font families inside
CSSPrimitive, instead of using a simple String as previously. We need
an additional 'fromSystemFontID' flag in addition to the font family
name now that system font ID are expanded during parsing. This
information is needed later on by the StyleBuilder (see comment below).

* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::addFontFaceRule):
Update code dealing with font family CSSPrimitiveValues now that they
hold a CSSFontFamily internally instead of a String.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseSystemFont):
Expand system font values for the 'font' property by asking the
RenderTheme for the system font and using it to set the 'font'
longhand properties.

* css/CSSParserValues.cpp:
(WebCore::CSSParserValue::createCSSValue):
Handle CSS_FONT_FAMILY value in the switch.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::primitiveType):
Make sure we still expose font family CSSPrimitiveValues to the Web as
CSS_STRING, even though we are using a slightly different representation
internally. This is so that we don't change web-exposed behavior and I
added a new layout test to cover this.

(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::CSSPrimitiveValue::cleanup):
(WebCore::CSSPrimitiveValue::getStringValue):
(WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText):
(WebCore::CSSPrimitiveValue::cloneForCSSOM):
(WebCore::CSSPrimitiveValue::equals):
Handle CSS_FONT_FAMILY type in switches.

* css/CSSPrimitiveValue.h:
(WebCore::CSSPrimitiveValue::isFontFamily):
Add method to test if a CSSPrimitiveValue holds a CSSFontFamily
internally.

(WebCore::CSSPrimitiveValue::fontFamily):
Add a getter to retrieve the internal CSSFontFamily object if the
primitive type is CSS_FONT_FAMILY.

* css/CSSPropertyNames.in:
Treat 'font' as a regular shorthand property. Specify its longhand
properties so that makeprop.pl can generate the shorthand code for
us. Also demote 'font' to being a low-priority property as it is
now always expanded during parsing.

* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::createFontFamilyValue):
* css/CSSValuePool.h:
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyValueFontFamily):
- Update the 'font-family' value setter in the StyleBuilder to reflect
the changes in the CSS parser. The CSSPrimitiveValues in the list now
have CSS_FONT_FAMILY type instead of CSS_STRING.
- We also set the 'isGenericFamily' flag if the font-family was expanded
  from a system font ID (e.g. caption). The 'isGenericFamily' flag is
  used later on to property set the 'isSpecifiedFont' flag on the
  FontDescription object. If we don't do this, system font values will
  be treated as specified fonts, which means that we will no longer use
  the 'use backslash as Yen sign' hack for those. This is covered by the
  following layout tests:
  - fast/text/backslash-to-yen-sign-euc.html
  - editing/selection/find-yensign-and-backslash.html

(WebCore::StyleBuilderCustom::applyInitialFont): Deleted.
(WebCore::StyleBuilderCustom::applyInheritFont): Deleted.
(WebCore::StyleBuilderCustom::applyValueFont): Deleted.
Remove StyleBuilder code dealing with the 'font' property. Now that
the 'font' property is always expanded during parsing, this code can
never be reached.

* css/StylePropertyShorthand.cpp:
(WebCore::isExpandedShorthand):
Stop returning false for 'font' as it is now expanded during parsing
as well. We should probably consider renaming this method to something
else now that all shorthands are expanded, maybe isCSSShorthand() or
isShorthandProperty().

(WebCore::fontShorthand): Deleted.
* css/StylePropertyShorthand.h:
(WebCore::matchingCustomShorthandsForLonghand): Deleted.
Remove custom shorthand code for the 'font' property as it is now
generated by makeprop.pl, like other shorthands.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyFont): Deleted.
This is unused now that the StyleBuilder code for 'font' has been
removed.

* css/makeprop.pl:
Remove custom shorthand code for 'font' as it no longer requires any
special handling.

LayoutTests:

* fast/css/CSSPrimitiveValue-font-family-primitiveType-expected.txt: Added.
* fast/css/CSSPrimitiveValue-font-family-primitiveType.html: Added.
Add layout test to make sure that the font-family is still exposed to the
Web as a CSSValueList of CSSPrimitiveValues whose primitiveType is
CSS_STRING. This is useful because we now use a slightly different
representation internally.

* fast/css/font-shorthand-line-height-expected.txt:
* fast/css/font-shorthand-line-height.html:
Rebaseline the test. This is a progression. Setting the 'font' property
to a system font ID is supposed to reset the line-height property to
'normal'. It previously did not because system font IDs were not
expanded at parsing time. The new behavior is consistent with Chrome and
Firefox as well.

* fast/css/font-systemFontID-parsing-expected.txt: Added.
* fast/css/font-systemFontID-parsing.html: Added.
Add a layout test to make sure that the CSS parser is rejecting a 'font'
property with more than one system font id.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179100 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/CSSPrimitiveValue-font-family-primitiveType-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/CSSPrimitiveValue-font-family-primitiveType.html [new file with mode: 0644]
LayoutTests/fast/css/font-shorthand-line-height-expected.txt
LayoutTests/fast/css/font-shorthand-line-height.html
LayoutTests/fast/css/font-systemFontID-parsing-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/font-systemFontID-parsing.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSCalculationValue.cpp
Source/WebCore/css/CSSFontFamily.h [new file with mode: 0644]
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h
Source/WebCore/css/CSSParserValues.cpp
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/CSSPrimitiveValue.h
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/CSSValuePool.cpp
Source/WebCore/css/CSSValuePool.h
Source/WebCore/css/StyleBuilderCustom.h
Source/WebCore/css/StylePropertyShorthand.cpp
Source/WebCore/css/StylePropertyShorthand.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/StyleResolver.h
Source/WebCore/css/makeprop.pl