Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: Source/core/rendering/svg/RenderSVGResourceClipper.cpp

Issue 171663005: Consistently use ElementTraversal API when looking for an Element (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context, 84 bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context,
85 const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundi ngBox) { 85 const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundi ngBox) {
86 // If the current clip-path gets clipped itself, we have to fallback to mask ing. 86 // If the current clip-path gets clipped itself, we have to fallback to mask ing.
87 if (!style()->svgStyle()->clipperResource().isEmpty()) 87 if (!style()->svgStyle()->clipperResource().isEmpty())
88 return false; 88 return false;
89 WindRule clipRule = RULE_NONZERO; 89 WindRule clipRule = RULE_NONZERO;
90 Path clipPath = Path(); 90 Path clipPath = Path();
91 91
92 for (Node* childNode = element()->firstChild(); childNode; childNode = child Node->nextSibling()) { 92 for (Element* childElement = ElementTraversal::firstWithin(*element()); chil dElement; childElement = ElementTraversal::nextSibling(*childElement)) {
93 RenderObject* renderer = childNode->renderer(); 93 RenderObject* renderer = childElement->renderer();
94 if (!renderer) 94 if (!renderer)
95 continue; 95 continue;
96 // Only shapes or paths are supported for direct clipping. We need to fa llback to masking for texts. 96 // Only shapes or paths are supported for direct clipping. We need to fa llback to masking for texts.
97 if (renderer->isSVGText()) 97 if (renderer->isSVGText())
98 return false; 98 return false;
99 if (!childNode->isSVGElement() || !toSVGElement(childNode)->isSVGGraphic sElement()) 99 if (!childElement->isSVGElement() || !toSVGElement(childElement)->isSVGG raphicsElement())
100 continue; 100 continue;
101 SVGGraphicsElement* styled = toSVGGraphicsElement(childNode); 101 SVGGraphicsElement* styled = toSVGGraphicsElement(childElement);
102 RenderStyle* style = renderer->style(); 102 RenderStyle* style = renderer->style();
103 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 103 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
104 continue; 104 continue;
105 const SVGRenderStyle* svgStyle = style->svgStyle(); 105 const SVGRenderStyle* svgStyle = style->svgStyle();
106 // Current shape in clip-path gets clipped too. Fallback to masking. 106 // Current shape in clip-path gets clipped too. Fallback to masking.
107 if (!svgStyle->clipperResource().isEmpty()) 107 if (!svgStyle->clipperResource().isEmpty())
108 return false; 108 return false;
109 109
110 if (clipPath.isEmpty()) { 110 if (clipPath.isEmpty()) {
111 // First clip shape. 111 // First clip shape.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 context->beginRecording(strokeBoundingBox()); 264 context->beginRecording(strokeBoundingBox());
265 265
266 // Switch to a paint behavior where all children of this <clipPath> will be rendered using special constraints: 266 // Switch to a paint behavior where all children of this <clipPath> will be rendered using special constraints:
267 // - fill-opacity/stroke-opacity/opacity set to 1 267 // - fill-opacity/stroke-opacity/opacity set to 1
268 // - masker/filter not applied when rendering the children 268 // - masker/filter not applied when rendering the children
269 // - fill is set to the initial fill paint server (solid, black) 269 // - fill is set to the initial fill paint server (solid, black)
270 // - stroke is set to the initial stroke paint server (none) 270 // - stroke is set to the initial stroke paint server (none)
271 PaintBehavior oldBehavior = frame()->view()->paintBehavior(); 271 PaintBehavior oldBehavior = frame()->view()->paintBehavior();
272 frame()->view()->setPaintBehavior(oldBehavior | PaintBehaviorRenderingSVGMas k); 272 frame()->view()->setPaintBehavior(oldBehavior | PaintBehaviorRenderingSVGMas k);
273 273
274 for (Node* childNode = element()->firstChild(); childNode; childNode = child Node->nextSibling()) { 274 for (Element* childElement = ElementTraversal::firstWithin(*element()); chil dElement; childElement = ElementTraversal::nextSibling(*childElement)) {
275 RenderObject* renderer = childNode->renderer(); 275 RenderObject* renderer = childElement->renderer();
276 if (!childNode->isSVGElement() || !renderer) 276 if (!childElement->isSVGElement() || !renderer)
277 continue; 277 continue;
278 278
279 RenderStyle* style = renderer->style(); 279 RenderStyle* style = renderer->style();
280 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 280 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
281 continue; 281 continue;
282 282
283 WindRule newClipRule = style->svgStyle()->clipRule(); 283 WindRule newClipRule = style->svgStyle()->clipRule();
284 bool isUseElement = childNode->hasTagName(SVGNames::useTag); 284 bool isUseElement = childElement->hasTagName(SVGNames::useTag);
285 if (isUseElement) { 285 if (isUseElement) {
286 SVGUseElement* useElement = toSVGUseElement(childNode); 286 SVGUseElement* useElement = toSVGUseElement(childElement);
287 renderer = useElement->rendererClipChild(); 287 renderer = useElement->rendererClipChild();
288 if (!renderer) 288 if (!renderer)
289 continue; 289 continue;
290 if (!useElement->hasAttribute(SVGNames::clip_ruleAttr)) 290 if (!useElement->hasAttribute(SVGNames::clip_ruleAttr))
291 newClipRule = renderer->style()->svgStyle()->clipRule(); 291 newClipRule = renderer->style()->svgStyle()->clipRule();
292 } 292 }
293 293
294 // Only shapes, paths and texts are allowed for clipping. 294 // Only shapes, paths and texts are allowed for clipping.
295 if (!renderer->isSVGShape() && !renderer->isSVGText()) 295 if (!renderer->isSVGShape() && !renderer->isSVGText())
296 continue; 296 continue;
297 297
298 context->setFillRule(newClipRule); 298 context->setFillRule(newClipRule);
299 299
300 if (isUseElement) 300 if (isUseElement)
301 renderer = childNode->renderer(); 301 renderer = childElement->renderer();
302 302
303 SVGRenderingContext::renderSubtree(context, renderer, contentTransformat ion); 303 SVGRenderingContext::renderSubtree(context, renderer, contentTransformat ion);
304 } 304 }
305 305
306 frame()->view()->setPaintBehavior(oldBehavior); 306 frame()->view()->setPaintBehavior(oldBehavior);
307 307
308 return context->endRecording(); 308 return context->endRecording();
309 } 309 }
310 310
311 void RenderSVGResourceClipper::calculateClipContentRepaintRect() 311 void RenderSVGResourceClipper::calculateClipContentRepaintRect()
312 { 312 {
313 // This is a rough heuristic to appraise the clip size and doesn't consider clip on clip. 313 // This is a rough heuristic to appraise the clip size and doesn't consider clip on clip.
314 for (Node* childNode = element()->firstChild(); childNode; childNode = child Node->nextSibling()) { 314 for (Element* childElement = ElementTraversal::firstWithin(*element()); chil dElement; childElement = ElementTraversal::nextSibling(*childElement)) {
315 RenderObject* renderer = childNode->renderer(); 315 RenderObject* renderer = childElement->renderer();
316 if (!childNode->isSVGElement() || !renderer) 316 if (!childElement->isSVGElement() || !renderer)
317 continue; 317 continue;
318 if (!renderer->isSVGShape() && !renderer->isSVGText() && !childNode->has TagName(SVGNames::useTag)) 318 if (!renderer->isSVGShape() && !renderer->isSVGText() && !childElement-> hasTagName(SVGNames::useTag))
319 continue; 319 continue;
320 RenderStyle* style = renderer->style(); 320 RenderStyle* style = renderer->style();
321 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 321 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
322 continue; 322 continue;
323 m_clipBoundaries.unite(renderer->localToParentTransform().mapRect(render er->repaintRectInLocalCoordinates())); 323 m_clipBoundaries.unite(renderer->localToParentTransform().mapRect(render er->repaintRectInLocalCoordinates()));
324 } 324 }
325 m_clipBoundaries = toSVGClipPathElement(element())->animatedLocalTransform() .mapRect(m_clipBoundaries); 325 m_clipBoundaries = toSVGClipPathElement(element())->animatedLocalTransform() .mapRect(m_clipBoundaries);
326 } 326 }
327 327
328 bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin gBox, const FloatPoint& nodeAtPoint) 328 bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin gBox, const FloatPoint& nodeAtPoint)
329 { 329 {
330 FloatPoint point = nodeAtPoint; 330 FloatPoint point = nodeAtPoint;
331 if (!SVGRenderSupport::pointInClippingArea(this, point)) 331 if (!SVGRenderSupport::pointInClippingArea(this, point))
332 return false; 332 return false;
333 333
334 SVGClipPathElement* clipPathElement = toSVGClipPathElement(element()); 334 SVGClipPathElement* clipPathElement = toSVGClipPathElement(element());
335 if (clipPathElement->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_T YPE_OBJECTBOUNDINGBOX) { 335 if (clipPathElement->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_T YPE_OBJECTBOUNDINGBOX) {
336 AffineTransform transform; 336 AffineTransform transform;
337 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 337 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
338 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 338 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
339 point = transform.inverse().mapPoint(point); 339 point = transform.inverse().mapPoint(point);
340 } 340 }
341 341
342 point = clipPathElement->animatedLocalTransform().inverse().mapPoint(point); 342 point = clipPathElement->animatedLocalTransform().inverse().mapPoint(point);
343 343
344 for (Node* childNode = element()->firstChild(); childNode; childNode = child Node->nextSibling()) { 344 for (Element* childElement = ElementTraversal::firstWithin(*element()); chil dElement; childElement = ElementTraversal::nextSibling(*childElement)) {
345 RenderObject* renderer = childNode->renderer(); 345 RenderObject* renderer = childElement->renderer();
346 if (!childNode->isSVGElement() || !renderer) 346 if (!childElement->isSVGElement() || !renderer)
347 continue; 347 continue;
348 if (!renderer->isSVGShape() && !renderer->isSVGText() && !childNode->has TagName(SVGNames::useTag)) 348 if (!renderer->isSVGShape() && !renderer->isSVGText() && !childElement-> hasTagName(SVGNames::useTag))
349 continue; 349 continue;
350 IntPoint hitPoint; 350 IntPoint hitPoint;
351 HitTestResult result(hitPoint); 351 HitTestResult result(hitPoint);
352 if (renderer->nodeAtFloatPoint(HitTestRequest(HitTestRequest::SVGClipCon tent | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent), result, p oint, HitTestForeground)) 352 if (renderer->nodeAtFloatPoint(HitTestRequest(HitTestRequest::SVGClipCon tent | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent), result, p oint, HitTestForeground))
353 return true; 353 return true;
354 } 354 }
355 355
356 return false; 356 return false;
357 } 357 }
358 358
(...skipping 11 matching lines...) Expand all
370 AffineTransform transform; 370 AffineTransform transform;
371 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 371 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
372 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 372 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
373 return transform.mapRect(m_clipBoundaries); 373 return transform.mapRect(m_clipBoundaries);
374 } 374 }
375 375
376 return m_clipBoundaries; 376 return m_clipBoundaries;
377 } 377 }
378 378
379 } 379 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/ReferenceFilterBuilder.cpp ('k') | Source/core/rendering/svg/RenderSVGResourceFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698