Title: [103208] trunk/Source/WebCore
Revision
103208
Author
[email protected]
Date
2011-12-18 19:01:29 -0800 (Sun, 18 Dec 2011)

Log Message

Implement CSS font-size property in CSSStyleApplyProperty.
https://bugs.webkit.org/show_bug.cgi?id=74368

Reviewed by Andreas Kling.

No new tests / refactoring only.

* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyFontSize::largerFontSize):
(WebCore::ApplyPropertyFontSize::smallerFontSize):
(WebCore::ApplyPropertyFontSize::applyInheritValue):
(WebCore::ApplyPropertyFontSize::applyInitialValue):
(WebCore::ApplyPropertyFontSize::applyValue):
(WebCore::ApplyPropertyFontSize::createHandler):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
* css/CSSStyleSelector.h:
(WebCore::CSSStyleSelector::hasParentNode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103207 => 103208)


--- trunk/Source/WebCore/ChangeLog	2011-12-19 02:59:34 UTC (rev 103207)
+++ trunk/Source/WebCore/ChangeLog	2011-12-19 03:01:29 UTC (rev 103208)
@@ -1,3 +1,25 @@
+2011-12-18  Luke Macpherson   <[email protected]>
+
+        Implement CSS font-size property in CSSStyleApplyProperty.
+        https://bugs.webkit.org/show_bug.cgi?id=74368
+
+        Reviewed by Andreas Kling.
+
+        No new tests / refactoring only.
+
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyFontSize::largerFontSize):
+        (WebCore::ApplyPropertyFontSize::smallerFontSize):
+        (WebCore::ApplyPropertyFontSize::applyInheritValue):
+        (WebCore::ApplyPropertyFontSize::applyInitialValue):
+        (WebCore::ApplyPropertyFontSize::applyValue):
+        (WebCore::ApplyPropertyFontSize::createHandler):
+        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        * css/CSSStyleSelector.h:
+        (WebCore::CSSStyleSelector::hasParentNode):
+
 2011-12-18  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r103199.

Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (103207 => 103208)


--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-12-19 02:59:34 UTC (rev 103207)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-12-19 03:01:29 UTC (rev 103208)
@@ -578,6 +578,122 @@
     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
