OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
4 * Copyright (C) 2013 Xidorn Quan (quanxunzhen@gmail.com) | 4 * Copyright (C) 2013 Xidorn Quan (quanxunzhen@gmail.com) |
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 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 13 matching lines...) Expand all Loading... |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "platform/geometry/RoundedRect.h" | 29 #include "platform/geometry/RoundedRect.h" |
30 | 30 |
31 #include "wtf/Assertions.h" | 31 #include "wtf/Assertions.h" |
32 #include <algorithm> | 32 #include <algorithm> |
33 | 33 |
34 using namespace std; | |
35 | |
36 namespace blink { | 34 namespace blink { |
37 | 35 |
38 bool RoundedRect::Radii::isZero() const | 36 bool RoundedRect::Radii::isZero() const |
39 { | 37 { |
40 return m_topLeft.isZero() && m_topRight.isZero() && m_bottomLeft.isZero() &&
m_bottomRight.isZero(); | 38 return m_topLeft.isZero() && m_topRight.isZero() && m_bottomLeft.isZero() &&
m_bottomRight.isZero(); |
41 } | 39 } |
42 | 40 |
43 void RoundedRect::Radii::scale(float factor) | 41 void RoundedRect::Radii::scale(float factor) |
44 { | 42 { |
45 if (factor == 1) | 43 if (factor == 1) |
(...skipping 11 matching lines...) Expand all Loading... |
57 m_bottomLeft = IntSize(); | 55 m_bottomLeft = IntSize(); |
58 m_bottomRight.scale(factor); | 56 m_bottomRight.scale(factor); |
59 if (!m_bottomRight.width() || !m_bottomRight.height()) | 57 if (!m_bottomRight.width() || !m_bottomRight.height()) |
60 m_bottomRight = IntSize(); | 58 m_bottomRight = IntSize(); |
61 | 59 |
62 } | 60 } |
63 | 61 |
64 void RoundedRect::Radii::expand(int topWidth, int bottomWidth, int leftWidth, in
t rightWidth) | 62 void RoundedRect::Radii::expand(int topWidth, int bottomWidth, int leftWidth, in
t rightWidth) |
65 { | 63 { |
66 if (m_topLeft.width() > 0 && m_topLeft.height() > 0) { | 64 if (m_topLeft.width() > 0 && m_topLeft.height() > 0) { |
67 m_topLeft.setWidth(max<int>(0, m_topLeft.width() + leftWidth)); | 65 m_topLeft.setWidth(std::max<int>(0, m_topLeft.width() + leftWidth)); |
68 m_topLeft.setHeight(max<int>(0, m_topLeft.height() + topWidth)); | 66 m_topLeft.setHeight(std::max<int>(0, m_topLeft.height() + topWidth)); |
69 } | 67 } |
70 if (m_topRight.width() > 0 && m_topRight.height() > 0) { | 68 if (m_topRight.width() > 0 && m_topRight.height() > 0) { |
71 m_topRight.setWidth(max<int>(0, m_topRight.width() + rightWidth)); | 69 m_topRight.setWidth(std::max<int>(0, m_topRight.width() + rightWidth)); |
72 m_topRight.setHeight(max<int>(0, m_topRight.height() + topWidth)); | 70 m_topRight.setHeight(std::max<int>(0, m_topRight.height() + topWidth)); |
73 } | 71 } |
74 if (m_bottomLeft.width() > 0 && m_bottomLeft.height() > 0) { | 72 if (m_bottomLeft.width() > 0 && m_bottomLeft.height() > 0) { |
75 m_bottomLeft.setWidth(max<int>(0, m_bottomLeft.width() + leftWidth)); | 73 m_bottomLeft.setWidth(std::max<int>(0, m_bottomLeft.width() + leftWidth)
); |
76 m_bottomLeft.setHeight(max<int>(0, m_bottomLeft.height() + bottomWidth))
; | 74 m_bottomLeft.setHeight(std::max<int>(0, m_bottomLeft.height() + bottomWi
dth)); |
77 } | 75 } |
78 if (m_bottomRight.width() > 0 && m_bottomRight.height() > 0) { | 76 if (m_bottomRight.width() > 0 && m_bottomRight.height() > 0) { |
79 m_bottomRight.setWidth(max<int>(0, m_bottomRight.width() + rightWidth)); | 77 m_bottomRight.setWidth(std::max<int>(0, m_bottomRight.width() + rightWid
th)); |
80 m_bottomRight.setHeight(max<int>(0, m_bottomRight.height() + bottomWidth
)); | 78 m_bottomRight.setHeight(std::max<int>(0, m_bottomRight.height() + bottom
Width)); |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 void RoundedRect::inflateWithRadii(int size) | 82 void RoundedRect::inflateWithRadii(int size) |
85 { | 83 { |
86 IntRect old = m_rect; | 84 IntRect old = m_rect; |
87 | 85 |
88 m_rect.inflate(size); | 86 m_rect.inflate(size); |
89 // Considering the inflation factor of shorter size to scale the radii seems
appropriate here | 87 // Considering the inflation factor of shorter size to scale the radii seems
appropriate here |
90 float factor; | 88 float factor; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 145 |
148 RoundedRect::RoundedRect(const IntRect& rect, const IntSize& topLeft, const IntS
ize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight) | 146 RoundedRect::RoundedRect(const IntRect& rect, const IntSize& topLeft, const IntS
ize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight) |
149 : m_rect(rect) | 147 : m_rect(rect) |
150 , m_radii(topLeft, topRight, bottomLeft, bottomRight) | 148 , m_radii(topLeft, topRight, bottomLeft, bottomRight) |
151 { | 149 { |
152 } | 150 } |
153 | 151 |
154 IntRect RoundedRect::radiusCenterRect() const | 152 IntRect RoundedRect::radiusCenterRect() const |
155 { | 153 { |
156 ASSERT(isRenderable()); | 154 ASSERT(isRenderable()); |
157 int minX = m_rect.x() + max(m_radii.topLeft().width(), m_radii.bottomLeft().
width()); | 155 int minX = m_rect.x() + std::max(m_radii.topLeft().width(), m_radii.bottomLe
ft().width()); |
158 int minY = m_rect.y() + max(m_radii.topLeft().height(), m_radii.topRight().h
eight()); | 156 int minY = m_rect.y() + std::max(m_radii.topLeft().height(), m_radii.topRigh
t().height()); |
159 int maxX = m_rect.maxX() - max(m_radii.topRight().width(), m_radii.bottomRig
ht().width()); | 157 int maxX = m_rect.maxX() - std::max(m_radii.topRight().width(), m_radii.bott
omRight().width()); |
160 int maxY = m_rect.maxY() - max(m_radii.bottomLeft().height(), m_radii.bottom
Right().height()); | 158 int maxY = m_rect.maxY() - std::max(m_radii.bottomLeft().height(), m_radii.b
ottomRight().height()); |
161 return IntRect(minX, minY, maxX - minX, maxY - minY); | 159 return IntRect(minX, minY, maxX - minX, maxY - minY); |
162 } | 160 } |
163 | 161 |
164 void RoundedRect::includeLogicalEdges(const Radii& edges, bool isHorizontal, boo
l includeLogicalLeftEdge, bool includeLogicalRightEdge) | 162 void RoundedRect::includeLogicalEdges(const Radii& edges, bool isHorizontal, boo
l includeLogicalLeftEdge, bool includeLogicalRightEdge) |
165 { | 163 { |
166 m_radii.includeLogicalEdges(edges, isHorizontal, includeLogicalLeftEdge, inc
ludeLogicalRightEdge); | 164 m_radii.includeLogicalEdges(edges, isHorizontal, includeLogicalLeftEdge, inc
ludeLogicalRightEdge); |
167 } | 165 } |
168 | 166 |
169 void RoundedRect::excludeLogicalEdges(bool isHorizontal, bool excludeLogicalLeft
Edge, bool excludeLogicalRightEdge) | 167 void RoundedRect::excludeLogicalEdges(bool isHorizontal, bool excludeLogicalLeft
Edge, bool excludeLogicalRightEdge) |
170 { | 168 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 FloatSize size(bottomRight.width(), bottomRight.height()); | 238 FloatSize size(bottomRight.width(), bottomRight.height()); |
241 if (!quad.intersectsEllipse(center, size)) | 239 if (!quad.intersectsEllipse(center, size)) |
242 return false; | 240 return false; |
243 } | 241 } |
244 } | 242 } |
245 | 243 |
246 return true; | 244 return true; |
247 } | 245 } |
248 | 246 |
249 } // namespace blink | 247 } // namespace blink |
OLD | NEW |