Title: [91038] trunk/Source/WebCore
Revision
91038
Author
[email protected]
Date
2011-07-14 18:28:54 -0700 (Thu, 14 Jul 2011)

Log Message

Reviewed by Dimitri Glazkov.

Introduce templated compute length class in CSSStyleApplyProperty, and use to handle several CSS properties.
https://bugs.webkit.org/show_bug.cgi?id=62957

No new tests / refactoring only.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeLength):
Add computeLength function that returns unsigned short.
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyComputeLength::ApplyPropertyComputeLength):
Added class to handle computeLength based properties.
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
Initialize ApplyPropertyComputeLength for appropriate properties.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::useSVGZoomRules):
Make this a public member function instead of a private static function.
(WebCore::CSSStyleSelector::applyProperty):
Removed code now implemented in CSSStyleApplyProperty.
(WebCore::CSSStyleSelector::setFontSize):
Use new useSVGZoomRules function.
* css/CSSStyleSelector.h:
Add interface for useSVGZoomRules.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (91037 => 91038)


--- trunk/Source/WebCore/ChangeLog	2011-07-14 23:48:51 UTC (rev 91037)
+++ trunk/Source/WebCore/ChangeLog	2011-07-15 01:28:54 UTC (rev 91038)
@@ -1,3 +1,30 @@
+2011-07-14  Luke Macpherson   <[email protected]>
+
+        Reviewed by Dimitri Glazkov.
+
+        Introduce templated compute length class in CSSStyleApplyProperty, and use to handle several CSS properties.
+        https://bugs.webkit.org/show_bug.cgi?id=62957
+
+        No new tests / refactoring only.
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::computeLength):
+        Add computeLength function that returns unsigned short.
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyComputeLength::ApplyPropertyComputeLength):
+        Added class to handle computeLength based properties.
+        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
+        Initialize ApplyPropertyComputeLength for appropriate properties.
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::useSVGZoomRules):
+        Make this a public member function instead of a private static function.
+        (WebCore::CSSStyleSelector::applyProperty):
+        Removed code now implemented in CSSStyleApplyProperty.
+        (WebCore::CSSStyleSelector::setFontSize):
+        Use new useSVGZoomRules function.
+        * css/CSSStyleSelector.h:
+        Add interface for useSVGZoomRules.
+
 2011-07-14  Antti Koivisto  <[email protected]>
 
         REGRESSION: Should not dispatch didFirstVisuallyNonEmptyLayout for the initial empty document

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (91037 => 91038)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2011-07-14 23:48:51 UTC (rev 91037)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2011-07-15 01:28:54 UTC (rev 91038)
@@ -291,6 +291,11 @@
     return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
 }
 
+template<> unsigned short CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
+{
+    return roundForImpreciseConversion<unsigned short, USHRT_MAX, 0>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
+}
+
 template<> float CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
 {
     return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));

Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (91037 => 91038)


--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-07-14 23:48:51 UTC (rev 91037)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-07-15 01:28:54 UTC (rev 91038)
@@ -189,7 +189,6 @@
     InitialFunction m_initial;
 };
 
-// CSSPropertyDirection
 class ApplyPropertyDirection : public ApplyPropertyDefault<TextDirection> {
 public:
     ApplyPropertyDirection(GetterFunction getter, SetterFunction setter, InitialFunction initial)
@@ -387,42 +386,48 @@
     void (CSSStyleSelector::*m_mapFill)(CSSPropertyID, FillLayer*, CSSValue*);
 };
 
