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

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

Issue 23063002: Add toSVGClipPathElement(), and use it (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 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
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 Path subPath; 120 Path subPath;
121 styled->toClipPath(subPath); 121 styled->toClipPath(subPath);
122 subPath.setWindRule(svgStyle->clipRule()); 122 subPath.setWindRule(svgStyle->clipRule());
123 if (!clipPath.unionPath(subPath)) 123 if (!clipPath.unionPath(subPath))
124 return false; 124 return false;
125 } else { 125 } else {
126 return false; 126 return false;
127 } 127 }
128 } 128 }
129 // Only one visible shape/path was found. Directly continue clipping and tra nsform the content to userspace if necessary. 129 // Only one visible shape/path was found. Directly continue clipping and tra nsform the content to userspace if necessary.
130 if (static_cast<SVGClipPathElement*>(node())->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { 130 if (toSVGClipPathElement(node())->clipPathUnitsCurrentValue() == SVGUnitType s::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
131 AffineTransform transform; 131 AffineTransform transform;
132 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 132 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
133 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 133 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
134 clipPath.transform(transform); 134 clipPath.transform(transform);
135 } 135 }
136 136
137 // Transform path by animatedLocalTransform. 137 // Transform path by animatedLocalTransform.
138 clipPath.transform(animatedLocalTransform); 138 clipPath.transform(animatedLocalTransform);
139 139
140 // The SVG specification wants us to clip everything, if clip-path doesn't h ave a child. 140 // The SVG specification wants us to clip everything, if clip-path doesn't h ave a child.
141 if (clipPath.isEmpty()) 141 if (clipPath.isEmpty())
142 clipPath.addRect(FloatRect()); 142 clipPath.addRect(FloatRect());
143 context->clipPath(clipPath, clipRule); 143 context->clipPath(clipPath, clipRule);
144 return true; 144 return true;
145 } 145 }
146 146
147 bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* object, cons t FloatRect& objectBoundingBox, 147 bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* object, cons t FloatRect& objectBoundingBox,
148 const FloatRect& repaintRe ct, GraphicsContext* context) 148 const FloatRect& repaintRe ct, GraphicsContext* context)
149 { 149 {
150 bool missingClipperData = !m_clipper.contains(object); 150 bool missingClipperData = !m_clipper.contains(object);
151 if (missingClipperData) 151 if (missingClipperData)
152 m_clipper.set(object, new ClipperData); 152 m_clipper.set(object, new ClipperData);
153 153
154 bool shouldCreateClipData = false; 154 bool shouldCreateClipData = false;
155 AffineTransform animatedLocalTransform = static_cast<SVGClipPathElement*>(no de())->animatedLocalTransform(); 155 AffineTransform animatedLocalTransform = toSVGClipPathElement(node())->anima tedLocalTransform();
156 ClipperData* clipperData = m_clipper.get(object); 156 ClipperData* clipperData = m_clipper.get(object);
157 if (!clipperData->clipMaskImage) { 157 if (!clipperData->clipMaskImage) {
158 if (pathOnlyClipping(context, animatedLocalTransform, objectBoundingBox) ) 158 if (pathOnlyClipping(context, animatedLocalTransform, objectBoundingBox) )
159 return true; 159 return true;
160 shouldCreateClipData = true; 160 shouldCreateClipData = true;
161 } 161 }
162 162
163 AffineTransform absoluteTransform; 163 AffineTransform absoluteTransform;
164 SVGRenderingContext::calculateTransformationToOutermostCoordinateSystem(obje ct, absoluteTransform); 164 SVGRenderingContext::calculateTransformationToOutermostCoordinateSystem(obje ct, absoluteTransform);
165 165
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 bool RenderSVGResourceClipper::drawContentIntoMaskImage(ClipperData* clipperData , const FloatRect& objectBoundingBox) 201 bool RenderSVGResourceClipper::drawContentIntoMaskImage(ClipperData* clipperData , const FloatRect& objectBoundingBox)
202 { 202 {
203 ASSERT(frame()); 203 ASSERT(frame());
204 ASSERT(clipperData); 204 ASSERT(clipperData);
205 ASSERT(clipperData->clipMaskImage); 205 ASSERT(clipperData->clipMaskImage);
206 206
207 GraphicsContext* maskContext = clipperData->clipMaskImage->context(); 207 GraphicsContext* maskContext = clipperData->clipMaskImage->context();
208 ASSERT(maskContext); 208 ASSERT(maskContext);
209 209
210 AffineTransform maskContentTransformation; 210 AffineTransform maskContentTransformation;
211 SVGClipPathElement* clipPath = static_cast<SVGClipPathElement*>(node()); 211 if (toSVGClipPathElement(node())->clipPathUnitsCurrentValue() == SVGUnitType s::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
212 if (clipPath->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJ ECTBOUNDINGBOX) {
213 maskContentTransformation.translate(objectBoundingBox.x(), objectBoundin gBox.y()); 212 maskContentTransformation.translate(objectBoundingBox.x(), objectBoundin gBox.y());
214 maskContentTransformation.scaleNonUniform(objectBoundingBox.width(), obj ectBoundingBox.height()); 213 maskContentTransformation.scaleNonUniform(objectBoundingBox.width(), obj ectBoundingBox.height());
215 maskContext->concatCTM(maskContentTransformation); 214 maskContext->concatCTM(maskContentTransformation);
216 } 215 }
217 216
218 // Switch to a paint behavior where all children of this <clipPath> will be rendered using special constraints: 217 // Switch to a paint behavior where all children of this <clipPath> will be rendered using special constraints:
219 // - fill-opacity/stroke-opacity/opacity set to 1 218 // - fill-opacity/stroke-opacity/opacity set to 1
220 // - masker/filter not applied when rendering the children 219 // - masker/filter not applied when rendering the children
221 // - fill is set to the initial fill paint server (solid, black) 220 // - fill is set to the initial fill paint server (solid, black)
222 // - stroke is set to the initial stroke paint server (none) 221 // - stroke is set to the initial stroke paint server (none)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 RenderObject* renderer = childNode->renderer(); 269 RenderObject* renderer = childNode->renderer();
271 if (!childNode->isSVGElement() || !renderer) 270 if (!childNode->isSVGElement() || !renderer)
272 continue; 271 continue;
273 if (!renderer->isSVGShape() && !renderer->isSVGText() && !childNode->has TagName(SVGNames::useTag)) 272 if (!renderer->isSVGShape() && !renderer->isSVGText() && !childNode->has TagName(SVGNames::useTag))
274 continue; 273 continue;
275 RenderStyle* style = renderer->style(); 274 RenderStyle* style = renderer->style();
276 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 275 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
277 continue; 276 continue;
278 m_clipBoundaries.unite(renderer->localToParentTransform().mapRect(render er->repaintRectInLocalCoordinates())); 277 m_clipBoundaries.unite(renderer->localToParentTransform().mapRect(render er->repaintRectInLocalCoordinates()));
279 } 278 }
280 m_clipBoundaries = static_cast<SVGClipPathElement*>(node())->animatedLocalTr ansform().mapRect(m_clipBoundaries); 279 m_clipBoundaries = toSVGClipPathElement(node())->animatedLocalTransform().ma pRect(m_clipBoundaries);
281 } 280 }
282 281
283 bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin gBox, const FloatPoint& nodeAtPoint) 282 bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin gBox, const FloatPoint& nodeAtPoint)
284 { 283 {
285 FloatPoint point = nodeAtPoint; 284 FloatPoint point = nodeAtPoint;
286 if (!SVGRenderSupport::pointInClippingArea(this, point)) 285 if (!SVGRenderSupport::pointInClippingArea(this, point))
287 return false; 286 return false;
288 287
289 SVGClipPathElement* clipPathElement = static_cast<SVGClipPathElement*>(node( )); 288 SVGClipPathElement* clipPathElement = toSVGClipPathElement(node());
290 if (clipPathElement->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_T YPE_OBJECTBOUNDINGBOX) { 289 if (clipPathElement->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_T YPE_OBJECTBOUNDINGBOX) {
291 AffineTransform transform; 290 AffineTransform transform;
292 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 291 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
293 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 292 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
294 point = transform.inverse().mapPoint(point); 293 point = transform.inverse().mapPoint(point);
295 } 294 }
296 295
297 point = clipPathElement->animatedLocalTransform().inverse().mapPoint(point); 296 point = clipPathElement->animatedLocalTransform().inverse().mapPoint(point);
298 297
299 for (Node* childNode = node()->firstChild(); childNode; childNode = childNod e->nextSibling()) { 298 for (Node* childNode = node()->firstChild(); childNode; childNode = childNod e->nextSibling()) {
(...skipping 13 matching lines...) Expand all
313 312
314 FloatRect RenderSVGResourceClipper::resourceBoundingBox(RenderObject* object) 313 FloatRect RenderSVGResourceClipper::resourceBoundingBox(RenderObject* object)
315 { 314 {
316 // Resource was not layouted yet. Give back the boundingBox of the object. 315 // Resource was not layouted yet. Give back the boundingBox of the object.
317 if (selfNeedsLayout()) 316 if (selfNeedsLayout())
318 return object->objectBoundingBox(); 317 return object->objectBoundingBox();
319 318
320 if (m_clipBoundaries.isEmpty()) 319 if (m_clipBoundaries.isEmpty())
321 calculateClipContentRepaintRect(); 320 calculateClipContentRepaintRect();
322 321
323 if (static_cast<SVGClipPathElement*>(node())->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { 322 if (toSVGClipPathElement(node())->clipPathUnitsCurrentValue() == SVGUnitType s::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
324 FloatRect objectBoundingBox = object->objectBoundingBox(); 323 FloatRect objectBoundingBox = object->objectBoundingBox();
325 AffineTransform transform; 324 AffineTransform transform;
326 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 325 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
327 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 326 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
328 return transform.mapRect(m_clipBoundaries); 327 return transform.mapRect(m_clipBoundaries);
329 } 328 }
330 329
331 return m_clipBoundaries; 330 return m_clipBoundaries;
332 } 331 }
333 332
334 } 333 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/RenderSVGResourceClipper.h ('k') | Source/core/svg/SVGClipPathElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698