Home | History | Annotate | Download | only in css
      1 /*
      2     Copyright (C) 2007 Eric Seidel <eric (at) webkit.org>
      3     Copyright (C) 2007 Alexey Proskuryakov <ap (at) webkit.org>
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Library General Public
      7     License as published by the Free Software Foundation; either
      8     version 2 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Library General Public License for more details.
     14 
     15     You should have received a copy of the GNU Library General Public License
     16     along with this library; see the file COPYING.LIB.  If not, write to
     17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18     Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #include "config.h"
     22 
     23 #if ENABLE(SVG)
     24 #include "CSSComputedStyleDeclaration.h"
     25 
     26 #include "CSSPrimitiveValueMappings.h"
     27 #include "CSSPropertyNames.h"
     28 #include "Document.h"
     29 #include "RenderStyle.h"
     30 
     31 namespace WebCore {
     32 
     33 static PassRefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)
     34 {
     35     switch (orientation) {
     36         case GO_0DEG:
     37             return CSSPrimitiveValue::create(0.0f, CSSPrimitiveValue::CSS_DEG);
     38         case GO_90DEG:
     39             return CSSPrimitiveValue::create(90.0f, CSSPrimitiveValue::CSS_DEG);
     40         case GO_180DEG:
     41             return CSSPrimitiveValue::create(180.0f, CSSPrimitiveValue::CSS_DEG);
     42         case GO_270DEG:
     43             return CSSPrimitiveValue::create(270.0f, CSSPrimitiveValue::CSS_DEG);
     44         default:
     45             return 0;
     46     }
     47 }
     48 
     49 static PassRefPtr<CSSValue> strokeDashArrayToCSSValueList(const Vector<SVGLength>& dashes)
     50 {
     51     if (dashes.isEmpty())
     52         return CSSPrimitiveValue::createIdentifier(CSSValueNone);
     53 
     54     RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
     55     const Vector<SVGLength>::const_iterator end = dashes.end();
     56     for (Vector<SVGLength>::const_iterator it = dashes.begin(); it != end; ++it)
     57         list->append(SVGLength::toCSSPrimitiveValue(*it));
     58 
     59     return list.release();
     60 }
     61 
     62 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
     63 {
     64     Node* node = m_node.get();
     65     if (!node)
     66         return 0;
     67 
     68     // Make sure our layout is up to date before we allow a query on these attributes.
     69     if (updateLayout)
     70         node->document()->updateLayout();
     71 
     72     RenderStyle* style = node->computedStyle();
     73     if (!style)
     74         return 0;
     75 
     76     const SVGRenderStyle* svgStyle = style->svgStyle();
     77     if (!svgStyle)
     78         return 0;
     79 
     80     switch (static_cast<CSSPropertyID>(propertyID)) {
     81         case CSSPropertyClipRule:
     82             return CSSPrimitiveValue::create(svgStyle->clipRule());
     83         case CSSPropertyFloodOpacity:
     84             return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER);
     85         case CSSPropertyStopOpacity:
     86             return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER);
     87         case CSSPropertyColorInterpolation:
     88             return CSSPrimitiveValue::create(svgStyle->colorInterpolation());
     89         case CSSPropertyColorInterpolationFilters:
     90             return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters());
     91         case CSSPropertyFillOpacity:
     92             return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER);
     93         case CSSPropertyFillRule:
     94             return CSSPrimitiveValue::create(svgStyle->fillRule());
     95         case CSSPropertyColorRendering:
     96             return CSSPrimitiveValue::create(svgStyle->colorRendering());
     97         case CSSPropertyImageRendering:
     98             return CSSPrimitiveValue::create(svgStyle->imageRendering());
     99         case CSSPropertyShapeRendering:
    100             return CSSPrimitiveValue::create(svgStyle->shapeRendering());
    101         case CSSPropertyStrokeLinecap:
    102             return CSSPrimitiveValue::create(svgStyle->capStyle());
    103         case CSSPropertyStrokeLinejoin:
    104             return CSSPrimitiveValue::create(svgStyle->joinStyle());
    105         case CSSPropertyStrokeMiterlimit:
    106             return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER);
    107         case CSSPropertyStrokeOpacity:
    108             return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER);
    109         case CSSPropertyAlignmentBaseline:
    110             return CSSPrimitiveValue::create(svgStyle->alignmentBaseline());
    111         case CSSPropertyDominantBaseline:
    112             return CSSPrimitiveValue::create(svgStyle->dominantBaseline());
    113         case CSSPropertyTextAnchor:
    114             return CSSPrimitiveValue::create(svgStyle->textAnchor());
    115         case CSSPropertyWritingMode:
    116             return CSSPrimitiveValue::create(svgStyle->writingMode());
    117         case CSSPropertyClipPath:
    118             if (!svgStyle->clipperResource().isEmpty())
    119                 return CSSPrimitiveValue::create(svgStyle->clipperResource(), CSSPrimitiveValue::CSS_URI);
    120             return CSSPrimitiveValue::createIdentifier(CSSValueNone);
    121         case CSSPropertyMask:
    122             if (!svgStyle->maskerResource().isEmpty())
    123                 return CSSPrimitiveValue::create(svgStyle->maskerResource(), CSSPrimitiveValue::CSS_URI);
    124             return CSSPrimitiveValue::createIdentifier(CSSValueNone);
    125         case CSSPropertyFilter:
    126             if (!svgStyle->filterResource().isEmpty())
    127                 return CSSPrimitiveValue::create(svgStyle->filterResource(), CSSPrimitiveValue::CSS_URI);
    128             return CSSPrimitiveValue::createIdentifier(CSSValueNone);
    129         case CSSPropertyFloodColor:
    130             return CSSPrimitiveValue::createColor(svgStyle->floodColor().rgb());
    131         case CSSPropertyLightingColor:
    132             return CSSPrimitiveValue::createColor(svgStyle->lightingColor().rgb());
    133         case CSSPropertyStopColor:
    134             return CSSPrimitiveValue::createColor(svgStyle->stopColor().rgb());
    135         case CSSPropertyFill:
    136             return svgStyle->fillPaint();
    137         case CSSPropertyKerning:
    138             return SVGLength::toCSSPrimitiveValue(svgStyle->kerning());
    139         case CSSPropertyMarkerEnd:
    140             if (!svgStyle->markerEndResource().isEmpty())
    141                 return CSSPrimitiveValue::create(svgStyle->markerEndResource(), CSSPrimitiveValue::CSS_URI);
    142             return CSSPrimitiveValue::createIdentifier(CSSValueNone);
    143         case CSSPropertyMarkerMid:
    144             if (!svgStyle->markerMidResource().isEmpty())
    145                 return CSSPrimitiveValue::create(svgStyle->markerMidResource(), CSSPrimitiveValue::CSS_URI);
    146             return CSSPrimitiveValue::createIdentifier(CSSValueNone);
    147         case CSSPropertyMarkerStart:
    148             if (!svgStyle->markerStartResource().isEmpty())
    149                 return CSSPrimitiveValue::create(svgStyle->markerStartResource(), CSSPrimitiveValue::CSS_URI);
    150             return CSSPrimitiveValue::createIdentifier(CSSValueNone);
    151         case CSSPropertyStroke:
    152             return svgStyle->strokePaint();
    153         case CSSPropertyStrokeDasharray:
    154             return strokeDashArrayToCSSValueList(svgStyle->strokeDashArray());
    155         case CSSPropertyStrokeDashoffset:
    156             return SVGLength::toCSSPrimitiveValue(svgStyle->strokeDashOffset());
    157         case CSSPropertyStrokeWidth:
    158             return SVGLength::toCSSPrimitiveValue(svgStyle->strokeWidth());
    159         case CSSPropertyBaselineShift: {
    160             switch (svgStyle->baselineShift()) {
    161                 case BS_BASELINE:
    162                     return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
    163                 case BS_SUPER:
    164                     return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
    165                 case BS_SUB:
    166                     return CSSPrimitiveValue::createIdentifier(CSSValueSub);
    167                 case BS_LENGTH:
    168                     return SVGLength::toCSSPrimitiveValue(svgStyle->baselineShiftValue());
    169             }
    170         }
    171         case CSSPropertyGlyphOrientationHorizontal:
    172             return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
    173         case CSSPropertyGlyphOrientationVertical: {
    174             if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
    175                 return value.release();
    176 
    177             if (svgStyle->glyphOrientationVertical() == GO_AUTO)
    178                 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
    179 
    180             return 0;
    181         }
    182         case CSSPropertyWebkitSvgShadow:
    183             return valueForShadow(svgStyle->shadow(), propertyID, style);
    184         case CSSPropertyVectorEffect:
    185             return CSSPrimitiveValue::create(svgStyle->vectorEffect());
    186         case CSSPropertyMarker:
    187         case CSSPropertyEnableBackground:
    188         case CSSPropertyColorProfile:
    189             // the above properties are not yet implemented in the engine
    190             break;
    191     default:
    192         // If you crash here, it's because you added a css property and are not handling it
    193         // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
    194         ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
    195     }
    196     LOG_ERROR("unimplemented propertyID: %d", propertyID);
    197     return 0;
    198 }
    199 
    200 }
    201 
    202 #endif // ENABLE(SVG)
    203 
    204 // vim:ts=4:noet
    205