| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 5 * Copyright (C) 2011 Dirk Schulze <krit@webkit.org> | 5 * Copyright (C) 2011 Dirk Schulze <krit@webkit.org> |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 | |
| 25 #include "core/rendering/svg/RenderSVGResourceClipper.h" | 24 #include "core/rendering/svg/RenderSVGResourceClipper.h" |
| 26 | 25 |
| 27 #include "core/SVGNames.h" | 26 #include "core/SVGNames.h" |
| 28 #include "core/dom/ElementTraversal.h" | 27 #include "core/dom/ElementTraversal.h" |
| 29 #include "core/frame/FrameView.h" | |
| 30 #include "core/frame/LocalFrame.h" | |
| 31 #include "core/rendering/HitTestResult.h" | 28 #include "core/rendering/HitTestResult.h" |
| 29 #include "core/rendering/PaintInfo.h" |
| 32 #include "core/rendering/svg/SVGRenderSupport.h" | 30 #include "core/rendering/svg/SVGRenderSupport.h" |
| 33 #include "core/rendering/svg/SVGRenderingContext.h" | 31 #include "core/rendering/svg/SVGRenderingContext.h" |
| 34 #include "core/rendering/svg/SVGResources.h" | 32 #include "core/rendering/svg/SVGResources.h" |
| 35 #include "core/rendering/svg/SVGResourcesCache.h" | 33 #include "core/rendering/svg/SVGResourcesCache.h" |
| 36 #include "core/svg/SVGUseElement.h" | 34 #include "core/svg/SVGUseElement.h" |
| 37 #include "platform/RuntimeEnabledFeatures.h" | 35 #include "platform/RuntimeEnabledFeatures.h" |
| 38 #include "platform/graphics/DisplayList.h" | 36 #include "platform/graphics/DisplayList.h" |
| 39 #include "platform/graphics/GraphicsContextStateSaver.h" | 37 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 40 #include "wtf/TemporaryChange.h" | 38 #include "wtf/TemporaryChange.h" |
| 41 | 39 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 { | 238 { |
| 241 ASSERT(context); | 239 ASSERT(context); |
| 242 ASSERT(frame()); | 240 ASSERT(frame()); |
| 243 | 241 |
| 244 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat
es) to avoid the intersection | 242 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat
es) to avoid the intersection |
| 245 // with local clips/mask, which may yield incorrect results when mixing obje
ctBoundingBox and | 243 // with local clips/mask, which may yield incorrect results when mixing obje
ctBoundingBox and |
| 246 // userSpaceOnUse units (http://crbug.com/294900). | 244 // userSpaceOnUse units (http://crbug.com/294900). |
| 247 FloatRect bounds = strokeBoundingBox(); | 245 FloatRect bounds = strokeBoundingBox(); |
| 248 context->beginRecording(bounds); | 246 context->beginRecording(bounds); |
| 249 | 247 |
| 250 // Switch to a paint behavior where all children of this <clipPath> will be
rendered using special constraints: | |
| 251 // - fill-opacity/stroke-opacity/opacity set to 1 | |
| 252 // - masker/filter not applied when rendering the children | |
| 253 // - fill is set to the initial fill paint server (solid, black) | |
| 254 // - stroke is set to the initial stroke paint server (none) | |
| 255 PaintBehavior oldBehavior = frame()->view()->paintBehavior(); | |
| 256 frame()->view()->setPaintBehavior(oldBehavior | PaintBehaviorRenderingClipPa
thAsMask); | |
| 257 | |
| 258 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 248 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
| 259 RenderObject* renderer = childElement->renderer(); | 249 RenderObject* renderer = childElement->renderer(); |
| 260 if (!renderer) | 250 if (!renderer) |
| 261 continue; | 251 continue; |
| 262 | 252 |
| 263 RenderStyle* style = renderer->style(); | 253 RenderStyle* style = renderer->style(); |
| 264 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) | 254 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) |
| 265 continue; | 255 continue; |
| 266 | 256 |
| 267 WindRule newClipRule = style->svgStyle().clipRule(); | 257 WindRule newClipRule = style->svgStyle().clipRule(); |
| 268 bool isUseElement = isSVGUseElement(*childElement); | 258 bool isUseElement = isSVGUseElement(*childElement); |
| 269 if (isUseElement) { | 259 if (isUseElement) { |
| 270 SVGUseElement& useElement = toSVGUseElement(*childElement); | 260 SVGUseElement& useElement = toSVGUseElement(*childElement); |
| 271 renderer = useElement.rendererClipChild(); | 261 renderer = useElement.rendererClipChild(); |
| 272 if (!renderer) | 262 if (!renderer) |
| 273 continue; | 263 continue; |
| 274 if (!useElement.hasAttribute(SVGNames::clip_ruleAttr)) | 264 if (!useElement.hasAttribute(SVGNames::clip_ruleAttr)) |
| 275 newClipRule = renderer->style()->svgStyle().clipRule(); | 265 newClipRule = renderer->style()->svgStyle().clipRule(); |
| 276 } | 266 } |
| 277 | 267 |
| 278 // Only shapes, paths and texts are allowed for clipping. | 268 // Only shapes, paths and texts are allowed for clipping. |
| 279 if (!renderer->isSVGShape() && !renderer->isSVGText()) | 269 if (!renderer->isSVGShape() && !renderer->isSVGText()) |
| 280 continue; | 270 continue; |
| 281 | 271 |
| 282 context->setFillRule(newClipRule); | 272 context->setFillRule(newClipRule); |
| 283 | 273 |
| 284 if (isUseElement) | 274 if (isUseElement) |
| 285 renderer = childElement->renderer(); | 275 renderer = childElement->renderer(); |
| 286 | 276 |
| 287 SVGRenderingContext::renderSubtree(context, renderer); | 277 // Switch to a paint behavior where all children of this <clipPath> will
be rendered using special constraints: |
| 278 // - fill-opacity/stroke-opacity/opacity set to 1 |
| 279 // - masker/filter not applied when rendering the children |
| 280 // - fill is set to the initial fill paint server (solid, black) |
| 281 // - stroke is set to the initial stroke paint server (none) |
| 282 PaintInfo info(context, PaintInfo::infiniteRect(), PaintPhaseForeground,
PaintBehaviorRenderingClipPathAsMask); |
| 283 renderer->paint(info, IntPoint()); |
| 288 } | 284 } |
| 289 | 285 |
| 290 frame()->view()->setPaintBehavior(oldBehavior); | |
| 291 | |
| 292 m_clipContentDisplayList = context->endRecording(); | 286 m_clipContentDisplayList = context->endRecording(); |
| 293 } | 287 } |
| 294 | 288 |
| 295 void RenderSVGResourceClipper::calculateClipContentPaintInvalidationRect() | 289 void RenderSVGResourceClipper::calculateClipContentPaintInvalidationRect() |
| 296 { | 290 { |
| 297 // This is a rough heuristic to appraise the clip size and doesn't consider
clip on clip. | 291 // This is a rough heuristic to appraise the clip size and doesn't consider
clip on clip. |
| 298 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 292 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
| 299 RenderObject* renderer = childElement->renderer(); | 293 RenderObject* renderer = childElement->renderer(); |
| 300 if (!renderer) | 294 if (!renderer) |
| 301 continue; | 295 continue; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 AffineTransform transform; | 351 AffineTransform transform; |
| 358 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); | 352 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); |
| 359 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h
eight()); | 353 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h
eight()); |
| 360 return transform.mapRect(m_clipBoundaries); | 354 return transform.mapRect(m_clipBoundaries); |
| 361 } | 355 } |
| 362 | 356 |
| 363 return m_clipBoundaries; | 357 return m_clipBoundaries; |
| 364 } | 358 } |
| 365 | 359 |
| 366 } | 360 } |
| OLD | NEW |