+    // table, and failing that, will simply multiply by 1.2.
+    static float largerFontSize(float size)
+    {
+        // FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) and scale up to
+        // the next size level.
+        return size * 1.2f;
+    }
+
+    // Like the previous function, but for the keyword "smaller".
+    static float smallerFontSize(float size)
+    {
+        // FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) and scale down to
+        // the next size level.
+        return size / 1.2f;
+    }
+public:
+    static void applyInheritValue(CSSStyleSelector* selector)
+    {
+        float size = selector->parentStyle()->fontDescription().specifiedSize();
+
+        if (size < 0)
+            return;
+
+        FontDescription fontDescription = selector->style()->fontDescription();
+        fontDescription.setKeywordSize(selector->parentStyle()->fontDescription().keywordSize());
+        selector->setFontSize(fontDescription, size);
+        selector->setFontDescription(fontDescription);
+        return;
+    }
+
+    static void applyInitialValue(CSSStyleSelector* selector)
+    {
+        FontDescription fontDescription = selector->style()->fontDescription();
+        float size = selector->fontSizeForKeyword(selector->document(), CSSValueMedium, fontDescription.useFixedDefaultSize());
+
+        if (size < 0)
+            return;
+
+        fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
+        selector->setFontSize(fontDescription, size);
+        selector->setFontDescription(fontDescription);
+        return;
+    }
+
+    static void applyValue(CSSStyleSelector* selector, CSSValue* value)
+    {
+        if (!value->isPrimitiveValue())
+            return;
+
+        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
+
+        FontDescription fontDescription = selector->style()->fontDescription();
+        fontDescription.setKeywordSize(0);
+        float parentSize = 0;
+        bool parentIsAbsoluteSize = false;
+        float size = 0;
+
+        if (selector->hasParentNode()) {
+            parentSize = selector->parentStyle()->fontDescription().specifiedSize();
+            parentIsAbsoluteSize = selector->parentStyle()->fontDescription().isAbsoluteSize();
+        }
+
+        if (int ident = primitiveValue->getIdent()) {
+            // Keywords are being used.
+            switch (ident) {
+            case CSSValueXxSmall:
+            case CSSValueXSmall:
+            case CSSValueSmall:
+            case CSSValueMedium:
+            case CSSValueLarge:
+            case CSSValueXLarge:
+            case CSSValueXxLarge:
+            case CSSValueWebkitXxxLarge:
+                size = selector->fontSizeForKeyword(selector->document(), ident, fontDescription.useFixedDefaultSize());
+                fontDescription.setKeywordSize(ident - CSSValueXxSmall + 1);
+                break;
+            case CSSValueLarger:
+                size = largerFontSize(parentSize);
+                break;
+            case CSSValueSmaller:
+                size = smallerFontSize(parentSize);
+                break;
+            default:
+                return;
+            }
+
+            fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize && (ident == CSSValueLarger || ident == CSSValueSmaller));
+        } else {
+            int type = primitiveValue->primitiveType();
+            fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize
+                                              || (type != CSSPrimitiveValue::CSS_PERCENTAGE
+                                                  && type != CSSPrimitiveValue::CSS_EMS
+                                                  && type != CSSPrimitiveValue::CSS_EXS
+                                                  && type != CSSPrimitiveValue::CSS_REMS));
+            if (primitiveValue->isLength())
+                size = primitiveValue->computeLength<float>(selector->parentStyle(), selector->rootElementStyle(), 1.0, true);
+            else if (primitiveValue->isPercentage())
+                size = (primitiveValue->getFloatValue() * parentSize) / 100.0f;
+            else
+                return;
+        }
+
+        if (size < 0)
+            return;
+
+        selector->setFontSize(fontDescription, size);
+        selector->setFontDescription(fontDescription);
+        return;
+    }
+
+    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
+};
+
 class ApplyPropertyFontWeight {
 public:
     static void applyValue(CSSStyleSelector* selector, CSSValue* value)
@@ -1525,6 +1641,7 @@
     setPropertyHandler(CSSPropertyWebkitFlexWrap, ApplyPropertyDefault<EFlexWrap, &RenderStyle::flexWrap, EFlexWrap, &RenderStyle::setFlexWrap, EFlexWrap, &RenderStyle::initialFlexWrap>::createHandler());
     setPropertyHandler(CSSPropertyWebkitFlexFlow, ApplyPropertyExpanding<SuppressValue, CSSPropertyWebkitFlexDirection, CSSPropertyWebkitFlexWrap>::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());
     setPropertyHandler(CSSPropertyTextRendering, ApplyPropertyFont<TextRenderingMode, &FontDescription::textRenderingMode, &FontDescription::setTextRenderingMode, AutoTextRendering>::createHandler());

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (103207 => 103208)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-12-19 02:59:34 UTC (rev 103207)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-12-19 03:01:29 UTC (rev 103208)
@@ -2681,76 +2681,6 @@
     case CSSPropertyWebkitMatchNearestMailBlockquoteColor:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(matchNearestMailBlockquoteColor, MatchNearestMailBlockquoteColor)
         return;
-    case CSSPropertyFontSize:
-    {
-        FontDescription fontDescription = m_style->fontDescription();
-        fontDescription.setKeywordSize(0);
-        float oldSize = 0;
-        float size = 0;
-
-        bool parentIsAbsoluteSize = false;
-        if (m_parentNode) {
-            oldSize = m_parentStyle->fontDescription().specifiedSize();
-            parentIsAbsoluteSize = m_parentStyle->fontDescription().isAbsoluteSize();
-        }
-
-        if (isInherit) {
-            size = oldSize;
-            if (m_parentNode)
-                fontDescription.setKeywordSize(m_parentStyle->fontDescription().keywordSize());
-        } else if (isInitial) {
-            size = fontSizeForKeyword(m_checker.document(), CSSValueMedium, fontDescription.useFixedDefaultSize());
-            fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
-        } else if (primitiveValue->getIdent()) {
-            // Keywords are being used.
-            switch (primitiveValue->getIdent()) {
-                case CSSValueXxSmall:
-                case CSSValueXSmall:
-                case CSSValueSmall:
-                case CSSValueMedium:
-                case CSSValueLarge:
-                case CSSValueXLarge:
-                case CSSValueXxLarge:
-                case CSSValueWebkitXxxLarge:
-                    size = fontSizeForKeyword(m_checker.document(), primitiveValue->getIdent(), fontDescription.useFixedDefaultSize());
-                    fontDescription.setKeywordSize(primitiveValue->getIdent() - CSSValueXxSmall + 1);
-                    break;
-                case CSSValueLarger:
-                    size = largerFontSize(oldSize, m_checker.document()->inQuirksMode());
-                    break;
-                case CSSValueSmaller:
-                    size = smallerFontSize(oldSize, m_checker.document()->inQuirksMode());
-                    break;
-                default:
-                    return;
-            }
-
-            fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize
-                                              && (primitiveValue->getIdent() == CSSValueLarger
-                                                  || primitiveValue->getIdent() == CSSValueSmaller));
-        } else {
-            int type = primitiveValue->primitiveType();
-            fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize
-                                              || (type != CSSPrimitiveValue::CSS_PERCENTAGE
-                                                  && type != CSSPrimitiveValue::CSS_EMS
-                                                  && type != CSSPrimitiveValue::CSS_EXS
-                                                  && type != CSSPrimitiveValue::CSS_REMS));
-            if (CSSPrimitiveValue::isUnitTypeLength(type))
-                size = primitiveValue->computeLength<float>(m_parentStyle, m_rootElementStyle, 1.0, true);
-            else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
-                size = (primitiveValue->getFloatValue() * oldSize) / 100.0f;
-            else
-                return;
-        }
-
-        if (size < 0)
-            return;
-
-        setFontSize(fontDescription, size);
-        setFontDescription(fontDescription);
-        return;
-    }
-
     case CSSPropertyWidows:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(widows, Widows)
         return;
