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

Side by Side Diff: Source/core/layout/svg/LayoutSVGRect.cpp

Issue 927583002: Moving RenderSVG* files from rendering/ to layout/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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
« no previous file with comments | « Source/core/layout/svg/LayoutSVGRect.h ('k') | Source/core/layout/svg/LayoutSVGShape.h » ('j') | 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) 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 15 matching lines...) Expand all
26 */ 26 */
27 27
28 #include "config.h" 28 #include "config.h"
29 #include "core/layout/svg/LayoutSVGRect.h" 29 #include "core/layout/svg/LayoutSVGRect.h"
30 30
31 #include "core/svg/SVGRectElement.h" 31 #include "core/svg/SVGRectElement.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 LayoutSVGRect::LayoutSVGRect(SVGRectElement* node) 35 LayoutSVGRect::LayoutSVGRect(SVGRectElement* node)
36 : RenderSVGShape(node) 36 : LayoutSVGShape(node)
37 , m_usePathFallback(false) 37 , m_usePathFallback(false)
38 { 38 {
39 } 39 }
40 40
41 LayoutSVGRect::~LayoutSVGRect() 41 LayoutSVGRect::~LayoutSVGRect()
42 { 42 {
43 } 43 }
44 44
45 void LayoutSVGRect::updateShapeFromElement() 45 void LayoutSVGRect::updateShapeFromElement()
46 { 46 {
47 // Before creating a new object we need to clear the cached bounding box 47 // Before creating a new object we need to clear the cached bounding box
48 // to avoid using garbage. 48 // to avoid using garbage.
49 m_fillBoundingBox = FloatRect(); 49 m_fillBoundingBox = FloatRect();
50 m_innerStrokeRect = FloatRect(); 50 m_innerStrokeRect = FloatRect();
51 m_outerStrokeRect = FloatRect(); 51 m_outerStrokeRect = FloatRect();
52 m_usePathFallback = false; 52 m_usePathFallback = false;
53 SVGRectElement* rect = toSVGRectElement(element()); 53 SVGRectElement* rect = toSVGRectElement(element());
54 ASSERT(rect); 54 ASSERT(rect);
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 and path-based hit detection if the rect 65 // Fallback to LayoutSVGShape and path-based hit detection if the rect
66 // has rounded corners or a non-scaling or non-simple stroke. 66 // has rounded corners or a non-scaling or non-simple stroke.
67 if (rect->rx()->currentValue()->value(lengthContext) > 0 67 if (rect->rx()->currentValue()->value(lengthContext) > 0
68 || rect->ry()->currentValue()->value(lengthContext) > 0 68 || rect->ry()->currentValue()->value(lengthContext) > 0
69 || hasNonScalingStroke() 69 || hasNonScalingStroke()
70 || !definitelyHasSimpleStroke()) { 70 || !definitelyHasSimpleStroke()) {
71 RenderSVGShape::updateShapeFromElement(); 71 LayoutSVGShape::updateShapeFromElement();
72 m_usePathFallback = true; 72 m_usePathFallback = true;
73 return; 73 return;
74 } 74 }
75 } 75 }
76 76
77 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) ;
78 78
79 // 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
80 // 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.
81 m_innerStrokeRect = m_fillBoundingBox; 81 m_innerStrokeRect = m_fillBoundingBox;
82 m_outerStrokeRect = m_fillBoundingBox; 82 m_outerStrokeRect = m_fillBoundingBox;
83 83
84 if (style()->svgStyle().hasStroke()) { 84 if (style()->svgStyle().hasStroke()) {
85 float strokeWidth = this->strokeWidth(); 85 float strokeWidth = this->strokeWidth();
86 m_innerStrokeRect.inflate(-strokeWidth / 2); 86 m_innerStrokeRect.inflate(-strokeWidth / 2);
87 m_outerStrokeRect.inflate(strokeWidth / 2); 87 m_outerStrokeRect.inflate(strokeWidth / 2);
88 } 88 }
89 89
90 m_strokeBoundingBox = m_outerStrokeRect; 90 m_strokeBoundingBox = m_outerStrokeRect;
91 } 91 }
92 92
93 bool LayoutSVGRect::shapeDependentStrokeContains(const FloatPoint& point) 93 bool LayoutSVGRect::shapeDependentStrokeContains(const FloatPoint& point)
94 { 94 {
95 // The optimized code below does not support non-simple strokes so we need 95 // The optimized code below does not support non-simple strokes so we need
96 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas es. 96 // to fall back to LayoutSVGShape::shapeDependentStrokeContains in these cas es.
97 if (m_usePathFallback || !definitelyHasSimpleStroke()) { 97 if (m_usePathFallback || !definitelyHasSimpleStroke()) {
98 if (!hasPath()) 98 if (!hasPath())
99 RenderSVGShape::updateShapeFromElement(); 99 LayoutSVGShape::updateShapeFromElement();
100 return RenderSVGShape::shapeDependentStrokeContains(point); 100 return LayoutSVGShape::shapeDependentStrokeContains(point);
101 } 101 }
102 102
103 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);
104 } 104 }
105 105
106 bool LayoutSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi ndRule fillRule) const 106 bool LayoutSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi ndRule fillRule) const
107 { 107 {
108 if (m_usePathFallback) 108 if (m_usePathFallback)
109 return RenderSVGShape::shapeDependentFillContains(point, fillRule); 109 return LayoutSVGShape::shapeDependentFillContains(point, fillRule);
110 return m_fillBoundingBox.contains(point.x(), point.y()); 110 return m_fillBoundingBox.contains(point.x(), point.y());
111 } 111 }
112 112
113 // Returns true if the stroke is continuous and definitely uses miter joins. 113 // Returns true if the stroke is continuous and definitely uses miter joins.
114 bool LayoutSVGRect::definitelyHasSimpleStroke() const 114 bool LayoutSVGRect::definitelyHasSimpleStroke() const
115 { 115 {
116 const SVGLayoutStyle& svgStyle = style()->svgStyle(); 116 const SVGLayoutStyle& svgStyle = style()->svgStyle();
117 117
118 // The four angles of a rect are 90 degrees. Using the formula at: 118 // The four angles of a rect are 90 degrees. Using the formula at:
119 // http://www.w3.org/TR/SVG/painting.html#StrokeMiterlimitProperty 119 // http://www.w3.org/TR/SVG/painting.html#StrokeMiterlimitProperty
(...skipping 10 matching lines...) Expand all
130 // An approximation of sqrt(2) is used here because at certain precise 130 // An approximation of sqrt(2) is used here because at certain precise
131 // miterlimits, the join style used might not be correct (e.g. a miterlimit 131 // miterlimits, the join style used might not be correct (e.g. a miterlimit
132 // of 1.4142135 should result in bevel joins, but may be drawn using miter 132 // of 1.4142135 should result in bevel joins, but may be drawn using miter
133 // joins). 133 // joins).
134 return svgStyle.strokeDashArray()->isEmpty() 134 return svgStyle.strokeDashArray()->isEmpty()
135 && svgStyle.joinStyle() == MiterJoin 135 && svgStyle.joinStyle() == MiterJoin
136 && svgStyle.strokeMiterLimit() >= 1.5; 136 && svgStyle.strokeMiterLimit() >= 1.5;
137 } 137 }
138 138
139 } 139 }
OLDNEW
« no previous file with comments | « Source/core/layout/svg/LayoutSVGRect.h ('k') | Source/core/layout/svg/LayoutSVGShape.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698