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. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 bool LayoutSVGResourceClipper::tryPathOnlyClipping(DisplayItemClient client, Gra
phicsContext* context, | 79 bool LayoutSVGResourceClipper::tryPathOnlyClipping(DisplayItemClient client, Gra
phicsContext* context, |
80 const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundi
ngBox) { | 80 const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundi
ngBox) { |
81 // If the current clip-path gets clipped itself, we have to fallback to mask
ing. | 81 // If the current clip-path gets clipped itself, we have to fallback to mask
ing. |
82 if (!style()->svgStyle().clipperResource().isEmpty()) | 82 if (!style()->svgStyle().clipperResource().isEmpty()) |
83 return false; | 83 return false; |
84 WindRule clipRule = RULE_NONZERO; | 84 WindRule clipRule = RULE_NONZERO; |
85 Path clipPath = Path(); | 85 Path clipPath = Path(); |
86 | 86 |
87 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 87 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
88 LayoutObject* renderer = childElement->renderer(); | 88 LayoutObject* renderer = childElement->layoutObject(); |
89 if (!renderer) | 89 if (!renderer) |
90 continue; | 90 continue; |
91 // Only shapes or paths are supported for direct clipping. We need to fa
llback to masking for texts. | 91 // Only shapes or paths are supported for direct clipping. We need to fa
llback to masking for texts. |
92 if (renderer->isSVGText()) | 92 if (renderer->isSVGText()) |
93 return false; | 93 return false; |
94 if (!childElement->isSVGGraphicsElement()) | 94 if (!childElement->isSVGGraphicsElement()) |
95 continue; | 95 continue; |
96 SVGGraphicsElement* styled = toSVGGraphicsElement(childElement); | 96 SVGGraphicsElement* styled = toSVGGraphicsElement(childElement); |
97 const LayoutStyle* style = renderer->style(); | 97 const LayoutStyle* style = renderer->style(); |
98 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) | 98 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // userSpaceOnUse units (http://crbug.com/294900). | 263 // userSpaceOnUse units (http://crbug.com/294900). |
264 FloatRect bounds = strokeBoundingBox(); | 264 FloatRect bounds = strokeBoundingBox(); |
265 | 265 |
266 OwnPtr<DisplayItemList> displayItemList; | 266 OwnPtr<DisplayItemList> displayItemList; |
267 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 267 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
268 displayItemList = DisplayItemList::create(); | 268 displayItemList = DisplayItemList::create(); |
269 GraphicsContext context(nullptr, displayItemList.get()); | 269 GraphicsContext context(nullptr, displayItemList.get()); |
270 context.beginRecording(bounds); | 270 context.beginRecording(bounds); |
271 | 271 |
272 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 272 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
273 LayoutObject* renderer = childElement->renderer(); | 273 LayoutObject* renderer = childElement->layoutObject(); |
274 if (!renderer) | 274 if (!renderer) |
275 continue; | 275 continue; |
276 | 276 |
277 const LayoutStyle* style = renderer->style(); | 277 const LayoutStyle* style = renderer->style(); |
278 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) | 278 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) |
279 continue; | 279 continue; |
280 | 280 |
281 WindRule newClipRule = style->svgStyle().clipRule(); | 281 WindRule newClipRule = style->svgStyle().clipRule(); |
282 bool isUseElement = isSVGUseElement(*childElement); | 282 bool isUseElement = isSVGUseElement(*childElement); |
283 if (isUseElement) { | 283 if (isUseElement) { |
284 SVGUseElement& useElement = toSVGUseElement(*childElement); | 284 SVGUseElement& useElement = toSVGUseElement(*childElement); |
285 renderer = useElement.rendererClipChild(); | 285 renderer = useElement.rendererClipChild(); |
286 if (!renderer) | 286 if (!renderer) |
287 continue; | 287 continue; |
288 if (!useElement.hasAttribute(SVGNames::clip_ruleAttr)) | 288 if (!useElement.hasAttribute(SVGNames::clip_ruleAttr)) |
289 newClipRule = renderer->style()->svgStyle().clipRule(); | 289 newClipRule = renderer->style()->svgStyle().clipRule(); |
290 } | 290 } |
291 | 291 |
292 // Only shapes, paths and texts are allowed for clipping. | 292 // Only shapes, paths and texts are allowed for clipping. |
293 if (!renderer->isSVGShape() && !renderer->isSVGText()) | 293 if (!renderer->isSVGShape() && !renderer->isSVGText()) |
294 continue; | 294 continue; |
295 | 295 |
296 context.setFillRule(newClipRule); | 296 context.setFillRule(newClipRule); |
297 | 297 |
298 if (isUseElement) | 298 if (isUseElement) |
299 renderer = childElement->renderer(); | 299 renderer = childElement->layoutObject(); |
300 | 300 |
301 // Switch to a paint behavior where all children of this <clipPath> will
be rendered using special constraints: | 301 // Switch to a paint behavior where all children of this <clipPath> will
be rendered using special constraints: |
302 // - fill-opacity/stroke-opacity/opacity set to 1 | 302 // - fill-opacity/stroke-opacity/opacity set to 1 |
303 // - masker/filter not applied when rendering the children | 303 // - masker/filter not applied when rendering the children |
304 // - fill is set to the initial fill paint server (solid, black) | 304 // - fill is set to the initial fill paint server (solid, black) |
305 // - stroke is set to the initial stroke paint server (none) | 305 // - stroke is set to the initial stroke paint server (none) |
306 PaintInfo info(&context, LayoutRect::infiniteIntRect(), PaintPhaseForegr
ound, PaintBehaviorRenderingClipPathAsMask); | 306 PaintInfo info(&context, LayoutRect::infiniteIntRect(), PaintPhaseForegr
ound, PaintBehaviorRenderingClipPathAsMask); |
307 renderer->paint(info, IntPoint()); | 307 renderer->paint(info, IntPoint()); |
308 } | 308 } |
309 | 309 |
310 if (displayItemList) | 310 if (displayItemList) |
311 displayItemList->replay(&context); | 311 displayItemList->replay(&context); |
312 return context.endRecording(); | 312 return context.endRecording(); |
313 } | 313 } |
314 | 314 |
315 void LayoutSVGResourceClipper::calculateClipContentPaintInvalidationRect() | 315 void LayoutSVGResourceClipper::calculateClipContentPaintInvalidationRect() |
316 { | 316 { |
317 // This is a rough heuristic to appraise the clip size and doesn't consider
clip on clip. | 317 // This is a rough heuristic to appraise the clip size and doesn't consider
clip on clip. |
318 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 318 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
319 LayoutObject* renderer = childElement->renderer(); | 319 LayoutObject* renderer = childElement->layoutObject(); |
320 if (!renderer) | 320 if (!renderer) |
321 continue; | 321 continue; |
322 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen
t(*childElement)) | 322 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen
t(*childElement)) |
323 continue; | 323 continue; |
324 const LayoutStyle* style = renderer->style(); | 324 const LayoutStyle* style = renderer->style(); |
325 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) | 325 if (!style || style->display() == NONE || style->visibility() != VISIBLE
) |
326 continue; | 326 continue; |
327 m_clipBoundaries.unite(renderer->localToParentTransform().mapRect(render
er->paintInvalidationRectInLocalCoordinates())); | 327 m_clipBoundaries.unite(renderer->localToParentTransform().mapRect(render
er->paintInvalidationRectInLocalCoordinates())); |
328 } | 328 } |
329 m_clipBoundaries = toSVGClipPathElement(element())->calculateAnimatedLocalTr
ansform().mapRect(m_clipBoundaries); | 329 m_clipBoundaries = toSVGClipPathElement(element())->calculateAnimatedLocalTr
ansform().mapRect(m_clipBoundaries); |
(...skipping 12 matching lines...) Expand all Loading... |
342 point = transform.inverse().mapPoint(point); | 342 point = transform.inverse().mapPoint(point); |
343 } | 343 } |
344 | 344 |
345 AffineTransform animatedLocalTransform = toSVGClipPathElement(element())->ca
lculateAnimatedLocalTransform(); | 345 AffineTransform animatedLocalTransform = toSVGClipPathElement(element())->ca
lculateAnimatedLocalTransform(); |
346 if (!animatedLocalTransform.isInvertible()) | 346 if (!animatedLocalTransform.isInvertible()) |
347 return false; | 347 return false; |
348 | 348 |
349 point = animatedLocalTransform.inverse().mapPoint(point); | 349 point = animatedLocalTransform.inverse().mapPoint(point); |
350 | 350 |
351 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 351 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
352 LayoutObject* renderer = childElement->renderer(); | 352 LayoutObject* renderer = childElement->layoutObject(); |
353 if (!renderer) | 353 if (!renderer) |
354 continue; | 354 continue; |
355 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen
t(*childElement)) | 355 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen
t(*childElement)) |
356 continue; | 356 continue; |
357 IntPoint hitPoint; | 357 IntPoint hitPoint; |
358 HitTestResult result(hitPoint); | 358 HitTestResult result(hitPoint); |
359 if (renderer->nodeAtFloatPoint(HitTestRequest(HitTestRequest::SVGClipCon
tent), result, point, HitTestForeground)) | 359 if (renderer->nodeAtFloatPoint(HitTestRequest(HitTestRequest::SVGClipCon
tent), result, point, HitTestForeground)) |
360 return true; | 360 return true; |
361 } | 361 } |
362 | 362 |
(...skipping 14 matching lines...) Expand all Loading... |
377 AffineTransform transform; | 377 AffineTransform transform; |
378 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); | 378 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); |
379 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h
eight()); | 379 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h
eight()); |
380 return transform.mapRect(m_clipBoundaries); | 380 return transform.mapRect(m_clipBoundaries); |
381 } | 381 } |
382 | 382 |
383 return m_clipBoundaries; | 383 return m_clipBoundaries; |
384 } | 384 } |
385 | 385 |
386 } | 386 } |
OLD | NEW |