-class ApplyPropertyWidth : public ApplyPropertyDefaultBase<unsigned short> {
+enum ComputeLengthNormal {NormalDisabled = 0, NormalEnabled};
+enum ComputeLengthThickness {ThicknessDisabled = 0, ThicknessEnabled};
+enum ComputeLengthSVGZoom {SVGZoomDisabled = 0, SVGZoomEnabled};
+template <typename T,
+          ComputeLengthNormal normalEnabled = NormalDisabled,
+          ComputeLengthThickness thicknessEnabled = ThicknessDisabled,
+          ComputeLengthSVGZoom svgZoomEnabled = SVGZoomDisabled>
+class ApplyPropertyComputeLength : public ApplyPropertyDefaultBase<T> {
 public:
-    ApplyPropertyWidth(GetterFunction getter, SetterFunction setter, InitialFunction initial)
-        : ApplyPropertyDefaultBase<unsigned short>(getter, setter, initial)
+    ApplyPropertyComputeLength(typename ApplyPropertyDefaultBase<T>::GetterFunction getter, typename ApplyPropertyDefaultBase<T>::SetterFunction setter, typename ApplyPropertyDefaultBase<T>::InitialFunction initial)
+        : ApplyPropertyDefaultBase<T>(getter, setter, initial)
     {
     }
 
 private:
     virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
     {
+        // note: CSSPropertyLetter/WordSpacing right now sets to zero if it's not a primitive value for some reason...
         if (!value->isPrimitiveValue())
             return;
 
         CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
-        short width;
-        switch (primitiveValue->getIdent()) {
-        case CSSValueThin:
-            width = 1;
-            break;
-        case CSSValueMedium:
-            width = 3;
-            break;
-        case CSSValueThick:
-            width = 5;
-            break;
-        case CSSValueInvalid:
-            width = primitiveValue->computeLength<short>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
-            // CSS2 box model does not allow negative lengths for borders.
-            if (width < 0)
-                return;
-            break;
-        default:
-            return;
+
+        int ident = primitiveValue->getIdent();
+        T length;
+        if (normalEnabled && ident == CSSValueNormal) {
+            length = 0;
+        } else if (thicknessEnabled && ident == CSSValueThin) {
+            length = 1;
+        } else if (thicknessEnabled && ident == CSSValueMedium) {
+            length = 3;
+        } else if (thicknessEnabled && ident == CSSValueThick) {
+            length = 5;
+        } else if (ident == CSSValueInvalid) {
+            float zoom = (svgZoomEnabled && selector->useSVGZoomRules()) ? 1.0f : selector->style()->effectiveZoom();
+            length = primitiveValue->computeLength<T>(selector->style(), selector->rootElementStyle(), zoom);
+        } else {
+            ASSERT_NOT_REACHED();
+            length = 0;
         }
 
-        setValue(selector->style(), width);
+        setValue(selector->style(), length);
     }
 };
 
@@ -582,12 +587,12 @@
     setPropertyHandler(CSSPropertyBorderBottomStyle, new ApplyPropertyDefault<EBorderStyle>(&RenderStyle::borderBottomStyle, &RenderStyle::setBorderBottomStyle, &RenderStyle::initialBorderStyle));
     setPropertyHandler(CSSPropertyBorderLeftStyle, new ApplyPropertyDefault<EBorderStyle>(&RenderStyle::borderLeftStyle, &RenderStyle::setBorderLeftStyle, &RenderStyle::initialBorderStyle));
 
-    setPropertyHandler(CSSPropertyBorderTopWidth, new ApplyPropertyWidth(&RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth, &RenderStyle::initialBorderWidth));
-    setPropertyHandler(CSSPropertyBorderRightWidth, new ApplyPropertyWidth(&RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth, &RenderStyle::initialBorderWidth));
-    setPropertyHandler(CSSPropertyBorderBottomWidth, new ApplyPropertyWidth(&RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth, &RenderStyle::initialBorderWidth));
-    setPropertyHandler(CSSPropertyBorderLeftWidth, new ApplyPropertyWidth(&RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth, &RenderStyle::initialBorderWidth));
-    setPropertyHandler(CSSPropertyOutlineWidth, new ApplyPropertyWidth(&RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth, &RenderStyle::initialBorderWidth));
-    setPropertyHandler(CSSPropertyWebkitColumnRuleWidth, new ApplyPropertyWidth(&RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth, &RenderStyle::initialBorderWidth));
+    setPropertyHandler(CSSPropertyBorderTopWidth, new ApplyPropertyComputeLength<unsigned short, NormalDisabled, ThicknessEnabled>(&RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth, &RenderStyle::initialBorderWidth));
+    setPropertyHandler(CSSPropertyBorderRightWidth, new ApplyPropertyComputeLength<unsigned short, NormalDisabled, ThicknessEnabled>(&RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth, &RenderStyle::initialBorderWidth));
+    setPropertyHandler(CSSPropertyBorderBottomWidth, new ApplyPropertyComputeLength<unsigned short, NormalDisabled, ThicknessEnabled>(&RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth, &RenderStyle::initialBorderWidth));
+    setPropertyHandler(CSSPropertyBorderLeftWidth, new ApplyPropertyComputeLength<unsigned short, NormalDisabled, ThicknessEnabled>(&RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth, &RenderStyle::initialBorderWidth));
+    setPropertyHandler(CSSPropertyOutlineWidth, new ApplyPropertyComputeLength<unsigned short, NormalDisabled, ThicknessEnabled>(&RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth, &RenderStyle::initialBorderWidth));
+    setPropertyHandler(CSSPropertyWebkitColumnRuleWidth, new ApplyPropertyComputeLength<unsigned short, NormalDisabled, ThicknessEnabled>(&RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth, &RenderStyle::initialBorderWidth));
 
     setPropertyHandler(CSSPropertyBorderTop, new ApplyPropertyExpanding<SuppressValue>(propertyHandler(CSSPropertyBorderTopColor), propertyHandler(CSSPropertyBorderTopStyle), propertyHandler(CSSPropertyBorderTopWidth)));
     setPropertyHandler(CSSPropertyBorderRight, new ApplyPropertyExpanding<SuppressValue>(propertyHandler(CSSPropertyBorderRightColor), propertyHandler(CSSPropertyBorderRightStyle), propertyHandler(CSSPropertyBorderRightWidth)));
@@ -606,6 +611,13 @@
     setPropertyHandler(CSSPropertyBorderRadius, new ApplyPropertyExpanding<ExpandValue>(propertyHandler(CSSPropertyBorderTopLeftRadius), propertyHandler(CSSPropertyBorderTopRightRadius), propertyHandler(CSSPropertyBorderBottomLeftRadius), propertyHandler(CSSPropertyBorderBottomRightRadius)));
     setPropertyHandler(CSSPropertyWebkitBorderRadius, CSSPropertyBorderRadius);
 
+    setPropertyHandler(CSSPropertyWebkitBorderHorizontalSpacing, new ApplyPropertyComputeLength<short>(&RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing, &RenderStyle::initialHorizontalBorderSpacing));
+    setPropertyHandler(CSSPropertyWebkitBorderVerticalSpacing, new ApplyPropertyComputeLength<short>(&RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing, &RenderStyle::initialVerticalBorderSpacing));
+    setPropertyHandler(CSSPropertyBorderSpacing, new ApplyPropertyExpanding<SuppressValue>(propertyHandler(CSSPropertyWebkitBorderHorizontalSpacing), propertyHandler(CSSPropertyWebkitBorderVerticalSpacing)));
+
+    setPropertyHandler(CSSPropertyLetterSpacing, new ApplyPropertyComputeLength<int, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>(&RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing, &RenderStyle::initialLetterWordSpacing));
+    setPropertyHandler(CSSPropertyWordSpacing, new ApplyPropertyComputeLength<int, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>(&RenderStyle::wordSpacing, &RenderStyle::setWordSpacing, &RenderStyle::initialLetterWordSpacing));
+
     setPropertyHandler(CSSPropertyFontStyle, new ApplyPropertyFont<FontItalic>(&FontDescription::italic, &FontDescription::setItalic, FontItalicOff));
     setPropertyHandler(CSSPropertyFontVariant, new ApplyPropertyFont<FontSmallCaps>(&FontDescription::smallCaps, &FontDescription::setSmallCaps, FontSmallCapsOff));
     setPropertyHandler(CSSPropertyTextRendering, new ApplyPropertyFont<TextRenderingMode>(&FontDescription::textRenderingMode, &FontDescription::setTextRenderingMode, AutoTextRendering));
@@ -616,7 +628,6 @@
     setPropertyHandler(CSSPropertyOutlineStyle, new ApplyPropertyExpanding<ExpandValue>(new ApplyPropertyDefault<OutlineIsAuto>(&RenderStyle::outlineStyleIsAuto, &RenderStyle::setOutlineStyleIsAuto, &RenderStyle::initialOutlineStyleIsAuto), new ApplyPropertyDefault<EBorderStyle>(&RenderStyle::outlineStyle, &RenderStyle::setOutlineStyle, &RenderStyle::initialBorderStyle)));
     setPropertyHandler(CSSPropertyOutlineColor, new ApplyPropertyColor<InheritFromParent>(&RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::color));
 
-
     setPropertyHandler(CSSPropertyOverflowX, new ApplyPropertyDefault<EOverflow>(&RenderStyle::overflowX, &RenderStyle::setOverflowX, &RenderStyle::initialOverflowX));
     setPropertyHandler(CSSPropertyOverflowY, new ApplyPropertyDefault<EOverflow>(&RenderStyle::overflowY, &RenderStyle::setOverflowY, &RenderStyle::initialOverflowY));
     setPropertyHandler(CSSPropertyOverflow, new ApplyPropertyExpanding<ExpandValue>(propertyHandler(CSSPropertyOverflowX), propertyHandler(CSSPropertyOverflowY)));

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (91037 => 91038)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-07-14 23:48:51 UTC (rev 91037)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-07-15 01:28:54 UTC (rev 91038)
@@ -3667,9 +3667,9 @@
 // width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale,
 // if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific
 // properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size).
-static inline bool useSVGZoomRules(const Element* e)
+bool CSSStyleSelector::useSVGZoomRules()
 {
-    return e && e->isSVGElement();
+    return m_element && m_element->isSVGElement();
 }
 
 void CSSStyleSelector::applyProperty(int id, CSSValue *value)
@@ -3780,33 +3780,6 @@
     case CSSPropertyWhiteSpace:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(whiteSpace, WhiteSpace)
         return;
-    case CSSPropertyBorderSpacing: {
-        if (isInherit) {
-            m_style->setHorizontalBorderSpacing(m_parentStyle->horizontalBorderSpacing());
-            m_style->setVerticalBorderSpacing(m_parentStyle->verticalBorderSpacing());
-        }
-        else if (isInitial) {
-            m_style->setHorizontalBorderSpacing(0);
-            m_style->setVerticalBorderSpacing(0);
-        }
-        return;
-    }
-    case CSSPropertyWebkitBorderHorizontalSpacing: {
-        HANDLE_INHERIT_AND_INITIAL(horizontalBorderSpacing, HorizontalBorderSpacing)
-        if (!primitiveValue)
-            return;
-        short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor);
-        m_style->setHorizontalBorderSpacing(spacing);
-        return;
-    }
-    case CSSPropertyWebkitBorderVerticalSpacing: {
-        HANDLE_INHERIT_AND_INITIAL(verticalBorderSpacing, VerticalBorderSpacing)
-        if (!primitiveValue)
-            return;
-        short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor);
-        m_style->setVerticalBorderSpacing(spacing);
-        return;
-    }
     case CSSPropertyCursor:
         if (isInherit) {
             m_style->setCursor(m_parentStyle->cursor());
@@ -3852,41 +3825,6 @@
         m_style->setListStyleImage(styleImage(CSSPropertyListStyleImage, value));
         return;
     }
