Get rid of custom StyleBuilder code for 'line-height' CSS property
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Jan 2015 17:20:44 +0000 (17:20 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Jan 2015 17:20:44 +0000 (17:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140462

Reviewed by Antti Koivisto.

Get rid of custom StyleBuilder code for 'line-height' CSS property by
using a conditional converter.

* css/CSSPropertyNames.in:
* css/StyleBuilderConverter.h:
(WebCore::StyleBuilderConverter::convertLineHeight):
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyValueLineHeight):
(WebCore::StyleBuilderCustom::convertLineHeight): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@178512 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSPropertyNames.in
Source/WebCore/css/StyleBuilderConverter.h
Source/WebCore/css/StyleBuilderCustom.h

index d731fb8..32f15f9 100644 (file)
@@ -1,3 +1,20 @@
+2015-01-15  Chris Dumez  <cdumez@apple.com>
+
+        Get rid of custom StyleBuilder code for 'line-height' CSS property
+        https://bugs.webkit.org/show_bug.cgi?id=140462
+
+        Reviewed by Antti Koivisto.
+
+        Get rid of custom StyleBuilder code for 'line-height' CSS property by
+        using a conditional converter.
+
+        * css/CSSPropertyNames.in:
+        * css/StyleBuilderConverter.h:
+        (WebCore::StyleBuilderConverter::convertLineHeight):
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::applyValueLineHeight):
+        (WebCore::StyleBuilderCustom::convertLineHeight): Deleted.
+
 2015-01-15  Antti Koivisto  <antti@apple.com>
 
         Rename Font to FontCascade
index 1bd4dd8..082b3cc 100644 (file)
@@ -121,7 +121,7 @@ zoom [Custom=All]
 #if defined(ENABLE_IOS_TEXT_AUTOSIZING) && ENABLE_IOS_TEXT_AUTOSIZING
 line-height [Inherited, Custom=All]
 #else
-line-height [Inherited, Getter=specifiedLineHeight, Custom=Value]
+line-height [Inherited, Getter=specifiedLineHeight, ConditionalConverter=LineHeight]
 #endif
 
 // Keep this in between the highest priority props and the lower ones.
index 5cbfaf4..d53bd75 100644 (file)
@@ -123,6 +123,7 @@ public:
     static Color convertSVGColor(StyleResolver&, CSSValue&);
     static EGlyphOrientation convertGlyphOrientation(StyleResolver&, CSSValue&);
     static EGlyphOrientation convertGlyphOrientationOrAuto(StyleResolver&, CSSValue&);
+    static Optional<Length> convertLineHeight(StyleResolver&, CSSValue&, float multiplier = 1.f);
 
 private:
     friend class StyleBuilderCustom;
@@ -1211,6 +1212,29 @@ inline EGlyphOrientation StyleBuilderConverter::convertGlyphOrientationOrAuto(St
     return convertGlyphOrientation(styleResolver, value);
 }
 
+inline Optional<Length> StyleBuilderConverter::convertLineHeight(StyleResolver& styleResolver, CSSValue& value, float multiplier)
+{
+    auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
+    if (primitiveValue.getValueID() == CSSValueNormal)
+        return RenderStyle::initialLineHeight();
+
+    if (primitiveValue.isLength()) {
+        Length length = primitiveValue.computeLength<Length>(StyleBuilderConverter::csstoLengthConversionDataWithTextZoomFactor(styleResolver));
+        if (multiplier != 1.f)
+            length = Length(length.value() * multiplier, Fixed);
+        return length;
+    }
+    if (primitiveValue.isPercentage()) {
+        // FIXME: percentage should not be restricted to an integer here.
+        return Length((styleResolver.style()->computedFontSize() * primitiveValue.getIntValue()) / 100, Fixed);
+    }
+    if (primitiveValue.isNumber()) {
+        // FIXME: number and percentage values should produce the same type of Length (ie. Fixed or Percent).
+        return Length(primitiveValue.getDoubleValue() * multiplier * 100.0, Percent);
+    }
+    return Nullopt;
+}
+
 } // namespace WebCore
 
 #endif // StyleBuilderConverter_h
