Move 'font-family' CSS property to the new StyleBuilder
https://bugs.webkit.org/show_bug.cgi?id=139172

Reviewed by Antti Koivisto.

Move 'font-family' CSS property to the new StyleBuilder by using
custom code.

No new tests, no behavior change.

* css/CSSPropertyNames.in:
* css/DeprecatedStyleBuilder.cpp:
(WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):
(WebCore::ApplyPropertyFontFamily::applyInheritValue): Deleted.
(WebCore::ApplyPropertyFontFamily::applyInitialValue): Deleted.
(WebCore::ApplyPropertyFontFamily::applyValue): Deleted.
(WebCore::ApplyPropertyFontFamily::createHandler): Deleted.
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyInitialFontFamily):
(WebCore::StyleBuilderCustom::applyInheritFontFamily):
(WebCore::StyleBuilderCustom::applyValueFontFamily):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176657 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 8dc50eb..8d6d0c8 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,27 @@
+2014-12-02  Chris Dumez  <cdumez@apple.com>
+
+        Move 'font-family' CSS property to the new StyleBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=139172
+
+        Reviewed by Antti Koivisto.
+
+        Move 'font-family' CSS property to the new StyleBuilder by using
+        custom code.
+
+        No new tests, no behavior change.
+
+        * css/CSSPropertyNames.in:
+        * css/DeprecatedStyleBuilder.cpp:
+        (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):
+        (WebCore::ApplyPropertyFontFamily::applyInheritValue): Deleted.
+        (WebCore::ApplyPropertyFontFamily::applyInitialValue): Deleted.
+        (WebCore::ApplyPropertyFontFamily::applyValue): Deleted.
+        (WebCore::ApplyPropertyFontFamily::createHandler): Deleted.
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::applyInitialFontFamily):
+        (WebCore::StyleBuilderCustom::applyInheritFontFamily):
+        (WebCore::StyleBuilderCustom::applyValueFontFamily):
+
 2014-12-02  Eva Balazsfalvi  <evab.u-szeged@partner.samsung.com>
 
         Fix class was previously declared as a struct warnings
diff --git a/Source/WebCore/css/CSSPropertyNames.in b/Source/WebCore/css/CSSPropertyNames.in
index b570d47..b583529 100644
--- a/Source/WebCore/css/CSSPropertyNames.in
+++ b/Source/WebCore/css/CSSPropertyNames.in
@@ -59,7 +59,7 @@
 direction [Inherited, Custom=Value]
 display [LegacyStyleBuilder]
 font [Inherited, LegacyStyleBuilder]
-font-family [Inherited, LegacyStyleBuilder]
+font-family [Inherited, Custom=All]
 font-size [Inherited, LegacyStyleBuilder]
 font-style [Inherited, LegacyStyleBuilder]
 font-variant [Inherited, LegacyStyleBuilder]
diff --git a/Source/WebCore/css/DeprecatedStyleBuilder.cpp b/Source/WebCore/css/DeprecatedStyleBuilder.cpp
index 262356e..98bda74 100644
--- a/Source/WebCore/css/DeprecatedStyleBuilder.cpp
+++ b/Source/WebCore/css/DeprecatedStyleBuilder.cpp
@@ -372,113 +372,6 @@
     static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
 };
 