@@ -3801,6 +3731,7 @@
     case CSSPropertyWebkitFlexDirection:
     case CSSPropertyWebkitFlexFlow:
     case CSSPropertyWebkitFlexWrap:
+    case CSSPropertyFontSize:
     case CSSPropertyFontStyle:
     case CSSPropertyFontVariant:
     case CSSPropertyTextRendering:
@@ -4729,20 +4660,6 @@
     return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, mediumSize);
 }
 
-float CSSStyleSelector::largerFontSize(float size, bool) const
-{
-    // FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) and scale up to
-    // the next size level.
-    return size * 1.2f;
-}
-
-float CSSStyleSelector::smallerFontSize(float size, bool) const
-{
-    // FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) and scale down to
-    // the next size level.
-    return size / 1.2f;
-}
-
 static Color colorForCSSValue(int cssValueId)
 {
     struct ColorValue {

Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (103207 => 103208)


--- trunk/Source/WebCore/css/CSSStyleSelector.h	2011-12-19 02:59:34 UTC (rev 103207)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h	2011-12-19 03:01:29 UTC (rev 103208)
@@ -126,6 +126,7 @@
     void setZoom(float f) { m_fontDirty |= style()->setZoom(f); }
     void setEffectiveZoom(float f) { m_fontDirty |= style()->setEffectiveZoom(f); }
     void setTextSizeAdjust(bool b) { m_fontDirty |= style()->setTextSizeAdjust(b); }
+    bool hasParentNode() const { return m_parentNode; }
 
 private:
     void initForStyleResolve(Element*, RenderStyle* parentStyle = 0, PseudoId = NOPSEUDO);
@@ -163,15 +164,6 @@
     // Given a font size in pixel, this function will return legacy font size between 1 and 7.
     static int legacyFontSize(Document*, int pixelFontSize, bool shouldUseFixedDefaultSize);
 
-private:
-
-    // When the CSS keyword "larger" is used, this function will attempt to match within the keyword
-    // table, and failing that, will simply multiply by 1.2.
-    float largerFontSize(float size, bool quirksMode) const;
-
-    // Like the previous function, but for the keyword "smaller".
-    float smallerFontSize(float size, bool quirksMode) const;
-
 public:
     void setStyle(PassRefPtr<RenderStyle> s) { m_style = s; } // Used by the document when setting up its root style.
 
@@ -183,9 +175,9 @@
 
     static float getComputedSizeFromSpecifiedSize(Document*, float zoomFactor, bool isAbsoluteSize, float specifiedSize, ESmartMinimumForFontSize = UseSmartMinimumForFontFize);
 
-private:
     void setFontSize(FontDescription&, float size);
 
+private:
     static float getComputedSizeFromSpecifiedSize(Document*, RenderStyle*, bool isAbsoluteSize, float specifiedSize, bool useSVGZoomRules);
 
 public:
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to