Ejemplo n.º 1
0
RenderSVGResource* RenderSVGResource::strokePaintingResource(const RenderObject* object, const RenderStyle* style)
{
    ASSERT(object);
    ASSERT(style);

    const SVGRenderStyle* svgStyle = style->svgStyle();
    if (!svgStyle || !svgStyle->hasStroke())
        return 0;

    SVGPaint* strokePaint = svgStyle->strokePaint();
    ASSERT(strokePaint);

    RenderSVGResource* strokePaintingResource = 0;
    FloatRect objectBoundingBox = object->objectBoundingBox();

    SVGPaint::SVGPaintType paintType = strokePaint->paintType();
    if (!objectBoundingBox.isEmpty()
        && (paintType == SVGPaint::SVG_PAINTTYPE_URI || paintType == SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR)) {
        AtomicString id(SVGURIReference::getTarget(strokePaint->uri()));
        strokePaintingResource = getRenderSVGResourceContainerById(object->document(), id);

        if (!strokePaintingResource)
            registerPendingResource(id, paintType, object);
    }

    if (paintType != SVGPaint::SVG_PAINTTYPE_URI && !strokePaintingResource) {
        RenderSVGResourceSolidColor* solidResource = sharedSolidPaintingResource();
        strokePaintingResource = solidResource;

        Color strokeColor;
        if (strokePaint->paintType() == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR)
            strokeColor = style->visitedDependentColor(CSSPropertyColor);
        else
            strokeColor = strokePaint->color();

        adjustColorForPseudoRules(style, false /* useFillPaint */, strokeColor);

        // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT
        if (strokeColor.isValid())
            solidResource->setColor(strokeColor);
        else
            strokePaintingResource = 0;
    }

    if (!strokePaintingResource) {
        // default value (black), see bug 11017
        RenderSVGResourceSolidColor* solidResource = sharedSolidPaintingResource();
        solidResource->setColor(Color::black);
        strokePaintingResource = solidResource;
    }

    return strokePaintingResource;
}
Ejemplo n.º 2
0
// FIXME: This method and strokePaintingResource() should be refactored, to share even more code
RenderSVGResource* RenderSVGResource::fillPaintingResource(RenderObject* object, const RenderStyle* style)
{
    ASSERT(object);
    ASSERT(style);

    const SVGRenderStyle* svgStyle = style->svgStyle();
    if (!svgStyle || !svgStyle->hasFill())
        return 0;

    SVGPaint* fillPaint = svgStyle->fillPaint();
    ASSERT(fillPaint);

    RenderSVGResource* fillPaintingResource = 0;

    SVGPaint::SVGPaintType paintType = fillPaint->paintType();
    if (paintType == SVGPaint::SVG_PAINTTYPE_URI || paintType == SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR) {
        if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(object))
            fillPaintingResource = resources->fill();
    }

    if (paintType != SVGPaint::SVG_PAINTTYPE_URI && !fillPaintingResource) {
        RenderSVGResourceSolidColor* solidResource = sharedSolidPaintingResource();
        fillPaintingResource = solidResource;

        Color fillColor;
        if (fillPaint->paintType() == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR)
            fillColor = style->visitedDependentColor(CSSPropertyColor);
        else
            fillColor = fillPaint->color();

        adjustColorForPseudoRules(style, true /* useFillPaint */, fillColor);

        // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT
        if (fillColor.isValid())
            solidResource->setColor(fillColor);
        else
            fillPaintingResource = 0;
    }

    if (!fillPaintingResource) {
        // default value (black), see bug 11017
        RenderSVGResourceSolidColor* solidResource = sharedSolidPaintingResource();
        solidResource->setColor(Color::black);
        fillPaintingResource = solidResource;
    }

    return fillPaintingResource;
}