IntSize SVGImage::size() const { IntSize defaultSize(300, 150); // FIXME: Eventually we'll be passed in the dest size and can scale against that IntSize destSize = defaultSize; if (!m_frame || !m_frame->document()) return IntSize(); SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); if (!rootElement) return defaultSize; SVGLength width = rootElement->width(); SVGLength height = rootElement->height(); IntSize svgSize; if (width.unitType() == LengthTypePercentage) svgSize.setWidth(static_cast<int>(width.valueInSpecifiedUnits() * destSize.width())); else svgSize.setWidth(static_cast<int>(width.value())); if (height.unitType() == LengthTypePercentage) svgSize.setHeight(static_cast<int>(height.valueInSpecifiedUnits() * destSize.height())); else svgSize.setHeight(static_cast<int>(height.value())); return svgSize; }
static v8::Handle<v8::Value> valueInSpecifiedUnitsAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.SVGLength.valueInSpecifiedUnits._get"); V8SVGPODTypeWrapper<SVGLength>* impWrapper = V8SVGPODTypeWrapper<SVGLength>::toNative(info.Holder()); SVGLength impInstance = *impWrapper; SVGLength* imp = &impInstance; return v8::Number::New(imp->valueInSpecifiedUnits()); }
PassRefPtr<CSSPrimitiveValue> SVGLength::toCSSPrimitiveValue(const SVGLength& length) { CSSPrimitiveValue::UnitTypes cssType = CSSPrimitiveValue::CSS_UNKNOWN; switch (length.unitType()) { case LengthTypeUnknown: break; case LengthTypeNumber: cssType = CSSPrimitiveValue::CSS_NUMBER; break; case LengthTypePercentage: cssType = CSSPrimitiveValue::CSS_PERCENTAGE; break; case LengthTypeEMS: cssType = CSSPrimitiveValue::CSS_EMS; break; case LengthTypeEXS: cssType = CSSPrimitiveValue::CSS_EXS; break; case LengthTypePX: cssType = CSSPrimitiveValue::CSS_PX; break; case LengthTypeCM: cssType = CSSPrimitiveValue::CSS_CM; break; case LengthTypeMM: cssType = CSSPrimitiveValue::CSS_MM; break; case LengthTypeIN: cssType = CSSPrimitiveValue::CSS_IN; break; case LengthTypePT: cssType = CSSPrimitiveValue::CSS_PT; break; case LengthTypePC: cssType = CSSPrimitiveValue::CSS_PC; break; default: ASSERT_NOT_REACHED(); }; return CSSPrimitiveValue::create(length.valueInSpecifiedUnits(), cssType); }