-    case CSSPropertyLetterSpacing:
-    case CSSPropertyWordSpacing:
-    {
-        if (isInherit) {
-            HANDLE_INHERIT_COND(CSSPropertyLetterSpacing, letterSpacing, LetterSpacing)
-            HANDLE_INHERIT_COND(CSSPropertyWordSpacing, wordSpacing, WordSpacing)
-            return;
-        }
-        else if (isInitial) {
-            HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyLetterSpacing, LetterSpacing, LetterWordSpacing)
-            HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWordSpacing, WordSpacing, LetterWordSpacing)
-            return;
-        }
-        
-        int width = 0;
-        if (primitiveValue && primitiveValue->getIdent() == CSSValueNormal) {
-            width = 0;
-        } else {
-            if (!primitiveValue)
-                return;
-            width = primitiveValue->computeLength<int>(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor);
-        }
-        switch (id) {
-        case CSSPropertyLetterSpacing:
-            m_style->setLetterSpacing(width);
-            break;
-        case CSSPropertyWordSpacing:
-            m_style->setWordSpacing(width);
-            break;
-            // ### needs the definitions in renderstyle
-        default: break;
-        }
-        return;
-    }
-
     case CSSPropertyWordBreak:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(wordBreak, WordBreak)
         return;
@@ -4496,7 +4434,7 @@
                 fontDescription.setUsePrinterFont(m_checker.m_document->printing());
            
                 // Handle the zoom factor.
