2
2
* Copyright (C) 2007, 2008 Rob Buis <buis@kde.org>
3
3
* (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4
4
* (C) 2007 Eric Seidel <eric@webkit.org>
5
* Copyright (C) 2009 Google, Inc. All rights reserved.
6
7
* This library is free software; you can redistribute it and/or
7
8
* modify it under the terms of the GNU Library General Public
35
35
#include "SVGResourceMasker.h"
36
36
#include "SVGStyledElement.h"
37
37
#include "SVGURIReference.h"
38
#include "TransformState.h"
39
#include "TransformationMatrix.h"
40
#include <wtf/UnusedParam.h>
39
42
namespace WebCore {
41
void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
43
SVGElement* svgElement = static_cast<SVGElement*>(object->element());
44
IntRect SVGRenderBase::clippedOverflowRectForRepaint(RenderObject* object, RenderBoxModelObject* repaintContainer)
46
// Return early for any cases where we don't actually paint
47
if (object->style()->visibility() != VISIBLE && !object->enclosingLayer()->hasVisibleContent())
50
// Pass our local paint rect to computeRectForRepaint() which will
51
// map to parent coords and recurse up the parent chain.
52
IntRect repaintRect = enclosingIntRect(object->repaintRectInLocalCoordinates());
53
object->computeRectForRepaint(repaintContainer, repaintRect);
57
void SVGRenderBase::computeRectForRepaint(RenderObject* object, RenderBoxModelObject* repaintContainer, IntRect& repaintRect, bool fixed)
59
// Translate to coords in our parent renderer, and then call computeRectForRepaint on our parent
60
repaintRect = object->localToParentTransform().mapRect(repaintRect);
61
object->parent()->computeRectForRepaint(repaintContainer, repaintRect, fixed);
64
void SVGRenderBase::mapLocalToContainer(const RenderObject* object, RenderBoxModelObject* repaintContainer, bool fixed , bool useTransforms, TransformState& transformState)
66
ASSERT(!fixed); // We should have no fixed content in the SVG rendering tree.
67
ASSERT(useTransforms); // mapping a point through SVG w/o respecting trasnforms is useless.
68
transformState.applyTransform(object->localToParentTransform());
69
object->parent()->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState);
72
void SVGRenderBase::prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
76
UNUSED_PARAM(rootFilter);
80
SVGElement* svgElement = static_cast<SVGElement*>(object->node());
44
81
ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
47
83
SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(svgElement);
48
84
const RenderStyle* style = object->style();
81
117
SVGResourceClipper* clipper = getClipperById(document, clipperId);
82
118
SVGResourceMasker* masker = getMaskerById(document, maskerId);
84
#if ENABLE(SVG_FILTERS)
86
122
filter->addClient(styledElement);
87
filter->prepareFilter(paintInfo.context, boundingBox);
123
filter->prepareFilter(paintInfo.context, object);
88
124
} else if (!filterId.isEmpty())
89
125
svgElement->document()->accessSVGExtensions()->addPendingResource(filterId, styledElement);
102
138
svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);
105
void finishRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, GraphicsContext* savedContext)
141
void SVGRenderBase::finishRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, SVGResourceFilter*& filter, GraphicsContext* savedContext)
144
UNUSED_PARAM(filter);
145
UNUSED_PARAM(savedContext);
109
150
const RenderStyle* style = object->style();
112
#if ENABLE(SVG_FILTERS)
114
filter->applyFilter(paintInfo.context, boundingBox);
155
filter->applyFilter(paintInfo.context, object);
115
156
paintInfo.context = savedContext;
128
169
ASSERT(image->context());
129
170
RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
172
// FIXME: isSVGContainer returns true for RenderSVGViewportContainer, so if this is ever
173
// called with one of those, we will read from the wrong offset in an object due to a bad cast.
131
174
RenderSVGContainer* svgContainer = 0;
132
175
if (item && item->isSVGContainer())
133
svgContainer = static_cast<RenderSVGContainer*>(item);
176
svgContainer = toRenderSVGContainer(item);
135
178
bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
136
179
if (svgContainer && !drawsContents)
143
186
svgContainer->setDrawsContents(false);
146
void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
189
void clampImageBufferSizeToViewport(FrameView* frameView, IntSize& size)
148
if (!object || !object->isRenderView())
151
RenderView* view = static_cast<RenderView*>(object);
152
if (!view->frameView())
155
int viewWidth = view->frameView()->visibleWidth();
156
int viewHeight = view->frameView()->visibleHeight();
194
int viewWidth = frameView->visibleWidth();
195
int viewHeight = frameView->visibleHeight();
158
197
if (size.width() > viewWidth)
159
198
size.setWidth(viewWidth);
162
201
size.setHeight(viewHeight);
204
FloatRect SVGRenderBase::computeContainerBoundingBox(const RenderObject* container, bool includeAllPaintedContent)
206
FloatRect boundingBox;
208
RenderObject* current = container->firstChild();
209
for (; current != 0; current = current->nextSibling()) {
210
FloatRect childBBox = includeAllPaintedContent ? current->repaintRectInLocalCoordinates() : current->objectBoundingBox();
211
FloatRect childBBoxInLocalCoords = current->localToParentTransform().mapRect(childBBox);
212
boundingBox.unite(childBBoxInLocalCoords);
218
FloatRect SVGRenderBase::filterBoundingBoxForRenderer(const RenderObject* object)
221
SVGResourceFilter* filter = getFilterById(object->document(), object->style()->svgStyle()->filter());
223
return filter->filterBBoxForItemBBox(object->objectBoundingBox());
225
UNUSED_PARAM(object);
230
void applyTransformToPaintInfo(RenderObject::PaintInfo& paintInfo, const TransformationMatrix& localToAncestorTransform)
232
if (localToAncestorTransform.isIdentity())
235
paintInfo.context->concatCTM(localToAncestorTransform);
236
paintInfo.rect = localToAncestorTransform.inverse().mapRect(paintInfo.rect);
165
239
} // namespace WebCore
167
241
#endif // ENABLE(SVG)