OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> | 2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> |
3 * Copyright (C) 2006 Apple Computer, Inc. | 3 * Copyright (C) 2006 Apple Computer, Inc. |
4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> | 4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> |
5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org> | 5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org> |
6 * Copyright (C) 2009 Google, Inc. | 6 * Copyright (C) 2009 Google, Inc. |
7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
11 * modify it under the terms of the GNU Library General Public | 11 * modify it under the terms of the GNU Library General Public |
12 * License as published by the Free Software Foundation; either | 12 * License as published by the Free Software Foundation; either |
13 * version 2 of the License, or (at your option) any later version. | 13 * version 2 of the License, or (at your option) any later version. |
14 * | 14 * |
15 * This library is distributed in the hope that it will be useful, | 15 * This library is distributed in the hope that it will be useful, |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 * Library General Public License for more details. | 18 * Library General Public License for more details. |
19 * | 19 * |
20 * You should have received a copy of the GNU Library General Public License | 20 * You should have received a copy of the GNU Library General Public License |
21 * along with this library; see the file COPYING.LIB. If not, write to | 21 * along with this library; see the file COPYING.LIB. If not, write to |
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #include "core/rendering/svg/RenderSVGImage.h" | 28 #include "core/rendering/svg/RenderSVGImage.h" |
29 | 29 |
30 #include "core/rendering/GraphicsContextAnnotator.h" | 30 #include "core/paint/SVGImagePainter.h" |
31 #include "core/rendering/ImageQualityController.h" | 31 #include "core/rendering/ImageQualityController.h" |
32 #include "core/rendering/PointerEventsHitRules.h" | 32 #include "core/rendering/PointerEventsHitRules.h" |
33 #include "core/rendering/RenderImageResource.h" | 33 #include "core/rendering/RenderImageResource.h" |
34 #include "core/rendering/svg/RenderSVGResource.h" | 34 #include "core/rendering/svg/RenderSVGResource.h" |
35 #include "core/rendering/svg/SVGRenderSupport.h" | 35 #include "core/rendering/svg/SVGRenderSupport.h" |
36 #include "core/rendering/svg/SVGRenderingContext.h" | |
37 #include "core/rendering/svg/SVGResources.h" | 36 #include "core/rendering/svg/SVGResources.h" |
38 #include "core/rendering/svg/SVGResourcesCache.h" | 37 #include "core/rendering/svg/SVGResourcesCache.h" |
39 #include "core/svg/SVGImageElement.h" | 38 #include "core/svg/SVGImageElement.h" |
40 #include "platform/LengthFunctions.h" | 39 #include "platform/LengthFunctions.h" |
41 #include "platform/graphics/GraphicsContextStateSaver.h" | |
42 | 40 |
43 namespace blink { | 41 namespace blink { |
44 | 42 |
45 RenderSVGImage::RenderSVGImage(SVGImageElement* impl) | 43 RenderSVGImage::RenderSVGImage(SVGImageElement* impl) |
46 : RenderSVGModelObject(impl) | 44 : RenderSVGModelObject(impl) |
47 , m_needsBoundariesUpdate(true) | 45 , m_needsBoundariesUpdate(true) |
48 , m_needsTransformUpdate(true) | 46 , m_needsTransformUpdate(true) |
49 , m_imageResource(RenderImageResource::create()) | 47 , m_imageResource(RenderImageResource::create()) |
50 { | 48 { |
51 m_imageResource->initialize(this); | 49 m_imageResource->initialize(this); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 139 |
142 // If our bounds changed, notify the parents. | 140 // If our bounds changed, notify the parents. |
143 if (transformOrBoundariesUpdate) | 141 if (transformOrBoundariesUpdate) |
144 RenderSVGModelObject::setNeedsBoundariesUpdate(); | 142 RenderSVGModelObject::setNeedsBoundariesUpdate(); |
145 | 143 |
146 clearNeedsLayout(); | 144 clearNeedsLayout(); |
147 } | 145 } |
148 | 146 |
149 void RenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&) | 147 void RenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&) |
150 { | 148 { |
151 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this); | 149 SVGImagePainter(*this).paint(paintInfo); |
152 | |
153 if (paintInfo.phase != PaintPhaseForeground | |
154 || style()->visibility() == HIDDEN | |
155 || !m_imageResource->hasImage()) | |
156 return; | |
157 | |
158 FloatRect boundingBox = paintInvalidationRectInLocalCoordinates(); | |
159 if (!SVGRenderSupport::paintInfoIntersectsPaintInvalidationRect(boundingBox,
m_localTransform, paintInfo)) | |
160 return; | |
161 | |
162 PaintInfo childPaintInfo(paintInfo); | |
163 GraphicsContextStateSaver stateSaver(*childPaintInfo.context, false); | |
164 | |
165 if (!m_localTransform.isIdentity()) { | |
166 stateSaver.save(); | |
167 childPaintInfo.applyTransform(m_localTransform, false); | |
168 } | |
169 if (!m_objectBoundingBox.isEmpty()) { | |
170 // SVGRenderingContext may taint the state - make sure we're always savi
ng. | |
171 SVGRenderingContext renderingContext(this, childPaintInfo, stateSaver.sa
ved() ? | |
172 SVGRenderingContext::DontSaveGraphicsContext : SVGRenderingContext::
SaveGraphicsContext); | |
173 | |
174 if (renderingContext.isRenderingPrepared()) { | |
175 if (style()->svgStyle().bufferedRendering() == BR_STATIC && renderin
gContext.bufferForeground(m_bufferedForeground)) | |
176 return; | |
177 | |
178 paintForeground(childPaintInfo); | |
179 } | |
180 } | |
181 | |
182 if (style()->outlineWidth()) | |
183 paintOutline(childPaintInfo, IntRect(boundingBox)); | |
184 } | |
185 | |
186 void RenderSVGImage::paintForeground(PaintInfo& paintInfo) | |
187 { | |
188 RefPtr<Image> image = m_imageResource->image(); | |
189 FloatRect destRect = m_objectBoundingBox; | |
190 FloatRect srcRect(0, 0, image->width(), image->height()); | |
191 | |
192 SVGImageElement* imageElement = toSVGImageElement(element()); | |
193 imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect,
srcRect); | |
194 | |
195 InterpolationQuality interpolationQuality = InterpolationDefault; | |
196 if (style()->svgStyle().bufferedRendering() != BR_STATIC) | |
197 interpolationQuality = ImageQualityController::imageQualityController()-
>chooseInterpolationQuality(paintInfo.context, this, image.get(), image.get(), L
ayoutSize(destRect.size())); | |
198 | |
199 InterpolationQuality previousInterpolationQuality = paintInfo.context->image
InterpolationQuality(); | |
200 paintInfo.context->setImageInterpolationQuality(interpolationQuality); | |
201 paintInfo.context->drawImage(image.get(), destRect, srcRect, CompositeSource
Over); | |
202 paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality
); | |
203 } | 150 } |
204 | 151 |
205 void RenderSVGImage::invalidateBufferedForeground() | 152 void RenderSVGImage::invalidateBufferedForeground() |
206 { | 153 { |
207 m_bufferedForeground.clear(); | 154 m_bufferedForeground.clear(); |
208 } | 155 } |
209 | 156 |
210 bool RenderSVGImage::nodeAtFloatPoint(const HitTestRequest& request, HitTestResu
lt& result, const FloatPoint& pointInParent, HitTestAction hitTestAction) | 157 bool RenderSVGImage::nodeAtFloatPoint(const HitTestRequest& request, HitTestResu
lt& result, const FloatPoint& pointInParent, HitTestAction hitTestAction) |
211 { | 158 { |
212 // We only draw in the forground phase, so we only hit-test then. | 159 // We only draw in the forground phase, so we only hit-test then. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 200 |
254 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo
int&, const RenderLayerModelObject*) const | 201 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo
int&, const RenderLayerModelObject*) const |
255 { | 202 { |
256 // this is called from paint() after the localTransform has already been app
lied | 203 // this is called from paint() after the localTransform has already been app
lied |
257 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates(
)); | 204 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates(
)); |
258 if (!contentRect.isEmpty()) | 205 if (!contentRect.isEmpty()) |
259 rects.append(contentRect); | 206 rects.append(contentRect); |
260 } | 207 } |
261 | 208 |
262 } // namespace blink | 209 } // namespace blink |
OLD | NEW |