87
82
ASSERT(needsLayout());
91
84
// Arbitrary affine transforms are incompatible with LayoutState.
92
85
view()->disableLayoutState();
94
IntRect oldBounds = m_absoluteBounds;
95
IntRect oldOutlineBox;
96
bool checkForRepaint = checkForRepaintDuringLayout() && selfNeedsLayout();
98
oldOutlineBox = absoluteOutlineBounds();
87
LayoutRepainter repainter(*this, checkForRepaintDuringLayout() && selfNeedsLayout());
103
m_absoluteBounds = absoluteClippedOverflowRect();
104
SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
105
m_width = static_cast<int>(m_width * svg->currentScale());
106
m_height = static_cast<int>(m_height * svg->currentScale());
92
SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
93
setWidth(static_cast<int>(width() * svg->currentScale()));
94
setHeight(static_cast<int>(height() * svg->currentScale()));
108
98
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
109
99
if (selfNeedsLayout()) // either bounds or transform changed, force kids to relayout
110
child->setNeedsLayout(true);
100
child->setNeedsLayout(true, false);
112
102
child->layoutIfNeeded();
113
103
ASSERT(!child->needsLayout());
117
repaintAfterLayoutIfNeeded(oldBounds, oldOutlineBox);
106
repainter.repaintAfterLayout();
119
108
view()->enableLayoutState();
120
109
setNeedsLayout(false);
123
void RenderSVGRoot::applyContentTransforms(PaintInfo& paintInfo, int parentX, int parentY)
112
bool RenderSVGRoot::selfWillPaint() const
125
// Translate from parent offsets (html renderers) to a relative transform (svg renderers)
127
origin.move(parentX, parentY);
128
origin.move(m_x, m_y);
129
origin.move(borderLeft(), borderTop());
130
origin.move(paddingLeft(), paddingTop());
132
if (origin.x() || origin.y()) {
133
paintInfo.context->concatCTM(TransformationMatrix().translate(origin.x(), origin.y()));
134
paintInfo.rect.move(-origin.x(), -origin.y());
137
// Respect scroll offset caused by html parents
138
TransformationMatrix ctm = RenderContainer::absoluteTransform();
139
paintInfo.rect.move(static_cast<int>(ctm.e()), static_cast<int>(ctm.f()));
141
SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
142
paintInfo.context->concatCTM(TransformationMatrix().scale(svg->currentScale()));
144
if (!viewport().isEmpty()) {
145
if (style()->overflowX() != OVISIBLE)
146
paintInfo.context->clip(enclosingIntRect(viewport())); // FIXME: Eventually we'll want float-precision clipping
148
paintInfo.context->concatCTM(TransformationMatrix().translate(viewport().x(), viewport().y()));
151
paintInfo.context->concatCTM(TransformationMatrix().translate(svg->currentTranslate().x(), svg->currentTranslate().y()));
115
const SVGRenderStyle* svgStyle = style()->svgStyle();
116
SVGResourceFilter* filter = getFilterById(document(), svgStyle->filter());
154
123
void RenderSVGRoot::paint(PaintInfo& paintInfo, int parentX, int parentY)
156
125
if (paintInfo.context->paintingDisabled())
161
SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
162
// A value of zero disables rendering of the element.
163
if (viewport().width() <= 0. || viewport().height() <= 0.)
166
// This should only exist for <svg> renderers
128
IntPoint parentOriginInContainer(parentX, parentY);
129
IntPoint borderBoxOriginInContainer = parentOriginInContainer + IntSize(x(), y());
167
131
if (hasBoxDecorations() && (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection))
168
paintBoxDecorations(paintInfo, m_x + parentX, m_y + parentY);
171
#if ENABLE(SVG_FILTERS)
172
// Spec: groups w/o children still may render filter content.
173
const SVGRenderStyle* svgStyle = style()->svgStyle();
174
SVGResourceFilter* filter = getFilterById(document(), svgStyle->filter());
132
paintBoxDecorations(paintInfo, borderBoxOriginInContainer.x(), borderBoxOriginInContainer.y());
134
// An empty viewport disables rendering. FIXME: Should we still render filters?
135
if (viewportSize().isEmpty())
138
// Don't paint if we don't have kids, except if we have filters we should paint those.
139
if (!firstChild() && !selfWillPaint())
142
// Make a copy of the PaintInfo because applyTransformToPaintInfo will modify the damage rect.
180
143
RenderObject::PaintInfo childPaintInfo(paintInfo);
181
144
childPaintInfo.context->save();
183
applyContentTransforms(childPaintInfo, parentX, parentY);
146
// SVG does not support independent x/y clipping
147
if (style()->overflowX() != OVISIBLE)
148
childPaintInfo.context->clip(overflowClipRect(borderBoxOriginInContainer.x(), borderBoxOriginInContainer.y()));
150
// Convert from container offsets (html renderers) to a relative transform (svg renderers).
151
// Transform from our paint container's coordinate system to our local coords.
152
applyTransformToPaintInfo(childPaintInfo, localToRepaintContainerTransform(parentOriginInContainer));
185
154
SVGResourceFilter* filter = 0;
187
FloatRect boundingBox = relativeBBox(true);
188
if (childPaintInfo.phase == PaintPhaseForeground)
189
prepareToRenderSVGContent(this, childPaintInfo, boundingBox, filter);
191
childPaintInfo.context->concatCTM(svg->viewBoxToViewTransform(width(), height()));
192
RenderContainer::paint(childPaintInfo, 0, 0);
194
if (childPaintInfo.phase == PaintPhaseForeground)
195
finishRenderSVGContent(this, childPaintInfo, boundingBox, filter, paintInfo.context);
155
FloatRect boundingBox = repaintRectInLocalCoordinates();
156
if (childPaintInfo.phase == PaintPhaseForeground)
157
prepareToRenderSVGContent(this, childPaintInfo, boundingBox, filter);
159
RenderBox::paint(childPaintInfo, 0, 0);
161
if (childPaintInfo.phase == PaintPhaseForeground)
162
finishRenderSVGContent(this, childPaintInfo, filter, paintInfo.context);
197
164
childPaintInfo.context->restore();
199
if ((childPaintInfo.phase == PaintPhaseOutline || childPaintInfo.phase == PaintPhaseSelfOutline) && style()->outlineWidth() && style()->visibility() == VISIBLE)
200
paintOutline(childPaintInfo.context, m_absoluteBounds.x(), m_absoluteBounds.y(), m_absoluteBounds.width(), m_absoluteBounds.height(), style());
166
if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) && style()->outlineWidth() && style()->visibility() == VISIBLE)
167
paintOutline(paintInfo.context, borderBoxOriginInContainer.x(), borderBoxOriginInContainer.y(), width(), height(), style());
203
FloatRect RenderSVGRoot::viewport() const
170
const FloatSize& RenderSVGRoot::viewportSize() const
172
return m_viewportSize;
208
175
void RenderSVGRoot::calcViewport()
210
SVGElement* svgelem = static_cast<SVGElement*>(element());
211
if (svgelem->hasTagName(SVGNames::svgTag)) {
212
SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
214
if (!selfNeedsLayout() && !svg->hasRelativeValues())
177
SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
179
if (!selfNeedsLayout() && !svg->hasRelativeValues())
182
if (!svg->hasSetContainerSize()) {
183
// In the normal case of <svg> being stand-alone or in a CSSBoxModel object we use
184
// RenderBox::width()/height() (which pulls data from RenderStyle)
185
m_viewportSize = FloatSize(width(), height());
187
// In the SVGImage case grab the SVGLength values off of SVGSVGElement and use
188
// the special relativeWidthValue accessors which respect the specified containerSize
218
189
SVGLength width = svg->width();
219
if (width.unitType() == LengthTypePercentage && svg->hasSetContainerSize())
220
w = svg->relativeWidthValue();
222
w = width.value(svg);
224
190
SVGLength height = svg->height();
225
if (height.unitType() == LengthTypePercentage && svg->hasSetContainerSize())
226
h = svg->relativeHeightValue();
228
h = height.value(svg);
230
m_viewport = FloatRect(0, 0, w, h);
191
float viewportWidth = (width.unitType() == LengthTypePercentage) ? svg->relativeWidthValue() : width.value(svg);
192
float viewportHeight = (height.unitType() == LengthTypePercentage) ? svg->relativeHeightValue() : height.value(svg);
193
m_viewportSize = FloatSize(viewportWidth, viewportHeight);
234
IntRect RenderSVGRoot::absoluteClippedOverflowRect()
238
for (RenderObject* current = firstChild(); current != 0; current = current->nextSibling())
239
repaintRect.unite(current->absoluteClippedOverflowRect());
241
#if ENABLE(SVG_FILTERS)
242
// Filters can expand the bounding box
243
SVGResourceFilter* filter = getFilterById(document(), style()->svgStyle()->filter());
245
repaintRect.unite(enclosingIntRect(filter->filterBBoxForItemBBox(repaintRect)));
251
void RenderSVGRoot::addFocusRingRects(GraphicsContext* graphicsContext, int, int)
253
graphicsContext->addFocusRingRect(m_absoluteBounds);
256
void RenderSVGRoot::absoluteRects(Vector<IntRect>& rects, int, int)
258
for (RenderObject* current = firstChild(); current != 0; current = current->nextSibling())
259
current->absoluteRects(rects, 0, 0);
262
void RenderSVGRoot::absoluteQuads(Vector<FloatQuad>& quads, bool)
264
for (RenderObject* current = firstChild(); current != 0; current = current->nextSibling())
265
current->absoluteQuads(quads);
268
TransformationMatrix RenderSVGRoot::absoluteTransform() const
270
TransformationMatrix ctm = RenderContainer::absoluteTransform();
271
ctm.translate(m_x, m_y);
272
SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
197
// RenderBox methods will expect coordinates w/o any transforms in coordinates
198
// relative to our borderBox origin. This method gives us exactly that.
199
TransformationMatrix RenderSVGRoot::localToBorderBoxTransform() const
201
TransformationMatrix ctm;
202
IntSize borderAndPadding = borderOriginToContentBox();
203
ctm.translate(borderAndPadding.width(), borderAndPadding.height());
204
SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
273
205
ctm.scale(svg->currentScale());
274
206
ctm.translate(svg->currentTranslate().x(), svg->currentTranslate().y());
275
ctm.translate(viewport().x(), viewport().y());
276
207
return svg->viewBoxToViewTransform(width(), height()) * ctm;
279
FloatRect RenderSVGRoot::relativeBBox(bool includeStroke) const
283
RenderObject* current = firstChild();
284
for (; current != 0; current = current->nextSibling()) {
285
FloatRect childBBox = current->relativeBBox(includeStroke);
286
FloatRect mappedBBox = current->localTransform().mapRect(childBBox);
287
// <svg> can have a viewBox contributing to the bbox
288
if (current->isSVGContainer())
289
mappedBBox = static_cast<RenderSVGContainer*>(current)->viewportTransform().mapRect(mappedBBox);
290
rect.unite(mappedBBox);
210
IntSize RenderSVGRoot::parentOriginToBorderBox() const
212
return IntSize(x(), y());
215
IntSize RenderSVGRoot::borderOriginToContentBox() const
217
return IntSize(borderLeft() + paddingLeft(), borderTop() + paddingTop());
220
TransformationMatrix RenderSVGRoot::localToRepaintContainerTransform(const IntPoint& parentOriginInContainer) const
222
TransformationMatrix parentToContainer;
223
parentToContainer.translate(parentOriginInContainer.x(), parentOriginInContainer.y());
224
return localToParentTransform() * parentToContainer;
227
TransformationMatrix RenderSVGRoot::localToParentTransform() const
229
IntSize parentToBorderBoxOffset = parentOriginToBorderBox();
231
TransformationMatrix borderBoxOriginToParentOrigin;
232
borderBoxOriginToParentOrigin.translate(parentToBorderBoxOffset.width(), parentToBorderBoxOffset.height());
234
return localToBorderBoxTransform() * borderBoxOriginToParentOrigin;
237
// FIXME: This method should be removed as soon as callers to RenderBox::absoluteTransform() can be removed.
238
TransformationMatrix RenderSVGRoot::absoluteTransform() const
240
// This would apply localTransform() twice if localTransform() were not the identity.
241
return localToParentTransform() * RenderBox::absoluteTransform();
244
FloatRect RenderSVGRoot::objectBoundingBox() const
246
return computeContainerBoundingBox(this, false);
249
FloatRect RenderSVGRoot::repaintRectInLocalCoordinates() const
251
// FIXME: This does not include the border but it should!
252
return computeContainerBoundingBox(this, true);
296
255
TransformationMatrix RenderSVGRoot::localTransform() const
298
257
return TransformationMatrix();
260
void RenderSVGRoot::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& repaintRect, bool fixed)
262
// Apply our local transforms (except for x/y translation) and call RenderBox's method to handle all the normal CSS Box model bits
263
repaintRect = localToBorderBoxTransform().mapRect(repaintRect);
264
RenderBox::computeRectForRepaint(repaintContainer, repaintRect, fixed);
267
void RenderSVGRoot::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed , bool useTransforms, TransformState& transformState) const
269
ASSERT(!fixed); // We should have no fixed content in the SVG rendering tree.
270
ASSERT(useTransforms); // mapping a point through SVG w/o respecting trasnforms is useless.
272
// Transform to our border box and let RenderBox transform the rest of the way.
273
transformState.applyTransform(localToBorderBoxTransform());
274
RenderBox::mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState);
301
277
bool RenderSVGRoot::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int _x, int _y, int _tx, int _ty, HitTestAction hitTestAction)
303
TransformationMatrix ctm = RenderContainer::absoluteTransform();
305
int sx = (_tx - static_cast<int>(ctm.e())); // scroll offset
306
int sy = (_ty - static_cast<int>(ctm.f())); // scroll offset
308
if (!viewport().isEmpty()
309
&& style()->overflowX() == OHIDDEN
310
&& style()->overflowY() == OHIDDEN) {
311
int tx = m_x - _tx + sx;
312
int ty = m_y - _ty + sy;
314
// Check if we need to do anything at all.
315
IntRect overflowBox = overflowRect(false);
316
overflowBox.move(tx, ty);
317
ctm.translate(viewport().x(), viewport().y());
318
double localX, localY;
319
ctm.inverse().map(_x - _tx, _y - _ty, &localX, &localY);
320
if (!overflowBox.contains((int)localX, (int)localY))
279
IntPoint pointInContainer(_x, _y);
280
IntSize containerToParentOffset(_tx, _ty);
282
IntPoint pointInParent = pointInContainer - containerToParentOffset;
283
IntPoint pointInBorderBox = pointInParent - parentOriginToBorderBox();
285
// Note: For now, we're ignoring hits to border and padding for <svg>
287
if (style()->overflowX() == OHIDDEN) {
288
// SVG doesn't support independent x/y overflow
289
ASSERT(style()->overflowY() == OHIDDEN);
290
IntPoint pointInContentBox = pointInBorderBox - borderOriginToContentBox();
291
if (!contentBoxRect().contains(pointInContentBox))
295
IntPoint localPoint = localToParentTransform().inverse().mapPoint(pointInParent);
324
297
for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
325
if (child->nodeAtPoint(request, result, _x - sx, _y - sy, 0, 0, hitTestAction)) {
326
updateHitTestResult(result, IntPoint(_x - _tx, _y - _ty));
298
if (child->nodeAtFloatPoint(request, result, localPoint, hitTestAction)) {
299
// FIXME: CSS/HTML assumes the local point is relative to the border box, right?
300
updateHitTestResult(result, pointInBorderBox);
331
// Spec: Only graphical elements can be targeted by the mouse, period.
305
// Spec: Only graphical elements can be targeted by the mouse, so we don't check self here.
332
306
// 16.4: "If there are no graphics elements whose relevant graphics content is under the pointer (i.e., there is no target element), the event is not dispatched."
336
void RenderSVGRoot::position(InlineBox* box)
338
RenderContainer::position(box);
339
if (m_absoluteBounds.isEmpty())
340
setNeedsLayout(true, false);
345
312
#endif // ENABLE(SVG)