1 /*
2 * Copyright (C) 2006 Apple Computer, Inc.
3 * Copyright (C) 2009 Google, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22 #include "config.h"
23
24 #if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
25 #include "RenderForeignObject.h"
26
27 #include "GraphicsContext.h"
28 #include "RenderView.h"
29 #include "SVGForeignObjectElement.h"
30 #include "SVGLength.h"
31 #include "SVGRenderSupport.h"
32 #include "SVGTransformList.h"
33
34 namespace WebCore {
35
RenderForeignObject(SVGForeignObjectElement * node)36 RenderForeignObject::RenderForeignObject(SVGForeignObjectElement* node)
37 : RenderSVGBlock(node)
38 {
39 }
40
translationForAttributes() const41 TransformationMatrix RenderForeignObject::translationForAttributes() const
42 {
43 SVGForeignObjectElement* foreign = static_cast<SVGForeignObjectElement*>(node());
44 return TransformationMatrix().translate(foreign->x().value(foreign), foreign->y().value(foreign));
45 }
46
paint(PaintInfo & paintInfo,int,int)47 void RenderForeignObject::paint(PaintInfo& paintInfo, int, int)
48 {
49 if (paintInfo.context->paintingDisabled())
50 return;
51
52 // Copy the paint info so that modifications to the damage rect do not affect callers
53 PaintInfo childPaintInfo = paintInfo;
54 childPaintInfo.context->save();
55 applyTransformToPaintInfo(childPaintInfo, localToParentTransform());
56 childPaintInfo.context->clip(clipRect(0, 0));
57
58 float opacity = style()->opacity();
59 if (opacity < 1.0f)
60 childPaintInfo.context->beginTransparencyLayer(opacity);
61
62 RenderBlock::paint(childPaintInfo, 0, 0);
63
64 if (opacity < 1.0f)
65 childPaintInfo.context->endTransparencyLayer();
66
67 childPaintInfo.context->restore();
68 }
69
objectBoundingBox() const70 FloatRect RenderForeignObject::objectBoundingBox() const
71 {
72 return borderBoxRect();
73 }
74
repaintRectInLocalCoordinates() const75 FloatRect RenderForeignObject::repaintRectInLocalCoordinates() const
76 {
77 // HACK: to maintain historical LayoutTest results for now.
78 // RenderForeignObject is a RenderBlock (not a RenderSVGModelObject) so this
79 // should not affect repaint correctness. But it should really be:
80 // return borderBoxRect();
81 return FloatRect();
82 }
83
computeRectForRepaint(RenderBoxModelObject * repaintContainer,IntRect & rect,bool fixed)84 void RenderForeignObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed)
85 {
86 rect = localToParentTransform().mapRect(rect);
87 RenderBlock::computeRectForRepaint(repaintContainer, rect, fixed);
88 }
89
localToParentTransform() const90 TransformationMatrix RenderForeignObject::localToParentTransform() const
91 {
92 return localTransform() * translationForAttributes();
93 }
94
layout()95 void RenderForeignObject::layout()
96 {
97 ASSERT(needsLayout());
98 ASSERT(!view()->layoutStateEnabled()); // RenderSVGRoot disables layoutState for the SVG rendering tree.
99
100 LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
101 m_localTransform = static_cast<SVGForeignObjectElement*>(node())->animatedLocalTransform();
102
103 RenderBlock::layout();
104 repainter.repaintAfterLayout();
105
106 setNeedsLayout(false);
107 }
108
nodeAtFloatPoint(const HitTestRequest & request,HitTestResult & result,const FloatPoint & pointInParent,HitTestAction hitTestAction)109 bool RenderForeignObject::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
110 {
111 FloatPoint localPoint = localToParentTransform().inverse().mapPoint(pointInParent);
112 return RenderBlock::nodeAtPoint(request, result, static_cast<int>(localPoint.x()), static_cast<int>(localPoint.y()), 0, 0, hitTestAction);
113 }
114
nodeAtPoint(const HitTestRequest &,HitTestResult &,int,int,int,int,HitTestAction)115 bool RenderForeignObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction)
116 {
117 ASSERT_NOT_REACHED();
118 return false;
119 }
120
121 } // namespace WebCore
122
123 #endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
124