~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/rendering/SVGRenderSupport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
5
6
 *
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
25
26
#if ENABLE(SVG)
26
27
#include "SVGRenderSupport.h"
27
28
 
28
 
#include "TransformationMatrix.h"
29
29
#include "ImageBuffer.h"
30
30
#include "RenderObject.h"
31
31
#include "RenderSVGContainer.h"
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>
38
41
 
39
42
namespace WebCore {
40
43
 
41
 
void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
42
 
{    
43
 
    SVGElement* svgElement = static_cast<SVGElement*>(object->element());
 
44
IntRect SVGRenderBase::clippedOverflowRectForRepaint(RenderObject* object, RenderBoxModelObject* repaintContainer)
 
45
{
 
46
    // Return early for any cases where we don't actually paint
 
47
    if (object->style()->visibility() != VISIBLE && !object->enclosingLayer()->hasVisibleContent())
 
48
        return IntRect();
 
49
 
 
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);
 
54
    return repaintRect;
 
55
}
 
56
 
 
57
void SVGRenderBase::computeRectForRepaint(RenderObject* object, RenderBoxModelObject* repaintContainer, IntRect& repaintRect, bool fixed)
 
58
{
 
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);
 
62
}
 
63
 
 
64
void SVGRenderBase::mapLocalToContainer(const RenderObject* object, RenderBoxModelObject* repaintContainer, bool fixed , bool useTransforms, TransformState& transformState)
 
65
{
 
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);
 
70
}
 
71
 
 
72
void SVGRenderBase::prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
 
73
{
 
74
#if !ENABLE(FILTERS)
 
75
    UNUSED_PARAM(filter);
 
76
    UNUSED_PARAM(rootFilter);
 
77
#endif
 
78
 
 
79
    ASSERT(object);
 
80
    SVGElement* svgElement = static_cast<SVGElement*>(object->node());
44
81
    ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
45
 
    ASSERT(object);
46
82
 
47
83
    SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(svgElement);
48
84
    const RenderStyle* style = object->style();
58
94
        paintInfo.context->beginTransparencyLayer(opacity);
59
95
    }
60
96
 
61
 
#if ENABLE(SVG_FILTERS)
 
97
#if ENABLE(FILTERS)
62
98
    AtomicString filterId(svgStyle->filter());
63
99
#endif
64
100
 
67
103
 
68
104
    Document* document = object->document();
69
105
 
70
 
#if ENABLE(SVG_FILTERS)
 
106
#if ENABLE(FILTERS)
71
107
    SVGResourceFilter* newFilter = getFilterById(document, filterId);
72
108
    if (newFilter == rootFilter) {
73
109
        // Catch <text filter="url(#foo)">Test<tspan filter="url(#foo)">123</tspan></text>.
81
117
    SVGResourceClipper* clipper = getClipperById(document, clipperId);
82
118
    SVGResourceMasker* masker = getMaskerById(document, maskerId);
83
119
 
84
 
#if ENABLE(SVG_FILTERS)
 
120
#if ENABLE(FILTERS)
85
121
    if (filter) {
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);
90
126
#endif
102
138
        svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);
103
139
}
104
140
 
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)
106
142
{
 
143
#if !ENABLE(FILTERS)
 
144
    UNUSED_PARAM(filter);
 
145
    UNUSED_PARAM(savedContext);
 
146
#endif
 
147
 
107
148
    ASSERT(object);
108
149
 
109
150
    const RenderStyle* style = object->style();
110
151
    ASSERT(style);
111
152
 
112
 
#if ENABLE(SVG_FILTERS)
 
153
#if ENABLE(FILTERS)
113
154
    if (filter) {
114
 
        filter->applyFilter(paintInfo.context, boundingBox);
 
155
        filter->applyFilter(paintInfo.context, object);
115
156
        paintInfo.context = savedContext;
116
157
    }
117
158
#endif
128
169
    ASSERT(image->context());
129
170
    RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
130
171
 
 
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);
134
177
 
135
178
    bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
136
179
    if (svgContainer && !drawsContents)
143
186
        svgContainer->setDrawsContents(false);
144
187
}
145
188
 
146
 
void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
 
189
void clampImageBufferSizeToViewport(FrameView* frameView, IntSize& size)
147
190
{
148
 
    if (!object || !object->isRenderView())
149
 
        return;
150
 
 
151
 
    RenderView* view = static_cast<RenderView*>(object);
152
 
    if (!view->frameView())
153
 
        return;
154
 
 
155
 
    int viewWidth = view->frameView()->visibleWidth();
156
 
    int viewHeight = view->frameView()->visibleHeight();
 
191
    if (!frameView)
 
192
        return;
 
193
 
 
194
    int viewWidth = frameView->visibleWidth();
 
195
    int viewHeight = frameView->visibleHeight();
157
196
 
158
197
    if (size.width() > viewWidth)
159
198
        size.setWidth(viewWidth);
162
201
        size.setHeight(viewHeight);
163
202
}
164
203
 
 
204
FloatRect SVGRenderBase::computeContainerBoundingBox(const RenderObject* container, bool includeAllPaintedContent)
 
205
{
 
206
    FloatRect boundingBox;
 
207
 
 
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);
 
213
    }
 
214
 
 
215
    return boundingBox;
 
216
}
 
217
 
 
218
FloatRect SVGRenderBase::filterBoundingBoxForRenderer(const RenderObject* object)
 
219
{
 
220
#if ENABLE(FILTERS)
 
221
    SVGResourceFilter* filter = getFilterById(object->document(), object->style()->svgStyle()->filter());
 
222
    if (filter)
 
223
        return filter->filterBBoxForItemBBox(object->objectBoundingBox());
 
224
#else
 
225
    UNUSED_PARAM(object);
 
226
#endif
 
227
    return FloatRect();
 
228
}
 
229
 
 
230
void applyTransformToPaintInfo(RenderObject::PaintInfo& paintInfo, const TransformationMatrix& localToAncestorTransform)
 
231
{
 
232
    if (localToAncestorTransform.isIdentity())
 
233
        return;
 
234
 
 
235
    paintInfo.context->concatCTM(localToAncestorTransform);
 
236
    paintInfo.rect = localToAncestorTransform.inverse().mapRect(paintInfo.rect);
 
237
}
 
238
 
165
239
} // namespace WebCore
166
240
 
167
241
#endif // ENABLE(SVG)