index 030b22d..61fc661 100644 (file)
@@ -116,9 +116,6 @@ public:
     // Custom handling of value setting only.
     static void applyValueBaselineShift(StyleResolver&, CSSValue&);
     static void applyValueDirection(StyleResolver&, CSSValue&);
-#if !ENABLE(IOS_TEXT_AUTOSIZING)
-    static void applyValueLineHeight(StyleResolver&, CSSValue&);
-#endif
     static void applyValueVerticalAlign(StyleResolver&, CSSValue&);
 #if ENABLE(DASHBOARD_SUPPORT)
     static void applyValueWebkitDashboardRegion(StyleResolver&, CSSValue&);
@@ -134,7 +131,6 @@ public:
 
 private:
     static void resetEffectiveZoom(StyleResolver&);
-    static bool convertLineHeight(StyleResolver&, const CSSValue&, Length&, float multiplier = 1.f);
 
     static Length mmLength(double mm);
     static Length inchLength(double inch);
@@ -606,32 +602,6 @@ DEFINE_BORDER_IMAGE_MODIFIER_HANDLER(WebkitMaskBoxImage, Repeat)
 DEFINE_BORDER_IMAGE_MODIFIER_HANDLER(WebkitMaskBoxImage, Slice)
 DEFINE_BORDER_IMAGE_MODIFIER_HANDLER(WebkitMaskBoxImage, Width)
 
-inline bool StyleBuilderCustom::convertLineHeight(StyleResolver& styleResolver, const CSSValue& value, Length& length, float multiplier)
-{
-    auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
-    if (primitiveValue.getValueID() == CSSValueNormal) {
-        length = RenderStyle::initialLineHeight();
-        return true;
-    }
-    if (primitiveValue.isLength()) {
-        length = primitiveValue.computeLength<Length>(StyleBuilderConverter::csstoLengthConversionDataWithTextZoomFactor(styleResolver));
-        if (multiplier != 1.f)
-            length = Length(length.value() * multiplier, Fixed);
-        return true;
-    }
-    if (primitiveValue.isPercentage()) {
-        // FIXME: percentage should not be restricted to an integer here.
-        length = Length((styleResolver.style()->computedFontSize() * primitiveValue.getIntValue()) / 100, Fixed);
-        return true;
-    }
-    if (primitiveValue.isNumber()) {
-        // FIXME: number and percentage values should produce the same type of Length (ie. Fixed or Percent).
-        length = Length(primitiveValue.getDoubleValue() * multiplier * 100.0, Percent);
-        return true;
-    }
-    return false;
-}
-
 #if ENABLE(IOS_TEXT_AUTOSIZING)
 
 inline void StyleBuilderCustom::applyInheritLineHeight(StyleResolver& styleResolver)
@@ -648,24 +618,13 @@ inline void StyleBuilderCustom::applyInitialLineHeight(StyleResolver& styleResol
 
 inline void StyleBuilderCustom::applyValueLineHeight(StyleResolver& styleResolver, CSSValue& value)
 {
-    Length lineHeight;
     float multiplier = styleResolver.style()->textSizeAdjust().isPercentage() ? styleResolver.style()->textSizeAdjust().multiplier() : 1.f;
-    if (!convertLineHeight(styleResolver, value, lineHeight, multiplier))
-        return;
-
-    styleResolver.style()->setLineHeight(lineHeight);
-    styleResolver.style()->setSpecifiedLineHeight(lineHeight);
-}
-
-#else
-
-inline void StyleBuilderCustom::applyValueLineHeight(StyleResolver& styleResolver, CSSValue& value)
-{
-    Length lineHeight;
-    if (!convertLineHeight(styleResolver, value, lineHeight))
+    Optional<Length> lineHeight = StyleBuilderConverter::convertLineHeight(styleResolver, value, multiplier);
+    if (!lineHeight)
         return;
 
-    styleResolver.style()->setLineHeight(lineHeight);
+    styleResolver.style()->setLineHeight(lineHeight.value());
+    styleResolver.style()->setSpecifiedLineHeight(lineHeight.value());
 }
 
 #endif