Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 University of Szeged | 2 * Copyright (C) 2011 University of Szeged |
| 3 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> | 3 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> |
| 4 * All rights reserved. | 4 * All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 | 55 |
| 56 SVGLengthContext lengthContext(rect); | 56 SVGLengthContext lengthContext(rect); |
| 57 FloatSize boundingBoxSize(rect->width()->currentValue()->value(lengthContext ), rect->height()->currentValue()->value(lengthContext)); | 57 FloatSize boundingBoxSize(rect->width()->currentValue()->value(lengthContext ), rect->height()->currentValue()->value(lengthContext)); |
| 58 | 58 |
| 59 // Spec: "A negative value is an error." | 59 // Spec: "A negative value is an error." |
| 60 if (boundingBoxSize.width() < 0 || boundingBoxSize.height() < 0) | 60 if (boundingBoxSize.width() < 0 || boundingBoxSize.height() < 0) |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 // Spec: "A value of zero disables rendering of the element." | 63 // Spec: "A value of zero disables rendering of the element." |
| 64 if (!boundingBoxSize.isEmpty()) { | 64 if (!boundingBoxSize.isEmpty()) { |
| 65 // Fallback to RenderSVGShape if rect has rounded corners or a non-scali ng stroke. | 65 // Fallback to RenderSVGShape and path-based hit detection if the rect |
| 66 if (rect->rx()->currentValue()->value(lengthContext) > 0 || rect->ry()-> currentValue()->value(lengthContext) > 0 || hasNonScalingStroke()) { | 66 // has rounded corners or a non-scaling or non-simple stroke. |
| 67 if (rect->rx()->currentValue()->value(lengthContext) > 0 | |
| 68 || rect->ry()->currentValue()->value(lengthContext) > 0 | |
| 69 || hasNonScalingStroke() | |
| 70 || !hasSimpleStroke()) { | |
| 67 RenderSVGShape::updateShapeFromElement(); | 71 RenderSVGShape::updateShapeFromElement(); |
| 68 m_usePathFallback = true; | 72 m_usePathFallback = true; |
| 69 return; | 73 return; |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 m_fillBoundingBox = FloatRect(FloatPoint(rect->x()->currentValue()->value(le ngthContext), rect->y()->currentValue()->value(lengthContext)), boundingBoxSize) ; | 77 m_fillBoundingBox = FloatRect(FloatPoint(rect->x()->currentValue()->value(le ngthContext), rect->y()->currentValue()->value(lengthContext)), boundingBoxSize) ; |
| 74 | 78 |
| 75 // To decide if the stroke contains a point we create two rects which repres ent the inner and | 79 // To decide if the stroke contains a point we create two rects which repres ent the inner and |
| 76 // the outer stroke borders. A stroke contains the point, if the point is be tween them. | 80 // the outer stroke borders. A stroke contains the point, if the point is be tween them. |
| 77 m_innerStrokeRect = m_fillBoundingBox; | 81 m_innerStrokeRect = m_fillBoundingBox; |
| 78 m_outerStrokeRect = m_fillBoundingBox; | 82 m_outerStrokeRect = m_fillBoundingBox; |
| 79 | 83 |
| 80 if (style()->svgStyle().hasStroke()) { | 84 if (style()->svgStyle().hasStroke()) { |
| 81 float strokeWidth = this->strokeWidth(); | 85 float strokeWidth = this->strokeWidth(); |
| 82 m_innerStrokeRect.inflate(-strokeWidth / 2); | 86 m_innerStrokeRect.inflate(-strokeWidth / 2); |
| 83 m_outerStrokeRect.inflate(strokeWidth / 2); | 87 m_outerStrokeRect.inflate(strokeWidth / 2); |
| 84 } | 88 } |
| 85 | 89 |
| 86 m_strokeBoundingBox = m_outerStrokeRect; | 90 m_strokeBoundingBox = m_outerStrokeRect; |
| 87 } | 91 } |
| 88 | 92 |
| 89 bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point) | 93 bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point) |
| 90 { | 94 { |
| 91 // The optimized contains code below does not support non-smooth strokes so we need | 95 // The optimized contains code below does not support non-smooth strokes so we need |
| 92 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas es. | 96 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas es. |
| 93 if (m_usePathFallback || !hasSmoothStroke()) { | 97 if (m_usePathFallback || !hasSimpleStroke()) { |
| 94 if (!hasPath()) | 98 if (!hasPath()) |
| 95 RenderSVGShape::updateShapeFromElement(); | 99 RenderSVGShape::updateShapeFromElement(); |
| 96 return RenderSVGShape::shapeDependentStrokeContains(point); | 100 return RenderSVGShape::shapeDependentStrokeContains(point); |
| 97 } | 101 } |
| 98 | 102 |
| 99 return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_ innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke); | 103 return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_ innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke); |
| 100 } | 104 } |
| 101 | 105 |
| 102 bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi ndRule fillRule) const | 106 bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi ndRule fillRule) const |
| 103 { | 107 { |
| 104 if (m_usePathFallback) | 108 if (m_usePathFallback) |
| 105 return RenderSVGShape::shapeDependentFillContains(point, fillRule); | 109 return RenderSVGShape::shapeDependentFillContains(point, fillRule); |
| 106 return m_fillBoundingBox.contains(point.x(), point.y()); | 110 return m_fillBoundingBox.contains(point.x(), point.y()); |
| 107 } | 111 } |
| 108 | 112 |
| 113 bool RenderSVGRect::hasSimpleStroke() const | |
| 114 { | |
| 115 const SVGRenderStyle& svgStyle = style()->svgStyle(); | |
| 116 return svgStyle.strokeDashArray()->isEmpty() | |
| 117 && svgStyle.strokeMiterLimit() == SVGRenderStyle::initialStrokeMiterLimi t() | |
| 118 && svgStyle.joinStyle() == SVGRenderStyle::initialJoinStyle(); | |
|
Erik Dahlström (inactive)
2014/12/04 14:25:48
Here's an example where this might fail: http://js
| |
| 109 } | 119 } |
| 120 | |
| 121 } | |
| OLD | NEW |