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 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const 50 { 51 Node* node = m_node.get(); 52 if (!node) 53 return 0; 54 55 // Make sure our layout is up to date before we allow a query on these attributes. 56 if (updateLayout) 57 node->document()->updateLayout(); 58 59 RenderStyle* style = node->computedStyle(); 60 if (!style) 61 return 0; 62 63 const SVGRenderStyle* svgStyle = style->svgStyle(); 64 if (!svgStyle) 65 return 0; 66 67 switch (static_cast<CSSPropertyID>(propertyID)) { 68 case CSSPropertyClipRule: 69 return CSSPrimitiveValue::create(svgStyle->clipRule()); 70 case CSSPropertyFloodOpacity: 71 return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER); 72 case CSSPropertyStopOpacity: 73 return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER); 74 case CSSPropertyColorInterpolation: 75 return CSSPrimitiveValue::create(svgStyle->colorInterpolation()); 76 case CSSPropertyColorInterpolationFilters: 77 return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters()); 78 case CSSPropertyFillOpacity: 79 return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER); 80 case CSSPropertyFillRule: 81 return CSSPrimitiveValue::create(svgStyle->fillRule()); 82 case CSSPropertyColorRendering: 83 return CSSPrimitiveValue::create(svgStyle->colorRendering()); 84 case CSSPropertyImageRendering: 85 return CSSPrimitiveValue::create(svgStyle->imageRendering()); 86 case CSSPropertyShapeRendering: 87 return CSSPrimitiveValue::create(svgStyle->shapeRendering()); 88 case CSSPropertyStrokeLinecap: 89 return CSSPrimitiveValue::create(svgStyle->capStyle()); 90 case CSSPropertyStrokeLinejoin: 91 return CSSPrimitiveValue::create(svgStyle->joinStyle()); 92 case CSSPropertyStrokeMiterlimit: 93 return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER); 94 case CSSPropertyStrokeOpacity: 95 return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER); 96 case CSSPropertyAlignmentBaseline: 97 return CSSPrimitiveValue::create(svgStyle->alignmentBaseline()); 98 case CSSPropertyDominantBaseline: 99 return CSSPrimitiveValue::create(svgStyle->dominantBaseline()); 100 case CSSPropertyTextAnchor: 101 return CSSPrimitiveValue::create(svgStyle->textAnchor()); 102 case CSSPropertyWritingMode: 103 return CSSPrimitiveValue::create(svgStyle->writingMode()); 104 case CSSPropertyClipPath: 105 if (!svgStyle->clipPath().isEmpty()) 106 return CSSPrimitiveValue::create(svgStyle->clipPath(), CSSPrimitiveValue::CSS_URI); 107 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 108 case CSSPropertyMask: 109 if (!svgStyle->maskElement().isEmpty()) 110 return CSSPrimitiveValue::create(svgStyle->maskElement(), CSSPrimitiveValue::CSS_URI); 111 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 112 case CSSPropertyFilter: 113 if (!svgStyle->filter().isEmpty()) 114 return CSSPrimitiveValue::create(svgStyle->filter(), CSSPrimitiveValue::CSS_URI); 115 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 116 case CSSPropertyFloodColor: 117 return CSSPrimitiveValue::createColor(svgStyle->floodColor().rgb()); 118 case CSSPropertyLightingColor: 119 return CSSPrimitiveValue::createColor(svgStyle->lightingColor().rgb()); 120 case CSSPropertyStopColor: 121 return CSSPrimitiveValue::createColor(svgStyle->stopColor().rgb()); 122 case CSSPropertyFill: 123 return svgStyle->fillPaint(); 124 case CSSPropertyKerning: 125 return svgStyle->kerning(); 126 case CSSPropertyMarkerEnd: 127 if (!svgStyle->endMarker().isEmpty()) 128 return CSSPrimitiveValue::create(svgStyle->endMarker(), CSSPrimitiveValue::CSS_URI); 129 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 130 case CSSPropertyMarkerMid: 131 if (!svgStyle->midMarker().isEmpty()) 132 return CSSPrimitiveValue::create(svgStyle->midMarker(), CSSPrimitiveValue::CSS_URI); 133 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 134 case CSSPropertyMarkerStart: 135 if (!svgStyle->startMarker().isEmpty()) 136 return CSSPrimitiveValue::create(svgStyle->startMarker(), CSSPrimitiveValue::CSS_URI); 137 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 138 case CSSPropertyStroke: 139 return svgStyle->strokePaint(); 140 case CSSPropertyStrokeDasharray: 141 return svgStyle->strokeDashArray(); 142 case CSSPropertyStrokeDashoffset: 143 return svgStyle->strokeDashOffset(); 144 case CSSPropertyStrokeWidth: 145 return svgStyle->strokeWidth(); 146 case CSSPropertyBaselineShift: { 147 switch (svgStyle->baselineShift()) { 148 case BS_BASELINE: 149 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline); 150 case BS_SUPER: 151 return CSSPrimitiveValue::createIdentifier(CSSValueSuper); 152 case BS_SUB: 153 return CSSPrimitiveValue::createIdentifier(CSSValueSub); 154 case BS_LENGTH: 155 return svgStyle->baselineShiftValue(); 156 } 157 } 158 case CSSPropertyGlyphOrientationHorizontal: 159 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal()); 160 case CSSPropertyGlyphOrientationVertical: { 161 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical())) 162 return value.release(); 163 164 if (svgStyle->glyphOrientationVertical() == GO_AUTO) 165 return CSSPrimitiveValue::createIdentifier(CSSValueAuto); 166 167 return 0; 168 } 169 case CSSPropertyWebkitSvgShadow: 170 return valueForShadow(svgStyle->shadow(), propertyID); 171 case CSSPropertyMarker: 172 case CSSPropertyEnableBackground: 173 case CSSPropertyColorProfile: 174 // the above properties are not yet implemented in the engine 175 break; 176 default: 177 // If you crash here, it's because you added a css property and are not handling it 178 // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue 179 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID); 180 } 181 LOG_ERROR("unimplemented propertyID: %d", propertyID); 182 return 0; 183 } 184 185 } 186 187 #endif // ENABLE(SVG) 188 189 // vim:ts=4:noet 190