|
1 /* |
|
2 * This file is part of the WebKit project. |
|
3 * |
|
4 * Copyright (C) 2006 Apple Computer, Inc. |
|
5 * |
|
6 * This library is free software; you can redistribute it and/or |
|
7 * modify it under the terms of the GNU Library General Public |
|
8 * License as published by the Free Software Foundation; either |
|
9 * version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This library is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * Library General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU Library General Public License |
|
17 * along with this library; see the file COPYING.LIB. If not, write to |
|
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 * Boston, MA 02110-1301, USA. |
|
20 * |
|
21 */ |
|
22 |
|
23 #include "config.h" |
|
24 |
|
25 #if ENABLE(SVG) && ENABLE(SVG_EXPERIMENTAL_FEATURES) |
|
26 |
|
27 #include "RenderForeignObject.h" |
|
28 |
|
29 #include "GraphicsContext.h" |
|
30 #include "RenderView.h" |
|
31 #include "SVGForeignObjectElement.h" |
|
32 #include "SVGLength.h" |
|
33 |
|
34 namespace WebCore { |
|
35 |
|
36 RenderForeignObject::RenderForeignObject(SVGForeignObjectElement* node) |
|
37 : RenderSVGBlock(node) |
|
38 { |
|
39 } |
|
40 |
|
41 AffineTransform RenderForeignObject::translationForAttributes() |
|
42 { |
|
43 SVGForeignObjectElement* foreign = static_cast<SVGForeignObjectElement*>(element()); |
|
44 return AffineTransform().translate(foreign->x().value(), foreign->y().value()); |
|
45 } |
|
46 |
|
47 void RenderForeignObject::paint(PaintInfo& paintInfo, int parentX, int parentY) |
|
48 { |
|
49 if (paintInfo.context->paintingDisabled()) |
|
50 return; |
|
51 |
|
52 paintInfo.context->save(); |
|
53 paintInfo.context->concatCTM(AffineTransform().translate(parentX, parentY)); |
|
54 paintInfo.context->concatCTM(localTransform()); |
|
55 paintInfo.context->concatCTM(translationForAttributes()); |
|
56 paintInfo.context->clip(getClipRect(parentX, parentY)); |
|
57 |
|
58 float opacity = style()->opacity(); |
|
59 if (opacity < 1.0f) |
|
60 // FIXME: Possible optimization by clipping to bbox here, once relativeBBox is implemented & clip, mask and filter support added. |
|
61 paintInfo.context->beginTransparencyLayer(opacity); |
|
62 |
|
63 PaintInfo pi(paintInfo); |
|
64 pi.rect = absoluteTransform().inverse().mapRect(paintInfo.rect); |
|
65 RenderBlock::paint(pi, 0, 0); |
|
66 |
|
67 if (opacity < 1.0f) |
|
68 paintInfo.context->endTransparencyLayer(); |
|
69 |
|
70 paintInfo.context->restore(); |
|
71 } |
|
72 |
|
73 void RenderForeignObject::computeAbsoluteRepaintRect(IntRect& r, bool f) |
|
74 { |
|
75 AffineTransform transform = translationForAttributes() * localTransform(); |
|
76 r = transform.mapRect(r); |
|
77 |
|
78 RenderBlock::computeAbsoluteRepaintRect(r, f); |
|
79 } |
|
80 |
|
81 bool RenderForeignObject::requiresLayer() |
|
82 { |
|
83 return false; |
|
84 } |
|
85 |
|
86 void RenderForeignObject::layout() |
|
87 { |
|
88 ASSERT(needsLayout()); |
|
89 |
|
90 // Arbitrary affine transforms are incompatible with LayoutState. |
|
91 view()->disableLayoutState(); |
|
92 |
|
93 IntRect oldBounds; |
|
94 IntRect oldOutlineBox; |
|
95 bool checkForRepaint = checkForRepaintDuringLayout(); |
|
96 if (checkForRepaint) { |
|
97 oldBounds = m_absoluteBounds; |
|
98 oldOutlineBox = absoluteOutlineBox(); |
|
99 } |
|
100 |
|
101 RenderBlock::layout(); |
|
102 |
|
103 m_absoluteBounds = absoluteClippedOverflowRect(); |
|
104 |
|
105 if (checkForRepaint) |
|
106 repaintAfterLayoutIfNeeded(oldBounds, oldOutlineBox); |
|
107 |
|
108 view()->enableLayoutState(); |
|
109 setNeedsLayout(false); |
|
110 } |
|
111 |
|
112 bool RenderForeignObject::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestAction hitTestAction) |
|
113 { |
|
114 AffineTransform totalTransform = absoluteTransform(); |
|
115 totalTransform *= translationForAttributes(); |
|
116 double localX, localY; |
|
117 totalTransform.inverse().map(x, y, &localX, &localY); |
|
118 return RenderBlock::nodeAtPoint(request, result, static_cast<int>(localX), static_cast<int>(localY), tx, ty, hitTestAction); |
|
119 } |
|
120 |
|
121 } // namespace WebCore |
|
122 |
|
123 #endif // ENABLE(SVG) |