-class ApplyPropertyFontFamily {
-public:
-    static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
-    {
-        FontDescription fontDescription = styleResolver->style()->fontDescription();
-        FontDescription parentFontDescription = styleResolver->parentStyle()->fontDescription();
-        
-        fontDescription.setGenericFamily(parentFontDescription.genericFamily());
-        fontDescription.setFamilies(parentFontDescription.families());
-        fontDescription.setIsSpecifiedFont(parentFontDescription.isSpecifiedFont());
-        styleResolver->setFontDescription(fontDescription);
-        return;
-    }
-
-    static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
-    {
-        FontDescription fontDescription = styleResolver->style()->fontDescription();
-        FontDescription initialDesc = FontDescription();
-        
-        // We need to adjust the size to account for the generic family change from monospace to non-monospace.
-        if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
-            styleResolver->setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, false, styleResolver->document()));
-        fontDescription.setGenericFamily(initialDesc.genericFamily());
-        if (!initialDesc.firstFamily().isEmpty())
-            fontDescription.setFamilies(initialDesc.families());
-
-        styleResolver->setFontDescription(fontDescription);
-        return;
-    }
-
-    static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
-    {
-        if (!is<CSSValueList>(*value))
-            return;
-
-        auto& valueList = downcast<CSSValueList>(*value);
-
-        FontDescription fontDescription = styleResolver->style()->fontDescription();
-        // Before mapping in a new font-family property, we should reset the generic family.
-        bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
-        fontDescription.setGenericFamily(FontDescription::NoFamily);
-
-        Vector<AtomicString> families;
-        families.reserveInitialCapacity(valueList.length());
-
-        for (unsigned i = 0; i < valueList.length(); ++i) {
-            CSSValue* item = valueList.item(i);
-            if (!is<CSSPrimitiveValue>(*item))
-                continue;
-            CSSPrimitiveValue& contentValue = downcast<CSSPrimitiveValue>(*item);
-            AtomicString face;
-            if (contentValue.isString())
-                face = contentValue.getStringValue();
-            else if (Settings* settings = styleResolver->document().settings()) {
-                switch (contentValue.getValueID()) {
-                case CSSValueWebkitBody:
-                    face = settings->standardFontFamily();
-                    break;
-                case CSSValueSerif:
-                    face = serifFamily;
-                    fontDescription.setGenericFamily(FontDescription::SerifFamily);
-                    break;
-                case CSSValueSansSerif:
-                    face = sansSerifFamily;
-                    fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
-                    break;
-                case CSSValueCursive:
-                    face = cursiveFamily;
-                    fontDescription.setGenericFamily(FontDescription::CursiveFamily);
-                    break;
-                case CSSValueFantasy:
-                    face = fantasyFamily;
-                    fontDescription.setGenericFamily(FontDescription::FantasyFamily);
-                    break;
-                case CSSValueMonospace:
-                    face = monospaceFamily;
-                    fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
-                    break;
-                case CSSValueWebkitPictograph:
-                    face = pictographFamily;
-                    fontDescription.setGenericFamily(FontDescription::PictographFamily);
-                    break;
-                default:
-                    break;
-                }
-            }
-
-            if (face.isEmpty())
-                continue;
-            if (families.isEmpty())
-                fontDescription.setIsSpecifiedFont(fontDescription.genericFamily() == FontDescription::NoFamily);
-            families.uncheckedAppend(face);
-        }
-
-        if (families.isEmpty())
-            return;
-        fontDescription.setFamilies(families);
-
-        if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize)
-            styleResolver->setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize, styleResolver->document()));
-
-        styleResolver->setFontDescription(fontDescription);
-    }
-
-    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
-};
-
 class ApplyPropertyFontSize {
 private:
     // When the CSS keyword "larger" is used, this function will attempt to match within the keyword
@@ -1147,7 +1040,6 @@
     setPropertyHandler(CSSPropertyCounterReset, ApplyPropertyCounter<Reset>::createHandler());
     setPropertyHandler(CSSPropertyCursor, ApplyPropertyCursor::createHandler());
     setPropertyHandler(CSSPropertyDisplay, ApplyPropertyDisplay::createHandler());
-    setPropertyHandler(CSSPropertyFontFamily, ApplyPropertyFontFamily::createHandler());
     setPropertyHandler(CSSPropertyFontSize, ApplyPropertyFontSize::createHandler());
     setPropertyHandler(CSSPropertyFontStyle, ApplyPropertyFont<FontItalic, &FontDescription::italic, &FontDescription::setItalic, FontItalicOff>::createHandler());
     setPropertyHandler(CSSPropertyFontVariant, ApplyPropertyFont<FontSmallCaps, &FontDescription::smallCaps, &FontDescription::setSmallCaps, FontSmallCapsOff>::createHandler());
diff --git a/Source/WebCore/css/StyleBuilderCustom.h b/Source/WebCore/css/StyleBuilderCustom.h
index 3fb8ac9..1bf172e 100644
--- a/Source/WebCore/css/StyleBuilderCustom.h
+++ b/Source/WebCore/css/StyleBuilderCustom.h
@@ -35,6 +35,7 @@
 #include "Frame.h"
 #include "LocaleToScriptMapping.h"
 #include "Rect.h"
+#include "StyleFontSizeFunctions.h"
 #include "StyleResolver.h"
 
 namespace WebCore {
@@ -116,6 +117,10 @@
     static void applyInheritWebkitBoxShadow(StyleResolver&);
     static void applyValueWebkitBoxShadow(StyleResolver&, CSSValue&);
 
+    static void applyInitialFontFamily(StyleResolver&);
+    static void applyInheritFontFamily(StyleResolver&);
+    static void applyValueFontFamily(StyleResolver&, CSSValue&);
+
 private:
     static void resetEffectiveZoom(StyleResolver&);
     static CSSToLengthConversionData csstoLengthConversionDataWithTextZoomFactor(StyleResolver&);
@@ -881,6 +886,100 @@
     applyTextOrBoxShadowValue<CSSPropertyWebkitBoxShadow>(styleResolver, value);
 }
 
+inline void StyleBuilderCustom::applyInitialFontFamily(StyleResolver& styleResolver)
+{
+    FontDescription fontDescription = styleResolver.style()->fontDescription();
+    FontDescription initialDesc = FontDescription();
+
+    // We need to adjust the size to account for the generic family change from monospace to non-monospace.
+    if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
+        styleResolver.setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, false, styleResolver.document()));
+    fontDescription.setGenericFamily(initialDesc.genericFamily());
+    if (!initialDesc.firstFamily().isEmpty())
+        fontDescription.setFamilies(initialDesc.families());
+
+    styleResolver.setFontDescription(fontDescription);
+}
+
+inline void StyleBuilderCustom::applyInheritFontFamily(StyleResolver& styleResolver)
+{
+    FontDescription fontDescription = styleResolver.style()->fontDescription();
+    FontDescription parentFontDescription = styleResolver.parentStyle()->fontDescription();
+
+    fontDescription.setGenericFamily(parentFontDescription.genericFamily());
+    fontDescription.setFamilies(parentFontDescription.families());
+    fontDescription.setIsSpecifiedFont(parentFontDescription.isSpecifiedFont());
+    styleResolver.setFontDescription(fontDescription);
+}
+
+inline void StyleBuilderCustom::applyValueFontFamily(StyleResolver& styleResolver, CSSValue& value)
+{
+    auto& valueList = downcast<CSSValueList>(value);
+
+    FontDescription fontDescription = styleResolver.style()->fontDescription();
+    // Before mapping in a new font-family property, we should reset the generic family.
+    bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
+    fontDescription.setGenericFamily(FontDescription::NoFamily);
+
+    Vector<AtomicString> families;
+    families.reserveInitialCapacity(valueList.length());
+
+    for (auto& item : valueList) {
+        auto& contentValue = downcast<CSSPrimitiveValue>(item.get());
+        AtomicString face;
+        if (contentValue.isString())
+            face = contentValue.getStringValue();
+        else if (Settings* settings = styleResolver.document().settings()) {
+            switch (contentValue.getValueID()) {
+            case CSSValueWebkitBody:
+                face = settings->standardFontFamily();
+                break;
+            case CSSValueSerif:
+                face = serifFamily;
+                fontDescription.setGenericFamily(FontDescription::SerifFamily);
+                break;
+            case CSSValueSansSerif:
+                face = sansSerifFamily;
+                fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
+                break;
+            case CSSValueCursive:
+                face = cursiveFamily;
+                fontDescription.setGenericFamily(FontDescription::CursiveFamily);
+                break;
+            case CSSValueFantasy:
+                face = fantasyFamily;
+                fontDescription.setGenericFamily(FontDescription::FantasyFamily);
+                break;
+            case CSSValueMonospace:
+                face = monospaceFamily;
+                fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
+                break;
+            case CSSValueWebkitPictograph:
+                face = pictographFamily;
+                fontDescription.setGenericFamily(FontDescription::PictographFamily);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (face.isEmpty())
+            continue;
+        if (families.isEmpty())
+            fontDescription.setIsSpecifiedFont(fontDescription.genericFamily() == FontDescription::NoFamily);
+        families.uncheckedAppend(face);
+    }
+
+    if (families.isEmpty())
+        return;
+    fontDescription.setFamilies(families);
+
+    if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize)
+        styleResolver.setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize, styleResolver.document()));
+
+    styleResolver.setFontDescription(fontDescription);
+}
+
 } // namespace WebCore
 
 #endif // StyleBuilderCustom_h