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

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

Issue 570583002: Make some use of RenderSVGResourceClipper::clipPathUnits() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 Path subPath; 122 Path subPath;
123 styled->toClipPath(subPath); 123 styled->toClipPath(subPath);
124 subPath.setWindRule(svgStyle.clipRule()); 124 subPath.setWindRule(svgStyle.clipRule());
125 if (!clipPath.unionPath(subPath)) 125 if (!clipPath.unionPath(subPath))
126 return false; 126 return false;
127 } else { 127 } else {
128 return false; 128 return false;
129 } 129 }
130 } 130 }
131 // Only one visible shape/path was found. Directly continue clipping and tra nsform the content to userspace if necessary. 131 // Only one visible shape/path was found. Directly continue clipping and tra nsform the content to userspace if necessary.
132 if (toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enumVa lue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { 132 if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
133 AffineTransform transform; 133 AffineTransform transform;
134 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 134 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
135 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 135 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
136 clipPath.transform(transform); 136 clipPath.transform(transform);
137 } 137 }
138 138
139 // Transform path by animatedLocalTransform. 139 // Transform path by animatedLocalTransform.
140 clipPath.transform(animatedLocalTransform); 140 clipPath.transform(animatedLocalTransform);
141 141
142 // The SVG specification wants us to clip everything, if clip-path doesn't h ave a child. 142 // The SVG specification wants us to clip everything, if clip-path doesn't h ave a child.
(...skipping 12 matching lines...) Expand all
155 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); 155 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout());
156 156
157 if (paintInvalidationRect.isEmpty() || m_inClipExpansion) 157 if (paintInvalidationRect.isEmpty() || m_inClipExpansion)
158 return false; 158 return false;
159 TemporaryChange<bool> inClipExpansionChange(m_inClipExpansion, true); 159 TemporaryChange<bool> inClipExpansionChange(m_inClipExpansion, true);
160 160
161 AffineTransform animatedLocalTransform = toSVGClipPathElement(element())->an imatedLocalTransform(); 161 AffineTransform animatedLocalTransform = toSVGClipPathElement(element())->an imatedLocalTransform();
162 // When drawing a clip for non-SVG elements, the CTM does not include the zo om factor. 162 // When drawing a clip for non-SVG elements, the CTM does not include the zo om factor.
163 // In this case, we need to apply the zoom scale explicitly - but only for c lips with 163 // In this case, we need to apply the zoom scale explicitly - but only for c lips with
164 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve d lengths). 164 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve d lengths).
165 if (!target->isSVG() 165 if (!target->isSVG() && clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_USERS PACEONUSE) {
166 && toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enu mValue() == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
167 ASSERT(style()); 166 ASSERT(style());
168 animatedLocalTransform.scale(style()->effectiveZoom()); 167 animatedLocalTransform.scale(style()->effectiveZoom());
169 } 168 }
170 169
171 // First, try to apply the clip as a clipPath. 170 // First, try to apply the clip as a clipPath.
172 if (tryPathOnlyClipping(context, animatedLocalTransform, targetBoundingBox)) { 171 if (tryPathOnlyClipping(context, animatedLocalTransform, targetBoundingBox)) {
173 clipperState = ClipperAppliedPath; 172 clipperState = ClipperAppliedPath;
174 return true; 173 return true;
175 } 174 }
176 175
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 default: 229 default:
231 ASSERT_NOT_REACHED(); 230 ASSERT_NOT_REACHED();
232 } 231 }
233 } 232 }
234 233
235 void RenderSVGResourceClipper::drawClipMaskContent(GraphicsContext* context, con st FloatRect& targetBoundingBox) 234 void RenderSVGResourceClipper::drawClipMaskContent(GraphicsContext* context, con st FloatRect& targetBoundingBox)
236 { 235 {
237 ASSERT(context); 236 ASSERT(context);
238 237
239 AffineTransform contentTransformation; 238 AffineTransform contentTransformation;
240 SVGUnitTypes::SVGUnitType contentUnits = toSVGClipPathElement(element())->cl ipPathUnits()->currentValue()->enumValue(); 239 if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
241 if (contentUnits == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
242 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox .y()); 240 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox .y());
243 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB oundingBox.height()); 241 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB oundingBox.height());
244 context->concatCTM(contentTransformation); 242 context->concatCTM(contentTransformation);
245 } 243 }
246 244
247 if (!m_clipContentDisplayList) 245 if (!m_clipContentDisplayList)
248 createDisplayList(context, contentTransformation); 246 createDisplayList(context, contentTransformation);
249 247
250 ASSERT(m_clipContentDisplayList); 248 ASSERT(m_clipContentDisplayList);
251 context->drawDisplayList(m_clipContentDisplayList.get()); 249 context->drawDisplayList(m_clipContentDisplayList.get());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 322 }
325 m_clipBoundaries = toSVGClipPathElement(element())->animatedLocalTransform() .mapRect(m_clipBoundaries); 323 m_clipBoundaries = toSVGClipPathElement(element())->animatedLocalTransform() .mapRect(m_clipBoundaries);
326 } 324 }
327 325
328 bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin gBox, const FloatPoint& nodeAtPoint) 326 bool RenderSVGResourceClipper::hitTestClipContent(const FloatRect& objectBoundin gBox, const FloatPoint& nodeAtPoint)
329 { 327 {
330 FloatPoint point = nodeAtPoint; 328 FloatPoint point = nodeAtPoint;
331 if (!SVGRenderSupport::pointInClippingArea(this, point)) 329 if (!SVGRenderSupport::pointInClippingArea(this, point))
332 return false; 330 return false;
333 331
334 SVGClipPathElement* clipPathElement = toSVGClipPathElement(element()); 332 if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
335 if (clipPathElement->clipPathUnits()->currentValue()->enumValue() == SVGUnit Types::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
336 AffineTransform transform; 333 AffineTransform transform;
337 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 334 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
338 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 335 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
339 point = transform.inverse().mapPoint(point); 336 point = transform.inverse().mapPoint(point);
340 } 337 }
341 338
342 AffineTransform animatedLocalTransform = clipPathElement->animatedLocalTrans form(); 339 AffineTransform animatedLocalTransform = toSVGClipPathElement(element())->an imatedLocalTransform();
343 if (!animatedLocalTransform.isInvertible()) 340 if (!animatedLocalTransform.isInvertible())
344 return false; 341 return false;
345 342
346 point = animatedLocalTransform.inverse().mapPoint(point); 343 point = animatedLocalTransform.inverse().mapPoint(point);
347 344
348 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) { 345 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) {
349 RenderObject* renderer = childElement->renderer(); 346 RenderObject* renderer = childElement->renderer();
350 if (!renderer) 347 if (!renderer)
351 continue; 348 continue;
352 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen t(*childElement)) 349 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen t(*childElement))
353 continue; 350 continue;
354 IntPoint hitPoint; 351 IntPoint hitPoint;
355 HitTestResult result(hitPoint); 352 HitTestResult result(hitPoint);
356 if (renderer->nodeAtFloatPoint(HitTestRequest(HitTestRequest::SVGClipCon tent), result, point, HitTestForeground)) 353 if (renderer->nodeAtFloatPoint(HitTestRequest(HitTestRequest::SVGClipCon tent), result, point, HitTestForeground))
357 return true; 354 return true;
358 } 355 }
359 356
360 return false; 357 return false;
361 } 358 }
362 359
363 FloatRect RenderSVGResourceClipper::resourceBoundingBox(const RenderObject* obje ct) 360 FloatRect RenderSVGResourceClipper::resourceBoundingBox(const RenderObject* obje ct)
364 { 361 {
365 // Resource was not layouted yet. Give back the boundingBox of the object. 362 // Resource was not layouted yet. Give back the boundingBox of the object.
366 if (selfNeedsLayout()) 363 if (selfNeedsLayout())
367 return object->objectBoundingBox(); 364 return object->objectBoundingBox();
368 365
369 if (m_clipBoundaries.isEmpty()) 366 if (m_clipBoundaries.isEmpty())
370 calculateClipContentPaintInvalidationRect(); 367 calculateClipContentPaintInvalidationRect();
371 368
372 if (toSVGClipPathElement(element())->clipPathUnits()->currentValue()->enumVa lue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { 369 if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
373 FloatRect objectBoundingBox = object->objectBoundingBox(); 370 FloatRect objectBoundingBox = object->objectBoundingBox();
374 AffineTransform transform; 371 AffineTransform transform;
375 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 372 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
376 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 373 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
377 return transform.mapRect(m_clipBoundaries); 374 return transform.mapRect(m_clipBoundaries);
378 } 375 }
379 376
380 return m_clipBoundaries; 377 return m_clipBoundaries;
381 } 378 }
382 379
383 } 380 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698