-                fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(m_checker.m_document, m_style.get(), fontDescription.isAbsoluteSize(), fontDescription.specifiedSize(), useSVGZoomRules(m_element)));
+                fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(m_checker.m_document, m_style.get(), fontDescription.isAbsoluteSize(), fontDescription.specifiedSize(), useSVGZoomRules()));
                 if (m_style->setFontDescription(fontDescription))
                     m_fontDirty = true;
             }
@@ -5398,6 +5336,11 @@
     case CSSPropertyBorderTopRightRadius:
     case CSSPropertyBorderBottomLeftRadius:
     case CSSPropertyBorderBottomRightRadius:
+    case CSSPropertyBorderSpacing:
+    case CSSPropertyWebkitBorderHorizontalSpacing:
+    case CSSPropertyWebkitBorderVerticalSpacing:
+    case CSSPropertyLetterSpacing:
+    case CSSPropertyWordSpacing:
     case CSSPropertyFontStyle:
     case CSSPropertyFontVariant:
     case CSSPropertyTextRendering:
@@ -6162,9 +6105,7 @@
 void CSSStyleSelector::setFontSize(FontDescription& fontDescription, float size)
 {
     fontDescription.setSpecifiedSize(size);
-
-    bool useSVGZoomRules = m_element && m_element->isSVGElement();
-    fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(m_checker.m_document, m_style.get(), fontDescription.isAbsoluteSize(), size, useSVGZoomRules)); 
+    fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(m_checker.m_document, m_style.get(), fontDescription.isAbsoluteSize(), size, useSVGZoomRules()));
 }
 
 float CSSStyleSelector::getComputedSizeFromSpecifiedSize(Document* document, RenderStyle* style, bool isAbsoluteSize, float specifiedSize, bool useSVGZoomRules)

Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (91037 => 91038)


--- trunk/Source/WebCore/css/CSSStyleSelector.h	2011-07-14 23:48:51 UTC (rev 91037)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h	2011-07-15 01:28:54 UTC (rev 91038)
@@ -181,7 +181,10 @@
         void setFontSize(FontDescription&, float size);
 
         static float getComputedSizeFromSpecifiedSize(Document*, RenderStyle*, bool isAbsoluteSize, float specifiedSize, bool useSVGZoomRules);
+
     public:
+        bool useSVGZoomRules();
+
         Color getColorFromPrimitiveValue(CSSPrimitiveValue*) const;
 
         bool hasSelectorForAttribute(const AtomicString&) const;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to